I am trying to understand how can I get 2 captured groups with regex(JS), from the following string:
"Group: i_am_group |SubGroup: i_am_sub_group"
I want to get in the end:
group1: i_am_group and
the rules are-
Extract the first word after "Group: " into group1 Extract the first word after "SubGroup: " into group2
I need to implement those two rules with regex so I can run it with
I was trying to do the following:
and the result was:
Thanks in advance.
| has special meaning in regular expressions, it’s used to specify alternatives. You need to escape it to match it literally.
There’s no need to use lookbehinds when you’re capturing the part after that. The purpose of lookarounds is to keep them out of the matched string, but if you’re only interested in the capture groups this is irrelevant.
This regexp should work for you:
Answered By – Barmar
Answer Checked By – Willingham (BugsFixing Volunteer)