++
(and ?+
, *+
and {n,m}+
) are called possessive quantifiers .
Both [0-9]+
and [0-9]++
correspond to one or more ASCII digits, but the second does not allow the regular expression mechanism to return to correspondence if it is necessary for the successful execution of the general regular expression.
Example:
[0-9]+0
matches string 00
, while [0-9]++0
does not match.
In the first case, [0-9]+
first matches 00
, but then returns one character to resolve the next 0
. In the second case, ++
prevents this, so a complete match is not performed.
Not all regular expression flavors support this syntax; some others instead realize atomic groups (or even both).
Tim pietzcker
source share