/[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 972 by ph10, Fri Jun 1 18:03:18 2012 UTC revision 1219 by ph10, Sun Nov 11 18:04:37 2012 UTC
# Line 1  Line 1 
1  .TH PCREPATTERN 3 "04 May 2012" "PCRE 8.31"  .TH PCREPATTERN 3 "11 November 2012" "PCRE 8.32"
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 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 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     Form feed    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 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 777  Unicode table. Line 804  Unicode table.
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.
806  .P  .P
807  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
808  Unicode sequence. \eX is equivalent to  multistage table lookup in order to find a character's property. That is why
809  .sp  the traditional escape sequences such as \ed and \ew do not use Unicode
810    (?>\ePM\epM*)  properties in PCRE by default, though you can make them do so by setting the
811    PCRE_UCP option or by starting the pattern with (*UCP).
812    .
813    .
814    .SS Extended grapheme clusters
815    .rs
816  .sp  .sp
817  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
818  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  
819  .\" HTML <a href="#atomicgroup">  .\" HTML <a href="#atomicgroup">
820  .\" </a>  .\" </a>
821  (see below).  (see below).
822  .\"  .\"
823  Characters with the "mark" property are typically accents that affect the  Up to and including release 8.31, PCRE matched an earlier, simpler definition
824  preceding character. None of them have codepoints less than 256, so in  that was equivalent to
825  8-bit non-UTF-8 mode \eX matches any one character.  .sp
826  .P    (?>\ePM\epM*)
827  Note that recent versions of Perl have changed \eX to match what Unicode calls  .sp
828  an "extended grapheme cluster", which has a more complicated definition.  That is, it matched a character without the "mark" property, followed by zero
829  .P  or more characters with the "mark" property. Characters with the "mark"
830  Matching characters by Unicode property is not fast, because PCRE has to search  property are typically non-spacing accents that affect the preceding character.
831  a structure that contains data for over fifteen thousand characters. That is  .P
832  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
833  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
834  PCRE_UCP option or by starting the pattern with (*UCP).  property, and creating rules that use these properties to define the boundaries
835    of extended grapheme clusters. In releases of PCRE later than 8.31, \eX matches
836    one of these clusters.
837    .P
838    \eX always matches at least one character. Then it decides whether to add
839    additional characters according to the following rules for ending a cluster:
840    .P
841    1. End at the end of the subject string.
842    .P
843    2. Do not end between CR and LF; otherwise end after any control character.
844    .P
845    3. Do not break Hangul (a Korean script) syllable sequences. Hangul characters
846    are of five types: L, V, T, LV, and LVT. An L character may be followed by an
847    L, V, LV, or LVT character; an LV or V character may be followed by a V or T
848    character; an LVT or T character may be follwed only by a T character.
849    .P
850    4. Do not end before extending characters or spacing marks. Characters with
851    the "mark" property always have the "extend" grapheme breaking property.
852    .P
853    5. Do not end after prepend characters.
854    .P
855    6. Otherwise, end the cluster.
856  .  .
857  .  .
858  .\" HTML <a name="extraprops"></a>  .\" HTML <a name="extraprops"></a>
859  .SS PCRE's additional properties  .SS PCRE's additional properties
860  .rs  .rs
861  .sp  .sp
862  As well as the standard Unicode properties described in the previous  As well as the standard Unicode properties described above, PCRE supports four
863  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
864  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
865  properties. PCRE uses these non-standard, non-Perl properties internally when  non-standard, non-Perl properties internally when PCRE_UCP is set. They are:
 PCRE_UCP is set. They are:  
866  .sp  .sp
867    Xan   Any alphanumeric character    Xan   Any alphanumeric character
868    Xps   Any POSIX space character    Xps   Any POSIX space character
# Line 928  regular expression. Line 979  regular expression.
979  .SH "CIRCUMFLEX AND DOLLAR"  .SH "CIRCUMFLEX AND DOLLAR"
980  .rs  .rs
981  .sp  .sp
982    The circumflex and dollar metacharacters are zero-width assertions. That is,
983    they test for a particular condition being true without consuming any
984    characters from the subject string.
985    .P
986  Outside a character class, in the default matching mode, the circumflex  Outside a character class, in the default matching mode, the circumflex
987  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
988  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
989  \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
990  option is unset. Inside a character class, circumflex has an entirely different  option is unset. Inside a character class, circumflex has an entirely different
991  meaning  meaning
# Line 947  constrained to match only at the start o Line 1002  constrained to match only at the start o
1002  "anchored" pattern. (There are also other constructs that can cause a pattern  "anchored" pattern. (There are also other constructs that can cause a pattern
1003  to be anchored.)  to be anchored.)
1004  .P  .P
1005  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
1006  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
1007  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
1008  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
1009  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
1010  character class.  branch in which it appears. Dollar has no special meaning in a character class.
1011  .P  .P
1012  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
1013  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 1068  name; PCRE does not support this.
1068  .sp  .sp
1069  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,
1070  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
1071  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
1072    a 32-bit unit. Unlike a dot, \eC always
1073  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
1074  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
1075  used. Because \eC breaks up characters into individual data units, matching one  used. Because \eC breaks up characters into individual data units, matching one
1076  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
1077  malformed UTF character. This has undefined results, because PCRE assumes that  malformed UTF character. This has undefined results, because PCRE assumes that
1078  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
1079  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
1080  is used).  PCRE_NO_UTF32_CHECK option is used).
1081  .P  .P
1082  PCRE does not allow \eC to appear in lookbehind assertions  PCRE does not allow \eC to appear in lookbehind assertions
1083  .\" HTML <a href="#lookbehind">  .\" HTML <a href="#lookbehind">
# Line 1080  circumflex is not an assertion; it still Line 1136  circumflex is not an assertion; it still
1136  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
1137  string.  string.
1138  .P  .P
1139  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)
1140  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
1141  escaping mechanism.  \ex{ escaping mechanism.
1142  .P  .P
1143  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
1144  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 1351  the section entitled
1351  .\" </a>  .\" </a>
1352  "Newline sequences"  "Newline sequences"
1353  .\"  .\"
1354  above. There are also the (*UTF8), (*UTF16), and (*UCP) leading sequences that  above. There are also the (*UTF8), (*UTF16),(*UTF32), and (*UCP) leading
1355  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
1356  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
1357    options, respectively. The (*UTF) sequence is a generic version that can be
1358    used with any of the libraries.
1359  .  .
1360  .  .
1361  .\" HTML <a name="subpattern"></a>  .\" HTML <a name="subpattern"></a>
# Line 1532  quantifier, but a literal string of four Line 1590  quantifier, but a literal string of four
1590  In UTF modes, quantifiers apply to characters rather than to individual data  In UTF modes, quantifiers apply to characters rather than to individual data
1591  units. Thus, for example, \ex{100}{2} matches two characters, each of  units. Thus, for example, \ex{100}{2} matches two characters, each of
1592  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,
1593  \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
1594  data units long (and they may be of different lengths).  several data units long (and they may be of different lengths).
1595  .P  .P
1596  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
1597  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 1677  In cases where it is known that the subj
1677  worth setting PCRE_DOTALL in order to obtain this optimization, or  worth setting PCRE_DOTALL in order to obtain this optimization, or
1678  alternatively using ^ to indicate anchoring explicitly.  alternatively using ^ to indicate anchoring explicitly.
1679  .P  .P
1680  However, there is one situation where the optimization cannot be used. When .*  However, there are some cases where the optimization cannot be used. When .*
1681  is inside capturing parentheses that are the subject of a back reference  is inside capturing parentheses that are the subject of a back reference
1682  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
1683  succeeds. Consider, for example:  succeeds. Consider, for example:
# Line 1629  succeeds. Consider, for example: Line 1687  succeeds. Consider, for example:
1687  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
1688  this reason, such a pattern is not implicitly anchored.  this reason, such a pattern is not implicitly anchored.
1689  .P  .P
1690    Another case where implicit anchoring is not applied is when the leading .* is
1691    inside an atomic group. Once again, a match at the start may fail where a later
1692    one succeeds. Consider this pattern:
1693    .sp
1694      (?>.*?a)b
1695    .sp
1696    It matches "ab" in the subject "aab". The use of the backtracking control verbs
1697    (*PRUNE) and (*SKIP) also disable this optimization.
1698    .P
1699  When a capturing subpattern is repeated, the value captured is the substring  When a capturing subpattern is repeated, the value captured is the substring
1700  that matched the final iteration. For example, after  that matched the final iteration. For example, after
1701  .sp  .sp
# Line 2550  same pair of parentheses when there is a Line 2617  same pair of parentheses when there is a
2617  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
2618  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
2619  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
2620  (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).
2621  variable contains NULL, which disables all calling out.  By default, this variable contains NULL, which disables all calling out.
2622  .P  .P
2623  Within a regular expression, (?C) indicates the points at which the external  Within a regular expression, (?C) indicates the points at which the external
2624  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 2606  parenthesis followed by an asterisk. The Line 2673  parenthesis followed by an asterisk. The
2673  (*VERB) or (*VERB:NAME). Some may take either form, with differing behaviour,  (*VERB) or (*VERB:NAME). Some may take either form, with differing behaviour,
2674  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
2675  characters that does not include a closing parenthesis. The maximum length of  characters that does not include a closing parenthesis. The maximum length of
2676  name is 255 in the 8-bit library and 65535 in the 16-bit library. If the name  name is 255 in the 8-bit library and 65535 in the 16-bit and 32-bit library.
2677  is empty, that is, if the closing parenthesis immediately follows the colon,  If the name is empty, that is, if the closing parenthesis immediately follows
2678  the effect is as if the colon were not there. Any number of these verbs may  the colon, the effect is as if the colon were not there. Any number of these
2679  occur in a pattern.  verbs may occur in a pattern.
2680  .  .
2681  .  .
2682  .\" HTML <a name="nooptimize"></a>  .\" HTML <a name="nooptimize"></a>
# Line 2633  in the Line 2700  in the
2700  .\" HREF  .\" HREF
2701  \fBpcreapi\fP  \fBpcreapi\fP
2702  .\"  .\"
2703  documentation.  documentation.
2704  .P  .P
2705  Experiments with Perl suggest that it too has similar optimizations, sometimes  Experiments with Perl suggest that it too has similar optimizations, sometimes
2706  leading to anomalous results.  leading to anomalous results.
# Line 2727  attempts starting at "P" and then with a Line 2794  attempts starting at "P" and then with a
2794  (*MARK) item, but nevertheless do not reset it.  (*MARK) item, but nevertheless do not reset it.
2795  .P  .P
2796  If you are interested in (*MARK) values after failed matches, you should  If you are interested in (*MARK) values after failed matches, you should
2797  probably set the PCRE_NO_START_OPTIMIZE option  probably set the PCRE_NO_START_OPTIMIZE option
2798  .\" HTML <a href="#nooptimize">  .\" HTML <a href="#nooptimize">
2799  .\" </a>  .\" </a>
2800  (see above)  (see above)
2801  .\"  .\"
2802  to ensure that the match is always attempted.  to ensure that the match is always attempted.
2803  .  .
# Line 2894  overrides. Line 2961  overrides.
2961  .rs  .rs
2962  .sp  .sp
2963  \fBpcreapi\fP(3), \fBpcrecallout\fP(3), \fBpcrematching\fP(3),  \fBpcreapi\fP(3), \fBpcrecallout\fP(3), \fBpcrematching\fP(3),
2964  \fBpcresyntax\fP(3), \fBpcre\fP(3), \fBpcre16(3)\fP.  \fBpcresyntax\fP(3), \fBpcre\fP(3), \fBpcre16(3)\fP, \fBpcre32(3)\fP.
2965  .  .
2966  .  .
2967  .SH AUTHOR  .SH AUTHOR
# Line 2911  Cambridge CB2 3QH, England. Line 2978  Cambridge CB2 3QH, England.
2978  .rs  .rs
2979  .sp  .sp
2980  .nf  .nf
2981  Last updated: 01 June 2012  Last updated: 11 November 2012
2982  Copyright (c) 1997-2012 University of Cambridge.  Copyright (c) 1997-2012 University of Cambridge.
2983  .fi  .fi

Legend:
Removed from v.972  
changed lines
  Added in v.1219

  ViewVC Help
Powered by ViewVC 1.1.5