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().
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: