I have this text:
start start word word word end
and this regex with flag gm:
start.*?end
In my understanding the lazy quantifier *? should limit the match to only:
start word word word end
However it still matches the whole string. However if the string is:
start word word word end end
Then it works correctly. Why is that?
From https://www.regular-expressions.info/engine.html:
There is a related "leftmost longest" rule, which not all regex engines use.
For example the POSIX Regular Expressions definition, under "matched" says:
In contrast, Perl tries alternations from left to right and chooses the first that matches: