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

  • SEARCH
  • Home
  • 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 6208661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:50:46+00:00 2026-05-24T05:50:46+00:00

I was just playing with the native replace method for strings in javascript. Is

  • 0

I was just playing with the native replace method for strings in javascript. Is there any thing like groups of groups. If not, how are groups ordered in string where a group encapsulates other open and closed parentheses (potential groups). For example,

var string = "my name is name that is named man".replace(/((name)|(is)|(man))/g, "$1");

What will the group references $1, $2, $3, and $4 be. I already tried it on my local computer (on firebug) but it gives me results that I can’t readily understand. A clear explanation on this will be appreciated!!

  • 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-05-24T05:50:46+00:00Added an answer on May 24, 2026 at 5:50 am

    In some languages you can specify a flag to say the order you want the groups to be in. In Javascript you can’t specify it. They will be in the order that the opening parenthesis occur in.
    So in your above example the groups will be, in order:

    1) ((name)|(is)|(man))

    2) (name)

    3) (is)

    4) (man)

    To see the output more clearly from your above string, execute:

    "my name is name that is named man".replace(/((name)|(is)|(man))/g, '1($1) 2($2) 3($3) 4($4)\n');
    

    Then you can cleary see what’s in each group when each match is reached:

    "my 1(name) 2(name) 3() 4()
     1(is) 2() 3(is) 4()
     1(name) 2(name) 3() 4()
     that 1(is) 2() 3(is) 4()
     1(name) 2(name) 3() 4()
    d 1(man) 2() 3() 4(man)"
    

    When the first match is reached you can see that the string which matched group 2 (name) matched group 1 as well. Group 3 and 4 didn’t match anything. Same goes for each match. in this case since group one wraps everything it will always contain the whole match, and since the inner part is an or, only one of those three groups will contain any text on each match.

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

Sidebar

Related Questions

I just ordered an Android smartphone and want to start playing around with creating
While just playing with jQuery/JavaScript I ran across this problem. I could capture Alt
I was just playing around with ckeditor and can't get the darn thing to
I'm just playing with some linq and asp.net - absolute beginner so I'm not
I'm just playing with an NFA for string recognition. I have a macro that
Just playing around with the now released Silverlight 2.0. I'm trying to put a
I'm just playing around and I'm trying to grab information from websites. Unfortunately, with
I was just playing around with the python command line and the ** operator,
I'm just playing around with WPF and MVVM, and I have made a simple
So I'm kind of new to VB and am just playing around with a

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.