1175 |
.sp |
.sp |
1176 |
/(?|(abc)|(def))(?1)/ |
/(?|(abc)|(def))(?1)/ |
1177 |
.sp |
.sp |
1178 |
An alternative approach to using the "branch reset" feature is to use |
If a |
1179 |
|
.\" HTML <a href="#conditions"> |
1180 |
|
.\" </a> |
1181 |
|
condition test |
1182 |
|
.\" |
1183 |
|
for a subpattern's having matched refers to a non-unique number, the test is |
1184 |
|
true if any of the subpatterns of that number have matched. |
1185 |
|
.P |
1186 |
|
An alternative approach to using this "branch reset" feature is to use |
1187 |
duplicate named subpatterns, as described in the next section. |
duplicate named subpatterns, as described in the next section. |
1188 |
. |
. |
1189 |
. |
. |
1196 |
difficulty, PCRE supports the naming of subpatterns. This feature was not |
difficulty, PCRE supports the naming of subpatterns. This feature was not |
1197 |
added to Perl until release 5.10. Python had the feature earlier, and PCRE |
added to Perl until release 5.10. Python had the feature earlier, and PCRE |
1198 |
introduced it at release 4.0, using the Python syntax. PCRE now supports both |
introduced it at release 4.0, using the Python syntax. PCRE now supports both |
1199 |
the Perl and the Python syntax. |
the Perl and the Python syntax. Perl allows identically numbered subpatterns to |
1200 |
|
have different names, but PCRE does not. |
1201 |
.P |
.P |
1202 |
In PCRE, a subpattern can be named in one of three ways: (?<name>...) or |
In PCRE, a subpattern can be named in one of three ways: (?<name>...) or |
1203 |
(?'name'...) as in Perl, or (?P<name>...) as in Python. References to capturing |
(?'name'...) as in Perl, or (?P<name>...) as in Python. References to capturing |
1244 |
.P |
.P |
1245 |
The convenience function for extracting the data by name returns the substring |
The convenience function for extracting the data by name returns the substring |
1246 |
for the first (and in this example, the only) subpattern of that name that |
for the first (and in this example, the only) subpattern of that name that |
1247 |
matched. This saves searching to find which numbered subpattern it was. If you |
matched. This saves searching to find which numbered subpattern it was. |
1248 |
make a reference to a non-unique named subpattern from elsewhere in the |
.P |
1249 |
pattern, the one that corresponds to the lowest number is used. For further |
If you make a backreference to a non-unique named subpattern from elsewhere in |
1250 |
details of the interfaces for handling named subpatterns, see the |
the pattern, the one that corresponds to the first occurrence of the name is |
1251 |
|
used. In the absence of duplicate numbers (see the previous section) this is |
1252 |
|
the one with the lowest number. If you use a named reference in a condition |
1253 |
|
test (see the |
1254 |
|
.\" |
1255 |
|
.\" HTML <a href="#conditions"> |
1256 |
|
.\" </a> |
1257 |
|
section about conditions |
1258 |
|
.\" |
1259 |
|
below), either to check whether a subpattern has matched, or to check for |
1260 |
|
recursion, all subpatterns with the same name are tested. If the condition is |
1261 |
|
true for any one of them, the overall condition is true. This is the same |
1262 |
|
behaviour as testing by number. For further details of the interfaces for |
1263 |
|
handling named subpatterns, see the |
1264 |
.\" HREF |
.\" HREF |
1265 |
\fBpcreapi\fP |
\fBpcreapi\fP |
1266 |
.\" |
.\" |
1899 |
.sp |
.sp |
1900 |
(?<OPEN> \e( )? [^()]+ (?(<OPEN>) \e) ) |
(?<OPEN> \e( )? [^()]+ (?(<OPEN>) \e) ) |
1901 |
.sp |
.sp |
1902 |
|
If the name used in a condition of this kind is a duplicate, the test is |
1903 |
|
applied to all subpatterns of the same name, and is true if any one of them has |
1904 |
|
matched. |
1905 |
. |
. |
1906 |
.SS "Checking for pattern recursion" |
.SS "Checking for pattern recursion" |
1907 |
.rs |
.rs |
1915 |
.sp |
.sp |
1916 |
the condition is true if the most recent recursion is into a subpattern whose |
the condition is true if the most recent recursion is into a subpattern whose |
1917 |
number or name is given. This condition does not check the entire recursion |
number or name is given. This condition does not check the entire recursion |
1918 |
stack. |
stack. If the name used in a condition of this kind is a duplicate, the test is |
1919 |
|
applied to all subpatterns of the same name, and is true if any one of them is |
1920 |
|
the most recent recursion. |
1921 |
.P |
.P |
1922 |
At "top level", all these recursion test conditions are false. |
At "top level", all these recursion test conditions are false. |
1923 |
.\" HTML <a href="#recursion"> |
.\" HTML <a href="#recursion"> |
1924 |
.\" </a> |
.\" </a> |
1925 |
Recursive patterns |
The syntax for recursive patterns |
1926 |
.\" |
.\" |
1927 |
are described below. |
is described below. |
1928 |
. |
. |
1929 |
.SS "Defining subpatterns for use by reference only" |
.SS "Defining subpatterns for use by reference only" |
1930 |
.rs |
.rs |
2418 |
.rs |
.rs |
2419 |
.sp |
.sp |
2420 |
.nf |
.nf |
2421 |
Last updated: 03 October 2009 |
Last updated: 04 October 2009 |
2422 |
Copyright (c) 1997-2009 University of Cambridge. |
Copyright (c) 1997-2009 University of Cambridge. |
2423 |
.fi |
.fi |