/[pcre]/code/trunk/doc/pcre.txt
ViewVC logotype

Diff of /code/trunk/doc/pcre.txt

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

revision 99 by ph10, Tue Mar 6 12:27:42 2007 UTC revision 208 by ph10, Mon Aug 6 15:23:29 2007 UTC
# Line 45  INTRODUCTION Line 45  INTRODUCTION
45    
46         Details of exactly which Perl regular expression features are  and  are         Details of exactly which Perl regular expression features are  and  are
47         not supported by PCRE are given in separate documents. See the pcrepat-         not supported by PCRE are given in separate documents. See the pcrepat-
48         tern and pcrecompat pages.         tern and pcrecompat pages. There is a syntax summary in the  pcresyntax
49           page.
50    
51         Some features of PCRE can be included, excluded, or  changed  when  the         Some  features  of  PCRE can be included, excluded, or changed when the
52         library  is  built.  The pcre_config() function makes it possible for a         library is built. The pcre_config() function makes it  possible  for  a
53         client to discover which features are  available.  The  features  them-         client  to  discover  which  features are available. The features them-
54         selves  are described in the pcrebuild page. Documentation about build-         selves are described in the pcrebuild page. Documentation about  build-
55         ing PCRE for various operating systems can be found in the README  file         ing  PCRE for various operating systems can be found in the README file
56         in the source distribution.         in the source distribution.
57    
58         The  library  contains  a number of undocumented internal functions and         The library contains a number of undocumented  internal  functions  and
59         data tables that are used by more than one  of  the  exported  external         data  tables  that  are  used by more than one of the exported external
60         functions,  but  which  are  not  intended for use by external callers.         functions, but which are not intended  for  use  by  external  callers.
61         Their names all begin with "_pcre_", which hopefully will  not  provoke         Their  names  all begin with "_pcre_", which hopefully will not provoke
62         any name clashes. In some environments, it is possible to control which         any name clashes. In some environments, it is possible to control which
63         external symbols are exported when a shared library is  built,  and  in         external  symbols  are  exported when a shared library is built, and in
64         these cases the undocumented symbols are not exported.         these cases the undocumented symbols are not exported.
65    
66    
67  USER DOCUMENTATION  USER DOCUMENTATION
68    
69         The  user  documentation  for PCRE comprises a number of different sec-         The user documentation for PCRE comprises a number  of  different  sec-
70         tions. In the "man" format, each of these is a separate "man page".  In         tions.  In the "man" format, each of these is a separate "man page". In
71         the  HTML  format, each is a separate page, linked from the index page.         the HTML format, each is a separate page, linked from the  index  page.
72         In the plain text format, all the sections are concatenated,  for  ease         In  the  plain text format, all the sections are concatenated, for ease
73         of searching. The sections are as follows:         of searching. The sections are as follows:
74    
75           pcre              this document           pcre              this document
76             pcre-config       show PCRE installation configuration information
77           pcreapi           details of PCRE's native C API           pcreapi           details of PCRE's native C API
78           pcrebuild         options for building PCRE           pcrebuild         options for building PCRE
79           pcrecallout       details of the callout feature           pcrecallout       details of the callout feature
# Line 82  USER DOCUMENTATION Line 84  USER DOCUMENTATION
84           pcrepartial       details of the partial matching facility           pcrepartial       details of the partial matching facility
85           pcrepattern       syntax and semantics of supported           pcrepattern       syntax and semantics of supported
86                               regular expressions                               regular expressions
87             pcresyntax        quick syntax reference
88           pcreperform       discussion of performance issues           pcreperform       discussion of performance issues
89           pcreposix         the POSIX-compatible C API           pcreposix         the POSIX-compatible C API
90           pcreprecompile    details of saving and re-using precompiled patterns           pcreprecompile    details of saving and re-using precompiled patterns
# Line 89  USER DOCUMENTATION Line 92  USER DOCUMENTATION
92           pcrestack         discussion of stack usage           pcrestack         discussion of stack usage
93           pcretest          description of the pcretest testing command           pcretest          description of the pcretest testing command
94    
95         In addition, in the "man" and HTML formats, there is a short  page  for         In  addition,  in the "man" and HTML formats, there is a short page for
96         each C library function, listing its arguments and results.         each C library function, listing its arguments and results.
97    
98    
99  LIMITATIONS  LIMITATIONS
100    
101         There  are some size limitations in PCRE but it is hoped that they will         There are some size limitations in PCRE but it is hoped that they  will
102         never in practice be relevant.         never in practice be relevant.
103    
104         The maximum length of a compiled pattern is 65539 (sic) bytes  if  PCRE         The  maximum  length of a compiled pattern is 65539 (sic) bytes if PCRE
105         is compiled with the default internal linkage size of 2. If you want to         is compiled with the default internal linkage size of 2. If you want to
106         process regular expressions that are truly enormous,  you  can  compile         process  regular  expressions  that are truly enormous, you can compile
107         PCRE  with  an  internal linkage size of 3 or 4 (see the README file in         PCRE with an internal linkage size of 3 or 4 (see the  README  file  in
108         the source distribution and the pcrebuild documentation  for  details).         the  source  distribution and the pcrebuild documentation for details).
109         In  these  cases the limit is substantially larger.  However, the speed         In these cases the limit is substantially larger.  However,  the  speed
110         of execution is slower.         of execution is slower.
111    
112         All values in repeating quantifiers must be less than 65536. The  maxi-         All values in repeating quantifiers must be less than 65536.
        mum  compiled  length  of  subpattern  with an explicit repeat count is  
        30000 bytes. The maximum number of capturing subpatterns is 65535.  
113    
114         There is no limit to the number of parenthesized subpatterns, but there         There is no limit to the number of parenthesized subpatterns, but there
115         can be no more than 65535 capturing subpatterns.         can be no more than 65535 capturing subpatterns.
# Line 116  LIMITATIONS Line 117  LIMITATIONS
117         The maximum length of name for a named subpattern is 32 characters, and         The maximum length of name for a named subpattern is 32 characters, and
118         the maximum number of named subpatterns is 10000.         the maximum number of named subpatterns is 10000.
119    
120         The maximum length of a subject string is the largest  positive  number         The  maximum  length of a subject string is the largest positive number
121         that  an integer variable can hold. However, when using the traditional         that an integer variable can hold. However, when using the  traditional
122         matching function, PCRE uses recursion to handle subpatterns and indef-         matching function, PCRE uses recursion to handle subpatterns and indef-
123         inite  repetition.  This means that the available stack space may limit         inite repetition.  This means that the available stack space may  limit
124         the size of a subject string that can be processed by certain patterns.         the size of a subject string that can be processed by certain patterns.
125         For a discussion of stack issues, see the pcrestack documentation.         For a discussion of stack issues, see the pcrestack documentation.
126    
127    
128  UTF-8 AND UNICODE PROPERTY SUPPORT  UTF-8 AND UNICODE PROPERTY SUPPORT
129    
130         From  release  3.3,  PCRE  has  had  some support for character strings         From release 3.3, PCRE has  had  some  support  for  character  strings
131         encoded in the UTF-8 format. For release 4.0 this was greatly  extended         encoded  in the UTF-8 format. For release 4.0 this was greatly extended
132         to  cover  most common requirements, and in release 5.0 additional sup-         to cover most common requirements, and in release 5.0  additional  sup-
133         port for Unicode general category properties was added.         port for Unicode general category properties was added.
134    
135         In order process UTF-8 strings, you must build PCRE  to  include  UTF-8         In  order  process  UTF-8 strings, you must build PCRE to include UTF-8
136         support  in  the  code,  and, in addition, you must call pcre_compile()         support in the code, and, in addition,  you  must  call  pcre_compile()
137         with the PCRE_UTF8 option flag. When you do this, both the pattern  and         with  the PCRE_UTF8 option flag. When you do this, both the pattern and
138         any  subject  strings  that are matched against it are treated as UTF-8         any subject strings that are matched against it are  treated  as  UTF-8
139         strings instead of just strings of bytes.         strings instead of just strings of bytes.
140    
141         If you compile PCRE with UTF-8 support, but do not use it at run  time,         If  you compile PCRE with UTF-8 support, but do not use it at run time,
142         the  library will be a bit bigger, but the additional run time overhead         the library will be a bit bigger, but the additional run time  overhead
143         is limited to testing the PCRE_UTF8 flag occasionally, so should not be         is limited to testing the PCRE_UTF8 flag occasionally, so should not be
144         very big.         very big.
145    
146         If PCRE is built with Unicode character property support (which implies         If PCRE is built with Unicode character property support (which implies
147         UTF-8 support), the escape sequences \p{..}, \P{..}, and  \X  are  sup-         UTF-8  support),  the  escape sequences \p{..}, \P{..}, and \X are sup-
148         ported.  The available properties that can be tested are limited to the         ported.  The available properties that can be tested are limited to the
149         general category properties such as Lu for an upper case letter  or  Nd         general  category  properties such as Lu for an upper case letter or Nd
150         for  a  decimal number, the Unicode script names such as Arabic or Han,         for a decimal number, the Unicode script names such as Arabic  or  Han,
151         and the derived properties Any and L&. A full  list  is  given  in  the         and  the  derived  properties  Any  and L&. A full list is given in the
152         pcrepattern documentation. Only the short names for properties are sup-         pcrepattern documentation. Only the short names for properties are sup-
153         ported. For example, \p{L} matches a letter. Its Perl synonym,  \p{Let-         ported.  For example, \p{L} matches a letter. Its Perl synonym, \p{Let-
154         ter},  is  not  supported.   Furthermore,  in Perl, many properties may         ter}, is not supported.  Furthermore,  in  Perl,  many  properties  may
155         optionally be prefixed by "Is", for compatibility with Perl  5.6.  PCRE         optionally  be  prefixed by "Is", for compatibility with Perl 5.6. PCRE
156         does not support this.         does not support this.
157    
158         The following comments apply when PCRE is running in UTF-8 mode:         The following comments apply when PCRE is running in UTF-8 mode:
159    
160         1.  When you set the PCRE_UTF8 flag, the strings passed as patterns and         1. When you set the PCRE_UTF8 flag, the strings passed as patterns  and
161         subjects are checked for validity on entry to the  relevant  functions.         subjects  are  checked for validity on entry to the relevant functions.
162         If an invalid UTF-8 string is passed, an error return is given. In some         If an invalid UTF-8 string is passed, an error return is given. In some
163         situations, you may already know  that  your  strings  are  valid,  and         situations,  you  may  already  know  that  your strings are valid, and
164         therefore want to skip these checks in order to improve performance. If         therefore want to skip these checks in order to improve performance. If
165         you set the PCRE_NO_UTF8_CHECK flag at compile time  or  at  run  time,         you  set  the  PCRE_NO_UTF8_CHECK  flag at compile time or at run time,
166         PCRE  assumes  that  the  pattern or subject it is given (respectively)         PCRE assumes that the pattern or subject  it  is  given  (respectively)
167         contains only valid UTF-8 codes. In this case, it does not diagnose  an         contains  only valid UTF-8 codes. In this case, it does not diagnose an
168         invalid  UTF-8 string. If you pass an invalid UTF-8 string to PCRE when         invalid UTF-8 string. If you pass an invalid UTF-8 string to PCRE  when
169         PCRE_NO_UTF8_CHECK is set, the results are undefined. Your program  may         PCRE_NO_UTF8_CHECK  is set, the results are undefined. Your program may
170         crash.         crash.
171    
172         2.  An  unbraced  hexadecimal  escape sequence (such as \xb3) matches a         2. An unbraced hexadecimal escape sequence (such  as  \xb3)  matches  a
173         two-byte UTF-8 character if the value is greater than 127.         two-byte UTF-8 character if the value is greater than 127.
174    
175         3. Octal numbers up to \777 are recognized, and  match  two-byte  UTF-8         3.  Octal  numbers  up to \777 are recognized, and match two-byte UTF-8
176         characters for values greater than \177.         characters for values greater than \177.
177    
178         4.  Repeat quantifiers apply to complete UTF-8 characters, not to indi-         4. Repeat quantifiers apply to complete UTF-8 characters, not to  indi-
179         vidual bytes, for example: \x{100}{3}.         vidual bytes, for example: \x{100}{3}.
180    
181         5. The dot metacharacter matches one UTF-8 character instead of a  sin-         5.  The dot metacharacter matches one UTF-8 character instead of a sin-
182         gle byte.         gle byte.
183    
184         6.  The  escape sequence \C can be used to match a single byte in UTF-8         6. The escape sequence \C can be used to match a single byte  in  UTF-8
185         mode, but its use can lead to some strange effects.  This  facility  is         mode,  but  its  use can lead to some strange effects. This facility is
186         not available in the alternative matching function, pcre_dfa_exec().         not available in the alternative matching function, pcre_dfa_exec().
187    
188         7.  The  character escapes \b, \B, \d, \D, \s, \S, \w, and \W correctly         7. The character escapes \b, \B, \d, \D, \s, \S, \w, and  \W  correctly
189         test characters of any code value, but the characters that PCRE  recog-         test  characters of any code value, but the characters that PCRE recog-
190         nizes  as  digits,  spaces,  or  word characters remain the same set as         nizes as digits, spaces, or word characters  remain  the  same  set  as
191         before, all with values less than 256. This remains true even when PCRE         before, all with values less than 256. This remains true even when PCRE
192         includes  Unicode  property support, because to do otherwise would slow         includes Unicode property support, because to do otherwise  would  slow
193         down PCRE in many common cases. If you really want to test for a  wider         down  PCRE in many common cases. If you really want to test for a wider
194         sense  of,  say,  "digit",  you must use Unicode property tests such as         sense of, say, "digit", you must use Unicode  property  tests  such  as
195         \p{Nd}.         \p{Nd}.
196    
197         8. Similarly, characters that match the POSIX named  character  classes         8.  Similarly,  characters that match the POSIX named character classes
198         are all low-valued characters.         are all low-valued characters.
199    
200         9.  Case-insensitive  matching  applies only to characters whose values         9. However, the Perl 5.10 horizontal and vertical  whitespace  matching
201         are less than 128, unless PCRE is built with Unicode property  support.         escapes (\h, \H, \v, and \V) do match all the appropriate Unicode char-
202         Even  when  Unicode  property support is available, PCRE still uses its         acters.
203         own character tables when checking the case of  low-valued  characters,  
204         so  as not to degrade performance.  The Unicode property information is         10. Case-insensitive matching applies only to characters  whose  values
205           are  less than 128, unless PCRE is built with Unicode property support.
206           Even when Unicode property support is available, PCRE  still  uses  its
207           own  character  tables when checking the case of low-valued characters,
208           so as not to degrade performance.  The Unicode property information  is
209         used only for characters with higher values. Even when Unicode property         used only for characters with higher values. Even when Unicode property
210         support is available, PCRE supports case-insensitive matching only when         support is available, PCRE supports case-insensitive matching only when
211         there is a one-to-one mapping between a letter's  cases.  There  are  a         there  is  a  one-to-one  mapping between a letter's cases. There are a
212         small  number  of  many-to-one  mappings in Unicode; these are not sup-         small number of many-to-one mappings in Unicode;  these  are  not  sup-
213         ported by PCRE.         ported by PCRE.
214    
215    
# Line 214  AUTHOR Line 219  AUTHOR
219         University Computing Service         University Computing Service
220         Cambridge CB2 3QH, England.         Cambridge CB2 3QH, England.
221    
222         Putting an actual email address here seems to have been a spam  magnet,         Putting  an actual email address here seems to have been a spam magnet,
223         so I've taken it away. If you want to email me, use my initial and sur-         so I've taken it away. If you want to email me, use  my  two  initials,
224         name, separated by a dot, at the domain ucs.cam.ac.uk.         followed by the two digits 10, at the domain cam.ac.uk.
225    
226    
227  REVISION  REVISION
228    
229         Last updated: 06 March 2007         Last updated: 06 August 2007
230         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
231  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
232    
233    
234  PCREBUILD(3)                                                      PCREBUILD(3)  PCREBUILD(3)                                                      PCREBUILD(3)
235    
236    
# Line 244  PCRE BUILD-TIME OPTIONS Line 249  PCRE BUILD-TIME OPTIONS
249    
250           ./configure --help           ./configure --help
251    
252         The following sections describe certain options whose names begin  with         The following sections include  descriptions  of  options  whose  names
253         --enable  or  --disable. These settings specify changes to the defaults         begin with --enable or --disable. These settings specify changes to the
254         for the configure command. Because of the  way  that  configure  works,         defaults for the configure command. Because of the way  that  configure
255         --enable  and  --disable  always  come  in  pairs, so the complementary         works,  --enable  and --disable always come in pairs, so the complemen-
256         option always exists as well, but as it specifies the  default,  it  is         tary option always exists as well, but as it specifies the default,  it
257         not described.         is not described.
258    
259    
260  C++ SUPPORT  C++ SUPPORT
# Line 288  UNICODE CHARACTER PROPERTY SUPPORT Line 293  UNICODE CHARACTER PROPERTY SUPPORT
293         to the configure command. This implies UTF-8 support, even if you  have         to the configure command. This implies UTF-8 support, even if you  have
294         not explicitly requested it.         not explicitly requested it.
295    
296         Including  Unicode  property  support  adds around 90K of tables to the         Including  Unicode  property  support  adds around 30K of tables to the
297         PCRE library, approximately doubling its size. Only the  general  cate-         PCRE library. Only the general category properties such as  Lu  and  Nd
298         gory  properties  such as Lu and Nd are supported. Details are given in         are supported. Details are given in the pcrepattern documentation.
        the pcrepattern documentation.  
299    
300    
301  CODE VALUE OF NEWLINE  CODE VALUE OF NEWLINE
302    
303         By default, PCRE interprets character 10 (linefeed, LF)  as  indicating         By  default,  PCRE interprets character 10 (linefeed, LF) as indicating
304         the  end  of  a line. This is the normal newline character on Unix-like         the end of a line. This is the normal newline  character  on  Unix-like
305         systems. You can compile PCRE to use character 13 (carriage return, CR)         systems. You can compile PCRE to use character 13 (carriage return, CR)
306         instead, by adding         instead, by adding
307    
308           --enable-newline-is-cr           --enable-newline-is-cr
309    
310         to  the  configure  command.  There  is  also  a --enable-newline-is-lf         to the  configure  command.  There  is  also  a  --enable-newline-is-lf
311         option, which explicitly specifies linefeed as the newline character.         option, which explicitly specifies linefeed as the newline character.
312    
313         Alternatively, you can specify that line endings are to be indicated by         Alternatively, you can specify that line endings are to be indicated by
# Line 313  CODE VALUE OF NEWLINE Line 317  CODE VALUE OF NEWLINE
317    
318         to the configure command. There is a fourth option, specified by         to the configure command. There is a fourth option, specified by
319    
320             --enable-newline-is-anycrlf
321    
322           which causes PCRE to recognize any of the three sequences  CR,  LF,  or
323           CRLF as indicating a line ending. Finally, a fifth option, specified by
324    
325           --enable-newline-is-any           --enable-newline-is-any
326    
327         which causes PCRE to recognize any Unicode newline sequence.         causes PCRE to recognize any Unicode newline sequence.
328    
329         Whatever  line  ending convention is selected when PCRE is built can be         Whatever line ending convention is selected when PCRE is built  can  be
330         overridden when the library functions are called. At build time  it  is         overridden  when  the library functions are called. At build time it is
331         conventional to use the standard for your operating system.         conventional to use the standard for your operating system.
332    
333    
334  BUILDING SHARED AND STATIC LIBRARIES  BUILDING SHARED AND STATIC LIBRARIES
335    
336         The  PCRE building process uses libtool to build both shared and static         The PCRE building process uses libtool to build both shared and  static
337         Unix libraries by default. You can suppress one of these by adding  one         Unix  libraries by default. You can suppress one of these by adding one
338         of         of
339    
340           --disable-shared           --disable-shared
# Line 337  BUILDING SHARED AND STATIC LIBRARIES Line 346  BUILDING SHARED AND STATIC LIBRARIES
346  POSIX MALLOC USAGE  POSIX MALLOC USAGE
347    
348         When PCRE is called through the POSIX interface (see the pcreposix doc-         When PCRE is called through the POSIX interface (see the pcreposix doc-
349         umentation), additional working storage is  required  for  holding  the         umentation),  additional  working  storage  is required for holding the
350         pointers  to capturing substrings, because PCRE requires three integers         pointers to capturing substrings, because PCRE requires three  integers
351         per substring, whereas the POSIX interface provides only  two.  If  the         per  substring,  whereas  the POSIX interface provides only two. If the
352         number of expected substrings is small, the wrapper function uses space         number of expected substrings is small, the wrapper function uses space
353         on the stack, because this is faster than using malloc() for each call.         on the stack, because this is faster than using malloc() for each call.
354         The default threshold above which the stack is no longer used is 10; it         The default threshold above which the stack is no longer used is 10; it
# Line 352  POSIX MALLOC USAGE Line 361  POSIX MALLOC USAGE
361    
362  HANDLING VERY LARGE PATTERNS  HANDLING VERY LARGE PATTERNS
363    
364         Within a compiled pattern, offset values are used  to  point  from  one         Within  a  compiled  pattern,  offset values are used to point from one
365         part  to another (for example, from an opening parenthesis to an alter-         part to another (for example, from an opening parenthesis to an  alter-
366         nation metacharacter). By default, two-byte values are used  for  these         nation  metacharacter).  By default, two-byte values are used for these
367         offsets,  leading  to  a  maximum size for a compiled pattern of around         offsets, leading to a maximum size for a  compiled  pattern  of  around
368         64K. This is sufficient to handle all but the most  gigantic  patterns.         64K.  This  is sufficient to handle all but the most gigantic patterns.
369         Nevertheless,  some  people do want to process enormous patterns, so it         Nevertheless, some people do want to process enormous patterns,  so  it
370         is possible to compile PCRE to use three-byte or four-byte  offsets  by         is  possible  to compile PCRE to use three-byte or four-byte offsets by
371         adding a setting such as         adding a setting such as
372    
373           --with-link-size=3           --with-link-size=3
374    
375         to  the  configure  command.  The value given must be 2, 3, or 4. Using         to the configure command. The value given must be 2,  3,  or  4.  Using
376         longer offsets slows down the operation of PCRE because it has to  load         longer  offsets slows down the operation of PCRE because it has to load
377         additional bytes when handling them.         additional bytes when handling them.
378    
        If  you  build  PCRE with an increased link size, test 2 (and test 5 if  
        you are using UTF-8) will fail. Part of the output of these tests is  a  
        representation  of the compiled pattern, and this changes with the link  
        size.  
   
