/[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 243 by ph10, Thu Sep 13 09:28:14 2007 UTC revision 358 by ph10, Wed Jul 9 11:03:07 2008 UTC
# Line 18  INTRODUCTION Line 18  INTRODUCTION
18    
19         The  PCRE  library is a set of functions that implement regular expres-         The  PCRE  library is a set of functions that implement regular expres-
20         sion pattern matching using the same syntax and semantics as Perl, with         sion pattern matching using the same syntax and semantics as Perl, with
21         just  a  few differences. (Certain features that appeared in Python and         just  a  few  differences. Certain features that appeared in Python and
22         PCRE before they appeared in Perl are also available using  the  Python         PCRE before they appeared in Perl are also available using  the  Python
23         syntax.)         syntax.  There is also some support for certain .NET and Oniguruma syn-
24           tax items, and there is an option for  requesting  some  minor  changes
25           that give better JavaScript compatibility.
26    
27         The  current  implementation of PCRE (release 7.x) corresponds approxi-         The  current  implementation of PCRE (release 7.x) corresponds approxi-
28         mately with Perl 5.10, including support for UTF-8 encoded strings  and         mately with Perl 5.10, including support for UTF-8 encoded strings  and
# Line 256  AUTHOR Line 258  AUTHOR
258    
259  REVISION  REVISION
260    
261         Last updated: 09 August 2007         Last updated: 12 April 2008
262         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
263  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
264    
265    
# Line 271  NAME Line 273  NAME
273  PCRE BUILD-TIME OPTIONS  PCRE BUILD-TIME OPTIONS
274    
275         This  document  describes  the  optional  features  of PCRE that can be         This  document  describes  the  optional  features  of PCRE that can be
276         selected when the library is compiled. They are all selected, or  dese-         selected when the library is compiled. It assumes use of the  configure
277         lected, by providing options to the configure script that is run before         script,  where the optional features are selected or deselected by pro-
278         the make command. The complete list of  options  for  configure  (which         viding options to configure before running the make  command.  However,
279         includes  the  standard  ones such as the selection of the installation         the  same  options  can be selected in both Unix-like and non-Unix-like
280         directory) can be obtained by running         environments using the GUI facility of  CMakeSetup  if  you  are  using
281           CMake instead of configure to build PCRE.
282    
283           The complete list of options for configure (which includes the standard
284           ones such as the  selection  of  the  installation  directory)  can  be
285           obtained by running
286    
287           ./configure --help           ./configure --help
288    
289         The following sections include  descriptions  of  options  whose  names         The  following  sections  include  descriptions  of options whose names
290         begin with --enable or --disable. These settings specify changes to the         begin with --enable or --disable. These settings specify changes to the
291         defaults for the configure command. Because of the way  that  configure         defaults  for  the configure command. Because of the way that configure
292         works,  --enable  and --disable always come in pairs, so the complemen-         works, --enable and --disable always come in pairs, so  the  complemen-
293         tary option always exists as well, but as it specifies the default,  it         tary  option always exists as well, but as it specifies the default, it
294         is not described.         is not described.
295    
296    
# Line 304  UTF-8 SUPPORT Line 311  UTF-8 SUPPORT
311    
312           --enable-utf8           --enable-utf8
313    
314         to  the  configure  command.  Of  itself, this does not make PCRE treat         to the configure command. Of itself, this  does  not  make  PCRE  treat
315         strings as UTF-8. As well as compiling PCRE with this option, you  also         strings  as UTF-8. As well as compiling PCRE with this option, you also
316         have  have to set the PCRE_UTF8 option when you call the pcre_compile()         have have to set the PCRE_UTF8 option when you call the  pcre_compile()
317         function.         function.
318    
319    
320  UNICODE CHARACTER PROPERTY SUPPORT  UNICODE CHARACTER PROPERTY SUPPORT
321    
322         UTF-8 support allows PCRE to process character values greater than  255         UTF-8  support allows PCRE to process character values greater than 255
323         in  the  strings that it handles. On its own, however, it does not pro-         in the strings that it handles. On its own, however, it does  not  pro-
324         vide any facilities for accessing the properties of such characters. If         vide any facilities for accessing the properties of such characters. If
325         you  want  to  be able to use the pattern escapes \P, \p, and \X, which         you want to be able to use the pattern escapes \P, \p,  and  \X,  which
326         refer to Unicode character properties, you must add         refer to Unicode character properties, you must add
327    
328           --enable-unicode-properties           --enable-unicode-properties
329    
330         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
331         not explicitly requested it.         not explicitly requested it.
332    
333         Including  Unicode  property  support  adds around 30K of tables to the         Including Unicode property support adds around 30K  of  tables  to  the
334         PCRE library. Only the general category properties such as  Lu  and  Nd         PCRE  library.  Only  the general category properties such as Lu and Nd
335         are supported. Details are given in the pcrepattern documentation.         are supported. Details are given in the pcrepattern documentation.
336    
337    
338  CODE VALUE OF NEWLINE  CODE VALUE OF NEWLINE
339    
340         By  default,  PCRE interprets character 10 (linefeed, LF) as indicating         By default, PCRE interprets character 10 (linefeed, LF)  as  indicating
341         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
342         systems. You can compile PCRE to use character 13 (carriage return, CR)         systems. You can compile PCRE to use character 13 (carriage return, CR)
343         instead, by adding         instead, by adding
344    
345           --enable-newline-is-cr           --enable-newline-is-cr
346    
347         to the  configure  command.  There  is  also  a  --enable-newline-is-lf         to  the  configure  command.  There  is  also  a --enable-newline-is-lf
348         option, which explicitly specifies linefeed as the newline character.         option, which explicitly specifies linefeed as the newline character.
349    
350         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 349  CODE VALUE OF NEWLINE Line 356  CODE VALUE OF NEWLINE
356    
357           --enable-newline-is-anycrlf           --enable-newline-is-anycrlf
358    
359         which causes PCRE to recognize any of the three sequences  CR,  LF,  or         which  causes  PCRE  to recognize any of the three sequences CR, LF, or
360         CRLF as indicating a line ending. Finally, a fifth option, specified by         CRLF as indicating a line ending. Finally, a fifth option, specified by
361    
362           --enable-newline-is-any           --enable-newline-is-any
363    
364         causes PCRE to recognize any Unicode newline sequence.         causes PCRE to recognize any Unicode newline sequence.
365    
366         Whatever line ending convention is selected when PCRE is built  can  be         Whatever  line  ending convention is selected when PCRE is built can be
367         overridden  when  the library functions are called. At build time it is         overridden when the library functions are called. At build time  it  is
368         conventional to use the standard for your operating system.         conventional to use the standard for your operating system.
369    
370    
371  WHAT \R MATCHES  WHAT \R MATCHES
372    
373         By default, the sequence \R in a pattern matches  any  Unicode  newline         By  default,  the  sequence \R in a pattern matches any Unicode newline
374         sequence,  whatever  has  been selected as the line ending sequence. If         sequence, whatever has been selected as the line  ending  sequence.  If
375         you specify         you specify
376    
377           --enable-bsr-anycrlf           --enable-bsr-anycrlf
378    
379         the default is changed so that \R matches only CR, LF, or  CRLF.  What-         the  default  is changed so that \R matches only CR, LF, or CRLF. What-
380         ever  is selected when PCRE is built can be overridden when the library         ever is selected when PCRE is built can be overridden when the  library
381         functions are called.         functions are called.
382    
383    
384  BUILDING SHARED AND STATIC LIBRARIES  BUILDING SHARED AND STATIC LIBRARIES
385    
386         The PCRE building process uses libtool to build both shared and  static         The  PCRE building process uses libtool to build both shared and static
387         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
388         of         of
389    
390           --disable-shared           --disable-shared
# Line 389  BUILDING SHARED AND STATIC LIBRARIES Line 396  BUILDING SHARED AND STATIC LIBRARIES
396  POSIX MALLOC USAGE  POSIX MALLOC USAGE
397    
398         When PCRE is called through the POSIX interface (see the pcreposix doc-         When PCRE is called through the POSIX interface (see the pcreposix doc-
399         umentation),  additional  working  storage  is required for holding the         umentation), additional working storage is  required  for  holding  the
400         pointers to capturing substrings, because PCRE requires three  integers         pointers  to capturing substrings, because PCRE requires three integers
401         per  substring,  whereas  the POSIX interface provides only two. If the         per substring, whereas the POSIX interface provides only  two.  If  the
402         number of expected substrings is small, the wrapper function uses space         number of expected substrings is small, the wrapper function uses space
403         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.
404         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 404  POSIX MALLOC USAGE Line 411  POSIX MALLOC USAGE
411    
412  HANDLING VERY LARGE PATTERNS  HANDLING VERY LARGE PATTERNS
413    
414         Within  a  compiled  pattern,  offset values are used to point from one         Within a compiled pattern, offset values are used  to  point  from  one
415         part to another (for example, from an opening parenthesis to an  alter-         part  to another (for example, from an opening parenthesis to an alter-
416         nation  metacharacter).  By default, two-byte values are used for these         nation metacharacter). By default, two-byte values are used  for  these
417         offsets, leading to a maximum size for a  compiled  pattern  of  around         offsets,  leading  to  a  maximum size for a compiled pattern of around
418         64K.  This  is sufficient to handle all but the most gigantic patterns.         64K. This is sufficient to handle all but the most  gigantic  patterns.
419         Nevertheless, some people do want to process enormous patterns,  so  it         Nevertheless,  some  people do want to process enormous patterns, so it
420         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
421         adding a setting such as         adding a setting such as
422    
423           --with-link-size=3           --with-link-size=3
424    
425         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
426         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
427         additional bytes when handling them.         additional bytes when handling them.
428    
429    
430  AVOIDING EXCESSIVE STACK USAGE  AVOIDING EXCESSIVE STACK USAGE
431    
432         When matching with the pcre_exec() function, PCRE implements backtrack-         When matching with the pcre_exec() function, PCRE implements backtrack-
433         ing  by  making recursive calls to an internal function called match().         ing by making recursive calls to an internal function  called  match().
434         In environments where the size of the stack is limited,  this  can  se-         In  environments  where  the size of the stack is limited, this can se-
435         verely  limit  PCRE's operation. (The Unix environment does not usually         verely limit PCRE's operation. (The Unix environment does  not  usually
436         suffer from this problem, but it may sometimes be necessary to increase         suffer from this problem, but it may sometimes be necessary to increase
437         the  maximum  stack size.  There is a discussion in the pcrestack docu-         the maximum stack size.  There is a discussion in the  pcrestack  docu-
438         mentation.) An alternative approach to recursion that uses memory  from         mentation.)  An alternative approach to recursion that uses memory from
439         the  heap  to remember data, instead of using recursive function calls,         the heap to remember data, instead of using recursive  function  calls,
440         has been implemented to work round the problem of limited  stack  size.         has  been  implemented to work round the problem of limited stack size.
441         If you want to build a version of PCRE that works this way, add         If you want to build a version of PCRE that works this way, add
442    
443           --disable-stack-for-recursion           --disable-stack-for-recursion
444    
445         to  the  configure  command. With this configuration, PCRE will use the         to the configure command. With this configuration, PCRE  will  use  the
446         pcre_stack_malloc and pcre_stack_free variables to call memory  manage-         pcre_stack_malloc  and pcre_stack_free variables to call memory manage-
447         ment  functions. By default these point to malloc() and free(), but you         ment functions. By default these point to malloc() and free(), but  you
448         can replace the pointers so that your own functions are used.         can replace the pointers so that your own functions are used.
449    
450         Separate functions are  provided  rather  than  using  pcre_malloc  and         Separate  functions  are  provided  rather  than  using pcre_malloc and
451         pcre_free  because  the  usage  is  very  predictable:  the block sizes         pcre_free because the  usage  is  very  predictable:  the  block  sizes
452         requested are always the same, and  the  blocks  are  always  freed  in         requested  are  always  the  same,  and  the blocks are always freed in
453         reverse  order.  A calling program might be able to implement optimized         reverse order. A calling program might be able to  implement  optimized
454         functions that perform better  than  malloc()  and  free().  PCRE  runs         functions  that  perform  better  than  malloc()  and free(). PCRE runs
455         noticeably more slowly when built in this way. This option affects only         noticeably more slowly when built in this way. This option affects only
456         the  pcre_exec()  function;  it   is   not   relevant   for   the   the         the   pcre_exec()   function;   it   is   not   relevant  for  the  the
457         pcre_dfa_exec() function.         pcre_dfa_exec() function.
458    
459    
460  LIMITING PCRE RESOURCE USAGE  LIMITING PCRE RESOURCE USAGE
461    
462         Internally,  PCRE has a function called match(), which it calls repeat-         Internally, PCRE has a function called match(), which it calls  repeat-
463         edly  (sometimes  recursively)  when  matching  a  pattern   with   the         edly   (sometimes   recursively)  when  matching  a  pattern  with  the
464         pcre_exec()  function.  By controlling the maximum number of times this         pcre_exec() function. By controlling the maximum number of  times  this
465         function may be called during a single matching operation, a limit  can         function  may be called during a single matching operation, a limit can
466         be  placed  on  the resources used by a single call to pcre_exec(). The         be placed on the resources used by a single call  to  pcre_exec().  The
467         limit can be changed at run time, as described in the pcreapi  documen-         limit  can be changed at run time, as described in the pcreapi documen-
468         tation.  The default is 10 million, but this can be changed by adding a         tation. The default is 10 million, but this can be changed by adding  a
469         setting such as         setting such as
470    
471           --with-match-limit=500000           --with-match-limit=500000
472    
473         to  the  configure  command.  This  setting  has  no  effect   on   the         to   the   configure  command.  This  setting  has  no  effect  on  the
474         pcre_dfa_exec() matching function.         pcre_dfa_exec() matching function.
475    
476         In  some  environments  it is desirable to limit the depth of recursive         In some environments it is desirable to limit the  depth  of  recursive
477         calls of match() more strictly than the total number of calls, in order         calls of match() more strictly than the total number of calls, in order
478         to  restrict  the maximum amount of stack (or heap, if --disable-stack-         to restrict the maximum amount of stack (or heap,  if  --disable-stack-
479         for-recursion is specified) that is used. A second limit controls this;         for-recursion is specified) that is used. A second limit controls this;
480         it  defaults  to  the  value  that is set for --with-match-limit, which         it defaults to the value that  is  set  for  --with-match-limit,  which
481         imposes no additional constraints. However, you can set a  lower  limit         imposes  no  additional constraints. However, you can set a lower limit
482         by adding, for example,         by adding, for example,
483    
484           --with-match-limit-recursion=10000           --with-match-limit-recursion=10000
485    
486         to  the  configure  command.  This  value can also be overridden at run         to the configure command. This value can  also  be  overridden  at  run
487         time.         time.
488    
489    
490  CREATING CHARACTER TABLES AT BUILD TIME  CREATING CHARACTER TABLES AT BUILD TIME
491    
492         PCRE uses fixed tables for processing characters whose code values  are         PCRE  uses fixed tables for processing characters whose code values are
493         less  than 256. By default, PCRE is built with a set of tables that are         less than 256. By default, PCRE is built with a set of tables that  are
494         distributed in the file pcre_chartables.c.dist. These  tables  are  for         distributed  in  the  file pcre_chartables.c.dist. These tables are for
495         ASCII codes only. If you add         ASCII codes only. If you add
496    
497           --enable-rebuild-chartables           --enable-rebuild-chartables
498    
499         to  the  configure  command, the distributed tables are no longer used.         to the configure command, the distributed tables are  no  longer  used.
500         Instead, a program called dftables is compiled and  run.  This  outputs         Instead,  a  program  called dftables is compiled and run. This outputs
501         the source for new set of tables, created in the default locale of your         the source for new set of tables, created in the default locale of your
502         C runtime system. (This method of replacing the tables does not work if         C runtime system. (This method of replacing the tables does not work if
503         you  are cross compiling, because dftables is run on the local host. If         you are cross compiling, because dftables is run on the local host.  If
504         you need to create alternative tables when cross  compiling,  you  will         you  need  to  create alternative tables when cross compiling, you will
505         have to do so "by hand".)         have to do so "by hand".)
506    
507    
508  USING EBCDIC CODE  USING EBCDIC CODE
509    
510         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
511         character code is ASCII (or Unicode, which is  a  superset  of  ASCII).         character  code  is  ASCII  (or Unicode, which is a superset of ASCII).
512         This  is  the  case for most computer operating systems. PCRE can, how-         This is the case for most computer operating systems.  PCRE  can,  how-
513         ever, be compiled to run in an EBCDIC environment by adding         ever, be compiled to run in an EBCDIC environment by adding
514    
515           --enable-ebcdic           --enable-ebcdic
516    
517         to the configure command. This setting implies --enable-rebuild-charta-         to the configure command. This setting implies --enable-rebuild-charta-
518         bles.  You  should  only  use  it if you know that you are in an EBCDIC         bles. You should only use it if you know that  you  are  in  an  EBCDIC
519         environment (for example, an IBM mainframe operating system).         environment (for example, an IBM mainframe operating system).
520    
521    
522    PCREGREP OPTIONS FOR COMPRESSED FILE SUPPORT
523    
524           By default, pcregrep reads all files as plain text. You can build it so
525           that it recognizes files whose names end in .gz or .bz2, and reads them
526           with libz or libbz2, respectively, by adding one or both of
527    
528             --enable-pcregrep-libz
529             --enable-pcregrep-libbz2
530    
531           to the configure command. These options naturally require that the rel-
532           evant libraries are installed on your system. Configuration  will  fail
533           if they are not.
534    
535    
536    PCRETEST OPTION FOR LIBREADLINE SUPPORT
537    
538           If you add
539    
540             --enable-pcretest-libreadline
541    
542           to  the  configure  command,  pcretest  is  linked with the libreadline
543           library, and when its input is from a terminal, it reads it  using  the
544           readline() function. This provides line-editing and history facilities.
545           Note that libreadline is GPL-licenced, so if you distribute a binary of
546           pcretest linked in this way, there may be licensing issues.
547    
548           Setting  this  option  causes  the -lreadline option to be added to the
549           pcretest build. In many operating environments with  a  sytem-installed
550           libreadline this is sufficient. However, in some environments (e.g.  if
551           an unmodified distribution version of readline is in use),  some  extra
552           configuration  may  be necessary. The INSTALL file for libreadline says
553           this:
554    
555             "Readline uses the termcap functions, but does not link with the
556             termcap or curses library itself, allowing applications which link
557             with readline the to choose an appropriate library."
558    
559           If your environment has not been set up so that an appropriate  library
560           is automatically included, you may need to add something like
561    
562             LIBS="-ncurses"
563    
564           immediately before the configure command.
565    
566    
567  SEE ALSO  SEE ALSO
568    
569         pcreapi(3), pcre_config(3).         pcreapi(3), pcre_config(3).
# Line 526  AUTHOR Line 578  AUTHOR
578    
579  REVISION  REVISION
580    
581         Last updated: 11 September 2007         Last updated: 13 April 2008
582         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
583  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
584    
585    
# Line 675  THE ALTERNATIVE MATCHING ALGORITHM Line 727  THE ALTERNATIVE MATCHING ALGORITHM
727         tive algorithm moves through the subject  string  one  character  at  a         tive algorithm moves through the subject  string  one  character  at  a
728         time, for all active paths through the tree.         time, for all active paths through the tree.
729    
730         8.  None  of  the  backtracking control verbs such as (*PRUNE) are sup-         8.  Except for (*FAIL), the backtracking control verbs such as (*PRUNE)
731         ported.         are not supported. (*FAIL) is supported, and  behaves  like  a  failing
732           negative assertion.
733    
734    
735  ADVANTAGES OF THE ALTERNATIVE ALGORITHM  ADVANTAGES OF THE ALTERNATIVE ALGORITHM
736    
737         Using the alternative matching algorithm provides the following  advan-         Using  the alternative matching algorithm provides the following advan-
738         tages:         tages:
739    
740         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-
741         ically found, and in particular, the longest match is  found.  To  find         ically  found,  and  in particular, the longest match is found. To find
742         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
743         things with callouts.         things with callouts.
744    
745         2. There is much better support for partial matching. The  restrictions         2.  There is much better support for partial matching. The restrictions
746         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-
747         rithm for partial matching do not apply to the  alternative  algorithm.         rithm  for  partial matching do not apply to the alternative algorithm.
748         For  non-anchored patterns, the starting position of a partial match is         For non-anchored patterns, the starting position of a partial match  is
749         available.         available.
750    
751         3. Because the alternative algorithm  scans  the  subject  string  just         3.  Because  the  alternative  algorithm  scans the subject string just
752         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
753         subject strings to the matching function in  several  pieces,  checking         subject  strings  to  the matching function in several pieces, checking
754         for partial matching each time.         for partial matching each time.
755    
756    
# Line 705  DISADVANTAGES OF THE ALTERNATIVE ALGORIT Line 758  DISADVANTAGES OF THE ALTERNATIVE ALGORIT
758    
759         The alternative algorithm suffers from a number of disadvantages:         The alternative algorithm suffers from a number of disadvantages:
760    
761         1.  It  is  substantially  slower  than the standard algorithm. This is         1. It is substantially slower than  the  standard  algorithm.  This  is
762         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
763         because it is less susceptible to optimization.         because it is less susceptible to optimization.
764    
765         2. Capturing parentheses and back references are not supported.         2. Capturing parentheses and back references are not supported.
# Line 724  AUTHOR Line 777  AUTHOR
777    
778  REVISION  REVISION
779    
780         Last updated: 08 August 2007         Last updated: 19 April 2008
781         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
782  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
783    
784    
# Line 837  PCRE API OVERVIEW Line 890  PCRE API OVERVIEW
890         a  Perl-compatible  manner. A sample program that demonstrates the sim-         a  Perl-compatible  manner. A sample program that demonstrates the sim-
891         plest way of using them is provided in the file  called  pcredemo.c  in         plest way of using them is provided in the file  called  pcredemo.c  in
892         the  source distribution. The pcresample documentation describes how to         the  source distribution. The pcresample documentation describes how to
893         run it.         compile and run it.
894    
895         A second matching function, pcre_dfa_exec(), which is not Perl-compati-         A second matching function, pcre_dfa_exec(), which is not Perl-compati-
896         ble,  is  also provided. This uses a different algorithm for the match-         ble,  is  also provided. This uses a different algorithm for the match-
# Line 1212  COMPILING A PATTERN Line 1265  COMPILING A PATTERN
1265         before or at the first  newline  in  the  subject  string,  though  the         before or at the first  newline  in  the  subject  string,  though  the
1266         matched text may continue over the newline.         matched text may continue over the newline.
1267    
1268             PCRE_JAVASCRIPT_COMPAT
1269    
1270           If this option is set, PCRE's behaviour is changed in some ways so that
1271           it is compatible with JavaScript rather than Perl. The changes  are  as
1272           follows:
1273    
1274           (1)  A  lone  closing square bracket in a pattern causes a compile-time
1275           error, because this is illegal in JavaScript (by default it is  treated
1276           as a data character). Thus, the pattern AB]CD becomes illegal when this
1277           option is set.
1278    
1279           (2) At run time, a back reference to an unset subpattern group  matches
1280           an  empty  string (by default this causes the current matching alterna-
1281           tive to fail). A pattern such as (\1)(a) succeeds when this  option  is
1282           set  (assuming  it can find an "a" in the subject), whereas it fails by
1283           default, for Perl compatibility.
1284    
1285           PCRE_MULTILINE           PCRE_MULTILINE
1286    
1287         By  default,  PCRE  treats the subject string as consisting of a single         By default, PCRE treats the subject string as consisting  of  a  single
1288         line of characters (even if it actually contains newlines). The  "start         line  of characters (even if it actually contains newlines). The "start
1289         of  line"  metacharacter  (^)  matches only at the start of the string,         of line" metacharacter (^) matches only at the  start  of  the  string,
1290         while the "end of line" metacharacter ($) matches only at  the  end  of         while  the  "end  of line" metacharacter ($) matches only at the end of
1291         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY
1292         is set). This is the same as Perl.         is set). This is the same as Perl.
1293    
1294         When PCRE_MULTILINE it is set, the "start of line" and  "end  of  line"         When  PCRE_MULTILINE  it  is set, the "start of line" and "end of line"
1295         constructs  match  immediately following or immediately before internal         constructs match immediately following or immediately  before  internal
1296         newlines in the subject string, respectively, as well as  at  the  very         newlines  in  the  subject string, respectively, as well as at the very
1297         start  and  end.  This is equivalent to Perl's /m option, and it can be         start and end. This is equivalent to Perl's /m option, and  it  can  be
1298         changed within a pattern by a (?m) option setting. If there are no new-         changed within a pattern by a (?m) option setting. If there are no new-
1299         lines  in  a  subject string, or no occurrences of ^ or $ in a pattern,         lines in a subject string, or no occurrences of ^ or $  in  a  pattern,
1300         setting PCRE_MULTILINE has no effect.         setting PCRE_MULTILINE has no effect.
1301    
1302           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
# Line 1235  COMPILING A PATTERN Line 1305  COMPILING A PATTERN
1305           PCRE_NEWLINE_ANYCRLF           PCRE_NEWLINE_ANYCRLF
1306           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
1307    
1308         These options override the default newline definition that  was  chosen         These  options  override the default newline definition that was chosen
1309         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
1310         newline is indicated by a single character (CR  or  LF,  respectively).         newline  is  indicated  by a single character (CR or LF, respectively).
1311         Setting  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the         Setting PCRE_NEWLINE_CRLF specifies that a newline is indicated by  the
1312         two-character CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF  specifies         two-character  CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF specifies
1313         that any of the three preceding sequences should be recognized. Setting         that any of the three preceding sequences should be recognized. Setting
1314         PCRE_NEWLINE_ANY specifies that any Unicode newline sequence should  be         PCRE_NEWLINE_ANY  specifies that any Unicode newline sequence should be
1315         recognized. The Unicode newline sequences are the three just mentioned,         recognized. The Unicode newline sequences are the three just mentioned,
1316         plus the single characters VT (vertical  tab,  U+000B),  FF  (formfeed,         plus  the  single  characters  VT (vertical tab, U+000B), FF (formfeed,
1317         U+000C),  NEL  (next line, U+0085), LS (line separator, U+2028), and PS         U+000C), NEL (next line, U+0085), LS (line separator, U+2028),  and  PS
1318         (paragraph separator, U+2029). The last  two  are  recognized  only  in         (paragraph  separator,  U+2029).  The  last  two are recognized only in
1319         UTF-8 mode.         UTF-8 mode.
1320    
1321         The  newline  setting  in  the  options  word  uses three bits that are         The newline setting in the  options  word  uses  three  bits  that  are
1322         treated as a number, giving eight possibilities. Currently only six are         treated as a number, giving eight possibilities. Currently only six are
1323         used  (default  plus the five values above). This means that if you set         used (default plus the five values above). This means that if  you  set
1324         more than one newline option, the combination may or may not be  sensi-         more  than one newline option, the combination may or may not be sensi-
1325         ble. For example, PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is equivalent to         ble. For example, PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is equivalent to
1326         PCRE_NEWLINE_CRLF, but other combinations may yield unused numbers  and         PCRE_NEWLINE_CRLF,  but other combinations may yield unused numbers and
1327         cause an error.         cause an error.
1328    
1329         The  only time that a line break is specially recognized when compiling         The only time that a line break is specially recognized when  compiling
1330         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
1331         character  class  is  encountered.  This indicates a comment that lasts         character class is encountered. This indicates  a  comment  that  lasts
1332         until after the next line break sequence. In other circumstances,  line         until  after the next line break sequence. In other circumstances, line
1333         break   sequences   are   treated  as  literal  data,  except  that  in         break  sequences  are  treated  as  literal  data,   except   that   in
1334         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters
1335         and are therefore ignored.         and are therefore ignored.
1336    
1337         The newline option that is set at compile time becomes the default that         The newline option that is set at compile time becomes the default that
1338         is used for pcre_exec() and pcre_dfa_exec(), but it can be  overridden.         is  used for pcre_exec() and pcre_dfa_exec(), but it can be overridden.
1339    
1340           PCRE_NO_AUTO_CAPTURE           PCRE_NO_AUTO_CAPTURE
1341    
1342         If this option is set, it disables the use of numbered capturing paren-         If this option is set, it disables the use of numbered capturing paren-
1343         theses in the pattern. Any opening parenthesis that is not followed  by         theses  in the pattern. Any opening parenthesis that is not followed by
1344         ?  behaves as if it were followed by ?: but named parentheses can still         ? behaves as if it were followed by ?: but named parentheses can  still
1345         be used for capturing (and they acquire  numbers  in  the  usual  way).         be  used  for  capturing  (and  they acquire numbers in the usual way).
1346         There is no equivalent of this option in Perl.         There is no equivalent of this option in Perl.
1347    
1348           PCRE_UNGREEDY           PCRE_UNGREEDY
1349    
1350         This  option  inverts  the "greediness" of the quantifiers so that they         This option inverts the "greediness" of the quantifiers  so  that  they
1351         are not greedy by default, but become greedy if followed by "?". It  is         are  not greedy by default, but become greedy if followed by "?". It is
1352         not  compatible  with Perl. It can also be set by a (?U) option setting         not compatible with Perl. It can also be set by a (?U)  option  setting
1353         within the pattern.         within the pattern.
1354    
1355           PCRE_UTF8           PCRE_UTF8
1356    
1357         This option causes PCRE to regard both the pattern and the  subject  as         This  option  causes PCRE to regard both the pattern and the subject as
1358         strings  of  UTF-8 characters instead of single-byte character strings.         strings of UTF-8 characters instead of single-byte  character  strings.
1359         However, it is available only when PCRE is built to include UTF-8  sup-         However,  it is available only when PCRE is built to include UTF-8 sup-
1360         port.  If not, the use of this option provokes an error. Details of how         port. If not, the use of this option provokes an error. Details of  how
1361         this option changes the behaviour of PCRE are given in the  section  on         this  option  changes the behaviour of PCRE are given in the section on
1362         UTF-8 support in the main pcre page.         UTF-8 support in the main pcre page.
1363    
1364           PCRE_NO_UTF8_CHECK           PCRE_NO_UTF8_CHECK
1365    
1366         When PCRE_UTF8 is set, the validity of the pattern as a UTF-8 string is         When PCRE_UTF8 is set, the validity of the pattern as a UTF-8 string is
1367         automatically checked. There is a  discussion  about  the  validity  of         automatically  checked.  There  is  a  discussion about the validity of
1368         UTF-8  strings  in  the main pcre page. If an invalid UTF-8 sequence of         UTF-8 strings in the main pcre page. If an invalid  UTF-8  sequence  of
1369         bytes is found, pcre_compile() returns an error. If  you  already  know         bytes  is  found,  pcre_compile() returns an error. If you already know
1370         that your pattern is valid, and you want to skip this check for perfor-         that your pattern is valid, and you want to skip this check for perfor-
1371         mance reasons, you can set the PCRE_NO_UTF8_CHECK option.  When  it  is         mance  reasons,  you  can set the PCRE_NO_UTF8_CHECK option. When it is
1372         set,  the  effect  of  passing  an invalid UTF-8 string as a pattern is         set, the effect of passing an invalid UTF-8  string  as  a  pattern  is
1373         undefined. It may cause your program to crash. Note  that  this  option         undefined.  It  may  cause your program to crash. Note that this option
1374         can  also be passed to pcre_exec() and pcre_dfa_exec(), to suppress the         can also be passed to pcre_exec() and pcre_dfa_exec(), to suppress  the
1375         UTF-8 validity checking of subject strings.         UTF-8 validity checking of subject strings.
1376    
1377    
1378  COMPILATION ERROR CODES  COMPILATION ERROR CODES
1379    
1380         The following table lists the error  codes  than  may  be  returned  by         The  following  table  lists  the  error  codes than may be returned by
1381         pcre_compile2(),  along with the error messages that may be returned by         pcre_compile2(), along with the error messages that may be returned  by
1382         both compiling functions. As PCRE has developed, some error codes  have         both  compiling functions. As PCRE has developed, some error codes have
1383         fallen out of use. To avoid confusion, they have not been re-used.         fallen out of use. To avoid confusion, they have not been re-used.
1384    
1385            0  no error            0  no error
# Line 1324  COMPILATION ERROR CODES Line 1394  COMPILATION ERROR CODES
1394            9  nothing to repeat            9  nothing to repeat
1395           10  [this code is not in use]           10  [this code is not in use]
1396           11  internal error: unexpected repeat           11  internal error: unexpected repeat
1397           12  unrecognized character after (?           12  unrecognized character after (? or (?-
1398           13  POSIX named classes are supported only within a class           13  POSIX named classes are supported only within a class
1399           14  missing )           14  missing )
1400           15  reference to non-existent subpattern           15  reference to non-existent subpattern
# Line 1332  COMPILATION ERROR CODES Line 1402  COMPILATION ERROR CODES
1402           17  unknown option bit(s) set           17  unknown option bit(s) set
1403           18  missing ) after comment           18  missing ) after comment
1404           19  [this code is not in use]           19  [this code is not in use]
1405           20  regular expression too large           20  regular expression is too large
1406           21  failed to get memory           21  failed to get memory
1407           22  unmatched parentheses           22  unmatched parentheses
1408           23  internal error: code overflow           23  internal error: code overflow
# Line 1361  COMPILATION ERROR CODES Line 1431  COMPILATION ERROR CODES
1431           46  malformed \P or \p sequence           46  malformed \P or \p sequence
1432           47  unknown property name after \P or \p           47  unknown property name after \P or \p
1433           48  subpattern name is too long (maximum 32 characters)           48  subpattern name is too long (maximum 32 characters)
1434           49  too many named subpatterns (maximum 10,000)           49  too many named subpatterns (maximum 10000)
1435           50  [this code is not in use]           50  [this code is not in use]
1436           51  octal value is greater than \377 (not in UTF-8 mode)           51  octal value is greater than \377 (not in UTF-8 mode)
1437           52  internal error: overran compiling workspace           52  internal error: overran compiling workspace
1438           53   internal  error:  previously-checked  referenced  subpattern not           53  internal  error:  previously-checked  referenced  subpattern  not
1439         found         found
1440           54  DEFINE group contains more than one branch           54  DEFINE group contains more than one branch
1441           55  repeating a DEFINE group is not allowed           55  repeating a DEFINE group is not allowed
1442           56  inconsistent NEWLINE options           56  inconsistent NEWLINE options
1443           57  \g is not followed by a braced name or an optionally braced           57  \g is not followed by a braced, angle-bracketed, or quoted
1444                 non-zero number                 name/number or by a plain number
1445           58  (?+ or (?- or (?(+ or (?(- must be followed by a non-zero number           58  a numbered reference must not be zero
1446             59  (*VERB) with an argument is not supported
1447             60  (*VERB) not recognized
1448             61  number is too big
1449             62  subpattern name expected
1450             63  digit expected after (?+
1451             64  ] is an invalid data character in JavaScript compatibility mode
1452    
1453           The  numbers  32  and 10000 in errors 48 and 49 are defaults; different
1454           values may be used if the limits were changed when PCRE was built.
1455    
1456    
1457  STUDYING A PATTERN  STUDYING A PATTERN
# Line 1570  INFORMATION ABOUT A PATTERN Line 1649  INFORMATION ABOUT A PATTERN
1649    
1650           PCRE_INFO_JCHANGED           PCRE_INFO_JCHANGED
1651    
1652         Return 1 if the (?J) option setting is used in the  pattern,  otherwise         Return 1 if the (?J) or (?-J) option setting is used  in  the  pattern,
1653         0. The fourth argument should point to an int variable. The (?J) inter-         otherwise  0. The fourth argument should point to an int variable. (?J)
1654         nal option setting changes the local PCRE_DUPNAMES option.         and (?-J) set and unset the local PCRE_DUPNAMES option, respectively.
1655    
1656           PCRE_INFO_LASTLITERAL           PCRE_INFO_LASTLITERAL
1657    
# Line 2525  AUTHOR Line 2604  AUTHOR
2604    
2605  REVISION  REVISION
2606    
2607         Last updated: 11 September 2007         Last updated: 12 April 2008
2608         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
2609  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2610    
2611    
# Line 2853  PCRE REGULAR EXPRESSION DETAILS Line 2932  PCRE REGULAR EXPRESSION DETAILS
2932    
2933         The  syntax and semantics of the regular expressions that are supported         The  syntax and semantics of the regular expressions that are supported
2934         by PCRE are described in detail below. There is a quick-reference  syn-         by PCRE are described in detail below. There is a quick-reference  syn-
2935         tax  summary  in  the  pcresyntax  page. Perl's regular expressions are         tax summary in the pcresyntax page. PCRE tries to match Perl syntax and
2936         described in its own documentation, and regular expressions in  general         semantics as closely as it can. PCRE  also  supports  some  alternative
2937         are  covered in a number of books, some of which have copious examples.         regular  expression  syntax (which does not conflict with the Perl syn-
2938         Jeffrey  Friedl's  "Mastering  Regular   Expressions",   published   by         tax) in order to provide some compatibility with regular expressions in
2939         O'Reilly,  covers regular expressions in great detail. This description         Python, .NET, and Oniguruma.
2940         of PCRE's regular expressions is intended as reference material.  
2941           Perl's  regular expressions are described in its own documentation, and
2942           regular expressions in general are covered in a number of  books,  some
2943           of  which  have  copious  examples. Jeffrey Friedl's "Mastering Regular
2944           Expressions", published by  O'Reilly,  covers  regular  expressions  in
2945           great  detail.  This  description  of  PCRE's  regular  expressions  is
2946           intended as reference material.
2947    
2948         The original operation of PCRE was on strings of  one-byte  characters.         The original operation of PCRE was on strings of  one-byte  characters.
2949         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 2911  NEWLINE CONVENTIONS Line 2996  NEWLINE CONVENTIONS
2996         The  newline  convention  does  not  affect what the \R escape sequence         The  newline  convention  does  not  affect what the \R escape sequence
2997         matches. By default, this is any Unicode  newline  sequence,  for  Perl         matches. By default, this is any Unicode  newline  sequence,  for  Perl
2998         compatibility.  However, this can be changed; see the description of \R         compatibility.  However, this can be changed; see the description of \R
2999         in the section entitled "Newline sequences" below.         in the section entitled "Newline sequences" below. A change of \R  set-
3000           ting can be combined with a change of newline convention.
3001    
3002    
3003  CHARACTERS AND METACHARACTERS  CHARACTERS AND METACHARACTERS
3004    
3005         A regular expression is a pattern that is  matched  against  a  subject         A  regular  expression  is  a pattern that is matched against a subject
3006         string  from  left  to right. Most characters stand for themselves in a         string from left to right. Most characters stand for  themselves  in  a
3007         pattern, and match the corresponding characters in the  subject.  As  a         pattern,  and  match  the corresponding characters in the subject. As a
3008         trivial example, the pattern         trivial example, the pattern
3009    
3010           The quick brown fox           The quick brown fox
3011    
3012         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
3013         caseless matching is specified (the PCRE_CASELESS option), letters  are         caseless  matching is specified (the PCRE_CASELESS option), letters are
3014         matched  independently  of case. In UTF-8 mode, PCRE always understands         matched independently of case. In UTF-8 mode, PCRE  always  understands
3015         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
3016         caseless  matching  is always possible. For characters with higher val-         caseless matching is always possible. For characters with  higher  val-
3017         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
3018         property  support,  but  not  otherwise.   If  you want to use caseless         property support, but not otherwise.   If  you  want  to  use  caseless
3019         matching for characters 128 and above, you must  ensure  that  PCRE  is         matching  for  characters  128  and above, you must ensure that PCRE is
3020         compiled with Unicode property support as well as with UTF-8 support.         compiled with Unicode property support as well as with UTF-8 support.
3021    
3022         The  power  of  regular  expressions  comes from the ability to include         The power of regular expressions comes  from  the  ability  to  include
3023         alternatives and repetitions in the pattern. These are encoded  in  the         alternatives  and  repetitions in the pattern. These are encoded in the
3024         pattern by the use of metacharacters, which do not stand for themselves         pattern by the use of metacharacters, which do not stand for themselves
3025         but instead are interpreted in some special way.         but instead are interpreted in some special way.
3026    
3027         There are two different sets of metacharacters: those that  are  recog-         There  are  two different sets of metacharacters: those that are recog-
3028         nized  anywhere in the pattern except within square brackets, and those         nized anywhere in the pattern except within square brackets, and  those
3029         that are recognized within square brackets.  Outside  square  brackets,         that  are  recognized  within square brackets. Outside square brackets,
3030         the metacharacters are as follows:         the metacharacters are as follows:
3031    
3032           \      general escape character with several uses           \      general escape character with several uses
# Line 2959  CHARACTERS AND METACHARACTERS Line 3045  CHARACTERS AND METACHARACTERS
3045                  also "possessive quantifier"                  also "possessive quantifier"
3046           {      start min/max quantifier           {      start min/max quantifier
3047    
3048         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
3049         class". In a character class the only metacharacters are:         class". In a character class the only metacharacters are:
3050    
3051           \      general escape character           \      general escape character
# Line 2969  CHARACTERS AND METACHARACTERS Line 3055  CHARACTERS AND METACHARACTERS
3055                    syntax)                    syntax)
3056           ]      terminates the character class           ]      terminates the character class
3057    
3058         The following sections describe the use of each of the  metacharacters.         The  following sections describe the use of each of the metacharacters.
3059    
3060    
3061  BACKSLASH  BACKSLASH
3062    
3063         The backslash character has several uses. Firstly, if it is followed by         The backslash character has several uses. Firstly, if it is followed by
3064         a non-alphanumeric character, it takes away any  special  meaning  that         a  non-alphanumeric  character,  it takes away any special meaning that
3065         character  may  have.  This  use  of  backslash  as an escape character         character may have. This  use  of  backslash  as  an  escape  character
3066         applies both inside and outside character classes.         applies both inside and outside character classes.
3067    
3068         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
3069         pattern.   This  escaping  action  applies whether or not the following         pattern.  This escaping action applies whether  or  not  the  following
3070         character would otherwise be interpreted as a metacharacter, so  it  is         character  would  otherwise be interpreted as a metacharacter, so it is
3071         always  safe  to  precede  a non-alphanumeric with backslash to specify         always safe to precede a non-alphanumeric  with  backslash  to  specify
3072         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-
3073         slash, you write \\.         slash, you write \\.
3074    
3075         If  a  pattern is compiled with the PCRE_EXTENDED option, whitespace in         If a pattern is compiled with the PCRE_EXTENDED option,  whitespace  in
3076         the pattern (other than in a character class) and characters between  a         the  pattern (other than in a character class) and characters between a
3077         # outside a character class and the next newline are ignored. An escap-         # outside a character class and the next newline are ignored. An escap-
3078         ing backslash can be used to include a whitespace  or  #  character  as         ing  backslash  can  be  used to include a whitespace or # character as
3079         part of the pattern.         part of the pattern.
3080    
3081         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-
3082         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-
3083         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
3084         sequences in PCRE, whereas in Perl, $ and @ cause  variable  interpola-         sequences  in  PCRE, whereas in Perl, $ and @ cause variable interpola-
3085         tion. Note the following examples:         tion. Note the following examples:
3086    
3087           Pattern            PCRE matches   Perl matches           Pattern            PCRE matches   Perl matches
# Line 3005  BACKSLASH Line 3091  BACKSLASH
3091           \Qabc\$xyz\E       abc\$xyz       abc\$xyz           \Qabc\$xyz\E       abc\$xyz       abc\$xyz
3092           \Qabc\E\$\Qxyz\E   abc$xyz        abc$xyz           \Qabc\E\$\Qxyz\E   abc$xyz        abc$xyz
3093    
3094         The  \Q...\E  sequence  is recognized both inside and outside character         The \Q...\E sequence is recognized both inside  and  outside  character
3095         classes.         classes.
3096    
3097     Non-printing characters     Non-printing characters
3098    
3099         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-
3100         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
3101         appearance of non-printing characters, apart from the binary zero  that         appearance  of non-printing characters, apart from the binary zero that
3102         terminates  a  pattern,  but  when  a pattern is being prepared by text         terminates a pattern, but when a pattern  is  being  prepared  by  text
3103         editing, it is usually easier  to  use  one  of  the  following  escape         editing,  it  is  usually  easier  to  use  one of the following escape
3104         sequences than the binary character it represents:         sequences than the binary character it represents:
3105    
3106           \a        alarm, that is, the BEL character (hex 07)           \a        alarm, that is, the BEL character (hex 07)
# Line 3028  BACKSLASH Line 3114  BACKSLASH
3114           \xhh      character with hex code hh           \xhh      character with hex code hh
3115           \x{hhh..} character with hex code hhh..           \x{hhh..} character with hex code hhh..
3116    
3117         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,
3118         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
3119         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;
3120         becomes hex 7B.         becomes hex 7B.
3121    
3122         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
3123         in  upper  or  lower case). Any number of hexadecimal digits may appear         in upper or lower case). Any number of hexadecimal  digits  may  appear
3124         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
3125         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,
3126         the maximum value in hexadecimal is 7FFFFFFF. Note that this is  bigger         the  maximum value in hexadecimal is 7FFFFFFF. Note that this is bigger
3127         than the largest Unicode code point, which is 10FFFF.         than the largest Unicode code point, which is 10FFFF.
3128    
3129         If  characters  other than hexadecimal digits appear between \x{ and },         If characters other than hexadecimal digits appear between \x{  and  },
3130         or if there is no terminating }, this form of escape is not recognized.         or if there is no terminating }, this form of escape is not recognized.
3131         Instead,  the  initial  \x  will  be interpreted as a basic hexadecimal         Instead, the initial \x will be  interpreted  as  a  basic  hexadecimal
3132         escape, with no following digits, giving a  character  whose  value  is         escape,  with  no  following  digits, giving a character whose value is
3133         zero.         zero.
3134    
3135         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
3136         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-
3137         dled. For example, \xdc is exactly the same as \x{dc}.         dled. For example, \xdc is exactly the same as \x{dc}.
3138    
3139         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
3140         than two digits, just  those  that  are  present  are  used.  Thus  the         than  two  digits,  just  those  that  are  present  are used. Thus the
3141         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
3142         (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
3143         if the pattern character that follows is itself an octal digit.         if the pattern character that follows is itself an octal digit.
3144    
3145         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-
3146         cated.  Outside a character class, PCRE reads it and any following dig-         cated.  Outside a character class, PCRE reads it and any following dig-
3147         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
3148         have been at least that many previous capturing left parentheses in the         have been at least that many previous capturing left parentheses in the
3149         expression,  the  entire  sequence  is  taken  as  a  back reference. A         expression, the entire  sequence  is  taken  as  a  back  reference.  A
3150         description of how this works is given later, following the  discussion         description  of how this works is given later, following the discussion
3151         of parenthesized subpatterns.         of parenthesized subpatterns.
3152    
3153         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
3154         and there have not been that many capturing subpatterns, PCRE  re-reads         and  there have not been that many capturing subpatterns, PCRE re-reads
3155         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-
3156         erate a data character. Any subsequent digits stand for themselves.  In         erate  a data character. Any subsequent digits stand for themselves. In
3157         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
3158         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
3159         example:         example:
3160    
3161           \040   is another way of writing a space           \040   is another way of writing a space
# Line 3087  BACKSLASH Line 3173  BACKSLASH
3173           \81    is either a back reference, or a binary zero           \81    is either a back reference, or a binary zero
3174                     followed by the two characters "8" and "1"                     followed by the two characters "8" and "1"
3175    
3176         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
3177         leading zero, because no more than three octal digits are ever read.         leading zero, because no more than three octal digits are ever read.
3178    
3179         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
3180         inside  and  outside character classes. In addition, inside a character         inside and outside character classes. In addition, inside  a  character
3181         class, the sequence \b is interpreted as the backspace  character  (hex         class,  the  sequence \b is interpreted as the backspace character (hex
3182         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"
3183         and "X", respectively. Outside a character class, these sequences  have         and  "X", respectively. Outside a character class, these sequences have
3184         different meanings (see below).         different meanings (see below).
3185    
3186     Absolute and relative back references     Absolute and relative back references
3187    
3188         The  sequence  \g followed by an unsigned or a negative number, option-         The sequence \g followed by an unsigned or a negative  number,  option-
3189         ally enclosed in braces, is an absolute or relative back  reference.  A         ally  enclosed  in braces, is an absolute or relative back reference. A
3190         named back reference can be coded as \g{name}. Back references are dis-         named back reference can be coded as \g{name}. Back references are dis-
3191         cussed later, following the discussion of parenthesized subpatterns.         cussed later, following the discussion of parenthesized subpatterns.
3192    
3193       Absolute and relative subroutine calls
3194    
3195           For  compatibility with Oniguruma, the non-Perl syntax \g followed by a
3196           name or a number enclosed either in angle brackets or single quotes, is
3197           an  alternative  syntax for referencing a subpattern as a "subroutine".
3198           Details are discussed later.   Note  that  \g{...}  (Perl  syntax)  and
3199           \g<...>  (Oniguruma  syntax)  are  not synonymous. The former is a back
3200           reference; the latter is a subroutine call.
3201    
3202     Generic character types     Generic character types
3203    
3204         Another use of backslash is for specifying generic character types. The         Another use of backslash is for specifying generic character types. The
# Line 3207  BACKSLASH Line 3302  BACKSLASH
3302         It is possible to restrict \R to match only CR, LF, or CRLF (instead of         It is possible to restrict \R to match only CR, LF, or CRLF (instead of
3303         the complete set  of  Unicode  line  endings)  by  setting  the  option         the complete set  of  Unicode  line  endings)  by  setting  the  option
3304         PCRE_BSR_ANYCRLF either at compile time or when the pattern is matched.         PCRE_BSR_ANYCRLF either at compile time or when the pattern is matched.
3305         This can be made the default when PCRE is built; if this is  the  case,         (BSR is an abbrevation for "backslash R".) This can be made the default
3306         the  other  behaviour can be requested via the PCRE_BSR_UNICODE option.         when  PCRE  is  built;  if this is the case, the other behaviour can be
3307         It is also possible to specify these settings  by  starting  a  pattern         requested via the PCRE_BSR_UNICODE option.   It  is  also  possible  to
3308         string with one of the following sequences:         specify  these  settings  by  starting a pattern string with one of the
3309           following sequences:
3310    
3311           (*BSR_ANYCRLF)   CR, LF, or CRLF only           (*BSR_ANYCRLF)   CR, LF, or CRLF only
3312           (*BSR_UNICODE)   any Unicode newline sequence           (*BSR_UNICODE)   any Unicode newline sequence
# Line 3218  BACKSLASH Line 3314  BACKSLASH
3314         These override the default and the options given to pcre_compile(), but         These override the default and the options given to pcre_compile(), but
3315         they can be overridden by options given to pcre_exec(). Note that these         they can be overridden by options given to pcre_exec(). Note that these
3316         special settings, which are not Perl-compatible, are recognized only at         special settings, which are not Perl-compatible, are recognized only at
3317         the very start of a pattern, and that they must be in  upper  case.  If         the  very  start  of a pattern, and that they must be in upper case. If
3318         more than one of them is present, the last one is used.         more than one of them is present, the last one is  used.  They  can  be
3319           combined  with  a  change of newline convention, for example, a pattern
3320           can start with:
3321    
3322             (*ANY)(*BSR_ANYCRLF)
3323    
3324         Inside a character class, \R matches the letter "R".         Inside a character class, \R matches the letter "R".
3325    
3326     Unicode character properties     Unicode character properties
3327    
3328         When PCRE is built with Unicode character property support, three addi-         When PCRE is built with Unicode character property support, three addi-
3329         tional escape sequences that match characters with specific  properties         tional  escape sequences that match characters with specific properties
3330         are  available.   When not in UTF-8 mode, these sequences are of course         are available.  When not in UTF-8 mode, these sequences are  of  course
3331         limited to testing characters whose codepoints are less than  256,  but         limited  to  testing characters whose codepoints are less than 256, but
3332         they do work in this mode.  The extra escape sequences are:         they do work in this mode.  The extra escape sequences are:
3333    
3334           \p{xx}   a character with the xx property           \p{xx}   a character with the xx property
3335           \P{xx}   a character without the xx property           \P{xx}   a character without the xx property
3336           \X       an extended Unicode sequence           \X       an extended Unicode sequence
3337    
3338         The  property  names represented by xx above are limited to the Unicode         The property names represented by xx above are limited to  the  Unicode
3339         script names, the general category properties, and "Any", which matches         script names, the general category properties, and "Any", which matches
3340         any character (including newline). Other properties such as "InMusical-         any character (including newline). Other properties such as "InMusical-
3341         Symbols" are not currently supported by PCRE. Note  that  \P{Any}  does         Symbols"  are  not  currently supported by PCRE. Note that \P{Any} does
3342         not match any characters, so always causes a match failure.         not match any characters, so always causes a match failure.
3343    
3344         Sets of Unicode characters are defined as belonging to certain scripts.         Sets of Unicode characters are defined as belonging to certain scripts.
3345         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.
3346         For example:         For example:
3347    
3348           \p{Greek}           \p{Greek}
3349           \P{Han}           \P{Han}
3350    
3351         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
3352         "Common". The current list of scripts is:         "Common". The current list of scripts is:
3353    
3354         Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,         Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,
3355         Buhid,   Canadian_Aboriginal,   Cherokee,  Common,  Coptic,  Cuneiform,         Buhid,  Canadian_Aboriginal,  Cherokee,  Common,   Coptic,   Cuneiform,
3356         Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,         Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,
3357         Gothic,  Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hira-         Gothic, Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew,  Hira-
3358         gana, Inherited, Kannada,  Katakana,  Kharoshthi,  Khmer,  Lao,  Latin,         gana,  Inherited,  Kannada,  Katakana,  Kharoshthi,  Khmer, Lao, Latin,
3359         Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,         Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,
3360         Ogham, Old_Italic, Old_Persian, Oriya, Osmanya,  Phags_Pa,  Phoenician,         Ogham,  Old_Italic,  Old_Persian, Oriya, Osmanya, Phags_Pa, Phoenician,
3361         Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,         Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,
3362         Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.         Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.
3363    
3364         Each character has exactly one general category property, specified  by         Each  character has exactly one general category property, specified by
3365         a two-letter abbreviation. For compatibility with Perl, negation can be         a two-letter abbreviation. For compatibility with Perl, negation can be
3366         specified by including a circumflex between the opening brace  and  the         specified  by  including a circumflex between the opening brace and the
3367         property name. For example, \p{^Lu} is the same as \P{Lu}.         property name. For example, \p{^Lu} is the same as \P{Lu}.
3368    
3369         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-
3370         eral category properties that start with that letter. In this case,  in         eral  category properties that start with that letter. In this case, in
3371         the  absence of negation, the curly brackets in the escape sequence are         the absence of negation, the curly brackets in the escape sequence  are
3372         optional; these two examples have the same effect:         optional; these two examples have the same effect:
3373    
3374           \p{L}           \p{L}
# Line 3320  BACKSLASH Line 3420  BACKSLASH
3420           Zp    Paragraph separator           Zp    Paragraph separator
3421           Zs    Space separator           Zs    Space separator
3422    
3423         The special property L& is also supported: it matches a character  that         The  special property L& is also supported: it matches a character that
3424         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
3425         classified as a modifier or "other".         classified as a modifier or "other".
3426    
3427         The Cs (Surrogate) property applies only to  characters  in  the  range         The  Cs  (Surrogate)  property  applies only to characters in the range
3428         U+D800  to  U+DFFF. Such characters are not valid in UTF-8 strings (see         U+D800 to U+DFFF. Such characters are not valid in UTF-8  strings  (see
3429         RFC 3629) and so cannot be tested by PCRE, unless UTF-8 validity check-         RFC 3629) and so cannot be tested by PCRE, unless UTF-8 validity check-
3430         ing  has  been  turned off (see the discussion of PCRE_NO_UTF8_CHECK in         ing has been turned off (see the discussion  of  PCRE_NO_UTF8_CHECK  in
3431         the pcreapi page).         the pcreapi page).
3432    
3433         The long synonyms for these properties  that  Perl  supports  (such  as         The  long  synonyms  for  these  properties that Perl supports (such as
3434         \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
3435         any of these properties with "Is".         any of these properties with "Is".
3436    
3437         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-
3438         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
3439         in the Unicode table.         in the Unicode table.
3440    
3441         Specifying caseless matching does not affect  these  escape  sequences.         Specifying  caseless  matching  does not affect these escape sequences.
3442         For example, \p{Lu} always matches only upper case letters.         For example, \p{Lu} always matches only upper case letters.
3443    
3444         The  \X  escape  matches  any number of Unicode characters that form an         The \X escape matches any number of Unicode  characters  that  form  an
3445         extended Unicode sequence. \X is equivalent to         extended Unicode sequence. \X is equivalent to
3446    
3447           (?>\PM\pM*)           (?>\PM\pM*)
3448    
3449         That is, it matches a character without the "mark"  property,  followed         That  is,  it matches a character without the "mark" property, followed
3450         by  zero  or  more  characters with the "mark" property, and treats the         by zero or more characters with the "mark"  property,  and  treats  the
3451         sequence as an atomic group (see below).  Characters  with  the  "mark"         sequence  as  an  atomic group (see below).  Characters with the "mark"
3452         property  are  typically  accents  that affect the preceding character.         property are typically accents that  affect  the  preceding  character.
3453         None of them have codepoints less than 256, so  in  non-UTF-8  mode  \X         None  of  them  have  codepoints less than 256, so in non-UTF-8 mode \X
3454         matches any one character.         matches any one character.
3455    
3456         Matching  characters  by Unicode property is not fast, because PCRE has         Matching characters by Unicode property is not fast, because  PCRE  has
3457         to search a structure that contains  data  for  over  fifteen  thousand         to  search  a  structure  that  contains data for over fifteen thousand
3458         characters. That is why the traditional escape sequences such as \d and         characters. That is why the traditional escape sequences such as \d and
3459         \w do not use Unicode properties in PCRE.         \w do not use Unicode properties in PCRE.
3460    
3461     Resetting the match start     Resetting the match start
3462    
3463         The escape sequence \K, which is a Perl 5.10 feature, causes any previ-         The escape sequence \K, which is a Perl 5.10 feature, causes any previ-
3464         ously  matched  characters  not  to  be  included  in the final matched         ously matched characters not  to  be  included  in  the  final  matched
3465         sequence. For example, the pattern:         sequence. For example, the pattern:
3466    
3467           foo\Kbar           foo\Kbar
3468    
3469         matches "foobar", but reports that it has matched "bar".  This  feature         matches  "foobar",  but reports that it has matched "bar". This feature
3470         is  similar  to  a lookbehind assertion (described below).  However, in         is similar to a lookbehind assertion (described  below).   However,  in
3471         this case, the part of the subject before the real match does not  have         this  case, the part of the subject before the real match does not have
3472         to  be of fixed length, as lookbehind assertions do. The use of \K does         to be of fixed length, as lookbehind assertions do. The use of \K  does
3473         not interfere with the setting of captured  substrings.   For  example,         not  interfere  with  the setting of captured substrings.  For example,
3474         when the pattern         when the pattern
3475    
3476           (foo)\Kbar           (foo)\Kbar
# Line 3379  BACKSLASH Line 3479  BACKSLASH
3479    
3480     Simple assertions     Simple assertions
3481    
3482         The  final use of backslash is for certain simple assertions. An asser-         The final use of backslash is for certain simple assertions. An  asser-
3483         tion specifies a condition that has to be met at a particular point  in         tion  specifies a condition that has to be met at a particular point in
3484         a  match, without consuming any characters from the subject string. The         a match, without consuming any characters from the subject string.  The
3485         use of subpatterns for more complicated assertions is described  below.         use  of subpatterns for more complicated assertions is described below.
3486         The backslashed assertions are:         The backslashed assertions are:
3487    
3488           \b     matches at a word boundary           \b     matches at a word boundary
# Line 3393  BACKSLASH Line 3493  BACKSLASH
3493           \z     matches only at the end of the subject           \z     matches only at the end of the subject
3494           \G     matches at the first matching position in the subject           \G     matches at the first matching position in the subject
3495    
3496         These  assertions may not appear in character classes (but note that \b         These assertions may not appear in character classes (but note that  \b
3497         has a different meaning, namely the backspace character, inside a char-         has a different meaning, namely the backspace character, inside a char-
3498         acter class).         acter class).
3499    
3500         A  word  boundary is a position in the subject string where the current         A word boundary is a position in the subject string where  the  current
3501         character and the previous character do not both match \w or  \W  (i.e.         character  and  the previous character do not both match \w or \W (i.e.
3502         one  matches  \w  and the other matches \W), or the start or end of the         one matches \w and the other matches \W), or the start or  end  of  the
3503         string if the first or last character matches \w, respectively.         string if the first or last character matches \w, respectively.
3504    
3505         The \A, \Z, and \z assertions differ from  the  traditional  circumflex         The  \A,  \Z,  and \z assertions differ from the traditional circumflex
3506         and dollar (described in the next section) in that they only ever match         and dollar (described in the next section) in that they only ever match
3507         at the very start and end of the subject string, whatever  options  are         at  the  very start and end of the subject string, whatever options are
3508         set.  Thus,  they are independent of multiline mode. These three asser-         set. Thus, they are independent of multiline mode. These  three  asser-
3509         tions are not affected by the PCRE_NOTBOL or PCRE_NOTEOL options, which         tions are not affected by the PCRE_NOTBOL or PCRE_NOTEOL options, which
3510         affect  only the behaviour of the circumflex and dollar metacharacters.         affect only the behaviour of the circumflex and dollar  metacharacters.
3511         However, if the startoffset argument of pcre_exec() is non-zero,  indi-         However,  if the startoffset argument of pcre_exec() is non-zero, indi-
3512         cating that matching is to start at a point other than the beginning of         cating that matching is to start at a point other than the beginning of
3513         the subject, \A can never match. The difference between \Z  and  \z  is         the  subject,  \A  can never match. The difference between \Z and \z is
3514         that \Z matches before a newline at the end of the string as well as at         that \Z matches before a newline at the end of the string as well as at
3515         the very end, whereas \z matches only at the end.         the very end, whereas \z matches only at the end.
3516    
3517         The \G assertion is true only when the current matching position is  at         The  \G assertion is true only when the current matching position is at
3518         the  start point of the match, as specified by the startoffset argument         the start point of the match, as specified by the startoffset  argument
3519         of pcre_exec(). It differs from \A when the  value  of  startoffset  is         of  pcre_exec().  It  differs  from \A when the value of startoffset is
3520         non-zero.  By calling pcre_exec() multiple times with appropriate argu-         non-zero. By calling pcre_exec() multiple times with appropriate  argu-
3521         ments, you can mimic Perl's /g option, and it is in this kind of imple-         ments, you can mimic Perl's /g option, and it is in this kind of imple-
3522         mentation where \G can be useful.         mentation where \G can be useful.
3523    
3524         Note,  however,  that  PCRE's interpretation of \G, as the start of the         Note, however, that PCRE's interpretation of \G, as the  start  of  the
3525         current match, is subtly different from Perl's, which defines it as the         current match, is subtly different from Perl's, which defines it as the
3526         end  of  the  previous  match. In Perl, these can be different when the         end of the previous match. In Perl, these can  be  different  when  the
3527         previously matched string was empty. Because PCRE does just  one  match         previously  matched  string was empty. Because PCRE does just one match
3528         at a time, it cannot reproduce this behaviour.         at a time, it cannot reproduce this behaviour.
3529    
3530         If  all  the alternatives of a pattern begin with \G, the expression is         If all the alternatives of a pattern begin with \G, the  expression  is
3531         anchored to the starting match position, and the "anchored" flag is set         anchored to the starting match position, and the "anchored" flag is set
3532         in the compiled regular expression.         in the compiled regular expression.
3533    
# Line 3435  BACKSLASH Line 3535  BACKSLASH
3535  CIRCUMFLEX AND DOLLAR  CIRCUMFLEX AND DOLLAR
3536    
3537         Outside a character class, in the default matching mode, the circumflex         Outside a character class, in the default matching mode, the circumflex
3538         character is an assertion that is true only  if  the  current  matching         character  is  an  assertion  that is true only if the current matching
3539         point  is  at the start of the subject string. If the startoffset argu-         point is at the start of the subject string. If the  startoffset  argu-
3540         ment of pcre_exec() is non-zero, circumflex  can  never  match  if  the         ment  of  pcre_exec()  is  non-zero,  circumflex can never match if the
3541         PCRE_MULTILINE  option  is  unset. Inside a character class, circumflex         PCRE_MULTILINE option is unset. Inside a  character  class,  circumflex
3542         has an entirely different meaning (see below).         has an entirely different meaning (see below).
3543    
3544         Circumflex need not be the first character of the pattern if  a  number         Circumflex  need  not be the first character of the pattern if a number
3545         of  alternatives are involved, but it should be the first thing in each         of alternatives are involved, but it should be the first thing in  each
3546         alternative in which it appears if the pattern is ever  to  match  that         alternative  in  which  it appears if the pattern is ever to match that
3547         branch.  If all possible alternatives start with a circumflex, that is,         branch. If all possible alternatives start with a circumflex, that  is,
3548         if the pattern is constrained to match only at the start  of  the  sub-         if  the  pattern  is constrained to match only at the start of the sub-
3549         ject,  it  is  said  to be an "anchored" pattern. (There are also other         ject, it is said to be an "anchored" pattern.  (There  are  also  other
3550         constructs that can cause a pattern to be anchored.)         constructs that can cause a pattern to be anchored.)
3551    
3552         A dollar character is an assertion that is true  only  if  the  current         A  dollar  character  is  an assertion that is true only if the current
3553         matching  point  is  at  the  end of the subject string, or immediately         matching point is at the end of  the  subject  string,  or  immediately
3554         before a newline at the end of the string (by default). Dollar need not         before a newline at the end of the string (by default). Dollar need not
3555         be  the  last  character of the pattern if a number of alternatives are         be the last character of the pattern if a number  of  alternatives  are
3556         involved, but it should be the last item in  any  branch  in  which  it         involved,  but  it  should  be  the last item in any branch in which it
3557         appears. Dollar has no special meaning in a character class.         appears. Dollar has no special meaning in a character class.
3558    
3559         The  meaning  of  dollar  can be changed so that it matches only at the         The meaning of dollar can be changed so that it  matches  only  at  the
3560         very end of the string, by setting the  PCRE_DOLLAR_ENDONLY  option  at         very  end  of  the string, by setting the PCRE_DOLLAR_ENDONLY option at
3561         compile time. This does not affect the \Z assertion.         compile time. This does not affect the \Z assertion.
3562    
3563         The meanings of the circumflex and dollar characters are changed if the         The meanings of the circumflex and dollar characters are changed if the
3564         PCRE_MULTILINE option is set. When  this  is  the  case,  a  circumflex         PCRE_MULTILINE  option  is  set.  When  this  is the case, a circumflex
3565         matches  immediately after internal newlines as well as at the start of         matches immediately after internal newlines as well as at the start  of
3566         the subject string. It does not match after a  newline  that  ends  the         the  subject  string.  It  does not match after a newline that ends the
3567         string.  A dollar matches before any newlines in the string, as well as         string. A dollar matches before any newlines in the string, as well  as
3568         at the very end, when PCRE_MULTILINE is set. When newline is  specified         at  the very end, when PCRE_MULTILINE is set. When newline is specified
3569         as  the  two-character  sequence CRLF, isolated CR and LF characters do         as the two-character sequence CRLF, isolated CR and  LF  characters  do
3570         not indicate newlines.         not indicate newlines.
3571    
3572         For example, the pattern /^abc$/ matches the subject string  "def\nabc"         For  example, the pattern /^abc$/ matches the subject string "def\nabc"
3573         (where  \n  represents a newline) in multiline mode, but not otherwise.         (where \n represents a newline) in multiline mode, but  not  otherwise.
3574         Consequently, patterns that are anchored in single  line  mode  because         Consequently,  patterns  that  are anchored in single line mode because
3575         all  branches  start  with  ^ are not anchored in multiline mode, and a         all branches start with ^ are not anchored in  multiline  mode,  and  a
3576         match for circumflex is  possible  when  the  startoffset  argument  of         match  for  circumflex  is  possible  when  the startoffset argument of
3577         pcre_exec()  is  non-zero. The PCRE_DOLLAR_ENDONLY option is ignored if         pcre_exec() is non-zero. The PCRE_DOLLAR_ENDONLY option is  ignored  if
3578         PCRE_MULTILINE is set.         PCRE_MULTILINE is set.
3579    
3580         Note that the sequences \A, \Z, and \z can be used to match  the  start         Note  that  the sequences \A, \Z, and \z can be used to match the start
3581         and  end of the subject in both modes, and if all branches of a pattern         and end of the subject in both modes, and if all branches of a  pattern
3582         start with \A it is always anchored, whether or not  PCRE_MULTILINE  is         start  with  \A it is always anchored, whether or not PCRE_MULTILINE is
3583         set.         set.
3584    
3585    
3586  FULL STOP (PERIOD, DOT)  FULL STOP (PERIOD, DOT)
3587    
3588         Outside a character class, a dot in the pattern matches any one charac-         Outside a character class, a dot in the pattern matches any one charac-
3589         ter in the subject string except (by default) a character  that  signi-         ter  in  the subject string except (by default) a character that signi-
3590         fies  the  end  of  a line. In UTF-8 mode, the matched character may be         fies the end of a line. In UTF-8 mode, the  matched  character  may  be
3591         more than one byte long.         more than one byte long.
3592    
3593         When a line ending is defined as a single character, dot never  matches         When  a line ending is defined as a single character, dot never matches
3594         that  character; when the two-character sequence CRLF is used, dot does         that character; when the two-character sequence CRLF is used, dot  does
3595         not match CR if it is immediately followed  by  LF,  but  otherwise  it         not  match  CR  if  it  is immediately followed by LF, but otherwise it
3596         matches  all characters (including isolated CRs and LFs). When any Uni-         matches all characters (including isolated CRs and LFs). When any  Uni-
3597         code line endings are being recognized, dot does not match CR or LF  or         code  line endings are being recognized, dot does not match CR or LF or
3598         any of the other line ending characters.         any of the other line ending characters.
3599    
3600         The  behaviour  of  dot  with regard to newlines can be changed. If the         The behaviour of dot with regard to newlines can  be  changed.  If  the
3601         PCRE_DOTALL option is set, a dot matches  any  one  character,  without         PCRE_DOTALL  option  is  set,  a dot matches any one character, without
3602         exception. If the two-character sequence CRLF is present in the subject         exception. If the two-character sequence CRLF is present in the subject
3603         string, it takes two dots to match it.         string, it takes two dots to match it.
3604    
3605         The handling of dot is entirely independent of the handling of  circum-         The  handling of dot is entirely independent of the handling of circum-
3606         flex  and  dollar,  the  only relationship being that they both involve         flex and dollar, the only relationship being  that  they  both  involve
3607         newlines. Dot has no special meaning in a character class.         newlines. Dot has no special meaning in a character class.
3608    
3609    
3610  MATCHING A SINGLE BYTE  MATCHING A SINGLE BYTE
3611    
3612         Outside a character class, the escape sequence \C matches any one byte,         Outside a character class, the escape sequence \C matches any one byte,
3613         both  in  and  out  of  UTF-8 mode. Unlike a dot, it always matches any         both in and out of UTF-8 mode. Unlike a  dot,  it  always  matches  any
3614         line-ending characters. The feature is provided in  Perl  in  order  to         line-ending  characters.  The  feature  is provided in Perl in order to
3615         match  individual bytes in UTF-8 mode. Because it breaks up UTF-8 char-         match individual bytes in UTF-8 mode. Because it breaks up UTF-8  char-
3616         acters into individual bytes, what remains in the string may be a  mal-         acters  into individual bytes, what remains in the string may be a mal-
3617         formed  UTF-8  string.  For this reason, the \C escape sequence is best         formed UTF-8 string. For this reason, the \C escape  sequence  is  best
3618         avoided.         avoided.
3619    
3620         PCRE does not allow \C to appear in  lookbehind  assertions  (described         PCRE  does  not  allow \C to appear in lookbehind assertions (described
3621         below),  because  in UTF-8 mode this would make it impossible to calcu-         below), because in UTF-8 mode this would make it impossible  to  calcu-
3622         late the length of the lookbehind.         late the length of the lookbehind.
3623    
3624    
# Line 3527  SQUARE BRACKETS AND CHARACTER CLASSES Line 3627  SQUARE BRACKETS AND CHARACTER CLASSES
3627         An opening square bracket introduces a character class, terminated by a         An opening square bracket introduces a character class, terminated by a
3628         closing square bracket. A closing square bracket on its own is not spe-         closing square bracket. A closing square bracket on its own is not spe-
3629         cial. If a closing square bracket is required as a member of the class,         cial. If a closing square bracket is required as a member of the class,
3630         it  should  be  the first data character in the class (after an initial         it should be the first data character in the class  (after  an  initial
3631         circumflex, if present) or escaped with a backslash.         circumflex, if present) or escaped with a backslash.
3632    
3633         A character class matches a single character in the subject.  In  UTF-8         A  character  class matches a single character in the subject. In UTF-8
3634         mode,  the character may occupy more than one byte. A matched character         mode, the character may occupy more than one byte. A matched  character
3635         must be in the set of characters defined by the class, unless the first         must be in the set of characters defined by the class, unless the first
3636         character  in  the  class definition is a circumflex, in which case the         character in the class definition is a circumflex, in  which  case  the
3637         subject character must not be in the set defined by  the  class.  If  a         subject  character  must  not  be in the set defined by the class. If a
3638         circumflex  is actually required as a member of the class, ensure it is         circumflex is actually required as a member of the class, ensure it  is
3639         not the first character, or escape it with a backslash.         not the first character, or escape it with a backslash.
3640    
3641         For example, the character class [aeiou] matches any lower case  vowel,         For  example, the character class [aeiou] matches any lower case vowel,
3642         while  [^aeiou]  matches  any character that is not a lower case vowel.         while [^aeiou] matches any character that is not a  lower  case  vowel.
3643         Note that a circumflex is just a convenient notation for specifying the         Note that a circumflex is just a convenient notation for specifying the
3644         characters  that  are in the class by enumerating those that are not. A         characters that are in the class by enumerating those that are  not.  A
3645         class that starts with a circumflex is not an assertion: it still  con-         class  that starts with a circumflex is not an assertion: it still con-
3646         sumes  a  character  from the subject string, and therefore it fails if         sumes a character from the subject string, and therefore  it  fails  if
3647         the current pointer is at the end of the string.         the current pointer is at the end of the string.
3648    
3649         In UTF-8 mode, characters with values greater than 255 can be  included         In  UTF-8 mode, characters with values greater than 255 can be included
3650         in  a  class as a literal string of bytes, or by using the \x{ escaping         in a class as a literal string of bytes, or by using the  \x{  escaping
3651         mechanism.         mechanism.
3652    
3653         When caseless matching is set, any letters in a  class  represent  both         When  caseless  matching  is set, any letters in a class represent both
3654         their  upper  case  and lower case versions, so for example, a caseless         their upper case and lower case versions, so for  example,  a  caseless
3655         [aeiou] matches "A" as well as "a", and a caseless  [^aeiou]  does  not         [aeiou]  matches  "A"  as well as "a", and a caseless [^aeiou] does not
3656         match  "A", whereas a caseful version would. In UTF-8 mode, PCRE always         match "A", whereas a caseful version would. In UTF-8 mode, PCRE  always
3657         understands the concept of case for characters whose  values  are  less         understands  the  concept  of case for characters whose values are less
3658         than  128, so caseless matching is always possible. For characters with         than 128, so caseless matching is always possible. For characters  with
3659         higher values, the concept of case is supported  if  PCRE  is  compiled         higher  values,  the  concept  of case is supported if PCRE is compiled
3660         with  Unicode  property support, but not otherwise.  If you want to use         with Unicode property support, but not otherwise.  If you want  to  use
3661         caseless matching for characters 128 and above, you  must  ensure  that         caseless  matching  for  characters 128 and above, you must ensure that
3662         PCRE  is  compiled  with Unicode property support as well as with UTF-8         PCRE is compiled with Unicode property support as well  as  with  UTF-8
3663         support.         support.
3664    
3665         Characters that might indicate line breaks are  never  treated  in  any         Characters  that  might  indicate  line breaks are never treated in any
3666         special  way  when  matching  character  classes,  whatever line-ending         special way  when  matching  character  classes,  whatever  line-ending
3667         sequence is in  use,  and  whatever  setting  of  the  PCRE_DOTALL  and         sequence  is  in  use,  and  whatever  setting  of  the PCRE_DOTALL and
3668         PCRE_MULTILINE options is used. A class such as [^a] always matches one         PCRE_MULTILINE options is used. A class such as [^a] always matches one
3669         of these characters.         of these characters.
3670    
3671         The minus (hyphen) character can be used to specify a range of  charac-         The  minus (hyphen) character can be used to specify a range of charac-
3672         ters  in  a  character  class.  For  example,  [d-m] matches any letter         ters in a character  class.  For  example,  [d-m]  matches  any  letter
3673         between d and m, inclusive. If a  minus  character  is  required  in  a         between  d  and  m,  inclusive.  If  a minus character is required in a
3674         class,  it  must  be  escaped  with a backslash or appear in a position         class, it must be escaped with a backslash  or  appear  in  a  position
3675         where it cannot be interpreted as indicating a range, typically as  the         where  it cannot be interpreted as indicating a range, typically as the
3676         first or last character in the class.         first or last character in the class.
3677    
3678         It is not possible to have the literal character "]" as the end charac-         It is not possible to have the literal character "]" as the end charac-
3679         ter of a range. A pattern such as [W-]46] is interpreted as a class  of         ter  of a range. A pattern such as [W-]46] is interpreted as a class of
3680         two  characters ("W" and "-") followed by a literal string "46]", so it         two characters ("W" and "-") followed by a literal string "46]", so  it
3681         would match "W46]" or "-46]". However, if the "]"  is  escaped  with  a         would  match  "W46]"  or  "-46]". However, if the "]" is escaped with a
3682         backslash  it is interpreted as the end of range, so [W-\]46] is inter-         backslash it is interpreted as the end of range, so [W-\]46] is  inter-
3683         preted as a class containing a range followed by two other  characters.         preted  as a class containing a range followed by two other characters.
3684         The  octal or hexadecimal representation of "]" can also be used to end         The octal or hexadecimal representation of "]" can also be used to  end
3685         a range.         a range.
3686    
3687         Ranges operate in the collating sequence of character values. They  can         Ranges  operate in the collating sequence of character values. They can
3688         also   be  used  for  characters  specified  numerically,  for  example         also  be  used  for  characters  specified  numerically,  for   example
3689         [\000-\037]. In UTF-8 mode, ranges can include characters whose  values         [\000-\037].  In UTF-8 mode, ranges can include characters whose values
3690         are greater than 255, for example [\x{100}-\x{2ff}].         are greater than 255, for example [\x{100}-\x{2ff}].
3691    
3692         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,
3693         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
3694         to  [][\\^_`wxyzabc],  matched  caselessly,  and  in non-UTF-8 mode, if         to [][\\^_`wxyzabc], matched caselessly,  and  in  non-UTF-8  mode,  if
3695         character tables for a French locale are in  use,  [\xc8-\xcb]  matches         character  tables  for  a French locale are in use, [\xc8-\xcb] matches
3696         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
3697         concept of case for characters with values greater than 128  only  when         concept  of  case for characters with values greater than 128 only when
3698         it is compiled with Unicode property support.         it is compiled with Unicode property support.
3699    
3700         The  character types \d, \D, \p, \P, \s, \S, \w, and \W may also appear         The character types \d, \D, \p, \P, \s, \S, \w, and \W may also  appear
3701         in a character class, and add the characters that  they  match  to  the         in  a  character  class,  and add the characters that they match to the
3702         class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-         class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-
3703         flex can conveniently be used with the upper case  character  types  to         flex  can  conveniently  be used with the upper case character types to
3704         specify  a  more  restricted  set of characters than the matching lower         specify a more restricted set of characters  than  the  matching  lower
3705         case type. For example, the class [^\W_] matches any letter  or  digit,         case  type.  For example, the class [^\W_] matches any letter or digit,
3706         but not underscore.         but not underscore.
3707    
3708         The  only  metacharacters  that are recognized in character classes are         The only metacharacters that are recognized in  character  classes  are
3709         backslash, hyphen (only where it can be  interpreted  as  specifying  a         backslash,  hyphen  (only  where  it can be interpreted as specifying a
3710         range),  circumflex  (only  at the start), opening square bracket (only         range), circumflex (only at the start), opening  square  bracket  (only
3711         when it can be interpreted as introducing a POSIX class name - see  the         when  it can be interpreted as introducing a POSIX class name - see the
3712         next  section),  and  the  terminating closing square bracket. However,         next section), and the terminating  closing  square  bracket.  However,
3713         escaping other non-alphanumeric characters does no harm.         escaping other non-alphanumeric characters does no harm.
3714    
3715    
3716  POSIX CHARACTER CLASSES  POSIX CHARACTER CLASSES
3717    
3718         Perl supports the POSIX notation for character classes. This uses names         Perl supports the POSIX notation for character classes. This uses names
3719         enclosed  by  [: and :] within the enclosing square brackets. PCRE also         enclosed by [: and :] within the enclosing square brackets.  PCRE  also
3720         supports this notation. For example,         supports this notation. For example,
3721    
3722           [01[:alpha:]%]           [01[:alpha:]%]
# Line 3639  POSIX CHARACTER CLASSES Line 3739  POSIX CHARACTER CLASSES
3739           word     "word" characters (same as \w)           word     "word" characters (same as \w)
3740           xdigit   hexadecimal digits           xdigit   hexadecimal digits
3741    
3742         The  "space" characters are HT (9), LF (10), VT (11), FF (12), CR (13),         The "space" characters are HT (9), LF (10), VT (11), FF (12), CR  (13),
3743         and space (32). Notice that this list includes the VT  character  (code         and  space  (32). Notice that this list includes the VT character (code
3744         11). This makes "space" different to \s, which does not include VT (for         11). This makes "space" different to \s, which does not include VT (for
3745         Perl compatibility).         Perl compatibility).
3746    
3747         The name "word" is a Perl extension, and "blank"  is  a  GNU  extension         The  name  "word"  is  a Perl extension, and "blank" is a GNU extension
3748         from  Perl  5.8. Another Perl extension is negation, which is indicated         from Perl 5.8. Another Perl extension is negation, which  is  indicated
3749         by a ^ character after the colon. For example,         by a ^ character after the colon. For example,
3750    
3751           [12[:^digit:]]           [12[:^digit:]]
3752    
3753         matches "1", "2", or any non-digit. PCRE (and Perl) also recognize  the         matches  "1", "2", or any non-digit. PCRE (and Perl) also recognize the
3754         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but
3755         these are not supported, and an error is given if they are encountered.         these are not supported, and an error is given if they are encountered.
3756    
# Line 3660  POSIX CHARACTER CLASSES Line 3760  POSIX CHARACTER CLASSES
3760    
3761  VERTICAL BAR  VERTICAL BAR
3762    
3763         Vertical bar characters are used to separate alternative patterns.  For         Vertical  bar characters are used to separate alternative patterns. For
3764         example, the pattern         example, the pattern
3765    
3766           gilbert|sullivan           gilbert|sullivan
3767    
3768         matches  either "gilbert" or "sullivan". Any number of alternatives may         matches either "gilbert" or "sullivan". Any number of alternatives  may
3769         appear, and an empty  alternative  is  permitted  (matching  the  empty         appear,  and  an  empty  alternative  is  permitted (matching the empty
3770         string). The matching process tries each alternative in turn, from left         string). The matching process tries each alternative in turn, from left
3771         to right, and the first one that succeeds is used. If the  alternatives         to  right, and the first one that succeeds is used. If the alternatives
3772         are  within a subpattern (defined below), "succeeds" means matching the         are within a subpattern (defined below), "succeeds" means matching  the
3773         rest of the main pattern as well as the alternative in the  subpattern.         rest  of the main pattern as well as the alternative in the subpattern.
3774    
3775    
3776  INTERNAL OPTION SETTING  INTERNAL OPTION SETTING
3777    
3778         The  settings  of  the  PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and         The settings of the  PCRE_CASELESS,  PCRE_MULTILINE,  PCRE_DOTALL,  and
3779         PCRE_EXTENDED options (which are Perl-compatible) can be  changed  from         PCRE_EXTENDED  options  (which are Perl-compatible) can be changed from
3780         within  the  pattern  by  a  sequence  of  Perl option letters enclosed         within the pattern by  a  sequence  of  Perl  option  letters  enclosed
3781         between "(?" and ")".  The option letters are         between "(?" and ")".  The option letters are
3782    
3783           i  for PCRE_CASELESS           i  for PCRE_CASELESS
# Line 3687  INTERNAL OPTION SETTING Line 3787  INTERNAL OPTION SETTING
3787    
3788         For example, (?im) sets caseless, multiline matching. It is also possi-         For example, (?im) sets caseless, multiline matching. It is also possi-
3789         ble to unset these options by preceding the letter with a hyphen, and a         ble to unset these options by preceding the letter with a hyphen, and a
3790         combined setting and unsetting such as (?im-sx), which sets  PCRE_CASE-         combined  setting and unsetting such as (?im-sx), which sets PCRE_CASE-
3791         LESS  and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED,         LESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and  PCRE_EXTENDED,
3792         is also permitted. If a  letter  appears  both  before  and  after  the         is  also  permitted.  If  a  letter  appears  both before and after the
3793         hyphen, the option is unset.         hyphen, the option is unset.
3794    
3795         The  PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA         The PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and  PCRE_EXTRA
3796         can be changed in the same way as the Perl-compatible options by  using         can  be changed in the same way as the Perl-compatible options by using
3797         the characters J, U and X respectively.         the characters J, U and X respectively.
3798    
3799         When  an option change occurs at top level (that is, not inside subpat-         When an option change occurs at top level (that is, not inside  subpat-
3800         tern parentheses), the change applies to the remainder of  the  pattern         tern  parentheses),  the change applies to the remainder of the pattern
3801         that follows.  If the change is placed right at the start of a pattern,         that follows.  If the change is placed right at the start of a pattern,
3802         PCRE extracts it into the global options (and it will therefore show up         PCRE extracts it into the global options (and it will therefore show up
3803         in data extracted by the pcre_fullinfo() function).         in data extracted by the pcre_fullinfo() function).
3804    
3805         An  option  change  within a subpattern (see below for a description of         An option change within a subpattern (see below for  a  description  of
3806         subpatterns) affects only that part of the current pattern that follows         subpatterns) affects only that part of the current pattern that follows
3807         it, so         it, so
3808    
3809           (a(?i)b)c           (a(?i)b)c
3810    
3811         matches abc and aBc and no other strings (assuming PCRE_CASELESS is not         matches abc and aBc and no other strings (assuming PCRE_CASELESS is not
3812         used).  By this means, options can be made to have  different  settings         used).   By  this means, options can be made to have different settings
3813         in  different parts of the pattern. Any changes made in one alternative         in different parts of the pattern. Any changes made in one  alternative
3814         do carry on into subsequent branches within the  same  subpattern.  For         do  carry  on  into subsequent branches within the same subpattern. For
3815         example,         example,
3816    
3817           (a(?i)b|c)           (a(?i)b|c)
3818    
3819         matches  "ab",  "aB",  "c",  and "C", even though when matching "C" the         matches "ab", "aB", "c", and "C", even though  when  matching  "C"  the
3820         first branch is abandoned before the option setting.  This  is  because         first  branch  is  abandoned before the option setting. This is because
3821         the  effects  of option settings happen at compile time. There would be         the effects of option settings happen at compile time. There  would  be
3822         some very weird behaviour otherwise.         some very weird behaviour otherwise.
3823    
3824           Note:  There  are  other  PCRE-specific  options that can be set by the
3825           application when the compile or match functions  are  called.  In  some
3826           cases  the  pattern  can  contain special leading sequences to override
3827           what the application has set or what has been  defaulted.  Details  are
3828           given in the section entitled "Newline sequences" above.
3829    
3830    
3831  SUBPATTERNS  SUBPATTERNS
3832    
# Line 3731  SUBPATTERNS Line 3837  SUBPATTERNS
3837    
3838           cat(aract|erpillar|)           cat(aract|erpillar|)
3839    
3840         matches  one  of the words "cat", "cataract", or "caterpillar". Without         matches one of the words "cat", "cataract", or  "caterpillar".  Without
3841         the parentheses, it would match  "cataract",  "erpillar"  or  an  empty         the  parentheses,  it  would  match  "cataract", "erpillar" or an empty
3842         string.         string.
3843    
3844         2.  It  sets  up  the  subpattern as a capturing subpattern. This means         2. It sets up the subpattern as  a  capturing  subpattern.  This  means
3845         that, when the whole pattern  matches,  that  portion  of  the  subject         that,  when  the  whole  pattern  matches,  that portion of the subject
3846         string that matched the subpattern is passed back to the caller via the         string that matched the subpattern is passed back to the caller via the
3847         ovector argument of pcre_exec(). Opening parentheses are  counted  from         ovector  argument  of pcre_exec(). Opening parentheses are counted from
3848         left  to  right  (starting  from 1) to obtain numbers for the capturing         left to right (starting from 1) to obtain  numbers  for  the  capturing
3849         subpatterns.         subpatterns.
3850    
3851         For example, if the string "the red king" is matched against  the  pat-         For  example,  if the string "the red king" is matched against the pat-
3852         tern         tern
3853    
3854           the ((red|white) (king|queen))           the ((red|white) (king|queen))
# Line 3750  SUBPATTERNS Line 3856  SUBPATTERNS
3856         the captured substrings are "red king", "red", and "king", and are num-         the captured substrings are "red king", "red", and "king", and are num-
3857         bered 1, 2, and 3, respectively.         bered 1, 2, and 3, respectively.
3858    
3859         The fact that plain parentheses fulfil  two  functions  is  not  always         The  fact  that  plain  parentheses  fulfil two functions is not always
3860         helpful.   There are often times when a grouping subpattern is required         helpful.  There are often times when a grouping subpattern is  required
3861         without a capturing requirement. If an opening parenthesis is  followed         without  a capturing requirement. If an opening parenthesis is followed
3862         by  a question mark and a colon, the subpattern does not do any captur-         by a question mark and a colon, the subpattern does not do any  captur-
3863         ing, and is not counted when computing the  number  of  any  subsequent         ing,  and  is  not  counted when computing the number of any subsequent
3864         capturing  subpatterns. For example, if the string "the white queen" is         capturing subpatterns. For example, if the string "the white queen"  is
3865         matched against the pattern         matched against the pattern
3866    
3867           the ((?:red|white) (king|queen))           the ((?:red|white) (king|queen))
# Line 3763  SUBPATTERNS Line 3869  SUBPATTERNS
3869         the captured substrings are "white queen" and "queen", and are numbered         the captured substrings are "white queen" and "queen", and are numbered
3870         1 and 2. The maximum number of capturing subpatterns is 65535.         1 and 2. The maximum number of capturing subpatterns is 65535.
3871    
3872         As  a  convenient shorthand, if any option settings are required at the         As a convenient shorthand, if any option settings are required  at  the
3873         start of a non-capturing subpattern,  the  option  letters  may  appear         start  of  a  non-capturing  subpattern,  the option letters may appear
3874         between the "?" and the ":". Thus the two patterns         between the "?" and the ":". Thus the two patterns
3875    
3876           (?i:saturday|sunday)           (?i:saturday|sunday)
3877           (?:(?i)saturday|sunday)           (?:(?i)saturday|sunday)
3878    
3879         match exactly the same set of strings. Because alternative branches are         match exactly the same set of strings. Because alternative branches are
3880         tried from left to right, and options are not reset until  the  end  of         tried  from  left  to right, and options are not reset until the end of
3881         the  subpattern is reached, an option setting in one branch does affect         the subpattern is reached, an option setting in one branch does  affect
3882         subsequent branches, so the above patterns match "SUNDAY"  as  well  as         subsequent  branches,  so  the above patterns match "SUNDAY" as well as
3883         "Saturday".         "Saturday".
3884    
3885    
3886  DUPLICATE SUBPATTERN NUMBERS  DUPLICATE SUBPATTERN NUMBERS
3887    
3888         Perl 5.10 introduced a feature whereby each alternative in a subpattern         Perl 5.10 introduced a feature whereby each alternative in a subpattern
3889         uses the same numbers for its capturing parentheses. Such a  subpattern         uses  the same numbers for its capturing parentheses. Such a subpattern
3890         starts  with (?| and is itself a non-capturing subpattern. For example,         starts with (?| and is itself a non-capturing subpattern. For  example,
3891         consider this pattern:         consider this pattern:
3892    
3893           (?|(Sat)ur|(Sun))day           (?|(Sat)ur|(Sun))day
3894    
3895         Because the two alternatives are inside a (?| group, both sets of  cap-         Because  the two alternatives are inside a (?| group, both sets of cap-
3896         turing  parentheses  are  numbered one. Thus, when the pattern matches,         turing parentheses are numbered one. Thus, when  the  pattern  matches,
3897         you can look at captured substring number  one,  whichever  alternative         you  can  look  at captured substring number one, whichever alternative
3898         matched.  This  construct  is useful when you want to capture part, but         matched. This construct is useful when you want to  capture  part,  but
3899         not all, of one of a number of alternatives. Inside a (?| group, paren-         not all, of one of a number of alternatives. Inside a (?| group, paren-
3900         theses  are  numbered as usual, but the number is reset at the start of         theses are numbered as usual, but the number is reset at the  start  of
3901         each branch. The numbers of any capturing buffers that follow the  sub-         each  branch. The numbers of any capturing buffers that follow the sub-
3902         pattern  start after the highest number used in any branch. The follow-         pattern start after the highest number used in any branch. The  follow-
3903         ing example is taken from the Perl documentation.  The  numbers  under-         ing  example  is taken from the Perl documentation.  The numbers under-
3904         neath show in which buffer the captured content will be stored.         neath show in which buffer the captured content will be stored.
3905    
3906           # before  ---------------branch-reset----------- after           # before  ---------------branch-reset----------- after
3907           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
3908           # 1            2         2  3        2     3     4           # 1            2         2  3        2     3     4
3909    
3910         A  backreference  or  a  recursive call to a numbered subpattern always         A backreference or a recursive call to  a  numbered  subpattern  always
3911         refers to the first one in the pattern with the given number.         refers to the first one in the pattern with the given number.
3912    
3913         An alternative approach to using this "branch reset" feature is to  use         An  alternative approach to using this "branch reset" feature is to use
3914         duplicate named subpatterns, as described in the next section.         duplicate named subpatterns, as described in the next section.
3915    
3916    
3917  NAMED SUBPATTERNS  NAMED SUBPATTERNS
3918    
3919         Identifying  capturing  parentheses  by number is simple, but it can be         Identifying capturing parentheses by number is simple, but  it  can  be
3920         very hard to keep track of the numbers in complicated  regular  expres-         very  hard  to keep track of the numbers in complicated regular expres-
3921         sions.  Furthermore,  if  an  expression  is  modified, the numbers may         sions. Furthermore, if an  expression  is  modified,  the  numbers  may
3922         change. To help with this difficulty, PCRE supports the naming of  sub-         change.  To help with this difficulty, PCRE supports the naming of sub-
3923         patterns. This feature was not added to Perl until release 5.10. Python         patterns. This feature was not added to Perl until release 5.10. Python
3924         had the feature earlier, and PCRE introduced it at release  4.0,  using         had  the  feature earlier, and PCRE introduced it at release 4.0, using
3925         the  Python syntax. PCRE now supports both the Perl and the Python syn-         the Python syntax. PCRE now supports both the Perl and the Python  syn-
3926         tax.         tax.
3927    
3928         In PCRE, a subpattern can be named in one of three  ways:  (?<name>...)         In  PCRE,  a subpattern can be named in one of three ways: (?<name>...)
3929         or  (?'name'...)  as in Perl, or (?P<name>...) as in Python. References         or (?'name'...) as in Perl, or (?P<name>...) as in  Python.  References
3930         to capturing parentheses from other parts of the pattern, such as back-         to capturing parentheses from other parts of the pattern, such as back-
3931         references,  recursion,  and conditions, can be made by name as well as         references, recursion, and conditions, can be made by name as  well  as
3932         by number.         by number.
3933    
3934         Names consist of up to  32  alphanumeric  characters  and  underscores.         Names  consist  of  up  to  32 alphanumeric characters and underscores.
3935         Named  capturing  parentheses  are  still  allocated numbers as well as         Named capturing parentheses are still  allocated  numbers  as  well  as
3936         names, exactly as if the names were not present. The PCRE API  provides         names,  exactly as if the names were not present. The PCRE API provides
3937         function calls for extracting the name-to-number translation table from         function calls for extracting the name-to-number translation table from
3938         a compiled pattern. There is also a convenience function for extracting         a compiled pattern. There is also a convenience function for extracting
3939         a captured substring by name.         a captured substring by name.
3940    
3941         By  default, a name must be unique within a pattern, but it is possible         By default, a name must be unique within a pattern, but it is  possible
3942         to relax this constraint by setting the PCRE_DUPNAMES option at compile         to relax this constraint by setting the PCRE_DUPNAMES option at compile
3943         time.  This  can  be useful for patterns where only one instance of the         time. This can be useful for patterns where only one  instance  of  the
3944         named parentheses can match. Suppose you want to match the  name  of  a         named  parentheses  can  match. Suppose you want to match the name of a
3945         weekday,  either as a 3-letter abbreviation or as the full name, and in         weekday, either as a 3-letter abbreviation or as the full name, and  in
3946         both cases you want to extract the abbreviation. This pattern (ignoring         both cases you want to extract the abbreviation. This pattern (ignoring
3947         the line breaks) does the job:         the line breaks) does the job:
3948    
# Line 3846  NAMED SUBPATTERNS Line 3952  NAMED SUBPATTERNS
3952           (?<DN>Thu)(?:rsday)?|           (?<DN>Thu)(?:rsday)?|
3953           (?<DN>Sat)(?:urday)?           (?<DN>Sat)(?:urday)?
3954    
3955         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
3956         match.  (An alternative way of solving this problem is to use a "branch         match.  (An alternative way of solving this problem is to use a "branch
3957         reset" subpattern, as described in the previous section.)         reset" subpattern, as described in the previous section.)
3958    
3959         The  convenience  function  for extracting the data by name returns the         The convenience function for extracting the data by  name  returns  the
3960         substring for the first (and in this example, the only)  subpattern  of         substring  for  the first (and in this example, the only) subpattern of
3961         that  name  that  matched.  This saves searching to find which numbered         that name that matched. This saves searching  to  find  which  numbered
3962         subpattern it was. If you make a reference to a non-unique  named  sub-         subpattern  it  was. If you make a reference to a non-unique named sub-
3963         pattern  from elsewhere in the pattern, the one that corresponds to the         pattern from elsewhere in the pattern, the one that corresponds to  the
3964         lowest number is used. For further details of the interfaces  for  han-         lowest  number  is used. For further details of the interfaces for han-
3965         dling named subpatterns, see the pcreapi documentation.         dling named subpatterns, see the pcreapi documentation.
3966    
3967    
3968  REPETITION  REPETITION
3969    
3970         Repetition  is  specified  by  quantifiers, which can follow any of the         Repetition is specified by quantifiers, which can  follow  any  of  the
3971         following items:         following items:
3972    
3973           a literal data character           a literal data character
# Line 3874  REPETITION Line 3980  REPETITION
3980           a back reference (see next section)           a back reference (see next section)
3981           a parenthesized subpattern (unless it is an assertion)           a parenthesized subpattern (unless it is an assertion)
3982    
3983         The general repetition quantifier specifies a minimum and maximum  num-         The  general repetition quantifier specifies a minimum and maximum num-
3984         ber  of  permitted matches, by giving the two numbers in curly brackets         ber of permitted matches, by giving the two numbers in  curly  brackets
3985         (braces), separated by a comma. The numbers must be  less  than  65536,         (braces),  separated  by  a comma. The numbers must be less than 65536,
3986         and the first must be less than or equal to the second. For example:         and the first must be less than or equal to the second. For example:
3987    
3988           z{2,4}           z{2,4}
3989    
3990         matches  "zz",  "zzz",  or  "zzzz". A closing brace on its own is not a         matches "zz", "zzz", or "zzzz". A closing brace on its  own  is  not  a
3991         special character. If the second number is omitted, but  the  comma  is         special  character.  If  the second number is omitted, but the comma is
3992         present,  there  is  no upper limit; if the second number and the comma         present, there is no upper limit; if the second number  and  the  comma
3993         are both omitted, the quantifier specifies an exact number of  required         are  both omitted, the quantifier specifies an exact number of required
3994         matches. Thus         matches. Thus
3995    
3996           [aeiou]{3,}           [aeiou]{3,}
# Line 3893  REPETITION Line 3999  REPETITION
3999    
4000           \d{8}           \d{8}
4001    
4002         matches  exactly  8  digits. An opening curly bracket that appears in a         matches exactly 8 digits. An opening curly bracket that  appears  in  a
4003         position where a quantifier is not allowed, or one that does not  match         position  where a quantifier is not allowed, or one that does not match
4004         the  syntax of a quantifier, is taken as a literal character. For exam-         the syntax of a quantifier, is taken as a literal character. For  exam-
4005         ple, {,6} is not a quantifier, but a literal string of four characters.         ple, {,6} is not a quantifier, but a literal string of four characters.
4006    
4007         In  UTF-8  mode,  quantifiers  apply to UTF-8 characters rather than to         In UTF-8 mode, quantifiers apply to UTF-8  characters  rather  than  to
4008         individual bytes. Thus, for example, \x{100}{2} matches two UTF-8 char-         individual bytes. Thus, for example, \x{100}{2} matches two UTF-8 char-
4009         acters, each of which is represented by a two-byte sequence. Similarly,         acters, each of which is represented by a two-byte sequence. Similarly,
4010         when Unicode property support is available, \X{3} matches three Unicode         when Unicode property support is available, \X{3} matches three Unicode
4011         extended  sequences,  each of which may be several bytes long (and they         extended sequences, each of which may be several bytes long  (and  they
4012         may be of different lengths).         may be of different lengths).
4013    
4014         The quantifier {0} is permitted, causing the expression to behave as if         The quantifier {0} is permitted, causing the expression to behave as if
4015         the previous item and the quantifier were not present.         the previous item and the quantifier were not present. This may be use-
4016           ful  for  subpatterns that are referenced as subroutines from elsewhere
4017           in the pattern. Items other than subpatterns that have a {0} quantifier
4018           are omitted from the compiled pattern.
4019    
4020         For  convenience, the three most common quantifiers have single-charac-         For  convenience, the three most common quantifiers have single-charac-
4021         ter abbreviations:         ter abbreviations:
# Line 4684  SUBPATTERNS AS SUBROUTINES Line 4793  SUBPATTERNS AS SUBROUTINES
4793         processing option does not affect the called subpattern.         processing option does not affect the called subpattern.
4794    
4795    
4796    ONIGURUMA SUBROUTINE SYNTAX
4797    
4798           For compatibility with Oniguruma, the non-Perl syntax \g followed by  a
4799           name or a number enclosed either in angle brackets or single quotes, is
4800           an alternative syntax for referencing a  subpattern  as  a  subroutine,
4801           possibly  recursively. Here are two of the examples used above, rewrit-
4802           ten using this syntax:
4803    
4804             (?<pn> \( ( (?>[^()]+) | \g<pn> )* \) )
4805             (sens|respons)e and \g'1'ibility
4806    
4807           PCRE supports an extension to Oniguruma: if a number is preceded  by  a
4808           plus or a minus sign it is taken as a relative reference. For example:
4809    
4810             (abc)(?i:\g<-1>)
4811    
4812           Note  that \g{...} (Perl syntax) and \g<...> (Oniguruma syntax) are not
4813           synonymous. The former is a back reference; the latter is a  subroutine
4814           call.
4815    
4816    
4817  CALLOUTS  CALLOUTS
4818    
4819         Perl has a feature whereby using the sequence (?{...}) causes arbitrary         Perl has a feature whereby using the sequence (?{...}) causes arbitrary
4820         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.
4821         This makes it possible, amongst other things, to extract different sub-         This makes it possible, amongst other things, to extract different sub-
4822         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-
4823         tion.         tion.
4824    
4825         PCRE provides a similar feature, but of course it cannot obey arbitrary         PCRE provides a similar feature, but of course it cannot obey arbitrary
4826         Perl code. The feature is called "callout". The caller of PCRE provides         Perl code. The feature is called "callout". The caller of PCRE provides
4827         an external function by putting its entry point in the global  variable         an  external function by putting its entry point in the global variable
4828         pcre_callout.   By default, this variable contains NULL, which disables         pcre_callout.  By default, this variable contains NULL, which  disables
4829         all calling out.         all calling out.
4830    
4831         Within a regular expression, (?C) indicates the  points  at  which  the         Within  a  regular  expression,  (?C) indicates the points at which the
4832         external  function  is  to be called. If you want to identify different         external function is to be called. If you want  to  identify  different
4833         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.
4834         The  default  value is zero.  For example, this pattern has two callout         The default value is zero.  For example, this pattern has  two  callout
4835         points:         points:
4836    
4837           (?C1)abc(?C2)def           (?C1)abc(?C2)def
4838    
4839         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
4840         automatically  installed  before each item in the pattern. They are all         automatically installed before each item in the pattern. They  are  all
4841         numbered 255.         numbered 255.
4842    
4843         During matching, when PCRE reaches a callout point (and pcre_callout is         During matching, when PCRE reaches a callout point (and pcre_callout is
4844         set),  the  external function is called. It is provided with the number         set), the external function is called. It is provided with  the  number
4845         of the callout, the position in the pattern, and, optionally, one  item         of  the callout, the position in the pattern, and, optionally, one item
4846         of  data  originally supplied by the caller of pcre_exec(). The callout         of data originally supplied by the caller of pcre_exec().  The  callout
4847         function may cause matching to proceed, to backtrack, or to fail  alto-         function  may cause matching to proceed, to backtrack, or to fail alto-
4848         gether. A complete description of the interface to the callout function         gether. A complete description of the interface to the callout function
4849         is given in the pcrecallout documentation.         is given in the pcrecallout documentation.
4850    
4851    
4852  BACKTRACKING CONTROL  BACKTRACKING CONTROL
4853    
4854         Perl 5.10 introduced a number of "Special Backtracking Control  Verbs",         Perl  5.10 introduced a number of "Special Backtracking Control Verbs",
4855         which are described in the Perl documentation as "experimental and sub-         which are described in the Perl documentation as "experimental and sub-
4856         ject to change or removal in a future version of Perl". It goes  on  to         ject  to  change or removal in a future version of Perl". It goes on to
4857         say:  "Their usage in production code should be noted to avoid problems         say: "Their usage in production code should be noted to avoid  problems
4858         during upgrades." The same remarks apply to the PCRE features described         during upgrades." The same remarks apply to the PCRE features described
4859         in this section.         in this section.
4860    
4861         Since these verbs are specifically related to backtracking, they can be         Since these verbs are specifically related  to  backtracking,  most  of
4862         used only when the pattern is to be matched  using  pcre_exec(),  which         them  can  be  used  only  when  the  pattern  is  to  be matched using
4863         uses  a  backtracking  algorithm. They cause an error if encountered by         pcre_exec(), which uses a backtracking algorithm. With the exception of
4864         pcre_dfa_exec().         (*FAIL), which behaves like a failing negative assertion, they cause an
4865           error if encountered by pcre_dfa_exec().
4866    
4867         The new verbs make use of what was previously invalid syntax: an  open-         The new verbs make use of what was previously invalid syntax: an  open-
4868         ing parenthesis followed by an asterisk. In Perl, they are generally of         ing parenthesis followed by an asterisk. In Perl, they are generally of
# Line 4850  AUTHOR Line 4981  AUTHOR
4981    
4982  REVISION  REVISION
4983    
4984         Last updated: 11 September 2007         Last updated: 19 April 2008
4985         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
4986  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
4987    
4988    
# Line 4979  CHARACTER CLASSES Line 5110  CHARACTER CLASSES
5110           [^...]      negative character class           [^...]      negative character class
5111           [x-y]       range (can be used for hex characters)           [x-y]       range (can be used for hex characters)
5112           [[:xxx:]]   positive POSIX named set           [[:xxx:]]   positive POSIX named set
5113           [[^:xxx:]]  negative POSIX named set           [[:^xxx:]]  negative POSIX named set
5114    
5115           alnum       alphanumeric           alnum       alphanumeric
5116           alpha       alphabetic           alpha       alphabetic
# Line 5109  SUBROUTINE REFERENCES (POSSIBLY RECURSIV Line 5240  SUBROUTINE REFERENCES (POSSIBLY RECURSIV
5240           (?-n)          call subpattern by relative number           (?-n)          call subpattern by relative number
5241           (?&name)       call subpattern by name (Perl)           (?&name)       call subpattern by name (Perl)
5242           (?P>name)      call subpattern by name (Python)           (?P>name)      call subpattern by name (Python)
5243             \g<name>       call subpattern by name (Oniguruma)
5244             \g'name'       call subpattern by name (Oniguruma)
5245             \g<n>          call subpattern by absolute number (Oniguruma)
5246             \g'n'          call subpattern by absolute number (Oniguruma)
5247             \g<+n>         call subpattern by relative number (PCRE extension)
5248             \g'+n'         call subpattern by relative number (PCRE extension)
5249             \g<-n>         call subpattern by relative number (PCRE extension)
5250             \g'-n'         call subpattern by relative number (PCRE extension)
5251    
5252    
5253  CONDITIONAL PATTERNS  CONDITIONAL PATTERNS
# Line 5149  BACKTRACKING CONTROL Line 5288  BACKTRACKING CONTROL
5288    
5289  NEWLINE CONVENTIONS  NEWLINE CONVENTIONS
5290    
5291         These are recognized only at the very start of a pattern.         These  are  recognized only at the very start of the pattern or after a
5292           (*BSR_...) option.
5293    
5294           (*CR)           (*CR)
5295           (*LF)           (*LF)
# Line 5160  NEWLINE CONVENTIONS Line 5300  NEWLINE CONVENTIONS
5300    
5301  WHAT \R MATCHES  WHAT \R MATCHES
5302    
5303         These are recognized only at the very start of a pattern.         These are recognized only at the very start of the pattern or  after  a
5304           (*...) option that sets the newline convention.
5305    
5306           (*BSR_ANYCRLF)           (*BSR_ANYCRLF)
5307           (*BSR_UNICODE)           (*BSR_UNICODE)
# Line 5186  AUTHOR Line 5327  AUTHOR
5327    
5328  REVISION  REVISION
5329    
5330         Last updated: 11 September 2007         Last updated: 09 April 2008
5331         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
5332  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
5333    
5334    
# Line 5842  MATCHING NEWLINE CHARACTERS Line 5983  MATCHING NEWLINE CHARACTERS
5983  MATCHING A PATTERN  MATCHING A PATTERN
5984    
5985         The  function  regexec()  is  called  to  match a compiled pattern preg         The  function  regexec()  is  called  to  match a compiled pattern preg
5986         against a given string, which is terminated by a zero byte, subject  to         against a given string, which is by default terminated by a  zero  byte
5987         the options in eflags. These can be:         (but  see  REG_STARTEND below), subject to the options in eflags. These
5988           can be:
5989    
5990           REG_NOTBOL           REG_NOTBOL
5991    
# Line 5855  MATCHING A PATTERN Line 5997  MATCHING A PATTERN
5997         The PCRE_NOTEOL option is set when calling the underlying PCRE matching         The PCRE_NOTEOL option is set when calling the underlying PCRE matching
5998         function.         function.
5999    
6000             REG_STARTEND
6001    
6002           The string is considered to start at string +  pmatch[0].rm_so  and  to
6003           have  a terminating NUL located at string + pmatch[0].rm_eo (there need
6004           not actually be a NUL at that location), regardless  of  the  value  of
6005           nmatch.  This  is a BSD extension, compatible with but not specified by
6006           IEEE Standard 1003.2 (POSIX.2), and should  be  used  with  caution  in
6007           software intended to be portable to other systems. Note that a non-zero
6008           rm_so does not imply REG_NOTBOL; REG_STARTEND affects only the location
6009           of the string, not how it is matched.
6010    
6011         If  the pattern was compiled with the REG_NOSUB flag, no data about any         If  the pattern was compiled with the REG_NOSUB flag, no data about any
6012         matched strings  is  returned.  The  nmatch  and  pmatch  arguments  of         matched strings  is  returned.  The  nmatch  and  pmatch  arguments  of
6013         regexec() are ignored.         regexec() are ignored.
# Line 5901  AUTHOR Line 6054  AUTHOR
6054    
6055  REVISION  REVISION
6056    
6057         Last updated: 06 March 2007         Last updated: 05 April 2008
6058         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
6059  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
6060    
6061    
# Line 5990  MATCHING INTERFACE Line 6143  MATCHING INTERFACE
6143    
6144           c. The "i"th argument has a suitable type for holding the           c. The "i"th argument has a suitable type for holding the
6145              string captured as the "i"th sub-pattern. If you pass in              string captured as the "i"th sub-pattern. If you pass in
6146              NULL for the "i"th argument, or pass fewer arguments than              void * NULL for the "i"th argument, or a non-void * NULL
6147                of the correct type, or pass fewer arguments than the
6148              number of sub-patterns, "i"th captured sub-pattern is              number of sub-patterns, "i"th captured sub-pattern is
6149              ignored.              ignored.
6150    
# Line 6238  AUTHOR Line 6392  AUTHOR
6392    
6393  REVISION  REVISION
6394    
6395         Last updated: 06 March 2007         Last updated: 12 November 2007
6396  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
6397    
6398    
# Line 6266  PCRE SAMPLE PROGRAM Line 6420  PCRE SAMPLE PROGRAM
6420         bility  of  matching an empty string. Comments in the code explain what         bility  of  matching an empty string. Comments in the code explain what
6421         is going on.         is going on.
6422    
6423         The demonstration program is automatically built if you use  "./config-         If PCRE is installed in the standard include  and  library  directories
6424         ure;make"  to  build PCRE. Otherwise, if PCRE is installed in the stan-         for  your  system, you should be able to compile the demonstration pro-
6425         dard include and library directories for your  system,  you  should  be         gram using this command:
        able to compile the demonstration program using this command:  
6426    
6427           gcc -o pcredemo pcredemo.c -lpcre           gcc -o pcredemo pcredemo.c -lpcre
6428    
6429         If  PCRE is installed elsewhere, you may need to add additional options         If PCRE is installed elsewhere, you may need to add additional  options
6430         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
6431         installed  in  /usr/local,  you  can  compile the demonstration program         installed in /usr/local, you  can  compile  the  demonstration  program
6432         using a command like this:         using a command like this:
6433    
6434           gcc -o pcredemo -I/usr/local/include pcredemo.c \           gcc -o pcredemo -I/usr/local/include pcredemo.c \
6435               -L/usr/local/lib -lpcre               -L/usr/local/lib -lpcre
6436    
6437         Once you have compiled the demonstration program, you  can  run  simple         Once  you  have  compiled the demonstration program, you can run simple
6438         tests like this:         tests like this:
6439    
6440           ./pcredemo 'cat|dog' 'the cat sat on the mat'           ./pcredemo 'cat|dog' 'the cat sat on the mat'
6441           ./pcredemo -g 'cat|dog' 'the dog sat on the cat'           ./pcredemo -g 'cat|dog' 'the dog sat on the cat'
6442    
6443         Note  that  there  is  a  much  more comprehensive test program, called         Note that there is a  much  more  comprehensive  test  program,  called
6444         pcretest, which supports  many  more  facilities  for  testing  regular         pcretest,  which  supports  many  more  facilities  for testing regular
6445         expressions and the PCRE library. The pcredemo program is provided as a         expressions and the PCRE library. The pcredemo program is provided as a
6446         simple coding example.         simple coding example.
6447    
# Line 6296  PCRE SAMPLE PROGRAM Line 6449  PCRE SAMPLE PROGRAM
6449         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
6450         try to run pcredemo:         try to run pcredemo:
6451    
6452           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
6453         directory         directory
6454    
6455         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-
6456         tems. You need to add         tems. You need to add
6457    
6458           -R/usr/local/lib           -R/usr/local/lib
# Line 6316  AUTHOR Line 6469  AUTHOR
6469    
6470  REVISION  REVISION
6471    
6472         Last updated: 13 June 2007         Last updated: 23 January 2008
6473         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
6474  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
6475  PCRESTACK(3)                                                      PCRESTACK(3)  PCRESTACK(3)                                                      PCRESTACK(3)
6476    
# Line 6383  PCRE DISCUSSION OF STACK USAGE Line 6536  PCRE DISCUSSION OF STACK USAGE
6536         ing long subject strings is to write repeated parenthesized subpatterns         ing long subject strings is to write repeated parenthesized subpatterns
6537         to match more than one character whenever possible.         to match more than one character whenever possible.
6538    
6539       Compiling PCRE to use heap instead of stack
6540    
6541         In environments where stack memory is constrained, you  might  want  to         In environments where stack memory is constrained, you  might  want  to
6542         compile  PCRE to use heap memory instead of stack for remembering back-         compile  PCRE to use heap memory instead of stack for remembering back-
6543         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
# Line 6395  PCRE DISCUSSION OF STACK USAGE Line 6550  PCRE DISCUSSION OF STACK USAGE
6550         freed in reverse order, it may be possible to implement customized mem-         freed in reverse order, it may be possible to implement customized mem-
6551         ory handlers that are more efficient than the standard functions.         ory handlers that are more efficient than the standard functions.
6552    
6553       Limiting PCRE's stack usage
6554    
6555           PCRE has an internal counter that can be used to  limit  the  depth  of
6556           recursion,  and  thus cause pcre_exec() to give an error code before it
6557           runs out of stack. By default, the limit is very  large,  and  unlikely
6558           ever  to operate. It can be changed when PCRE is built, and it can also
6559           be set when pcre_exec() is called. For details of these interfaces, see
6560           the pcrebuild and pcreapi documentation.
6561    
6562           As a very rough rule of thumb, you should reckon on about 500 bytes per
6563           recursion. Thus, if you want to limit your  stack  usage  to  8Mb,  you
6564           should  set  the  limit at 16000 recursions. A 64Mb stack, on the other
6565           hand, can support around 128000 recursions. The pcretest  test  program
6566           has a command line option (-S) that can be used to increase the size of
6567           its stack.
6568    
6569       Changing stack size in Unix-like systems
6570    
6571         In Unix-like environments, there is not often a problem with the  stack         In Unix-like environments, there is not often a problem with the  stack
6572         unless  very  long  strings  are  involved, though the default limit on         unless  very  long  strings  are  involved, though the default limit on
6573         stack size varies from system to system. Values from 8Mb  to  64Mb  are         stack size varies from system to system. Values from 8Mb  to  64Mb  are
# Line 6415  PCRE DISCUSSION OF STACK USAGE Line 6588  PCRE DISCUSSION OF STACK USAGE
6588         attempts to increase the soft limit to  100Mb  using  setrlimit().  You         attempts to increase the soft limit to  100Mb  using  setrlimit().  You
6589         must do this before calling pcre_exec().         must do this before calling pcre_exec().
6590    
6591         PCRE  has  an  internal  counter that can be used to limit the depth of     Changing stack size in Mac OS X
        recursion, and thus cause pcre_exec() to give an error code  before  it  
        runs  out  of  stack. By default, the limit is very large, and unlikely  
        ever to operate. It can be changed when PCRE is built, and it can  also  
        be set when pcre_exec() is called. For details of these interfaces, see  
        the pcrebuild and pcreapi documentation.  
6592    
6593         As a very rough rule of thumb, you should reckon on about 500 bytes per         Using setrlimit(), as described above, should also work on Mac OS X. It
6594         recursion.  Thus,  if  you  want  to limit your stack usage to 8Mb, you         is also possible to set a stack size when linking a program. There is a
6595         should set the limit at 16000 recursions. A 64Mb stack,  on  the  other         discussion   about   stack  sizes  in  Mac  OS  X  at  this  web  site:
6596         hand,  can  support around 128000 recursions. The pcretest test program         http://developer.apple.com/qa/qa2005/qa1419.html.
        has a command line option (-S) that can be used to increase the size of  
        its stack.  
6597    
6598    
6599  AUTHOR  AUTHOR
# Line 6439  AUTHOR Line 6605  AUTHOR
6605    
6606  REVISION  REVISION
6607    
6608         Last updated: 05 June 2007         Last updated: 09 July 2008
6609         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
6610  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
6611    
6612    

Legend:
Removed from v.243  
changed lines
  Added in v.358

  ViewVC Help
Powered by ViewVC 1.1.5