Possesive Quantifiers
Possessive quantifiers prevent a regular expression engine from trying all versions of a regex pattern, which can be useful for performance reasons. You can also use possessive quantifiers to eliminate certain matches.
A possessive quantifier is like a greedy quantifier because it will repeat the token as many times as possible, however, it will not give up matches as the engine backtracks. Adding a + makes a quantifier possessive.
The following table lists the possessive quantifiers:
Value | Definition |
---|---|
*+ | Matches the previous element zero or more times, possessive |
++ | Matches the previous element one or more times, possessive |
?+ | Matches the previous element zero or one time, possessive |
{n,m}+ | Matches the previous element at least n times, but no more than m times, possessive |
Supported by:
Java, PCRE