Reputation: 8990
I am porting some libraries from PHP to JavaScript and I came across this regular expression, some parts of it are unclear to me.
#(?: *+(?<= |^)\.((?:\([^)\n]++\)|\[[^\]\n]++\]|\{[^}\n]++\}|<>|>|=|<){1,4}?))#
Unclear parts are
*+
++
I know, that this expression should accept strings like
.(title)[class]{style}<>
.[class]{style}<>
.[class](title){style}
// and so one - no metter of order \(.+\), \[.+\] and \{.+\} parts
// and optional <>, >, = or < at the end
This expression is used with PCRE_UNGREEDY
modifier.
Upvotes: 26
Views: 18151
Reputation: 41934
++
From What is double plus in regular expressions?
That's a Possessive Quantifier.
It basically means that if the regex engine fails matching later, it will not go back and try to undo the matches it made here. In most cases, it allows the engine to fail much faster, and can give you some control where you need it - which is very rare for most uses.
*+
*+
is the possessive quantifier for the *
quantifier.
Upvotes: 29