| 41 |
</ul> |
</ul> |
| 42 |
<br><a name="SEC1" href="#TOC1">PCRE REGULAR EXPRESSION DETAILS</a><br> |
<br><a name="SEC1" href="#TOC1">PCRE REGULAR EXPRESSION DETAILS</a><br> |
| 43 |
<P> |
<P> |
| 44 |
The syntax and semantics of the regular expressions supported by PCRE are |
The syntax and semantics of the regular expressions that are supported by PCRE |
| 45 |
described below. Regular expressions are also described in the Perl |
are described in detail below. There is a quick-reference syntax summary in the |
| 46 |
documentation and in a number of books, some of which have copious examples. |
<a href="pcresyntax.html"><b>pcresyntax</b></a> |
| 47 |
Jeffrey Friedl's "Mastering Regular Expressions", published by O'Reilly, covers |
page. Perl's regular expressions are described in its own documentation, and |
| 48 |
regular expressions in great detail. This description of PCRE's regular |
regular expressions in general are covered in a number of books, some of which |
| 49 |
expressions is intended as reference material. |
have copious examples. Jeffrey Friedl's "Mastering Regular Expressions", |
| 50 |
|
published by O'Reilly, covers regular expressions in great detail. This |
| 51 |
|
description of PCRE's regular expressions is intended as reference material. |
| 52 |
</P> |
</P> |
| 53 |
<P> |
<P> |
| 54 |
The original operation of PCRE was on strings of one-byte characters. However, |
The original operation of PCRE was on strings of one-byte characters. However, |
| 257 |
Absolute and relative back references |
Absolute and relative back references |
| 258 |
</b><br> |
</b><br> |
| 259 |
<P> |
<P> |
| 260 |
The sequence \g followed by a positive or negative number, optionally enclosed |
The sequence \g followed by an unsigned or a negative number, optionally |
| 261 |
in braces, is an absolute or relative back reference. A named back reference |
enclosed in braces, is an absolute or relative back reference. A named back |
| 262 |
can be coded as \g{name}. Back references are discussed |
reference can be coded as \g{name}. Back references are discussed |
| 263 |
<a href="#backreferences">later,</a> |
<a href="#backreferences">later,</a> |
| 264 |
following the discussion of |
following the discussion of |
| 265 |
<a href="#subpattern">parenthesized subpatterns.</a> |
<a href="#subpattern">parenthesized subpatterns.</a> |
| 1305 |
<pre> |
<pre> |
| 1306 |
\d++foo |
\d++foo |
| 1307 |
</pre> |
</pre> |
| 1308 |
|
Note that a possessive quantifier can be used with an entire group, for |
| 1309 |
|
example: |
| 1310 |
|
<pre> |
| 1311 |
|
(abc|xyz){2,3}+ |
| 1312 |
|
</pre> |
| 1313 |
Possessive quantifiers are always greedy; the setting of the PCRE_UNGREEDY |
Possessive quantifiers are always greedy; the setting of the PCRE_UNGREEDY |
| 1314 |
option is ignored. They are a convenient notation for the simpler forms of |
option is ignored. They are a convenient notation for the simpler forms of |
| 1315 |
atomic group. However, there is no difference in the meaning of a possessive |
atomic group. However, there is no difference in the meaning of a possessive |
| 1384 |
<P> |
<P> |
| 1385 |
Another way of avoiding the ambiguity inherent in the use of digits following a |
Another way of avoiding the ambiguity inherent in the use of digits following a |
| 1386 |
backslash is to use the \g escape sequence, which is a feature introduced in |
backslash is to use the \g escape sequence, which is a feature introduced in |
| 1387 |
Perl 5.10. This escape must be followed by a positive or a negative number, |
Perl 5.10. This escape must be followed by an unsigned number or a negative |
| 1388 |
optionally enclosed in braces. These examples are all identical: |
number, optionally enclosed in braces. These examples are all identical: |
| 1389 |
<pre> |
<pre> |
| 1390 |
(ring), \1 |
(ring), \1 |
| 1391 |
(ring), \g1 |
(ring), \g1 |
| 1392 |
(ring), \g{1} |
(ring), \g{1} |
| 1393 |
</pre> |
</pre> |
| 1394 |
A positive number specifies an absolute reference without the ambiguity that is |
An unsigned number specifies an absolute reference without the ambiguity that |
| 1395 |
present in the older syntax. It is also useful when literal digits follow the |
is present in the older syntax. It is also useful when literal digits follow |
| 1396 |
reference. A negative number is a relative reference. Consider this example: |
the reference. A negative number is a relative reference. Consider this |
| 1397 |
|
example: |
| 1398 |
<pre> |
<pre> |
| 1399 |
(abc(def)ghi)\g{-1} |
(abc(def)ghi)\g{-1} |
| 1400 |
</pre> |
</pre> |
| 1998 |
</P> |
</P> |
| 1999 |
<br><a name="SEC25" href="#TOC1">REVISION</a><br> |
<br><a name="SEC25" href="#TOC1">REVISION</a><br> |
| 2000 |
<P> |
<P> |
| 2001 |
Last updated: 19 June 2007 |
Last updated: 06 August 2007 |
| 2002 |
<br> |
<br> |
| 2003 |
Copyright © 1997-2007 University of Cambridge. |
Copyright © 1997-2007 University of Cambridge. |
| 2004 |
<br> |
<br> |