1515 |
.sp |
.sp |
1516 |
If the text between the parentheses consists of a sequence of digits, the |
If the text between the parentheses consists of a sequence of digits, the |
1517 |
condition is true if the capturing subpattern of that number has previously |
condition is true if the capturing subpattern of that number has previously |
1518 |
matched. |
matched. An alternative notation is to precede the digits with a plus or minus |
1519 |
|
sign. In this case, the subpattern number is relative rather than absolute. |
1520 |
|
The most recently opened parentheses can be referenced by (?(-1), the next most |
1521 |
|
recent by (?(-2), and so on. In looping constructs it can also make sense to |
1522 |
|
refer to subsequent groups with constructs such as (?(+2). |
1523 |
.P |
.P |
1524 |
Consider the following pattern, which contains non-significant white space to |
Consider the following pattern, which contains non-significant white space to |
1525 |
make it more readable (assume the PCRE_EXTENDED option) and to divide it into |
make it more readable (assume the PCRE_EXTENDED option) and to divide it into |
1536 |
parenthesis is required. Otherwise, since no-pattern is not present, the |
parenthesis is required. Otherwise, since no-pattern is not present, the |
1537 |
subpattern matches nothing. In other words, this pattern matches a sequence of |
subpattern matches nothing. In other words, this pattern matches a sequence of |
1538 |
non-parentheses, optionally enclosed in parentheses. |
non-parentheses, optionally enclosed in parentheses. |
1539 |
|
.P |
1540 |
|
If you were embedding this pattern in a larger one, you could use a relative |
1541 |
|
reference: |
1542 |
|
.sp |
1543 |
|
...other stuff... ( \e( )? [^()]+ (?(-1) \e) ) ... |
1544 |
|
.sp |
1545 |
|
This makes the fragment independent of the parentheses in the larger pattern. |
1546 |
. |
. |
1547 |
.SS "Checking for a used subpattern by name" |
.SS "Checking for a used subpattern by name" |
1548 |
.rs |
.rs |
1853 |
.rs |
.rs |
1854 |
.sp |
.sp |
1855 |
.nf |
.nf |
1856 |
Last updated: 06 March 2007 |
Last updated: 09 May 2007 |
1857 |
Copyright (c) 1997-2007 University of Cambridge. |
Copyright (c) 1997-2007 University of Cambridge. |
1858 |
.fi |
.fi |