/[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 959 by ph10, Sat Apr 14 16:16:58 2012 UTC revision 1260 by ph10, Wed Feb 27 15:41:22 2013 UTC
# Line 1  Line 1 
1  .TH PCREPATTERN 3 "14 April 2012" "PCRE 8.31"  .TH PCREPATTERN 3 "27 February 2013" "PCRE 8.33"
2  .SH NAME  .SH NAME
3  PCRE - Perl-compatible regular expressions  PCRE - Perl-compatible regular expressions
4  .SH "PCRE REGULAR EXPRESSION DETAILS"  .SH "PCRE REGULAR EXPRESSION DETAILS"
# Line 21  published by O'Reilly, covers regular ex Line 21  published by O'Reilly, covers regular ex
21  description of PCRE's regular expressions is intended as reference material.  description of PCRE's regular expressions is intended as reference material.
22  .P  .P
23  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,
24  there is now also support for UTF-8 strings in the original library, and a  there is now also support for UTF-8 strings in the original library, an
25  second library that supports 16-bit and UTF-16 character strings. To use these  extra library that supports 16-bit and UTF-16 character strings, and a
26    third library that supports 32-bit and UTF-32 character strings. To use these
27  features, PCRE must be built to include appropriate support. When using UTF  features, PCRE must be built to include appropriate support. When using UTF
28  strings you must either call the compiling function with the PCRE_UTF8 or  strings you must either call the compiling function with the PCRE_UTF8,
29  PCRE_UTF16 option, or the pattern must start with one of these special  PCRE_UTF16, or PCRE_UTF32 option, or the pattern must start with one of
30  sequences:  these special sequences:
31  .sp  .sp
32    (*UTF8)    (*UTF8)
33    (*UTF16)    (*UTF16)
34      (*UTF32)
35      (*UTF)
36  .sp  .sp
37    (*UTF) is a generic sequence that can be used with any of the libraries.
38  Starting a pattern with such a sequence is equivalent to setting the relevant  Starting a pattern with such a sequence is equivalent to setting the relevant
39  option. This feature is not Perl-compatible. How setting a UTF mode affects  option. This feature is not Perl-compatible. How setting a UTF mode affects
40  pattern matching is mentioned in several places below. There is also a summary  pattern matching is mentioned in several places below. There is also a summary
# Line 41  of features in the Line 45  of features in the
45  page.  page.
46  .P  .P
47  Another special sequence that may appear at the start of a pattern or in  Another special sequence that may appear at the start of a pattern or in
48  combination with (*UTF8) or (*UTF16) is:  combination with (*UTF8), (*UTF16), (*UTF32) or (*UTF) is:
49  .sp  .sp
50    (*UCP)    (*UCP)
51  .sp  .sp
# Line 57  of newlines; they are described below. Line 61  of newlines; they are described below.
61  .P  .P
62  The remainder of this document discusses the patterns that are supported by  The remainder of this document discusses the patterns that are supported by
63  PCRE when one its main matching functions, \fBpcre_exec()\fP (8-bit) or  PCRE when one its main matching functions, \fBpcre_exec()\fP (8-bit) or
64  \fBpcre16_exec()\fP (16-bit), is used. PCRE also has alternative matching  \fBpcre[16|32]_exec()\fP (16- or 32-bit), is used. PCRE also has alternative
65  functions, \fBpcre_dfa_exec()\fP and \fBpcre16_dfa_exec()\fP, which match using  matching functions, \fBpcre_dfa_exec()\fP and \fBpcre[16|32_dfa_exec()\fP,
66  a different algorithm that is not Perl-compatible. Some of the features  which match using a different algorithm that is not Perl-compatible. Some of
67  discussed below are not available when DFA matching is used. The advantages and  the features discussed below are not available when DFA matching is used. The
68  disadvantages of the alternative functions, and how they differ from the normal  advantages and disadvantages of the alternative functions, and how they differ
69  functions, are discussed in the  from the normal functions, are discussed in the
70  .\" HREF  .\" HREF
71  \fBpcrematching\fP  \fBpcrematching\fP
72  .\"  .\"
73  page.  page.
74  .  .
75  .  .
76    .SH "EBCDIC CHARACTER CODES"
77    .rs
78    .sp
79    PCRE can be compiled to run in an environment that uses EBCDIC as its character
80    code rather than ASCII or Unicode (typically a mainframe system). In the
81    sections below, character code values are ASCII or Unicode; in an EBCDIC
82    environment these characters may have different code values, and there are no
83    code points greater than 255.
84    .
85    .
86  .\" HTML <a name="newlines"></a>  .\" HTML <a name="newlines"></a>
87  .SH "NEWLINE CONVENTIONS"  .SH "NEWLINE CONVENTIONS"
88  .rs  .rs
# Line 108  Perl-compatible, are recognized only at Line 122  Perl-compatible, are recognized only at
122  they must be in upper case. If more than one of them is present, the last one  they must be in upper case. If more than one of them is present, the last one
123  is used.  is used.
124  .P  .P
125  The newline convention affects the interpretation of the dot metacharacter when  The newline convention affects where the circumflex and dollar assertions are
126  PCRE_DOTALL is not set, and also the behaviour of \eN. However, it does not  true. It also affects the interpretation of the dot metacharacter when
127  affect what the \eR escape sequence matches. By default, this is any Unicode  PCRE_DOTALL is not set, and the behaviour of \eN. However, it does not affect
128  newline sequence, for Perl compatibility. However, this can be changed; see the  what the \eR escape sequence matches. By default, this is any Unicode newline
129    sequence, for Perl compatibility. However, this can be changed; see the
130  description of \eR in the section entitled  description of \eR in the section entitled
131  .\" HTML <a href="#newlineseq">  .\" HTML <a href="#newlineseq">
132  .\" </a>  .\" </a>
# Line 198  In a UTF mode, only ASCII numbers and le Line 213  In a UTF mode, only ASCII numbers and le
213  backslash. All other characters (in particular, those whose codepoints are  backslash. All other characters (in particular, those whose codepoints are
214  greater than 127) are treated as literals.  greater than 127) are treated as literals.
215  .P  .P
216  If a pattern is compiled with the PCRE_EXTENDED option, whitespace in the  If a pattern is compiled with the PCRE_EXTENDED option, white space in the
217  pattern (other than in a character class) and characters between a # outside  pattern (other than in a character class) and characters between a # outside
218  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
219  be used to include a whitespace or # character as part of the pattern.  be used to include a white space or # character as part of the pattern.
220  .P  .P
221  If you want to remove the special meaning from a sequence of characters, you  If you want to remove the special meaning from a sequence of characters, you
222  can do so by putting them between \eQ and \eE. This is different from Perl in  can do so by putting them between \eQ and \eE. This is different from Perl in
# Line 237  one of the following escape sequences th Line 252  one of the following escape sequences th
252    \ea        alarm, that is, the BEL character (hex 07)    \ea        alarm, that is, the BEL character (hex 07)
253    \ecx       "control-x", where x is any ASCII character    \ecx       "control-x", where x is any ASCII character
254    \ee        escape (hex 1B)    \ee        escape (hex 1B)
255    \ef        formfeed (hex 0C)    \ef        form feed (hex 0C)
256    \en        linefeed (hex 0A)    \en        linefeed (hex 0A)
257    \er        carriage return (hex 0D)    \er        carriage return (hex 0D)
258    \et        tab (hex 09)    \et        tab (hex 09)
# Line 246  one of the following escape sequences th Line 261  one of the following escape sequences th
261    \ex{hhh..} character with hex code hhh.. (non-JavaScript mode)    \ex{hhh..} character with hex code hhh.. (non-JavaScript mode)
262    \euhhhh    character with hex code hhhh (JavaScript mode only)    \euhhhh    character with hex code hhhh (JavaScript mode only)
263  .sp  .sp
264  The precise effect of \ecx is as follows: if x is a lower case letter, it  The precise effect of \ecx on ASCII characters is as follows: if x is a lower
265  is converted to upper case. Then bit 6 of the character (hex 40) is inverted.  case letter, it is converted to upper case. Then bit 6 of the character (hex
266  Thus \ecz becomes hex 1A (z is 7A), but \ec{ becomes hex 3B ({ is 7B), while  40) is inverted. Thus \ecA to \ecZ become hex 01 to hex 1A (A is 41, Z is 5A),
267  \ec; becomes hex 7B (; is 3B). If the byte following \ec has a value greater  but \ec{ becomes hex 3B ({ is 7B), and \ec; becomes hex 7B (; is 3B). If the
268  than 127, a compile-time error occurs. This locks out non-ASCII characters in  data item (byte or 16-bit value) following \ec has a value greater than 127, a
269  all modes. (When PCRE is compiled in EBCDIC mode, all byte values are valid. A  compile-time error occurs. This locks out non-ASCII characters in all modes.
270  lower case letter is converted to upper case, and then the 0xc0 bits are  .P
271  flipped.)  The \ec facility was designed for use with ASCII characters, but with the
272    extension to Unicode it is even less useful than it once was. It is, however,
273    recognized when PCRE is compiled in EBCDIC mode, where data items are always
274    bytes. In this mode, all values are valid after \ec. If the next character is a
275    lower case letter, it is converted to upper case. Then the 0xc0 bits of the
276    byte are inverted. Thus \ecA becomes hex 01, as in ASCII (A is C1), but because
277    the EBCDIC letters are disjoint, \ecZ becomes hex 29 (Z is E9), and other
278    characters also generate different values.
279  .P  .P
280  By default, after \ex, from zero to two hexadecimal digits are read (letters  By default, after \ex, from zero to two hexadecimal digits are read (letters
281  can be in upper or lower case). Any number of hexadecimal digits may appear  can be in upper or lower case). Any number of hexadecimal digits may appear
# Line 263  between \ex{ and }, but the character co Line 285  between \ex{ and }, but the character co
285    8-bit UTF-8 mode      less than 0x10ffff and a valid codepoint    8-bit UTF-8 mode      less than 0x10ffff and a valid codepoint
286    16-bit non-UTF mode   less than 0x10000    16-bit non-UTF mode   less than 0x10000
287    16-bit UTF-16 mode    less than 0x10ffff and a valid codepoint    16-bit UTF-16 mode    less than 0x10ffff and a valid codepoint
288      32-bit non-UTF mode   less than 0x80000000
289      32-bit UTF-32 mode    less than 0x10ffff and a valid codepoint
290  .sp  .sp
291  Invalid Unicode codepoints are the range 0xd800 to 0xdfff (the so-called  Invalid Unicode codepoints are the range 0xd800 to 0xdfff (the so-called
292  "surrogate" codepoints).  "surrogate" codepoints), and 0xffef.
293  .P  .P
294  If characters other than hexadecimal digits appear between \ex{ and }, or if  If characters other than hexadecimal digits appear between \ex{ and }, or if
295  there is no terminating }, this form of escape is not recognized. Instead, the  there is no terminating }, this form of escape is not recognized. Instead, the
# Line 277  as just described only when it is follow Line 301  as just described only when it is follow
301  Otherwise, it matches a literal "x" character. In JavaScript mode, support for  Otherwise, it matches a literal "x" character. In JavaScript mode, support for
302  code points greater than 256 is provided by \eu, which must be followed by  code points greater than 256 is provided by \eu, which must be followed by
303  four hexadecimal digits; otherwise it matches a literal "u" character.  four hexadecimal digits; otherwise it matches a literal "u" character.
304    Character codes specified by \eu in JavaScript mode are constrained in the same
305    was as those specified by \ex in non-JavaScript mode.
306  .P  .P
307  Characters whose value is less than 256 can be defined by either of the two  Characters whose value is less than 256 can be defined by either of the two
308  syntaxes for \ex (or by \eu in JavaScript mode). There is no difference in the  syntaxes for \ex (or by \eu in JavaScript mode). There is no difference in the
# Line 311  subsequent digits stand for themselves. Line 337  subsequent digits stand for themselves.
337  constrained in the same way as characters specified in hexadecimal.  constrained in the same way as characters specified in hexadecimal.
338  For example:  For example:
339  .sp  .sp
340    \e040   is another way of writing a space    \e040   is another way of writing an ASCII space
341  .\" JOIN  .\" JOIN
342    \e40    is the same, provided there are fewer than 40    \e40    is the same, provided there are fewer than 40
343              previous capturing subpatterns              previous capturing subpatterns
# Line 399  Another use of backslash is for specifyi Line 425  Another use of backslash is for specifyi
425  .sp  .sp
426    \ed     any decimal digit    \ed     any decimal digit
427    \eD     any character that is not a decimal digit    \eD     any character that is not a decimal digit
428    \eh     any horizontal whitespace character    \eh     any horizontal white space character
429    \eH     any character that is not a horizontal whitespace character    \eH     any character that is not a horizontal white space character
430    \es     any whitespace character    \es     any white space character
431    \eS     any character that is not a whitespace character    \eS     any character that is not a white space character
432    \ev     any vertical whitespace character    \ev     any vertical white space character
433    \eV     any character that is not a vertical whitespace character    \eV     any character that is not a vertical white space character
434    \ew     any "word" character    \ew     any "word" character
435    \eW     any "non-word" character    \eW     any "non-word" character
436  .sp  .sp
# Line 469  release 5.10. In contrast to the other s Line 495  release 5.10. In contrast to the other s
495  characters by default, these always match certain high-valued codepoints,  characters by default, these always match certain high-valued codepoints,
496  whether or not PCRE_UCP is set. The horizontal space characters are:  whether or not PCRE_UCP is set. The horizontal space characters are:
497  .sp  .sp
498    U+0009     Horizontal tab    U+0009     Horizontal tab (HT)
499    U+0020     Space    U+0020     Space
500    U+00A0     Non-break space    U+00A0     Non-break space
501    U+1680     Ogham space mark    U+1680     Ogham space mark
# Line 491  whether or not PCRE_UCP is set. The hori Line 517  whether or not PCRE_UCP is set. The hori
517  .sp  .sp
518  The vertical space characters are:  The vertical space characters are:
519  .sp  .sp
520    U+000A     Linefeed    U+000A     Linefeed (LF)
521    U+000B     Vertical tab    U+000B     Vertical tab (VT)
522    U+000C     Formfeed    U+000C     Form feed (FF)
523    U+000D     Carriage return    U+000D     Carriage return (CR)
524    U+0085     Next line    U+0085     Next line (NEL)
525    U+2028     Line separator    U+2028     Line separator
526    U+2029     Paragraph separator    U+2029     Paragraph separator
527  .sp  .sp
# Line 520  below. Line 546  below.
546  .\"  .\"
547  This particular group matches either the two-character sequence CR followed by  This particular group matches either the two-character sequence CR followed by
548  LF, or one of the single characters LF (linefeed, U+000A), VT (vertical tab,  LF, or one of the single characters LF (linefeed, U+000A), VT (vertical tab,
549  U+000B), FF (formfeed, U+000C), CR (carriage return, U+000D), or NEL (next  U+000B), FF (form feed, U+000C), CR (carriage return, U+000D), or NEL (next
550  line, U+0085). The two-character sequence is treated as a single unit that  line, U+0085). The two-character sequence is treated as a single unit that
551  cannot be split.  cannot be split.
552  .P  .P
# Line 549  change of newline convention; for exampl Line 575  change of newline convention; for exampl
575  .sp  .sp
576    (*ANY)(*BSR_ANYCRLF)    (*ANY)(*BSR_ANYCRLF)
577  .sp  .sp
578  They can also be combined with the (*UTF8), (*UTF16), or (*UCP) special  They can also be combined with the (*UTF8), (*UTF16), (*UTF32), (*UTF) or
579  sequences. Inside a character class, \eR is treated as an unrecognized escape  (*UCP) special sequences. Inside a character class, \eR is treated as an
580  sequence, and so matches the letter "R" by default, but causes an error if  unrecognized escape sequence, and so matches the letter "R" by default, but
581  PCRE_EXTRA is set.  causes an error if PCRE_EXTRA is set.
582  .  .
583  .  .
584  .\" HTML <a name="uniextseq"></a>  .\" HTML <a name="uniextseq"></a>
# Line 567  The extra escape sequences are: Line 593  The extra escape sequences are:
593  .sp  .sp
594    \ep{\fIxx\fP}   a character with the \fIxx\fP property    \ep{\fIxx\fP}   a character with the \fIxx\fP property
595    \eP{\fIxx\fP}   a character without the \fIxx\fP property    \eP{\fIxx\fP}   a character without the \fIxx\fP property
596    \eX       an extended Unicode sequence    \eX       a Unicode extended grapheme cluster
597  .sp  .sp
598  The property names represented by \fIxx\fP above are limited to the Unicode  The property names represented by \fIxx\fP above are limited to the Unicode
599  script names, the general category properties, "Any", which matches any  script names, the general category properties, "Any", which matches any
# Line 760  a modifier or "other". Line 786  a modifier or "other".
786  The Cs (Surrogate) property applies only to characters in the range U+D800 to  The Cs (Surrogate) property applies only to characters in the range U+D800 to
787  U+DFFF. Such characters are not valid in Unicode strings and so  U+DFFF. Such characters are not valid in Unicode strings and so
788  cannot be tested by PCRE, unless UTF validity checking has been turned off  cannot be tested by PCRE, unless UTF validity checking has been turned off
789  (see the discussion of PCRE_NO_UTF8_CHECK and PCRE_NO_UTF16_CHECK in the  (see the discussion of PCRE_NO_UTF8_CHECK, PCRE_NO_UTF16_CHECK and
790    PCRE_NO_UTF32_CHECK in the
791  .\" HREF  .\" HREF
792  \fBpcreapi\fP  \fBpcreapi\fP
793  .\"  .\"
# Line 775  Instead, this property is assumed for an Line 802  Instead, this property is assumed for an
802  Unicode table.  Unicode table.
803  .P  .P
804  Specifying caseless matching does not affect these escape sequences. For  Specifying caseless matching does not affect these escape sequences. For
805  example, \ep{Lu} always matches only upper case letters.  example, \ep{Lu} always matches only upper case letters. This is different from
806    the behaviour of current versions of Perl.
807  .P  .P
808  The \eX escape matches any number of Unicode characters that form an extended  Matching characters by Unicode property is not fast, because PCRE has to do a
809  Unicode sequence. \eX is equivalent to  multistage table lookup in order to find a character's property. That is why
810  .sp  the traditional escape sequences such as \ed and \ew do not use Unicode
811    (?>\ePM\epM*)  properties in PCRE by default, though you can make them do so by setting the
812    PCRE_UCP option or by starting the pattern with (*UCP).
813    .
814    .
815    .SS Extended grapheme clusters
816    .rs
817  .sp  .sp
818  That is, it matches a character without the "mark" property, followed by zero  The \eX escape matches any number of Unicode characters that form an "extended
819  or more characters with the "mark" property, and treats the sequence as an  grapheme cluster", and treats the sequence as an atomic group
 atomic group  
820  .\" HTML <a href="#atomicgroup">  .\" HTML <a href="#atomicgroup">
821  .\" </a>  .\" </a>
822  (see below).  (see below).
823  .\"  .\"
824  Characters with the "mark" property are typically accents that affect the  Up to and including release 8.31, PCRE matched an earlier, simpler definition
825  preceding character. None of them have codepoints less than 256, so in  that was equivalent to
826  8-bit non-UTF-8 mode \eX matches any one character.  .sp
827  .P    (?>\ePM\epM*)
828  Note that recent versions of Perl have changed \eX to match what Unicode calls  .sp
829  an "extended grapheme cluster", which has a more complicated definition.  That is, it matched a character without the "mark" property, followed by zero
830  .P  or more characters with the "mark" property. Characters with the "mark"
831  Matching characters by Unicode property is not fast, because PCRE has to search  property are typically non-spacing accents that affect the preceding character.
832  a structure that contains data for over fifteen thousand characters. That is  .P
833  why the traditional escape sequences such as \ed and \ew do not use Unicode  This simple definition was extended in Unicode to include more complicated
834  properties in PCRE by default, though you can make them do so by setting the  kinds of composite character by giving each character a grapheme breaking
835  PCRE_UCP option or by starting the pattern with (*UCP).  property, and creating rules that use these properties to define the boundaries
836    of extended grapheme clusters. In releases of PCRE later than 8.31, \eX matches
837    one of these clusters.
838    .P
839    \eX always matches at least one character. Then it decides whether to add
840    additional characters according to the following rules for ending a cluster:
841    .P
842    1. End at the end of the subject string.
843    .P
844    2. Do not end between CR and LF; otherwise end after any control character.
845    .P
846    3. Do not break Hangul (a Korean script) syllable sequences. Hangul characters
847    are of five types: L, V, T, LV, and LVT. An L character may be followed by an
848    L, V, LV, or LVT character; an LV or V character may be followed by a V or T
849    character; an LVT or T character may be follwed only by a T character.
850    .P
851    4. Do not end before extending characters or spacing marks. Characters with
852    the "mark" property always have the "extend" grapheme breaking property.
853    .P
854    5. Do not end after prepend characters.
855    .P
856    6. Otherwise, end the cluster.
857  .  .
858  .  .
859  .\" HTML <a name="extraprops"></a>  .\" HTML <a name="extraprops"></a>
860  .SS PCRE's additional properties  .SS PCRE's additional properties
861  .rs  .rs
862  .sp  .sp
863  As well as the standard Unicode properties described in the previous  As well as the standard Unicode properties described above, PCRE supports four
864  section, PCRE supports four more that make it possible to convert traditional  more that make it possible to convert traditional escape sequences such as \ew
865  escape sequences such as \ew and \es and POSIX character classes to use Unicode  and \es and POSIX character classes to use Unicode properties. PCRE uses these
866  properties. PCRE uses these non-standard, non-Perl properties internally when  non-standard, non-Perl properties internally when PCRE_UCP is set. However,
867  PCRE_UCP is set. They are:  they may also be used explicitly. These properties are:
868  .sp  .sp
869    Xan   Any alphanumeric character    Xan   Any alphanumeric character
870    Xps   Any POSIX space character    Xps   Any POSIX space character
# Line 819  PCRE_UCP is set. They are: Line 872  PCRE_UCP is set. They are:
872    Xwd   Any Perl "word" character    Xwd   Any Perl "word" character
873  .sp  .sp
874  Xan matches characters that have either the L (letter) or the N (number)  Xan matches characters that have either the L (letter) or the N (number)
875  property. Xps matches the characters tab, linefeed, vertical tab, formfeed, or  property. Xps matches the characters tab, linefeed, vertical tab, form feed, or
876  carriage return, and any other character that has the Z (separator) property.  carriage return, and any other character that has the Z (separator) property.
877  Xsp is the same as Xps, except that vertical tab is excluded. Xwd matches the  Xsp is the same as Xps, except that vertical tab is excluded. Xwd matches the
878  same characters as Xan, plus underscore.  same characters as Xan, plus underscore.
879    .P
880    There is another non-standard property, Xuc, which matches any character that
881    can be represented by a Universal Character Name in C++ and other programming
882    languages. These are the characters $, @, ` (grave accent), and all characters
883    with Unicode code points greater than or equal to U+00A0, except for the
884    surrogates U+D800 to U+DFFF. Note that most base (ASCII) characters are
885    excluded. (Universal Character Names are of the form \euHHHH or \eUHHHHHHHH
886    where H is a hexadecimal digit. Note that the Xuc property does not match these
887    sequences but the characters that they represent.)
888  .  .
889  .  .
890  .\" HTML <a name="resetmatchstart"></a>  .\" HTML <a name="resetmatchstart"></a>
# Line 928  regular expression. Line 990  regular expression.
990  .SH "CIRCUMFLEX AND DOLLAR"  .SH "CIRCUMFLEX AND DOLLAR"
991  .rs  .rs
992  .sp  .sp
993    The circumflex and dollar metacharacters are zero-width assertions. That is,
994    they test for a particular condition being true without consuming any
995    characters from the subject string.
996    .P
997  Outside a character class, in the default matching mode, the circumflex  Outside a character class, in the default matching mode, the circumflex
998  character is an assertion that is true only if the current matching point is  character is an assertion that is true only if the current matching point is at
999  at the start of the subject string. If the \fIstartoffset\fP argument of  the start of the subject string. If the \fIstartoffset\fP argument of
1000  \fBpcre_exec()\fP is non-zero, circumflex can never match if the PCRE_MULTILINE  \fBpcre_exec()\fP is non-zero, circumflex can never match if the PCRE_MULTILINE
1001  option is unset. Inside a character class, circumflex has an entirely different  option is unset. Inside a character class, circumflex has an entirely different
1002  meaning  meaning
# Line 947  constrained to match only at the start o Line 1013  constrained to match only at the start o
1013  "anchored" pattern. (There are also other constructs that can cause a pattern  "anchored" pattern. (There are also other constructs that can cause a pattern
1014  to be anchored.)  to be anchored.)
1015  .P  .P
1016  A dollar character is an assertion that is true only if the current matching  The dollar character is an assertion that is true only if the current matching
1017  point is at the end of the subject string, or immediately before a newline  point is at the end of the subject string, or immediately before a newline at
1018  at the end of the string (by default). Dollar need not be the last character of  the end of the string (by default). Note, however, that it does not actually
1019  the pattern if a number of alternatives are involved, but it should be the last  match the newline. Dollar need not be the last character of the pattern if a
1020  item in any branch in which it appears. Dollar has no special meaning in a  number of alternatives are involved, but it should be the last item in any
1021  character class.  branch in which it appears. Dollar has no special meaning in a character class.
1022  .P  .P
1023  The meaning of dollar can be changed so that it matches only at the very end of  The meaning of dollar can be changed so that it matches only at the very end of
1024  the string, by setting the PCRE_DOLLAR_ENDONLY option at compile time. This  the string, by setting the PCRE_DOLLAR_ENDONLY option at compile time. This
# Line 1013  name; PCRE does not support this. Line 1079  name; PCRE does not support this.
1079  .sp  .sp
1080  Outside a character class, the escape sequence \eC matches any one data unit,  Outside a character class, the escape sequence \eC matches any one data unit,
1081  whether or not a UTF mode is set. In the 8-bit library, one data unit is one  whether or not a UTF mode is set. In the 8-bit library, one data unit is one
1082  byte; in the 16-bit library it is a 16-bit unit. Unlike a dot, \eC always  byte; in the 16-bit library it is a 16-bit unit; in the 32-bit library it is
1083    a 32-bit unit. Unlike a dot, \eC always
1084  matches line-ending characters. The feature is provided in Perl in order to  matches line-ending characters. The feature is provided in Perl in order to
1085  match individual bytes in UTF-8 mode, but it is unclear how it can usefully be  match individual bytes in UTF-8 mode, but it is unclear how it can usefully be
1086  used. Because \eC breaks up characters into individual data units, matching one  used. Because \eC breaks up characters into individual data units, matching one
1087  unit with \eC in a UTF mode means that the rest of the string may start with a  unit with \eC in a UTF mode means that the rest of the string may start with a
1088  malformed UTF character. This has undefined results, because PCRE assumes that  malformed UTF character. This has undefined results, because PCRE assumes that
1089  it is dealing with valid UTF strings (and by default it checks this at the  it is dealing with valid UTF strings (and by default it checks this at the
1090  start of processing unless the PCRE_NO_UTF8_CHECK or PCRE_NO_UTF16_CHECK option  start of processing unless the PCRE_NO_UTF8_CHECK, PCRE_NO_UTF16_CHECK or
1091  is used).  PCRE_NO_UTF32_CHECK option is used).
1092  .P  .P
1093  PCRE does not allow \eC to appear in lookbehind assertions  PCRE does not allow \eC to appear in lookbehind assertions
1094  .\" HTML <a href="#lookbehind">  .\" HTML <a href="#lookbehind">
# Line 1080  circumflex is not an assertion; it still Line 1147  circumflex is not an assertion; it still
1147  string, and therefore it fails if the current pointer is at the end of the  string, and therefore it fails if the current pointer is at the end of the
1148  string.  string.
1149  .P  .P
1150  In UTF-8 (UTF-16) mode, characters with values greater than 255 (0xffff) can be  In UTF-8 (UTF-16, UTF-32) mode, characters with values greater than 255 (0xffff)
1151  included in a class as a literal string of data units, or by using the \ex{  can be included in a class as a literal string of data units, or by using the
1152  escaping mechanism.  \ex{ escaping mechanism.
1153  .P  .P
1154  When caseless matching is set, any letters in a class represent both their  When caseless matching is set, any letters in a class represent both their
1155  upper case and lower case versions, so for example, a caseless [aeiou] matches  upper case and lower case versions, so for example, a caseless [aeiou] matches
# Line 1295  the section entitled Line 1362  the section entitled
1362  .\" </a>  .\" </a>
1363  "Newline sequences"  "Newline sequences"
1364  .\"  .\"
1365  above. There are also the (*UTF8), (*UTF16), and (*UCP) leading sequences that  above. There are also the (*UTF8), (*UTF16),(*UTF32), and (*UCP) leading
1366  can be used to set UTF and Unicode property modes; they are equivalent to  sequences that can be used to set UTF and Unicode property modes; they are
1367  setting the PCRE_UTF8, PCRE_UTF16, and the PCRE_UCP options, respectively.  equivalent to setting the PCRE_UTF8, PCRE_UTF16, PCRE_UTF32 and the PCRE_UCP
1368    options, respectively. The (*UTF) sequence is a generic version that can be
1369    used with any of the libraries.
1370  .  .
1371  .  .
1372  .\" HTML <a name="subpattern"></a>  .\" HTML <a name="subpattern"></a>
# Line 1532  quantifier, but a literal string of four Line 1601  quantifier, but a literal string of four
1601  In UTF modes, quantifiers apply to characters rather than to individual data  In UTF modes, quantifiers apply to characters rather than to individual data
1602  units. Thus, for example, \ex{100}{2} matches two characters, each of  units. Thus, for example, \ex{100}{2} matches two characters, each of
1603  which is represented by a two-byte sequence in a UTF-8 string. Similarly,  which is represented by a two-byte sequence in a UTF-8 string. Similarly,
1604  \eX{3} matches three Unicode extended sequences, each of which may be several  \eX{3} matches three Unicode extended grapheme clusters, each of which may be
1605  data units long (and they may be of different lengths).  several data units long (and they may be of different lengths).
1606  .P  .P
1607  The quantifier {0} is permitted, causing the expression to behave as if the  The quantifier {0} is permitted, causing the expression to behave as if the
1608  previous item and the quantifier were not present. This may be useful for  previous item and the quantifier were not present. This may be useful for
# Line 1619  In cases where it is known that the subj Line 1688  In cases where it is known that the subj
1688  worth setting PCRE_DOTALL in order to obtain this optimization, or  worth setting PCRE_DOTALL in order to obtain this optimization, or
1689  alternatively using ^ to indicate anchoring explicitly.  alternatively using ^ to indicate anchoring explicitly.
1690  .P  .P
1691  However, there is one situation where the optimization cannot be used. When .*  However, there are some cases where the optimization cannot be used. When .*
1692  is inside capturing parentheses that are the subject of a back reference  is inside capturing parentheses that are the subject of a back reference
1693  elsewhere in the pattern, a match at the start may fail where a later one  elsewhere in the pattern, a match at the start may fail where a later one
1694  succeeds. Consider, for example:  succeeds. Consider, for example:
# Line 1629  succeeds. Consider, for example: Line 1698  succeeds. Consider, for example:
1698  If the subject is "xyz123abc123" the match point is the fourth character. For  If the subject is "xyz123abc123" the match point is the fourth character. For
1699  this reason, such a pattern is not implicitly anchored.  this reason, such a pattern is not implicitly anchored.
1700  .P  .P
1701    Another case where implicit anchoring is not applied is when the leading .* is
1702    inside an atomic group. Once again, a match at the start may fail where a later
1703    one succeeds. Consider this pattern:
1704    .sp
1705      (?>.*?a)b
1706    .sp
1707    It matches "ab" in the subject "aab". The use of the backtracking control verbs
1708    (*PRUNE) and (*SKIP) also disable this optimization.
1709    .P
1710  When a capturing subpattern is repeated, the value captured is the substring  When a capturing subpattern is repeated, the value captured is the substring
1711  that matched the final iteration. For example, after  that matched the final iteration. For example, after
1712  .sp  .sp
# Line 1843  Because there may be many capturing pare Line 1921  Because there may be many capturing pare
1921  following a backslash are taken as part of a potential back reference number.  following a backslash are taken as part of a potential back reference number.
1922  If the pattern continues with a digit character, some delimiter must be used to  If the pattern continues with a digit character, some delimiter must be used to
1923  terminate the back reference. If the PCRE_EXTENDED option is set, this can be  terminate the back reference. If the PCRE_EXTENDED option is set, this can be
1924  whitespace. Otherwise, the \eg{ syntax or an empty comment (see  white space. Otherwise, the \eg{ syntax or an empty comment (see
1925  .\" HTML <a href="#comments">  .\" HTML <a href="#comments">
1926  .\" </a>  .\" </a>
1927  "Comments"  "Comments"
# Line 2200  subroutines that can be referenced from Line 2278  subroutines that can be referenced from
2278  subroutines  subroutines
2279  .\"  .\"
2280  is described below.) For example, a pattern to match an IPv4 address such as  is described below.) For example, a pattern to match an IPv4 address such as
2281  "192.168.23.245" could be written like this (ignore whitespace and line  "192.168.23.245" could be written like this (ignore white space and line
2282  breaks):  breaks):
2283  .sp  .sp
2284    (?(DEFINE) (?<byte> 2[0-4]\ed | 25[0-5] | 1\ed\ed | [1-9]?\ed) )    (?(DEFINE) (?<byte> 2[0-4]\ed | 25[0-5] | 1\ed\ed | [1-9]?\ed) )
# Line 2550  same pair of parentheses when there is a Line 2628  same pair of parentheses when there is a
2628  PCRE provides a similar feature, but of course it cannot obey arbitrary Perl  PCRE provides a similar feature, but of course it cannot obey arbitrary Perl
2629  code. The feature is called "callout". The caller of PCRE provides an external  code. The feature is called "callout". The caller of PCRE provides an external
2630  function by putting its entry point in the global variable \fIpcre_callout\fP  function by putting its entry point in the global variable \fIpcre_callout\fP
2631  (8-bit library) or \fIpcre16_callout\fP (16-bit library). By default, this  (8-bit library) or \fIpcre[16|32]_callout\fP (16-bit or 32-bit library).
2632  variable contains NULL, which disables all calling out.  By default, this variable contains NULL, which disables all calling out.
2633  .P  .P
2634  Within a regular expression, (?C) indicates the points at which the external  Within a regular expression, (?C) indicates the points at which the external
2635  function is to be called. If you want to identify different callout points, you  function is to be called. If you want to identify different callout points, you
# Line 2599  exception: the name from a *(MARK), (*PR Line 2677  exception: the name from a *(MARK), (*PR
2677  a successful positive assertion \fIis\fP passed back when a match succeeds  a successful positive assertion \fIis\fP passed back when a match succeeds
2678  (compare capturing parentheses in assertions). Note that such subpatterns are  (compare capturing parentheses in assertions). Note that such subpatterns are
2679  processed as anchored at the point where they are tested. Note also that Perl's  processed as anchored at the point where they are tested. Note also that Perl's
2680  treatment of subroutines is different in some cases.  treatment of subroutines and assertions is different in some cases.
2681  .P  .P
2682  The new verbs make use of what was previously invalid syntax: an opening  The new verbs make use of what was previously invalid syntax: an opening
2683  parenthesis followed by an asterisk. They are generally of the form  parenthesis followed by an asterisk. They are generally of the form
2684  (*VERB) or (*VERB:NAME). Some may take either form, with differing behaviour,  (*VERB) or (*VERB:NAME). Some may take either form, with differing behaviour,
2685  depending on whether or not an argument is present. A name is any sequence of  depending on whether or not an argument is present. A name is any sequence of
2686  characters that does not include a closing parenthesis. If the name is empty,  characters that does not include a closing parenthesis. The maximum length of
2687  that is, if the closing parenthesis immediately follows the colon, the effect  name is 255 in the 8-bit library and 65535 in the 16-bit and 32-bit library.
2688  is as if the colon were not there. Any number of these verbs may occur in a  If the name is empty, that is, if the closing parenthesis immediately follows
2689  pattern.  the colon, the effect is as if the colon were not there. Any number of these
2690    verbs may occur in a pattern.
2691  .  .
2692  .  .
2693  .\" HTML <a name="nooptimize"></a>  .\" HTML <a name="nooptimize"></a>
# Line 2632  in the Line 2711  in the
2711  .\" HREF  .\" HREF
2712  \fBpcreapi\fP  \fBpcreapi\fP
2713  .\"  .\"
2714  documentation.  documentation.
2715  .P  .P
2716  Experiments with Perl suggest that it too has similar optimizations, sometimes  Experiments with Perl suggest that it too has similar optimizations, sometimes
2717  leading to anomalous results.  leading to anomalous results.
# Line 2726  attempts starting at "P" and then with a Line 2805  attempts starting at "P" and then with a
2805  (*MARK) item, but nevertheless do not reset it.  (*MARK) item, but nevertheless do not reset it.
2806  .P  .P
2807  If you are interested in (*MARK) values after failed matches, you should  If you are interested in (*MARK) values after failed matches, you should
2808  probably set the PCRE_NO_START_OPTIMIZE option  probably set the PCRE_NO_START_OPTIMIZE option
2809  .\" HTML <a href="#nooptimize">  .\" HTML <a href="#nooptimize">
2810  .\" </a>  .\" </a>
2811  (see above)  (see above)
2812  .\"  .\"
2813  to ensure that the match is always attempted.  to ensure that the match is always attempted.
2814  .  .
# Line 2893  overrides. Line 2972  overrides.
2972  .rs  .rs
2973  .sp  .sp
2974  \fBpcreapi\fP(3), \fBpcrecallout\fP(3), \fBpcrematching\fP(3),  \fBpcreapi\fP(3), \fBpcrecallout\fP(3), \fBpcrematching\fP(3),
2975  \fBpcresyntax\fP(3), \fBpcre\fP(3), \fBpcre16(3)\fP.  \fBpcresyntax\fP(3), \fBpcre\fP(3), \fBpcre16(3)\fP, \fBpcre32(3)\fP.
2976  .  .
2977  .  .
2978  .SH AUTHOR  .SH AUTHOR
# Line 2910  Cambridge CB2 3QH, England. Line 2989  Cambridge CB2 3QH, England.
2989  .rs  .rs
2990  .sp  .sp
2991  .nf  .nf
2992  Last updated: 14 April 2012  Last updated: 27 February 2013
2993  Copyright (c) 1997-2012 University of Cambridge.  Copyright (c) 1997-2013 University of Cambridge.
2994  .fi  .fi

Legend:
Removed from v.959  
changed lines
  Added in v.1260

  ViewVC Help
Powered by ViewVC 1.1.5