How does ^(x*)(.+)- \2= \1$ match xxx - xx = x. I am not understanding how the captured group2 is "xx" and how captured group 1 is "x". Shouldn't group1 be "xxx" since (x*) is asking for "x" 0 or more times which means it should cover all the x's up until the first space, right? I also am not understanding where group2 is getting its x's from since that group starts after (x*) and before "-" which means it should start at the first space after "xxx" and end right before "-"? I need help understanding this. Can someone break it down for me please.
Asked
Active
Viewed 6 times
0
-
in a word: backtracking – Patrick Parker May 30 '21 at 05:27
-
i find this site helps a lot to explain regular expressions regex101.com – AndersK May 30 '21 at 05:37
-
1Does this answer your question? [Which regular expression requires backtracking?](https://stackoverflow.com/questions/8132412/which-regular-expression-requires-backtracking) – Patrick Parker May 30 '21 at 05:38
-
After you understand how backtracking works, you might want to read about [Atomic Grouping](https://stackoverflow.com/q/14411818/8967612). – 41686d6564 May 30 '21 at 05:43