/[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 572 by ph10, Wed Nov 17 17:55:57 2010 UTC revision 607 by ph10, Sun Jun 12 15:09:49 2011 UTC
# Line 52  such as \ed and \ew to use Unicode prope Line 52  such as \ed and \ew to use Unicode prope
52  instead of recognizing only characters with codes less than 128 via a lookup  instead of recognizing only characters with codes less than 128 via a lookup
53  table.  table.
54  .P  .P
55    If a pattern starts with (*NO_START_OPT), it has the same effect as setting the
56    PCRE_NO_START_OPTIMIZE option either at compile or matching time. There are
57    also some more of these special sequences that are concerned with the handling
58    of newlines; they are described below.
59    .P
60  The remainder of this document discusses the patterns that are supported by  The remainder of this document discusses the patterns that are supported by
61  PCRE when its main matching function, \fBpcre_exec()\fP, is used.  PCRE when its main matching function, \fBpcre_exec()\fP, is used.
62  From release 6.0, PCRE offers a second matching function,  From release 6.0, PCRE offers a second matching function,
# Line 182  The following sections describe the use Line 187  The following sections describe the use
187  .rs  .rs
188  .sp  .sp
189  The backslash character has several uses. Firstly, if it is followed by a  The backslash character has several uses. Firstly, if it is followed by a
190  non-alphanumeric character, it takes away any special meaning that character  character that is not a number or a letter, it takes away any special meaning
191  may have. This use of backslash as an escape character applies both inside and  that character may have. This use of backslash as an escape character applies
192  outside character classes.  both inside and outside character classes.
193  .P  .P
194  For example, if you want to match a * character, you write \e* in the pattern.  For example, if you want to match a * character, you write \e* in the pattern.
195  This escaping action applies whether or not the following character would  This escaping action applies whether or not the following character would
# Line 192  otherwise be interpreted as a metacharac Line 197  otherwise be interpreted as a metacharac
197  non-alphanumeric with backslash to specify that it stands for itself. In  non-alphanumeric with backslash to specify that it stands for itself. In
198  particular, if you want to match a backslash, you write \e\e.  particular, if you want to match a backslash, you write \e\e.
199  .P  .P
200    In UTF-8 mode, only ASCII numbers and letters have any special meaning after a
201    backslash. All other characters (in particular, those whose codepoints are
202    greater than 127) are treated as literals.
203    .P
204  If a pattern is compiled with the PCRE_EXTENDED option, whitespace in the  If a pattern is compiled with the PCRE_EXTENDED option, whitespace in the
205  pattern (other than in a character class) and characters between a # outside  pattern (other than in a character class) and characters between a # outside
206  a character class and the next newline are ignored. An escaping backslash can  a character class and the next newline are ignored. An escaping backslash can
# Line 211  Perl, $ and @ cause variable interpolati Line 220  Perl, $ and @ cause variable interpolati
220    \eQabc\eE\e$\eQxyz\eE   abc$xyz        abc$xyz    \eQabc\eE\e$\eQxyz\eE   abc$xyz        abc$xyz
221  .sp  .sp
222  The \eQ...\eE sequence is recognized both inside and outside character classes.  The \eQ...\eE sequence is recognized both inside and outside character classes.
223  An isolated \eE that is not preceded by \eQ is ignored.  An isolated \eE that is not preceded by \eQ is ignored. If \eQ is not followed
224    by \eE later in the pattern, the literal interpretation continues to the end of
225    the pattern (that is, \eE is assumed at the end). If the isolated \eQ is inside
226    a character class, this causes an error, because the character class is not
227    terminated.
228  .  .
229  .  .
230  .\" HTML <a name="digitsafterbackslash"></a>  .\" HTML <a name="digitsafterbackslash"></a>
# Line 225  but when a pattern is being prepared by Line 238  but when a pattern is being prepared by
238  one of the following escape sequences than the binary character it represents:  one of the following escape sequences than the binary character it represents:
239  .sp  .sp
240    \ea        alarm, that is, the BEL character (hex 07)    \ea        alarm, that is, the BEL character (hex 07)
241    \ecx       "control-x", where x is any character    \ecx       "control-x", where x is any ASCII character
242    \ee        escape (hex 1B)    \ee        escape (hex 1B)
243    \ef        formfeed (hex 0C)    \ef        formfeed (hex 0C)
244    \en        linefeed (hex 0A)    \en        linefeed (hex 0A)
# Line 237  one of the following escape sequences th Line 250  one of the following escape sequences th
250  .sp  .sp
251  The precise effect of \ecx is as follows: if x is a lower case letter, it  The precise effect of \ecx is as follows: if x is a lower case letter, it
252  is converted to upper case. Then bit 6 of the character (hex 40) is inverted.  is converted to upper case. Then bit 6 of the character (hex 40) is inverted.
253  Thus \ecz becomes hex 1A, but \ec{ becomes hex 3B, while \ec; becomes hex  Thus \ecz becomes hex 1A (z is 7A), but \ec{ becomes hex 3B ({ is 7B), while
254  7B.  \ec; becomes hex 7B (; is 3B). If the byte following \ec has a value greater
255    than 127, a compile-time error occurs. This locks out non-ASCII characters in
256    both byte mode and UTF-8 mode. (When PCRE is compiled in EBCDIC mode, all byte
257    values are valid. A lower case letter is converted to upper case, and then the
258    0xc0 bits are flipped.)
259  .P  .P
260  After \ex, from zero to two hexadecimal digits are read (letters can be in  After \ex, from zero to two hexadecimal digits are read (letters can be in
261  upper or lower case). Any number of hexadecimal digits may appear between \ex{  upper or lower case). Any number of hexadecimal digits may appear between \ex{
# Line 424  any Unicode letter, and underscore. Note Line 441  any Unicode letter, and underscore. Note
441  \eB because they are defined in terms of \ew and \eW. Matching these sequences  \eB because they are defined in terms of \ew and \eW. Matching these sequences
442  is noticeably slower when PCRE_UCP is set.  is noticeably slower when PCRE_UCP is set.
443  .P  .P
444  The sequences \eh, \eH, \ev, and \eV are features that were added to Perl at  The sequences \eh, \eH, \ev, and \eV are features that were added to Perl at
445  release 5.10. In contrast to the other sequences, which match only ASCII  release 5.10. In contrast to the other sequences, which match only ASCII
446  characters by default, these always match certain high-valued codepoints in  characters by default, these always match certain high-valued codepoints in
447  UTF-8 mode, whether or not PCRE_UCP is set. The horizontal space characters  UTF-8 mode, whether or not PCRE_UCP is set. The horizontal space characters
# Line 947  The handling of dot is entirely independ Line 964  The handling of dot is entirely independ
964  dollar, the only relationship being that they both involve newlines. Dot has no  dollar, the only relationship being that they both involve newlines. Dot has no
965  special meaning in a character class.  special meaning in a character class.
966  .P  .P
967  The escape sequence \eN behaves like a dot, except that it is not affected by  The escape sequence \eN behaves like a dot, except that it is not affected by
968  the PCRE_DOTALL option. In other words, it matches any character except one  the PCRE_DOTALL option. In other words, it matches any character except one
969  that signifies the end of a line.  that signifies the end of a line.
970  .  .
# Line 1044  characters in both cases. In UTF-8 mode, Line 1061  characters in both cases. In UTF-8 mode,
1061  characters with values greater than 128 only when it is compiled with Unicode  characters with values greater than 128 only when it is compiled with Unicode
1062  property support.  property support.
1063  .P  .P
1064  The character types \ed, \eD, \eh, \eH, \ep, \eP, \es, \eS, \ev, \eV, \ew, and  The character escape sequences \ed, \eD, \eh, \eH, \ep, \eP, \es, \eS, \ev,
1065  \eW may also appear in a character class, and add the characters that they  \eV, \ew, and \eW may appear in a character class, and add the characters that
1066  match to the class. For example, [\edABCDEF] matches any hexadecimal digit. A  they match to the class. For example, [\edABCDEF] matches any hexadecimal
1067  circumflex can conveniently be used with the upper case character types to  digit. In UTF-8 mode, the PCRE_UCP option affects the meanings of \ed, \es, \ew
1068    and their upper case partners, just as it does when they appear outside a
1069    character class, as described in the section entitled
1070    .\" HTML <a href="#genericchartypes">
1071    .\" </a>
1072    "Generic character types"
1073    .\"
1074    above. The escape sequence \eb has a different meaning inside a character
1075    class; it matches the backspace character. The sequences \eB, \eN, \eR, and \eX
1076    are not special inside a character class. Like any other unrecognized escape
1077    sequences, they are treated as the literal characters "B", "N", "R", and "X" by
1078    default, but cause an error if the PCRE_EXTRA option is set.
1079    .P
1080    A circumflex can conveniently be used with the upper case character types to
1081  specify a more restricted set of characters than the matching lower case type.  specify a more restricted set of characters than the matching lower case type.
1082  For example, the class [^\eW_] matches any letter or digit, but not underscore.  For example, the class [^\eW_] matches any letter or digit, but not underscore,
1083    whereas [\ew] includes underscore. A positive character class should be read as
1084    "something OR something OR ..." and a negative class as "NOT something AND NOT
1085    something AND NOT ...".
1086  .P  .P
1087  The only metacharacters that are recognized in character classes are backslash,  The only metacharacters that are recognized in character classes are backslash,
1088  hyphen (only where it can be interpreted as specifying a range), circumflex  hyphen (only where it can be interpreted as specifying a range), circumflex
# Line 1968  already been matched. The two possible f Line 2001  already been matched. The two possible f
2001  If the condition is satisfied, the yes-pattern is used; otherwise the  If the condition is satisfied, the yes-pattern is used; otherwise the
2002  no-pattern (if present) is used. If there are more than two alternatives in the  no-pattern (if present) is used. If there are more than two alternatives in the
2003  subpattern, a compile-time error occurs. Each of the two alternatives may  subpattern, a compile-time error occurs. Each of the two alternatives may
2004  itself contain nested subpatterns of any form, including conditional  itself contain nested subpatterns of any form, including conditional
2005  subpatterns; the restriction to two alternatives applies only at the level of  subpatterns; the restriction to two alternatives applies only at the level of
2006  the condition. This pattern fragment is an example where the alternatives are  the condition. This pattern fragment is an example where the alternatives are
2007  complex:  complex:
2008  .sp  .sp
2009    (?(1) (A|B|C) | (D | (?(2)E|F) | E) )    (?(1) (A|B|C) | (D | (?(2)E|F) | E) )
# Line 1995  the condition is true if any of them hav Line 2028  the condition is true if any of them hav
2028  to precede the digits with a plus or minus sign. In this case, the subpattern  to precede the digits with a plus or minus sign. In this case, the subpattern
2029  number is relative rather than absolute. The most recently opened parentheses  number is relative rather than absolute. The most recently opened parentheses
2030  can be referenced by (?(-1), the next most recent by (?(-2), and so on. Inside  can be referenced by (?(-1), the next most recent by (?(-2), and so on. Inside
2031  loops it can also make sense to refer to subsequent groups. The next  loops it can also make sense to refer to subsequent groups. The next
2032  parentheses to be opened can be referenced as (?(+1), and so on. (The value  parentheses to be opened can be referenced as (?(+1), and so on. (The value
2033  zero in any of these forms is not used; it provokes a compile-time error.)  zero in any of these forms is not used; it provokes a compile-time error.)
2034  .P  .P
# Line 2115  dd-aaa-dd or dd-dd-dd, where aaa are let Line 2148  dd-aaa-dd or dd-dd-dd, where aaa are let
2148  .SH COMMENTS  .SH COMMENTS
2149  .rs  .rs
2150  .sp  .sp
2151  There are two ways of including comments in patterns that are processed by  There are two ways of including comments in patterns that are processed by
2152  PCRE. In both cases, the start of the comment must not be in a character class,  PCRE. In both cases, the start of the comment must not be in a character class,
2153  nor in the middle of any other sequence of related characters such as (?: or a  nor in the middle of any other sequence of related characters such as (?: or a
2154  subpattern name or number. The characters that make up a comment play no part  subpattern name or number. The characters that make up a comment play no part
# Line 2139  default newline convention is in force: Line 2172  default newline convention is in force:
2172  .sp  .sp
2173    abc #comment \en still comment    abc #comment \en still comment
2174  .sp  .sp
2175  On encountering the # character, \fBpcre_compile()\fP skips along, looking for  On encountering the # character, \fBpcre_compile()\fP skips along, looking for
2176  a newline in the pattern. The sequence \en is still literal at this stage, so  a newline in the pattern. The sequence \en is still literal at this stage, so
2177  it does not terminate the comment. Only an actual character with the code value  it does not terminate the comment. Only an actual character with the code value
2178  0x0a (the default newline) does so.  0x0a (the default newline) does so.
# Line 2473  minimum length of matching subject, or t Line 2506  minimum length of matching subject, or t
2506  present. When one of these optimizations suppresses the running of a match, any  present. When one of these optimizations suppresses the running of a match, any
2507  included backtracking verbs will not, of course, be processed. You can suppress  included backtracking verbs will not, of course, be processed. You can suppress
2508  the start-of-match optimizations by setting the PCRE_NO_START_OPTIMIZE option  the start-of-match optimizations by setting the PCRE_NO_START_OPTIMIZE option
2509  when calling \fBpcre_exec()\fP.  when calling \fBpcre_compile()\fP or \fBpcre_exec()\fP, or by starting the
2510    pattern with (*NO_START_OPT).
2511  .  .
2512  .  .
2513  .SS "Verbs that act immediately"  .SS "Verbs that act immediately"
# Line 2664  matching name is found, normal "bumpalon Line 2698  matching name is found, normal "bumpalon
2698  .sp  .sp
2699    (*THEN) or (*THEN:NAME)    (*THEN) or (*THEN:NAME)
2700  .sp  .sp
2701  This verb causes a skip to the next alternation in the innermost enclosing  This verb causes a skip to the next alternation in the innermost enclosing
2702  group if the rest of the pattern does not match. That is, it cancels pending  group if the rest of the pattern does not match. That is, it cancels pending
2703  backtracking, but only within the current alternation. Its name comes from the  backtracking, but only within the current alternation. Its name comes from the
2704  observation that it can be used for a pattern-based if-then-else block:  observation that it can be used for a pattern-based if-then-else block:
# Line 2679  overall match fails. If (*THEN) is not d Line 2713  overall match fails. If (*THEN) is not d
2713  like (*PRUNE).  like (*PRUNE).
2714  .  .
2715  .P  .P
2716  The above verbs provide four different "strengths" of control when subsequent  The above verbs provide four different "strengths" of control when subsequent
2717  matching fails. (*THEN) is the weakest, carrying on the match at the next  matching fails. (*THEN) is the weakest, carrying on the match at the next
2718  alternation. (*PRUNE) comes next, failing the match at the current starting  alternation. (*PRUNE) comes next, failing the match at the current starting
2719  position, but allowing an advance to the next character (for an unanchored  position, but allowing an advance to the next character (for an unanchored
# Line 2718  Cambridge CB2 3QH, England. Line 2752  Cambridge CB2 3QH, England.
2752  .rs  .rs
2753  .sp  .sp
2754  .nf  .nf
2755  Last updated: 17 November 2010  Last updated: 12 June 2011
2756  Copyright (c) 1997-2010 University of Cambridge.  Copyright (c) 1997-2011 University of Cambridge.
2757  .fi  .fi

Legend:
Removed from v.572  
changed lines
  Added in v.607

  ViewVC Help
Powered by ViewVC 1.1.5