Regexp: (?=(\d+))\w+\1
String: 456x56
Hi,
I am not getting the concept, how this regex matches “56×56” in the string “456×56”.
- The lookaround, (?=(\d+)), captures 456 and put into \1, for (\d+)
- The wordcharacter, \w+, matches the whole string(“456×56”)
- \1, which is 456, should be followed by \w+
- After backtracking the string, it should not find a match, as there is no “456” preceded by a word character
However the regexp matches 56×56.
You don’t anchor your regex, as has been said. Another problem is that
\walso matches digits… Now look at how the regex engine proceeds to match with your input: