in reply to Why do these regex variants behave as they do?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why do these regex variants behave as they do?
by AnomalousMonk (Archbishop) on Oct 02, 2011 at 20:34 UTC | |
|
Re^2: Why do these regex variants behave as they do?
by ww (Archbishop) on Oct 02, 2011 at 22:05 UTC | |
by AnomalousMonk (Archbishop) on Oct 03, 2011 at 01:23 UTC |