Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9005321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:06:47+00:00 2026-06-16T01:06:47+00:00

Using the following text as my msg variable: /private UserName:some message without leading whitespace

  • 0

Using the following text as my msg variable:

/private UserName:some message without leading whitespace
/private UserName: some message with leading whitespace

And the following javascript to parse it:

if(msg.indexOf('/private') == 0){
    msg = msg.substring(8,msg.length);
    var parts = msg.match(/\s+(.+?)\:\s*(.+?)/);

    alert("Name: " + parts[0]);
    alert("Message: " + parts[1]);
}

I would expect index 0 to contain UserName
and index 1 to contain some message with …

Anyone see what I’m missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:06:49+00:00Added an answer on June 16, 2026 at 1:06 am

    Tweak your regex a little bit:

    /^\/private\s+(.*?):\s*(.*?)$/
    

    And simplify your code:

    var regex = /^\/private\s+(.*?):\s*(.*?)$/;
    var parts = regex.exec(msg);
    
    if (parts){
        alert("Name: " + parts[1]);
        alert("Message: " + parts[2]);
    }
    

    parts[0] is the entire matched string. You want parts[1] and parts[2].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following scenary: <div class=maindiv> <div class=msg>some text</div> ... <div class=msg>some other
I am using the following Hyperlink Text by using the TextBlock.... <Button Grid.Row=2 Foreground=#FF057BC3
Using following code I try to get updated list of checkbuttons' corresponding text values,
I have the following text: We%27re%20proud%20to%20introduce%20the%20Amazing I'd like to remove the encoding using PHP,
I'm using the Tabularize plugin in Vim and have the following text: reg [321:123]
I'm matching the following strings: watermark=testing watermark=text-testing|position-24-50 watermark=text-testing|position-24-50|color-6aa6cc watermark=text-testing|position-24-50|color-6aa6cc|size-48 using the following regex: watermark=(text-\w+\|position-\d+-\d+\|color-([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\|size-\d+|text-\w+\|position-\d+-\d+\|color-([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})|text-\w+\|position-\d+-\d+|\w+)
I'm using the following JQUERY Autocomplete plug-in: jQuery Plugin: Tokenizing Autocomplete Text Entry What'd
I'm writing to a text file using the following declaration: void create_out_file(char file_name[],long double
I send the text file to multiple devices using the following code, ContentValues values
I'm using the following code.. $(document).ready(function(){ $(#test a).click(function(){ var labelTo = $(this).text(); window.location =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.