379    
380  AVOIDING EXCESSIVE STACK USAGE  AVOIDING EXCESSIVE STACK USAGE
381    
# Line 390  AVOIDING EXCESSIVE STACK USAGE Line 394  AVOIDING EXCESSIVE STACK USAGE
394    
395         to  the  configure  command. With this configuration, PCRE will use the         to  the  configure  command. With this configuration, PCRE will use the
396         pcre_stack_malloc and pcre_stack_free variables to call memory  manage-         pcre_stack_malloc and pcre_stack_free variables to call memory  manage-
397         ment  functions.  Separate  functions are provided because the usage is         ment  functions. By default these point to malloc() and free(), but you
398         very predictable: the block sizes requested are always  the  same,  and         can replace the pointers so that your own functions are used.
399         the  blocks  are always freed in reverse order. A calling program might  
400         be able to implement optimized functions that perform better  than  the         Separate functions are  provided  rather  than  using  pcre_malloc  and
401         standard  malloc()  and  free()  functions.  PCRE  runs noticeably more         pcre_free  because  the  usage  is  very  predictable:  the block sizes
402         slowly when built in this way. This option affects only the pcre_exec()         requested are always the same, and  the  blocks  are  always  freed  in
403         function; it is not relevant for the the pcre_dfa_exec() function.         reverse  order.  A calling program might be able to implement optimized
404           functions that perform better  than  malloc()  and  free().  PCRE  runs
405           noticeably more slowly when built in this way. This option affects only
406           the  pcre_exec()  function;  it   is   not   relevant   for   the   the
407           pcre_dfa_exec() function.
408    
409    
410  LIMITING PCRE RESOURCE USAGE  LIMITING PCRE RESOURCE USAGE
# Line 429  LIMITING PCRE RESOURCE USAGE Line 437  LIMITING PCRE RESOURCE USAGE
437         time.         time.
438    
439    
440    CREATING CHARACTER TABLES AT BUILD TIME
441    
442           PCRE uses fixed tables for processing characters whose code values  are
443           less  than 256. By default, PCRE is built with a set of tables that are
444           distributed in the file pcre_chartables.c.dist. These  tables  are  for
445           ASCII codes only. If you add
446    
447             --enable-rebuild-chartables
448    
449           to  the  configure  command, the distributed tables are no longer used.
450           Instead, a program called dftables is compiled and  run.  This  outputs
451           the source for new set of tables, created in the default locale of your
452           C runtime system. (This method of replacing the tables does not work if
453           you  are cross compiling, because dftables is run on the local host. If
454           you need to create alternative tables when cross  compiling,  you  will
455           have to do so "by hand".)
456    
457    
458  USING EBCDIC CODE  USING EBCDIC CODE
459    
460         PCRE assumes by default that it will run in an  environment  where  the         PCRE  assumes  by  default that it will run in an environment where the
461         character  code  is  ASCII  (or Unicode, which is a superset of ASCII).         character code is ASCII (or Unicode, which is  a  superset  of  ASCII).
462         PCRE can, however, be compiled to  run  in  an  EBCDIC  environment  by         This  is  the  case for most computer operating systems. PCRE can, how-
463         adding         ever, be compiled to run in an EBCDIC environment by adding
464    
465           --enable-ebcdic           --enable-ebcdic
466    
467         to the configure command.         to the configure command. This setting implies --enable-rebuild-charta-
468           bles.  You  should  only  use  it if you know that you are in an EBCDIC
469           environment (for example, an IBM mainframe operating system).
470    
471    
472  SEE ALSO  SEE ALSO
# Line 455  AUTHOR Line 483  AUTHOR
483    
484  REVISION  REVISION
485    
486         Last updated: 06 March 2007         Last updated: 30 July 2007
487         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
488  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
489    
490    
491  PCREMATCHING(3)                                                PCREMATCHING(3)  PCREMATCHING(3)                                                PCREMATCHING(3)
492    
493    
# Line 508  REGULAR EXPRESSIONS AS TREES Line 536  REGULAR EXPRESSIONS AS TREES
536    
537  THE STANDARD MATCHING ALGORITHM  THE STANDARD MATCHING ALGORITHM
538    
539         In the terminology of Jeffrey Friedl's book Mastering  Regular  Expres-         In the terminology of Jeffrey Friedl's book "Mastering Regular  Expres-
540         sions,  the  standard  algorithm  is  an "NFA algorithm". It conducts a         sions",  the  standard  algorithm  is an "NFA algorithm". It conducts a
541         depth-first search of the pattern tree. That is, it  proceeds  along  a         depth-first search of the pattern tree. That is, it  proceeds  along  a
542         single path through the tree, checking that the subject matches what is         single path through the tree, checking that the subject matches what is
543         required. When there is a mismatch, the algorithm  tries  any  alterna-         required. When there is a mismatch, the algorithm  tries  any  alterna-
# Line 591  THE ALTERNATIVE MATCHING ALGORITHM Line 619  THE ALTERNATIVE MATCHING ALGORITHM
619         ence  as  the  condition or test for a specific group recursion are not         ence  as  the  condition or test for a specific group recursion are not
620         supported.         supported.
621    
622         5. Callouts are supported, but the value of the  capture_top  field  is         5. Because many paths through the tree may be  active,  the  \K  escape
623           sequence, which resets the start of the match when encountered (but may
624           be on some paths and not on others), is not  supported.  It  causes  an
625           error if encountered.
626    
627           6.  Callouts  are  supported, but the value of the capture_top field is
628         always 1, and the value of the capture_last field is always -1.         always 1, and the value of the capture_last field is always -1.
629    
630         6.  The \C escape sequence, which (in the standard algorithm) matches a         7.  The \C escape sequence, which (in the standard algorithm) matches a
631         single byte, even in UTF-8 mode, is not supported because the  alterna-         single  byte, even in UTF-8 mode, is not supported because the alterna-
632         tive  algorithm  moves  through  the  subject string one character at a         tive algorithm moves through the subject  string  one  character  at  a
633         time, for all active paths through the tree.         time, for all active paths through the tree.
634    
635    
636  ADVANTAGES OF THE ALTERNATIVE ALGORITHM  ADVANTAGES OF THE ALTERNATIVE ALGORITHM
637    
638         Using the alternative matching algorithm provides the following  advan-         Using  the alternative matching algorithm provides the following advan-
639         tages:         tages:
640    
641         1. All possible matches (at a single point in the subject) are automat-         1. All possible matches (at a single point in the subject) are automat-
642         ically found, and in particular, the longest match is  found.  To  find         ically  found,  and  in particular, the longest match is found. To find
643         more than one match using the standard algorithm, you have to do kludgy         more than one match using the standard algorithm, you have to do kludgy
644         things with callouts.         things with callouts.
645    
646         2. There is much better support for partial matching. The  restrictions         2.  There is much better support for partial matching. The restrictions
647         on  the content of the pattern that apply when using the standard algo-         on the content of the pattern that apply when using the standard  algo-
648         rithm for partial matching do not apply to the  alternative  algorithm.         rithm  for  partial matching do not apply to the alternative algorithm.
649         For  non-anchored patterns, the starting position of a partial match is         For non-anchored patterns, the starting position of a partial match  is
650         available.         available.
651    
652         3. Because the alternative algorithm  scans  the  subject  string  just         3.  Because  the  alternative  algorithm  scans the subject string just
653         once,  and  never  needs to backtrack, it is possible to pass very long         once, and never needs to backtrack, it is possible to  pass  very  long
654         subject strings to the matching function in  several  pieces,  checking         subject  strings  to  the matching function in several pieces, checking
655         for partial matching each time.         for partial matching each time.
656    
657    
# Line 626  DISADVANTAGES OF THE ALTERNATIVE ALGORIT Line 659  DISADVANTAGES OF THE ALTERNATIVE ALGORIT
659    
660         The alternative algorithm suffers from a number of disadvantages:         The alternative algorithm suffers from a number of disadvantages:
661    
662         1.  It  is  substantially  slower  than the standard algorithm. This is         1. It is substantially slower than  the  standard  algorithm.  This  is
663         partly because it has to search for all possible matches, but  is  also         partly  because  it has to search for all possible matches, but is also
664         because it is less susceptible to optimization.         because it is less susceptible to optimization.
665    
666         2. Capturing parentheses and back references are not supported.         2. Capturing parentheses and back references are not supported.
# Line 645  AUTHOR Line 678  AUTHOR
678    
679  REVISION  REVISION
680    
681         Last updated: 06 March 2007         Last updated: 29 May 2007
682         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
683  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
684    
685    
686  PCREAPI(3)                                                          PCREAPI(3)  PCREAPI(3)                                                          PCREAPI(3)
687    
688    
# Line 828  PCRE API OVERVIEW Line 861  PCRE API OVERVIEW
861    
862  NEWLINES  NEWLINES
863    
864         PCRE  supports four different conventions for indicating line breaks in         PCRE  supports five different conventions for indicating line breaks in
865         strings: a single CR (carriage return) character, a  single  LF  (line-         strings: a single CR (carriage return) character, a  single  LF  (line-
866         feed)  character,  the two-character sequence CRLF, or any Unicode new-         feed) character, the two-character sequence CRLF, any of the three pre-
867         line sequence.  The Unicode newline sequences are the three  just  men-         ceding, or any Unicode newline sequence. The Unicode newline  sequences
868         tioned, plus the single characters VT (vertical tab, U+000B), FF (form-         are  the  three just mentioned, plus the single characters VT (vertical
869         feed, U+000C), NEL (next line, U+0085), LS  (line  separator,  U+2028),         tab, U+000B), FF (formfeed, U+000C), NEL (next line, U+0085), LS  (line
870         and PS (paragraph separator, U+2029).         separator, U+2028), and PS (paragraph separator, U+2029).
871    
872         Each  of  the first three conventions is used by at least one operating         Each  of  the first three conventions is used by at least one operating
873         system as its standard newline sequence. When PCRE is built, a  default         system as its standard newline sequence. When PCRE is built, a  default
# Line 868  SAVING PRECOMPILED PATTERNS FOR LATER US Line 901  SAVING PRECOMPILED PATTERNS FOR LATER US
901         The compiled form of a regular expression can be saved and re-used at a         The compiled form of a regular expression can be saved and re-used at a
902         later time, possibly by a different program, and even on a  host  other         later time, possibly by a different program, and even on a  host  other
903         than  the  one  on  which  it  was  compiled.  Details are given in the         than  the  one  on  which  it  was  compiled.  Details are given in the
904         pcreprecompile documentation.         pcreprecompile documentation. However, compiling a  regular  expression
905           with  one version of PCRE for use with a different version is not guar-
906           anteed to work and may cause crashes.
907    
908    
909  CHECKING BUILD-TIME OPTIONS  CHECKING BUILD-TIME OPTIONS
# Line 899  CHECKING BUILD-TIME OPTIONS Line 934  CHECKING BUILD-TIME OPTIONS
934    
935         The output is an integer whose value specifies  the  default  character         The output is an integer whose value specifies  the  default  character
936         sequence  that is recognized as meaning "newline". The four values that         sequence  that is recognized as meaning "newline". The four values that
937         are supported are: 10 for LF, 13 for CR, 3338 for CRLF, and -1 for ANY.         are supported are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF,
938         The default should normally be the standard sequence for your operating         and  -1  for  ANY. The default should normally be the standard sequence
939         system.         for your operating system.
940    
941           PCRE_CONFIG_LINK_SIZE           PCRE_CONFIG_LINK_SIZE
942    
# Line 1125  COMPILING A PATTERN Line 1160  COMPILING A PATTERN
1160           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
1161           PCRE_NEWLINE_LF           PCRE_NEWLINE_LF
1162           PCRE_NEWLINE_CRLF           PCRE_NEWLINE_CRLF
1163             PCRE_NEWLINE_ANYCRLF
1164           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
1165    
1166         These  options  override the default newline definition that was chosen         These  options  override the default newline definition that was chosen
1167         when PCRE was built. Setting the first or the second specifies  that  a         when PCRE was built. Setting the first or the second specifies  that  a
1168         newline  is  indicated  by a single character (CR or LF, respectively).         newline  is  indicated  by a single character (CR or LF, respectively).
1169         Setting PCRE_NEWLINE_CRLF specifies that a newline is indicated by  the         Setting PCRE_NEWLINE_CRLF specifies that a newline is indicated by  the
1170         two-character  CRLF  sequence.  Setting PCRE_NEWLINE_ANY specifies that         two-character  CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF specifies
1171         any Unicode newline sequence should be recognized. The Unicode  newline         that any of the three preceding sequences should be recognized. Setting
1172         sequences  are  the three just mentioned, plus the single characters VT         PCRE_NEWLINE_ANY  specifies that any Unicode newline sequence should be
1173         (vertical tab, U+000B), FF (formfeed, U+000C), NEL (next line, U+0085),         recognized. The Unicode newline sequences are the three just mentioned,
1174         LS  (line separator, U+2028), and PS (paragraph separator, U+2029). The         plus  the  single  characters  VT (vertical tab, U+000B), FF (formfeed,
1175         last two are recognized only in UTF-8 mode.         U+000C), NEL (next line, U+0085), LS (line separator, U+2028),  and  PS
1176           (paragraph  separator,  U+2029).  The  last  two are recognized only in
1177           UTF-8 mode.
1178    
1179         The newline setting in the  options  word  uses  three  bits  that  are         The newline setting in the  options  word  uses  three  bits  that  are
1180         treated  as  a  number, giving eight possibilities. Currently only five         treated as a number, giving eight possibilities. Currently only six are
1181         are used (default plus the four values above). This means that  if  you         used (default plus the five values above). This means that if  you  set
1182         set  more  than  one  newline option, the combination may or may not be         more  than one newline option, the combination may or may not be sensi-
1183         sensible. For example, PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is  equiva-         ble. For example, PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is equivalent to
1184         lent  to PCRE_NEWLINE_CRLF, but other combinations yield unused numbers         PCRE_NEWLINE_CRLF,  but other combinations may yield unused numbers and
1185         and cause an error.         cause an error.
1186    
1187         The only time that a line break is specially recognized when  compiling         The only time that a line break is specially recognized when  compiling
1188         a  pattern  is  if  PCRE_EXTENDED  is set, and an unescaped # outside a         a  pattern  is  if  PCRE_EXTENDED  is set, and an unescaped # outside a
# Line 1230  COMPILATION ERROR CODES Line 1268  COMPILATION ERROR CODES
1268           26  malformed number or name after (?(           26  malformed number or name after (?(
1269           27  conditional group contains more than two branches           27  conditional group contains more than two branches
1270           28  assertion expected after (?(           28  assertion expected after (?(
1271           29  (?R or (?digits must be followed by )           29  (?R or (?[+-]digits must be followed by )
1272           30  unknown POSIX class name           30  unknown POSIX class name
1273           31  POSIX collating elements are not supported           31  POSIX collating elements are not supported
1274           32  this version of PCRE is not compiled with PCRE_UTF8 support           32  this version of PCRE is not compiled with PCRE_UTF8 support
# Line 1251  COMPILATION ERROR CODES Line 1289  COMPILATION ERROR CODES
1289           47  unknown property name after \P or \p           47  unknown property name after \P or \p
1290           48  subpattern name is too long (maximum 32 characters)           48  subpattern name is too long (maximum 32 characters)
1291           49  too many named subpatterns (maximum 10,000)           49  too many named subpatterns (maximum 10,000)
1292           50  repeated subpattern is too long           50  [this code is not in use]
1293           51  octal value is greater than \377 (not in UTF-8 mode)           51  octal value is greater than \377 (not in UTF-8 mode)
1294           52  internal error: overran compiling workspace           52  internal error: overran compiling workspace
1295           53   internal  error:  previously-checked  referenced  subpattern not           53   internal  error:  previously-checked  referenced  subpattern not
# Line 1259  COMPILATION ERROR CODES Line 1297  COMPILATION ERROR CODES
1297           54  DEFINE group contains more than one branch           54  DEFINE group contains more than one branch
1298           55  repeating a DEFINE group is not allowed           55  repeating a DEFINE group is not allowed
1299           56  inconsistent NEWLINE options"           56  inconsistent NEWLINE options"
1300             57  \g is not followed by a braced name or an optionally braced
1301                   non-zero number
1302             58  (?+ or (?- or (?(+ or (?(- must be followed by a non-zero number
1303    
1304    
1305  STUDYING A PATTERN  STUDYING A PATTERN
# Line 1310  STUDYING A PATTERN Line 1351  STUDYING A PATTERN
1351  LOCALE SUPPORT  LOCALE SUPPORT
1352    
1353         PCRE handles caseless matching, and determines whether  characters  are         PCRE handles caseless matching, and determines whether  characters  are
1354         letters  digits,  or whatever, by reference to a set of tables, indexed         letters,  digits, or whatever, by reference to a set of tables, indexed
1355         by character value. When running in UTF-8 mode, this  applies  only  to         by character value. When running in UTF-8 mode, this  applies  only  to
1356         characters  with  codes  less than 128. Higher-valued codes never match         characters  with  codes  less than 128. Higher-valued codes never match
1357         escapes such as \w or \d, but can be tested with \p if  PCRE  is  built         escapes such as \w or \d, but can be tested with \p if  PCRE  is  built
1358         with  Unicode  character property support. The use of locales with Uni-         with  Unicode  character property support. The use of locales with Uni-
1359         code is discouraged.         code is discouraged. If you are handling characters with codes  greater
1360           than  128, you should either use UTF-8 and Unicode, or use locales, but
1361         An internal set of tables is created in the default C locale when  PCRE         not try to mix the two.
1362         is  built.  This  is  used when the final argument of pcre_compile() is  
1363         NULL, and is sufficient for many applications. An  alternative  set  of         PCRE contains an internal set of tables that are used  when  the  final
1364         tables  can,  however, be supplied. These may be created in a different         argument  of  pcre_compile()  is  NULL.  These  are sufficient for many
1365         locale from the default. As more and more applications change to  using         applications.  Normally, the internal tables recognize only ASCII char-
1366         Unicode, the need for this locale support is expected to die away.         acters. However, when PCRE is built, it is possible to cause the inter-
1367           nal tables to be rebuilt in the default "C" locale of the local system,
1368         External  tables  are  built by calling the pcre_maketables() function,         which may cause them to be different.
1369         which has no arguments, in the relevant locale. The result can then  be  
1370         passed  to  pcre_compile()  or  pcre_exec()  as often as necessary. For         The  internal tables can always be overridden by tables supplied by the
1371         example, to build and use tables that are appropriate  for  the  French         application that calls PCRE. These may be created in a different locale
1372         locale  (where  accented  characters  with  values greater than 128 are         from  the  default.  As more and more applications change to using Uni-
1373           code, the need for this locale support is expected to die away.
1374    
1375           External tables are built by calling  the  pcre_maketables()  function,
1376           which  has no arguments, in the relevant locale. The result can then be
1377           passed to pcre_compile() or pcre_exec()  as  often  as  necessary.  For
1378           example,  to  build  and use tables that are appropriate for the French
1379           locale (where accented characters with  values  greater  than  128  are
1380         treated as letters), the following code could be used:         treated as letters), the following code could be used:
1381    
1382           setlocale(LC_CTYPE, "fr_FR");           setlocale(LC_CTYPE, "fr_FR");
1383           tables = pcre_maketables();           tables = pcre_maketables();
1384           re = pcre_compile(..., tables);           re = pcre_compile(..., tables);
1385    
1386           The  locale  name "fr_FR" is used on Linux and other Unix-like systems;
1387           if you are using Windows, the name for the French locale is "french".
1388    
1389         When pcre_maketables() runs, the tables are built  in  memory  that  is         When pcre_maketables() runs, the tables are built  in  memory  that  is
1390         obtained  via  pcre_malloc. It is the caller's responsibility to ensure         obtained  via  pcre_malloc. It is the caller's responsibility to ensure
1391         that the memory containing the tables remains available for as long  as         that the memory containing the tables remains available for as long  as
# Line 1437  INFORMATION ABOUT A PATTERN Line 1488  INFORMATION ABOUT A PATTERN
1488         returned. The fourth argument should point to an unsigned char *  vari-         returned. The fourth argument should point to an unsigned char *  vari-
1489         able.         able.
1490    
1491             PCRE_INFO_JCHANGED
1492    
1493           Return  1  if the (?J) option setting is used in the pattern, otherwise
1494           0. The fourth argument should point to an int variable. The (?J) inter-
1495           nal option setting changes the local PCRE_DUPNAMES option.
1496    
1497           PCRE_INFO_LASTLITERAL           PCRE_INFO_LASTLITERAL
1498    
1499         Return  the  value of the rightmost literal byte that must exist in any         Return  the  value of the rightmost literal byte that must exist in any
# Line 1491  INFORMATION ABOUT A PATTERN Line 1548  INFORMATION ABOUT A PATTERN
1548         name-to-number map, remember that the length of the entries  is  likely         name-to-number map, remember that the length of the entries  is  likely
1549         to be different for each compiled pattern.         to be different for each compiled pattern.
1550    
1551             PCRE_INFO_OKPARTIAL
1552    
1553           Return  1 if the pattern can be used for partial matching, otherwise 0.
1554           The fourth argument should point to an int  variable.  The  pcrepartial
1555           documentation  lists  the restrictions that apply to patterns when par-
1556           tial matching is used.
1557    
1558           PCRE_INFO_OPTIONS           PCRE_INFO_OPTIONS
1559    
1560         Return  a  copy of the options with which the pattern was compiled. The         Return a copy of the options with which the pattern was  compiled.  The
1561         fourth argument should point to an unsigned long  int  variable.  These         fourth  argument  should  point to an unsigned long int variable. These
1562         option bits are those specified in the call to pcre_compile(), modified         option bits are those specified in the call to pcre_compile(), modified
1563         by any top-level option settings within the pattern itself.         by any top-level option settings at the start of the pattern itself. In
1564           other words, they are the options that will be in force  when  matching
1565           starts.  For  example, if the pattern /(?im)abc(?-i)d/ is compiled with
1566           the PCRE_EXTENDED option, the result is PCRE_CASELESS,  PCRE_MULTILINE,
1567           and PCRE_EXTENDED.
1568    
1569         A pattern is automatically anchored by PCRE if  all  of  its  top-level         A  pattern  is  automatically  anchored by PCRE if all of its top-level
1570         alternatives begin with one of the following:         alternatives begin with one of the following:
1571    
1572           ^     unless PCRE_MULTILINE is set           ^     unless PCRE_MULTILINE is set
# Line 1512  INFORMATION ABOUT A PATTERN Line 1580  INFORMATION ABOUT A PATTERN
1580    
1581           PCRE_INFO_SIZE           PCRE_INFO_SIZE
1582    
1583         Return the size of the compiled pattern, that is, the  value  that  was         Return  the  size  of the compiled pattern, that is, the value that was
1584         passed as the argument to pcre_malloc() when PCRE was getting memory in         passed as the argument to pcre_malloc() when PCRE was getting memory in
1585         which to place the compiled data. The fourth argument should point to a         which to place the compiled data. The fourth argument should point to a
1586         size_t variable.         size_t variable.
# Line 1520  INFORMATION ABOUT A PATTERN Line 1588  INFORMATION ABOUT A PATTERN
1588           PCRE_INFO_STUDYSIZE           PCRE_INFO_STUDYSIZE
1589    
1590         Return the size of the data block pointed to by the study_data field in         Return the size of the data block pointed to by the study_data field in
1591         a pcre_extra block. That is,  it  is  the  value  that  was  passed  to         a  pcre_extra  block.  That  is,  it  is  the  value that was passed to
1592         pcre_malloc() when PCRE was getting memory into which to place the data         pcre_malloc() when PCRE was getting memory into which to place the data
1593         created by pcre_study(). The fourth argument should point to  a  size_t         created  by  pcre_study(). The fourth argument should point to a size_t
1594         variable.         variable.
1595    
1596    
# Line 1530  OBSOLETE INFO FUNCTION Line 1598  OBSOLETE INFO FUNCTION
1598    
1599         int pcre_info(const pcre *code, int *optptr, int *firstcharptr);         int pcre_info(const pcre *code, int *optptr, int *firstcharptr);
1600    
1601         The  pcre_info()  function is now obsolete because its interface is too         The pcre_info() function is now obsolete because its interface  is  too
1602         restrictive to return all the available data about a compiled  pattern.         restrictive  to return all the available data about a compiled pattern.
1603         New   programs   should  use  pcre_fullinfo()  instead.  The  yield  of         New  programs  should  use  pcre_fullinfo()  instead.  The   yield   of
1604         pcre_info() is the number of capturing subpatterns, or one of the  fol-         pcre_info()  is the number of capturing subpatterns, or one of the fol-
1605         lowing negative numbers:         lowing negative numbers:
1606    
1607           PCRE_ERROR_NULL       the argument code was NULL           PCRE_ERROR_NULL       the argument code was NULL
1608           PCRE_ERROR_BADMAGIC   the "magic number" was not found           PCRE_ERROR_BADMAGIC   the "magic number" was not found
1609    
1610         If  the  optptr  argument is not NULL, a copy of the options with which         If the optptr argument is not NULL, a copy of the  options  with  which
1611         the pattern was compiled is placed in the integer  it  points  to  (see         the  pattern  was  compiled  is placed in the integer it points to (see
1612         PCRE_INFO_OPTIONS above).         PCRE_INFO_OPTIONS above).
1613    
1614         If  the  pattern  is  not anchored and the firstcharptr argument is not         If the pattern is not anchored and the  firstcharptr  argument  is  not
1615         NULL, it is used to pass back information about the first character  of         NULL,  it is used to pass back information about the first character of
1616         any matched string (see PCRE_INFO_FIRSTBYTE above).         any matched string (see PCRE_INFO_FIRSTBYTE above).
1617    
1618    
# Line 1552  REFERENCE COUNTS Line 1620  REFERENCE COUNTS
1620    
1621         int pcre_refcount(pcre *code, int adjust);         int pcre_refcount(pcre *code, int adjust);
1622    
1623         The  pcre_refcount()  function is used to maintain a reference count in         The pcre_refcount() function is used to maintain a reference  count  in
1624         the data block that contains a compiled pattern. It is provided for the         the data block that contains a compiled pattern. It is provided for the
1625         benefit  of  applications  that  operate  in an object-oriented manner,         benefit of applications that  operate  in  an  object-oriented  manner,
1626         where different parts of the application may be using the same compiled         where different parts of the application may be using the same compiled
1627         pattern, but you want to free the block when they are all done.         pattern, but you want to free the block when they are all done.
1628    
1629         When a pattern is compiled, the reference count field is initialized to         When a pattern is compiled, the reference count field is initialized to
1630         zero.  It is changed only by calling this function, whose action is  to         zero.   It is changed only by calling this function, whose action is to
1631         add  the  adjust  value  (which may be positive or negative) to it. The         add the adjust value (which may be positive or  negative)  to  it.  The
1632         yield of the function is the new value. However, the value of the count         yield of the function is the new value. However, the value of the count
1633         is  constrained to lie between 0 and 65535, inclusive. If the new value         is constrained to lie between 0 and 65535, inclusive. If the new  value
1634         is outside these limits, it is forced to the appropriate limit value.         is outside these limits, it is forced to the appropriate limit value.
1635    
1636         Except when it is zero, the reference count is not correctly  preserved         Except  when it is zero, the reference count is not correctly preserved
1637         if  a  pattern  is  compiled on one host and then transferred to a host         if a pattern is compiled on one host and then  transferred  to  a  host
1638         whose byte-order is different. (This seems a highly unlikely scenario.)         whose byte-order is different. (This seems a highly unlikely scenario.)
1639    
1640    
# Line 1576  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1644  MATCHING A PATTERN: THE TRADITIONAL FUNC
1644              const char *subject, int length, int startoffset,              const char *subject, int length, int startoffset,
1645              int options, int *ovector, int ovecsize);              int options, int *ovector, int ovecsize);
1646    
1647         The  function pcre_exec() is called to match a subject string against a         The function pcre_exec() is called to match a subject string against  a
1648         compiled pattern, which is passed in the code argument. If the  pattern         compiled  pattern, which is passed in the code argument. If the pattern
1649         has been studied, the result of the study should be passed in the extra         has been studied, the result of the study should be passed in the extra
1650         argument. This function is the main matching facility of  the  library,         argument.  This  function is the main matching facility of the library,
1651         and it operates in a Perl-like manner. For specialist use there is also         and it operates in a Perl-like manner. For specialist use there is also
1652         an alternative matching function, which is described below in the  sec-         an  alternative matching function, which is described below in the sec-
1653         tion about the pcre_dfa_exec() function.         tion about the pcre_dfa_exec() function.
1654    
1655         In  most applications, the pattern will have been compiled (and option-         In most applications, the pattern will have been compiled (and  option-
1656         ally studied) in the same process that calls pcre_exec().  However,  it         ally  studied)  in the same process that calls pcre_exec(). However, it
1657         is possible to save compiled patterns and study data, and then use them         is possible to save compiled patterns and study data, and then use them
1658         later in different processes, possibly even on different hosts.  For  a         later  in  different processes, possibly even on different hosts. For a
1659         discussion about this, see the pcreprecompile documentation.         discussion about this, see the pcreprecompile documentation.
1660    
1661         Here is an example of a simple call to pcre_exec():         Here is an example of a simple call to pcre_exec():
# Line 1606  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1674  MATCHING A PATTERN: THE TRADITIONAL FUNC
1674    
1675     Extra data for pcre_exec()     Extra data for pcre_exec()
1676    
1677         If  the  extra argument is not NULL, it must point to a pcre_extra data         If the extra argument is not NULL, it must point to a  pcre_extra  data
1678         block. The pcre_study() function returns such a block (when it  doesn't         block.  The pcre_study() function returns such a block (when it doesn't
1679         return  NULL), but you can also create one for yourself, and pass addi-         return NULL), but you can also create one for yourself, and pass  addi-
1680         tional information in it. The pcre_extra block contains  the  following         tional  information  in it. The pcre_extra block contains the following
1681         fields (not necessarily in this order):         fields (not necessarily in this order):
1682    
1683           unsigned long int flags;           unsigned long int flags;
# Line 1619  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1687  MATCHING A PATTERN: THE TRADITIONAL FUNC
1687           void *callout_data;           void *callout_data;
1688           const unsigned char *tables;           const unsigned char *tables;
1689    
1690         The  flags  field  is a bitmap that specifies which of the other fields         The flags field is a bitmap that specifies which of  the  other  fields
1691         are set. The flag bits are:         are set. The flag bits are:
1692    
1693           PCRE_EXTRA_STUDY_DATA           PCRE_EXTRA_STUDY_DATA
# Line 1628  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1696  MATCHING A PATTERN: THE TRADITIONAL FUNC
1696           PCRE_EXTRA_CALLOUT_DATA           PCRE_EXTRA_CALLOUT_DATA
1697           PCRE_EXTRA_TABLES           PCRE_EXTRA_TABLES
1698    
1699         Other flag bits should be set to zero. The study_data field is  set  in         Other  flag  bits should be set to zero. The study_data field is set in
1700         the  pcre_extra  block  that is returned by pcre_study(), together with         the pcre_extra block that is returned by  pcre_study(),  together  with
1701         the appropriate flag bit. You should not set this yourself, but you may         the appropriate flag bit. You should not set this yourself, but you may
1702         add  to  the  block by setting the other fields and their corresponding         add to the block by setting the other fields  and  their  corresponding
1703         flag bits.         flag bits.
1704    
1705         The match_limit field provides a means of preventing PCRE from using up         The match_limit field provides a means of preventing PCRE from using up
1706         a  vast amount of resources when running patterns that are not going to         a vast amount of resources when running patterns that are not going  to
1707         match, but which have a very large number  of  possibilities  in  their         match,  but  which  have  a very large number of possibilities in their
1708         search  trees.  The  classic  example  is  the  use of nested unlimited         search trees. The classic  example  is  the  use  of  nested  unlimited
1709         repeats.         repeats.
1710    
1711         Internally, PCRE uses a function called match() which it calls  repeat-         Internally,  PCRE uses a function called match() which it calls repeat-
1712         edly  (sometimes  recursively). The limit set by match_limit is imposed         edly (sometimes recursively). The limit set by match_limit  is  imposed
1713         on the number of times this function is called during  a  match,  which         on  the  number  of times this function is called during a match, which
1714         has  the  effect  of  limiting the amount of backtracking that can take         has the effect of limiting the amount of  backtracking  that  can  take
1715         place. For patterns that are not anchored, the count restarts from zero         place. For patterns that are not anchored, the count restarts from zero
1716         for each position in the subject string.         for each position in the subject string.
1717    
1718         The  default  value  for  the  limit can be set when PCRE is built; the         The default value for the limit can be set  when  PCRE  is  built;  the
1719         default default is 10 million, which handles all but the  most  extreme         default  default  is 10 million, which handles all but the most extreme
1720         cases.  You  can  override  the  default by suppling pcre_exec() with a         cases. You can override the default  by  suppling  pcre_exec()  with  a
1721         pcre_extra    block    in    which    match_limit    is    set,     and         pcre_extra     block    in    which    match_limit    is    set,    and
1722         PCRE_EXTRA_MATCH_LIMIT  is  set  in  the  flags  field. If the limit is         PCRE_EXTRA_MATCH_LIMIT is set in the  flags  field.  If  the  limit  is
1723         exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT.         exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT.
1724    
1725         The match_limit_recursion field is similar to match_limit, but  instead         The  match_limit_recursion field is similar to match_limit, but instead
1726         of limiting the total number of times that match() is called, it limits         of limiting the total number of times that match() is called, it limits
1727         the depth of recursion. The recursion depth is a  smaller  number  than         the  depth  of  recursion. The recursion depth is a smaller number than
1728         the  total number of calls, because not all calls to match() are recur-         the total number of calls, because not all calls to match() are  recur-
1729         sive.  This limit is of use only if it is set smaller than match_limit.         sive.  This limit is of use only if it is set smaller than match_limit.
1730    
1731         Limiting  the  recursion  depth  limits the amount of stack that can be         Limiting the recursion depth limits the amount of  stack  that  can  be
1732         used, or, when PCRE has been compiled to use memory on the heap instead         used, or, when PCRE has been compiled to use memory on the heap instead
1733         of the stack, the amount of heap memory that can be used.         of the stack, the amount of heap memory that can be used.
1734    
1735         The  default  value  for  match_limit_recursion can be set when PCRE is         The default value for match_limit_recursion can be  set  when  PCRE  is
1736         built; the default default  is  the  same  value  as  the  default  for         built;  the  default  default  is  the  same  value  as the default for
1737         match_limit.  You can override the default by suppling pcre_exec() with         match_limit. You can override the default by suppling pcre_exec()  with
1738         a  pcre_extra  block  in  which  match_limit_recursion  is   set,   and         a   pcre_extra   block  in  which  match_limit_recursion  is  set,  and
1739         PCRE_EXTRA_MATCH_LIMIT_RECURSION  is  set  in  the  flags field. If the         PCRE_EXTRA_MATCH_LIMIT_RECURSION is set in  the  flags  field.  If  the
1740         limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT.         limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT.
1741    
1742         The pcre_callout field is used in conjunction with the  "callout"  fea-         The  pcre_callout  field is used in conjunction with the "callout" fea-
1743         ture, which is described in the pcrecallout documentation.         ture, which is described in the pcrecallout documentation.
1744    
1745         The  tables  field  is  used  to  pass  a  character  tables pointer to         The tables field  is  used  to  pass  a  character  tables  pointer  to
1746         pcre_exec(); this overrides the value that is stored with the  compiled         pcre_exec();  this overrides the value that is stored with the compiled
1747         pattern.  A  non-NULL value is stored with the compiled pattern only if         pattern. A non-NULL value is stored with the compiled pattern  only  if
1748         custom tables were supplied to pcre_compile() via  its  tableptr  argu-         custom  tables  were  supplied to pcre_compile() via its tableptr argu-
1749         ment.  If NULL is passed to pcre_exec() using this mechanism, it forces         ment.  If NULL is passed to pcre_exec() using this mechanism, it forces
1750         PCRE's internal tables to be used. This facility is  helpful  when  re-         PCRE's  internal  tables  to be used. This facility is helpful when re-
1751         using  patterns  that  have been saved after compiling with an external         using patterns that have been saved after compiling  with  an  external
1752         set of tables, because the external tables  might  be  at  a  different         set  of  tables,  because  the  external tables might be at a different
1753         address  when  pcre_exec() is called. See the pcreprecompile documenta-         address when pcre_exec() is called. See the  pcreprecompile  documenta-
1754         tion for a discussion of saving compiled patterns for later use.         tion for a discussion of saving compiled patterns for later use.
1755    
1756     Option bits for pcre_exec()     Option bits for pcre_exec()
1757    
1758         The unused bits of the options argument for pcre_exec() must  be  zero.         The  unused  bits of the options argument for pcre_exec() must be zero.
1759         The  only  bits  that  may  be set are PCRE_ANCHORED, PCRE_NEWLINE_xxx,         The only bits that may  be  set  are  PCRE_ANCHORED,  PCRE_NEWLINE_xxx,
1760         PCRE_NOTBOL,   PCRE_NOTEOL,   PCRE_NOTEMPTY,   PCRE_NO_UTF8_CHECK   and         PCRE_NOTBOL,   PCRE_NOTEOL,   PCRE_NOTEMPTY,   PCRE_NO_UTF8_CHECK   and
1761         PCRE_PARTIAL.         PCRE_PARTIAL.
1762    
1763           PCRE_ANCHORED           PCRE_ANCHORED
1764    
1765         The  PCRE_ANCHORED  option  limits pcre_exec() to matching at the first         The PCRE_ANCHORED option limits pcre_exec() to matching  at  the  first
1766         matching position. If a pattern was  compiled  with  PCRE_ANCHORED,  or         matching  position.  If  a  pattern was compiled with PCRE_ANCHORED, or
1767         turned  out to be anchored by virtue of its contents, it cannot be made         turned out to be anchored by virtue of its contents, it cannot be  made
1768         unachored at matching time.         unachored at matching time.
1769    
1770           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
1771           PCRE_NEWLINE_LF           PCRE_NEWLINE_LF
1772           PCRE_NEWLINE_CRLF           PCRE_NEWLINE_CRLF
1773             PCRE_NEWLINE_ANYCRLF
1774           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
1775    
1776         These options override  the  newline  definition  that  was  chosen  or         These  options  override  the  newline  definition  that  was chosen or
1777         defaulted  when the pattern was compiled. For details, see the descrip-         defaulted when the pattern was compiled. For details, see the  descrip-
1778         tion of pcre_compile()  above.  During  matching,  the  newline  choice         tion  of  pcre_compile()  above.  During  matching,  the newline choice
1779         affects  the  behaviour  of the dot, circumflex, and dollar metacharac-         affects the behaviour of the dot, circumflex,  and  dollar  metacharac-
1780         ters. It may also alter the way the match position is advanced after  a         ters.  It may also alter the way the match position is advanced after a
1781         match  failure  for  an  unanchored  pattern. When PCRE_NEWLINE_CRLF or         match  failure  for  an  unanchored  pattern.  When  PCRE_NEWLINE_CRLF,
1782         PCRE_NEWLINE_ANY is set, and a match attempt  fails  when  the  current         PCRE_NEWLINE_ANYCRLF,  or  PCRE_NEWLINE_ANY is set, and a match attempt
1783         position  is  at a CRLF sequence, the match position is advanced by two         fails when the current position is at a CRLF sequence, the match  posi-
1784         characters instead of one, in other words, to after the CRLF.         tion  is  advanced by two characters instead of one, in other words, to
1785           after the CRLF.
1786    
1787           PCRE_NOTBOL           PCRE_NOTBOL
1788    
# Line 1985  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 2055  MATCHING A PATTERN: THE TRADITIONAL FUNC
2055         field  in  a  pcre_extra  structure (or defaulted) was reached. See the         field  in  a  pcre_extra  structure (or defaulted) was reached. See the
2056         description above.         description above.
2057    
          PCRE_ERROR_NULLWSLIMIT    (-22)  
   
        When a group that can match an empty  substring  is  repeated  with  an  
        unbounded  upper  limit, the subject position at the start of the group  
        must be remembered, so that a test for an empty string can be made when  
        the  end  of the group is reached. Some workspace is required for this;  
        if it runs out, this error is given.  
   
2058           PCRE_ERROR_BADNEWLINE     (-23)           PCRE_ERROR_BADNEWLINE     (-23)
2059    
2060         An invalid combination of PCRE_NEWLINE_xxx options was given.         An invalid combination of PCRE_NEWLINE_xxx options was given.
2061    
2062         Error numbers -16 to -20 are not used by pcre_exec().         Error numbers -16 to -20 and -22 are not used by pcre_exec().
2063    
2064    
2065  EXTRACTING CAPTURED SUBSTRINGS BY NUMBER  EXTRACTING CAPTURED SUBSTRINGS BY NUMBER
# Line 2132  EXTRACTING CAPTURED SUBSTRINGS BY NAME Line 2194  EXTRACTING CAPTURED SUBSTRINGS BY NAME
2194    
2195         These  functions call pcre_get_stringnumber(), and if it succeeds, they         These  functions call pcre_get_stringnumber(), and if it succeeds, they
2196         then call pcre_copy_substring() or pcre_get_substring(),  as  appropri-         then call pcre_copy_substring() or pcre_get_substring(),  as  appropri-
2197         ate.         ate.  NOTE:  If PCRE_DUPNAMES is set and there are duplicate names, the
2198           behaviour may not be what you want (see the next section).
2199    
2200    
2201  DUPLICATE SUBPATTERN NAMES  DUPLICATE SUBPATTERN NAMES
# Line 2140  DUPLICATE SUBPATTERN NAMES Line 2203  DUPLICATE SUBPATTERN NAMES
2203         int pcre_get_stringtable_entries(const pcre *code,         int pcre_get_stringtable_entries(const pcre *code,
2204              const char *name, char **first, char **last);              const char *name, char **first, char **last);
2205    
2206         When  a  pattern  is  compiled with the PCRE_DUPNAMES option, names for         When a pattern is compiled with the  PCRE_DUPNAMES  option,  names  for
2207         subpatterns are not required to  be  unique.  Normally,  patterns  with         subpatterns  are  not  required  to  be unique. Normally, patterns with
2208         duplicate  names  are such that in any one match, only one of the named         duplicate names are such that in any one match, only one of  the  named
2209         subpatterns participates. An example is shown in the pcrepattern  docu-         subpatterns  participates. An example is shown in the pcrepattern docu-
2210         mentation. When duplicates are present, pcre_copy_named_substring() and         mentation.
2211         pcre_get_named_substring() return the first substring corresponding  to  
2212         the  given  name  that  is  set.  If  none  are set, an empty string is         When   duplicates   are   present,   pcre_copy_named_substring()    and
2213         returned.  The pcre_get_stringnumber() function returns one of the num-         pcre_get_named_substring()  return the first substring corresponding to
2214         bers  that are associated with the name, but it is not defined which it         the given name that is set. If  none  are  set,  PCRE_ERROR_NOSUBSTRING
2215         is.         (-7)  is  returned;  no  data  is returned. The pcre_get_stringnumber()
2216           function returns one of the numbers that are associated with the  name,
2217           but it is not defined which it is.
2218    
2219         If you want to get full details of all captured substrings for a  given         If  you want to get full details of all captured substrings for a given
2220         name,  you  must  use  the pcre_get_stringtable_entries() function. The         name, you must use  the  pcre_get_stringtable_entries()  function.  The
2221         first argument is the compiled pattern, and the second is the name. The         first argument is the compiled pattern, and the second is the name. The
2222         third  and  fourth  are  pointers to variables which are updated by the         third and fourth are pointers to variables which  are  updated  by  the
2223         function. After it has run, they point to the first and last entries in         function. After it has run, they point to the first and last entries in
2224         the  name-to-number  table  for  the  given  name.  The function itself         the name-to-number table  for  the  given  name.  The  function  itself
2225         returns the length of each entry,  or  PCRE_ERROR_NOSUBSTRING  (-7)  if         returns  the  length  of  each entry, or PCRE_ERROR_NOSUBSTRING (-7) if
2226         there  are none. The format of the table is described above in the sec-         there are none. The format of the table is described above in the  sec-
2227         tion entitled Information about a  pattern.   Given  all  the  relevant         tion  entitled  Information  about  a  pattern.  Given all the relevant
2228         entries  for the name, you can extract each of their numbers, and hence         entries for the name, you can extract each of their numbers, and  hence
2229         the captured data, if any.         the captured data, if any.
2230    
2231    
2232  FINDING ALL POSSIBLE MATCHES  FINDING ALL POSSIBLE MATCHES
2233    
2234         The traditional matching function uses a  similar  algorithm  to  Perl,         The  traditional  matching  function  uses a similar algorithm to Perl,
2235         which stops when it finds the first match, starting at a given point in         which stops when it finds the first match, starting at a given point in
2236         the subject. If you want to find all possible matches, or  the  longest         the  subject.  If you want to find all possible matches, or the longest
2237         possible  match,  consider using the alternative matching function (see         possible match, consider using the alternative matching  function  (see
2238         below) instead. If you cannot use the alternative function,  but  still         below)  instead.  If you cannot use the alternative function, but still
2239         need  to  find all possible matches, you can kludge it up by making use         need to find all possible matches, you can kludge it up by  making  use
2240         of the callout facility, which is described in the pcrecallout documen-         of the callout facility, which is described in the pcrecallout documen-
2241         tation.         tation.
2242    
2243         What you have to do is to insert a callout right at the end of the pat-         What you have to do is to insert a callout right at the end of the pat-
2244         tern.  When your callout function is called, extract and save the  cur-         tern.   When your callout function is called, extract and save the cur-
2245         rent  matched  substring.  Then  return  1, which forces pcre_exec() to         rent matched substring. Then return  1,  which  forces  pcre_exec()  to
2246         backtrack and try other alternatives. Ultimately, when it runs  out  of         backtrack  and  try other alternatives. Ultimately, when it runs out of
2247         matches, pcre_exec() will yield PCRE_ERROR_NOMATCH.         matches, pcre_exec() will yield PCRE_ERROR_NOMATCH.
2248    
2249    
# Line 2189  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 2254  MATCHING A PATTERN: THE ALTERNATIVE FUNC
2254              int options, int *ovector, int ovecsize,              int options, int *ovector, int ovecsize,
2255              int *workspace, int wscount);              int *workspace, int wscount);
2256    
2257         The  function  pcre_dfa_exec()  is  called  to  match  a subject string         The function pcre_dfa_exec()  is  called  to  match  a  subject  string
2258         against a compiled pattern, using a matching algorithm that  scans  the         against  a  compiled pattern, using a matching algorithm that scans the
2259         subject  string  just  once, and does not backtrack. This has different         subject string just once, and does not backtrack.  This  has  different
2260         characteristics to the normal algorithm, and  is  not  compatible  with         characteristics  to  the  normal  algorithm, and is not compatible with
2261         Perl.  Some  of the features of PCRE patterns are not supported. Never-         Perl. Some of the features of PCRE patterns are not  supported.  Never-
2262         theless, there are times when this kind of matching can be useful.  For         theless,  there are times when this kind of matching can be useful. For
2263         a discussion of the two matching algorithms, see the pcrematching docu-         a discussion of the two matching algorithms, see the pcrematching docu-
2264         mentation.         mentation.
2265    
2266         The arguments for the pcre_dfa_exec() function  are  the  same  as  for         The  arguments  for  the  pcre_dfa_exec()  function are the same as for
2267         pcre_exec(), plus two extras. The ovector argument is used in a differ-         pcre_exec(), plus two extras. The ovector argument is used in a differ-
2268         ent way, and this is described below. The other  common  arguments  are         ent  way,  and  this is described below. The other common arguments are
2269         used  in  the  same way as for pcre_exec(), so their description is not         used in the same way as for pcre_exec(), so their  description  is  not
2270         repeated here.         repeated here.
2271    
2272         The two additional arguments provide workspace for  the  function.  The         The  two  additional  arguments provide workspace for the function. The
2273         workspace  vector  should  contain at least 20 elements. It is used for         workspace vector should contain at least 20 elements. It  is  used  for
2274         keeping  track  of  multiple  paths  through  the  pattern  tree.  More         keeping  track  of  multiple  paths  through  the  pattern  tree.  More
2275         workspace  will  be  needed for patterns and subjects where there are a         workspace will be needed for patterns and subjects where  there  are  a
2276         lot of potential matches.         lot of potential matches.
2277    
2278         Here is an example of a simple call to pcre_dfa_exec():         Here is an example of a simple call to pcre_dfa_exec():
# Line 2229  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 2294  MATCHING A PATTERN: THE ALTERNATIVE FUNC
2294    
2295     Option bits for pcre_dfa_exec()     Option bits for pcre_dfa_exec()
2296    
2297         The unused bits of the options argument  for  pcre_dfa_exec()  must  be         The  unused  bits  of  the options argument for pcre_dfa_exec() must be
2298         zero.  The  only  bits  that  may  be  set are PCRE_ANCHORED, PCRE_NEW-         zero. The only bits  that  may  be  set  are  PCRE_ANCHORED,  PCRE_NEW-
2299         LINE_xxx, PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY,  PCRE_NO_UTF8_CHECK,         LINE_xxx,  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK,
2300         PCRE_PARTIAL, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last         PCRE_PARTIAL, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last
2301         three of these are the same as for pcre_exec(), so their description is         three of these are the same as for pcre_exec(), so their description is
2302         not repeated here.         not repeated here.
2303    
2304           PCRE_PARTIAL           PCRE_PARTIAL
2305    
2306         This  has  the  same general effect as it does for pcre_exec(), but the         This has the same general effect as it does for  pcre_exec(),  but  the
2307         details  are  slightly  different.  When  PCRE_PARTIAL   is   set   for         details   are   slightly   different.  When  PCRE_PARTIAL  is  set  for
2308         pcre_dfa_exec(),  the  return code PCRE_ERROR_NOMATCH is converted into         pcre_dfa_exec(), the return code PCRE_ERROR_NOMATCH is  converted  into
2309         PCRE_ERROR_PARTIAL if the end of the subject  is  reached,  there  have         PCRE_ERROR_PARTIAL  if  the  end  of the subject is reached, there have
2310         been no complete matches, but there is still at least one matching pos-         been no complete matches, but there is still at least one matching pos-
2311         sibility. The portion of the string that provided the partial match  is         sibility.  The portion of the string that provided the partial match is
2312         set as the first matching string.         set as the first matching string.
2313    
2314           PCRE_DFA_SHORTEST           PCRE_DFA_SHORTEST
2315    
2316         Setting  the  PCRE_DFA_SHORTEST option causes the matching algorithm to         Setting the PCRE_DFA_SHORTEST option causes the matching  algorithm  to
2317         stop as soon as it has found one match. Because of the way the alterna-         stop as soon as it has found one match. Because of the way the alterna-
2318         tive  algorithm  works, this is necessarily the shortest possible match         tive algorithm works, this is necessarily the shortest  possible  match
2319         at the first possible matching point in the subject string.         at the first possible matching point in the subject string.
2320    
2321           PCRE_DFA_RESTART           PCRE_DFA_RESTART
2322    
2323         When pcre_dfa_exec()  is  called  with  the  PCRE_PARTIAL  option,  and         When  pcre_dfa_exec()  is  called  with  the  PCRE_PARTIAL  option, and
2324         returns  a  partial  match, it is possible to call it again, with addi-         returns a partial match, it is possible to call it  again,  with  addi-
2325         tional subject characters, and have it continue with  the  same  match.         tional  subject  characters,  and have it continue with the same match.
2326         The  PCRE_DFA_RESTART  option requests this action; when it is set, the         The PCRE_DFA_RESTART option requests this action; when it is  set,  the
2327         workspace and wscount options must reference the same vector as  before         workspace  and wscount options must reference the same vector as before
2328         because  data  about  the  match so far is left in them after a partial         because data about the match so far is left in  them  after  a  partial
2329         match. There is more discussion of this  facility  in  the  pcrepartial         match.  There  is  more  discussion of this facility in the pcrepartial
2330         documentation.         documentation.
2331    
2332     Successful returns from pcre_dfa_exec()     Successful returns from pcre_dfa_exec()
2333    
2334         When  pcre_dfa_exec()  succeeds, it may have matched more than one sub-         When pcre_dfa_exec() succeeds, it may have matched more than  one  sub-
2335         string in the subject. Note, however, that all the matches from one run         string in the subject. Note, however, that all the matches from one run
2336         of  the  function  start  at the same point in the subject. The shorter         of the function start at the same point in  the  subject.  The  shorter
2337         matches are all initial substrings of the longer matches. For  example,         matches  are all initial substrings of the longer matches. For example,
2338         if the pattern         if the pattern
2339    
2340           <.*>           <.*>
# Line 2284  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 2349  MATCHING A PATTERN: THE ALTERNATIVE FUNC
2349           <something> <something else>           <something> <something else>
2350           <something> <something else> <something further>           <something> <something else> <something further>
2351    
2352         On  success,  the  yield of the function is a number greater than zero,         On success, the yield of the function is a number  greater  than  zero,
2353         which is the number of matched substrings.  The  substrings  themselves         which  is  the  number of matched substrings. The substrings themselves
2354         are  returned  in  ovector. Each string uses two elements; the first is         are returned in ovector. Each string uses two elements;  the  first  is
2355         the offset to the start, and the second is the offset to  the  end.  In         the  offset  to  the start, and the second is the offset to the end. In
2356         fact,  all  the  strings  have the same start offset. (Space could have         fact, all the strings have the same start  offset.  (Space  could  have
2357         been saved by giving this only once, but it was decided to retain  some         been  saved by giving this only once, but it was decided to retain some
2358         compatibility  with  the  way pcre_exec() returns data, even though the         compatibility with the way pcre_exec() returns data,  even  though  the
2359         meaning of the strings is different.)         meaning of the strings is different.)
2360    
2361         The strings are returned in reverse order of length; that is, the long-         The strings are returned in reverse order of length; that is, the long-
2362         est  matching  string is given first. If there were too many matches to         est matching string is given first. If there were too many  matches  to
2363         fit into ovector, the yield of the function is zero, and the vector  is         fit  into ovector, the yield of the function is zero, and the vector is
2364         filled with the longest matches.         filled with the longest matches.
2365    
2366     Error returns from pcre_dfa_exec()     Error returns from pcre_dfa_exec()
2367    
2368         The  pcre_dfa_exec()  function returns a negative number when it fails.         The pcre_dfa_exec() function returns a negative number when  it  fails.
2369         Many of the errors are the same  as  for  pcre_exec(),  and  these  are         Many  of  the  errors  are  the  same as for pcre_exec(), and these are
2370         described  above.   There are in addition the following errors that are         described above.  There are in addition the following errors  that  are
2371         specific to pcre_dfa_exec():         specific to pcre_dfa_exec():
2372    
2373           PCRE_ERROR_DFA_UITEM      (-16)           PCRE_ERROR_DFA_UITEM      (-16)
2374    
2375         This return is given if pcre_dfa_exec() encounters an item in the  pat-         This  return is given if pcre_dfa_exec() encounters an item in the pat-
2376         tern  that  it  does not support, for instance, the use of \C or a back         tern that it does not support, for instance, the use of \C  or  a  back
2377         reference.         reference.
2378    
2379           PCRE_ERROR_DFA_UCOND      (-17)           PCRE_ERROR_DFA_UCOND      (-17)
2380    
2381         This return is given if pcre_dfa_exec()  encounters  a  condition  item         This  return  is  given  if pcre_dfa_exec() encounters a condition item
2382         that  uses  a back reference for the condition, or a test for recursion         that uses a back reference for the condition, or a test  for  recursion
2383         in a specific group. These are not supported.         in a specific group. These are not supported.
2384    
2385           PCRE_ERROR_DFA_UMLIMIT    (-18)           PCRE_ERROR_DFA_UMLIMIT    (-18)
2386    
2387         This return is given if pcre_dfa_exec() is called with an  extra  block         This  return  is given if pcre_dfa_exec() is called with an extra block
2388         that contains a setting of the match_limit field. This is not supported         that contains a setting of the match_limit field. This is not supported
2389         (it is meaningless).         (it is meaningless).
2390    
2391           PCRE_ERROR_DFA_WSSIZE     (-19)           PCRE_ERROR_DFA_WSSIZE     (-19)
2392    
2393         This return is given if  pcre_dfa_exec()  runs  out  of  space  in  the         This  return  is  given  if  pcre_dfa_exec()  runs  out of space in the
2394         workspace vector.         workspace vector.
2395    
2396           PCRE_ERROR_DFA_RECURSE    (-20)           PCRE_ERROR_DFA_RECURSE    (-20)
2397    
2398         When  a  recursive subpattern is processed, the matching function calls         When a recursive subpattern is processed, the matching  function  calls
2399         itself recursively, using private vectors for  ovector  and  workspace.         itself  recursively,  using  private vectors for ovector and workspace.
2400         This  error  is  given  if  the output vector is not large enough. This         This error is given if the output vector  is  not  large  enough.  This
2401         should be extremely rare, as a vector of size 1000 is used.         should be extremely rare, as a vector of size 1000 is used.
2402    
2403    
2404  SEE ALSO  SEE ALSO
2405    
2406         pcrebuild(3), pcrecallout(3), pcrecpp(3)(3), pcrematching(3),  pcrepar-         pcrebuild(3),  pcrecallout(3), pcrecpp(3)(3), pcrematching(3), pcrepar-
2407         tial(3),  pcreposix(3), pcreprecompile(3), pcresample(3), pcrestack(3).         tial(3), pcreposix(3), pcreprecompile(3), pcresample(3),  pcrestack(3).
2408    
2409    
2410  AUTHOR  AUTHOR
# Line 2351  AUTHOR Line 2416  AUTHOR
2416    
2417  REVISION  REVISION
2418    
2419         Last updated: 06 March 2007         Last updated: 30 July 2007
2420         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
2421  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2422    
2423    
2424  PCRECALLOUT(3)                                                  PCRECALLOUT(3)  PCRECALLOUT(3)                                                  PCRECALLOUT(3)
2425    
2426    
# Line 2379  PCRE CALLOUTS Line 2444  PCRE CALLOUTS
2444         default value is zero.  For  example,  this  pattern  has  two  callout         default value is zero.  For  example,  this  pattern  has  two  callout
2445         points:         points:
2446    
2447           (?C1)eabc(?C2)def           (?C1)abc(?C2)def
2448    
2449         If  the  PCRE_AUTO_CALLOUT  option  bit  is  set when pcre_compile() is         If  the  PCRE_AUTO_CALLOUT  option  bit  is  set when pcre_compile() is
2450         called, PCRE automatically  inserts  callouts,  all  with  number  255,         called, PCRE automatically  inserts  callouts,  all  with  number  255,
# Line 2454  THE CALLOUT INTERFACE Line 2519  THE CALLOUT INTERFACE
2519         The subject and subject_length fields contain copies of the values that         The subject and subject_length fields contain copies of the values that
2520         were passed to pcre_exec().         were passed to pcre_exec().
2521    
2522         The start_match field contains the offset within the subject  at  which         The start_match field normally contains the offset within  the  subject
2523         the  current match attempt started. If the pattern is not anchored, the         at  which  the  current  match  attempt started. However, if the escape
2524         callout function may be called several times from the same point in the         sequence \K has been encountered, this value is changed to reflect  the
2525         pattern for different starting points in the subject.         modified  starting  point.  If the pattern is not anchored, the callout
2526           function may be called several times from the same point in the pattern
2527           for different starting points in the subject.
2528    
2529         The  current_position  field  contains the offset within the subject of         The  current_position  field  contains the offset within the subject of
2530         the current match pointer.         the current match pointer.
# Line 2520  AUTHOR Line 2587  AUTHOR
2587    
2588  REVISION  REVISION
2589    
2590         Last updated: 06 March 2007         Last updated: 29 May 2007
2591         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
2592  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2593    
2594    
2595  PCRECOMPAT(3)                                                    PCRECOMPAT(3)  PCRECOMPAT(3)                                                    PCRECOMPAT(3)
2596    
2597    
# Line 2536  DIFFERENCES BETWEEN PCRE AND PERL Line 2603  DIFFERENCES BETWEEN PCRE AND PERL
2603    
2604         This  document describes the differences in the ways that PCRE and Perl         This  document describes the differences in the ways that PCRE and Perl
2605         handle regular expressions. The differences described here  are  mainly         handle regular expressions. The differences described here  are  mainly
2606         with  respect  to  Perl 5.8, though PCRE version 7.0 contains some fea-         with  respect  to  Perl 5.8, though PCRE versions 7.0 and later contain
2607         tures that are expected to be in the forthcoming Perl 5.10.         some features that are expected to be in the forthcoming Perl 5.10.
2608    
2609         1. PCRE has only a subset of Perl's UTF-8 and Unicode support.  Details         1. PCRE has only a subset of Perl's UTF-8 and Unicode support.  Details
2610         of  what  it does have are given in the section on UTF-8 support in the         of  what  it does have are given in the section on UTF-8 support in the
# Line 2615  DIFFERENCES BETWEEN PCRE AND PERL Line 2682  DIFFERENCES BETWEEN PCRE AND PERL
2682         meta-character matches only at the very end of the string.         meta-character matches only at the very end of the string.
2683    
2684         (c) If PCRE_EXTRA is set, a backslash followed by a letter with no spe-         (c) If PCRE_EXTRA is set, a backslash followed by a letter with no spe-
2685         cial  meaning  is  faulted.  Otherwise,  like  Perl,  the  backslash is         cial meaning is faulted. Otherwise, like Perl, the backslash is quietly
2686         ignored. (Perl can be made to issue a warning.)         ignored.  (Perl can be made to issue a warning.)
2687    
2688         (d) If PCRE_UNGREEDY is set, the greediness of the  repetition  quanti-         (d) If PCRE_UNGREEDY is set, the greediness of the  repetition  quanti-
2689         fiers is inverted, that is, by default they are not greedy, but if fol-         fiers is inverted, that is, by default they are not greedy, but if fol-
# Line 2648  AUTHOR Line 2715  AUTHOR
2715    
2716  REVISION  REVISION
2717    
2718         Last updated: 06 March 2007         Last updated: 13 June 2007
2719         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
2720  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2721    
2722    
2723  PCREPATTERN(3)                                                  PCREPATTERN(3)  PCREPATTERN(3)                                                  PCREPATTERN(3)
2724    
2725    
# Line 2662  NAME Line 2729  NAME
2729    
2730  PCRE REGULAR EXPRESSION DETAILS  PCRE REGULAR EXPRESSION DETAILS
2731    
2732         The  syntax  and semantics of the regular expressions supported by PCRE         The  syntax and semantics of the regular expressions that are supported
2733         are described below. Regular expressions are also described in the Perl         by PCRE are described in detail below. There is a quick-reference  syn-
2734         documentation  and  in  a  number  of books, some of which have copious         tax  summary  in  the  pcresyntax  page. Perl's regular expressions are
2735         examples.  Jeffrey Friedl's "Mastering Regular Expressions",  published         described in its own documentation, and regular expressions in  general
2736         by  O'Reilly, covers regular expressions in great detail. This descrip-         are  covered in a number of books, some of which have copious examples.
2737         tion of PCRE's regular expressions is intended as reference material.         Jeffrey  Friedl's  "Mastering  Regular   Expressions",   published   by
2738           O'Reilly,  covers regular expressions in great detail. This description
2739           of PCRE's regular expressions is intended as reference material.
2740    
2741         The original operation of PCRE was on strings of  one-byte  characters.         The original operation of PCRE was on strings of  one-byte  characters.
2742         However,  there is now also support for UTF-8 character strings. To use         However,  there is now also support for UTF-8 character strings. To use
# Line 2681  PCRE REGULAR EXPRESSION DETAILS Line 2750  PCRE REGULAR EXPRESSION DETAILS
2750         ported  by  PCRE when its main matching function, pcre_exec(), is used.         ported  by  PCRE when its main matching function, pcre_exec(), is used.
2751         From  release  6.0,   PCRE   offers   a   second   matching   function,         From  release  6.0,   PCRE   offers   a   second   matching   function,
2752         pcre_dfa_exec(),  which matches using a different algorithm that is not         pcre_dfa_exec(),  which matches using a different algorithm that is not
2753         Perl-compatible. The advantages and disadvantages  of  the  alternative         Perl-compatible. Some of the features discussed below are not available
2754         function, and how it differs from the normal function, are discussed in         when  pcre_dfa_exec()  is used. The advantages and disadvantages of the
2755         the pcrematching page.         alternative function, and how it differs from the normal function,  are
2756           discussed in the pcrematching page.
2757    
2758    
2759  CHARACTERS AND METACHARACTERS  CHARACTERS AND METACHARACTERS
2760    
2761         A regular expression is a pattern that is  matched  against  a  subject         A  regular  expression  is  a pattern that is matched against a subject
2762         string  from  left  to right. Most characters stand for themselves in a         string from left to right. Most characters stand for  themselves  in  a
2763         pattern, and match the corresponding characters in the  subject.  As  a         pattern,  and  match  the corresponding characters in the subject. As a
2764         trivial example, the pattern         trivial example, the pattern
2765    
2766           The quick brown fox           The quick brown fox
2767    
2768         matches a portion of a subject string that is identical to itself. When         matches a portion of a subject string that is identical to itself. When
2769         caseless matching is specified (the PCRE_CASELESS option), letters  are         caseless  matching is specified (the PCRE_CASELESS option), letters are
2770         matched  independently  of case. In UTF-8 mode, PCRE always understands         matched independently of case. In UTF-8 mode, PCRE  always  understands
2771         the concept of case for characters whose values are less than  128,  so         the  concept  of case for characters whose values are less than 128, so
2772         caseless  matching  is always possible. For characters with higher val-         caseless matching is always possible. For characters with  higher  val-
2773         ues, the concept of case is supported if PCRE is compiled with  Unicode         ues,  the concept of case is supported if PCRE is compiled with Unicode
2774         property  support,  but  not  otherwise.   If  you want to use caseless         property support, but not otherwise.   If  you  want  to  use  caseless
2775         matching for characters 128 and above, you must  ensure  that  PCRE  is         matching  for  characters  128  and above, you must ensure that PCRE is
2776         compiled with Unicode property support as well as with UTF-8 support.         compiled with Unicode property support as well as with UTF-8 support.
2777    
2778         The  power  of  regular  expressions  comes from the ability to include         The power of regular expressions comes  from  the  ability  to  include
2779         alternatives and repetitions in the pattern. These are encoded  in  the         alternatives  and  repetitions in the pattern. These are encoded in the
2780         pattern by the use of metacharacters, which do not stand for themselves         pattern by the use of metacharacters, which do not stand for themselves
2781         but instead are interpreted in some special way.         but instead are interpreted in some special way.
2782    
2783         There are two different sets of metacharacters: those that  are  recog-         There  are  two different sets of metacharacters: those that are recog-
2784         nized  anywhere in the pattern except within square brackets, and those         nized anywhere in the pattern except within square brackets, and  those
2785         that are recognized within square brackets.  Outside  square  brackets,         that  are  recognized  within square brackets. Outside square brackets,
2786         the metacharacters are as follows:         the metacharacters are as follows:
2787    
2788           \      general escape character with several uses           \      general escape character with several uses
# Line 2731  CHARACTERS AND METACHARACTERS Line 2801  CHARACTERS AND METACHARACTERS
2801                  also "possessive quantifier"                  also "possessive quantifier"
2802           {      start min/max quantifier           {      start min/max quantifier
2803    
2804         Part  of  a  pattern  that is in square brackets is called a "character         Part of a pattern that is in square brackets  is  called  a  "character
2805         class". In a character class the only metacharacters are:         class". In a character class the only metacharacters are:
2806    
2807           \      general escape character           \      general escape character
# Line 2741  CHARACTERS AND METACHARACTERS Line 2811  CHARACTERS AND METACHARACTERS
2811                    syntax)                    syntax)
2812           ]      terminates the character class           ]      terminates the character class
2813    
2814         The following sections describe the use of each of the  metacharacters.         The  following sections describe the use of each of the metacharacters.
2815    
2816    
2817  BACKSLASH  BACKSLASH
2818    
2819         The backslash character has several uses. Firstly, if it is followed by         The backslash character has several uses. Firstly, if it is followed by
2820         a non-alphanumeric character, it takes away any  special  meaning  that         a  non-alphanumeric  character,  it takes away any special meaning that
2821         character  may  have.  This  use  of  backslash  as an escape character         character may have. This  use  of  backslash  as  an  escape  character
2822         applies both inside and outside character classes.         applies both inside and outside character classes.
2823    
2824         For example, if you want to match a * character, you write  \*  in  the         For  example,  if  you want to match a * character, you write \* in the
2825         pattern.   This  escaping  action  applies whether or not the following         pattern.  This escaping action applies whether  or  not  the  following
2826         character would otherwise be interpreted as a metacharacter, so  it  is         character  would  otherwise be interpreted as a metacharacter, so it is
2827         always  safe  to  precede  a non-alphanumeric with backslash to specify         always safe to precede a non-alphanumeric  with  backslash  to  specify
2828         that it stands for itself. In particular, if you want to match a  back-         that  it stands for itself. In particular, if you want to match a back-
2829         slash, you write \\.         slash, you write \\.
2830    
2831         If  a  pattern is compiled with the PCRE_EXTENDED option, whitespace in         If a pattern is compiled with the PCRE_EXTENDED option,  whitespace  in
2832         the pattern (other than in a character class) and characters between  a         the  pattern (other than in a character class) and characters between a
2833         # outside a character class and the next newline are ignored. An escap-         # outside a character class and the next newline are ignored. An escap-
2834         ing backslash can be used to include a whitespace  or  #  character  as         ing  backslash  can  be  used to include a whitespace or # character as
2835         part of the pattern.         part of the pattern.
2836    
2837         If  you  want  to remove the special meaning from a sequence of charac-         If you want to remove the special meaning from a  sequence  of  charac-
2838         ters, you can do so by putting them between \Q and \E. This is  differ-         ters,  you can do so by putting them between \Q and \E. This is differ-
2839         ent  from  Perl  in  that  $  and  @ are handled as literals in \Q...\E         ent from Perl in that $ and  @  are  handled  as  literals  in  \Q...\E
2840         sequences in PCRE, whereas in Perl, $ and @ cause  variable  interpola-         sequences  in  PCRE, whereas in Perl, $ and @ cause variable interpola-
2841         tion. Note the following examples:         tion. Note the following examples:
2842    
2843           Pattern            PCRE matches   Perl matches           Pattern            PCRE matches   Perl matches
# Line 2777  BACKSLASH Line 2847  BACKSLASH
2847           \Qabc\$xyz\E       abc\$xyz       abc\$xyz           \Qabc\$xyz\E       abc\$xyz       abc\$xyz
2848           \Qabc\E\$\Qxyz\E   abc$xyz        abc$xyz           \Qabc\E\$\Qxyz\E   abc$xyz        abc$xyz
2849    
2850         The  \Q...\E  sequence  is recognized both inside and outside character         The \Q...\E sequence is recognized both inside  and  outside  character
2851         classes.         classes.
2852    
2853     Non-printing characters     Non-printing characters
2854    
2855         A second use of backslash provides a way of encoding non-printing char-         A second use of backslash provides a way of encoding non-printing char-
2856         acters  in patterns in a visible manner. There is no restriction on the         acters in patterns in a visible manner. There is no restriction on  the
2857         appearance of non-printing characters, apart from the binary zero  that         appearance  of non-printing characters, apart from the binary zero that
2858         terminates  a  pattern,  but  when  a pattern is being prepared by text         terminates a pattern, but when a pattern  is  being  prepared  by  text
2859         editing, it is usually easier  to  use  one  of  the  following  escape         editing,  it  is  usually  easier  to  use  one of the following escape
2860         sequences than the binary character it represents:         sequences than the binary character it represents:
2861    
2862           \a        alarm, that is, the BEL character (hex 07)           \a        alarm, that is, the BEL character (hex 07)
# Line 2800  BACKSLASH Line 2870  BACKSLASH
2870           \xhh      character with hex code hh           \xhh      character with hex code hh
2871           \x{hhh..} character with hex code hhh..           \x{hhh..} character with hex code hhh..
2872    
2873         The  precise  effect of \cx is as follows: if x is a lower case letter,         The precise effect of \cx is as follows: if x is a lower  case  letter,
2874         it is converted to upper case. Then bit 6 of the character (hex 40)  is         it  is converted to upper case. Then bit 6 of the character (hex 40) is
2875         inverted.   Thus  \cz becomes hex 1A, but \c{ becomes hex 3B, while \c;         inverted.  Thus \cz becomes hex 1A, but \c{ becomes hex 3B,  while  \c;
2876         becomes hex 7B.         becomes hex 7B.
2877    
2878         After \x, from zero to two hexadecimal digits are read (letters can  be         After  \x, from zero to two hexadecimal digits are read (letters can be
2879         in  upper  or  lower case). Any number of hexadecimal digits may appear         in upper or lower case). Any number of hexadecimal  digits  may  appear
2880         between \x{ and }, but the value of the character  code  must  be  less         between  \x{  and  },  but the value of the character code must be less
2881         than 256 in non-UTF-8 mode, and less than 2**31 in UTF-8 mode (that is,         than 256 in non-UTF-8 mode, and less than 2**31 in UTF-8 mode (that is,
2882         the maximum hexadecimal value is 7FFFFFFF). If  characters  other  than         the  maximum  hexadecimal  value is 7FFFFFFF). If characters other than
2883         hexadecimal  digits  appear between \x{ and }, or if there is no termi-         hexadecimal digits appear between \x{ and }, or if there is  no  termi-
2884         nating }, this form of escape is not recognized.  Instead, the  initial         nating  }, this form of escape is not recognized.  Instead, the initial
2885         \x will be interpreted as a basic hexadecimal escape, with no following         \x will be interpreted as a basic hexadecimal escape, with no following
2886         digits, giving a character whose value is zero.         digits, giving a character whose value is zero.
2887    
2888         Characters whose value is less than 256 can be defined by either of the         Characters whose value is less than 256 can be defined by either of the
2889         two  syntaxes  for  \x. There is no difference in the way they are han-         two syntaxes for \x. There is no difference in the way  they  are  han-
2890         dled. For example, \xdc is exactly the same as \x{dc}.         dled. For example, \xdc is exactly the same as \x{dc}.
2891    
2892         After \0 up to two further octal digits are read. If  there  are  fewer         After  \0  up  to two further octal digits are read. If there are fewer
2893         than  two  digits,  just  those  that  are  present  are used. Thus the         than two digits, just  those  that  are  present  are  used.  Thus  the
2894         sequence \0\x\07 specifies two binary zeros followed by a BEL character         sequence \0\x\07 specifies two binary zeros followed by a BEL character
2895         (code  value 7). Make sure you supply two digits after the initial zero         (code value 7). Make sure you supply two digits after the initial  zero
2896         if the pattern character that follows is itself an octal digit.         if the pattern character that follows is itself an octal digit.
2897    
2898         The handling of a backslash followed by a digit other than 0 is compli-         The handling of a backslash followed by a digit other than 0 is compli-
2899         cated.  Outside a character class, PCRE reads it and any following dig-         cated.  Outside a character class, PCRE reads it and any following dig-
2900         its as a decimal number. If the number is less than  10,  or  if  there         its  as  a  decimal  number. If the number is less than 10, or if there
2901         have been at least that many previous capturing left parentheses in the         have been at least that many previous capturing left parentheses in the
2902         expression, the entire  sequence  is  taken  as  a  back  reference.  A         expression,  the  entire  sequence  is  taken  as  a  back reference. A
2903         description  of how this works is given later, following the discussion         description of how this works is given later, following the  discussion
2904         of parenthesized subpatterns.         of parenthesized subpatterns.
2905    
2906         Inside a character class, or if the decimal number is  greater  than  9         Inside  a  character  class, or if the decimal number is greater than 9
2907         and  there have not been that many capturing subpatterns, PCRE re-reads         and there have not been that many capturing subpatterns, PCRE  re-reads
2908         up to three octal digits following the backslash, and uses them to gen-         up to three octal digits following the backslash, and uses them to gen-
2909         erate  a data character. Any subsequent digits stand for themselves. In         erate a data character. Any subsequent digits stand for themselves.  In
2910         non-UTF-8 mode, the value of a character specified  in  octal  must  be         non-UTF-8  mode,  the  value  of a character specified in octal must be
2911         less  than  \400.  In  UTF-8 mode, values up to \777 are permitted. For         less than \400. In UTF-8 mode, values up to  \777  are  permitted.  For
2912         example:         example:
2913    
2914           \040   is another way of writing a space           \040   is another way of writing a space
# Line 2856  BACKSLASH Line 2926  BACKSLASH
2926           \81    is either a back reference, or a binary zero           \81    is either a back reference, or a binary zero
2927                     followed by the two characters "8" and "1"                     followed by the two characters "8" and "1"
2928    
2929         Note that octal values of 100 or greater must not be  introduced  by  a         Note  that  octal  values of 100 or greater must not be introduced by a
2930         leading zero, because no more than three octal digits are ever read.         leading zero, because no more than three octal digits are ever read.
2931    
2932         All the sequences that define a single character value can be used both         All the sequences that define a single character value can be used both
2933         inside and outside character classes. In addition, inside  a  character         inside  and  outside character classes. In addition, inside a character
2934         class,  the  sequence \b is interpreted as the backspace character (hex         class, the sequence \b is interpreted as the backspace  character  (hex
2935         08), and the sequences \R and \X are interpreted as the characters  "R"         08),  and the sequences \R and \X are interpreted as the characters "R"
2936         and  "X", respectively. Outside a character class, these sequences have         and "X", respectively. Outside a character class, these sequences  have
2937         different meanings (see below).         different meanings (see below).
2938    
2939     Absolute and relative back references     Absolute and relative back references
2940    
2941         The sequence \g followed by a positive or negative  number,  optionally         The  sequence  \g followed by an unsigned or a negative number, option-
2942         enclosed  in  braces,  is  an absolute or relative back reference. Back         ally enclosed in braces, is an absolute or relative back  reference.  A
2943         references are discussed later, following the discussion  of  parenthe-         named back reference can be coded as \g{name}. Back references are dis-
2944         sized subpatterns.         cussed later, following the discussion of parenthesized subpatterns.
2945    
2946     Generic character types     Generic character types
2947    
# Line 2880  BACKSLASH Line 2950  BACKSLASH
2950    
2951           \d     any decimal digit           \d     any decimal digit
2952           \D     any character that is not a decimal digit           \D     any character that is not a decimal digit
2953             \h     any horizontal whitespace character
2954             \H     any character that is not a horizontal whitespace character
2955           \s     any whitespace character           \s     any whitespace character
2956           \S     any character that is not a whitespace character           \S     any character that is not a whitespace character
2957             \v     any vertical whitespace character
2958             \V     any character that is not a vertical whitespace character
2959           \w     any "word" character           \w     any "word" character
2960           \W     any "non-word" character           \W     any "non-word" character
2961    
2962         Each pair of escape sequences partitions the complete set of characters         Each pair of escape sequences partitions the complete set of characters
2963         into  two disjoint sets. Any given character matches one, and only one,         into two disjoint sets. Any given character matches one, and only  one,
2964         of each pair.         of each pair.
2965    
2966         These character type sequences can appear both inside and outside char-         These character type sequences can appear both inside and outside char-
2967         acter  classes.  They each match one character of the appropriate type.         acter classes. They each match one character of the  appropriate  type.
2968         If the current matching point is at the end of the subject string,  all         If  the current matching point is at the end of the subject string, all
2969         of them fail, since there is no character to match.         of them fail, since there is no character to match.
2970    
2971         For  compatibility  with Perl, \s does not match the VT character (code         For compatibility with Perl, \s does not match the VT  character  (code
2972         11).  This makes it different from the the POSIX "space" class. The  \s         11).   This makes it different from the the POSIX "space" class. The \s
2973         characters  are  HT (9), LF (10), FF (12), CR (13), and space (32). (If         characters are HT (9), LF (10), FF (12), CR (13), and  space  (32).  If
2974         "use locale;" is included in a Perl script, \s may match the VT charac-         "use locale;" is included in a Perl script, \s may match the VT charac-
2975         ter. In PCRE, it never does.)         ter. In PCRE, it never does.
2976    
2977         A "word" character is an underscore or any character less than 256 that         In UTF-8 mode, characters with values greater than 128 never match  \d,
        is a letter or digit. The definition of  letters  and  digits  is  con-  
        trolled  by PCRE's low-valued character tables, and may vary if locale-  
        specific matching is taking place (see "Locale support" in the  pcreapi  
        page).  For  example,  in  the  "fr_FR" (French) locale, some character  
        codes greater than 128 are used for accented  letters,  and  these  are  
        matched by \w.  
   
        In  UTF-8 mode, characters with values greater than 128 never match \d,  
2978         \s, or \w, and always match \D, \S, and \W. This is true even when Uni-         \s, or \w, and always match \D, \S, and \W. This is true even when Uni-
2979         code  character  property support is available. The use of locales with         code character property support is available.  These  sequences  retain
2980         Unicode is discouraged.         their original meanings from before UTF-8 support was available, mainly
2981           for efficiency reasons.
2982    
2983           The sequences \h, \H, \v, and \V are Perl 5.10 features. In contrast to
2984           the  other  sequences, these do match certain high-valued codepoints in
2985           UTF-8 mode.  The horizontal space characters are:
2986    
2987             U+0009     Horizontal tab
2988             U+0020     Space
2989             U+00A0     Non-break space
2990             U+1680     Ogham space mark
2991             U+180E     Mongolian vowel separator
2992             U+2000     En quad
2993             U+2001     Em quad
2994             U+2002     En space
2995             U+2003     Em space
2996             U+2004     Three-per-em space
2997             U+2005     Four-per-em space
2998             U+2006     Six-per-em space
2999             U+2007     Figure space
3000             U+2008     Punctuation space
3001             U+2009     Thin space
3002             U+200A     Hair space
3003             U+202F     Narrow no-break space
3004             U+205F     Medium mathematical space
3005             U+3000     Ideographic space
3006    
3007           The vertical space characters are:
3008    
3009             U+000A     Linefeed
3010             U+000B     Vertical tab
3011             U+000C     Formfeed
3012             U+000D     Carriage return
3013             U+0085     Next line
3014             U+2028     Line separator
3015             U+2029     Paragraph separator
3016    
3017           A "word" character is an underscore or any character less than 256 that
3018           is  a  letter  or  digit.  The definition of letters and digits is con-
3019           trolled by PCRE's low-valued character tables, and may vary if  locale-
3020           specific  matching is taking place (see "Locale support" in the pcreapi
3021           page). For example, in a French locale such  as  "fr_FR"  in  Unix-like
3022           systems,  or "french" in Windows, some character codes greater than 128
3023           are used for accented letters, and these are matched by \w. The use  of
3024           locales with Unicode is discouraged.
3025    
3026     Newline sequences     Newline sequences
3027    
3028         Outside a character class, the escape sequence \R matches  any  Unicode         Outside  a  character class, the escape sequence \R matches any Unicode
3029         newline sequence. This is an extension to Perl. In non-UTF-8 mode \R is         newline sequence. This is a Perl 5.10 feature. In non-UTF-8 mode \R  is
3030         equivalent to the following:         equivalent to the following:
3031    
3032           (?>\r\n|\n|\x0b|\f|\r|\x85)           (?>\r\n|\n|\x0b|\f|\r|\x85)
3033    
3034         This is an example of an "atomic group", details  of  which  are  given         This  is  an  example  of an "atomic group", details of which are given
3035         below.  This particular group matches either the two-character sequence         below.  This particular group matches either the two-character sequence
3036         CR followed by LF, or  one  of  the  single  characters  LF  (linefeed,         CR  followed  by  LF,  or  one  of  the single characters LF (linefeed,
3037         U+000A), VT (vertical tab, U+000B), FF (formfeed, U+000C), CR (carriage         U+000A), VT (vertical tab, U+000B), FF (formfeed, U+000C), CR (carriage
3038         return, U+000D), or NEL (next line, U+0085). The two-character sequence         return, U+000D), or NEL (next line, U+0085). The two-character sequence
3039         is treated as a single unit that cannot be split.         is treated as a single unit that cannot be split.
3040    
3041         In  UTF-8  mode, two additional characters whose codepoints are greater         In UTF-8 mode, two additional characters whose codepoints  are  greater
3042         than 255 are added: LS (line separator, U+2028) and PS (paragraph sepa-         than 255 are added: LS (line separator, U+2028) and PS (paragraph sepa-
3043         rator,  U+2029).   Unicode character property support is not needed for         rator, U+2029).  Unicode character property support is not  needed  for
3044         these characters to be recognized.         these characters to be recognized.
3045    
3046         Inside a character class, \R matches the letter "R".         Inside a character class, \R matches the letter "R".
# Line 2938  BACKSLASH Line 3048  BACKSLASH
3048     Unicode character properties     Unicode character properties
3049    
3050         When PCRE is built with Unicode character property support, three addi-         When PCRE is built with Unicode character property support, three addi-
3051         tional  escape  sequences  to  match character properties are available         tional escape sequences that match characters with specific  properties
3052         when UTF-8 mode is selected. They are:         are  available.   When not in UTF-8 mode, these sequences are of course
3053           limited to testing characters whose codepoints are less than  256,  but
3054           they do work in this mode.  The extra escape sequences are:
3055    
3056           \p{xx}   a character with the xx property           \p{xx}   a character with the xx property
3057           \P{xx}   a character without the xx property           \P{xx}   a character without the xx property
3058           \X       an extended Unicode sequence           \X       an extended Unicode sequence
3059    
3060         The property names represented by xx above are limited to  the  Unicode         The  property  names represented by xx above are limited to the Unicode
3061         script names, the general category properties, and "Any", which matches         script names, the general category properties, and "Any", which matches
3062         any character (including newline). Other properties such as "InMusical-         any character (including newline). Other properties such as "InMusical-
3063         Symbols"  are  not  currently supported by PCRE. Note that \P{Any} does         Symbols" are not currently supported by PCRE. Note  that  \P{Any}  does
3064         not match any characters, so always causes a match failure.         not match any characters, so always causes a match failure.
3065    
3066         Sets of Unicode characters are defined as belonging to certain scripts.         Sets of Unicode characters are defined as belonging to certain scripts.
3067         A  character from one of these sets can be matched using a script name.         A character from one of these sets can be matched using a script  name.
3068         For example:         For example:
3069    
3070           \p{Greek}           \p{Greek}
3071           \P{Han}           \P{Han}
3072    
3073         Those that are not part of an identified script are lumped together  as         Those  that are not part of an identified script are lumped together as
3074         "Common". The current list of scripts is:         "Common". The current list of scripts is:
3075    
3076         Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,         Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,
3077         Buhid,  Canadian_Aboriginal,  Cherokee,  Common,   Coptic,   Cuneiform,         Buhid,   Canadian_Aboriginal,   Cherokee,  Common,  Coptic,  Cuneiform,
3078         Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,         Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,
3079         Gothic, Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew,  Hira-         Gothic,  Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hira-
3080         gana,  Inherited,  Kannada,  Katakana,  Kharoshthi,  Khmer, Lao, Latin,         gana, Inherited, Kannada,  Katakana,  Kharoshthi,  Khmer,  Lao,  Latin,
3081         Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,         Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,
3082         Ogham,  Old_Italic,  Old_Persian, Oriya, Osmanya, Phags_Pa, Phoenician,         Ogham, Old_Italic, Old_Persian, Oriya, Osmanya,  Phags_Pa,  Phoenician,
3083         Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,         Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,
3084         Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.         Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.
3085    
3086         Each  character has exactly one general category property, specified by         Each character has exactly one general category property, specified  by
3087         a two-letter abbreviation. For compatibility with Perl, negation can be         a two-letter abbreviation. For compatibility with Perl, negation can be
3088         specified  by  including a circumflex between the opening brace and the         specified by including a circumflex between the opening brace  and  the
3089         property name. For example, \p{^Lu} is the same as \P{Lu}.         property name. For example, \p{^Lu} is the same as \P{Lu}.
3090    
3091         If only one letter is specified with \p or \P, it includes all the gen-         If only one letter is specified with \p or \P, it includes all the gen-
3092         eral  category properties that start with that letter. In this case, in         eral category properties that start with that letter. In this case,  in
3093         the absence of negation, the curly brackets in the escape sequence  are         the  absence of negation, the curly brackets in the escape sequence are
3094         optional; these two examples have the same effect:         optional; these two examples have the same effect:
3095    
3096           \p{L}           \p{L}
# Line 3030  BACKSLASH Line 3142  BACKSLASH
3142           Zp    Paragraph separator           Zp    Paragraph separator
3143           Zs    Space separator           Zs    Space separator
3144    
3145         The  special property L& is also supported: it matches a character that         The special property L& is also supported: it matches a character  that
3146         has the Lu, Ll, or Lt property, in other words, a letter  that  is  not         has  the  Lu,  Ll, or Lt property, in other words, a letter that is not
3147         classified as a modifier or "other".         classified as a modifier or "other".
3148    
3149         The  long  synonyms  for  these  properties that Perl supports (such as         The long synonyms for these properties  that  Perl  supports  (such  as
3150         \p{Letter}) are not supported by PCRE, nor is it  permitted  to  prefix         \p{Letter})  are  not  supported by PCRE, nor is it permitted to prefix
3151         any of these properties with "Is".         any of these properties with "Is".
3152    
3153         No character that is in the Unicode table has the Cn (unassigned) prop-         No character that is in the Unicode table has the Cn (unassigned) prop-
3154         erty.  Instead, this property is assumed for any code point that is not         erty.  Instead, this property is assumed for any code point that is not
3155         in the Unicode table.         in the Unicode table.
3156    
3157         Specifying  caseless  matching  does not affect these escape sequences.         Specifying caseless matching does not affect  these  escape  sequences.
3158         For example, \p{Lu} always matches only upper case letters.         For example, \p{Lu} always matches only upper case letters.
3159    
3160         The \X escape matches any number of Unicode  characters  that  form  an         The  \X  escape  matches  any number of Unicode characters that form an
3161         extended Unicode sequence. \X is equivalent to         extended Unicode sequence. \X is equivalent to
3162    
3163           (?>\PM\pM*)           (?>\PM\pM*)
3164    
3165         That  is,  it matches a character without the "mark" property, followed         That is, it matches a character without the "mark"  property,  followed
3166         by zero or more characters with the "mark"  property,  and  treats  the         by  zero  or  more  characters with the "mark" property, and treats the
3167         sequence  as  an  atomic group (see below).  Characters with the "mark"         sequence as an atomic group (see below).  Characters  with  the  "mark"
3168         property are typically accents that affect the preceding character.         property  are  typically  accents  that affect the preceding character.
3169           None of them have codepoints less than 256, so  in  non-UTF-8  mode  \X
3170           matches any one character.
3171    
3172         Matching characters by Unicode property is not fast, because  PCRE  has         Matching  characters  by Unicode property is not fast, because PCRE has
3173         to  search  a  structure  that  contains data for over fifteen thousand         to search a structure that contains  data  for  over  fifteen  thousand
3174         characters. That is why the traditional escape sequences such as \d and         characters. That is why the traditional escape sequences such as \d and
3175         \w do not use Unicode properties in PCRE.         \w do not use Unicode properties in PCRE.
3176    
3177       Resetting the match start
3178    
3179           The escape sequence \K, which is a Perl 5.10 feature, causes any previ-
3180           ously  matched  characters  not  to  be  included  in the final matched
3181           sequence. For example, the pattern:
3182    
3183             foo\Kbar
3184    
3185           matches "foobar", but reports that it has matched "bar".  This  feature
3186           is  similar  to  a lookbehind assertion (described below).  However, in
3187           this case, the part of the subject before the real match does not  have
3188           to  be of fixed length, as lookbehind assertions do. The use of \K does
3189           not interfere with the setting of captured  substrings.   For  example,
3190           when the pattern
3191    
3192             (foo)\Kbar
3193    
3194           matches "foobar", the first substring is still set to "foo".
3195    
3196     Simple assertions     Simple assertions
3197    
3198         The  final use of backslash is for certain simple assertions. An asser-         The  final use of backslash is for certain simple assertions. An asser-
# Line 3275  SQUARE BRACKETS AND CHARACTER CLASSES Line 3408  SQUARE BRACKETS AND CHARACTER CLASSES
3408         If a range that includes letters is used when caseless matching is set,         If a range that includes letters is used when caseless matching is set,
3409         it matches the letters in either case. For example, [W-c] is equivalent         it matches the letters in either case. For example, [W-c] is equivalent
3410         to  [][\\^_`wxyzabc],  matched  caselessly,  and  in non-UTF-8 mode, if         to  [][\\^_`wxyzabc],  matched  caselessly,  and  in non-UTF-8 mode, if
3411         character tables for the "fr_FR" locale are in use, [\xc8-\xcb] matches         character tables for a French locale are in  use,  [\xc8-\xcb]  matches
3412         accented  E  characters in both cases. In UTF-8 mode, PCRE supports the         accented  E  characters in both cases. In UTF-8 mode, PCRE supports the
3413         concept of case for characters with values greater than 128  only  when         concept of case for characters with values greater than 128  only  when
3414         it is compiled with Unicode property support.         it is compiled with Unicode property support.
# Line 3460  SUBPATTERNS Line 3593  SUBPATTERNS
3593         "Saturday".         "Saturday".
3594    
3595    
3596    DUPLICATE SUBPATTERN NUMBERS
3597    
3598           Perl 5.10 introduced a feature whereby each alternative in a subpattern
3599           uses the same numbers for its capturing parentheses. Such a  subpattern
3600           starts  with (?| and is itself a non-capturing subpattern. For example,
3601           consider this pattern:
3602    
3603             (?|(Sat)ur|(Sun))day
3604    
3605           Because the two alternatives are inside a (?| group, both sets of  cap-
3606           turing  parentheses  are  numbered one. Thus, when the pattern matches,
3607           you can look at captured substring number  one,  whichever  alternative
3608           matched.  This  construct  is useful when you want to capture part, but
3609           not all, of one of a number of alternatives. Inside a (?| group, paren-
3610           theses  are  numbered as usual, but the number is reset at the start of
3611           each branch. The numbers of any capturing buffers that follow the  sub-
3612           pattern  start after the highest number used in any branch. The follow-
3613           ing example is taken from the Perl documentation.  The  numbers  under-
3614           neath show in which buffer the captured content will be stored.
3615    
3616             # before  ---------------branch-reset----------- after
3617             / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
3618             # 1            2         2  3        2     3     4
3619    
3620           A  backreference  or  a  recursive call to a numbered subpattern always
3621           refers to the first one in the pattern with the given number.
3622    
3623           An alternative approach to using this "branch reset" feature is to  use
3624           duplicate named subpatterns, as described in the next section.
3625    
3626    
3627  NAMED SUBPATTERNS  NAMED SUBPATTERNS
3628    
3629         Identifying  capturing  parentheses  by number is simple, but it can be         Identifying  capturing  parentheses  by number is simple, but it can be
# Line 3499  NAMED SUBPATTERNS Line 3663  NAMED SUBPATTERNS
3663           (?<DN>Sat)(?:urday)?           (?<DN>Sat)(?:urday)?
3664    
3665         There  are  five capturing substrings, but only one is ever set after a         There  are  five capturing substrings, but only one is ever set after a
3666         match.  The convenience  function  for  extracting  the  data  by  name         match.  (An alternative way of solving this problem is to use a "branch
3667         returns  the  substring  for  the first (and in this example, the only)         reset" subpattern, as described in the previous section.)
3668         subpattern of that name that matched.  This  saves  searching  to  find  
3669         which  numbered  subpattern  it  was. If you make a reference to a non-         The  convenience  function  for extracting the data by name returns the
3670         unique named subpattern from elsewhere in the  pattern,  the  one  that         substring for the first (and in this example, the only)  subpattern  of
3671         corresponds  to  the  lowest number is used. For further details of the         that  name  that  matched.  This saves searching to find which numbered
3672         interfaces for handling named subpatterns, see the  pcreapi  documenta-         subpattern it was. If you make a reference to a non-unique  named  sub-
3673         tion.         pattern  from elsewhere in the pattern, the one that corresponds to the
3674           lowest number is used. For further details of the interfaces  for  han-
3675           dling named subpatterns, see the pcreapi documentation.
3676    
3677    
3678  REPETITION  REPETITION
# Line 3711  ATOMIC GROUPING AND POSSESSIVE QUANTIFIE Line 3877  ATOMIC GROUPING AND POSSESSIVE QUANTIFIE
3877    
3878           \d++foo           \d++foo
3879    
3880         Possessive  quantifiers  are  always  greedy;  the   setting   of   the         Note that a possessive quantifier can be used with an entire group, for
3881           example:
3882    
3883             (abc|xyz){2,3}+
3884    
3885           Possessive   quantifiers   are   always  greedy;  the  setting  of  the
3886         PCRE_UNGREEDY option is ignored. They are a convenient notation for the         PCRE_UNGREEDY option is ignored. They are a convenient notation for the
3887         simpler forms of atomic group. However, there is no difference  in  the         simpler  forms  of atomic group. However, there is no difference in the
3888         meaning  of  a  possessive  quantifier and the equivalent atomic group,         meaning of a possessive quantifier and  the  equivalent  atomic  group,
3889         though there may be a performance  difference;  possessive  quantifiers         though  there  may  be a performance difference; possessive quantifiers
3890         should be slightly faster.         should be slightly faster.
3891    
3892         The  possessive  quantifier syntax is an extension to the Perl 5.8 syn-         The possessive quantifier syntax is an extension to the Perl  5.8  syn-
3893         tax.  Jeffrey Friedl originated the idea (and the name)  in  the  first         tax.   Jeffrey  Friedl  originated the idea (and the name) in the first
3894         edition of his book. Mike McCloskey liked it, so implemented it when he         edition of his book. Mike McCloskey liked it, so implemented it when he
3895         built Sun's Java package, and PCRE copied it from there. It  ultimately         built  Sun's Java package, and PCRE copied it from there. It ultimately
3896         found its way into Perl at release 5.10.         found its way into Perl at release 5.10.
3897    
3898         PCRE has an optimization that automatically "possessifies" certain sim-         PCRE has an optimization that automatically "possessifies" certain sim-
3899         ple pattern constructs. For example, the sequence  A+B  is  treated  as         ple  pattern  constructs.  For  example, the sequence A+B is treated as
3900         A++B  because  there is no point in backtracking into a sequence of A's         A++B because there is no point in backtracking into a sequence  of  A's
3901         when B must follow.         when B must follow.
3902    
3903         When a pattern contains an unlimited repeat inside  a  subpattern  that         When  a  pattern  contains an unlimited repeat inside a subpattern that
3904         can  itself  be  repeated  an  unlimited number of times, the use of an         can itself be repeated an unlimited number of  times,  the  use  of  an
3905         atomic group is the only way to avoid some  failing  matches  taking  a         atomic  group  is  the  only way to avoid some failing matches taking a
3906         very long time indeed. The pattern         very long time indeed. The pattern
3907    
3908           (\D+|<\d+>)*[!?]           (\D+|<\d+>)*[!?]
3909    
3910         matches  an  unlimited number of substrings that either consist of non-         matches an unlimited number of substrings that either consist  of  non-
3911         digits, or digits enclosed in <>, followed by either ! or  ?.  When  it         digits,  or  digits  enclosed in <>, followed by either ! or ?. When it
3912         matches, it runs quickly. However, if it is applied to         matches, it runs quickly. However, if it is applied to
3913    
3914           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
3915    
3916         it  takes  a  long  time  before reporting failure. This is because the         it takes a long time before reporting  failure.  This  is  because  the
3917         string can be divided between the internal \D+ repeat and the  external         string  can be divided between the internal \D+ repeat and the external
3918         *  repeat  in  a  large  number of ways, and all have to be tried. (The         * repeat in a large number of ways, and all  have  to  be  tried.  (The
3919         example uses [!?] rather than a single character at  the  end,  because         example  uses  [!?]  rather than a single character at the end, because
3920         both  PCRE  and  Perl have an optimization that allows for fast failure         both PCRE and Perl have an optimization that allows  for  fast  failure
3921         when a single character is used. They remember the last single  charac-         when  a single character is used. They remember the last single charac-
3922         ter  that  is required for a match, and fail early if it is not present         ter that is required for a match, and fail early if it is  not  present
3923         in the string.) If the pattern is changed so that  it  uses  an  atomic         in  the  string.)  If  the pattern is changed so that it uses an atomic
3924         group, like this:         group, like this:
3925    
3926           ((?>\D+)|<\d+>)*[!?]           ((?>\D+)|<\d+>)*[!?]
3927    
3928         sequences  of non-digits cannot be broken, and failure happens quickly.         sequences of non-digits cannot be broken, and failure happens  quickly.
3929    
3930    
3931  BACK REFERENCES  BACK REFERENCES
3932    
3933         Outside a character class, a backslash followed by a digit greater than         Outside a character class, a backslash followed by a digit greater than
3934         0 (and possibly further digits) is a back reference to a capturing sub-         0 (and possibly further digits) is a back reference to a capturing sub-
3935         pattern earlier (that is, to its left) in the pattern,  provided  there         pattern  earlier  (that is, to its left) in the pattern, provided there
3936         have been that many previous capturing left parentheses.         have been that many previous capturing left parentheses.
3937    
3938         However, if the decimal number following the backslash is less than 10,         However, if the decimal number following the backslash is less than 10,
3939         it is always taken as a back reference, and causes  an  error  only  if         it  is  always  taken  as a back reference, and causes an error only if
3940         there  are  not that many capturing left parentheses in the entire pat-         there are not that many capturing left parentheses in the  entire  pat-
3941         tern. In other words, the parentheses that are referenced need  not  be         tern.  In  other words, the parentheses that are referenced need not be
3942         to  the left of the reference for numbers less than 10. A "forward back         to the left of the reference for numbers less than 10. A "forward  back
3943         reference" of this type can make sense when a  repetition  is  involved         reference"  of  this  type can make sense when a repetition is involved
3944         and  the  subpattern to the right has participated in an earlier itera-         and the subpattern to the right has participated in an  earlier  itera-
3945         tion.         tion.
3946    
3947         It is not possible to have a numerical "forward back  reference"  to  a         It  is  not  possible to have a numerical "forward back reference" to a
3948         subpattern  whose  number  is  10  or  more using this syntax because a         subpattern whose number is 10 or  more  using  this  syntax  because  a
3949         sequence such as \50 is interpreted as a character  defined  in  octal.         sequence  such  as  \50 is interpreted as a character defined in octal.
3950         See the subsection entitled "Non-printing characters" above for further         See the subsection entitled "Non-printing characters" above for further
3951         details of the handling of digits following a backslash.  There  is  no         details  of  the  handling of digits following a backslash. There is no
3952         such  problem  when named parentheses are used. A back reference to any         such problem when named parentheses are used. A back reference  to  any
3953         subpattern is possible using named parentheses (see below).         subpattern is possible using named parentheses (see below).
3954    
3955         Another way of avoiding the ambiguity inherent in  the  use  of  digits         Another  way  of  avoiding  the ambiguity inherent in the use of digits
3956         following a backslash is to use the \g escape sequence, which is a fea-         following a backslash is to use the \g escape sequence, which is a fea-
3957         ture introduced in Perl 5.10. This escape must be followed by  a  posi-         ture  introduced  in  Perl  5.10.  This  escape  must be followed by an
3958         tive  or  a negative number, optionally enclosed in braces. These exam-         unsigned number or a negative number, optionally  enclosed  in  braces.
3959         ples are all identical:         These examples are all identical:
3960    
3961           (ring), \1           (ring), \1
3962           (ring), \g1           (ring), \g1
3963           (ring), \g{1}           (ring), \g{1}
3964    
3965         A positive number specifies an absolute reference without the ambiguity         An  unsigned number specifies an absolute reference without the ambigu-
3966         that  is  present  in  the older syntax. It is also useful when literal         ity that is present in the older syntax. It is also useful when literal
3967         digits follow the reference. A negative number is a relative reference.         digits follow the reference. A negative number is a relative reference.
3968         Consider this example:         Consider this example:
3969    
3970           (abc(def)ghi)\g{-1}           (abc(def)ghi)\g{-1}
3971    
3972         The sequence \g{-1} is a reference to the most recently started captur-         The sequence \g{-1} is a reference to the most recently started captur-
3973         ing subpattern before \g, that is, is it equivalent to  \2.  Similarly,         ing  subpattern  before \g, that is, is it equivalent to \2. Similarly,
3974         \g{-2} would be equivalent to \1. The use of relative references can be         \g{-2} would be equivalent to \1. The use of relative references can be
3975         helpful in long patterns, and also in  patterns  that  are  created  by         helpful  in  long  patterns,  and  also in patterns that are created by
3976         joining together fragments that contain references within themselves.         joining together fragments that contain references within themselves.
3977    
3978         A  back  reference matches whatever actually matched the capturing sub-         A back reference matches whatever actually matched the  capturing  sub-
3979         pattern in the current subject string, rather  than  anything  matching         pattern  in  the  current subject string, rather than anything matching
3980         the subpattern itself (see "Subpatterns as subroutines" below for a way         the subpattern itself (see "Subpatterns as subroutines" below for a way
3981         of doing that). So the pattern         of doing that). So the pattern
3982    
3983           (sens|respons)e and \1ibility           (sens|respons)e and \1ibility
3984    
3985         matches "sense and sensibility" and "response and responsibility",  but         matches  "sense and sensibility" and "response and responsibility", but
3986         not  "sense and responsibility". If caseful matching is in force at the         not "sense and responsibility". If caseful matching is in force at  the
3987         time of the back reference, the case of letters is relevant. For  exam-         time  of the back reference, the case of letters is relevant. For exam-
3988         ple,         ple,
3989    
3990           ((?i)rah)\s+\1           ((?i)rah)\s+\1
3991    
3992         matches  "rah  rah"  and  "RAH RAH", but not "RAH rah", even though the         matches "rah rah" and "RAH RAH", but not "RAH  rah",  even  though  the
3993         original capturing subpattern is matched caselessly.         original capturing subpattern is matched caselessly.
3994    
3995         Back references to named subpatterns use the Perl  syntax  \k<name>  or         There  are  several  different ways of writing back references to named
3996         \k'name'  or  the  Python  syntax (?P=name). We could rewrite the above         subpatterns. The .NET syntax \k{name} and the Perl syntax  \k<name>  or
3997         example in either of the following ways:         \k'name'  are supported, as is the Python syntax (?P=name). Perl 5.10's
3998           unified back reference syntax, in which \g can be used for both numeric
3999           and  named  references,  is  also supported. We could rewrite the above
4000           example in any of the following ways:
4001    
4002           (?<p1>(?i)rah)\s+\k<p1>           (?<p1>(?i)rah)\s+\k<p1>
4003             (?'p1'(?i)rah)\s+\k{p1}
4004           (?P<p1>(?i)rah)\s+(?P=p1)           (?P<p1>(?i)rah)\s+(?P=p1)
4005             (?<p1>(?i)rah)\s+\g{p1}
4006    
4007         A subpattern that is referenced by  name  may  appear  in  the  pattern         A subpattern that is referenced by  name  may  appear  in  the  pattern
4008         before or after the reference.         before or after the reference.
# Line 3941  ASSERTIONS Line 4117  ASSERTIONS
4117    
4118           (?<=abc|abde)           (?<=abc|abde)
4119    
4120           In some cases, the Perl 5.10 escape sequence \K (see above) can be used
4121           instead  of  a lookbehind assertion; this is not restricted to a fixed-
4122           length.
4123    
4124         The implementation of lookbehind assertions is, for  each  alternative,         The implementation of lookbehind assertions is, for  each  alternative,
4125         to  temporarily  move the current position back by the fixed length and         to  temporarily  move the current position back by the fixed length and
4126         then try to match. If there are insufficient characters before the cur-         then try to match. If there are insufficient characters before the cur-
# Line 4034  CONDITIONAL SUBPATTERNS Line 4214  CONDITIONAL SUBPATTERNS
4214    
4215         If  the  text between the parentheses consists of a sequence of digits,         If  the  text between the parentheses consists of a sequence of digits,
4216         the condition is true if the capturing subpattern of  that  number  has         the condition is true if the capturing subpattern of  that  number  has
4217         previously matched.         previously  matched.  An  alternative notation is to precede the digits
4218           with a plus or minus sign. In this case, the subpattern number is rela-
4219           tive rather than absolute.  The most recently opened parentheses can be
4220           referenced by (?(-1), the next most recent by (?(-2),  and  so  on.  In
4221           looping constructs it can also make sense to refer to subsequent groups
4222           with constructs such as (?(+2).
4223    
4224         Consider  the  following  pattern, which contains non-significant white         Consider the following pattern, which  contains  non-significant  white
4225         space to make it more readable (assume the PCRE_EXTENDED option) and to         space to make it more readable (assume the PCRE_EXTENDED option) and to
4226         divide it into three parts for ease of discussion:         divide it into three parts for ease of discussion:
4227    
4228           ( \( )?    [^()]+    (?(1) \) )           ( \( )?    [^()]+    (?(1) \) )
4229    
4230         The  first  part  matches  an optional opening parenthesis, and if that         The first part matches an optional opening  parenthesis,  and  if  that
4231         character is present, sets it as the first captured substring. The sec-         character is present, sets it as the first captured substring. The sec-
4232         ond  part  matches one or more characters that are not parentheses. The         ond part matches one or more characters that are not  parentheses.  The
4233         third part is a conditional subpattern that tests whether the first set         third part is a conditional subpattern that tests whether the first set
4234         of parentheses matched or not. If they did, that is, if subject started         of parentheses matched or not. If they did, that is, if subject started
4235         with an opening parenthesis, the condition is true, and so the yes-pat-         with an opening parenthesis, the condition is true, and so the yes-pat-
4236         tern  is  executed  and  a  closing parenthesis is required. Otherwise,         tern is executed and a  closing  parenthesis  is  required.  Otherwise,
4237         since no-pattern is not present, the  subpattern  matches  nothing.  In         since  no-pattern  is  not  present, the subpattern matches nothing. In
4238         other  words,  this  pattern  matches  a  sequence  of non-parentheses,         other words,  this  pattern  matches  a  sequence  of  non-parentheses,
4239         optionally enclosed in parentheses.         optionally enclosed in parentheses.
4240    
4241           If  you  were  embedding  this pattern in a larger one, you could use a
4242           relative reference:
4243    
4244             ...other stuff... ( \( )?    [^()]+    (?(-1) \) ) ...
4245    
4246           This makes the fragment independent of the parentheses  in  the  larger
4247           pattern.
4248    
4249     Checking for a used subpattern by name     Checking for a used subpattern by name
4250    
4251         Perl uses the syntax (?(<name>)...) or (?('name')...)  to  test  for  a         Perl  uses  the  syntax  (?(<name>)...) or (?('name')...) to test for a
4252         used  subpattern  by  name.  For compatibility with earlier versions of         used subpattern by name. For compatibility  with  earlier  versions  of
4253         PCRE, which had this facility before Perl, the syntax  (?(name)...)  is         PCRE,  which  had this facility before Perl, the syntax (?(name)...) is
4254         also  recognized. However, there is a possible ambiguity with this syn-         also recognized. However, there is a possible ambiguity with this  syn-
4255         tax, because subpattern names may  consist  entirely  of  digits.  PCRE         tax,  because  subpattern  names  may  consist entirely of digits. PCRE
4256         looks  first for a named subpattern; if it cannot find one and the name         looks first for a named subpattern; if it cannot find one and the  name
4257         consists entirely of digits, PCRE looks for a subpattern of  that  num-         consists  entirely  of digits, PCRE looks for a subpattern of that num-
4258         ber,  which must be greater than zero. Using subpattern names that con-         ber, which must be greater than zero. Using subpattern names that  con-
4259         sist entirely of digits is not recommended.         sist entirely of digits is not recommended.
4260    
4261         Rewriting the above example to use a named subpattern gives this:         Rewriting the above example to use a named subpattern gives this:
# Line 4073  CONDITIONAL SUBPATTERNS Line 4266  CONDITIONAL SUBPATTERNS
4266     Checking for pattern recursion     Checking for pattern recursion
4267    
4268         If the condition is the string (R), and there is no subpattern with the         If the condition is the string (R), and there is no subpattern with the
4269         name  R, the condition is true if a recursive call to the whole pattern         name R, the condition is true if a recursive call to the whole  pattern
4270         or any subpattern has been made. If digits or a name preceded by amper-         or any subpattern has been made. If digits or a name preceded by amper-
4271         sand follow the letter R, for example:         sand follow the letter R, for example:
4272    
4273           (?(R3)...) or (?(R&name)...)           (?(R3)...) or (?(R&name)...)
4274    
4275         the  condition is true if the most recent recursion is into the subpat-         the condition is true if the most recent recursion is into the  subpat-
4276         tern whose number or name is given. This condition does not  check  the         tern  whose  number or name is given. This condition does not check the
4277         entire recursion stack.         entire recursion stack.
4278    
4279         At  "top  level", all these recursion test conditions are false. Recur-         At "top level", all these recursion test conditions are  false.  Recur-
4280         sive patterns are described below.         sive patterns are described below.
4281    
4282     Defining subpatterns for use by reference only     Defining subpatterns for use by reference only
4283    
4284         If the condition is the string (DEFINE), and  there  is  no  subpattern         If  the  condition  is  the string (DEFINE), and there is no subpattern
4285         with  the  name  DEFINE,  the  condition is always false. In this case,         with the name DEFINE, the condition is  always  false.  In  this  case,
4286         there may be only one alternative  in  the  subpattern.  It  is  always         there  may  be  only  one  alternative  in the subpattern. It is always
4287         skipped  if  control  reaches  this  point  in the pattern; the idea of         skipped if control reaches this point  in  the  pattern;  the  idea  of
4288         DEFINE is that it can be used to define "subroutines" that can be  ref-         DEFINE  is that it can be used to define "subroutines" that can be ref-
4289         erenced  from elsewhere. (The use of "subroutines" is described below.)         erenced from elsewhere. (The use of "subroutines" is described  below.)
4290         For example, a pattern to match an IPv4 address could be  written  like         For  example,  a pattern to match an IPv4 address could be written like
4291         this (ignore whitespace and line breaks):         this (ignore whitespace and line breaks):
4292    
4293           (?(DEFINE) (?<byte> 2[0-4]\d | 25[0-5] | 1\d\d | [1-9]?\d) )           (?(DEFINE) (?<byte> 2[0-4]\d | 25[0-5] | 1\d\d | [1-9]?\d) )
4294           \b (?&byte) (\.(?&byte)){3} \b           \b (?&byte) (\.(?&byte)){3} \b
4295    
4296         The  first part of the pattern is a DEFINE group inside which a another         The first part of the pattern is a DEFINE group inside which a  another
4297         group named "byte" is defined. This matches an individual component  of         group  named "byte" is defined. This matches an individual component of
4298         an  IPv4  address  (a number less than 256). When matching takes place,         an IPv4 address (a number less than 256). When  matching  takes  place,
4299         this part of the pattern is skipped because DEFINE acts  like  a  false         this  part  of  the pattern is skipped because DEFINE acts like a false
4300         condition.         condition.
4301    
4302         The rest of the pattern uses references to the named group to match the         The rest of the pattern uses references to the named group to match the
4303         four dot-separated components of an IPv4 address, insisting on  a  word         four  dot-separated  components of an IPv4 address, insisting on a word
4304         boundary at each end.         boundary at each end.
4305    
4306     Assertion conditions     Assertion conditions
4307    
4308         If  the  condition  is  not  in any of the above formats, it must be an         If the condition is not in any of the above  formats,  it  must  be  an
4309         assertion.  This may be a positive or negative lookahead or  lookbehind         assertion.   This may be a positive or negative lookahead or lookbehind
4310         assertion.  Consider  this  pattern,  again  containing non-significant         assertion. Consider  this  pattern,  again  containing  non-significant
4311         white space, and with the two alternatives on the second line:         white space, and with the two alternatives on the second line:
4312    
4313           (?(?=[^a-z]*[a-z])           (?(?=[^a-z]*[a-z])
4314           \d{2}-[a-z]{3}-\d{2}  |  \d{2}-\d{2}-\d{2} )           \d{2}-[a-z]{3}-\d{2}  |  \d{2}-\d{2}-\d{2} )
4315    
4316         The condition  is  a  positive  lookahead  assertion  that  matches  an         The  condition  is  a  positive  lookahead  assertion  that  matches an
4317         optional  sequence of non-letters followed by a letter. In other words,         optional sequence of non-letters followed by a letter. In other  words,
4318         it tests for the presence of at least one letter in the subject.  If  a         it  tests  for the presence of at least one letter in the subject. If a
4319         letter  is found, the subject is matched against the first alternative;         letter is found, the subject is matched against the first  alternative;
4320         otherwise it is  matched  against  the  second.  This  pattern  matches         otherwise  it  is  matched  against  the  second.  This pattern matches
4321         strings  in  one  of the two forms dd-aaa-dd or dd-dd-dd, where aaa are         strings in one of the two forms dd-aaa-dd or dd-dd-dd,  where  aaa  are
4322         letters and dd are digits.         letters and dd are digits.
4323    
4324    
4325  COMMENTS  COMMENTS
4326    
4327         The sequence (?# marks the start of a comment that continues up to  the         The  sequence (?# marks the start of a comment that continues up to the
4328         next  closing  parenthesis.  Nested  parentheses are not permitted. The         next closing parenthesis. Nested parentheses  are  not  permitted.  The
4329         characters that make up a comment play no part in the pattern  matching         characters  that make up a comment play no part in the pattern matching
4330         at all.         at all.
4331    
4332         If  the PCRE_EXTENDED option is set, an unescaped # character outside a         If the PCRE_EXTENDED option is set, an unescaped # character outside  a
4333         character class introduces a  comment  that  continues  to  immediately         character  class  introduces  a  comment  that continues to immediately
4334         after the next newline in the pattern.         after the next newline in the pattern.
4335    
4336    
4337  RECURSIVE PATTERNS  RECURSIVE PATTERNS
4338    
4339         Consider  the problem of matching a string in parentheses, allowing for         Consider the problem of matching a string in parentheses, allowing  for
4340         unlimited nested parentheses. Without the use of  recursion,  the  best         unlimited  nested  parentheses.  Without the use of recursion, the best
4341         that  can  be  done  is  to use a pattern that matches up to some fixed         that can be done is to use a pattern that  matches  up  to  some  fixed
4342         depth of nesting. It is not possible to  handle  an  arbitrary  nesting         depth  of  nesting.  It  is not possible to handle an arbitrary nesting
4343         depth.         depth.
4344    
4345         For some time, Perl has provided a facility that allows regular expres-         For some time, Perl has provided a facility that allows regular expres-
4346         sions to recurse (amongst other things). It does this by  interpolating         sions  to recurse (amongst other things). It does this by interpolating
4347         Perl  code in the expression at run time, and the code can refer to the         Perl code in the expression at run time, and the code can refer to  the
4348         expression itself. A Perl pattern using code interpolation to solve the         expression itself. A Perl pattern using code interpolation to solve the
4349         parentheses problem can be created like this:         parentheses problem can be created like this:
4350    
# Line 4161  RECURSIVE PATTERNS Line 4354  RECURSIVE PATTERNS
4354         refers recursively to the pattern in which it appears.         refers recursively to the pattern in which it appears.
4355    
4356         Obviously, PCRE cannot support the interpolation of Perl code. Instead,         Obviously, PCRE cannot support the interpolation of Perl code. Instead,
4357         it  supports  special  syntax  for recursion of the entire pattern, and         it supports special syntax for recursion of  the  entire  pattern,  and
4358         also for individual subpattern recursion.  After  its  introduction  in         also  for  individual  subpattern  recursion. After its introduction in
4359         PCRE  and  Python,  this  kind of recursion was introduced into Perl at         PCRE and Python, this kind of recursion was  introduced  into  Perl  at
4360         release 5.10.         release 5.10.
4361    
4362         A special item that consists of (? followed by a  number  greater  than         A  special  item  that consists of (? followed by a number greater than
4363         zero and a closing parenthesis is a recursive call of the subpattern of         zero and a closing parenthesis is a recursive call of the subpattern of
4364         the given number, provided that it occurs inside that  subpattern.  (If         the  given  number, provided that it occurs inside that subpattern. (If
4365         not,  it  is  a  "subroutine" call, which is described in the next sec-         not, it is a "subroutine" call, which is described  in  the  next  sec-
4366         tion.) The special item (?R) or (?0) is a recursive call of the  entire         tion.)  The special item (?R) or (?0) is a recursive call of the entire
4367         regular expression.         regular expression.
4368    
4369         In  PCRE (like Python, but unlike Perl), a recursive subpattern call is         In PCRE (like Python, but unlike Perl), a recursive subpattern call  is
4370         always treated as an atomic group. That is, once it has matched some of         always treated as an atomic group. That is, once it has matched some of
4371         the subject string, it is never re-entered, even if it contains untried         the subject string, it is never re-entered, even if it contains untried
4372         alternatives and there is a subsequent matching failure.         alternatives and there is a subsequent matching failure.
4373    
4374         This PCRE pattern solves the nested  parentheses  problem  (assume  the         This  PCRE  pattern  solves  the nested parentheses problem (assume the
4375         PCRE_EXTENDED option is set so that white space is ignored):         PCRE_EXTENDED option is set so that white space is ignored):
4376    
4377           \( ( (?>[^()]+) | (?R) )* \)           \( ( (?>[^()]+) | (?R) )* \)
4378    
4379         First  it matches an opening parenthesis. Then it matches any number of         First it matches an opening parenthesis. Then it matches any number  of
4380         substrings which can either be a  sequence  of  non-parentheses,  or  a         substrings  which  can  either  be  a sequence of non-parentheses, or a
4381         recursive  match  of the pattern itself (that is, a correctly parenthe-         recursive match of the pattern itself (that is, a  correctly  parenthe-
4382         sized substring).  Finally there is a closing parenthesis.         sized substring).  Finally there is a closing parenthesis.
4383    
4384         If this were part of a larger pattern, you would not  want  to  recurse         If  this  were  part of a larger pattern, you would not want to recurse
4385         the entire pattern, so instead you could use this:         the entire pattern, so instead you could use this:
4386    
4387           ( \( ( (?>[^()]+) | (?1) )* \) )           ( \( ( (?>[^()]+) | (?1) )* \) )
4388    
4389         We  have  put the pattern into parentheses, and caused the recursion to         We have put the pattern into parentheses, and caused the  recursion  to
4390         refer to them instead of the whole pattern. In a larger pattern,  keep-         refer to them instead of the whole pattern.
4391         ing  track  of parenthesis numbers can be tricky. It may be more conve-  
4392         nient to use named parentheses instead. The Perl  syntax  for  this  is         In  a  larger  pattern,  keeping  track  of  parenthesis numbers can be
4393         (?&name);  PCRE's  earlier syntax (?P>name) is also supported. We could         tricky. This is made easier by the use of relative references. (A  Perl
4394         rewrite the above example as follows:         5.10  feature.)   Instead  of  (?1)  in the pattern above you can write
4395           (?-2) to refer to the second most recently opened parentheses preceding
4396           the  recursion.  In  other  words,  a  negative number counts capturing
4397           parentheses leftwards from the point at which it is encountered.
4398    
4399           It is also possible to refer to  subsequently  opened  parentheses,  by
4400           writing  references  such  as (?+2). However, these cannot be recursive
4401           because the reference is not inside the  parentheses  that  are  refer-
4402           enced.  They  are  always  "subroutine" calls, as described in the next
4403           section.
4404    
4405           An alternative approach is to use named parentheses instead.  The  Perl
4406           syntax  for  this  is (?&name); PCRE's earlier syntax (?P>name) is also
4407           supported. We could rewrite the above example as follows:
4408    
4409           (?<pn> \( ( (?>[^()]+) | (?&pn) )* \) )           (?<pn> \( ( (?>[^()]+) | (?&pn) )* \) )
4410    
4411         If there is more than one subpattern with the same name,  the  earliest         If there is more than one subpattern with the same name,  the  earliest
4412         one  is used. This particular example pattern contains nested unlimited         one is used.
4413         repeats, and so the use of atomic grouping for matching strings of non-  
4414         parentheses  is  important when applying the pattern to strings that do         This  particular  example pattern that we have been looking at contains
4415         not match. For example, when this pattern is applied to         nested unlimited repeats, and so the use of atomic grouping for  match-
4416           ing  strings  of non-parentheses is important when applying the pattern
4417           to strings that do not match. For example, when this pattern is applied
4418           to
4419    
4420           (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()           (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
4421    
4422         it yields "no match" quickly. However, if atomic grouping is not  used,         it  yields "no match" quickly. However, if atomic grouping is not used,
4423         the  match  runs  for a very long time indeed because there are so many         the match runs for a very long time indeed because there  are  so  many
4424         different ways the + and * repeats can carve up the  subject,  and  all         different  ways  the  + and * repeats can carve up the subject, and all
4425         have to be tested before failure can be reported.         have to be tested before failure can be reported.
4426    
4427         At the end of a match, the values set for any capturing subpatterns are         At the end of a match, the values set for any capturing subpatterns are
4428         those from the outermost level of the recursion at which the subpattern         those from the outermost level of the recursion at which the subpattern
4429         value  is  set.   If  you want to obtain intermediate values, a callout         value is set.  If you want to obtain  intermediate  values,  a  callout
4430         function can be used (see below and the pcrecallout documentation).  If         function  can be used (see below and the pcrecallout documentation). If
4431         the pattern above is matched against         the pattern above is matched against
4432    
4433           (ab(cd)ef)           (ab(cd)ef)
4434    
4435         the  value  for  the  capturing  parentheses is "ef", which is the last         the value for the capturing parentheses is  "ef",  which  is  the  last
4436         value taken on at the top level. If additional parentheses  are  added,         value  taken  on at the top level. If additional parentheses are added,
4437         giving         giving
4438    
4439           \( ( ( (?>[^()]+) | (?R) )* ) \)           \( ( ( (?>[^()]+) | (?R) )* ) \)
4440              ^                        ^              ^                        ^
4441              ^                        ^              ^                        ^
4442    
4443         the  string  they  capture is "ab(cd)ef", the contents of the top level         the string they capture is "ab(cd)ef", the contents of  the  top  level
4444         parentheses. If there are more than 15 capturing parentheses in a  pat-         parentheses.  If there are more than 15 capturing parentheses in a pat-
4445         tern, PCRE has to obtain extra memory to store data during a recursion,         tern, PCRE has to obtain extra memory to store data during a recursion,
4446         which it does by using pcre_malloc, freeing  it  via  pcre_free  after-         which  it  does  by  using pcre_malloc, freeing it via pcre_free after-
4447         wards.  If  no  memory  can  be  obtained,  the  match  fails  with the         wards. If  no  memory  can  be  obtained,  the  match  fails  with  the
4448         PCRE_ERROR_NOMEMORY error.         PCRE_ERROR_NOMEMORY error.
4449    
4450         Do not confuse the (?R) item with the condition (R),  which  tests  for         Do  not  confuse  the (?R) item with the condition (R), which tests for
4451         recursion.   Consider  this pattern, which matches text in angle brack-         recursion.  Consider this pattern, which matches text in  angle  brack-
4452         ets, allowing for arbitrary nesting. Only digits are allowed in  nested         ets,  allowing for arbitrary nesting. Only digits are allowed in nested
4453         brackets  (that is, when recursing), whereas any characters are permit-         brackets (that is, when recursing), whereas any characters are  permit-
4454         ted at the outer level.         ted at the outer level.
4455    
4456           < (?: (?(R) \d++  | [^<>]*+) | (?R)) * >           < (?: (?(R) \d++  | [^<>]*+) | (?R)) * >
4457    
4458         In this pattern, (?(R) is the start of a conditional  subpattern,  with         In  this  pattern, (?(R) is the start of a conditional subpattern, with
4459         two  different  alternatives for the recursive and non-recursive cases.         two different alternatives for the recursive and  non-recursive  cases.
4460         The (?R) item is the actual recursive call.         The (?R) item is the actual recursive call.
4461    
4462    
4463  SUBPATTERNS AS SUBROUTINES  SUBPATTERNS AS SUBROUTINES
4464    
4465         If the syntax for a recursive subpattern reference (either by number or         If the syntax for a recursive subpattern reference (either by number or
4466         by  name)  is used outside the parentheses to which it refers, it oper-         by name) is used outside the parentheses to which it refers,  it  oper-
4467         ates like a subroutine in a programming language. The "called"  subpat-         ates  like a subroutine in a programming language. The "called" subpat-
4468         tern  may  be defined before or after the reference. An earlier example         tern may be defined before or after the reference. A numbered reference
4469         pointed out that the pattern         can be absolute or relative, as in these examples:
4470    
4471             (...(absolute)...)...(?2)...
4472             (...(relative)...)...(?-1)...
4473             (...(?+1)...(relative)...
4474    
4475           An earlier example pointed out that the pattern
4476    
4477           (sens|respons)e and \1ibility           (sens|respons)e and \1ibility
4478    
4479         matches "sense and sensibility" and "response and responsibility",  but         matches  "sense and sensibility" and "response and responsibility", but
4480         not "sense and responsibility". If instead the pattern         not "sense and responsibility". If instead the pattern
4481    
4482           (sens|respons)e and (?1)ibility           (sens|respons)e and (?1)ibility
4483    
4484         is  used, it does match "sense and responsibility" as well as the other         is used, it does match "sense and responsibility" as well as the  other
4485         two strings. Another example is  given  in  the  discussion  of  DEFINE         two  strings.  Another  example  is  given  in the discussion of DEFINE
4486         above.         above.
4487    
4488         Like recursive subpatterns, a "subroutine" call is always treated as an         Like recursive subpatterns, a "subroutine" call is always treated as an
4489         atomic group. That is, once it has matched some of the subject  string,         atomic  group. That is, once it has matched some of the subject string,
4490         it  is  never  re-entered, even if it contains untried alternatives and         it is never re-entered, even if it contains  untried  alternatives  and
4491         there is a subsequent matching failure.         there is a subsequent matching failure.
4492    
4493         When a subpattern is used as a subroutine, processing options  such  as         When  a  subpattern is used as a subroutine, processing options such as
4494         case-independence are fixed when the subpattern is defined. They cannot         case-independence are fixed when the subpattern is defined. They cannot
4495         be changed for different calls. For example, consider this pattern:         be changed for different calls. For example, consider this pattern:
4496    
4497           (abc)(?i:(?1))           (abc)(?i:(?-1))
4498    
4499         It matches "abcabc". It does not match "abcABC" because the  change  of         It  matches  "abcabc". It does not match "abcABC" because the change of
4500         processing option does not affect the called subpattern.         processing option does not affect the called subpattern.
4501    
4502    
4503  CALLOUTS  CALLOUTS
4504    
4505         Perl has a feature whereby using the sequence (?{...}) causes arbitrary         Perl has a feature whereby using the sequence (?{...}) causes arbitrary
4506         Perl code to be obeyed in the middle of matching a regular  expression.         Perl  code to be obeyed in the middle of matching a regular expression.
4507         This makes it possible, amongst other things, to extract different sub-         This makes it possible, amongst other things, to extract different sub-
4508         strings that match the same pair of parentheses when there is a repeti-         strings that match the same pair of parentheses when there is a repeti-
4509         tion.         tion.
4510    
4511         PCRE provides a similar feature, but of course it cannot obey arbitrary         PCRE provides a similar feature, but of course it cannot obey arbitrary
4512         Perl code. The feature is called "callout". The caller of PCRE provides         Perl code. The feature is called "callout". The caller of PCRE provides
4513         an  external function by putting its entry point in the global variable         an external function by putting its entry point in the global  variable
4514         pcre_callout.  By default, this variable contains NULL, which  disables         pcre_callout.   By default, this variable contains NULL, which disables
4515         all calling out.         all calling out.
4516    
4517         Within  a  regular  expression,  (?C) indicates the points at which the         Within a regular expression, (?C) indicates the  points  at  which  the
4518         external function is to be called. If you want  to  identify  different         external  function  is  to be called. If you want to identify different
4519         callout  points, you can put a number less than 256 after the letter C.         callout points, you can put a number less than 256 after the letter  C.
4520         The default value is zero.  For example, this pattern has  two  callout         The  default  value is zero.  For example, this pattern has two callout
4521         points:         points:
4522    
4523           (?C1)abc(?C2)def           (?C1)abc(?C2)def
4524    
4525         If the PCRE_AUTO_CALLOUT flag is passed to pcre_compile(), callouts are         If the PCRE_AUTO_CALLOUT flag is passed to pcre_compile(), callouts are
4526         automatically installed before each item in the pattern. They  are  all         automatically  installed  before each item in the pattern. They are all
4527         numbered 255.         numbered 255.
4528    
4529         During matching, when PCRE reaches a callout point (and pcre_callout is         During matching, when PCRE reaches a callout point (and pcre_callout is
4530         set), the external function is called. It is provided with  the  number         set),  the  external function is called. It is provided with the number
4531         of  the callout, the position in the pattern, and, optionally, one item         of the callout, the position in the pattern, and, optionally, one  item
4532         of data originally supplied by the caller of pcre_exec().  The  callout         of  data  originally supplied by the caller of pcre_exec(). The callout
4533         function  may cause matching to proceed, to backtrack, or to fail alto-         function may cause matching to proceed, to backtrack, or to fail  alto-
4534         gether. A complete description of the interface to the callout function         gether. A complete description of the interface to the callout function
4535         is given in the pcrecallout documentation.         is given in the pcrecallout documentation.
4536    
# Line 4334  AUTHOR Line 4549  AUTHOR
4549    
4550  REVISION  REVISION
4551    
4552         Last updated: 06 March 2007         Last updated: 06 August 2007
4553         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
4554  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
4555    
4556    
4557    PCRESYNTAX(3)                                                    PCRESYNTAX(3)
4558    
4559    
4560    NAME
4561           PCRE - Perl-compatible regular expressions
4562    
4563    
4564    PCRE REGULAR EXPRESSION SYNTAX SUMMARY
4565    
4566           The  full syntax and semantics of the regular expressions that are sup-
4567           ported by PCRE are described in  the  pcrepattern  documentation.  This
4568           document contains just a quick-reference summary of the syntax.
4569    
4570    
4571    QUOTING
4572    
4573             \x         where x is non-alphanumeric is a literal x
4574             \Q...\E    treat enclosed characters as literal
4575    
4576    
4577    CHARACTERS
4578    
4579             \a         alarm, that is, the BEL character (hex 07)
4580             \cx        "control-x", where x is any character
4581             \e         escape (hex 1B)
4582             \f         formfeed (hex 0C)
4583             \n         newline (hex 0A)
4584             \r         carriage return (hex 0D)
4585             \t         tab (hex 09)
4586             \ddd       character with octal code ddd, or backreference
4587             \xhh       character with hex code hh
4588             \x{hhh..}  character with hex code hhh..
4589    
4590    
4591    CHARACTER TYPES
4592    
4593             .          any character except newline;
4594                          in dotall mode, any character whatsoever
4595             \C         one byte, even in UTF-8 mode (best avoided)
4596             \d         a decimal digit
4597             \D         a character that is not a decimal digit
4598             \h         a horizontal whitespace character
4599             \H         a character that is not a horizontal whitespace character
4600             \p{xx}     a character with the xx property
4601             \P{xx}     a character without the xx property
4602             \R         a newline sequence
4603             \s         a whitespace character
4604             \S         a character that is not a whitespace character
4605             \v         a vertical whitespace character
4606             \V         a character that is not a vertical whitespace character
4607             \w         a "word" character
4608             \W         a "non-word" character
4609             \X         an extended Unicode sequence
4610    
4611           In PCRE, \d, \D, \s, \S, \w, and \W recognize only ASCII characters.
4612    
4613    
4614    GENERAL CATEGORY PROPERTY CODES FOR \p and \P
4615    
4616             C          Other
4617             Cc         Control
4618             Cf         Format
4619             Cn         Unassigned
4620             Co         Private use
4621             Cs         Surrogate
4622    
4623             L          Letter
4624             Ll         Lower case letter
4625             Lm         Modifier letter
4626             Lo         Other letter
4627             Lt         Title case letter
4628             Lu         Upper case letter
4629             L&         Ll, Lu, or Lt
4630    
4631             M          Mark
4632             Mc         Spacing mark
4633             Me         Enclosing mark
4634             Mn         Non-spacing mark
4635    
4636             N          Number
4637             Nd         Decimal number
4638             Nl         Letter number
4639             No         Other number
4640    
4641             P          Punctuation
4642             Pc         Connector punctuation
4643             Pd         Dash punctuation
4644             Pe         Close punctuation
4645             Pf         Final punctuation
4646             Pi         Initial punctuation
4647             Po         Other punctuation
4648             Ps         Open punctuation
4649    
4650             S          Symbol
4651             Sc         Currency symbol
4652             Sk         Modifier symbol
4653             Sm         Mathematical symbol
4654             So         Other symbol
4655    
4656             Z          Separator
4657             Zl         Line separator
4658             Zp         Paragraph separator
4659             Zs         Space separator
4660    
4661    
4662    SCRIPT NAMES FOR \p AND \P
4663    
4664           Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,
4665           Buhid,  Canadian_Aboriginal,  Cherokee,  Common,   Coptic,   Cuneiform,
4666           Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,
4667           Gothic, Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew,  Hira-
4668           gana,  Inherited,  Kannada,  Katakana,  Kharoshthi,  Khmer, Lao, Latin,
4669           Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,
4670           Ogham,  Old_Italic,  Old_Persian, Oriya, Osmanya, Phags_Pa, Phoenician,
4671           Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,
4672           Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.
4673    
4674    
4675    CHARACTER CLASSES
4676    
4677             [...]       positive character class
4678             [^...]      negative character class
4679             [x-y]       range (can be used for hex characters)
4680             [[:xxx:]]   positive POSIX named set
4681             [[^:xxx:]]  negative POSIX named set
4682    
4683             alnum       alphanumeric
4684             alpha       alphabetic
4685             ascii       0-127
4686             blank       space or tab
4687             cntrl       control character
4688             digit       decimal digit
4689             graph       printing, excluding space
4690             lower       lower case letter
4691             print       printing, including space
4692             punct       printing, excluding alphanumeric
4693             space       whitespace
4694             upper       upper case letter
4695             word        same as \w
4696             xdigit      hexadecimal digit
4697    
4698           In PCRE, POSIX character set names recognize only ASCII characters. You
4699           can use \Q...\E inside a character class.
4700    
4701    
4702    QUANTIFIERS
4703    
4704             ?           0 or 1, greedy
4705             ?+          0 or 1, possessive
4706             ??          0 or 1, lazy
4707             *           0 or more, greedy
4708             *+          0 or more, possessive
4709             *?          0 or more, lazy
4710             +           1 or more, greedy
4711             ++          1 or more, possessive
4712             +?          1 or more, lazy
4713             {n}         exactly n
4714             {n,m}       at least n, no more than m, greedy
4715             {n,m}+      at least n, no more than m, possessive
4716             {n,m}?      at least n, no more than m, lazy
4717             {n,}        n or more, greedy
4718             {n,}+       n or more, possessive
4719             {n,}?       n or more, lazy
4720    
4721    
4722    ANCHORS AND SIMPLE ASSERTIONS
4723    
4724             \b          word boundary
4725             \B          not a word boundary
4726             ^           start of subject
4727                          also after internal newline in multiline mode
4728             \A          start of subject
4729             $           end of subject
4730                          also before newline at end of subject
4731                          also before internal newline in multiline mode
4732             \Z          end of subject
4733                          also before newline at end of subject
4734             \z          end of subject
4735             \G          first matching position in subject
4736    
4737    
4738    MATCH POINT RESET
4739    
4740             \K          reset start of match
4741    
4742    
4743    ALTERNATION
4744    
4745             expr|expr|expr...
4746    
4747    
4748    CAPTURING
4749    
4750             (...)          capturing group
4751             (?<name>...)   named capturing group (Perl)
4752             (?'name'...)   named capturing group (Perl)
4753             (?P<name>...)  named capturing group (Python)
4754             (?:...)        non-capturing group
4755             (?|...)        non-capturing group; reset group numbers for
4756                             capturing groups in each alternative
4757    
4758    
4759    ATOMIC GROUPS
4760    
4761             (?>...)        atomic, non-capturing group
4762    
4763    
4764    COMMENT
4765    
4766             (?#....)       comment (not nestable)
4767    
4768    
4769    OPTION SETTING
4770    
4771             (?i)           caseless
4772             (?J)           allow duplicate names
4773             (?m)           multiline
4774             (?s)           single line (dotall)
4775             (?U)           default ungreedy (lazy)
4776             (?x)           extended (ignore white space)
4777             (?-...)        unset option(s)
4778    
4779    
4780    LOOKAHEAD AND LOOKBEHIND ASSERTIONS
4781    
4782             (?=...)        positive look ahead
4783             (?!...)        negative look ahead
4784             (?<=...)       positive look behind
4785             (?<!...)       negative look behind
4786    
4787           Each top-level branch of a look behind must be of a fixed length.
4788    
4789    
4790    BACKREFERENCES
4791    
4792             \n             reference by number (can be ambiguous)
4793             \gn            reference by number
4794             \g{n}          reference by number
4795             \g{-n}         relative reference by number
4796             \k<name>       reference by name (Perl)
4797             \k'name'       reference by name (Perl)
4798             \g{name}       reference by name (Perl)
4799             \k{name}       reference by name (.NET)
4800             (?P=name)      reference by name (Python)
4801    
4802    
4803    SUBROUTINE REFERENCES (POSSIBLY RECURSIVE)
4804    
4805             (?R)           recurse whole pattern
4806             (?n)           call subpattern by absolute number
4807             (?+n)          call subpattern by relative number
4808             (?-n)          call subpattern by relative number
4809             (?&name)       call subpattern by name (Perl)
4810             (?P>name)      call subpattern by name (Python)
4811    
4812    
4813    CONDITIONAL PATTERNS
4814    
4815             (?(condition)yes-pattern)
4816             (?(condition)yes-pattern|no-pattern)
4817    
4818             (?(n)...       absolute reference condition
4819             (?(+n)...      relative reference condition
4820             (?(-n)...      relative reference condition
4821             (?(<name>)...  named reference condition (Perl)
4822             (?('name')...  named reference condition (Perl)
4823             (?(name)...    named reference condition (PCRE)
4824             (?(R)...       overall recursion condition
4825             (?(Rn)...      specific group recursion condition
4826             (?(R&name)...  specific recursion condition
4827             (?(DEFINE)...  define subpattern for reference
4828             (?(assert)...  assertion condition
4829    
4830    
4831    CALLOUTS
4832    
4833             (?C)      callout
4834             (?Cn)     callout with data n
4835    
4836    
4837    SEE ALSO
4838    
4839           pcrepattern(3), pcreapi(3), pcrecallout(3), pcrematching(3), pcre(3).
4840    
4841    
4842    AUTHOR
4843    
4844           Philip Hazel
4845           University Computing Service
4846           Cambridge CB2 3QH, England.
4847    
4848    
4849    REVISION
4850    
4851           Last updated: 06 August 2007
4852           Copyright (c) 1997-2007 University of Cambridge.
4853    ------------------------------------------------------------------------------
4854    
4855    
4856  PCREPARTIAL(3)                                                  PCREPARTIAL(3)  PCREPARTIAL(3)                                                  PCREPARTIAL(3)
4857    
4858    
# Line 4415  RESTRICTED PATTERNS FOR PCRE_PARTIAL Line 4929  RESTRICTED PATTERNS FOR PCRE_PARTIAL
4929    
4930         If PCRE_PARTIAL is set for a pattern  that  does  not  conform  to  the         If PCRE_PARTIAL is set for a pattern  that  does  not  conform  to  the
4931         restrictions,  pcre_exec() returns the error code PCRE_ERROR_BADPARTIAL         restrictions,  pcre_exec() returns the error code PCRE_ERROR_BADPARTIAL
4932         (-13).         (-13).  You can use the PCRE_INFO_OKPARTIAL call to pcre_fullinfo()  to
4933           find out if a compiled pattern can be used for partial matching.
4934    
4935    
4936  EXAMPLE OF PARTIAL MATCHING USING PCRETEST  EXAMPLE OF PARTIAL MATCHING USING PCRETEST
4937    
4938         If the escape sequence \P is present  in  a  pcretest  data  line,  the         If  the  escape  sequence  \P  is  present in a pcretest data line, the
4939         PCRE_PARTIAL flag is used for the match. Here is a run of pcretest that         PCRE_PARTIAL flag is used for the match. Here is a run of pcretest that
4940         uses the date example quoted above:         uses the date example quoted above:
4941    
# Line 4437  EXAMPLE OF PARTIAL MATCHING USING PCRETE Line 4952  EXAMPLE OF PARTIAL MATCHING USING PCRETE
4952           data> j\P           data> j\P
4953           No match           No match
4954    
4955         The first data string is matched  completely,  so  pcretest  shows  the         The  first  data  string  is  matched completely, so pcretest shows the
4956         matched  substrings.  The  remaining four strings do not match the com-         matched substrings. The remaining four strings do not  match  the  com-
4957         plete pattern, but the first two are partial matches.  The  same  test,         plete  pattern,  but  the first two are partial matches. The same test,
4958         using  pcre_dfa_exec()  matching  (by means of the \D escape sequence),         using pcre_dfa_exec() matching (by means of the  \D  escape  sequence),
4959         produces the following output:         produces the following output:
4960    
4961             re> /^?(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)$/             re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
4962           data> 25jun04\P\D           data> 25jun04\P\D
4963            0: 25jun04            0: 25jun04
4964           data> 23dec3\P\D           data> 23dec3\P\D
# Line 4455  EXAMPLE OF PARTIAL MATCHING USING PCRETE Line 4970  EXAMPLE OF PARTIAL MATCHING USING PCRETE
4970           data> j\P\D           data> j\P\D
4971           No match           No match
4972    
4973         Notice that in this case the portion of the string that was matched  is         Notice  that in this case the portion of the string that was matched is
4974         made available.         made available.
4975    
4976    
4977  MULTI-SEGMENT MATCHING WITH pcre_dfa_exec()  MULTI-SEGMENT MATCHING WITH pcre_dfa_exec()
4978    
4979         When a partial match has been found using pcre_dfa_exec(), it is possi-         When a partial match has been found using pcre_dfa_exec(), it is possi-
4980         ble to continue the match by  providing  additional  subject  data  and         ble  to  continue  the  match  by providing additional subject data and
4981         calling  pcre_dfa_exec()  again  with the same compiled regular expres-         calling pcre_dfa_exec() again with the same  compiled  regular  expres-
4982         sion, this time setting the PCRE_DFA_RESTART option. You must also pass         sion, this time setting the PCRE_DFA_RESTART option. You must also pass
4983         the  same working space as before, because this is where details of the         the same working space as before, because this is where details of  the
4984         previous partial match are stored. Here is an example  using  pcretest,         previous  partial  match are stored. Here is an example using pcretest,
4985         using the \R escape sequence to set the PCRE_DFA_RESTART option (\P and         using the \R escape sequence to set the PCRE_DFA_RESTART option (\P and
4986         \D are as above):         \D are as above):
4987    
4988             re> /^?(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)$/             re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
4989           data> 23ja\P\D           data> 23ja\P\D
4990           Partial match: 23ja           Partial match: 23ja
4991           data> n05\R\D           data> n05\R\D
4992            0: n05            0: n05
4993    
4994         The first call has "23ja" as the subject, and requests  partial  match-         The  first  call has "23ja" as the subject, and requests partial match-
4995         ing;  the  second  call  has  "n05"  as  the  subject for the continued         ing; the second call  has  "n05"  as  the  subject  for  the  continued
4996         (restarted) match.  Notice that when the match is  complete,  only  the         (restarted)  match.   Notice  that when the match is complete, only the
4997         last  part  is  shown;  PCRE  does not retain the previously partially-         last part is shown; PCRE does  not  retain  the  previously  partially-
4998         matched string. It is up to the calling program to do that if it  needs         matched  string. It is up to the calling program to do that if it needs
4999         to.         to.
5000    
5001         You  can  set  PCRE_PARTIAL  with  PCRE_DFA_RESTART to continue partial         You can set PCRE_PARTIAL  with  PCRE_DFA_RESTART  to  continue  partial
5002         matching over multiple segments. This facility can be used to pass very         matching over multiple segments. This facility can be used to pass very
5003         long  subject  strings to pcre_dfa_exec(). However, some care is needed         long subject strings to pcre_dfa_exec(). However, some care  is  needed
5004         for certain types of pattern.         for certain types of pattern.
5005    
5006         1. If the pattern contains tests for the beginning or end  of  a  line,         1.  If  the  pattern contains tests for the beginning or end of a line,
5007         you  need  to pass the PCRE_NOTBOL or PCRE_NOTEOL options, as appropri-         you need to pass the PCRE_NOTBOL or PCRE_NOTEOL options,  as  appropri-
5008         ate, when the subject string for any call does not contain  the  begin-         ate,  when  the subject string for any call does not contain the begin-
5009         ning or end of a line.         ning or end of a line.
5010    
5011         2.  If  the  pattern contains backward assertions (including \b or \B),         2. If the pattern contains backward assertions (including  \b  or  \B),
5012         you need to arrange for some overlap in the subject  strings  to  allow         you  need  to  arrange for some overlap in the subject strings to allow
5013         for  this.  For  example, you could pass the subject in chunks that are         for this. For example, you could pass the subject in  chunks  that  are
5014         500 bytes long, but in a buffer of 700 bytes, with the starting  offset         500  bytes long, but in a buffer of 700 bytes, with the starting offset
5015         set to 200 and the previous 200 bytes at the start of the buffer.         set to 200 and the previous 200 bytes at the start of the buffer.
5016    
5017         3.  Matching a subject string that is split into multiple segments does         3. Matching a subject string that is split into multiple segments  does
5018         not always produce exactly the same result as matching over one  single         not  always produce exactly the same result as matching over one single
5019         long  string.   The  difference arises when there are multiple matching         long string.  The difference arises when there  are  multiple  matching
5020         possibilities, because a partial match result is given only when  there         possibilities,  because a partial match result is given only when there
5021         are  no  completed  matches  in a call to fBpcre_dfa_exec(). This means         are no completed matches in a call to pcre_dfa_exec(). This means  that
5022         that as soon as the shortest match has been found,  continuation  to  a         as  soon  as  the  shortest match has been found, continuation to a new
5023         new  subject  segment  is  no  longer possible.  Consider this pcretest         subject segment is no longer possible.  Consider this pcretest example:
        example:  
5024    
5025             re> /dog(sbody)?/             re> /dog(sbody)?/
5026           data> do\P\D           data> do\P\D
# Line 4517  MULTI-SEGMENT MATCHING WITH pcre_dfa_exe Line 5031  MULTI-SEGMENT MATCHING WITH pcre_dfa_exe
5031            0: dogsbody            0: dogsbody
5032            1: dog            1: dog
5033    
5034         The pattern matches the words "dog" or "dogsbody". When the subject  is         The  pattern matches the words "dog" or "dogsbody". When the subject is
5035         presented  in  several  parts  ("do" and "gsb" being the first two) the         presented in several parts ("do" and "gsb" being  the  first  two)  the
5036         match stops when "dog" has been found, and it is not possible  to  con-         match  stops  when "dog" has been found, and it is not possible to con-
5037         tinue.  On  the  other  hand,  if  "dogsbody"  is presented as a single         tinue. On the other hand,  if  "dogsbody"  is  presented  as  a  single
5038         string, both matches are found.         string, both matches are found.
5039    
5040         Because of this phenomenon, it does not usually make  sense  to  end  a         Because  of  this  phenomenon,  it does not usually make sense to end a
5041         pattern that is going to be matched in this way with a variable repeat.         pattern that is going to be matched in this way with a variable repeat.
5042    
5043         4. Patterns that contain alternatives at the top level which do not all         4. Patterns that contain alternatives at the top level which do not all
# Line 4532  MULTI-SEGMENT MATCHING WITH pcre_dfa_exe Line 5046  MULTI-SEGMENT MATCHING WITH pcre_dfa_exe
5046    
5047           1234|3789           1234|3789
5048    
5049         If the first part of the subject is "ABC123", a partial  match  of  the         If  the  first  part of the subject is "ABC123", a partial match of the
5050         first  alternative  is found at offset 3. There is no partial match for         first alternative is found at offset 3. There is no partial  match  for
5051         the second alternative, because such a match does not start at the same         the second alternative, because such a match does not start at the same
5052         point  in  the  subject  string. Attempting to continue with the string         point in the subject string. Attempting to  continue  with  the  string
5053         "789" does not yield a match because only those alternatives that match         "789" does not yield a match because only those alternatives that match
5054         at  one point in the subject are remembered. The problem arises because         at one point in the subject are remembered. The problem arises  because
5055         the start of the second alternative matches within the  first  alterna-         the  start  of the second alternative matches within the first alterna-
5056         tive. There is no problem with anchored patterns or patterns such as:         tive. There is no problem with anchored patterns or patterns such as:
5057    
5058           1234|ABCD           1234|ABCD
# Line 4555  AUTHOR Line 5069  AUTHOR
5069    
5070  REVISION  REVISION
5071    
5072         Last updated: 06 March 2007         Last updated: 04 June 2007
5073         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
5074  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
5075    
5076    
5077  PCREPRECOMPILE(3)                                            PCREPRECOMPILE(3)  PCREPRECOMPILE(3)                                            PCREPRECOMPILE(3)
5078    
5079    
# Line 4580  SAVING AND RE-USING PRECOMPILED PCRE PAT Line 5094  SAVING AND RE-USING PRECOMPILED PCRE PAT
5094         ent  host  and  run them there. This works even if the new host has the         ent  host  and  run them there. This works even if the new host has the
5095         opposite endianness to the one on which  the  patterns  were  compiled.         opposite endianness to the one on which  the  patterns  were  compiled.
5096         There  may  be a small performance penalty, but it should be insignifi-         There  may  be a small performance penalty, but it should be insignifi-
5097         cant.         cant. However, compiling regular expressions with one version  of  PCRE
5098           for  use  with  a  different  version is not guaranteed to work and may
5099           cause crashes.
5100    
5101    
5102  SAVING A COMPILED PATTERN  SAVING A COMPILED PATTERN
# Line 4663  RE-USING A PRECOMPILED PATTERN Line 5179  RE-USING A PRECOMPILED PATTERN
5179    
5180  COMPATIBILITY WITH DIFFERENT PCRE RELEASES  COMPATIBILITY WITH DIFFERENT PCRE RELEASES
5181    
5182         The layout of the control block that is at the start of the  data  that         In general, it is safest to  recompile  all  saved  patterns  when  you
5183         makes  up  a  compiled pattern was changed for release 5.0. If you have         update  to  a new PCRE release, though not all updates actually require
5184         any saved patterns that were compiled with  previous  releases  (not  a         this. Recompiling is definitely needed for release 7.2.
        facility  that  was  previously advertised), you will have to recompile  
        them for release 5.0 and above.  
   
        If you have any saved patterns in UTF-8 mode that use  \p  or  \P  that  
        were  compiled  with any release up to and including 6.4, you will have  
        to recompile them for release 6.5 and above.  
   
        All saved patterns from earlier releases must be recompiled for release  
        7.0  or  higher,  because  there was an internal reorganization at that  
        release.  
5185    
5186    
5187  AUTHOR  AUTHOR
# Line 4687  AUTHOR Line 5193  AUTHOR
5193    
5194  REVISION  REVISION
5195    
5196         Last updated: 06 March 2007         Last updated: 13 June 2007
5197         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
5198  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
5199    
5200    
5201  PCREPERFORM(3)                                                  PCREPERFORM(3)  PCREPERFORM(3)                                                  PCREPERFORM(3)
5202    
5203    
# Line 4840  REVISION Line 5346  REVISION
5346         Last updated: 06 March 2007         Last updated: 06 March 2007
5347         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
5348  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
5349    
5350    
5351  PCREPOSIX(3)                                                      PCREPOSIX(3)  PCREPOSIX(3)                                                      PCREPOSIX(3)
5352    
5353    
# Line 5060  REVISION Line 5566  REVISION
5566         Last updated: 06 March 2007         Last updated: 06 March 2007
5567         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
5568  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
5569    
5570    
5571  PCRECPP(3)                                                          PCRECPP(3)  PCRECPP(3)                                                          PCRECPP(3)
5572    
5573    
# Line 5155  MATCHING INTERFACE Line 5661  MATCHING INTERFACE
5661         return false (because the empty string is not a valid number):         return false (because the empty string is not a valid number):
5662    
5663            int number;            int number;
5664            pcrecpp::RE::FullMatch("abc", "[a-z]+(\d+)?", &number);            pcrecpp::RE::FullMatch("abc", "[a-z]+(\\d+)?", &number);
5665    
5666         The matching interface supports at most 16 arguments per call.  If  you         The matching interface supports at most 16 arguments per call.  If  you
5667         need    more,    consider    using    the    more   general   interface         need    more,    consider    using    the    more   general   interface
# Line 5389  REPLACING PARTS OF STRINGS Line 5895  REPLACING PARTS OF STRINGS
5895  AUTHOR  AUTHOR
5896    
5897         The C++ wrapper was contributed by Google Inc.         The C++ wrapper was contributed by Google Inc.
5898         Copyright (c) 2006 Google Inc.         Copyright (c) 2007 Google Inc.
5899    
5900    
5901  REVISION  REVISION
5902    
5903         Last updated: 06 March 2007         Last updated: 06 March 2007
5904  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
5905    
5906    
5907  PCRESAMPLE(3)                                                    PCRESAMPLE(3)  PCRESAMPLE(3)                                                    PCRESAMPLE(3)
5908    
5909    
# Line 5422  PCRE SAMPLE PROGRAM Line 5928  PCRE SAMPLE PROGRAM
5928         bility  of  matching an empty string. Comments in the code explain what         bility  of  matching an empty string. Comments in the code explain what
5929         is going on.         is going on.
5930    
5931         If PCRE is installed in the standard include  and  library  directories         The demonstration program is automatically built if you use  "./config-
5932         for  your  system, you should be able to compile the demonstration pro-         ure;make"  to  build PCRE. Otherwise, if PCRE is installed in the stan-
5933         gram using this command:         dard include and library directories for your  system,  you  should  be
5934           able to compile the demonstration program using this command:
5935    
5936           gcc -o pcredemo pcredemo.c -lpcre           gcc -o pcredemo pcredemo.c -lpcre
5937    
5938         If PCRE is installed elsewhere, you may need to add additional  options         If  PCRE is installed elsewhere, you may need to add additional options
5939         to  the  command line. For example, on a Unix-like system that has PCRE         to the command line. For example, on a Unix-like system that  has  PCRE
5940         installed in /usr/local, you  can  compile  the  demonstration  program         installed  in  /usr/local,  you  can  compile the demonstration program
5941         using a command like this:         using a command like this:
5942    
5943           gcc -o pcredemo -I/usr/local/include pcredemo.c \           gcc -o pcredemo -I/usr/local/include pcredemo.c \
5944               -L/usr/local/lib -lpcre               -L/usr/local/lib -lpcre
5945    
5946         Once  you  have  compiled the demonstration program, you can run simple         Once you have compiled the demonstration program, you  can  run  simple
5947         tests like this:         tests like this:
5948    
5949           ./pcredemo 'cat|dog' 'the cat sat on the mat'           ./pcredemo 'cat|dog' 'the cat sat on the mat'
5950           ./pcredemo -g 'cat|dog' 'the dog sat on the cat'           ./pcredemo -g 'cat|dog' 'the dog sat on the cat'
5951    
5952         Note that there is a  much  more  comprehensive  test  program,  called         Note  that  there  is  a  much  more comprehensive test program, called
5953         pcretest,  which  supports  many  more  facilities  for testing regular         pcretest, which supports  many  more  facilities  for  testing  regular
5954         expressions and the PCRE library. The pcredemo program is provided as a         expressions and the PCRE library. The pcredemo program is provided as a
5955         simple coding example.         simple coding example.
5956    
# Line 5451  PCRE SAMPLE PROGRAM Line 5958  PCRE SAMPLE PROGRAM
5958         the standard library directory, you may get an error like this when you         the standard library directory, you may get an error like this when you
5959         try to run pcredemo:         try to run pcredemo:
5960    
5961           ld.so.1:  a.out:  fatal:  libpcre.so.0:  open failed: No such file or           ld.so.1: a.out: fatal: libpcre.so.0: open failed:  No  such  file  or
5962         directory         directory
5963    
5964         This is caused by the way shared library support works  on  those  sys-         This  is  caused  by the way shared library support works on those sys-
5965         tems. You need to add         tems. You need to add
5966    
5967           -R/usr/local/lib           -R/usr/local/lib
# Line 5471  AUTHOR Line 5978  AUTHOR
5978    
5979  REVISION  REVISION
5980    
5981         Last updated: 06 March 2007         Last updated: 13 June 2007
5982         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
5983  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
5984  PCRESTACK(3)                                                      PCRESTACK(3)  PCRESTACK(3)                                                      PCRESTACK(3)
# Line 5525  PCRE DISCUSSION OF STACK USAGE Line 6032  PCRE DISCUSSION OF STACK USAGE
6032         ter. For a long string, a lot of stack is required. Consider  now  this         ter. For a long string, a lot of stack is required. Consider  now  this
6033         rewritten pattern, which matches exactly the same strings:         rewritten pattern, which matches exactly the same strings:
6034    
6035           ([^<]++|<(?!inet))           ([^<]++|<(?!inet))+
6036    
6037         This  uses very much less stack, because runs of characters that do not         This  uses very much less stack, because runs of characters that do not
6038         contain "<" are "swallowed" in one item inside the parentheses.  Recur-         contain "<" are "swallowed" in one item inside the parentheses.  Recur-
# Line 5541  PCRE DISCUSSION OF STACK USAGE Line 6048  PCRE DISCUSSION OF STACK USAGE
6048         In environments where stack memory is constrained, you  might  want  to         In environments where stack memory is constrained, you  might  want  to
6049         compile  PCRE to use heap memory instead of stack for remembering back-         compile  PCRE to use heap memory instead of stack for remembering back-
6050         up points. This makes it run a lot more slowly, however. Details of how         up points. This makes it run a lot more slowly, however. Details of how
6051         to do this are given in the pcrebuild documentation.         to do this are given in the pcrebuild documentation. When built in this
6052           way, instead of using the stack, PCRE obtains and frees memory by call-
6053         In  Unix-like environments, there is not often a problem with the stack         ing  the  functions  that  are  pointed to by the pcre_stack_malloc and
6054         unless very long strings are involved,  though  the  default  limit  on         pcre_stack_free variables. By default,  these  point  to  malloc()  and
6055         stack  size  varies  from system to system. Values from 8Mb to 64Mb are         free(),  but you can replace the pointers to cause PCRE to use your own
6056           functions. Since the block sizes are always the same,  and  are  always
6057           freed in reverse order, it may be possible to implement customized mem-
6058           ory handlers that are more efficient than the standard functions.
6059    
6060           In Unix-like environments, there is not often a problem with the  stack
6061           unless  very  long  strings  are  involved, though the default limit on
6062           stack size varies from system to system. Values from 8Mb  to  64Mb  are
6063         common. You can find your default limit by running the command:         common. You can find your default limit by running the command:
6064    
6065           ulimit -s           ulimit -s
6066    
6067         Unfortunately, the effect of running out of  stack  is  often  SIGSEGV,         Unfortunately,  the  effect  of  running out of stack is often SIGSEGV,
6068         though  sometimes  a more explicit error message is given. You can nor-         though sometimes a more explicit error message is given. You  can  nor-
6069         mally increase the limit on stack size by code such as this:         mally increase the limit on stack size by code such as this:
6070    
6071           struct rlimit rlim;           struct rlimit rlim;
# Line 5559  PCRE DISCUSSION OF STACK USAGE Line 6073  PCRE DISCUSSION OF STACK USAGE
6073           rlim.rlim_cur = 100*1024*1024;           rlim.rlim_cur = 100*1024*1024;
6074           setrlimit(RLIMIT_STACK, &rlim);           setrlimit(RLIMIT_STACK, &rlim);
6075    
6076         This reads the current limits (soft and hard) using  getrlimit(),  then         This  reads  the current limits (soft and hard) using getrlimit(), then
6077         attempts  to  increase  the  soft limit to 100Mb using setrlimit(). You         attempts to increase the soft limit to  100Mb  using  setrlimit().  You
6078         must do this before calling pcre_exec().         must do this before calling pcre_exec().
6079    
6080         PCRE has an internal counter that can be used to  limit  the  depth  of         PCRE  has  an  internal  counter that can be used to limit the depth of
6081         recursion,  and  thus cause pcre_exec() to give an error code before it         recursion, and thus cause pcre_exec() to give an error code  before  it
6082         runs out of stack. By default, the limit is very  large,  and  unlikely         runs  out  of  stack. By default, the limit is very large, and unlikely
6083         ever  to operate. It can be changed when PCRE is built, and it can also         ever to operate. It can be changed when PCRE is built, and it can  also
6084         be set when pcre_exec() is called. For details of these interfaces, see         be set when pcre_exec() is called. For details of these interfaces, see
6085         the pcrebuild and pcreapi documentation.         the pcrebuild and pcreapi documentation.
6086    
6087         As a very rough rule of thumb, you should reckon on about 500 bytes per         As a very rough rule of thumb, you should reckon on about 500 bytes per
6088         recursion. Thus, if you want to limit your  stack  usage  to  8Mb,  you         recursion.  Thus,  if  you  want  to limit your stack usage to 8Mb, you
6089         should  set  the  limit at 16000 recursions. A 64Mb stack, on the other         should set the limit at 16000 recursions. A 64Mb stack,  on  the  other
6090         hand, can support around 128000 recursions. The pcretest  test  program         hand,  can  support around 128000 recursions. The pcretest test program
6091         has a command line option (-S) that can be used to increase the size of         has a command line option (-S) that can be used to increase the size of
6092         its stack.         its stack.
6093    
# Line 5587  AUTHOR Line 6101  AUTHOR
6101    
6102  REVISION  REVISION
6103    
6104         Last updated: 06 March 2007         Last updated: 05 June 2007
6105         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
6106  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
6107    
6108    

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

  ViewVC Help
Powered by ViewVC 1.1.5