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 9167215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:20:08+00:00 2026-06-17T15:20:08+00:00

Usually when you do something like ‘test’.match(/(e)/) you would receive an array [‘e’, ‘e’]

  • 0

Usually when you do something like 'test'.match(/(e)/) you would receive an array ['e', 'e'], where the first element is the match itself and the second from the selector (braces), but when using the global modifier as in 'test'.match(/(e)/g) it will omit the match, while it doesn’t in case I don’t use selectors at all.

I wonder if and where the following behavior is specified (using Chromium for this test).

  • 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-17T15:20:09+00:00Added an answer on June 17, 2026 at 3:20 pm

    If the global flag (g) is not set, Element zero of the array contains the entire match, while elements 1 through n contain any submatches. This behavior is the same as the behavior of the exec Method (Regular Expression) (JavaScript) when the global flag is not set. If the global flag is set, elements 0 through n contain all matches that occurred.

    http://msdn.microsoft.com/en-us/library/ie/7df7sf4x(v=vs.94).aspx

    In other words, when g is provided, match collects only topmost matches, ignoring any capturing groups.

    Example:

    > s = "Foo Bar"
    "Foo Bar"
    > s.match(/([A-Z])([a-z]+)/)
    ["Foo", "F", "oo"]
    > s.match(/([A-Z])([a-z]+)/g)
    ["Foo", "Bar"]
    

    There’s no built-in that would collect all groups from all matches, like python findall does, but it’s easy to write using exec:

    function matchAll(re, str) {
        var p, r = [];
        while(p = re.exec(str))
            r.push(p);
        return r;
    }
    matchAll(/([A-Z])([a-z]+)/g, "Foo Bar")
    

    Result:

    [
    Array[3]
    0: "Foo"
    1: "F"
    2: "oo"
    index: 0
    input: "Foo Bar"
    length: 3
    __proto__: Array[0]
    , 
    Array[3]
    0: "Bar"
    1: "B"
    2: "ar"
    index: 4
    input: "Foo Bar"
    length: 3
    __proto__: Array[0]
    ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Usually in a django view you would do something like queryset = MyModel.objects.something() How
I usually do something like array.sort{|a,b| a.something <=> b.something} How should I DRY this
I usually write something like this: <mx:VBox height=100% width=155> <mx:Button label=b1 width=100%/> <mx:Buttonlabel=b2 width=100%/>
Usually I was doing something like that (just a example): using (Stream xmlStream =
I usually have my structure laid out something like this: <div id=all> <div id=page>
Almost every ios app now has something like Feed option. Programming that usually includes
in my view I usually do something like this <%= render :partial => shared/p
When looking at the reshape examples in the redbook, I usually find something like:
When I want to use a branch in CC, I usually put something like
I have a circular image, something like a pie chart. I would like 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.