Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emulating possessive quantifiers

Is it possible to emulate possessive quantifiers (.NET doesn’t support it) using atomic grouping (or in other way)?

Note. I found that (x+x+)++y can be replaced with (?>(x+x+)+)y, but this is just an example and I don’t know whether always {something}@+ equals to (?>{something}@) (where @ is a quantifier).

like image 422
LukeSw Avatar asked Apr 04 '11 10:04

LukeSw


People also ask

What are possessive quantifiers?

A possessive quantifier is similar to greedy quantifier. It indicates the engine to start by checking the entire string.It is different in the sense if it doesn't work, if match failed and there is no looking back. Following are various examples of Possessive Quantifiers using regular expression in java.

What is quantifier in regex?

Quantifiers specify how many instances of a character, group, or character class must be present in the input for a match to be found.


1 Answers

Yup. May I quote the master himself, Jeffrey Friedl, from page 142 of his classic Mastering Regular Expressions (3rd Edition):

"In one sense, possessive quantifiers are just syntactic sugar, as they can be mimicked with atomic grouping. Something like .++ has exactly the same result as (?>.+), although a smart implementation can optimize possessive quantifiers more than atomic grouping."

like image 96
ridgerunner Avatar answered Oct 11 '22 13:10

ridgerunner