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. The advantages and disadvantages of the alternative function, |
Perl-compatible. Some of the features discussed below are not available when |
34 |
and how it differs from the normal function, are discussed in 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 |
36 |
|
discussed in the |
37 |
.\" HREF |
.\" HREF |
38 |
\fBpcrematching\fP |
\fBpcrematching\fP |
39 |
.\" |
.\" |
521 |
properties in PCRE. |
properties in PCRE. |
522 |
. |
. |
523 |
. |
. |
524 |
|
.\" HTML <a name="resetmatchstart"></a> |
525 |
|
.SS "Resetting the match start" |
526 |
|
.rs |
527 |
|
.sp |
528 |
|
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 |
530 |
|
example, the pattern: |
531 |
|
.sp |
532 |
|
foo\eKbar |
533 |
|
.sp |
534 |
|
matches "foobar", but reports that it has matched "bar". This feature is |
535 |
|
similar to a lookbehind assertion |
536 |
|
.\" HTML <a href="#lookbehind"> |
537 |
|
.\" </a> |
538 |
|
(described below). |
539 |
|
.\" |
540 |
|
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 |
542 |
|
not interfere with the setting of |
543 |
|
.\" HTML <a href="#subpattern"> |
544 |
|
.\" </a> |
545 |
|
captured substrings. |
546 |
|
.\" |
547 |
|
For example, when the pattern |
548 |
|
.sp |
549 |
|
(foo)\eKbar |
550 |
|
.sp |
551 |
|
matches "foobar", the first substring is still set to "foo". |
552 |
|
. |
553 |
|
. |
554 |
.\" HTML <a name="smallassertions"></a> |
.\" HTML <a name="smallassertions"></a> |
555 |
.SS "Simple assertions" |
.SS "Simple assertions" |
556 |
.rs |
.rs |
1453 |
.sp |
.sp |
1454 |
(?<=abc|abde) |
(?<=abc|abde) |
1455 |
.sp |
.sp |
1456 |
|
In some cases, the Perl 5.10 escape sequence \eK |
1457 |
|
.\" HTML <a href="#resetmatchstart"> |
1458 |
|
.\" </a> |
1459 |
|
(see above) |
1460 |
|
.\" |
1461 |
|
can be used instead of a lookbehind assertion; this is not restricted to a |
1462 |
|
fixed-length. |
1463 |
|
.P |
1464 |
The implementation of lookbehind assertions is, for each alternative, to |
The implementation of lookbehind assertions is, for each alternative, to |
1465 |
temporarily move the current position back by the fixed length and then try to |
temporarily move the current position back by the fixed length and then try to |
1466 |
match. If there are insufficient characters before the current position, the |
match. If there are insufficient characters before the current position, the |
1555 |
.sp |
.sp |
1556 |
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 |
1557 |
condition is true if the capturing subpattern of that number has previously |
condition is true if the capturing subpattern of that number has previously |
1558 |
matched. |
matched. An alternative notation is to precede the digits with a plus or minus |
1559 |
|
sign. In this case, the subpattern number is relative rather than absolute. |
1560 |
|
The most recently opened parentheses can be referenced by (?(-1), the next most |
1561 |
|
recent by (?(-2), and so on. In looping constructs it can also make sense to |
1562 |
|
refer to subsequent groups with constructs such as (?(+2). |
1563 |
.P |
.P |
1564 |
Consider the following pattern, which contains non-significant white space to |
Consider the following pattern, which contains non-significant white space to |
1565 |
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 |
1576 |
parenthesis is required. Otherwise, since no-pattern is not present, the |
parenthesis is required. Otherwise, since no-pattern is not present, the |
1577 |
subpattern matches nothing. In other words, this pattern matches a sequence of |
subpattern matches nothing. In other words, this pattern matches a sequence of |
1578 |
non-parentheses, optionally enclosed in parentheses. |
non-parentheses, optionally enclosed in parentheses. |
1579 |
|
.P |
1580 |
|
If you were embedding this pattern in a larger one, you could use a relative |
1581 |
|
reference: |
1582 |
|
.sp |
1583 |
|
...other stuff... ( \e( )? [^()]+ (?(-1) \e) ) ... |
1584 |
|
.sp |
1585 |
|
This makes the fragment independent of the parentheses in the larger pattern. |
1586 |
. |
. |
1587 |
.SS "Checking for a used subpattern by name" |
.SS "Checking for a used subpattern by name" |
1588 |
.rs |
.rs |
1893 |
.rs |
.rs |
1894 |
.sp |
.sp |
1895 |
.nf |
.nf |
1896 |
Last updated: 06 March 2007 |
Last updated: 29 May 2007 |
1897 |
Copyright (c) 1997-2007 University of Cambridge. |
Copyright (c) 1997-2007 University of Cambridge. |
1898 |
.fi |
.fi |