Other Resources:
Possessive (non-backtracking) quantified subpatterns ++ *+ {}+
What is possessive (non-backtracking) quantified subpatterns?
How to write a possessive quantified subpattern to match double-quoted strings like this: "He said: \“Hello!\â€"?
✍: FYIcenter.com
![]()
If you don't want the default backtracking behavior of quantified subpatterns, you can turn it off by adding the "possessive" quantifier '+' immediately after the quantifier. This will force the quantified subpattern to repeat itself as many time as allowed.
In most case, possessive (non-backtracking) quantified subpatterns are used to improve match performance by avoiding unnecessary backtracking. For example,
<[^>]*+> # [^>]*+ is a possessive quantified subpattern
non-'>' character subpattern can be repeated safely
without any backtracking because the next subpattern is >
The regular expression to match double-quoted strings efficiently is:
"(?:[^"\]++|\.)*+"
(?:...) - non-capture grouping
[^"\]++ - repeat [^"\] 1 or more times without backtracking
\. - any character escaped by \
(...)*+ - repeat (...) 0 or more times without backtracking
2013-01-26, 0👍, 0💬
Popular Posts:
How to capture the Baidu spider entries from Web log file? Here are some Web log file entries: 127.0...
All credit card numbers issued by Diners Club must start with 300 through 305, 36 or 38 and have 14 ...
According to the IEEE 802 specification, a MAC address has 6 groups of 2 hexadecimal digits separate...
How to write a regular expression to validate GUID (Globally Unique IDentifier) or UUID (Universally...
All credit card numbers issued by Diners Club must start with 300 through 305, 36 or 38 and have 14 ...