30 |
PCRE when its main matching function, \fBpcre_exec()\fP, is used. |
PCRE when its main matching function, \fBpcre_exec()\fP, is used. |
31 |
From release 6.0, PCRE offers a second matching function, |
From release 6.0, PCRE offers a second matching function, |
32 |
\fBpcre_dfa_exec()\fP, which matches using a different algorithm that is not |
\fBpcre_dfa_exec()\fP, which matches using a different algorithm that is not |
33 |
Perl-compatible. Some of the features discussed below are not available when |
Perl-compatible. Some of the features discussed below are not available when |
34 |
\fBpcre_dfa_exec()\fP is used. The advantages and disadvantages of the |
\fBpcre_dfa_exec()\fP is used. The advantages and disadvantages of the |
35 |
alternative function, and how it differs from the normal function, are |
alternative function, and how it differs from the normal function, are |
36 |
discussed in the |
discussed in the |
241 |
.rs |
.rs |
242 |
.sp |
.sp |
243 |
The sequence \eg followed by a positive or negative number, optionally enclosed |
The sequence \eg followed by a positive or negative number, optionally enclosed |
244 |
in braces, is an absolute or relative back reference. A named back reference |
in braces, is an absolute or relative back reference. A named back reference |
245 |
can be coded as \eg{name}. Back references are discussed |
can be coded as \eg{name}. Back references are discussed |
246 |
.\" HTML <a href="#backreferences"> |
.\" HTML <a href="#backreferences"> |
247 |
.\" </a> |
.\" </a> |
525 |
.SS "Resetting the match start" |
.SS "Resetting the match start" |
526 |
.rs |
.rs |
527 |
.sp |
.sp |
528 |
The escape sequence \eK, which is a Perl 5.10 feature, causes any previously |
The escape sequence \eK, which is a Perl 5.10 feature, causes any previously |
529 |
matched characters not to be included in the final matched sequence. For |
matched characters not to be included in the final matched sequence. For |
530 |
example, the pattern: |
example, the pattern: |
531 |
.sp |
.sp |
532 |
foo\eKbar |
foo\eKbar |
533 |
.sp |
.sp |
534 |
matches "foobar", but reports that it has matched "bar". This feature is |
matches "foobar", but reports that it has matched "bar". This feature is |
535 |
similar to a lookbehind assertion |
similar to a lookbehind assertion |
536 |
.\" HTML <a href="#lookbehind"> |
.\" HTML <a href="#lookbehind"> |
537 |
.\" </a> |
.\" </a> |
538 |
(described below). |
(described below). |
539 |
.\" |
.\" |
540 |
However, in this case, the part of the subject before the real match does not |
However, in this case, the part of the subject before the real match does not |
541 |
have to be of fixed length, as lookbehind assertions do. The use of \eK does |
have to be of fixed length, as lookbehind assertions do. The use of \eK does |
542 |
not interfere with the setting of |
not interfere with the setting of |
543 |
.\" HTML <a href="#subpattern"> |
.\" HTML <a href="#subpattern"> |
544 |
.\" </a> |
.\" </a> |
545 |
captured substrings. |
captured substrings. |
546 |
.\" |
.\" |
547 |
For example, when the pattern |
For example, when the pattern |
548 |
.sp |
.sp |
549 |
(foo)\eKbar |
(foo)\eKbar |
550 |
.sp |
.sp |
551 |
matches "foobar", the first substring is still set to "foo". |
matches "foobar", the first substring is still set to "foo". |
552 |
. |
. |
553 |
. |
. |
554 |
.\" HTML <a name="smallassertions"></a> |
.\" HTML <a name="smallassertions"></a> |
1458 |
.sp |
.sp |
1459 |
(?<=abc|abde) |
(?<=abc|abde) |
1460 |
.sp |
.sp |
1461 |
In some cases, the Perl 5.10 escape sequence \eK |
In some cases, the Perl 5.10 escape sequence \eK |
1462 |
.\" HTML <a href="#resetmatchstart"> |
.\" HTML <a href="#resetmatchstart"> |
1463 |
.\" </a> |
.\" </a> |
1464 |
(see above) |
(see above) |
1560 |
.sp |
.sp |
1561 |
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 |
1562 |
condition is true if the capturing subpattern of that number has previously |
condition is true if the capturing subpattern of that number has previously |
1563 |
matched. An alternative notation is to precede the digits with a plus or minus |
matched. An alternative notation is to precede the digits with a plus or minus |
1564 |
sign. In this case, the subpattern number is relative rather than absolute. |
sign. In this case, the subpattern number is relative rather than absolute. |
1565 |
The most recently opened parentheses can be referenced by (?(-1), the next most |
The most recently opened parentheses can be referenced by (?(-1), the next most |
1566 |
recent by (?(-2), and so on. In looping constructs it can also make sense to |
recent by (?(-2), and so on. In looping constructs it can also make sense to |
1567 |
refer to subsequent groups with constructs such as (?(+2). |
refer to subsequent groups with constructs such as (?(+2). |
1568 |
.P |
.P |
1582 |
subpattern matches nothing. In other words, this pattern matches a sequence of |
subpattern matches nothing. In other words, this pattern matches a sequence of |
1583 |
non-parentheses, optionally enclosed in parentheses. |
non-parentheses, optionally enclosed in parentheses. |
1584 |
.P |
.P |
1585 |
If you were embedding this pattern in a larger one, you could use a relative |
If you were embedding this pattern in a larger one, you could use a relative |
1586 |
reference: |
reference: |
1587 |
.sp |
.sp |
1588 |
...other stuff... ( \e( )? [^()]+ (?(-1) \e) ) ... |
...other stuff... ( \e( )? [^()]+ (?(-1) \e) ) ... |
1730 |
( \e( ( (?>[^()]+) | (?1) )* \e) ) |
( \e( ( (?>[^()]+) | (?1) )* \e) ) |
1731 |
.sp |
.sp |
1732 |
We have put the pattern into parentheses, and caused the recursion to refer to |
We have put the pattern into parentheses, and caused the recursion to refer to |
1733 |
them instead of the whole pattern. |
them instead of the whole pattern. |
1734 |
.P |
.P |
1735 |
In a larger pattern, keeping track of parenthesis numbers can be tricky. This |
In a larger pattern, keeping track of parenthesis numbers can be tricky. This |
1736 |
is made easier by the use of relative references. (A Perl 5.10 feature.) |
is made easier by the use of relative references. (A Perl 5.10 feature.) |
1751 |
(?<pn> \e( ( (?>[^()]+) | (?&pn) )* \e) ) |
(?<pn> \e( ( (?>[^()]+) | (?&pn) )* \e) ) |
1752 |
.sp |
.sp |
1753 |
If there is more than one subpattern with the same name, the earliest one is |
If there is more than one subpattern with the same name, the earliest one is |
1754 |
used. |
used. |
1755 |
.P |
.P |
1756 |
This particular example pattern that we have been looking at contains nested |
This particular example pattern that we have been looking at contains nested |
1757 |
unlimited repeats, and so the use of atomic grouping for matching strings of |
unlimited repeats, and so the use of atomic grouping for matching strings of |
1813 |
.sp |
.sp |
1814 |
(...(absolute)...)...(?2)... |
(...(absolute)...)...(?2)... |
1815 |
(...(relative)...)...(?-1)... |
(...(relative)...)...(?-1)... |
1816 |
(...(?+1)...(relative)... |
(...(?+1)...(relative)... |
1817 |
.sp |
.sp |
1818 |
An earlier example pointed out that the pattern |
An earlier example pointed out that the pattern |
1819 |
.sp |
.sp |