/[pcre]/code/trunk/doc/pcrepattern.3
ViewVC logotype

Diff of /code/trunk/doc/pcrepattern.3

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 178 by ph10, Wed Jun 13 08:44:34 2007 UTC revision 208 by ph10, Mon Aug 6 15:23:29 2007 UTC
# Line 4  PCRE - Perl-compatible regular expressio Line 4  PCRE - Perl-compatible regular expressio
4  .SH "PCRE REGULAR EXPRESSION DETAILS"  .SH "PCRE REGULAR EXPRESSION DETAILS"
5  .rs  .rs
6  .sp  .sp
7  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
8  described below. Regular expressions are also described in the Perl  are described in detail below. There is a quick-reference syntax summary in the
9  documentation and in a number of books, some of which have copious examples.  .\" HREF
10  Jeffrey Friedl's "Mastering Regular Expressions", published by O'Reilly, covers  \fBpcresyntax\fP
11  regular expressions in great detail. This description of PCRE's regular  .\"
12  expressions is intended as reference material.  page. Perl's regular expressions are described in its own documentation, and
13    regular expressions in general are covered in a number of books, some of which
14    have copious examples. Jeffrey Friedl's "Mastering Regular Expressions",
15    published by O'Reilly, covers regular expressions in great detail. This
16    description of PCRE's regular expressions is intended as reference material.
17  .P  .P
18  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,
19  there is now also support for UTF-8 character strings. To use this, you must  there is now also support for UTF-8 character strings. To use this, you must
# Line 240  meanings Line 244  meanings
244  .SS "Absolute and relative back references"  .SS "Absolute and relative back references"
245  .rs  .rs
246  .sp  .sp
247  The sequence \eg followed by a positive or negative number, optionally enclosed  The sequence \eg followed by an unsigned or a negative number, optionally
248  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
249  can be coded as \eg{name}. Back references are discussed  reference can be coded as \eg{name}. Back references are discussed
250  .\" HTML <a href="#backreferences">  .\" HTML <a href="#backreferences">
251  .\" </a>  .\" </a>
252  later,  later,
# Line 260  parenthesized subpatterns. Line 264  parenthesized subpatterns.
264  Another use of backslash is for specifying generic character types. The  Another use of backslash is for specifying generic character types. The
265  following are always recognized:  following are always recognized:
266  .sp  .sp
267    \ed     any decimal digit    \ed     any decimal digit
268    \eD     any character that is not a decimal digit    \eD     any character that is not a decimal digit
269    \eh     any horizontal whitespace character    \eh     any horizontal whitespace character
270    \eH     any character that is not a horizontal whitespace character    \eH     any character that is not a horizontal whitespace character
271    \es     any whitespace character    \es     any whitespace character
272    \eS     any character that is not a whitespace character    \eS     any character that is not a whitespace character
273    \ev     any vertical whitespace character    \ev     any vertical whitespace character
274    \eV     any character that is not a vertical whitespace character    \eV     any character that is not a vertical whitespace character
275    \ew     any "word" character    \ew     any "word" character
276    \eW     any "non-word" character    \eW     any "non-word" character
277  .sp  .sp
# Line 287  does. Line 291  does.
291  .P  .P
292  In UTF-8 mode, characters with values greater than 128 never match \ed, \es, or  In UTF-8 mode, characters with values greater than 128 never match \ed, \es, or
293  \ew, and always match \eD, \eS, and \eW. This is true even when Unicode  \ew, and always match \eD, \eS, and \eW. This is true even when Unicode
294  character property support is available. These sequences retain their original  character property support is available. These sequences retain their original
295  meanings from before UTF-8 support was available, mainly for efficiency  meanings from before UTF-8 support was available, mainly for efficiency
296  reasons.  reasons.
297  .P  .P
298  The sequences \eh, \eH, \ev, and \eV are Perl 5.10 features. In contrast to the  The sequences \eh, \eH, \ev, and \eV are Perl 5.10 features. In contrast to the
299  other sequences, these do match certain high-valued codepoints in UTF-8 mode.  other sequences, these do match certain high-valued codepoints in UTF-8 mode.
300  The horizontal space characters are:  The horizontal space characters are:
301  .sp  .sp
# Line 376  Inside a character class, \eR matches th Line 380  Inside a character class, \eR matches th
380  .rs  .rs
381  .sp  .sp
382  When PCRE is built with Unicode character property support, three additional  When PCRE is built with Unicode character property support, three additional
383  escape sequences to match character properties are available when UTF-8 mode  escape sequences that match characters with specific properties are available.
384  is selected. They are:  When not in UTF-8 mode, these sequences are of course limited to testing
385    characters whose codepoints are less than 256, but they do work in this mode.
386    The extra escape sequences are:
387  .sp  .sp
388    \ep{\fIxx\fP}   a character with the \fIxx\fP property    \ep{\fIxx\fP}   a character with the \fIxx\fP property
389    \eP{\fIxx\fP}   a character without the \fIxx\fP property    \eP{\fIxx\fP}   a character without the \fIxx\fP property
# Line 553  atomic group Line 559  atomic group
559  (see below).  (see below).
560  .\"  .\"
561  Characters with the "mark" property are typically accents that affect the  Characters with the "mark" property are typically accents that affect the
562  preceding character.  preceding character. None of them have codepoints less than 256, so in
563    non-UTF-8 mode \eX matches any one character.
564  .P  .P
565  Matching characters by Unicode property is not fast, because PCRE has to search  Matching characters by Unicode property is not fast, because PCRE has to search
566  a structure that contains data for over fifteen thousand characters. That is  a structure that contains data for over fifteen thousand characters. That is
# Line 1001  the above patterns match "SUNDAY" as wel Line 1008  the above patterns match "SUNDAY" as wel
1008  .SH "DUPLICATE SUBPATTERN NUMBERS"  .SH "DUPLICATE SUBPATTERN NUMBERS"
1009  .rs  .rs
1010  .sp  .sp
1011  Perl 5.10 introduced a feature whereby each alternative in a subpattern uses  Perl 5.10 introduced a feature whereby each alternative in a subpattern uses
1012  the same numbers for its capturing parentheses. Such a subpattern starts with  the same numbers for its capturing parentheses. Such a subpattern starts with
1013  (?| and is itself a non-capturing subpattern. For example, consider this  (?| and is itself a non-capturing subpattern. For example, consider this
1014  pattern:  pattern:
1015  .sp  .sp
1016    (?|(Sat)ur|(Sun))day    (?|(Sat)ur|(Sun))day
1017  .sp  .sp
1018  Because the two alternatives are inside a (?| group, both sets of capturing  Because the two alternatives are inside a (?| group, both sets of capturing
1019  parentheses are numbered one. Thus, when the pattern matches, you can look  parentheses are numbered one. Thus, when the pattern matches, you can look
1020  at captured substring number one, whichever alternative matched. This construct  at captured substring number one, whichever alternative matched. This construct
1021  is useful when you want to capture part, but not all, of one of a number of  is useful when you want to capture part, but not all, of one of a number of
1022  alternatives. Inside a (?| group, parentheses are numbered as usual, but the  alternatives. Inside a (?| group, parentheses are numbered as usual, but the
1023  number is reset at the start of each branch. The numbers of any capturing  number is reset at the start of each branch. The numbers of any capturing
1024  buffers that follow the subpattern start after the highest number used in any  buffers that follow the subpattern start after the highest number used in any
1025  branch. The following example is taken from the Perl documentation.  branch. The following example is taken from the Perl documentation.
1026  The numbers underneath show in which buffer the captured content will be  The numbers underneath show in which buffer the captured content will be
1027  stored.  stored.
1028  .sp  .sp
1029    # before  ---------------branch-reset----------- after    # before  ---------------branch-reset----------- after
1030    / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x    / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
1031    # 1            2         2  3        2     3     4    # 1            2         2  3        2     3     4
1032  .sp  .sp
1033  A backreference or a recursive call to a numbered subpattern always refers to  A backreference or a recursive call to a numbered subpattern always refers to
1034  the first one in the pattern with the given number.  the first one in the pattern with the given number.
1035  .P  .P
# Line 1079  abbreviation. This pattern (ignoring the Line 1086  abbreviation. This pattern (ignoring the
1086    (?<DN>Sat)(?:urday)?    (?<DN>Sat)(?:urday)?
1087  .sp  .sp
1088  There are five capturing substrings, but only one is ever set after a match.  There are five capturing substrings, but only one is ever set after a match.
1089  (An alternative way of solving this problem is to use a "branch reset"  (An alternative way of solving this problem is to use a "branch reset"
1090  subpattern, as described in the previous section.)  subpattern, as described in the previous section.)
1091  .P  .P
1092  The convenience function for extracting the data by name returns the substring  The convenience function for extracting the data by name returns the substring
# Line 1287  previous example can be rewritten as Line 1294  previous example can be rewritten as
1294  .sp  .sp
1295    \ed++foo    \ed++foo
1296  .sp  .sp
1297    Note that a possessive quantifier can be used with an entire group, for
1298    example:
1299    .sp
1300      (abc|xyz){2,3}+
1301    .sp
1302  Possessive quantifiers are always greedy; the setting of the PCRE_UNGREEDY  Possessive quantifiers are always greedy; the setting of the PCRE_UNGREEDY
1303  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
1304  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
# Line 1361  subpattern is possible using named paren Line 1373  subpattern is possible using named paren
1373  .P  .P
1374  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
1375  backslash is to use the \eg escape sequence, which is a feature introduced in  backslash is to use the \eg escape sequence, which is a feature introduced in
1376  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
1377  optionally enclosed in braces. These examples are all identical:  number, optionally enclosed in braces. These examples are all identical:
1378  .sp  .sp
1379    (ring), \e1    (ring), \e1
1380    (ring), \eg1    (ring), \eg1
1381    (ring), \eg{1}    (ring), \eg{1}
1382  .sp  .sp
1383  A positive number specifies an absolute reference without the ambiguity that is  An unsigned number specifies an absolute reference without the ambiguity that
1384  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
1385  reference. A negative number is a relative reference. Consider this example:  the reference. A negative number is a relative reference. Consider this
1386    example:
1387  .sp  .sp
1388    (abc(def)ghi)\eg{-1}    (abc(def)ghi)\eg{-1}
1389  .sp  .sp
# Line 1973  Cambridge CB2 3QH, England. Line 1986  Cambridge CB2 3QH, England.
1986  .rs  .rs
1987  .sp  .sp
1988  .nf  .nf
1989  Last updated: 13 June 2007  Last updated: 06 August 2007
1990  Copyright (c) 1997-2007 University of Cambridge.  Copyright (c) 1997-2007 University of Cambridge.
1991  .fi  .fi

Legend:
Removed from v.178  
changed lines
  Added in v.208

  ViewVC Help
Powered by ViewVC 1.1.5