| 168 |
After \ex, from zero to two hexadecimal digits are read (letters can be in |
After \ex, from zero to two hexadecimal digits are read (letters can be in |
| 169 |
upper or lower case). Any number of hexadecimal digits may appear between \ex{ |
upper or lower case). Any number of hexadecimal digits may appear between \ex{ |
| 170 |
and }, but the value of the character code must be less than 256 in non-UTF-8 |
and }, but the value of the character code must be less than 256 in non-UTF-8 |
| 171 |
mode, and less than 2**31 in UTF-8 mode (that is, the maximum hexadecimal value |
mode, and less than 2**31 in UTF-8 mode. That is, the maximum value in |
| 172 |
is 7FFFFFFF). If characters other than hexadecimal digits appear between \ex{ |
hexadecimal is 7FFFFFFF. Note that this is bigger than the largest Unicode code |
| 173 |
and }, or if there is no terminating }, this form of escape is not recognized. |
point, which is 10FFFF. |
| 174 |
Instead, the initial \ex will be interpreted as a basic hexadecimal escape, |
.P |
| 175 |
with no following digits, giving a character whose value is zero. |
If characters other than hexadecimal digits appear between \ex{ and }, or if |
| 176 |
|
there is no terminating }, this form of escape is not recognized. Instead, the |
| 177 |
|
initial \ex will be interpreted as a basic hexadecimal escape, with no |
| 178 |
|
following digits, giving a character whose value is zero. |
| 179 |
.P |
.P |
| 180 |
Characters whose value is less than 256 can be defined by either of the two |
Characters whose value is less than 256 can be defined by either of the two |
| 181 |
syntaxes for \ex. There is no difference in the way they are handled. For |
syntaxes for \ex. There is no difference in the way they are handled. For |
| 538 |
the Lu, Ll, or Lt property, in other words, a letter that is not classified as |
the Lu, Ll, or Lt property, in other words, a letter that is not classified as |
| 539 |
a modifier or "other". |
a modifier or "other". |
| 540 |
.P |
.P |
| 541 |
|
The Cs (Surrogate) property applies only to characters in the range U+D800 to |
| 542 |
|
U+DFFF. Such characters are not valid in UTF-8 strings (see RFC 3629) and so |
| 543 |
|
cannot be tested by PCRE, unless UTF-8 validity checking has been turned off |
| 544 |
|
(see the discussion of PCRE_NO_UTF8_CHECK in the |
| 545 |
|
.\" HREF |
| 546 |
|
\fBpcreapi\fP |
| 547 |
|
.\" |
| 548 |
|
page). |
| 549 |
|
.P |
| 550 |
The long synonyms for these properties that Perl supports (such as \ep{Letter}) |
The long synonyms for these properties that Perl supports (such as \ep{Letter}) |
| 551 |
are not supported by PCRE, nor is it permitted to prefix any of these |
are not supported by PCRE, nor is it permitted to prefix any of these |
| 552 |
properties with "Is". |
properties with "Is". |
| 1981 |
.SH "BACTRACKING CONTROL" |
.SH "BACTRACKING CONTROL" |
| 1982 |
.rs |
.rs |
| 1983 |
.sp |
.sp |
| 1984 |
Perl 5.10 introduced a number of "Special Backtracking Control Verbs", which |
Perl 5.10 introduced a number of "Special Backtracking Control Verbs", which |
| 1985 |
are described in the Perl documentation as "experimental and subject to change |
are described in the Perl documentation as "experimental and subject to change |
| 1986 |
or removal in a future version of Perl". It goes on to say: "Their usage in |
or removal in a future version of Perl". It goes on to say: "Their usage in |
| 1987 |
production code should be noted to avoid problems during upgrades." The same |
production code should be noted to avoid problems during upgrades." The same |
| 1988 |
remarks apply to the PCRE features described in this section. |
remarks apply to the PCRE features described in this section. |
| 1989 |
.P |
.P |
| 1990 |
Since these verbs are specifically related to backtracking, they can be used |
Since these verbs are specifically related to backtracking, they can be used |
| 1991 |
only when the pattern is to be matched using \fBpcre_exec()\fP, which uses a |
only when the pattern is to be matched using \fBpcre_exec()\fP, which uses a |
| 1992 |
backtracking algorithm. They cause an error if encountered by |
backtracking algorithm. They cause an error if encountered by |
| 1993 |
\fBpcre_dfa_exec()\fP. |
\fBpcre_dfa_exec()\fP. |
| 1994 |
.P |
.P |
| 1995 |
The new verbs make use of what was previously invalid syntax: an opening |
The new verbs make use of what was previously invalid syntax: an opening |
| 1996 |
parenthesis followed by an asterisk. In Perl, they are generally of the form |
parenthesis followed by an asterisk. In Perl, they are generally of the form |
| 1997 |
(*VERB:ARG) but PCRE does not support the use of arguments, so its general |
(*VERB:ARG) but PCRE does not support the use of arguments, so its general |
| 1998 |
form is just (*VERB). Any number of these verbs may occur in a pattern. There |
form is just (*VERB). Any number of these verbs may occur in a pattern. There |
| 2006 |
(*ACCEPT) |
(*ACCEPT) |
| 2007 |
.sp |
.sp |
| 2008 |
This verb causes the match to end successfully, skipping the remainder of the |
This verb causes the match to end successfully, skipping the remainder of the |
| 2009 |
pattern. When inside a recursion, only the innermost pattern is ended |
pattern. When inside a recursion, only the innermost pattern is ended |
| 2010 |
immediately. PCRE differs from Perl in what happens if the (*ACCEPT) is inside |
immediately. PCRE differs from Perl in what happens if the (*ACCEPT) is inside |
| 2011 |
capturing parentheses. In Perl, the data so far is captured: in PCRE no data is |
capturing parentheses. In Perl, the data so far is captured: in PCRE no data is |
| 2012 |
captured. For example: |
captured. For example: |
| 2013 |
.sp |
.sp |
| 2014 |
A(A|B(*ACCEPT)|C)D |
A(A|B(*ACCEPT)|C)D |
| 2015 |
.sp |
.sp |
| 2016 |
This matches "AB", "AAD", or "ACD", but when it matches "AB", no data is |
This matches "AB", "AAD", or "ACD", but when it matches "AB", no data is |
| 2017 |
captured. |
captured. |
| 2018 |
.sp |
.sp |
| 2019 |
(*FAIL) or (*F) |
(*FAIL) or (*F) |
| 2020 |
.sp |
.sp |
| 2021 |
This verb causes the match to fail, forcing backtracking to occur. It is |
This verb causes the match to fail, forcing backtracking to occur. It is |
| 2022 |
equivalent to (?!) but easier to read. The Perl documentation notes that it is |
equivalent to (?!) but easier to read. The Perl documentation notes that it is |
| 2023 |
probably useful only when combined with (?{}) or (??{}). Those are, of course, |
probably useful only when combined with (?{}) or (??{}). Those are, of course, |
| 2024 |
Perl features that are not present in PCRE. The nearest equivalent is the |
Perl features that are not present in PCRE. The nearest equivalent is the |
| 2026 |
.sp |
.sp |
| 2027 |
a+(?C)(*FAIL) |
a+(?C)(*FAIL) |
| 2028 |
.sp |
.sp |
| 2029 |
A match with the string "aaaa" always fails, but the callout is taken before |
A match with the string "aaaa" always fails, but the callout is taken before |
| 2030 |
each backtrack happens (in this example, 10 times). |
each backtrack happens (in this example, 10 times). |
| 2031 |
. |
. |
| 2032 |
.SS "Verbs that act after backtracking" |
.SS "Verbs that act after backtracking" |
| 2033 |
.rs |
.rs |
| 2034 |
.sp |
.sp |
| 2035 |
The following verbs do nothing when they are encountered. Matching continues |
The following verbs do nothing when they are encountered. Matching continues |
| 2036 |
with what follows, but if there is no subsequent match, a failure is forced. |
with what follows, but if there is no subsequent match, a failure is forced. |
| 2037 |
The verbs differ in exactly what kind of failure occurs. |
The verbs differ in exactly what kind of failure occurs. |
| 2038 |
.sp |
.sp |
| 2039 |
(*COMMIT) |
(*COMMIT) |
| 2040 |
.sp |
.sp |
| 2041 |
This verb causes the whole match to fail outright if the rest of the pattern |
This verb causes the whole match to fail outright if the rest of the pattern |
| 2042 |
does not match. Even if the pattern is unanchored, no further attempts to find |
does not match. Even if the pattern is unanchored, no further attempts to find |
| 2043 |
a match by advancing the start point take place. Once (*COMMIT) has been |
a match by advancing the start point take place. Once (*COMMIT) has been |
| 2044 |
passed, \fBpcre_exec()\fP is committed to finding a match at the current |
passed, \fBpcre_exec()\fP is committed to finding a match at the current |
| 2045 |
starting point, or not at all. For example: |
starting point, or not at all. For example: |
| 2046 |
.sp |
.sp |
| 2047 |
a+(*COMMIT)b |
a+(*COMMIT)b |
| 2048 |
.sp |
.sp |
| 2049 |
This matches "xxaab" but not "aacaab". It can be thought of as a kind of |
This matches "xxaab" but not "aacaab". It can be thought of as a kind of |
| 2050 |
dynamic anchor, or "I've started, so I must finish." |
dynamic anchor, or "I've started, so I must finish." |
| 2051 |
.sp |
.sp |
| 2052 |
(*PRUNE) |
(*PRUNE) |
| 2053 |
.sp |
.sp |
| 2054 |
This verb causes the match to fail at the current position if the rest of the |
This verb causes the match to fail at the current position if the rest of the |
| 2055 |
pattern does not match. If the pattern is unanchored, the normal "bumpalong" |
pattern does not match. If the pattern is unanchored, the normal "bumpalong" |
| 2056 |
advance to the next starting character then happens. Backtracking can occur as |
advance to the next starting character then happens. Backtracking can occur as |
| 2057 |
usual to the left of (*PRUNE), or when matching to the right of (*PRUNE), but |
usual to the left of (*PRUNE), or when matching to the right of (*PRUNE), but |
| 2058 |
if there is no match to the right, backtracking cannot cross (*PRUNE). |
if there is no match to the right, backtracking cannot cross (*PRUNE). |
| 2059 |
In simple cases, the use of (*PRUNE) is just an alternative to an atomic |
In simple cases, the use of (*PRUNE) is just an alternative to an atomic |
| 2060 |
group or possessive quantifier, but there are some uses of (*PRUNE) that cannot |
group or possessive quantifier, but there are some uses of (*PRUNE) that cannot |
| 2061 |
be expressed in any other way. |
be expressed in any other way. |
| 2062 |
.sp |
.sp |
| 2063 |
(*SKIP) |
(*SKIP) |
| 2064 |
.sp |
.sp |
| 2065 |
This verb is like (*PRUNE), except that if the pattern is unanchored, the |
This verb is like (*PRUNE), except that if the pattern is unanchored, the |
| 2066 |
"bumpalong" advance is not to the next character, but to the position in the |
"bumpalong" advance is not to the next character, but to the position in the |
| 2067 |
subject where (*SKIP) was encountered. (*SKIP) signifies that whatever text |
subject where (*SKIP) was encountered. (*SKIP) signifies that whatever text |
| 2068 |
was matched leading up to it cannot be part of a successful match. Consider: |
was matched leading up to it cannot be part of a successful match. Consider: |
| 2069 |
.sp |
.sp |
| 2070 |
a+(*SKIP)b |
a+(*SKIP)b |
| 2071 |
.sp |
.sp |
| 2072 |
If the subject is "aaaac...", after the first match attempt fails (starting at |
If the subject is "aaaac...", after the first match attempt fails (starting at |
| 2073 |
the first character in the string), the starting point skips on to start the |
the first character in the string), the starting point skips on to start the |
| 2074 |
next attempt at "c". Note that a possessive quantifer does not have the same |
next attempt at "c". Note that a possessive quantifer does not have the same |
| 2075 |
effect in this example; although it would suppress backtracking during the |
effect in this example; although it would suppress backtracking during the |
| 2076 |
first match attempt, the second attempt would start at the second character |
first match attempt, the second attempt would start at the second character |
| 2077 |
instead of skipping on to "c". |
instead of skipping on to "c". |
| 2078 |
.sp |
.sp |
| 2079 |
(*THEN) |
(*THEN) |
| 2080 |
.sp |
.sp |
| 2081 |
This verb causes a skip to the next alternation if the rest of the pattern does |
This verb causes a skip to the next alternation if the rest of the pattern does |
| 2082 |
not match. That is, it cancels pending backtracking, but only within the |
not match. That is, it cancels pending backtracking, but only within the |
| 2083 |
current alternation. Its name comes from the observation that it can be used |
current alternation. Its name comes from the observation that it can be used |
| 2085 |
.sp |
.sp |
| 2086 |
( COND1 (*THEN) FOO | COND2 (*THEN) BAR | COND3 (*THEN) BAZ ) ... |
( COND1 (*THEN) FOO | COND2 (*THEN) BAR | COND3 (*THEN) BAZ ) ... |
| 2087 |
.sp |
.sp |
| 2088 |
If the COND1 pattern matches, FOO is tried (and possibly further items after |
If the COND1 pattern matches, FOO is tried (and possibly further items after |
| 2089 |
the end of the group if FOO succeeds); on failure the matcher skips to the |
the end of the group if FOO succeeds); on failure the matcher skips to the |
| 2090 |
second alternative and tries COND2, without backtracking into COND1. If (*THEN) |
second alternative and tries COND2, without backtracking into COND1. If (*THEN) |
| 2091 |
is used outside of any alternation, it acts exactly like (*PRUNE). |
is used outside of any alternation, it acts exactly like (*PRUNE). |
| 2092 |
. |
. |
| 2093 |
. |
. |
| 2111 |
.rs |
.rs |
| 2112 |
.sp |
.sp |
| 2113 |
.nf |
.nf |
| 2114 |
Last updated: 08 August 2007 |
Last updated: 09 August 2007 |
| 2115 |
Copyright (c) 1997-2007 University of Cambridge. |
Copyright (c) 1997-2007 University of Cambridge. |
| 2116 |
.fi |
.fi |