Why does regex 1, with the error, produce the desired output, while regex 2 fails to capture the terminal "g" in the desired link-text and regex3 fails almost entirely?
This works because the error is irrelevant, and redundant, to what is captured.
Without it, the resultant regex / > ( (?: \s | \w )+ ) /mx still works exactly the same.
The only place in the string where '>' is immediately followed by a space (\s) or word (\w) character, starts at '>Moving'.
And the string of 1 or more space or word characters ends with the first '<'.
So the regex omits the 'g' which is followed by that string.
( \s | \w ) says 'capture either a single space, or a single word character', so it does.
The presence of the quantifier '+' outside the capturing parens does not change that.
In reply to Re: Why do these regex variants behave as they do?
by BrowserUk
in thread Why do these regex variants behave as they do?
by ww
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |