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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:07:44+00:00 2026-05-26T05:07:44+00:00

I got a string like this: str = ‘autocomplete=\\\off\\\ name=\\\composer_session_id\\\ value=\\\1557423901\\\ \\\/>\\u003cinput type=\\\hidden\\\ autocomplete=\\\off\\\

  • 0

I got a string like this:

str = 'autocomplete=\\\"off\\\" name=\\\"composer_session_id\\\" value=\\\"1557423901\\\" \\\/>\\u003cinput type=\\\"hidden\\\" autocomplete=\\\"off\\\" name=\\\"is_explicit_place\\\" id=\\\"u436754_5\\\"';

and a regexp match:

str.match(/(composer_session_id|is_explicit_place)\\" (?:value|id)=\\"([_a-zA-Z0-9]+)\\"/g)

It working (kinda’), but despite the fact, I’m using capture groups to get the (composer_session_id|is_explicit_place) and ([_a-zA-Z0-9]+) the result array contains only two elements (biggest of matched strings):

["composer_session_id\" value=\"1557423901\"", "is_explicit_place\" id=\"u436754_5\""]

What am I missing here?

How can I use regexp to get strings: composer_session_id, is_explicit_place, 1557423901 and u436754_5 in a single run?

Bonus points for explanation why there are only two strings returned and solution for getting values I need that doesn’t involve using split() and/or replace().

  • 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-26T05:07:44+00:00Added an answer on May 26, 2026 at 5:07 am

    If regex is used with g flag, method string.match returns array only of matches, it doesn’t include captured groups. Method RegExp.exec returns array with the last match and captured groups in the last match, which is not a solution either.
    To achieve what you need in a comparatively simple way I suggest to look into the replacer function:

    <script type="text/javascript">
        var result = []
    
        //match - the match
        //group1, group2 and so on - are parameters that contain captured groups
        //number of parameters "group" should be exactly as the number of captured groups
        //offset - the index of the match
        //target - the target string itself
        function replacer(match, group1, group2, offset, target)
        {
            if (group1 != "")
            {
                //here group1, group2 should contain values of captured groups
                result.push(group1);
                result.push(group2);
            }
            //if we return the match 
            //the target string will not be modified
            return match;
        }
    
        var str = 'autocomplete=\\\"off\\\" name=\\\"composer_session_id\\\" value=\\\"1557423901\\\" \\\/>\\u003cinput type=\\\"hidden\\\" autocomplete=\\\"off\\\" name=\\\"is_explicit_place\\\" id=\\\"u436754_5\\\"';
        //"g" causes the replacer function 
        //to be called for each symbol of target string
        //that is why if (group1 != "") is needed above
        var regexp = /(composer_session_id|is_explicit_place)\\" (?:value|id)=\\"([_a-zA-Z0-9]+)\\"/g;
        str.replace(regexp, replacer);
        document.write(result);
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm struggling with some regex I've got a string like this: a:b||c:{d:e||f:g}||h:i basically
I got a string from parsing a XML file which looks like this: Fri,
I've got a class like this: [XmlRoot(channel)] public class Channel { [XmlElement(title)] public String
I've got this date time string: post[date] = 2007-07-18 10:03:19 I'd like to extract
i have a long string like $str = this is [my] test [string] and
If I have code like this: string s = MyClass.GetString(); // Returns string containing
I can read settings like this, for example: final String mytest = System.getString(this.getContentResolver(), System.AIRPLANE_MODE_ON);
I've got a string like foo (123) bar I want to retrieve all numbers
Say I've got a class where the sole data member is something like std::string
I've got a class with many string arrays. I'd like to have one generic

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.