Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does the *+ quantifier do?

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?

like image 493
Song Gao Avatar asked Dec 25 '22 23:12

Song Gao


1 Answers

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.

like image 70
Boris the Spider Avatar answered Dec 29 '22 04:12

Boris the Spider