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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:37:07+00:00 2026-06-09T08:37:07+00:00

I’m fairly sure after spending the night trying to find an answer that this

  • 0

I’m fairly sure after spending the night trying to find an answer that this isn’t possible, and I’ve developed a work around – but, if someone knows of a better method, I would love to hear it…

I’ve gone through a lot of iterations on the code, and the following is just a line of thought really. At some point I was using the global flag, I believe, in order for match() to work, and I can’t remember if it was necessary now or not.

var str = "@abc@def@ghi&jkl";
var regex = /^(?:@([a-z]+))?(?:&([a-z]+))?$/;

The idea here, in this simplified code, is the optional group 1, of which there is an unspecified amount, will match @abc, @def and @ghi. It will only capture the alpha characters of which there will be one or more. Group 2 is the same, except matches on & symbol. It should also be anchored to the start and end of the string.

I want to be able to back reference all matches of both groups, ie:

result = str.match(regex);
alert(result[1]); //abc,def,ghi
alert(result[1][0]); //abc
alert(result[1][1]); //def
alert(result[1][2]); //ghi
alert(result[2]); //jkl

My mate says this works fine for him in .net, unfortunately I simply can’t get it to work – only the last matched of any group is returned in the back reference, as can be seen in the following:

(additionally, making either group optional makes a mess, as does setting global flag)

var str = "@abc@def@ghi&jkl";
var regex = /(?:@([a-z]+))(?:&([a-z]+))/;

var result = str.match(regex);

alert(result[1]); //ghi
alert(result[1][0]); //g
alert(result[2]); //jkl

The following is the solution I arrived at, capturing the whole portion in question, and creating the array myself:

var str = "@abc@def@ghi&jkl";
var regex = /^([@a-z]+)?(?:&([a-z]+))?$/;

var result = regex.exec(str);

alert(result[1]); //@abc@def@ghi
alert(result[2]); //jkl

var result1 = result[1].toString();
result[1] = result1.split('@')

alert(result[1][1]); //abc
alert(result[1][2]); //def
alert(result[1][3]); //ghi
alert(result[2]); //jkl
  • 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-09T08:37:08+00:00Added an answer on June 9, 2026 at 8:37 am

    That’s simply not how .match() works in JavaScript. The returned array is an array of simple strings. There’s no “nesting” of capture groups; you just count the ( symbols from left to right.

    The first string (at index [0]) is always the overall matched string. Then come the capture groups, one string (or null) per array element.

    You can, as you’ve done, rearrange the result array to your heart’s content. It’s just an array.

    edit — oh, and the reason your result[1][0] was “g” is that array indexing notation applied to a string gets you the individual characters of the string.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.