The sample string is =aa=bb=cc=dd=.
I tried
string.match(/=(\w*)=/)
but that returns only aa.
How do I find aa, bb, cc and dd from the sample string?
The sample string is =aa=bb=cc=dd=.
I tried
string.match(/=(\w*)=/)
but that returns only aa.
How do I find aa, bb, cc and dd from the sample string?
This regex will match explicitly your requirements, and put the non, delimiter portion it the first capture group:
=([^=]+)(?==)
Unfortunately JavaScript regex does not have look behinds, otherwise this could be done in much easier fashion.
Here is some code:
var str = '=([^=]+)(?==)';
var re = /=([^=]+)(?==)/g,
ary = [],
match;
while (match = re.exec(str)) {
ary.push(match[1]);
}
console.log(ary);
(?==) capturing group for? Without it, it works fine too. Can you please post a string where this is important?nomatch in =a=b=nomatch,=c= would match. Just trying to be as exact as possible.(?= ... ) is a lookahead. It checks that the character coming just after is what is within the ... without consuming it, so that you don't get alternate results (i.e. aa, cc and missing bb, dd).var values = yourString.split('='); You'll get an array with all your required values.
this regex will capture all the non-equal characters in your string
=([^=]*)(?==)

Live example: http://www.rubular.com/r/vPW2GJqBWP
Sample Text
=aa=bb=cc=dd=
Matches
Capture group 1 will have the following
[0] => aa
[1] => bb
[2] => cc
[3] => dd