The idea of lazy and greedy are easy to understand, but I have only seen/used *+
once in my regex (in Java) [A]|[^B]*+(?!C)
(A,B,C are arbitrary values) simply because it worked when the lazy modifier resulted in a StackOverflow error.
Because of most search engines' inability to search symbols, I can't find any documentation on this. So what exactly does *+ do and how does it do it?
A greedy quantifier matches everything it can and then the pattern backtracks until the match succeeds.
A lazy quantifier forward tracks until the match succeeds.
A possessive quantifier matches everything it can and never backtracks.
The +
denotes a possessive quantifier. If can be used as, for example, ++
or *+
.
This ability to prevent backtracking means it can stop catastrophic backtracking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With