1438 |
an escape such as \ed or \epL that matches a single character |
an escape such as \ed or \epL that matches a single character |
1439 |
a character class |
a character class |
1440 |
a back reference (see next section) |
a back reference (see next section) |
1441 |
a parenthesized subpattern (unless it is an assertion) |
a parenthesized subpattern (including assertions) |
1442 |
a recursive or "subroutine" call to a subpattern |
a recursive or "subroutine" call to a subpattern |
1443 |
.sp |
.sp |
1444 |
The general repetition quantifier specifies a minimum and maximum number of |
The general repetition quantifier specifies a minimum and maximum number of |
1829 |
that look behind it. An assertion subpattern is matched in the normal way, |
that look behind it. An assertion subpattern is matched in the normal way, |
1830 |
except that it does not cause the current matching position to be changed. |
except that it does not cause the current matching position to be changed. |
1831 |
.P |
.P |
1832 |
Assertion subpatterns are not capturing subpatterns, and may not be repeated, |
Assertion subpatterns are not capturing subpatterns. If such an assertion |
1833 |
because it makes no sense to assert the same thing several times. If any kind |
contains capturing subpatterns within it, these are counted for the purposes of |
1834 |
of assertion contains capturing subpatterns within it, these are counted for |
numbering the capturing subpatterns in the whole pattern. However, substring |
1835 |
the purposes of numbering the capturing subpatterns in the whole pattern. |
capturing is carried out only for positive assertions, because it does not make |
1836 |
However, substring capturing is carried out only for positive assertions, |
sense for negative assertions. |
1837 |
because it does not make sense for negative assertions. |
.P |
1838 |
|
For compatibility with Perl, assertion subpatterns may be repeated, even though |
1839 |
|
it makes no sense to assert the same thing several times. In practice, there |
1840 |
|
only three cases: |
1841 |
|
.sp |
1842 |
|
(1) If the quantifier is {0}, the assertion is never obeyed during matching. |
1843 |
|
However, it may contain internal capturing parenthesized groups that are called |
1844 |
|
from elsewhere via the |
1845 |
|
.\" HTML <a href="#subpatternsassubroutines"> |
1846 |
|
.\" </a> |
1847 |
|
subroutine mechanism. |
1848 |
|
.\" |
1849 |
|
.sp |
1850 |
|
(2) If quantifier is {0,n} where n is greater than zero, it is treated as if it |
1851 |
|
were {0,1}. At run time, the rest of the pattern match is tried with and |
1852 |
|
without the assertion, the order depending on the greediness of the quantifier. |
1853 |
|
.sp |
1854 |
|
(3) If the minimum repetition is greater than zero, the quantifier is ignored. |
1855 |
|
The assertion is obeyed just once when encountered during matching. |
1856 |
. |
. |
1857 |
. |
. |
1858 |
.SS "Lookahead assertions" |
.SS "Lookahead assertions" |
2779 |
.rs |
.rs |
2780 |
.sp |
.sp |
2781 |
.nf |
.nf |
2782 |
Last updated: 22 July 2011 |
Last updated: 24 July 2011 |
2783 |
Copyright (c) 1997-2011 University of Cambridge. |
Copyright (c) 1997-2011 University of Cambridge. |
2784 |
.fi |
.fi |