/[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 211 by ph10, Thu Aug 9 09:52:43 2007 UTC revision 313 by ph10, Wed Jan 23 18:05:06 2008 UTC
# Line 271  NAME Line 271  NAME
271  PCRE BUILD-TIME OPTIONS  PCRE BUILD-TIME OPTIONS
272    
273         This  document  describes  the  optional  features  of PCRE that can be         This  document  describes  the  optional  features  of PCRE that can be
274         selected when the library is compiled. They are all selected, or  dese-         selected when the library is compiled. It assumes use of the  configure
275         lected, by providing options to the configure script that is run before         script,  where the optional features are selected or deselected by pro-
276         the make command. The complete list of  options  for  configure  (which         viding options to configure before running the make  command.  However,
277         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
278         directory) can be obtained by running         environments using the GUI facility of  CMakeSetup  if  you  are  using
279           CMake instead of configure to build PCRE.
280    
281           The complete list of options for configure (which includes the standard
282           ones such as the  selection  of  the  installation  directory)  can  be
283           obtained by running
284    
285           ./configure --help           ./configure --help
286    
287         The following sections include  descriptions  of  options  whose  names         The  following  sections  include  descriptions  of options whose names
288         begin with --enable or --disable. These settings specify changes to the         begin with --enable or --disable. These settings specify changes to the
289         defaults for the configure command. Because of the way  that  configure         defaults  for  the configure command. Because of the way that configure
290         works,  --enable  and --disable always come in pairs, so the complemen-         works, --enable and --disable always come in pairs, so  the  complemen-
291         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
292         is not described.         is not described.
293    
294    
# Line 304  UTF-8 SUPPORT Line 309  UTF-8 SUPPORT
309    
310           --enable-utf8           --enable-utf8
311    
312         to  the  configure  command.  Of  itself, this does not make PCRE treat         to the configure command. Of itself, this  does  not  make  PCRE  treat
313         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
314         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()
315         function.         function.
316    
317    
318  UNICODE CHARACTER PROPERTY SUPPORT  UNICODE CHARACTER PROPERTY SUPPORT
319    
320         UTF-8 support allows PCRE to process character values greater than  255         UTF-8  support allows PCRE to process character values greater than 255
321         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-
322         vide any facilities for accessing the properties of such characters. If         vide any facilities for accessing the properties of such characters. If
323         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
324         refer to Unicode character properties, you must add         refer to Unicode character properties, you must add
325    
326           --enable-unicode-properties           --enable-unicode-properties
327    
328         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
329         not explicitly requested it.         not explicitly requested it.
330    
331         Including  Unicode  property  support  adds around 30K of tables to the         Including Unicode property support adds around 30K  of  tables  to  the
332         PCRE library. Only the general category properties such as  Lu  and  Nd         PCRE  library.  Only  the general category properties such as Lu and Nd
333         are supported. Details are given in the pcrepattern documentation.         are supported. Details are given in the pcrepattern documentation.
334    
335    
336  CODE VALUE OF NEWLINE  CODE VALUE OF NEWLINE
337    
338         By  default,  PCRE interprets character 10 (linefeed, LF) as indicating         By default, PCRE interprets character 10 (linefeed, LF)  as  indicating
339         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
340         systems. You can compile PCRE to use character 13 (carriage return, CR)         systems. You can compile PCRE to use character 13 (carriage return, CR)
341         instead, by adding         instead, by adding
342    
343           --enable-newline-is-cr           --enable-newline-is-cr
344    
345         to the  configure  command.  There  is  also  a  --enable-newline-is-lf         to  the  configure  command.  There  is  also  a --enable-newline-is-lf
346         option, which explicitly specifies linefeed as the newline character.         option, which explicitly specifies linefeed as the newline character.
347    
348         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 354  CODE VALUE OF NEWLINE
354    
355           --enable-newline-is-anycrlf           --enable-newline-is-anycrlf
356    
357         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
358         CRLF as indicating a line ending. Finally, a fifth option, specified by         CRLF as indicating a line ending. Finally, a fifth option, specified by
359    
360           --enable-newline-is-any           --enable-newline-is-any
361    
362         causes PCRE to recognize any Unicode newline sequence.         causes PCRE to recognize any Unicode newline sequence.
363    
364         Whatever line ending convention is selected when PCRE is built  can  be         Whatever  line  ending convention is selected when PCRE is built can be
365         overridden  when  the library functions are called. At build time it is         overridden when the library functions are called. At build time  it  is
366         conventional to use the standard for your operating system.         conventional to use the standard for your operating system.
367    
368    
369    WHAT \R MATCHES
370    
371           By  default,  the  sequence \R in a pattern matches any Unicode newline
372           sequence, whatever has been selected as the line  ending  sequence.  If
373           you specify
374    
375             --enable-bsr-anycrlf
376    
377           the  default  is changed so that \R matches only CR, LF, or CRLF. What-
378           ever is selected when PCRE is built can be overridden when the  library
379           functions are called.
380    
381    
382  BUILDING SHARED AND STATIC LIBRARIES  BUILDING SHARED AND STATIC LIBRARIES
383    
384         The PCRE building process uses libtool to build both shared and  static         The  PCRE building process uses libtool to build both shared and static
385         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
386         of         of
387    
388           --disable-shared           --disable-shared
# Line 376  BUILDING SHARED AND STATIC LIBRARIES Line 394  BUILDING SHARED AND STATIC LIBRARIES
394  POSIX MALLOC USAGE  POSIX MALLOC USAGE
395    
396         When PCRE is called through the POSIX interface (see the pcreposix doc-         When PCRE is called through the POSIX interface (see the pcreposix doc-
397         umentation),  additional  working  storage  is required for holding the         umentation), additional working storage is  required  for  holding  the
398         pointers to capturing substrings, because PCRE requires three  integers         pointers  to capturing substrings, because PCRE requires three integers
399         per  substring,  whereas  the POSIX interface provides only two. If the         per substring, whereas the POSIX interface provides only  two.  If  the
400         number of expected substrings is small, the wrapper function uses space         number of expected substrings is small, the wrapper function uses space
401         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.
402         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 391  POSIX MALLOC USAGE Line 409  POSIX MALLOC USAGE
409    
410  HANDLING VERY LARGE PATTERNS  HANDLING VERY LARGE PATTERNS
411    
412         Within  a  compiled  pattern,  offset values are used to point from one         Within a compiled pattern, offset values are used  to  point  from  one
413         part to another (for example, from an opening parenthesis to an  alter-         part  to another (for example, from an opening parenthesis to an alter-
414         nation  metacharacter).  By default, two-byte values are used for these         nation metacharacter). By default, two-byte values are used  for  these
415         offsets, leading to a maximum size for a  compiled  pattern  of  around         offsets,  leading  to  a  maximum size for a compiled pattern of around
416         64K.  This  is sufficient to handle all but the most gigantic patterns.         64K. This is sufficient to handle all but the most  gigantic  patterns.
417         Nevertheless, some people do want to process enormous patterns,  so  it         Nevertheless,  some  people do want to process enormous patterns, so it
418         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
419         adding a setting such as         adding a setting such as
420    
421           --with-link-size=3           --with-link-size=3
422    
423         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
424         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
425         additional bytes when handling them.         additional bytes when handling them.
426    
427    
428  AVOIDING EXCESSIVE STACK USAGE  AVOIDING EXCESSIVE STACK USAGE
429    
430         When matching with the pcre_exec() function, PCRE implements backtrack-         When matching with the pcre_exec() function, PCRE implements backtrack-
431         ing  by  making recursive calls to an internal function called match().         ing by making recursive calls to an internal function  called  match().
432         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-
433         verely  limit  PCRE's operation. (The Unix environment does not usually         verely limit PCRE's operation. (The Unix environment does  not  usually
434         suffer from this problem, but it may sometimes be necessary to increase         suffer from this problem, but it may sometimes be necessary to increase
435         the  maximum  stack size.  There is a discussion in the pcrestack docu-         the maximum stack size.  There is a discussion in the  pcrestack  docu-
436         mentation.) An alternative approach to recursion that uses memory  from         mentation.)  An alternative approach to recursion that uses memory from
437         the  heap  to remember data, instead of using recursive function calls,         the heap to remember data, instead of using recursive  function  calls,
438         has been implemented to work round the problem of limited  stack  size.         has  been  implemented to work round the problem of limited stack size.
439         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
440    
441           --disable-stack-for-recursion           --disable-stack-for-recursion
442    
443         to  the  configure  command. With this configuration, PCRE will use the         to the configure command. With this configuration, PCRE  will  use  the
444         pcre_stack_malloc and pcre_stack_free variables to call memory  manage-         pcre_stack_malloc  and pcre_stack_free variables to call memory manage-
445         ment  functions. By default these point to malloc() and free(), but you         ment functions. By default these point to malloc() and free(), but  you
446         can replace the pointers so that your own functions are used.         can replace the pointers so that your own functions are used.
447    
448         Separate functions are  provided  rather  than  using  pcre_malloc  and         Separate  functions  are  provided  rather  than  using pcre_malloc and
449         pcre_free  because  the  usage  is  very  predictable:  the block sizes         pcre_free because the  usage  is  very  predictable:  the  block  sizes
450         requested are always the same, and  the  blocks  are  always  freed  in         requested  are  always  the  same,  and  the blocks are always freed in
451         reverse  order.  A calling program might be able to implement optimized         reverse order. A calling program might be able to  implement  optimized
452         functions that perform better  than  malloc()  and  free().  PCRE  runs         functions  that  perform  better  than  malloc()  and free(). PCRE runs
453         noticeably more slowly when built in this way. This option affects only         noticeably more slowly when built in this way. This option affects only
454         the  pcre_exec()  function;  it   is   not   relevant   for   the   the         the   pcre_exec()   function;   it   is   not   relevant  for  the  the
455         pcre_dfa_exec() function.         pcre_dfa_exec() function.
456    
457    
458  LIMITING PCRE RESOURCE USAGE  LIMITING PCRE RESOURCE USAGE
459    
460         Internally,  PCRE has a function called match(), which it calls repeat-         Internally, PCRE has a function called match(), which it calls  repeat-
461         edly  (sometimes  recursively)  when  matching  a  pattern   with   the         edly   (sometimes   recursively)  when  matching  a  pattern  with  the
462         pcre_exec()  function.  By controlling the maximum number of times this         pcre_exec() function. By controlling the maximum number of  times  this
463         function may be called during a single matching operation, a limit  can         function  may be called during a single matching operation, a limit can
464         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
465         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-
466         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
467         setting such as         setting such as
468    
469           --with-match-limit=500000           --with-match-limit=500000
470    
471         to  the  configure  command.  This  setting  has  no  effect   on   the         to   the   configure  command.  This  setting  has  no  effect  on  the
472         pcre_dfa_exec() matching function.         pcre_dfa_exec() matching function.
473    
474         In  some  environments  it is desirable to limit the depth of recursive         In some environments it is desirable to limit the  depth  of  recursive
475         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
476         to  restrict  the maximum amount of stack (or heap, if --disable-stack-         to restrict the maximum amount of stack (or heap,  if  --disable-stack-
477         for-recursion is specified) that is used. A second limit controls this;         for-recursion is specified) that is used. A second limit controls this;
478         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
479         imposes no additional constraints. However, you can set a  lower  limit         imposes  no  additional constraints. However, you can set a lower limit
480         by adding, for example,         by adding, for example,
481    
482           --with-match-limit-recursion=10000           --with-match-limit-recursion=10000
483    
484         to  the  configure  command.  This  value can also be overridden at run         to the configure command. This value can  also  be  overridden  at  run
485         time.         time.
486    
487    
488  CREATING CHARACTER TABLES AT BUILD TIME  CREATING CHARACTER TABLES AT BUILD TIME
489    
490         PCRE uses fixed tables for processing characters whose code values  are         PCRE  uses fixed tables for processing characters whose code values are
491         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
492         distributed in the file pcre_chartables.c.dist. These  tables  are  for         distributed  in  the  file pcre_chartables.c.dist. These tables are for
493         ASCII codes only. If you add         ASCII codes only. If you add
494    
495           --enable-rebuild-chartables           --enable-rebuild-chartables
496    
497         to  the  configure  command, the distributed tables are no longer used.         to the configure command, the distributed tables are  no  longer  used.
498         Instead, a program called dftables is compiled and  run.  This  outputs         Instead,  a  program  called dftables is compiled and run. This outputs
499         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
500         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
501         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
502         you need to create alternative tables when cross  compiling,  you  will         you  need  to  create alternative tables when cross compiling, you will
503         have to do so "by hand".)         have to do so "by hand".)
504    
505    
506  USING EBCDIC CODE  USING EBCDIC CODE
507    
508         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
509         character code is ASCII (or Unicode, which is  a  superset  of  ASCII).         character  code  is  ASCII  (or Unicode, which is a superset of ASCII).
510         This  is  the  case for most computer operating systems. PCRE can, how-         This is the case for most computer operating systems.  PCRE  can,  how-
511         ever, be compiled to run in an EBCDIC environment by adding         ever, be compiled to run in an EBCDIC environment by adding
512    
513           --enable-ebcdic           --enable-ebcdic
514    
515         to the configure command. This setting implies --enable-rebuild-charta-         to the configure command. This setting implies --enable-rebuild-charta-
516         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
517         environment (for example, an IBM mainframe operating system).         environment (for example, an IBM mainframe operating system).
518    
519    
520    PCREGREP OPTIONS FOR COMPRESSED FILE SUPPORT
521    
522           By default, pcregrep reads all files as plain text. You can build it so
523           that it recognizes files whose names end in .gz or .bz2, and reads them
524           with libz or libbz2, respectively, by adding one or both of
525    
526             --enable-pcregrep-libz
527             --enable-pcregrep-libbz2
528    
529           to the configure command. These options naturally require that the rel-
530           evant libraries are installed on your system. Configuration  will  fail
531           if they are not.
532    
533    
534    PCRETEST OPTION FOR LIBREADLINE SUPPORT
535    
536           If you add
537    
538             --enable-pcretest-libreadline
539    
540           to  the  configure  command,  pcretest  is  linked with the libreadline
541           library, and when its input is from a terminal, it reads it  using  the
542           readline() function. This provides line-editing and history facilities.
543           Note that libreadline is GPL-licenced, so if you distribute a binary of
544           pcretest linked in this way, there may be licensing issues.
545    
546    
547  SEE ALSO  SEE ALSO
548    
549         pcreapi(3), pcre_config(3).         pcreapi(3), pcre_config(3).
# Line 513  AUTHOR Line 558  AUTHOR
558    
559  REVISION  REVISION
560    
561         Last updated: 30 July 2007         Last updated: 18 December 2007
562         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
563  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
564    
# Line 824  PCRE API OVERVIEW Line 869  PCRE API OVERVIEW
869         a  Perl-compatible  manner. A sample program that demonstrates the sim-         a  Perl-compatible  manner. A sample program that demonstrates the sim-
870         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
871         the  source distribution. The pcresample documentation describes how to         the  source distribution. The pcresample documentation describes how to
872         run it.         compile and run it.
873    
874         A second matching function, pcre_dfa_exec(), which is not Perl-compati-         A second matching function, pcre_dfa_exec(), which is not Perl-compati-
875         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 908  NEWLINES Line 953  NEWLINES
953         dard. When PCRE is run, the default can be overridden,  either  when  a         dard. When PCRE is run, the default can be overridden,  either  when  a
954         pattern is compiled, or when it is matched.         pattern is compiled, or when it is matched.
955    
956           At compile time, the newline convention can be specified by the options
957           argument of pcre_compile(), or it can be specified by special  text  at
958           the start of the pattern itself; this overrides any other settings. See
959           the pcrepattern page for details of the special character sequences.
960    
961         In the PCRE documentation the word "newline" is used to mean "the char-         In the PCRE documentation the word "newline" is used to mean "the char-
962         acter or pair of characters that indicate a line break". The choice  of         acter  or pair of characters that indicate a line break". The choice of
963         newline  convention  affects  the  handling of the dot, circumflex, and         newline convention affects the handling of  the  dot,  circumflex,  and
964         dollar metacharacters, the handling of #-comments in /x mode, and, when         dollar metacharacters, the handling of #-comments in /x mode, and, when
965         CRLF  is a recognized line ending sequence, the match position advance-         CRLF is a recognized line ending sequence, the match position  advance-
966         ment for a non-anchored pattern. The choice of newline convention  does         ment for a non-anchored pattern. There is more detail about this in the
967         not affect the interpretation of the \n or \r escape sequences.         section on pcre_exec() options below.
968    
969           The choice of newline convention does not affect the interpretation  of
970           the  \n  or  \r  escape  sequences, nor does it affect what \R matches,
971           which is controlled in a similar way, but by separate options.
972    
973    
974  MULTITHREADING  MULTITHREADING
975    
976         The  PCRE  functions  can be used in multi-threading applications, with         The PCRE functions can be used in  multi-threading  applications,  with
977         the  proviso  that  the  memory  management  functions  pointed  to  by         the  proviso  that  the  memory  management  functions  pointed  to  by
978         pcre_malloc, pcre_free, pcre_stack_malloc, and pcre_stack_free, and the         pcre_malloc, pcre_free, pcre_stack_malloc, and pcre_stack_free, and the
979         callout function pointed to by pcre_callout, are shared by all threads.         callout function pointed to by pcre_callout, are shared by all threads.
980    
981         The  compiled form of a regular expression is not altered during match-         The compiled form of a regular expression is not altered during  match-
982         ing, so the same compiled pattern can safely be used by several threads         ing, so the same compiled pattern can safely be used by several threads
983         at once.         at once.
984    
# Line 932  MULTITHREADING Line 986  MULTITHREADING
986  SAVING PRECOMPILED PATTERNS FOR LATER USE  SAVING PRECOMPILED PATTERNS FOR LATER USE
987    
988         The compiled form of a regular expression can be saved and re-used at a         The compiled form of a regular expression can be saved and re-used at a
989         later time, possibly by a different program, and even on a  host  other         later  time,  possibly by a different program, and even on a host other
990         than  the  one  on  which  it  was  compiled.  Details are given in the         than the one on which  it  was  compiled.  Details  are  given  in  the
991         pcreprecompile documentation. However, compiling a  regular  expression         pcreprecompile  documentation.  However, compiling a regular expression
992         with  one version of PCRE for use with a different version is not guar-         with one version of PCRE for use with a different version is not  guar-
993         anteed to work and may cause crashes.         anteed to work and may cause crashes.
994    
995    
# Line 943  CHECKING BUILD-TIME OPTIONS Line 997  CHECKING BUILD-TIME OPTIONS
997    
998         int pcre_config(int what, void *where);         int pcre_config(int what, void *where);
999    
1000         The function pcre_config() makes it possible for a PCRE client to  dis-         The  function pcre_config() makes it possible for a PCRE client to dis-
1001         cover which optional features have been compiled into the PCRE library.         cover which optional features have been compiled into the PCRE library.
1002         The pcrebuild documentation has more details about these optional  fea-         The  pcrebuild documentation has more details about these optional fea-
1003         tures.         tures.
1004    
1005         The  first  argument  for pcre_config() is an integer, specifying which         The first argument for pcre_config() is an  integer,  specifying  which
1006         information is required; the second argument is a pointer to a variable         information is required; the second argument is a pointer to a variable
1007         into  which  the  information  is  placed. The following information is         into which the information is  placed.  The  following  information  is
1008         available:         available:
1009    
1010           PCRE_CONFIG_UTF8           PCRE_CONFIG_UTF8
1011    
1012         The output is an integer that is set to one if UTF-8 support is  avail-         The  output is an integer that is set to one if UTF-8 support is avail-
1013         able; otherwise it is set to zero.         able; otherwise it is set to zero.
1014    
1015           PCRE_CONFIG_UNICODE_PROPERTIES           PCRE_CONFIG_UNICODE_PROPERTIES
1016    
1017         The  output  is  an  integer  that is set to one if support for Unicode         The output is an integer that is set to  one  if  support  for  Unicode
1018         character properties is available; otherwise it is set to zero.         character properties is available; otherwise it is set to zero.
1019    
1020           PCRE_CONFIG_NEWLINE           PCRE_CONFIG_NEWLINE
1021    
1022         The output is an integer whose value specifies  the  default  character         The  output  is  an integer whose value specifies the default character
1023         sequence  that is recognized as meaning "newline". The four values that         sequence that is recognized as meaning "newline". The four values  that
1024         are supported are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF,         are supported are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF,
1025         and  -1  for  ANY. The default should normally be the standard sequence         and -1 for ANY. The default should normally be  the  standard  sequence
1026         for your operating system.         for your operating system.
1027    
1028             PCRE_CONFIG_BSR
1029    
1030           The output is an integer whose value indicates what character sequences
1031           the \R escape sequence matches by default. A value of 0 means  that  \R
1032           matches  any  Unicode  line ending sequence; a value of 1 means that \R
1033           matches only CR, LF, or CRLF. The default can be overridden when a pat-
1034           tern is compiled or matched.
1035    
1036           PCRE_CONFIG_LINK_SIZE           PCRE_CONFIG_LINK_SIZE
1037    
1038         The output is an integer that contains the number  of  bytes  used  for         The  output  is  an  integer that contains the number of bytes used for
1039         internal linkage in compiled regular expressions. The value is 2, 3, or         internal linkage in compiled regular expressions. The value is 2, 3, or
1040         4. Larger values allow larger regular expressions to  be  compiled,  at         4.  Larger  values  allow larger regular expressions to be compiled, at
1041         the  expense  of  slower matching. The default value of 2 is sufficient         the expense of slower matching. The default value of  2  is  sufficient
1042         for all but the most massive patterns, since  it  allows  the  compiled         for  all  but  the  most massive patterns, since it allows the compiled
1043         pattern to be up to 64K in size.         pattern to be up to 64K in size.
1044    
1045           PCRE_CONFIG_POSIX_MALLOC_THRESHOLD           PCRE_CONFIG_POSIX_MALLOC_THRESHOLD
1046    
1047         The  output  is  an integer that contains the threshold above which the         The output is an integer that contains the threshold  above  which  the
1048         POSIX interface uses malloc() for output vectors. Further  details  are         POSIX  interface  uses malloc() for output vectors. Further details are
1049         given in the pcreposix documentation.         given in the pcreposix documentation.
1050    
1051           PCRE_CONFIG_MATCH_LIMIT           PCRE_CONFIG_MATCH_LIMIT
1052    
1053         The output is an integer that gives the default limit for the number of         The output is an integer that gives the default limit for the number of
1054         internal matching function calls in a  pcre_exec()  execution.  Further         internal  matching  function  calls in a pcre_exec() execution. Further
1055         details are given with pcre_exec() below.         details are given with pcre_exec() below.
1056    
1057           PCRE_CONFIG_MATCH_LIMIT_RECURSION           PCRE_CONFIG_MATCH_LIMIT_RECURSION
1058    
1059         The  output is an integer that gives the default limit for the depth of         The output is an integer that gives the default limit for the depth  of
1060         recursion when calling the internal matching function in a  pcre_exec()         recursion  when calling the internal matching function in a pcre_exec()
1061         execution. Further details are given with pcre_exec() below.         execution. Further details are given with pcre_exec() below.
1062    
1063           PCRE_CONFIG_STACKRECURSE           PCRE_CONFIG_STACKRECURSE
1064    
1065         The  output is an integer that is set to one if internal recursion when         The output is an integer that is set to one if internal recursion  when
1066         running pcre_exec() is implemented by recursive function calls that use         running pcre_exec() is implemented by recursive function calls that use
1067         the  stack  to remember their state. This is the usual way that PCRE is         the stack to remember their state. This is the usual way that  PCRE  is
1068         compiled. The output is zero if PCRE was compiled to use blocks of data         compiled. The output is zero if PCRE was compiled to use blocks of data
1069         on  the  heap  instead  of  recursive  function  calls.  In  this case,         on the  heap  instead  of  recursive  function  calls.  In  this  case,
1070         pcre_stack_malloc and  pcre_stack_free  are  called  to  manage  memory         pcre_stack_malloc  and  pcre_stack_free  are  called  to  manage memory
1071         blocks on the heap, thus avoiding the use of the stack.         blocks on the heap, thus avoiding the use of the stack.
1072    
1073    
# Line 1022  COMPILING A PATTERN Line 1084  COMPILING A PATTERN
1084    
1085         Either of the functions pcre_compile() or pcre_compile2() can be called         Either of the functions pcre_compile() or pcre_compile2() can be called
1086         to compile a pattern into an internal form. The only difference between         to compile a pattern into an internal form. The only difference between
1087         the  two interfaces is that pcre_compile2() has an additional argument,         the two interfaces is that pcre_compile2() has an additional  argument,
1088         errorcodeptr, via which a numerical error code can be returned.         errorcodeptr, via which a numerical error code can be returned.
1089    
1090         The pattern is a C string terminated by a binary zero, and is passed in         The pattern is a C string terminated by a binary zero, and is passed in
1091         the  pattern  argument.  A  pointer to a single block of memory that is         the pattern argument. A pointer to a single block  of  memory  that  is
1092         obtained via pcre_malloc is returned. This contains the  compiled  code         obtained  via  pcre_malloc is returned. This contains the compiled code
1093         and related data. The pcre type is defined for the returned block; this         and related data. The pcre type is defined for the returned block; this
1094         is a typedef for a structure whose contents are not externally defined.         is a typedef for a structure whose contents are not externally defined.
1095         It is up to the caller to free the memory (via pcre_free) when it is no         It is up to the caller to free the memory (via pcre_free) when it is no
1096         longer required.         longer required.
1097    
1098         Although the compiled code of a PCRE regex is relocatable, that is,  it         Although  the compiled code of a PCRE regex is relocatable, that is, it
1099         does not depend on memory location, the complete pcre data block is not         does not depend on memory location, the complete pcre data block is not
1100         fully relocatable, because it may contain a copy of the tableptr  argu-         fully  relocatable, because it may contain a copy of the tableptr argu-
1101         ment, which is an address (see below).         ment, which is an address (see below).
1102    
1103         The options argument contains various bit settings that affect the com-         The options argument contains various bit settings that affect the com-
1104         pilation. It should be zero if no options are required.  The  available         pilation.  It  should be zero if no options are required. The available
1105         options  are  described  below. Some of them, in particular, those that         options are described below. Some of them, in  particular,  those  that
1106         are compatible with Perl, can also be set and  unset  from  within  the         are  compatible  with  Perl,  can also be set and unset from within the
1107         pattern  (see  the  detailed  description in the pcrepattern documenta-         pattern (see the detailed description  in  the  pcrepattern  documenta-
1108         tion). For these options, the contents of the options  argument  speci-         tion).  For  these options, the contents of the options argument speci-
1109         fies  their initial settings at the start of compilation and execution.         fies their initial settings at the start of compilation and  execution.
1110         The PCRE_ANCHORED and PCRE_NEWLINE_xxx options can be set at  the  time         The  PCRE_ANCHORED  and PCRE_NEWLINE_xxx options can be set at the time
1111         of matching as well as at compile time.         of matching as well as at compile time.
1112    
1113         If errptr is NULL, pcre_compile() returns NULL immediately.  Otherwise,         If errptr is NULL, pcre_compile() returns NULL immediately.  Otherwise,
1114         if compilation of a pattern fails,  pcre_compile()  returns  NULL,  and         if  compilation  of  a  pattern fails, pcre_compile() returns NULL, and
1115         sets the variable pointed to by errptr to point to a textual error mes-         sets the variable pointed to by errptr to point to a textual error mes-
1116         sage. This is a static string that is part of the library. You must not         sage. This is a static string that is part of the library. You must not
1117         try to free it. The offset from the start of the pattern to the charac-         try to free it. The offset from the start of the pattern to the charac-
1118         ter where the error was discovered is placed in the variable pointed to         ter where the error was discovered is placed in the variable pointed to
1119         by  erroffset,  which must not be NULL. If it is, an immediate error is         by erroffset, which must not be NULL. If it is, an immediate  error  is
1120         given.         given.
1121    
1122         If pcre_compile2() is used instead of pcre_compile(),  and  the  error-         If  pcre_compile2()  is  used instead of pcre_compile(), and the error-
1123         codeptr  argument is not NULL, a non-zero error code number is returned         codeptr argument is not NULL, a non-zero error code number is  returned
1124         via this argument in the event of an error. This is in addition to  the         via  this argument in the event of an error. This is in addition to the
1125         textual error message. Error codes and messages are listed below.         textual error message. Error codes and messages are listed below.
1126    
1127         If  the  final  argument, tableptr, is NULL, PCRE uses a default set of         If the final argument, tableptr, is NULL, PCRE uses a  default  set  of
1128         character tables that are  built  when  PCRE  is  compiled,  using  the         character  tables  that  are  built  when  PCRE  is compiled, using the
1129         default  C  locale.  Otherwise, tableptr must be an address that is the         default C locale. Otherwise, tableptr must be an address  that  is  the
1130         result of a call to pcre_maketables(). This value is  stored  with  the         result  of  a  call to pcre_maketables(). This value is stored with the
1131         compiled  pattern,  and used again by pcre_exec(), unless another table         compiled pattern, and used again by pcre_exec(), unless  another  table
1132         pointer is passed to it. For more discussion, see the section on locale         pointer is passed to it. For more discussion, see the section on locale
1133         support below.         support below.
1134    
1135         This  code  fragment  shows a typical straightforward call to pcre_com-         This code fragment shows a typical straightforward  call  to  pcre_com-
1136         pile():         pile():
1137    
1138           pcre *re;           pcre *re;
# Line 1083  COMPILING A PATTERN Line 1145  COMPILING A PATTERN
1145             &erroffset,       /* for error offset */             &erroffset,       /* for error offset */
1146             NULL);            /* use default character tables */             NULL);            /* use default character tables */
1147    
1148         The following names for option bits are defined in  the  pcre.h  header         The  following  names  for option bits are defined in the pcre.h header
1149         file:         file:
1150    
1151           PCRE_ANCHORED           PCRE_ANCHORED
1152    
1153         If this bit is set, the pattern is forced to be "anchored", that is, it         If this bit is set, the pattern is forced to be "anchored", that is, it
1154         is constrained to match only at the first matching point in the  string         is  constrained to match only at the first matching point in the string
1155         that  is being searched (the "subject string"). This effect can also be         that is being searched (the "subject string"). This effect can also  be
1156         achieved by appropriate constructs in the pattern itself, which is  the         achieved  by appropriate constructs in the pattern itself, which is the
1157         only way to do it in Perl.         only way to do it in Perl.
1158    
1159           PCRE_AUTO_CALLOUT           PCRE_AUTO_CALLOUT
1160    
1161         If this bit is set, pcre_compile() automatically inserts callout items,         If this bit is set, pcre_compile() automatically inserts callout items,
1162         all with number 255, before each pattern item. For  discussion  of  the         all  with  number  255, before each pattern item. For discussion of the
1163         callout facility, see the pcrecallout documentation.         callout facility, see the pcrecallout documentation.
1164    
1165             PCRE_BSR_ANYCRLF
1166             PCRE_BSR_UNICODE
1167    
1168           These options (which are mutually exclusive) control what the \R escape
1169           sequence  matches.  The choice is either to match only CR, LF, or CRLF,
1170           or to match any Unicode newline sequence. The default is specified when
1171           PCRE is built. It can be overridden from within the pattern, or by set-
1172           ting an option when a compiled pattern is matched.
1173    
1174           PCRE_CASELESS           PCRE_CASELESS
1175    
1176         If  this  bit is set, letters in the pattern match both upper and lower         If this bit is set, letters in the pattern match both upper  and  lower
1177         case letters. It is equivalent to Perl's  /i  option,  and  it  can  be         case  letters.  It  is  equivalent  to  Perl's /i option, and it can be
1178         changed  within a pattern by a (?i) option setting. In UTF-8 mode, PCRE         changed within a pattern by a (?i) option setting. In UTF-8 mode,  PCRE
1179         always understands the concept of case for characters whose values  are         always  understands the concept of case for characters whose values are
1180         less  than 128, so caseless matching is always possible. For characters         less than 128, so caseless matching is always possible. For  characters
1181         with higher values, the concept of case is supported if  PCRE  is  com-         with  higher  values,  the concept of case is supported if PCRE is com-
1182         piled  with Unicode property support, but not otherwise. If you want to         piled with Unicode property support, but not otherwise. If you want  to
1183         use caseless matching for characters 128 and  above,  you  must  ensure         use  caseless  matching  for  characters 128 and above, you must ensure
1184         that  PCRE  is  compiled  with Unicode property support as well as with         that PCRE is compiled with Unicode property support  as  well  as  with
1185         UTF-8 support.         UTF-8 support.
1186    
1187           PCRE_DOLLAR_ENDONLY           PCRE_DOLLAR_ENDONLY
1188    
1189         If this bit is set, a dollar metacharacter in the pattern matches  only         If  this bit is set, a dollar metacharacter in the pattern matches only
1190         at  the  end  of the subject string. Without this option, a dollar also         at the end of the subject string. Without this option,  a  dollar  also
1191         matches immediately before a newline at the end of the string (but  not         matches  immediately before a newline at the end of the string (but not
1192         before  any  other newlines). The PCRE_DOLLAR_ENDONLY option is ignored         before any other newlines). The PCRE_DOLLAR_ENDONLY option  is  ignored
1193         if PCRE_MULTILINE is set.  There is no equivalent  to  this  option  in         if  PCRE_MULTILINE  is  set.   There is no equivalent to this option in
1194         Perl, and no way to set it within a pattern.         Perl, and no way to set it within a pattern.
1195    
1196           PCRE_DOTALL           PCRE_DOTALL
1197    
1198         If this bit is set, a dot metacharater in the pattern matches all char-         If this bit is set, a dot metacharater in the pattern matches all char-
1199         acters, including those that indicate newline. Without it, a  dot  does         acters,  including  those that indicate newline. Without it, a dot does
1200         not  match  when  the  current position is at a newline. This option is         not match when the current position is at a  newline.  This  option  is
1201         equivalent to Perl's /s option, and it can be changed within a  pattern         equivalent  to Perl's /s option, and it can be changed within a pattern
1202         by  a (?s) option setting. A negative class such as [^a] always matches         by a (?s) option setting. A negative class such as [^a] always  matches
1203         newline characters, independent of the setting of this option.         newline characters, independent of the setting of this option.
1204    
1205           PCRE_DUPNAMES           PCRE_DUPNAMES
1206    
1207         If this bit is set, names used to identify capturing  subpatterns  need         If  this  bit is set, names used to identify capturing subpatterns need
1208         not be unique. This can be helpful for certain types of pattern when it         not be unique. This can be helpful for certain types of pattern when it
1209         is known that only one instance of the named  subpattern  can  ever  be         is  known  that  only  one instance of the named subpattern can ever be
1210         matched.  There  are  more details of named subpatterns below; see also         matched. There are more details of named subpatterns  below;  see  also
1211         the pcrepattern documentation.         the pcrepattern documentation.
1212    
1213           PCRE_EXTENDED           PCRE_EXTENDED
1214    
1215         If this bit is set, whitespace  data  characters  in  the  pattern  are         If  this  bit  is  set,  whitespace  data characters in the pattern are
1216         totally ignored except when escaped or inside a character class. White-         totally ignored except when escaped or inside a character class. White-
1217         space does not include the VT character (code 11). In addition, charac-         space does not include the VT character (code 11). In addition, charac-
1218         ters between an unescaped # outside a character class and the next new-         ters between an unescaped # outside a character class and the next new-
1219         line, inclusive, are also ignored. This  is  equivalent  to  Perl's  /x         line,  inclusive,  are  also  ignored.  This is equivalent to Perl's /x
1220         option,  and  it  can be changed within a pattern by a (?x) option set-         option, and it can be changed within a pattern by a  (?x)  option  set-
1221         ting.         ting.
1222    
1223         This option makes it possible to include  comments  inside  complicated         This  option  makes  it possible to include comments inside complicated
1224         patterns.   Note,  however,  that this applies only to data characters.         patterns.  Note, however, that this applies only  to  data  characters.
1225         Whitespace  characters  may  never  appear  within  special   character         Whitespace   characters  may  never  appear  within  special  character
1226         sequences  in  a  pattern,  for  example  within the sequence (?( which         sequences in a pattern, for  example  within  the  sequence  (?(  which
1227         introduces a conditional subpattern.         introduces a conditional subpattern.
1228    
1229           PCRE_EXTRA           PCRE_EXTRA
1230    
1231         This option was invented in order to turn on  additional  functionality         This  option  was invented in order to turn on additional functionality
1232         of  PCRE  that  is  incompatible with Perl, but it is currently of very         of PCRE that is incompatible with Perl, but it  is  currently  of  very
1233         little use. When set, any backslash in a pattern that is followed by  a         little  use. When set, any backslash in a pattern that is followed by a
1234         letter  that  has  no  special  meaning causes an error, thus reserving         letter that has no special meaning  causes  an  error,  thus  reserving
1235         these combinations for future expansion. By  default,  as  in  Perl,  a         these  combinations  for  future  expansion.  By default, as in Perl, a
1236         backslash  followed by a letter with no special meaning is treated as a         backslash followed by a letter with no special meaning is treated as  a
1237         literal. (Perl can, however, be persuaded to give a warning for  this.)         literal.  (Perl can, however, be persuaded to give a warning for this.)
1238         There  are  at  present no other features controlled by this option. It         There are at present no other features controlled by  this  option.  It
1239         can also be set by a (?X) option setting within a pattern.         can also be set by a (?X) option setting within a pattern.
1240    
1241           PCRE_FIRSTLINE           PCRE_FIRSTLINE
1242    
1243         If this option is set, an  unanchored  pattern  is  required  to  match         If  this  option  is  set,  an  unanchored pattern is required to match
1244         before  or  at  the  first  newline  in  the subject string, though the         before or at the first  newline  in  the  subject  string,  though  the
1245         matched text may continue over the newline.         matched text may continue over the newline.
1246    
1247           PCRE_MULTILINE           PCRE_MULTILINE
1248    
1249         By default, PCRE treats the subject string as consisting  of  a  single         By  default,  PCRE  treats the subject string as consisting of a single
1250         line  of characters (even if it actually contains newlines). The "start         line of characters (even if it actually contains newlines). The  "start
1251         of line" metacharacter (^) matches only at the  start  of  the  string,         of  line"  metacharacter  (^)  matches only at the start of the string,
1252         while  the  "end  of line" metacharacter ($) matches only at the end of         while the "end of line" metacharacter ($) matches only at  the  end  of
1253         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY
1254         is set). This is the same as Perl.         is set). This is the same as Perl.
1255    
1256         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"
1257         constructs match immediately following or immediately  before  internal         constructs  match  immediately following or immediately before internal
1258         newlines  in  the  subject string, respectively, as well as at the very         newlines in the subject string, respectively, as well as  at  the  very
1259         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
1260         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-
1261         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,
1262         setting PCRE_MULTILINE has no effect.         setting PCRE_MULTILINE has no effect.
1263    
1264           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
# Line 1196  COMPILING A PATTERN Line 1267  COMPILING A PATTERN
1267           PCRE_NEWLINE_ANYCRLF           PCRE_NEWLINE_ANYCRLF
1268           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
1269    
1270         These  options  override the default newline definition that was chosen         These options override the default newline definition that  was  chosen
1271         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
1272         newline  is  indicated  by a single character (CR or LF, respectively).         newline is indicated by a single character (CR  or  LF,  respectively).
1273         Setting PCRE_NEWLINE_CRLF specifies that a newline is indicated by  the         Setting  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the
1274         two-character  CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF specifies         two-character CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF  specifies
1275         that any of the three preceding sequences should be recognized. Setting         that any of the three preceding sequences should be recognized. Setting
1276         PCRE_NEWLINE_ANY  specifies that any Unicode newline sequence should be         PCRE_NEWLINE_ANY specifies that any Unicode newline sequence should  be
1277         recognized. The Unicode newline sequences are the three just mentioned,         recognized. The Unicode newline sequences are the three just mentioned,
1278         plus  the  single  characters  VT (vertical tab, U+000B), FF (formfeed,         plus the single characters VT (vertical  tab,  U+000B),  FF  (formfeed,
1279         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
1280         (paragraph  separator,  U+2029).  The  last  two are recognized only in         (paragraph separator, U+2029). The last  two  are  recognized  only  in
1281         UTF-8 mode.         UTF-8 mode.
1282    
1283         The newline setting in the  options  word  uses  three  bits  that  are         The  newline  setting  in  the  options  word  uses three bits that are
1284         treated as a number, giving eight possibilities. Currently only six are         treated as a number, giving eight possibilities. Currently only six are
1285         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
1286         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-
1287         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
1288         PCRE_NEWLINE_CRLF,  but other combinations may yield unused numbers and         PCRE_NEWLINE_CRLF, but other combinations may yield unused numbers  and
1289         cause an error.         cause an error.
1290    
1291         The only time that a line break is specially recognized when  compiling         The  only time that a line break is specially recognized when compiling
1292         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
1293         character class is encountered. This indicates  a  comment  that  lasts         character  class  is  encountered.  This indicates a comment that lasts
1294         until  after the next line break sequence. In other circumstances, line         until after the next line break sequence. In other circumstances,  line
1295         break  sequences  are  treated  as  literal  data,   except   that   in         break   sequences   are   treated  as  literal  data,  except  that  in
1296         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters
1297         and are therefore ignored.         and are therefore ignored.
1298    
1299         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
1300         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.
1301    
1302           PCRE_NO_AUTO_CAPTURE           PCRE_NO_AUTO_CAPTURE
1303    
1304         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-
1305         theses  in the pattern. Any opening parenthesis that is not followed by         theses in the pattern. Any opening parenthesis that is not followed  by
1306         ? behaves as if it were followed by ?: but named parentheses can  still         ?  behaves as if it were followed by ?: but named parentheses can still
1307         be  used  for  capturing  (and  they acquire numbers in the usual way).         be used for capturing (and they acquire  numbers  in  the  usual  way).
1308         There is no equivalent of this option in Perl.         There is no equivalent of this option in Perl.
1309    
1310           PCRE_UNGREEDY           PCRE_UNGREEDY
1311    
1312         This option inverts the "greediness" of the quantifiers  so  that  they         This  option  inverts  the "greediness" of the quantifiers so that they
1313         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
1314         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
1315         within the pattern.         within the pattern.
1316    
1317           PCRE_UTF8           PCRE_UTF8
1318    
1319         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
1320         strings of UTF-8 characters instead of single-byte  character  strings.         strings  of  UTF-8 characters instead of single-byte character strings.
1321         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-
1322         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
1323         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
1324         UTF-8 support in the main pcre page.         UTF-8 support in the main pcre page.
1325    
1326           PCRE_NO_UTF8_CHECK           PCRE_NO_UTF8_CHECK
1327    
1328         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
1329         automatically  checked.  There  is  a  discussion about the validity of         automatically checked. There is a  discussion  about  the  validity  of
1330         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
1331         bytes  is  found,  pcre_compile() returns an error. If you already know         bytes is found, pcre_compile() returns an error. If  you  already  know
1332         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-
1333         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
1334         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
1335         undefined.  It  may  cause your program to crash. Note that this option         undefined. It may cause your program to crash. Note  that  this  option
1336         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
1337         UTF-8 validity checking of subject strings.         UTF-8 validity checking of subject strings.
1338    
1339    
1340  COMPILATION ERROR CODES  COMPILATION ERROR CODES
1341    
1342         The  following  table  lists  the  error  codes than may be returned by         The following table lists the error  codes  than  may  be  returned  by
1343         pcre_compile2(), along with the error messages that may be returned  by         pcre_compile2(),  along with the error messages that may be returned by
1344         both  compiling functions. As PCRE has developed, some error codes have         both compiling functions. As PCRE has developed, some error codes  have
1345         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.
1346    
1347            0  no error            0  no error
# Line 1285  COMPILATION ERROR CODES Line 1356  COMPILATION ERROR CODES
1356            9  nothing to repeat            9  nothing to repeat
1357           10  [this code is not in use]           10  [this code is not in use]
1358           11  internal error: unexpected repeat           11  internal error: unexpected repeat
1359           12  unrecognized character after (?           12  unrecognized character after (? or (?-
1360           13  POSIX named classes are supported only within a class           13  POSIX named classes are supported only within a class
1361           14  missing )           14  missing )
1362           15  reference to non-existent subpattern           15  reference to non-existent subpattern
# Line 1293  COMPILATION ERROR CODES Line 1364  COMPILATION ERROR CODES
1364           17  unknown option bit(s) set           17  unknown option bit(s) set
1365           18  missing ) after comment           18  missing ) after comment
1366           19  [this code is not in use]           19  [this code is not in use]
1367           20  regular expression too large           20  regular expression is too large
1368           21  failed to get memory           21  failed to get memory
1369           22  unmatched parentheses           22  unmatched parentheses
1370           23  internal error: code overflow           23  internal error: code overflow
# Line 1322  COMPILATION ERROR CODES Line 1393  COMPILATION ERROR CODES
1393           46  malformed \P or \p sequence           46  malformed \P or \p sequence
1394           47  unknown property name after \P or \p           47  unknown property name after \P or \p
1395           48  subpattern name is too long (maximum 32 characters)           48  subpattern name is too long (maximum 32 characters)
1396           49  too many named subpatterns (maximum 10,000)           49  too many named subpatterns (maximum 10000)
1397           50  [this code is not in use]           50  [this code is not in use]
1398           51  octal value is greater than \377 (not in UTF-8 mode)           51  octal value is greater than \377 (not in UTF-8 mode)
1399           52  internal error: overran compiling workspace           52  internal error: overran compiling workspace
1400           53  internal  error:  previously-checked  referenced  subpattern  not           53   internal  error:  previously-checked  referenced  subpattern not
1401         found         found
1402           54  DEFINE group contains more than one branch           54  DEFINE group contains more than one branch
1403           55  repeating a DEFINE group is not allowed           55  repeating a DEFINE group is not allowed
1404           56  inconsistent NEWLINE options"           56  inconsistent NEWLINE options
1405           57  \g is not followed by a braced name or an optionally braced           57  \g is not followed by a braced name or an optionally braced
1406                 non-zero number                 non-zero number
1407           58  (?+ or (?- or (?(+ or (?(- must be followed by a non-zero number           58  (?+ or (?- or (?(+ or (?(- must be followed by a non-zero number
1408             59  (*VERB) with an argument is not supported
1409             60  (*VERB) not recognized
1410             61  number is too big
1411             62  subpattern name expected
1412             63  digit expected after (?+
1413    
1414           The numbers 32 and 10000 in errors 48 and 49  are  defaults;  different
1415           values may be used if the limits were changed when PCRE was built.
1416    
1417    
1418  STUDYING A PATTERN  STUDYING A PATTERN
# Line 1522  INFORMATION ABOUT A PATTERN Line 1601  INFORMATION ABOUT A PATTERN
1601         returned.  The fourth argument should point to an unsigned char * vari-         returned.  The fourth argument should point to an unsigned char * vari-
1602         able.         able.
1603    
1604             PCRE_INFO_HASCRORLF
1605    
1606           Return 1 if the pattern contains any explicit  matches  for  CR  or  LF
1607           characters,  otherwise  0.  The  fourth argument should point to an int
1608           variable. An explicit match is either a literal CR or LF character,  or
1609           \r or \n.
1610    
1611           PCRE_INFO_JCHANGED           PCRE_INFO_JCHANGED
1612    
1613         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,
1614         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)
1615         nal option setting changes the local PCRE_DUPNAMES option.         and (?-J) set and unset the local PCRE_DUPNAMES option, respectively.
1616    
1617           PCRE_INFO_LASTLITERAL           PCRE_INFO_LASTLITERAL
1618    
1619         Return the value of the rightmost literal byte that must exist  in  any         Return  the  value of the rightmost literal byte that must exist in any
1620         matched  string,  other  than  at  its  start,  if such a byte has been         matched string, other than at its  start,  if  such  a  byte  has  been
1621         recorded. The fourth argument should point to an int variable. If there         recorded. The fourth argument should point to an int variable. If there
1622         is  no such byte, -1 is returned. For anchored patterns, a last literal         is no such byte, -1 is returned. For anchored patterns, a last  literal
1623         byte is recorded only if it follows something of variable  length.  For         byte  is  recorded only if it follows something of variable length. For
1624         example, for the pattern /^a\d+z\d+/ the returned value is "z", but for         example, for the pattern /^a\d+z\d+/ the returned value is "z", but for
1625         /^a\dz\d/ the returned value is -1.         /^a\dz\d/ the returned value is -1.
1626    
# Line 1542  INFORMATION ABOUT A PATTERN Line 1628  INFORMATION ABOUT A PATTERN
1628           PCRE_INFO_NAMEENTRYSIZE           PCRE_INFO_NAMEENTRYSIZE
1629           PCRE_INFO_NAMETABLE           PCRE_INFO_NAMETABLE
1630    
1631         PCRE supports the use of named as well as numbered capturing  parenthe-         PCRE  supports the use of named as well as numbered capturing parenthe-
1632         ses.  The names are just an additional way of identifying the parenthe-         ses. The names are just an additional way of identifying the  parenthe-
1633         ses, which still acquire numbers. Several convenience functions such as         ses, which still acquire numbers. Several convenience functions such as
1634         pcre_get_named_substring()  are  provided  for extracting captured sub-         pcre_get_named_substring() are provided for  extracting  captured  sub-
1635         strings by name. It is also possible to extract the data  directly,  by         strings  by  name. It is also possible to extract the data directly, by
1636         first  converting  the  name to a number in order to access the correct         first converting the name to a number in order to  access  the  correct
1637         pointers in the output vector (described with pcre_exec() below). To do         pointers in the output vector (described with pcre_exec() below). To do
1638         the  conversion,  you  need  to  use  the  name-to-number map, which is         the conversion, you need  to  use  the  name-to-number  map,  which  is
1639         described by these three values.         described by these three values.
1640    
1641         The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT         The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT
1642         gives the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size         gives the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size
1643         of each entry; both of these  return  an  int  value.  The  entry  size         of  each  entry;  both  of  these  return  an int value. The entry size
1644         depends  on the length of the longest name. PCRE_INFO_NAMETABLE returns         depends on the length of the longest name. PCRE_INFO_NAMETABLE  returns
1645         a pointer to the first entry of the table  (a  pointer  to  char).  The         a  pointer  to  the  first  entry of the table (a pointer to char). The
1646         first two bytes of each entry are the number of the capturing parenthe-         first two bytes of each entry are the number of the capturing parenthe-
1647         sis, most significant byte first. The rest of the entry is  the  corre-         sis,  most  significant byte first. The rest of the entry is the corre-
1648         sponding  name,  zero  terminated. The names are in alphabetical order.         sponding name, zero terminated. The names are  in  alphabetical  order.
1649         When PCRE_DUPNAMES is set, duplicate names are in order of their paren-         When PCRE_DUPNAMES is set, duplicate names are in order of their paren-
1650         theses  numbers.  For  example,  consider the following pattern (assume         theses numbers. For example, consider  the  following  pattern  (assume
1651         PCRE_EXTENDED is  set,  so  white  space  -  including  newlines  -  is         PCRE_EXTENDED  is  set,  so  white  space  -  including  newlines  - is
1652         ignored):         ignored):
1653    
1654           (?<date> (?<year>(\d\d)?\d\d) -           (?<date> (?<year>(\d\d)?\d\d) -
1655           (?<month>\d\d) - (?<day>\d\d) )           (?<month>\d\d) - (?<day>\d\d) )
1656    
1657         There  are  four  named subpatterns, so the table has four entries, and         There are four named subpatterns, so the table has  four  entries,  and
1658         each entry in the table is eight bytes long. The table is  as  follows,         each  entry  in the table is eight bytes long. The table is as follows,
1659         with non-printing bytes shows in hexadecimal, and undefined bytes shown         with non-printing bytes shows in hexadecimal, and undefined bytes shown
1660         as ??:         as ??:
1661    
# Line 1578  INFORMATION ABOUT A PATTERN Line 1664  INFORMATION ABOUT A PATTERN
1664           00 04 m  o  n  t  h  00           00 04 m  o  n  t  h  00
1665           00 02 y  e  a  r  00 ??           00 02 y  e  a  r  00 ??
1666    
1667         When writing code to extract data  from  named  subpatterns  using  the         When  writing  code  to  extract  data from named subpatterns using the
1668         name-to-number  map,  remember that the length of the entries is likely         name-to-number map, remember that the length of the entries  is  likely
1669         to be different for each compiled pattern.         to be different for each compiled pattern.
1670    
1671           PCRE_INFO_OKPARTIAL           PCRE_INFO_OKPARTIAL
1672    
1673         Return 1 if the pattern can be used for partial matching, otherwise  0.         Return  1 if the pattern can be used for partial matching, otherwise 0.
1674         The  fourth  argument  should point to an int variable. The pcrepartial         The fourth argument should point to an int  variable.  The  pcrepartial
1675         documentation lists the restrictions that apply to patterns  when  par-         documentation  lists  the restrictions that apply to patterns when par-
1676         tial matching is used.         tial matching is used.
1677    
1678           PCRE_INFO_OPTIONS           PCRE_INFO_OPTIONS
1679    
1680         Return  a  copy of the options with which the pattern was compiled. The         Return a copy of the options with which the pattern was  compiled.  The
1681         fourth argument should point to an unsigned long  int  variable.  These         fourth  argument  should  point to an unsigned long int variable. These
1682         option bits are those specified in the call to pcre_compile(), modified         option bits are those specified in the call to pcre_compile(), modified
1683         by any top-level option settings at the start of the pattern itself. In         by any top-level option settings at the start of the pattern itself. In
1684         other  words,  they are the options that will be in force when matching         other words, they are the options that will be in force  when  matching
1685         starts. For example, if the pattern /(?im)abc(?-i)d/ is  compiled  with         starts.  For  example, if the pattern /(?im)abc(?-i)d/ is compiled with
1686         the  PCRE_EXTENDED option, the result is PCRE_CASELESS, PCRE_MULTILINE,         the PCRE_EXTENDED option, the result is PCRE_CASELESS,  PCRE_MULTILINE,
1687         and PCRE_EXTENDED.         and PCRE_EXTENDED.
1688    
1689         A pattern is automatically anchored by PCRE if  all  of  its  top-level         A  pattern  is  automatically  anchored by PCRE if all of its top-level
1690         alternatives begin with one of the following:         alternatives begin with one of the following:
1691    
1692           ^     unless PCRE_MULTILINE is set           ^     unless PCRE_MULTILINE is set
# Line 1614  INFORMATION ABOUT A PATTERN Line 1700  INFORMATION ABOUT A PATTERN
1700    
1701           PCRE_INFO_SIZE           PCRE_INFO_SIZE
1702    
1703         Return the size of the compiled pattern, that is, the  value  that  was         Return  the  size  of the compiled pattern, that is, the value that was
1704         passed as the argument to pcre_malloc() when PCRE was getting memory in         passed as the argument to pcre_malloc() when PCRE was getting memory in
1705         which to place the compiled data. The fourth argument should point to a         which to place the compiled data. The fourth argument should point to a
1706         size_t variable.         size_t variable.
# Line 1622  INFORMATION ABOUT A PATTERN Line 1708  INFORMATION ABOUT A PATTERN
1708           PCRE_INFO_STUDYSIZE           PCRE_INFO_STUDYSIZE
1709    
1710         Return the size of the data block pointed to by the study_data field in         Return the size of the data block pointed to by the study_data field in
1711         a pcre_extra block. That is,  it  is  the  value  that  was  passed  to         a  pcre_extra  block.  That  is,  it  is  the  value that was passed to
1712         pcre_malloc() when PCRE was getting memory into which to place the data         pcre_malloc() when PCRE was getting memory into which to place the data
1713         created by pcre_study(). The fourth argument should point to  a  size_t         created  by  pcre_study(). The fourth argument should point to a size_t
1714         variable.         variable.
1715    
1716    
# Line 1632  OBSOLETE INFO FUNCTION Line 1718  OBSOLETE INFO FUNCTION
1718    
1719         int pcre_info(const pcre *code, int *optptr, int *firstcharptr);         int pcre_info(const pcre *code, int *optptr, int *firstcharptr);
1720    
1721         The  pcre_info()  function is now obsolete because its interface is too         The pcre_info() function is now obsolete because its interface  is  too
1722         restrictive to return all the available data about a compiled  pattern.         restrictive  to return all the available data about a compiled pattern.
1723         New   programs   should  use  pcre_fullinfo()  instead.  The  yield  of         New  programs  should  use  pcre_fullinfo()  instead.  The   yield   of
1724         pcre_info() is the number of capturing subpatterns, or one of the  fol-         pcre_info()  is the number of capturing subpatterns, or one of the fol-
1725         lowing negative numbers:         lowing negative numbers:
1726    
1727           PCRE_ERROR_NULL       the argument code was NULL           PCRE_ERROR_NULL       the argument code was NULL
1728           PCRE_ERROR_BADMAGIC   the "magic number" was not found           PCRE_ERROR_BADMAGIC   the "magic number" was not found
1729    
1730         If  the  optptr  argument is not NULL, a copy of the options with which         If the optptr argument is not NULL, a copy of the  options  with  which
1731         the pattern was compiled is placed in the integer  it  points  to  (see         the  pattern  was  compiled  is placed in the integer it points to (see
1732         PCRE_INFO_OPTIONS above).         PCRE_INFO_OPTIONS above).
1733    
1734         If  the  pattern  is  not anchored and the firstcharptr argument is not         If the pattern is not anchored and the  firstcharptr  argument  is  not
1735         NULL, it is used to pass back information about the first character  of         NULL,  it is used to pass back information about the first character of
1736         any matched string (see PCRE_INFO_FIRSTBYTE above).         any matched string (see PCRE_INFO_FIRSTBYTE above).
1737    
1738    
# Line 1654  REFERENCE COUNTS Line 1740  REFERENCE COUNTS
1740    
1741         int pcre_refcount(pcre *code, int adjust);         int pcre_refcount(pcre *code, int adjust);
1742    
1743         The  pcre_refcount()  function is used to maintain a reference count in         The pcre_refcount() function is used to maintain a reference  count  in
1744         the data block that contains a compiled pattern. It is provided for the         the data block that contains a compiled pattern. It is provided for the
1745         benefit  of  applications  that  operate  in an object-oriented manner,         benefit of applications that  operate  in  an  object-oriented  manner,
1746         where different parts of the application may be using the same compiled         where different parts of the application may be using the same compiled
1747         pattern, but you want to free the block when they are all done.         pattern, but you want to free the block when they are all done.
1748    
1749         When a pattern is compiled, the reference count field is initialized to         When a pattern is compiled, the reference count field is initialized to
1750         zero.  It is changed only by calling this function, whose action is  to         zero.   It is changed only by calling this function, whose action is to
1751         add  the  adjust  value  (which may be positive or negative) to it. The         add the adjust value (which may be positive or  negative)  to  it.  The
1752         yield of the function is the new value. However, the value of the count         yield of the function is the new value. However, the value of the count
1753         is  constrained to lie between 0 and 65535, inclusive. If the new value         is constrained to lie between 0 and 65535, inclusive. If the new  value
1754         is outside these limits, it is forced to the appropriate limit value.         is outside these limits, it is forced to the appropriate limit value.
1755    
1756         Except when it is zero, the reference count is not correctly  preserved         Except  when it is zero, the reference count is not correctly preserved
1757         if  a  pattern  is  compiled on one host and then transferred to a host         if a pattern is compiled on one host and then  transferred  to  a  host
1758         whose byte-order is different. (This seems a highly unlikely scenario.)         whose byte-order is different. (This seems a highly unlikely scenario.)
1759    
1760    
# Line 1678  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1764  MATCHING A PATTERN: THE TRADITIONAL FUNC
1764              const char *subject, int length, int startoffset,              const char *subject, int length, int startoffset,
1765              int options, int *ovector, int ovecsize);              int options, int *ovector, int ovecsize);
1766    
1767         The  function pcre_exec() is called to match a subject string against a         The function pcre_exec() is called to match a subject string against  a
1768         compiled pattern, which is passed in the code argument. If the  pattern         compiled  pattern, which is passed in the code argument. If the pattern
1769         has been studied, the result of the study should be passed in the extra         has been studied, the result of the study should be passed in the extra
1770         argument. This function is the main matching facility of  the  library,         argument.  This  function is the main matching facility of the library,
1771         and it operates in a Perl-like manner. For specialist use there is also         and it operates in a Perl-like manner. For specialist use there is also
1772         an alternative matching function, which is described below in the  sec-         an  alternative matching function, which is described below in the sec-
1773         tion about the pcre_dfa_exec() function.         tion about the pcre_dfa_exec() function.
1774    
1775         In  most applications, the pattern will have been compiled (and option-         In most applications, the pattern will have been compiled (and  option-
1776         ally studied) in the same process that calls pcre_exec().  However,  it         ally  studied)  in the same process that calls pcre_exec(). However, it
1777         is possible to save compiled patterns and study data, and then use them         is possible to save compiled patterns and study data, and then use them
1778         later in different processes, possibly even on different hosts.  For  a         later  in  different processes, possibly even on different hosts. For a
1779         discussion about this, see the pcreprecompile documentation.         discussion about this, see the pcreprecompile documentation.
1780    
1781         Here is an example of a simple call to pcre_exec():         Here is an example of a simple call to pcre_exec():
# Line 1708  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1794  MATCHING A PATTERN: THE TRADITIONAL FUNC
1794    
1795     Extra data for pcre_exec()     Extra data for pcre_exec()
1796    
1797         If  the  extra argument is not NULL, it must point to a pcre_extra data         If the extra argument is not NULL, it must point to a  pcre_extra  data
1798         block. The pcre_study() function returns such a block (when it  doesn't         block.  The pcre_study() function returns such a block (when it doesn't
1799         return  NULL), but you can also create one for yourself, and pass addi-         return NULL), but you can also create one for yourself, and pass  addi-
1800         tional information in it. The pcre_extra block contains  the  following         tional  information  in it. The pcre_extra block contains the following
1801         fields (not necessarily in this order):         fields (not necessarily in this order):
1802    
1803           unsigned long int flags;           unsigned long int flags;
# Line 1721  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1807  MATCHING A PATTERN: THE TRADITIONAL FUNC
1807           void *callout_data;           void *callout_data;
1808           const unsigned char *tables;           const unsigned char *tables;
1809    
1810         The  flags  field  is a bitmap that specifies which of the other fields         The flags field is a bitmap that specifies which of  the  other  fields
1811         are set. The flag bits are:         are set. The flag bits are:
1812    
1813           PCRE_EXTRA_STUDY_DATA           PCRE_EXTRA_STUDY_DATA
# Line 1730  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1816  MATCHING A PATTERN: THE TRADITIONAL FUNC
1816           PCRE_EXTRA_CALLOUT_DATA           PCRE_EXTRA_CALLOUT_DATA
1817           PCRE_EXTRA_TABLES           PCRE_EXTRA_TABLES
1818    
1819         Other flag bits should be set to zero. The study_data field is  set  in         Other  flag  bits should be set to zero. The study_data field is set in
1820         the  pcre_extra  block  that is returned by pcre_study(), together with         the pcre_extra block that is returned by  pcre_study(),  together  with
1821         the appropriate flag bit. You should not set this yourself, but you may         the appropriate flag bit. You should not set this yourself, but you may
1822         add  to  the  block by setting the other fields and their corresponding         add to the block by setting the other fields  and  their  corresponding
1823         flag bits.         flag bits.
1824    
1825         The match_limit field provides a means of preventing PCRE from using up         The match_limit field provides a means of preventing PCRE from using up
1826         a  vast amount of resources when running patterns that are not going to         a vast amount of resources when running patterns that are not going  to
1827         match, but which have a very large number  of  possibilities  in  their         match,  but  which  have  a very large number of possibilities in their
1828         search  trees.  The  classic  example  is  the  use of nested unlimited         search trees. The classic  example  is  the  use  of  nested  unlimited
1829         repeats.         repeats.
1830    
1831         Internally, PCRE uses a function called match() which it calls  repeat-         Internally,  PCRE uses a function called match() which it calls repeat-
1832         edly  (sometimes  recursively). The limit set by match_limit is imposed         edly (sometimes recursively). The limit set by match_limit  is  imposed
1833         on the number of times this function is called during  a  match,  which         on  the  number  of times this function is called during a match, which
1834         has  the  effect  of  limiting the amount of backtracking that can take         has the effect of limiting the amount of  backtracking  that  can  take
1835         place. For patterns that are not anchored, the count restarts from zero         place. For patterns that are not anchored, the count restarts from zero
1836         for each position in the subject string.         for each position in the subject string.
1837    
1838         The  default  value  for  the  limit can be set when PCRE is built; the         The default value for the limit can be set  when  PCRE  is  built;  the
1839         default default is 10 million, which handles all but the  most  extreme         default  default  is 10 million, which handles all but the most extreme
1840         cases.  You  can  override  the  default by suppling pcre_exec() with a         cases. You can override the default  by  suppling  pcre_exec()  with  a
1841         pcre_extra    block    in    which    match_limit    is    set,     and         pcre_extra     block    in    which    match_limit    is    set,    and
1842         PCRE_EXTRA_MATCH_LIMIT  is  set  in  the  flags  field. If the limit is         PCRE_EXTRA_MATCH_LIMIT is set in the  flags  field.  If  the  limit  is
1843         exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT.         exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT.
1844    
1845         The match_limit_recursion field is similar to match_limit, but  instead         The  match_limit_recursion field is similar to match_limit, but instead
1846         of limiting the total number of times that match() is called, it limits         of limiting the total number of times that match() is called, it limits
1847         the depth of recursion. The recursion depth is a  smaller  number  than         the  depth  of  recursion. The recursion depth is a smaller number than
1848         the  total number of calls, because not all calls to match() are recur-         the total number of calls, because not all calls to match() are  recur-
1849         sive.  This limit is of use only if it is set smaller than match_limit.         sive.  This limit is of use only if it is set smaller than match_limit.
1850    
1851         Limiting  the  recursion  depth  limits the amount of stack that can be         Limiting the recursion depth limits the amount of  stack  that  can  be
1852         used, or, when PCRE has been compiled to use memory on the heap instead         used, or, when PCRE has been compiled to use memory on the heap instead
1853         of the stack, the amount of heap memory that can be used.         of the stack, the amount of heap memory that can be used.
1854    
1855         The  default  value  for  match_limit_recursion can be set when PCRE is         The default value for match_limit_recursion can be  set  when  PCRE  is
1856         built; the default default  is  the  same  value  as  the  default  for         built;  the  default  default  is  the  same  value  as the default for
1857         match_limit.  You can override the default by suppling pcre_exec() with         match_limit. You can override the default by suppling pcre_exec()  with
1858         a  pcre_extra  block  in  which  match_limit_recursion  is   set,   and         a   pcre_extra   block  in  which  match_limit_recursion  is  set,  and
1859         PCRE_EXTRA_MATCH_LIMIT_RECURSION  is  set  in  the  flags field. If the         PCRE_EXTRA_MATCH_LIMIT_RECURSION is set in  the  flags  field.  If  the
1860         limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT.         limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT.
1861    
1862         The pcre_callout field is used in conjunction with the  "callout"  fea-         The  pcre_callout  field is used in conjunction with the "callout" fea-
1863         ture, which is described in the pcrecallout documentation.         ture, which is described in the pcrecallout documentation.
1864    
1865         The  tables  field  is  used  to  pass  a  character  tables pointer to         The tables field  is  used  to  pass  a  character  tables  pointer  to
1866         pcre_exec(); this overrides the value that is stored with the  compiled         pcre_exec();  this overrides the value that is stored with the compiled
1867         pattern.  A  non-NULL value is stored with the compiled pattern only if         pattern. A non-NULL value is stored with the compiled pattern  only  if
1868         custom tables were supplied to pcre_compile() via  its  tableptr  argu-         custom  tables  were  supplied to pcre_compile() via its tableptr argu-
1869         ment.  If NULL is passed to pcre_exec() using this mechanism, it forces         ment.  If NULL is passed to pcre_exec() using this mechanism, it forces
1870         PCRE's internal tables to be used. This facility is  helpful  when  re-         PCRE's  internal  tables  to be used. This facility is helpful when re-
1871         using  patterns  that  have been saved after compiling with an external         using patterns that have been saved after compiling  with  an  external
1872         set of tables, because the external tables  might  be  at  a  different         set  of  tables,  because  the  external tables might be at a different
1873         address  when  pcre_exec() is called. See the pcreprecompile documenta-         address when pcre_exec() is called. See the  pcreprecompile  documenta-
1874         tion for a discussion of saving compiled patterns for later use.         tion for a discussion of saving compiled patterns for later use.
1875    
1876     Option bits for pcre_exec()     Option bits for pcre_exec()
1877    
1878         The unused bits of the options argument for pcre_exec() must  be  zero.         The  unused  bits of the options argument for pcre_exec() must be zero.
1879         The  only  bits  that  may  be set are PCRE_ANCHORED, PCRE_NEWLINE_xxx,         The only bits that may  be  set  are  PCRE_ANCHORED,  PCRE_NEWLINE_xxx,
1880         PCRE_NOTBOL,   PCRE_NOTEOL,   PCRE_NOTEMPTY,   PCRE_NO_UTF8_CHECK   and         PCRE_NOTBOL,   PCRE_NOTEOL,   PCRE_NOTEMPTY,   PCRE_NO_UTF8_CHECK   and
1881         PCRE_PARTIAL.         PCRE_PARTIAL.
1882    
1883           PCRE_ANCHORED           PCRE_ANCHORED
1884    
1885         The  PCRE_ANCHORED  option  limits pcre_exec() to matching at the first         The PCRE_ANCHORED option limits pcre_exec() to matching  at  the  first
1886         matching position. If a pattern was  compiled  with  PCRE_ANCHORED,  or         matching  position.  If  a  pattern was compiled with PCRE_ANCHORED, or
1887         turned  out to be anchored by virtue of its contents, it cannot be made         turned out to be anchored by virtue of its contents, it cannot be  made
1888         unachored at matching time.         unachored at matching time.
1889    
1890             PCRE_BSR_ANYCRLF
1891             PCRE_BSR_UNICODE
1892    
1893           These options (which are mutually exclusive) control what the \R escape
1894           sequence matches. The choice is either to match only CR, LF,  or  CRLF,
1895           or  to  match  any Unicode newline sequence. These options override the
1896           choice that was made or defaulted when the pattern was compiled.
1897    
1898           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
1899           PCRE_NEWLINE_LF           PCRE_NEWLINE_LF
1900           PCRE_NEWLINE_CRLF           PCRE_NEWLINE_CRLF
# Line 1812  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1906  MATCHING A PATTERN: THE TRADITIONAL FUNC
1906         tion of pcre_compile()  above.  During  matching,  the  newline  choice         tion of pcre_compile()  above.  During  matching,  the  newline  choice
1907         affects  the  behaviour  of the dot, circumflex, and dollar metacharac-         affects  the  behaviour  of the dot, circumflex, and dollar metacharac-
1908         ters. It may also alter the way the match position is advanced after  a         ters. It may also alter the way the match position is advanced after  a
1909         match  failure  for  an  unanchored  pattern.  When  PCRE_NEWLINE_CRLF,         match failure for an unanchored pattern.
1910         PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is set, and a  match  attempt  
1911         fails  when the current position is at a CRLF sequence, the match posi-         When  PCRE_NEWLINE_CRLF,  PCRE_NEWLINE_ANYCRLF,  or PCRE_NEWLINE_ANY is
1912         tion is advanced by two characters instead of one, in other  words,  to         set, and a match attempt for an unanchored pattern fails when the  cur-
1913         after the CRLF.         rent  position  is  at  a  CRLF  sequence,  and the pattern contains no
1914           explicit matches for  CR  or  LF  characters,  the  match  position  is
1915           advanced by two characters instead of one, in other words, to after the
1916           CRLF.
1917    
1918           The above rule is a compromise that makes the most common cases work as
1919           expected.  For  example,  if  the  pattern  is .+A (and the PCRE_DOTALL
1920           option is not set), it does not match the string "\r\nA" because, after
1921           failing  at the start, it skips both the CR and the LF before retrying.
1922           However, the pattern [\r\n]A does match that string,  because  it  con-
1923           tains an explicit CR or LF reference, and so advances only by one char-
1924           acter after the first failure.
1925    
1926           An explicit match for CR of LF is either a literal appearance of one of
1927           those  characters,  or  one  of the \r or \n escape sequences. Implicit
1928           matches such as [^X] do not count, nor does \s (which includes  CR  and
1929           LF in the characters that it matches).
1930    
1931           Notwithstanding  the above, anomalous effects may still occur when CRLF
1932           is a valid newline sequence and explicit \r or \n escapes appear in the
1933           pattern.
1934    
1935           PCRE_NOTBOL           PCRE_NOTBOL
1936    
# Line 2451  AUTHOR Line 2565  AUTHOR
2565    
2566  REVISION  REVISION
2567    
2568         Last updated: 09 August 2007         Last updated: 23 January 2008
2569         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
2570  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2571    
2572    
# Line 2736  DIFFERENCES BETWEEN PCRE AND PERL Line 2850  DIFFERENCES BETWEEN PCRE AND PERL
2850         (f)  The PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, and PCRE_NO_AUTO_CAP-         (f)  The PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, and PCRE_NO_AUTO_CAP-
2851         TURE options for pcre_exec() have no Perl equivalents.         TURE options for pcre_exec() have no Perl equivalents.
2852    
2853         (g) The callout facility is PCRE-specific.         (g) The \R escape sequence can be restricted to match only CR,  LF,  or
2854           CRLF by the PCRE_BSR_ANYCRLF option.
2855    
2856         (h) The partial matching facility is PCRE-specific.         (h) The callout facility is PCRE-specific.
2857    
2858         (i) Patterns compiled by PCRE can be saved and re-used at a later time,         (i) The partial matching facility is PCRE-specific.
2859    
2860           (j) Patterns compiled by PCRE can be saved and re-used at a later time,
2861         even on different hosts that have the other endianness.         even on different hosts that have the other endianness.
2862    
2863         (j)  The  alternative  matching function (pcre_dfa_exec()) matches in a         (k) The alternative matching function (pcre_dfa_exec())  matches  in  a
2864         different way and is not Perl-compatible.         different way and is not Perl-compatible.
2865    
2866           (l)  PCRE  recognizes some special sequences such as (*CR) at the start
2867           of a pattern that set overall options that cannot be changed within the
2868           pattern.
2869    
2870    
2871  AUTHOR  AUTHOR
2872    
# Line 2756  AUTHOR Line 2877  AUTHOR
2877    
2878  REVISION  REVISION
2879    
2880         Last updated: 08 August 2007         Last updated: 11 September 2007
2881         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
2882  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2883    
# Line 2797  PCRE REGULAR EXPRESSION DETAILS Line 2918  PCRE REGULAR EXPRESSION DETAILS
2918         discussed in the pcrematching page.         discussed in the pcrematching page.
2919    
2920    
2921    NEWLINE CONVENTIONS
2922    
2923           PCRE  supports five different conventions for indicating line breaks in
2924           strings: a single CR (carriage return) character, a  single  LF  (line-
2925           feed) character, the two-character sequence CRLF, any of the three pre-
2926           ceding, or any Unicode newline sequence. The pcreapi page  has  further
2927           discussion  about newlines, and shows how to set the newline convention
2928           in the options arguments for the compiling and matching functions.
2929    
2930           It is also possible to specify a newline convention by starting a  pat-
2931           tern string with one of the following five sequences:
2932    
2933             (*CR)        carriage return
2934             (*LF)        linefeed
2935             (*CRLF)      carriage return, followed by linefeed
2936             (*ANYCRLF)   any of the three above
2937             (*ANY)       all Unicode newline sequences
2938    
2939           These override the default and the options given to pcre_compile(). For
2940           example, on a Unix system where LF is the default newline sequence, the
2941           pattern
2942    
2943             (*CR)a.b
2944    
2945           changes the convention to CR. That pattern matches "a\nb" because LF is
2946           no longer a newline. Note that these special settings,  which  are  not
2947           Perl-compatible,  are  recognized  only at the very start of a pattern,
2948           and that they must be in upper case.  If  more  than  one  of  them  is
2949           present, the last one is used.
2950    
2951           The  newline  convention  does  not  affect what the \R escape sequence
2952           matches. By default, this is any Unicode  newline  sequence,  for  Perl
2953           compatibility.  However, this can be changed; see the description of \R
2954           in the section entitled "Newline sequences" below. A change of \R  set-
2955           ting can be combined with a change of newline convention.
2956    
2957    
2958  CHARACTERS AND METACHARACTERS  CHARACTERS AND METACHARACTERS
2959    
2960         A  regular  expression  is  a pattern that is matched against a subject         A  regular  expression  is  a pattern that is matched against a subject
# Line 2904  BACKSLASH Line 3062  BACKSLASH
3062           \cx       "control-x", where x is any character           \cx       "control-x", where x is any character
3063           \e        escape (hex 1B)           \e        escape (hex 1B)
3064           \f        formfeed (hex 0C)           \f        formfeed (hex 0C)
3065           \n        newline (hex 0A)           \n        linefeed (hex 0A)
3066           \r        carriage return (hex 0D)           \r        carriage return (hex 0D)
3067           \t        tab (hex 09)           \t        tab (hex 09)
3068           \ddd      character with octal code ddd, or backreference           \ddd      character with octal code ddd, or backreference
# Line 3069  BACKSLASH Line 3227  BACKSLASH
3227    
3228     Newline sequences     Newline sequences
3229    
3230         Outside a character class, the escape sequence \R matches  any  Unicode         Outside a character class, by default, the escape sequence  \R  matches
3231         newline  sequence. This is a Perl 5.10 feature. In non-UTF-8 mode \R is         any Unicode newline sequence. This is a Perl 5.10 feature. In non-UTF-8
3232         equivalent to the following:         mode \R is equivalent to the following:
3233    
3234           (?>\r\n|\n|\x0b|\f|\r|\x85)           (?>\r\n|\n|\x0b|\f|\r|\x85)
3235    
# Line 3087  BACKSLASH Line 3245  BACKSLASH
3245         rator,  U+2029).   Unicode character property support is not needed for         rator,  U+2029).   Unicode character property support is not needed for
3246         these characters to be recognized.         these characters to be recognized.
3247    
3248           It is possible to restrict \R to match only CR, LF, or CRLF (instead of
3249           the  complete  set  of  Unicode  line  endings)  by  setting the option
3250           PCRE_BSR_ANYCRLF either at compile time or when the pattern is matched.
3251           (BSR is an abbrevation for "backslash R".) This can be made the default
3252           when PCRE is built; if this is the case, the  other  behaviour  can  be
3253           requested  via  the  PCRE_BSR_UNICODE  option.   It is also possible to
3254           specify these settings by starting a pattern string  with  one  of  the
3255           following sequences:
3256    
3257             (*BSR_ANYCRLF)   CR, LF, or CRLF only
3258             (*BSR_UNICODE)   any Unicode newline sequence
3259    
3260           These override the default and the options given to pcre_compile(), but
3261           they can be overridden by options given to pcre_exec(). Note that these
3262           special settings, which are not Perl-compatible, are recognized only at
3263           the very start of a pattern, and that they must be in  upper  case.  If
3264           more  than  one  of  them is present, the last one is used. They can be
3265           combined with a change of newline convention, for  example,  a  pattern
3266           can start with:
3267    
3268             (*ANY)(*BSR_ANYCRLF)
3269    
3270         Inside a character class, \R matches the letter "R".         Inside a character class, \R matches the letter "R".
3271    
3272     Unicode character properties     Unicode character properties
3273    
3274         When PCRE is built with Unicode character property support, three addi-         When PCRE is built with Unicode character property support, three addi-
3275         tional  escape sequences that match characters with specific properties         tional escape sequences that match characters with specific  properties
3276         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
3277         limited  to  testing characters whose codepoints are less than 256, but         limited to testing characters whose codepoints are less than  256,  but
3278         they do work in this mode.  The extra escape sequences are:         they do work in this mode.  The extra escape sequences are:
3279    
3280           \p{xx}   a character with the xx property           \p{xx}   a character with the xx property
3281           \P{xx}   a character without the xx property           \P{xx}   a character without the xx property
3282           \X       an extended Unicode sequence           \X       an extended Unicode sequence
3283    
3284         The property names represented by xx above are limited to  the  Unicode         The  property  names represented by xx above are limited to the Unicode
3285         script names, the general category properties, and "Any", which matches         script names, the general category properties, and "Any", which matches
3286         any character (including newline). Other properties such as "InMusical-         any character (including newline). Other properties such as "InMusical-
3287         Symbols"  are  not  currently supported by PCRE. Note that \P{Any} does         Symbols" are not currently supported by PCRE. Note  that  \P{Any}  does
3288         not match any characters, so always causes a match failure.         not match any characters, so always causes a match failure.
3289    
3290         Sets of Unicode characters are defined as belonging to certain scripts.         Sets of Unicode characters are defined as belonging to certain scripts.
3291         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.
3292         For example:         For example:
3293    
3294           \p{Greek}           \p{Greek}
3295           \P{Han}           \P{Han}
3296    
3297         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
3298         "Common". The current list of scripts is:         "Common". The current list of scripts is:
3299    
3300         Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,         Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,
3301         Buhid,  Canadian_Aboriginal,  Cherokee,  Common,   Coptic,   Cuneiform,         Buhid,   Canadian_Aboriginal,   Cherokee,  Common,  Coptic,  Cuneiform,
3302         Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,         Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,
3303         Gothic, Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew,  Hira-         Gothic,  Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hira-
3304         gana,  Inherited,  Kannada,  Katakana,  Kharoshthi,  Khmer, Lao, Latin,         gana, Inherited, Kannada,  Katakana,  Kharoshthi,  Khmer,  Lao,  Latin,
3305         Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,         Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,
3306         Ogham,  Old_Italic,  Old_Persian, Oriya, Osmanya, Phags_Pa, Phoenician,         Ogham, Old_Italic, Old_Persian, Oriya, Osmanya,  Phags_Pa,  Phoenician,
3307         Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,         Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,
3308         Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.         Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.
3309    
3310         Each  character has exactly one general category property, specified by         Each character has exactly one general category property, specified  by
3311         a two-letter abbreviation. For compatibility with Perl, negation can be         a two-letter abbreviation. For compatibility with Perl, negation can be
3312         specified  by  including a circumflex between the opening brace and the         specified by including a circumflex between the opening brace  and  the
3313         property name. For example, \p{^Lu} is the same as \P{Lu}.         property name. For example, \p{^Lu} is the same as \P{Lu}.
3314    
3315         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-
3316         eral  category properties that start with that letter. In this case, in         eral category properties that start with that letter. In this case,  in
3317         the absence of negation, the curly brackets in the escape sequence  are         the  absence of negation, the curly brackets in the escape sequence are
3318         optional; these two examples have the same effect:         optional; these two examples have the same effect:
3319    
3320           \p{L}           \p{L}
# Line 3186  BACKSLASH Line 3366  BACKSLASH
3366           Zp    Paragraph separator           Zp    Paragraph separator
3367           Zs    Space separator           Zs    Space separator
3368    
3369         The  special property L& is also supported: it matches a character that         The special property L& is also supported: it matches a character  that
3370         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
3371         classified as a modifier or "other".         classified as a modifier or "other".
3372    
3373         The  Cs  (Surrogate)  property  applies only to characters in the range         The Cs (Surrogate) property applies only to  characters  in  the  range
3374         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
3375         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-
3376         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
3377         the pcreapi page).         the pcreapi page).
3378    
3379         The  long  synonyms  for  these  properties that Perl supports (such as         The long synonyms for these properties  that  Perl  supports  (such  as
3380         \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
3381         any of these properties with "Is".         any of these properties with "Is".
3382    
3383         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-
3384         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
3385         in the Unicode table.         in the Unicode table.
3386    
3387         Specifying  caseless  matching  does not affect these escape sequences.         Specifying caseless matching does not affect  these  escape  sequences.
3388         For example, \p{Lu} always matches only upper case letters.         For example, \p{Lu} always matches only upper case letters.
3389    
3390         The \X escape matches any number of Unicode  characters  that  form  an         The  \X  escape  matches  any number of Unicode characters that form an
3391         extended Unicode sequence. \X is equivalent to         extended Unicode sequence. \X is equivalent to
3392    
3393           (?>\PM\pM*)           (?>\PM\pM*)
3394    
3395         That  is,  it matches a character without the "mark" property, followed         That is, it matches a character without the "mark"  property,  followed
3396         by zero or more characters with the "mark"  property,  and  treats  the         by  zero  or  more  characters with the "mark" property, and treats the
3397         sequence  as  an  atomic group (see below).  Characters with the "mark"         sequence as an atomic group (see below).  Characters  with  the  "mark"
3398         property are typically accents that  affect  the  preceding  character.         property  are  typically  accents  that affect the preceding character.
3399         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
3400         matches any one character.         matches any one character.
3401    
3402         Matching characters by Unicode property is not fast, because  PCRE  has         Matching  characters  by Unicode property is not fast, because PCRE has
3403         to  search  a  structure  that  contains data for over fifteen thousand         to search a structure that contains  data  for  over  fifteen  thousand
3404         characters. That is why the traditional escape sequences such as \d and         characters. That is why the traditional escape sequences such as \d and
3405         \w do not use Unicode properties in PCRE.         \w do not use Unicode properties in PCRE.
3406    
3407     Resetting the match start     Resetting the match start
3408    
3409         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-
3410         ously matched characters not  to  be  included  in  the  final  matched         ously  matched  characters  not  to  be  included  in the final matched
3411         sequence. For example, the pattern:         sequence. For example, the pattern:
3412    
3413           foo\Kbar           foo\Kbar
3414    
3415         matches  "foobar",  but reports that it has matched "bar". This feature         matches "foobar", but reports that it has matched "bar".  This  feature
3416         is similar to a lookbehind assertion (described  below).   However,  in         is  similar  to  a lookbehind assertion (described below).  However, in
3417         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
3418         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
3419         not  interfere  with  the setting of captured substrings.  For example,         not interfere with the setting of captured  substrings.   For  example,
3420         when the pattern         when the pattern
3421    
3422           (foo)\Kbar           (foo)\Kbar
# Line 3245  BACKSLASH Line 3425  BACKSLASH
3425    
3426     Simple assertions     Simple assertions
3427    
3428         The final use of backslash is for certain simple assertions. An  asser-         The  final use of backslash is for certain simple assertions. An asser-
3429         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
3430         a match, without consuming any characters from the subject string.  The         a  match, without consuming any characters from the subject string. The
3431         use  of subpatterns for more complicated assertions is described below.         use of subpatterns for more complicated assertions is described  below.
3432         The backslashed assertions are:         The backslashed assertions are:
3433    
3434           \b     matches at a word boundary           \b     matches at a word boundary
# Line 3259  BACKSLASH Line 3439  BACKSLASH
3439           \z     matches only at the end of the subject           \z     matches only at the end of the subject
3440           \G     matches at the first matching position in the subject           \G     matches at the first matching position in the subject
3441    
3442         These assertions may not appear in character classes (but note that  \b         These  assertions may not appear in character classes (but note that \b
3443         has a different meaning, namely the backspace character, inside a char-         has a different meaning, namely the backspace character, inside a char-
3444         acter class).         acter class).
3445    
3446         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
3447         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.
3448         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
3449         string if the first or last character matches \w, respectively.         string if the first or last character matches \w, respectively.
3450    
3451         The  \A,  \Z,  and \z assertions differ from the traditional circumflex         The \A, \Z, and \z assertions differ from  the  traditional  circumflex
3452         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
3453         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
3454         set. Thus, they are independent of multiline mode. These  three  asser-         set.  Thus,  they are independent of multiline mode. These three asser-
3455         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
3456         affect only the behaviour of the circumflex and dollar  metacharacters.         affect  only the behaviour of the circumflex and dollar metacharacters.
3457         However,  if the startoffset argument of pcre_exec() is non-zero, indi-         However, if the startoffset argument of pcre_exec() is non-zero,  indi-
3458         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
3459         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
3460         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
3461         the very end, whereas \z matches only at the end.         the very end, whereas \z matches only at the end.
3462    
3463         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
3464         the start point of the match, as specified by the startoffset  argument         the  start point of the match, as specified by the startoffset argument
3465         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
3466         non-zero. By calling pcre_exec() multiple times with appropriate  argu-         non-zero.  By calling pcre_exec() multiple times with appropriate argu-
3467         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-
3468         mentation where \G can be useful.         mentation where \G can be useful.
3469    
3470         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
3471         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
3472         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
3473         previously  matched  string was empty. Because PCRE does just one match         previously matched string was empty. Because PCRE does just  one  match
3474         at a time, it cannot reproduce this behaviour.         at a time, it cannot reproduce this behaviour.
3475    
3476         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
3477         anchored to the starting match position, and the "anchored" flag is set         anchored to the starting match position, and the "anchored" flag is set
3478         in the compiled regular expression.         in the compiled regular expression.
3479    
# Line 3301  BACKSLASH Line 3481  BACKSLASH
3481  CIRCUMFLEX AND DOLLAR  CIRCUMFLEX AND DOLLAR
3482    
3483         Outside a character class, in the default matching mode, the circumflex         Outside a character class, in the default matching mode, the circumflex
3484         character  is  an  assertion  that is true only if the current matching         character is an assertion that is true only  if  the  current  matching
3485         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-
3486         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
3487         PCRE_MULTILINE option is unset. Inside a  character  class,  circumflex         PCRE_MULTILINE  option  is  unset. Inside a character class, circumflex
3488         has an entirely different meaning (see below).         has an entirely different meaning (see below).
3489    
3490         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
3491         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
3492         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
3493         branch. If all possible alternatives start with a circumflex, that  is,         branch.  If all possible alternatives start with a circumflex, that is,
3494         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-
3495         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
3496         constructs that can cause a pattern to be anchored.)         constructs that can cause a pattern to be anchored.)
3497    
3498         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
3499         matching point is at the end of  the  subject  string,  or  immediately         matching  point  is  at  the  end of the subject string, or immediately
3500         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
3501         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
3502         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
3503         appears. Dollar has no special meaning in a character class.         appears. Dollar has no special meaning in a character class.
3504    
3505         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
3506         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
3507         compile time. This does not affect the \Z assertion.         compile time. This does not affect the \Z assertion.
3508    
3509         The meanings of the circumflex and dollar characters are changed if the         The meanings of the circumflex and dollar characters are changed if the
3510         PCRE_MULTILINE  option  is  set.  When  this  is the case, a circumflex         PCRE_MULTILINE option is set. When  this  is  the  case,  a  circumflex
3511         matches immediately after internal newlines as well as at the start  of         matches  immediately after internal newlines as well as at the start of
3512         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
3513         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
3514         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
3515         as the two-character sequence CRLF, isolated CR and  LF  characters  do         as  the  two-character  sequence CRLF, isolated CR and LF characters do
3516         not indicate newlines.         not indicate newlines.
3517    
3518         For  example, the pattern /^abc$/ matches the subject string "def\nabc"         For example, the pattern /^abc$/ matches the subject string  "def\nabc"
3519         (where \n represents a newline) in multiline mode, but  not  otherwise.         (where  \n  represents a newline) in multiline mode, but not otherwise.
3520         Consequently,  patterns  that  are anchored in single line mode because         Consequently, patterns that are anchored in single  line  mode  because
3521         all branches start with ^ are not anchored in  multiline  mode,  and  a         all  branches  start  with  ^ are not anchored in multiline mode, and a
3522         match  for  circumflex  is  possible  when  the startoffset argument of         match for circumflex is  possible  when  the  startoffset  argument  of
3523         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
3524         PCRE_MULTILINE is set.         PCRE_MULTILINE is set.
3525    
3526         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
3527         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
3528         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
3529         set.         set.
3530    
3531    
3532  FULL STOP (PERIOD, DOT)  FULL STOP (PERIOD, DOT)
3533    
3534         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-
3535         ter  in  the subject string except (by default) a character that signi-         ter in the subject string except (by default) a character  that  signi-
3536         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
3537         more than one byte long.         more than one byte long.
3538    
3539         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
3540         that character; when the two-character sequence CRLF is used, dot  does         that  character; when the two-character sequence CRLF is used, dot does
3541         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
3542         matches all characters (including isolated CRs and LFs). When any  Uni-         matches  all characters (including isolated CRs and LFs). When any Uni-
3543         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
3544         any of the other line ending characters.         any of the other line ending characters.
3545    
3546         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
3547         PCRE_DOTALL  option  is  set,  a dot matches any one character, without         PCRE_DOTALL option is set, a dot matches  any  one  character,  without
3548         exception. If the two-character sequence CRLF is present in the subject         exception. If the two-character sequence CRLF is present in the subject
3549         string, it takes two dots to match it.         string, it takes two dots to match it.
3550    
3551         The  handling of dot is entirely independent of the handling of circum-         The handling of dot is entirely independent of the handling of  circum-
3552         flex and dollar, the only relationship being  that  they  both  involve         flex  and  dollar,  the  only relationship being that they both involve
3553         newlines. Dot has no special meaning in a character class.         newlines. Dot has no special meaning in a character class.
3554    
3555    
3556  MATCHING A SINGLE BYTE  MATCHING A SINGLE BYTE
3557    
3558         Outside a character class, the escape sequence \C matches any one byte,         Outside a character class, the escape sequence \C matches any one byte,
3559         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
3560         line-ending  characters.  The  feature  is provided in Perl in order to         line-ending characters. The feature is provided in  Perl  in  order  to
3561         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-
3562         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-
3563         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
3564         avoided.         avoided.
3565    
3566         PCRE  does  not  allow \C to appear in lookbehind assertions (described         PCRE does not allow \C to appear in  lookbehind  assertions  (described
3567         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-
3568         late the length of the lookbehind.         late the length of the lookbehind.
3569    
3570    
# Line 3393  SQUARE BRACKETS AND CHARACTER CLASSES Line 3573  SQUARE BRACKETS AND CHARACTER CLASSES
3573         An opening square bracket introduces a character class, terminated by a         An opening square bracket introduces a character class, terminated by a
3574         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-
3575         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,
3576         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
3577         circumflex, if present) or escaped with a backslash.         circumflex, if present) or escaped with a backslash.
3578    
3579         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
3580         mode, the character may occupy more than one byte. A matched  character         mode,  the character may occupy more than one byte. A matched character
3581         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
3582         character in the class definition is a circumflex, in  which  case  the         character  in  the  class definition is a circumflex, in which case the
3583         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
3584         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
3585         not the first character, or escape it with a backslash.         not the first character, or escape it with a backslash.
3586    
3587         For  example, the character class [aeiou] matches any lower case vowel,         For example, the character class [aeiou] matches any lower case  vowel,
3588         while [^aeiou] matches any character that is not a  lower  case  vowel.         while  [^aeiou]  matches  any character that is not a lower case vowel.
3589         Note that a circumflex is just a convenient notation for specifying the         Note that a circumflex is just a convenient notation for specifying the
3590         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
3591         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-
3592         sumes a character from the subject string, and therefore  it  fails  if         sumes  a  character  from the subject string, and therefore it fails if
3593         the current pointer is at the end of the string.         the current pointer is at the end of the string.
3594    
3595         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
3596         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
3597         mechanism.         mechanism.
3598    
3599         When  caseless  matching  is set, any letters in a class represent both         When caseless matching is set, any letters in a  class  represent  both
3600         their upper case and lower case versions, so for  example,  a  caseless         their  upper  case  and lower case versions, so for example, a caseless
3601         [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
3602         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
3603         understands  the  concept  of case for characters whose values are less         understands the concept of case for characters whose  values  are  less
3604         than 128, so caseless matching is always possible. For characters  with         than  128, so caseless matching is always possible. For characters with
3605         higher  values,  the  concept  of case is supported if PCRE is compiled         higher values, the concept of case is supported  if  PCRE  is  compiled
3606         with Unicode property support, but not otherwise.  If you want  to  use         with  Unicode  property support, but not otherwise.  If you want to use
3607         caseless  matching  for  characters 128 and above, you must ensure that         caseless matching for characters 128 and above, you  must  ensure  that
3608         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
3609         support.         support.
3610    
3611         Characters  that  might  indicate  line breaks are never treated in any         Characters that might indicate line breaks are  never  treated  in  any
3612         special way  when  matching  character  classes,  whatever  line-ending         special  way  when  matching  character  classes,  whatever line-ending
3613         sequence  is  in  use,  and  whatever  setting  of  the PCRE_DOTALL and         sequence is in  use,  and  whatever  setting  of  the  PCRE_DOTALL  and
3614         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
3615         of these characters.         of these characters.
3616    
3617         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-
3618         ters in a character  class.  For  example,  [d-m]  matches  any  letter         ters  in  a  character  class.  For  example,  [d-m] matches any letter
3619         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
3620         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
3621         where  it cannot be interpreted as indicating a range, typically as the         where it cannot be interpreted as indicating a range, typically as  the
3622         first or last character in the class.         first or last character in the class.
3623    
3624         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-
3625         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
3626         two characters ("W" and "-") followed by a literal string "46]", so  it         two  characters ("W" and "-") followed by a literal string "46]", so it
3627         would  match  "W46]"  or  "-46]". However, if the "]" is escaped with a         would match "W46]" or "-46]". However, if the "]"  is  escaped  with  a
3628         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-
3629         preted  as a class containing a range followed by two other characters.         preted as a class containing a range followed by two other  characters.
3630         The octal or hexadecimal representation of "]" can also be used to  end         The  octal or hexadecimal representation of "]" can also be used to end
3631         a range.         a range.
3632    
3633         Ranges  operate in the collating sequence of character values. They can         Ranges operate in the collating sequence of character values. They  can
3634         also  be  used  for  characters  specified  numerically,  for   example         also   be  used  for  characters  specified  numerically,  for  example
3635         [\000-\037].  In UTF-8 mode, ranges can include characters whose values         [\000-\037]. In UTF-8 mode, ranges can include characters whose  values
3636         are greater than 255, for example [\x{100}-\x{2ff}].         are greater than 255, for example [\x{100}-\x{2ff}].
3637    
3638         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,
3639         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
3640         to [][\\^_`wxyzabc], matched caselessly,  and  in  non-UTF-8  mode,  if         to  [][\\^_`wxyzabc],  matched  caselessly,  and  in non-UTF-8 mode, if
3641         character  tables  for  a French locale are in use, [\xc8-\xcb] matches         character tables for a French locale are in  use,  [\xc8-\xcb]  matches
3642         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
3643         concept  of  case for characters with values greater than 128 only when         concept of case for characters with values greater than 128  only  when
3644         it is compiled with Unicode property support.         it is compiled with Unicode property support.
3645    
3646         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
3647         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
3648         class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-         class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-
3649         flex  can  conveniently  be used with the upper case character types to         flex can conveniently be used with the upper case  character  types  to
3650         specify a more restricted set of characters  than  the  matching  lower         specify  a  more  restricted  set of characters than the matching lower
3651         case  type.  For example, the class [^\W_] matches any letter or digit,         case type. For example, the class [^\W_] matches any letter  or  digit,
3652         but not underscore.         but not underscore.
3653    
3654         The only metacharacters that are recognized in  character  classes  are         The  only  metacharacters  that are recognized in character classes are
3655         backslash,  hyphen  (only  where  it can be interpreted as specifying a         backslash, hyphen (only where it can be  interpreted  as  specifying  a
3656         range), circumflex (only at the start), opening  square  bracket  (only         range),  circumflex  (only  at the start), opening square bracket (only
3657         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
3658         next section), and the terminating  closing  square  bracket.  However,         next  section),  and  the  terminating closing square bracket. However,
3659         escaping other non-alphanumeric characters does no harm.         escaping other non-alphanumeric characters does no harm.
3660    
3661    
3662  POSIX CHARACTER CLASSES  POSIX CHARACTER CLASSES
3663    
3664         Perl supports the POSIX notation for character classes. This uses names         Perl supports the POSIX notation for character classes. This uses names
3665         enclosed by [: and :] within the enclosing square brackets.  PCRE  also         enclosed  by  [: and :] within the enclosing square brackets. PCRE also
3666         supports this notation. For example,         supports this notation. For example,
3667    
3668           [01[:alpha:]%]           [01[:alpha:]%]
# Line 3505  POSIX CHARACTER CLASSES Line 3685  POSIX CHARACTER CLASSES
3685           word     "word" characters (same as \w)           word     "word" characters (same as \w)
3686           xdigit   hexadecimal digits           xdigit   hexadecimal digits
3687    
3688         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),
3689         and  space  (32). Notice that this list includes the VT character (code         and space (32). Notice that this list includes the VT  character  (code
3690         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
3691         Perl compatibility).         Perl compatibility).
3692    
3693         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
3694         from Perl 5.8. Another Perl extension is negation, which  is  indicated         from  Perl  5.8. Another Perl extension is negation, which is indicated
3695         by a ^ character after the colon. For example,         by a ^ character after the colon. For example,
3696    
3697           [12[:^digit:]]           [12[:^digit:]]
3698    
3699         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
3700         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but
3701         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.
3702    
# Line 3526  POSIX CHARACTER CLASSES Line 3706  POSIX CHARACTER CLASSES
3706    
3707  VERTICAL BAR  VERTICAL BAR
3708    
3709         Vertical  bar characters are used to separate alternative patterns. For         Vertical bar characters are used to separate alternative patterns.  For
3710         example, the pattern         example, the pattern
3711    
3712           gilbert|sullivan           gilbert|sullivan
3713    
3714         matches either "gilbert" or "sullivan". Any number of alternatives  may         matches  either "gilbert" or "sullivan". Any number of alternatives may
3715         appear,  and  an  empty  alternative  is  permitted (matching the empty         appear, and an empty  alternative  is  permitted  (matching  the  empty
3716         string). The matching process tries each alternative in turn, from left         string). The matching process tries each alternative in turn, from left
3717         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
3718         are within a subpattern (defined below), "succeeds" means matching  the         are  within a subpattern (defined below), "succeeds" means matching the
3719         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.
3720    
3721    
3722  INTERNAL OPTION SETTING  INTERNAL OPTION SETTING
3723    
3724         The settings of the  PCRE_CASELESS,  PCRE_MULTILINE,  PCRE_DOTALL,  and         The  settings  of  the  PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and
3725         PCRE_EXTENDED  options  can  be  changed  from  within the pattern by a         PCRE_EXTENDED options (which are Perl-compatible) can be  changed  from
3726         sequence of Perl option letters enclosed  between  "(?"  and  ")".  The         within  the  pattern  by  a  sequence  of  Perl option letters enclosed
3727         option letters are         between "(?" and ")".  The option letters are
3728    
3729           i  for PCRE_CASELESS           i  for PCRE_CASELESS
3730           m  for PCRE_MULTILINE           m  for PCRE_MULTILINE
# Line 3553  INTERNAL OPTION SETTING Line 3733  INTERNAL OPTION SETTING
3733    
3734         For example, (?im) sets caseless, multiline matching. It is also possi-         For example, (?im) sets caseless, multiline matching. It is also possi-
3735         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
3736         combined  setting and unsetting such as (?im-sx), which sets PCRE_CASE-         combined setting and unsetting such as (?im-sx), which sets  PCRE_CASE-
3737         LESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and  PCRE_EXTENDED,         LESS  and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED,
3738         is  also  permitted.  If  a  letter  appears  both before and after the         is also permitted. If a  letter  appears  both  before  and  after  the
3739         hyphen, the option is unset.         hyphen, the option is unset.
3740    
3741         When an option change occurs at top level (that is, not inside  subpat-         The  PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA
3742         tern  parentheses),  the change applies to the remainder of the pattern         can be changed in the same way as the Perl-compatible options by  using
3743           the characters J, U and X respectively.
3744    
3745           When  an option change occurs at top level (that is, not inside subpat-
3746           tern parentheses), the change applies to the remainder of  the  pattern
3747         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,
3748         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
3749         in data extracted by the pcre_fullinfo() function).         in data extracted by the pcre_fullinfo() function).
3750    
3751         An option change within a subpattern (see below for  a  description  of         An  option  change  within a subpattern (see below for a description of
3752         subpatterns) affects only that part of the current pattern that follows         subpatterns) affects only that part of the current pattern that follows
3753         it, so         it, so
3754    
3755           (a(?i)b)c           (a(?i)b)c
3756    
3757         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
3758         used).   By  this means, options can be made to have different settings         used).  By this means, options can be made to have  different  settings
3759         in different parts of the pattern. Any changes made in one  alternative         in  different parts of the pattern. Any changes made in one alternative
3760         do  carry  on  into subsequent branches within the same subpattern. For         do carry on into subsequent branches within the  same  subpattern.  For
3761         example,         example,
3762    
3763           (a(?i)b|c)           (a(?i)b|c)
3764    
3765         matches "ab", "aB", "c", and "C", even though  when  matching  "C"  the         matches  "ab",  "aB",  "c",  and "C", even though when matching "C" the
3766         first  branch  is  abandoned before the option setting. This is because         first branch is abandoned before the option setting.  This  is  because
3767         the effects of option settings happen at compile time. There  would  be         the  effects  of option settings happen at compile time. There would be
3768         some very weird behaviour otherwise.         some very weird behaviour otherwise.
3769    
3770         The  PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA         Note: There are other PCRE-specific options that  can  be  set  by  the
3771         can be changed in the same way as the Perl-compatible options by  using         application  when  the  compile  or match functions are called. In some
3772         the characters J, U and X respectively.         cases the pattern can contain special  leading  sequences  to  override
3773           what  the  application  has set or what has been defaulted. Details are
3774           given in the section entitled "Newline sequences" above.
3775    
3776    
3777  SUBPATTERNS  SUBPATTERNS
# Line 3597  SUBPATTERNS Line 3783  SUBPATTERNS
3783    
3784           cat(aract|erpillar|)           cat(aract|erpillar|)
3785    
3786         matches one of the words "cat", "cataract", or  "caterpillar".  Without         matches  one  of the words "cat", "cataract", or "caterpillar". Without
3787         the  parentheses,  it  would  match  "cataract", "erpillar" or an empty         the parentheses, it would match  "cataract",  "erpillar"  or  an  empty
3788         string.         string.
3789    
3790         2. It sets up the subpattern as  a  capturing  subpattern.  This  means         2.  It  sets  up  the  subpattern as a capturing subpattern. This means
3791         that,  when  the  whole  pattern  matches,  that portion of the subject         that, when the whole pattern  matches,  that  portion  of  the  subject
3792         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
3793         ovector  argument  of pcre_exec(). Opening parentheses are counted from         ovector argument of pcre_exec(). Opening parentheses are  counted  from
3794         left to right (starting from 1) to obtain  numbers  for  the  capturing         left  to  right  (starting  from 1) to obtain numbers for the capturing
3795         subpatterns.         subpatterns.
3796    
3797         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-
3798         tern         tern
3799    
3800           the ((red|white) (king|queen))           the ((red|white) (king|queen))
# Line 3616  SUBPATTERNS Line 3802  SUBPATTERNS
3802         the captured substrings are "red king", "red", and "king", and are num-         the captured substrings are "red king", "red", and "king", and are num-
3803         bered 1, 2, and 3, respectively.         bered 1, 2, and 3, respectively.
3804    
3805         The  fact  that  plain  parentheses  fulfil two functions is not always         The fact that plain parentheses fulfil  two  functions  is  not  always
3806         helpful.  There are often times when a grouping subpattern is  required         helpful.   There are often times when a grouping subpattern is required
3807         without  a capturing requirement. If an opening parenthesis is followed         without a capturing requirement. If an opening parenthesis is  followed
3808         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-
3809         ing,  and  is  not  counted when computing the number of any subsequent         ing, and is not counted when computing the  number  of  any  subsequent
3810         capturing subpatterns. For example, if the string "the white queen"  is         capturing  subpatterns. For example, if the string "the white queen" is
3811         matched against the pattern         matched against the pattern
3812    
3813           the ((?:red|white) (king|queen))           the ((?:red|white) (king|queen))
# Line 3629  SUBPATTERNS Line 3815  SUBPATTERNS
3815         the captured substrings are "white queen" and "queen", and are numbered         the captured substrings are "white queen" and "queen", and are numbered
3816         1 and 2. The maximum number of capturing subpatterns is 65535.         1 and 2. The maximum number of capturing subpatterns is 65535.
3817    
3818         As a convenient shorthand, if any option settings are required  at  the         As  a  convenient shorthand, if any option settings are required at the
3819         start  of  a  non-capturing  subpattern,  the option letters may appear         start of a non-capturing subpattern,  the  option  letters  may  appear
3820         between the "?" and the ":". Thus the two patterns         between the "?" and the ":". Thus the two patterns
3821    
3822           (?i:saturday|sunday)           (?i:saturday|sunday)
3823           (?:(?i)saturday|sunday)           (?:(?i)saturday|sunday)
3824    
3825         match exactly the same set of strings. Because alternative branches are         match exactly the same set of strings. Because alternative branches are
3826         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
3827         the subpattern is reached, an option setting in one branch does  affect         the  subpattern is reached, an option setting in one branch does affect
3828         subsequent  branches,  so  the above patterns match "SUNDAY" as well as         subsequent branches, so the above patterns match "SUNDAY"  as  well  as
3829         "Saturday".         "Saturday".
3830    
3831    
3832  DUPLICATE SUBPATTERN NUMBERS  DUPLICATE SUBPATTERN NUMBERS
3833    
3834         Perl 5.10 introduced a feature whereby each alternative in a subpattern         Perl 5.10 introduced a feature whereby each alternative in a subpattern
3835         uses  the same numbers for its capturing parentheses. Such a subpattern         uses the same numbers for its capturing parentheses. Such a  subpattern
3836         starts with (?| and is itself a non-capturing subpattern. For  example,         starts  with (?| and is itself a non-capturing subpattern. For example,
3837         consider this pattern:         consider this pattern:
3838    
3839           (?|(Sat)ur|(Sun))day           (?|(Sat)ur|(Sun))day
3840    
3841         Because  the two alternatives are inside a (?| group, both sets of cap-         Because the two alternatives are inside a (?| group, both sets of  cap-
3842         turing parentheses are numbered one. Thus, when  the  pattern  matches,         turing  parentheses  are  numbered one. Thus, when the pattern matches,
3843         you  can  look  at captured substring number one, whichever alternative         you can look at captured substring number  one,  whichever  alternative
3844         matched. This construct is useful when you want to  capture  part,  but         matched.  This  construct  is useful when you want to capture part, but
3845         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-
3846         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
3847         each  branch. The numbers of any capturing buffers that follow the sub-         each branch. The numbers of any capturing buffers that follow the  sub-
3848         pattern start after the highest number used in any branch. The  follow-         pattern  start after the highest number used in any branch. The follow-
3849         ing  example  is taken from the Perl documentation.  The numbers under-         ing example is taken from the Perl documentation.  The  numbers  under-
3850         neath show in which buffer the captured content will be stored.         neath show in which buffer the captured content will be stored.
3851    
3852           # before  ---------------branch-reset----------- after           # before  ---------------branch-reset----------- after
3853           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
3854           # 1            2         2  3        2     3     4           # 1            2         2  3        2     3     4
3855    
3856         A backreference or a recursive call to  a  numbered  subpattern  always         A  backreference  or  a  recursive call to a numbered subpattern always
3857         refers to the first one in the pattern with the given number.         refers to the first one in the pattern with the given number.
3858    
3859         An  alternative approach to using this "branch reset" feature is to use         An alternative approach to using this "branch reset" feature is to  use
3860         duplicate named subpatterns, as described in the next section.         duplicate named subpatterns, as described in the next section.
3861    
3862    
3863  NAMED SUBPATTERNS  NAMED SUBPATTERNS
3864    
3865         Identifying capturing parentheses by number is simple, but  it  can  be         Identifying  capturing  parentheses  by number is simple, but it can be
3866         very  hard  to keep track of the numbers in complicated regular expres-         very hard to keep track of the numbers in complicated  regular  expres-
3867         sions. Furthermore, if an  expression  is  modified,  the  numbers  may         sions.  Furthermore,  if  an  expression  is  modified, the numbers may
3868         change.  To help with this difficulty, PCRE supports the naming of sub-         change. To help with this difficulty, PCRE supports the naming of  sub-
3869         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
3870         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
3871         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-
3872         tax.         tax.
3873    
3874         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>...)
3875         or (?'name'...) as in Perl, or (?P<name>...) as in  Python.  References         or  (?'name'...)  as in Perl, or (?P<name>...) as in Python. References
3876         to capturing parentheses from other parts of the pattern, such as back-         to capturing parentheses from other parts of the pattern, such as back-
3877         references, recursion, and conditions, can be made by name as  well  as         references,  recursion,  and conditions, can be made by name as well as
3878         by number.         by number.
3879    
3880         Names  consist  of  up  to  32 alphanumeric characters and underscores.         Names consist of up to  32  alphanumeric  characters  and  underscores.
3881         Named capturing parentheses are still  allocated  numbers  as  well  as         Named  capturing  parentheses  are  still  allocated numbers as well as
3882         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
3883         function calls for extracting the name-to-number translation table from         function calls for extracting the name-to-number translation table from
3884         a compiled pattern. There is also a convenience function for extracting         a compiled pattern. There is also a convenience function for extracting
3885         a captured substring by name.         a captured substring by name.
3886    
3887         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
3888         to relax this constraint by setting the PCRE_DUPNAMES option at compile         to relax this constraint by setting the PCRE_DUPNAMES option at compile
3889         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
3890         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
3891         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
3892         both cases you want to extract the abbreviation. This pattern (ignoring         both cases you want to extract the abbreviation. This pattern (ignoring
3893         the line breaks) does the job:         the line breaks) does the job:
3894    
# Line 3712  NAMED SUBPATTERNS Line 3898  NAMED SUBPATTERNS
3898           (?<DN>Thu)(?:rsday)?|           (?<DN>Thu)(?:rsday)?|
3899           (?<DN>Sat)(?:urday)?           (?<DN>Sat)(?:urday)?
3900    
3901         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
3902         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
3903         reset" subpattern, as described in the previous section.)         reset" subpattern, as described in the previous section.)
3904    
3905         The convenience function for extracting the data by  name  returns  the         The  convenience  function  for extracting the data by name returns the
3906         substring  for  the first (and in this example, the only) subpattern of         substring for the first (and in this example, the only)  subpattern  of
3907         that name that matched. This saves searching  to  find  which  numbered         that  name  that  matched.  This saves searching to find which numbered
3908         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-
3909         pattern from elsewhere in the pattern, the one that corresponds to  the         pattern  from elsewhere in the pattern, the one that corresponds to the
3910         lowest  number  is used. For further details of the interfaces for han-         lowest number is used. For further details of the interfaces  for  han-
3911         dling named subpatterns, see the pcreapi documentation.         dling named subpatterns, see the pcreapi documentation.
3912    
3913    
3914  REPETITION  REPETITION
3915    
3916         Repetition is specified by quantifiers, which can  follow  any  of  the         Repetition  is  specified  by  quantifiers, which can follow any of the
3917         following items:         following items:
3918    
3919           a literal data character           a literal data character
# Line 3740  REPETITION Line 3926  REPETITION
3926           a back reference (see next section)           a back reference (see next section)
3927           a parenthesized subpattern (unless it is an assertion)           a parenthesized subpattern (unless it is an assertion)
3928    
3929         The  general repetition quantifier specifies a minimum and maximum num-         The general repetition quantifier specifies a minimum and maximum  num-
3930         ber of permitted matches, by giving the two numbers in  curly  brackets         ber  of  permitted matches, by giving the two numbers in curly brackets
3931         (braces),  separated  by  a comma. The numbers must be less than 65536,         (braces), separated by a comma. The numbers must be  less  than  65536,
3932         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:
3933    
3934           z{2,4}           z{2,4}
3935    
3936         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
3937         special  character.  If  the second number is omitted, but the comma is         special character. If the second number is omitted, but  the  comma  is
3938         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
3939         are  both omitted, the quantifier specifies an exact number of required         are both omitted, the quantifier specifies an exact number of  required
3940         matches. Thus         matches. Thus
3941    
3942           [aeiou]{3,}           [aeiou]{3,}
# Line 3759  REPETITION Line 3945  REPETITION
3945    
3946           \d{8}           \d{8}
3947    
3948         matches exactly 8 digits. An opening curly bracket that  appears  in  a         matches  exactly  8  digits. An opening curly bracket that appears in a
3949         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
3950         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-
3951         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.
3952    
3953         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
3954         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-
3955         acters, each of which is represented by a two-byte sequence. Similarly,         acters, each of which is represented by a two-byte sequence. Similarly,
3956         when Unicode property support is available, \X{3} matches three Unicode         when Unicode property support is available, \X{3} matches three Unicode
3957         extended sequences, each of which may be several bytes long  (and  they         extended  sequences,  each of which may be several bytes long (and they
3958         may be of different lengths).         may be of different lengths).
3959    
3960         The quantifier {0} is permitted, causing the expression to behave as if         The quantifier {0} is permitted, causing the expression to behave as if
3961         the previous item and the quantifier were not present.         the previous item and the quantifier were not present.
3962    
3963         For convenience, the three most common quantifiers have  single-charac-         For  convenience, the three most common quantifiers have single-charac-
3964         ter abbreviations:         ter abbreviations:
3965    
3966           *    is equivalent to {0,}           *    is equivalent to {0,}
3967           +    is equivalent to {1,}           +    is equivalent to {1,}
3968           ?    is equivalent to {0,1}           ?    is equivalent to {0,1}
3969    
3970         It  is  possible  to construct infinite loops by following a subpattern         It is possible to construct infinite loops by  following  a  subpattern
3971         that can match no characters with a quantifier that has no upper limit,         that can match no characters with a quantifier that has no upper limit,
3972         for example:         for example:
3973    
3974           (a?)*           (a?)*
3975    
3976         Earlier versions of Perl and PCRE used to give an error at compile time         Earlier versions of Perl and PCRE used to give an error at compile time
3977         for such patterns. However, because there are cases where this  can  be         for  such  patterns. However, because there are cases where this can be
3978         useful,  such  patterns  are now accepted, but if any repetition of the         useful, such patterns are now accepted, but if any  repetition  of  the
3979         subpattern does in fact match no characters, the loop is forcibly  bro-         subpattern  does in fact match no characters, the loop is forcibly bro-
3980         ken.         ken.
3981    
3982         By  default,  the quantifiers are "greedy", that is, they match as much         By default, the quantifiers are "greedy", that is, they match  as  much
3983         as possible (up to the maximum  number  of  permitted  times),  without         as  possible  (up  to  the  maximum number of permitted times), without
3984         causing  the  rest of the pattern to fail. The classic example of where         causing the rest of the pattern to fail. The classic example  of  where
3985         this gives problems is in trying to match comments in C programs. These         this gives problems is in trying to match comments in C programs. These
3986         appear  between  /*  and  */ and within the comment, individual * and /         appear between /* and */ and within the comment,  individual  *  and  /
3987         characters may appear. An attempt to match C comments by  applying  the         characters  may  appear. An attempt to match C comments by applying the
3988         pattern         pattern
3989    
3990           /\*.*\*/           /\*.*\*/
# Line 3807  REPETITION Line 3993  REPETITION
3993    
3994           /* first comment */  not comment  /* second comment */           /* first comment */  not comment  /* second comment */
3995    
3996         fails,  because it matches the entire string owing to the greediness of         fails, because it matches the entire string owing to the greediness  of
3997         the .*  item.         the .*  item.
3998    
3999         However, if a quantifier is followed by a question mark, it  ceases  to         However,  if  a quantifier is followed by a question mark, it ceases to
4000         be greedy, and instead matches the minimum number of times possible, so         be greedy, and instead matches the minimum number of times possible, so
4001         the pattern         the pattern
4002    
4003           /\*.*?\*/           /\*.*?\*/
4004    
4005         does the right thing with the C comments. The meaning  of  the  various         does  the  right  thing with the C comments. The meaning of the various
4006         quantifiers  is  not  otherwise  changed,  just the preferred number of         quantifiers is not otherwise changed,  just  the  preferred  number  of
4007         matches.  Do not confuse this use of question mark with its  use  as  a         matches.   Do  not  confuse this use of question mark with its use as a
4008         quantifier  in its own right. Because it has two uses, it can sometimes         quantifier in its own right. Because it has two uses, it can  sometimes
4009         appear doubled, as in         appear doubled, as in
4010    
4011           \d??\d           \d??\d
# Line 3827  REPETITION Line 4013  REPETITION
4013         which matches one digit by preference, but can match two if that is the         which matches one digit by preference, but can match two if that is the
4014         only way the rest of the pattern matches.         only way the rest of the pattern matches.
4015    
4016         If  the PCRE_UNGREEDY option is set (an option that is not available in         If the PCRE_UNGREEDY option is set (an option that is not available  in
4017         Perl), the quantifiers are not greedy by default, but  individual  ones         Perl),  the  quantifiers are not greedy by default, but individual ones
4018         can  be  made  greedy  by following them with a question mark. In other         can be made greedy by following them with a  question  mark.  In  other
4019         words, it inverts the default behaviour.         words, it inverts the default behaviour.
4020    
4021         When a parenthesized subpattern is quantified  with  a  minimum  repeat         When  a  parenthesized  subpattern  is quantified with a minimum repeat
4022         count  that is greater than 1 or with a limited maximum, more memory is         count that is greater than 1 or with a limited maximum, more memory  is
4023         required for the compiled pattern, in proportion to  the  size  of  the         required  for  the  compiled  pattern, in proportion to the size of the
4024         minimum or maximum.         minimum or maximum.
4025    
4026         If a pattern starts with .* or .{0,} and the PCRE_DOTALL option (equiv-         If a pattern starts with .* or .{0,} and the PCRE_DOTALL option (equiv-
4027         alent to Perl's /s) is set, thus allowing the dot  to  match  newlines,         alent  to  Perl's  /s) is set, thus allowing the dot to match newlines,
4028         the  pattern  is  implicitly anchored, because whatever follows will be         the pattern is implicitly anchored, because whatever  follows  will  be
4029         tried against every character position in the subject string, so  there         tried  against every character position in the subject string, so there
4030         is  no  point  in  retrying the overall match at any position after the         is no point in retrying the overall match at  any  position  after  the
4031         first. PCRE normally treats such a pattern as though it  were  preceded         first.  PCRE  normally treats such a pattern as though it were preceded
4032         by \A.         by \A.
4033    
4034         In  cases  where  it  is known that the subject string contains no new-         In cases where it is known that the subject  string  contains  no  new-
4035         lines, it is worth setting PCRE_DOTALL in order to  obtain  this  opti-         lines,  it  is  worth setting PCRE_DOTALL in order to obtain this opti-
4036         mization, or alternatively using ^ to indicate anchoring explicitly.         mization, or alternatively using ^ to indicate anchoring explicitly.
4037    
4038         However,  there is one situation where the optimization cannot be used.         However, there is one situation where the optimization cannot be  used.
4039         When .*  is inside capturing parentheses that  are  the  subject  of  a         When  .*   is  inside  capturing  parentheses that are the subject of a
4040         backreference  elsewhere  in the pattern, a match at the start may fail         backreference elsewhere in the pattern, a match at the start  may  fail
4041         where a later one succeeds. Consider, for example:         where a later one succeeds. Consider, for example:
4042    
4043           (.*)abc\1           (.*)abc\1
4044    
4045         If the subject is "xyz123abc123" the match point is the fourth  charac-         If  the subject is "xyz123abc123" the match point is the fourth charac-
4046         ter. For this reason, such a pattern is not implicitly anchored.         ter. For this reason, such a pattern is not implicitly anchored.
4047    
4048         When a capturing subpattern is repeated, the value captured is the sub-         When a capturing subpattern is repeated, the value captured is the sub-
# Line 3865  REPETITION Line 4051  REPETITION
4051           (tweedle[dume]{3}\s*)+           (tweedle[dume]{3}\s*)+
4052    
4053         has matched "tweedledum tweedledee" the value of the captured substring         has matched "tweedledum tweedledee" the value of the captured substring
4054         is  "tweedledee".  However,  if there are nested capturing subpatterns,         is "tweedledee". However, if there are  nested  capturing  subpatterns,
4055         the corresponding captured values may have been set in previous  itera-         the  corresponding captured values may have been set in previous itera-
4056         tions. For example, after         tions. For example, after
4057    
4058           /(a|(b))+/           /(a|(b))+/
# Line 3876  REPETITION Line 4062  REPETITION
4062    
4063  ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS  ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS
4064    
4065         With  both  maximizing ("greedy") and minimizing ("ungreedy" or "lazy")         With both maximizing ("greedy") and minimizing ("ungreedy"  or  "lazy")
4066         repetition, failure of what follows normally causes the  repeated  item         repetition,  failure  of what follows normally causes the repeated item
4067         to  be  re-evaluated to see if a different number of repeats allows the         to be re-evaluated to see if a different number of repeats  allows  the
4068         rest of the pattern to match. Sometimes it is useful to  prevent  this,         rest  of  the pattern to match. Sometimes it is useful to prevent this,
4069         either  to  change the nature of the match, or to cause it fail earlier         either to change the nature of the match, or to cause it  fail  earlier
4070         than it otherwise might, when the author of the pattern knows there  is         than  it otherwise might, when the author of the pattern knows there is
4071         no point in carrying on.         no point in carrying on.
4072    
4073         Consider,  for  example, the pattern \d+foo when applied to the subject         Consider, for example, the pattern \d+foo when applied to  the  subject
4074         line         line
4075    
4076           123456bar           123456bar
4077    
4078         After matching all 6 digits and then failing to match "foo", the normal         After matching all 6 digits and then failing to match "foo", the normal
4079         action  of  the matcher is to try again with only 5 digits matching the         action of the matcher is to try again with only 5 digits  matching  the
4080         \d+ item, and then with  4,  and  so  on,  before  ultimately  failing.         \d+  item,  and  then  with  4,  and  so on, before ultimately failing.
4081         "Atomic  grouping"  (a  term taken from Jeffrey Friedl's book) provides         "Atomic grouping" (a term taken from Jeffrey  Friedl's  book)  provides
4082         the means for specifying that once a subpattern has matched, it is  not         the  means for specifying that once a subpattern has matched, it is not
4083         to be re-evaluated in this way.         to be re-evaluated in this way.
4084    
4085         If  we  use atomic grouping for the previous example, the matcher gives         If we use atomic grouping for the previous example, the  matcher  gives
4086         up immediately on failing to match "foo" the first time.  The  notation         up  immediately  on failing to match "foo" the first time. The notation
4087         is a kind of special parenthesis, starting with (?> as in this example:         is a kind of special parenthesis, starting with (?> as in this example:
4088    
4089           (?>\d+)foo           (?>\d+)foo
4090    
4091         This kind of parenthesis "locks up" the  part of the  pattern  it  con-         This  kind  of  parenthesis "locks up" the  part of the pattern it con-
4092         tains  once  it  has matched, and a failure further into the pattern is         tains once it has matched, and a failure further into  the  pattern  is
4093         prevented from backtracking into it. Backtracking past it  to  previous         prevented  from  backtracking into it. Backtracking past it to previous
4094         items, however, works as normal.         items, however, works as normal.
4095    
4096         An  alternative  description  is that a subpattern of this type matches         An alternative description is that a subpattern of  this  type  matches
4097         the string of characters that an  identical  standalone  pattern  would         the  string  of  characters  that an identical standalone pattern would
4098         match, if anchored at the current point in the subject string.         match, if anchored at the current point in the subject string.
4099    
4100         Atomic grouping subpatterns are not capturing subpatterns. Simple cases         Atomic grouping subpatterns are not capturing subpatterns. Simple cases
4101         such as the above example can be thought of as a maximizing repeat that         such as the above example can be thought of as a maximizing repeat that
4102         must  swallow  everything  it can. So, while both \d+ and \d+? are pre-         must swallow everything it can. So, while both \d+ and  \d+?  are  pre-
4103         pared to adjust the number of digits they match in order  to  make  the         pared  to  adjust  the number of digits they match in order to make the
4104         rest of the pattern match, (?>\d+) can only match an entire sequence of         rest of the pattern match, (?>\d+) can only match an entire sequence of
4105         digits.         digits.
4106    
4107         Atomic groups in general can of course contain arbitrarily  complicated         Atomic  groups in general can of course contain arbitrarily complicated
4108         subpatterns,  and  can  be  nested. However, when the subpattern for an         subpatterns, and can be nested. However, when  the  subpattern  for  an
4109         atomic group is just a single repeated item, as in the example above, a         atomic group is just a single repeated item, as in the example above, a
4110         simpler  notation,  called  a "possessive quantifier" can be used. This         simpler notation, called a "possessive quantifier" can  be  used.  This
4111         consists of an additional + character  following  a  quantifier.  Using         consists  of  an  additional  + character following a quantifier. Using
4112         this notation, the previous example can be rewritten as         this notation, the previous example can be rewritten as
4113    
4114           \d++foo           \d++foo
# Line 3932  ATOMIC GROUPING AND POSSESSIVE QUANTIFIE Line 4118  ATOMIC GROUPING AND POSSESSIVE QUANTIFIE
4118    
4119           (abc|xyz){2,3}+           (abc|xyz){2,3}+
4120    
4121         Possessive  quantifiers  are  always  greedy;  the   setting   of   the         Possessive   quantifiers   are   always  greedy;  the  setting  of  the
4122         PCRE_UNGREEDY option is ignored. They are a convenient notation for the         PCRE_UNGREEDY option is ignored. They are a convenient notation for the
4123         simpler forms of atomic group. However, there is no difference  in  the         simpler  forms  of atomic group. However, there is no difference in the
4124         meaning  of  a  possessive  quantifier and the equivalent atomic group,         meaning of a possessive quantifier and  the  equivalent  atomic  group,
4125         though there may be a performance  difference;  possessive  quantifiers         though  there  may  be a performance difference; possessive quantifiers
4126         should be slightly faster.         should be slightly faster.
4127    
4128         The  possessive  quantifier syntax is an extension to the Perl 5.8 syn-         The possessive quantifier syntax is an extension to the Perl  5.8  syn-
4129         tax.  Jeffrey Friedl originated the idea (and the name)  in  the  first         tax.   Jeffrey  Friedl  originated the idea (and the name) in the first
4130         edition of his book. Mike McCloskey liked it, so implemented it when he         edition of his book. Mike McCloskey liked it, so implemented it when he
4131         built Sun's Java package, and PCRE copied it from there. It  ultimately         built  Sun's Java package, and PCRE copied it from there. It ultimately
4132         found its way into Perl at release 5.10.         found its way into Perl at release 5.10.
4133    
4134         PCRE has an optimization that automatically "possessifies" certain sim-         PCRE has an optimization that automatically "possessifies" certain sim-
4135         ple pattern constructs. For example, the sequence  A+B  is  treated  as         ple  pattern  constructs.  For  example, the sequence A+B is treated as
4136         A++B  because  there is no point in backtracking into a sequence of A's         A++B because there is no point in backtracking into a sequence  of  A's
4137         when B must follow.         when B must follow.
4138    
4139         When a pattern contains an unlimited repeat inside  a  subpattern  that         When  a  pattern  contains an unlimited repeat inside a subpattern that
4140         can  itself  be  repeated  an  unlimited number of times, the use of an         can itself be repeated an unlimited number of  times,  the  use  of  an
4141         atomic group is the only way to avoid some  failing  matches  taking  a         atomic  group  is  the  only way to avoid some failing matches taking a
4142         very long time indeed. The pattern         very long time indeed. The pattern
4143    
4144           (\D+|<\d+>)*[!?]           (\D+|<\d+>)*[!?]
4145    
4146         matches  an  unlimited number of substrings that either consist of non-         matches an unlimited number of substrings that either consist  of  non-
4147         digits, or digits enclosed in <>, followed by either ! or  ?.  When  it         digits,  or  digits  enclosed in <>, followed by either ! or ?. When it
4148         matches, it runs quickly. However, if it is applied to         matches, it runs quickly. However, if it is applied to
4149    
4150           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
4151    
4152         it  takes  a  long  time  before reporting failure. This is because the         it takes a long time before reporting  failure.  This  is  because  the
4153         string can be divided between the internal \D+ repeat and the  external         string  can be divided between the internal \D+ repeat and the external
4154         *  repeat  in  a  large  number of ways, and all have to be tried. (The         * repeat in a large number of ways, and all  have  to  be  tried.  (The
4155         example uses [!?] rather than a single character at  the  end,  because         example  uses  [!?]  rather than a single character at the end, because
4156         both  PCRE  and  Perl have an optimization that allows for fast failure         both PCRE and Perl have an optimization that allows  for  fast  failure
4157         when a single character is used. They remember the last single  charac-         when  a single character is used. They remember the last single charac-
4158         ter  that  is required for a match, and fail early if it is not present         ter that is required for a match, and fail early if it is  not  present
4159         in the string.) If the pattern is changed so that  it  uses  an  atomic         in  the  string.)  If  the pattern is changed so that it uses an atomic
4160         group, like this:         group, like this:
4161    
4162           ((?>\D+)|<\d+>)*[!?]           ((?>\D+)|<\d+>)*[!?]
4163    
4164         sequences  of non-digits cannot be broken, and failure happens quickly.         sequences of non-digits cannot be broken, and failure happens  quickly.
4165    
4166    
4167  BACK REFERENCES  BACK REFERENCES
4168    
4169         Outside a character class, a backslash followed by a digit greater than         Outside a character class, a backslash followed by a digit greater than
4170         0 (and possibly further digits) is a back reference to a capturing sub-         0 (and possibly further digits) is a back reference to a capturing sub-
4171         pattern earlier (that is, to its left) in the pattern,  provided  there         pattern  earlier  (that is, to its left) in the pattern, provided there
4172         have been that many previous capturing left parentheses.         have been that many previous capturing left parentheses.
4173    
4174         However, if the decimal number following the backslash is less than 10,         However, if the decimal number following the backslash is less than 10,
4175         it is always taken as a back reference, and causes  an  error  only  if         it  is  always  taken  as a back reference, and causes an error only if
4176         there  are  not that many capturing left parentheses in the entire pat-         there are not that many capturing left parentheses in the  entire  pat-
4177         tern. In other words, the parentheses that are referenced need  not  be         tern.  In  other words, the parentheses that are referenced need not be
4178         to  the left of the reference for numbers less than 10. A "forward back         to the left of the reference for numbers less than 10. A "forward  back
4179         reference" of this type can make sense when a  repetition  is  involved         reference"  of  this  type can make sense when a repetition is involved
4180         and  the  subpattern to the right has participated in an earlier itera-         and the subpattern to the right has participated in an  earlier  itera-
4181         tion.         tion.
4182    
4183         It is not possible to have a numerical "forward back  reference"  to  a         It  is  not  possible to have a numerical "forward back reference" to a
4184         subpattern  whose  number  is  10  or  more using this syntax because a         subpattern whose number is 10 or  more  using  this  syntax  because  a
4185         sequence such as \50 is interpreted as a character  defined  in  octal.         sequence  such  as  \50 is interpreted as a character defined in octal.
4186         See the subsection entitled "Non-printing characters" above for further         See the subsection entitled "Non-printing characters" above for further
4187         details of the handling of digits following a backslash.  There  is  no         details  of  the  handling of digits following a backslash. There is no
4188         such  problem  when named parentheses are used. A back reference to any         such problem when named parentheses are used. A back reference  to  any
4189         subpattern is possible using named parentheses (see below).         subpattern is possible using named parentheses (see below).
4190    
4191         Another way of avoiding the ambiguity inherent in  the  use  of  digits         Another  way  of  avoiding  the ambiguity inherent in the use of digits
4192         following a backslash is to use the \g escape sequence, which is a fea-         following a backslash is to use the \g escape sequence, which is a fea-
4193         ture introduced in Perl 5.10.  This  escape  must  be  followed  by  an         ture  introduced  in  Perl  5.10.  This  escape  must be followed by an
4194         unsigned  number  or  a negative number, optionally enclosed in braces.         unsigned number or a negative number, optionally  enclosed  in  braces.
4195         These examples are all identical:         These examples are all identical:
4196    
4197           (ring), \1           (ring), \1
4198           (ring), \g1           (ring), \g1
4199           (ring), \g{1}           (ring), \g{1}
4200    
4201         An unsigned number specifies an absolute reference without the  ambigu-         An  unsigned number specifies an absolute reference without the ambigu-
4202         ity that is present in the older syntax. It is also useful when literal         ity that is present in the older syntax. It is also useful when literal
4203         digits follow the reference. A negative number is a relative reference.         digits follow the reference. A negative number is a relative reference.
4204         Consider this example:         Consider this example:
# Line 4020  BACK REFERENCES Line 4206  BACK REFERENCES
4206           (abc(def)ghi)\g{-1}           (abc(def)ghi)\g{-1}
4207    
4208         The sequence \g{-1} is a reference to the most recently started captur-         The sequence \g{-1} is a reference to the most recently started captur-
4209         ing subpattern before \g, that is, is it equivalent to  \2.  Similarly,         ing  subpattern  before \g, that is, is it equivalent to \2. Similarly,
4210         \g{-2} would be equivalent to \1. The use of relative references can be         \g{-2} would be equivalent to \1. The use of relative references can be
4211         helpful in long patterns, and also in  patterns  that  are  created  by         helpful  in  long  patterns,  and  also in patterns that are created by
4212         joining together fragments that contain references within themselves.         joining together fragments that contain references within themselves.
4213    
4214         A  back  reference matches whatever actually matched the capturing sub-         A back reference matches whatever actually matched the  capturing  sub-
4215         pattern in the current subject string, rather  than  anything  matching         pattern  in  the  current subject string, rather than anything matching
4216         the subpattern itself (see "Subpatterns as subroutines" below for a way         the subpattern itself (see "Subpatterns as subroutines" below for a way
4217         of doing that). So the pattern         of doing that). So the pattern
4218    
4219           (sens|respons)e and \1ibility           (sens|respons)e and \1ibility
4220    
4221         matches "sense and sensibility" and "response and responsibility",  but         matches  "sense and sensibility" and "response and responsibility", but
4222         not  "sense and responsibility". If caseful matching is in force at the         not "sense and responsibility". If caseful matching is in force at  the
4223         time of the back reference, the case of letters is relevant. For  exam-         time  of the back reference, the case of letters is relevant. For exam-
4224         ple,         ple,
4225    
4226           ((?i)rah)\s+\1           ((?i)rah)\s+\1
4227    
4228         matches  "rah  rah"  and  "RAH RAH", but not "RAH rah", even though the         matches "rah rah" and "RAH RAH", but not "RAH  rah",  even  though  the
4229         original capturing subpattern is matched caselessly.         original capturing subpattern is matched caselessly.
4230    
4231         There are several different ways of writing back  references  to  named         There  are  several  different ways of writing back references to named
4232         subpatterns.  The  .NET syntax \k{name} and the Perl syntax \k<name> or         subpatterns. The .NET syntax \k{name} and the Perl syntax  \k<name>  or
4233         \k'name' are supported, as is the Python syntax (?P=name). Perl  5.10's         \k'name'  are supported, as is the Python syntax (?P=name). Perl 5.10's
4234         unified back reference syntax, in which \g can be used for both numeric         unified back reference syntax, in which \g can be used for both numeric
4235         and named references, is also supported. We  could  rewrite  the  above         and  named  references,  is  also supported. We could rewrite the above
4236         example in any of the following ways:         example in any of the following ways:
4237    
4238           (?<p1>(?i)rah)\s+\k<p1>           (?<p1>(?i)rah)\s+\k<p1>
# Line 4054  BACK REFERENCES Line 4240  BACK REFERENCES
4240           (?P<p1>(?i)rah)\s+(?P=p1)           (?P<p1>(?i)rah)\s+(?P=p1)
4241           (?<p1>(?i)rah)\s+\g{p1}           (?<p1>(?i)rah)\s+\g{p1}
4242    
4243         A  subpattern  that  is  referenced  by  name may appear in the pattern         A subpattern that is referenced by  name  may  appear  in  the  pattern
4244         before or after the reference.         before or after the reference.
4245    
4246         There may be more than one back reference to the same subpattern. If  a         There  may be more than one back reference to the same subpattern. If a
4247         subpattern  has  not actually been used in a particular match, any back         subpattern has not actually been used in a particular match,  any  back
4248         references to it always fail. For example, the pattern         references to it always fail. For example, the pattern
4249    
4250           (a|(bc))\2           (a|(bc))\2
4251    
4252         always fails if it starts to match "a" rather than "bc". Because  there         always  fails if it starts to match "a" rather than "bc". Because there
4253         may  be  many  capturing parentheses in a pattern, all digits following         may be many capturing parentheses in a pattern,  all  digits  following
4254         the backslash are taken as part of a potential back  reference  number.         the  backslash  are taken as part of a potential back reference number.
4255         If the pattern continues with a digit character, some delimiter must be         If the pattern continues with a digit character, some delimiter must be
4256         used to terminate the back reference. If the  PCRE_EXTENDED  option  is         used  to  terminate  the back reference. If the PCRE_EXTENDED option is
4257         set,  this  can  be  whitespace.  Otherwise an empty comment (see "Com-         set, this can be whitespace.  Otherwise an  empty  comment  (see  "Com-
4258         ments" below) can be used.         ments" below) can be used.
4259    
4260         A back reference that occurs inside the parentheses to which it  refers         A  back reference that occurs inside the parentheses to which it refers
4261         fails  when  the subpattern is first used, so, for example, (a\1) never         fails when the subpattern is first used, so, for example,  (a\1)  never
4262         matches.  However, such references can be useful inside  repeated  sub-         matches.   However,  such references can be useful inside repeated sub-
4263         patterns. For example, the pattern         patterns. For example, the pattern
4264    
4265           (a|b\1)+           (a|b\1)+
4266    
4267         matches any number of "a"s and also "aba", "ababbaa" etc. At each iter-         matches any number of "a"s and also "aba", "ababbaa" etc. At each iter-
4268         ation of the subpattern,  the  back  reference  matches  the  character         ation  of  the  subpattern,  the  back  reference matches the character
4269         string  corresponding  to  the previous iteration. In order for this to         string corresponding to the previous iteration. In order  for  this  to
4270         work, the pattern must be such that the first iteration does  not  need         work,  the  pattern must be such that the first iteration does not need
4271         to  match the back reference. This can be done using alternation, as in         to match the back reference. This can be done using alternation, as  in
4272         the example above, or by a quantifier with a minimum of zero.         the example above, or by a quantifier with a minimum of zero.
4273    
4274    
4275  ASSERTIONS  ASSERTIONS
4276    
4277         An assertion is a test on the characters  following  or  preceding  the         An  assertion  is  a  test on the characters following or preceding the
4278         current  matching  point that does not actually consume any characters.         current matching point that does not actually consume  any  characters.
4279         The simple assertions coded as \b, \B, \A, \G, \Z,  \z,  ^  and  $  are         The  simple  assertions  coded  as  \b, \B, \A, \G, \Z, \z, ^ and $ are
4280         described above.         described above.
4281    
4282         More  complicated  assertions  are  coded as subpatterns. There are two         More complicated assertions are coded as  subpatterns.  There  are  two
4283         kinds: those that look ahead of the current  position  in  the  subject         kinds:  those  that  look  ahead of the current position in the subject
4284         string,  and  those  that  look  behind  it. An assertion subpattern is         string, and those that look  behind  it.  An  assertion  subpattern  is
4285         matched in the normal way, except that it does not  cause  the  current         matched  in  the  normal way, except that it does not cause the current
4286         matching position to be changed.         matching position to be changed.
4287    
4288         Assertion  subpatterns  are  not  capturing subpatterns, and may not be         Assertion subpatterns are not capturing subpatterns,  and  may  not  be
4289         repeated, because it makes no sense to assert the  same  thing  several         repeated,  because  it  makes no sense to assert the same thing several
4290         times.  If  any kind of assertion contains capturing subpatterns within         times. If any kind of assertion contains capturing  subpatterns  within
4291         it, these are counted for the purposes of numbering the capturing  sub-         it,  these are counted for the purposes of numbering the capturing sub-
4292         patterns in the whole pattern.  However, substring capturing is carried         patterns in the whole pattern.  However, substring capturing is carried
4293         out only for positive assertions, because it does not  make  sense  for         out  only  for  positive assertions, because it does not make sense for
4294         negative assertions.         negative assertions.
4295    
4296     Lookahead assertions     Lookahead assertions
# Line 4114  ASSERTIONS Line 4300  ASSERTIONS
4300    
4301           \w+(?=;)           \w+(?=;)
4302    
4303         matches a word followed by a semicolon, but does not include the  semi-         matches  a word followed by a semicolon, but does not include the semi-
4304         colon in the match, and         colon in the match, and
4305    
4306           foo(?!bar)           foo(?!bar)
4307    
4308         matches  any  occurrence  of  "foo" that is not followed by "bar". Note         matches any occurrence of "foo" that is not  followed  by  "bar".  Note
4309         that the apparently similar pattern         that the apparently similar pattern
4310    
4311           (?!foo)bar           (?!foo)bar
4312    
4313         does not find an occurrence of "bar"  that  is  preceded  by  something         does  not  find  an  occurrence  of "bar" that is preceded by something
4314         other  than "foo"; it finds any occurrence of "bar" whatsoever, because         other than "foo"; it finds any occurrence of "bar" whatsoever,  because
4315         the assertion (?!foo) is always true when the next three characters are         the assertion (?!foo) is always true when the next three characters are
4316         "bar". A lookbehind assertion is needed to achieve the other effect.         "bar". A lookbehind assertion is needed to achieve the other effect.
4317    
4318         If you want to force a matching failure at some point in a pattern, the         If you want to force a matching failure at some point in a pattern, the
4319         most convenient way to do it is  with  (?!)  because  an  empty  string         most  convenient  way  to  do  it  is with (?!) because an empty string
4320         always  matches, so an assertion that requires there not to be an empty         always matches, so an assertion that requires there not to be an  empty
4321         string must always fail.         string must always fail.
4322    
4323     Lookbehind assertions     Lookbehind assertions
4324    
4325         Lookbehind assertions start with (?<= for positive assertions and  (?<!         Lookbehind  assertions start with (?<= for positive assertions and (?<!
4326         for negative assertions. For example,         for negative assertions. For example,
4327    
4328           (?<!foo)bar           (?<!foo)bar
4329    
4330         does  find  an  occurrence  of "bar" that is not preceded by "foo". The         does find an occurrence of "bar" that is not  preceded  by  "foo".  The
4331         contents of a lookbehind assertion are restricted  such  that  all  the         contents  of  a  lookbehind  assertion are restricted such that all the
4332         strings it matches must have a fixed length. However, if there are sev-         strings it matches must have a fixed length. However, if there are sev-
4333         eral top-level alternatives, they do not all  have  to  have  the  same         eral  top-level  alternatives,  they  do  not all have to have the same
4334         fixed length. Thus         fixed length. Thus
4335    
4336           (?<=bullock|donkey)           (?<=bullock|donkey)
# Line 4153  ASSERTIONS Line 4339  ASSERTIONS
4339    
4340           (?<!dogs?|cats?)           (?<!dogs?|cats?)
4341    
4342         causes  an  error at compile time. Branches that match different length         causes an error at compile time. Branches that match  different  length
4343         strings are permitted only at the top level of a lookbehind  assertion.         strings  are permitted only at the top level of a lookbehind assertion.
4344         This  is  an  extension  compared  with  Perl (at least for 5.8), which         This is an extension compared with  Perl  (at  least  for  5.8),  which
4345         requires all branches to match the same length of string. An  assertion         requires  all branches to match the same length of string. An assertion
4346         such as         such as
4347    
4348           (?<=ab(c|de))           (?<=ab(c|de))
4349    
4350         is  not  permitted,  because  its single top-level branch can match two         is not permitted, because its single top-level  branch  can  match  two
4351         different lengths, but it is acceptable if rewritten to  use  two  top-         different  lengths,  but  it is acceptable if rewritten to use two top-
4352         level branches:         level branches:
4353    
4354           (?<=abc|abde)           (?<=abc|abde)
4355    
4356         In some cases, the Perl 5.10 escape sequence \K (see above) can be used         In some cases, the Perl 5.10 escape sequence \K (see above) can be used
4357         instead of a lookbehind assertion; this is not restricted to  a  fixed-         instead  of  a lookbehind assertion; this is not restricted to a fixed-
4358         length.         length.
4359    
4360         The  implementation  of lookbehind assertions is, for each alternative,         The implementation of lookbehind assertions is, for  each  alternative,
4361         to temporarily move the current position back by the fixed  length  and         to  temporarily  move the current position back by the fixed length and
4362         then try to match. If there are insufficient characters before the cur-         then try to match. If there are insufficient characters before the cur-
4363         rent position, the assertion fails.         rent position, the assertion fails.
4364    
4365         PCRE does not allow the \C escape (which matches a single byte in UTF-8         PCRE does not allow the \C escape (which matches a single byte in UTF-8
4366         mode)  to appear in lookbehind assertions, because it makes it impossi-         mode) to appear in lookbehind assertions, because it makes it  impossi-
4367         ble to calculate the length of the lookbehind. The \X and  \R  escapes,         ble  to  calculate the length of the lookbehind. The \X and \R escapes,
4368         which can match different numbers of bytes, are also not permitted.         which can match different numbers of bytes, are also not permitted.
4369    
4370         Possessive  quantifiers  can  be  used  in  conjunction with lookbehind         Possessive quantifiers can  be  used  in  conjunction  with  lookbehind
4371         assertions to specify efficient matching at  the  end  of  the  subject         assertions  to  specify  efficient  matching  at the end of the subject
4372         string. Consider a simple pattern such as         string. Consider a simple pattern such as
4373    
4374           abcd$           abcd$
4375    
4376         when  applied  to  a  long string that does not match. Because matching         when applied to a long string that does  not  match.  Because  matching
4377         proceeds from left to right, PCRE will look for each "a" in the subject         proceeds from left to right, PCRE will look for each "a" in the subject
4378         and  then  see  if what follows matches the rest of the pattern. If the         and then see if what follows matches the rest of the  pattern.  If  the
4379         pattern is specified as         pattern is specified as
4380    
4381           ^.*abcd$           ^.*abcd$
4382    
4383         the initial .* matches the entire string at first, but when this  fails         the  initial .* matches the entire string at first, but when this fails
4384         (because there is no following "a"), it backtracks to match all but the         (because there is no following "a"), it backtracks to match all but the
4385         last character, then all but the last two characters, and so  on.  Once         last  character,  then all but the last two characters, and so on. Once
4386         again  the search for "a" covers the entire string, from right to left,         again the search for "a" covers the entire string, from right to  left,
4387         so we are no better off. However, if the pattern is written as         so we are no better off. However, if the pattern is written as
4388    
4389           ^.*+(?<=abcd)           ^.*+(?<=abcd)
4390    
4391         there can be no backtracking for the .*+ item; it can  match  only  the         there  can  be  no backtracking for the .*+ item; it can match only the
4392         entire  string.  The subsequent lookbehind assertion does a single test         entire string. The subsequent lookbehind assertion does a  single  test
4393         on the last four characters. If it fails, the match fails  immediately.         on  the last four characters. If it fails, the match fails immediately.
4394         For  long  strings, this approach makes a significant difference to the         For long strings, this approach makes a significant difference  to  the
4395         processing time.         processing time.
4396    
4397     Using multiple assertions     Using multiple assertions
# Line 4214  ASSERTIONS Line 4400  ASSERTIONS
4400    
4401           (?<=\d{3})(?<!999)foo           (?<=\d{3})(?<!999)foo
4402    
4403         matches "foo" preceded by three digits that are not "999". Notice  that         matches  "foo" preceded by three digits that are not "999". Notice that
4404         each  of  the  assertions is applied independently at the same point in         each of the assertions is applied independently at the  same  point  in
4405         the subject string. First there is a  check  that  the  previous  three         the  subject  string.  First  there  is a check that the previous three
4406         characters  are  all  digits,  and  then there is a check that the same         characters are all digits, and then there is  a  check  that  the  same
4407         three characters are not "999".  This pattern does not match "foo" pre-         three characters are not "999".  This pattern does not match "foo" pre-
4408         ceded  by  six  characters,  the first of which are digits and the last         ceded by six characters, the first of which are  digits  and  the  last
4409         three of which are not "999". For example, it  doesn't  match  "123abc-         three  of  which  are not "999". For example, it doesn't match "123abc-
4410         foo". A pattern to do that is         foo". A pattern to do that is
4411    
4412           (?<=\d{3}...)(?<!999)foo           (?<=\d{3}...)(?<!999)foo
4413    
4414         This  time  the  first assertion looks at the preceding six characters,         This time the first assertion looks at the  preceding  six  characters,
4415         checking that the first three are digits, and then the second assertion         checking that the first three are digits, and then the second assertion
4416         checks that the preceding three characters are not "999".         checks that the preceding three characters are not "999".
4417    
# Line 4233  ASSERTIONS Line 4419  ASSERTIONS
4419    
4420           (?<=(?<!foo)bar)baz           (?<=(?<!foo)bar)baz
4421    
4422         matches  an occurrence of "baz" that is preceded by "bar" which in turn         matches an occurrence of "baz" that is preceded by "bar" which in  turn
4423         is not preceded by "foo", while         is not preceded by "foo", while
4424    
4425           (?<=\d{3}(?!999)...)foo           (?<=\d{3}(?!999)...)foo
4426    
4427         is another pattern that matches "foo" preceded by three digits and  any         is  another pattern that matches "foo" preceded by three digits and any
4428         three characters that are not "999".         three characters that are not "999".
4429    
4430    
4431  CONDITIONAL SUBPATTERNS  CONDITIONAL SUBPATTERNS
4432    
4433         It  is possible to cause the matching process to obey a subpattern con-         It is possible to cause the matching process to obey a subpattern  con-
4434         ditionally or to choose between two alternative subpatterns,  depending         ditionally  or to choose between two alternative subpatterns, depending
4435         on  the result of an assertion, or whether a previous capturing subpat-         on the result of an assertion, or whether a previous capturing  subpat-
4436         tern matched or not. The two possible forms of  conditional  subpattern         tern  matched  or not. The two possible forms of conditional subpattern
4437         are         are
4438    
4439           (?(condition)yes-pattern)           (?(condition)yes-pattern)
4440           (?(condition)yes-pattern|no-pattern)           (?(condition)yes-pattern|no-pattern)
4441    
4442         If  the  condition is satisfied, the yes-pattern is used; otherwise the         If the condition is satisfied, the yes-pattern is used;  otherwise  the
4443         no-pattern (if present) is used. If there are more  than  two  alterna-         no-pattern  (if  present)  is used. If there are more than two alterna-
4444         tives in the subpattern, a compile-time error occurs.         tives in the subpattern, a compile-time error occurs.
4445    
4446         There  are  four  kinds of condition: references to subpatterns, refer-         There are four kinds of condition: references  to  subpatterns,  refer-
4447         ences to recursion, a pseudo-condition called DEFINE, and assertions.         ences to recursion, a pseudo-condition called DEFINE, and assertions.
4448    
4449     Checking for a used subpattern by number     Checking for a used subpattern by number
4450    
4451         If the text between the parentheses consists of a sequence  of  digits,         If  the  text between the parentheses consists of a sequence of digits,
4452         the  condition  is  true if the capturing subpattern of that number has         the condition is true if the capturing subpattern of  that  number  has
4453         previously matched. An alternative notation is to  precede  the  digits         previously  matched.  An  alternative notation is to precede the digits
4454         with a plus or minus sign. In this case, the subpattern number is rela-         with a plus or minus sign. In this case, the subpattern number is rela-
4455         tive rather than absolute.  The most recently opened parentheses can be         tive rather than absolute.  The most recently opened parentheses can be
4456         referenced  by  (?(-1),  the  next most recent by (?(-2), and so on. In         referenced by (?(-1), the next most recent by (?(-2),  and  so  on.  In
4457         looping constructs it can also make sense to refer to subsequent groups         looping constructs it can also make sense to refer to subsequent groups
4458         with constructs such as (?(+2).         with constructs such as (?(+2).
4459    
4460         Consider  the  following  pattern, which contains non-significant white         Consider the following pattern, which  contains  non-significant  white
4461         space to make it more readable (assume the PCRE_EXTENDED option) and to         space to make it more readable (assume the PCRE_EXTENDED option) and to
4462         divide it into three parts for ease of discussion:         divide it into three parts for ease of discussion:
4463    
4464           ( \( )?    [^()]+    (?(1) \) )           ( \( )?    [^()]+    (?(1) \) )
4465    
4466         The  first  part  matches  an optional opening parenthesis, and if that         The first part matches an optional opening  parenthesis,  and  if  that
4467         character is present, sets it as the first captured substring. The sec-         character is present, sets it as the first captured substring. The sec-
4468         ond  part  matches one or more characters that are not parentheses. The         ond part matches one or more characters that are not  parentheses.  The
4469         third part is a conditional subpattern that tests whether the first set         third part is a conditional subpattern that tests whether the first set
4470         of parentheses matched or not. If they did, that is, if subject started         of parentheses matched or not. If they did, that is, if subject started
4471         with an opening parenthesis, the condition is true, and so the yes-pat-         with an opening parenthesis, the condition is true, and so the yes-pat-
4472         tern  is  executed  and  a  closing parenthesis is required. Otherwise,         tern is executed and a  closing  parenthesis  is  required.  Otherwise,
4473         since no-pattern is not present, the  subpattern  matches  nothing.  In         since  no-pattern  is  not  present, the subpattern matches nothing. In
4474         other  words,  this  pattern  matches  a  sequence  of non-parentheses,         other words,  this  pattern  matches  a  sequence  of  non-parentheses,
4475         optionally enclosed in parentheses.         optionally enclosed in parentheses.
4476    
4477         If you were embedding this pattern in a larger one,  you  could  use  a         If  you  were  embedding  this pattern in a larger one, you could use a
4478         relative reference:         relative reference:
4479    
4480           ...other stuff... ( \( )?    [^()]+    (?(-1) \) ) ...           ...other stuff... ( \( )?    [^()]+    (?(-1) \) ) ...
4481    
4482         This  makes  the  fragment independent of the parentheses in the larger         This makes the fragment independent of the parentheses  in  the  larger
4483         pattern.         pattern.
4484    
4485     Checking for a used subpattern by name     Checking for a used subpattern by name
4486    
4487         Perl uses the syntax (?(<name>)...) or (?('name')...)  to  test  for  a         Perl  uses  the  syntax  (?(<name>)...) or (?('name')...) to test for a
4488         used  subpattern  by  name.  For compatibility with earlier versions of         used subpattern by name. For compatibility  with  earlier  versions  of
4489         PCRE, which had this facility before Perl, the syntax  (?(name)...)  is         PCRE,  which  had this facility before Perl, the syntax (?(name)...) is
4490         also  recognized. However, there is a possible ambiguity with this syn-         also recognized. However, there is a possible ambiguity with this  syn-
4491         tax, because subpattern names may  consist  entirely  of  digits.  PCRE         tax,  because  subpattern  names  may  consist entirely of digits. PCRE
4492         looks  first for a named subpattern; if it cannot find one and the name         looks first for a named subpattern; if it cannot find one and the  name
4493         consists entirely of digits, PCRE looks for a subpattern of  that  num-         consists  entirely  of digits, PCRE looks for a subpattern of that num-
4494         ber,  which must be greater than zero. Using subpattern names that con-         ber, which must be greater than zero. Using subpattern names that  con-
4495         sist entirely of digits is not recommended.         sist entirely of digits is not recommended.
4496    
4497         Rewriting the above example to use a named subpattern gives this:         Rewriting the above example to use a named subpattern gives this:
# Line 4316  CONDITIONAL SUBPATTERNS Line 4502  CONDITIONAL SUBPATTERNS
4502     Checking for pattern recursion     Checking for pattern recursion
4503    
4504         If the condition is the string (R), and there is no subpattern with the         If the condition is the string (R), and there is no subpattern with the
4505         name  R, the condition is true if a recursive call to the whole pattern         name R, the condition is true if a recursive call to the whole  pattern
4506         or any subpattern has been made. If digits or a name preceded by amper-         or any subpattern has been made. If digits or a name preceded by amper-
4507         sand follow the letter R, for example:         sand follow the letter R, for example:
4508    
4509           (?(R3)...) or (?(R&name)...)           (?(R3)...) or (?(R&name)...)
4510    
4511         the  condition is true if the most recent recursion is into the subpat-         the condition is true if the most recent recursion is into the  subpat-
4512         tern whose number or name is given. This condition does not  check  the         tern  whose  number or name is given. This condition does not check the
4513         entire recursion stack.         entire recursion stack.
4514    
4515         At  "top  level", all these recursion test conditions are false. Recur-         At "top level", all these recursion test conditions are  false.  Recur-
4516         sive patterns are described below.         sive patterns are described below.
4517    
4518     Defining subpatterns for use by reference only     Defining subpatterns for use by reference only
4519    
4520         If the condition is the string (DEFINE), and  there  is  no  subpattern         If  the  condition  is  the string (DEFINE), and there is no subpattern
4521         with  the  name  DEFINE,  the  condition is always false. In this case,         with the name DEFINE, the condition is  always  false.  In  this  case,
4522         there may be only one alternative  in  the  subpattern.  It  is  always         there  may  be  only  one  alternative  in the subpattern. It is always
4523         skipped  if  control  reaches  this  point  in the pattern; the idea of         skipped if control reaches this point  in  the  pattern;  the  idea  of
4524         DEFINE is that it can be used to define "subroutines" that can be  ref-         DEFINE  is that it can be used to define "subroutines" that can be ref-
4525         erenced  from elsewhere. (The use of "subroutines" is described below.)         erenced from elsewhere. (The use of "subroutines" is described  below.)
4526         For example, a pattern to match an IPv4 address could be  written  like         For  example,  a pattern to match an IPv4 address could be written like
4527         this (ignore whitespace and line breaks):         this (ignore whitespace and line breaks):
4528    
4529           (?(DEFINE) (?<byte> 2[0-4]\d | 25[0-5] | 1\d\d | [1-9]?\d) )           (?(DEFINE) (?<byte> 2[0-4]\d | 25[0-5] | 1\d\d | [1-9]?\d) )
4530           \b (?&byte) (\.(?&byte)){3} \b           \b (?&byte) (\.(?&byte)){3} \b
4531    
4532         The  first part of the pattern is a DEFINE group inside which a another         The first part of the pattern is a DEFINE group inside which a  another
4533         group named "byte" is defined. This matches an individual component  of         group  named "byte" is defined. This matches an individual component of
4534         an  IPv4  address  (a number less than 256). When matching takes place,         an IPv4 address (a number less than 256). When  matching  takes  place,
4535         this part of the pattern is skipped because DEFINE acts  like  a  false         this  part  of  the pattern is skipped because DEFINE acts like a false
4536         condition.         condition.
4537    
4538         The rest of the pattern uses references to the named group to match the         The rest of the pattern uses references to the named group to match the
4539         four dot-separated components of an IPv4 address, insisting on  a  word         four  dot-separated  components of an IPv4 address, insisting on a word
4540         boundary at each end.         boundary at each end.
4541    
4542     Assertion conditions     Assertion conditions
4543    
4544         If  the  condition  is  not  in any of the above formats, it must be an         If the condition is not in any of the above  formats,  it  must  be  an
4545         assertion.  This may be a positive or negative lookahead or  lookbehind         assertion.   This may be a positive or negative lookahead or lookbehind
4546         assertion.  Consider  this  pattern,  again  containing non-significant         assertion. Consider  this  pattern,  again  containing  non-significant
4547         white space, and with the two alternatives on the second line:         white space, and with the two alternatives on the second line:
4548    
4549           (?(?=[^a-z]*[a-z])           (?(?=[^a-z]*[a-z])
4550           \d{2}-[a-z]{3}-\d{2}  |  \d{2}-\d{2}-\d{2} )           \d{2}-[a-z]{3}-\d{2}  |  \d{2}-\d{2}-\d{2} )
4551    
4552         The condition  is  a  positive  lookahead  assertion  that  matches  an         The  condition  is  a  positive  lookahead  assertion  that  matches an
4553         optional  sequence of non-letters followed by a letter. In other words,         optional sequence of non-letters followed by a letter. In other  words,
4554         it tests for the presence of at least one letter in the subject.  If  a         it  tests  for the presence of at least one letter in the subject. If a
4555         letter  is found, the subject is matched against the first alternative;         letter is found, the subject is matched against the first  alternative;
4556         otherwise it is  matched  against  the  second.  This  pattern  matches         otherwise  it  is  matched  against  the  second.  This pattern matches
4557         strings  in  one  of the two forms dd-aaa-dd or dd-dd-dd, where aaa are         strings in one of the two forms dd-aaa-dd or dd-dd-dd,  where  aaa  are
4558         letters and dd are digits.         letters and dd are digits.
4559    
4560    
4561  COMMENTS  COMMENTS
4562    
4563         The sequence (?# marks the start of a comment that continues up to  the         The  sequence (?# marks the start of a comment that continues up to the
4564         next  closing  parenthesis.  Nested  parentheses are not permitted. The         next closing parenthesis. Nested parentheses  are  not  permitted.  The
4565         characters that make up a comment play no part in the pattern  matching         characters  that make up a comment play no part in the pattern matching
4566         at all.         at all.
4567    
4568         If  the PCRE_EXTENDED option is set, an unescaped # character outside a         If the PCRE_EXTENDED option is set, an unescaped # character outside  a
4569         character class introduces a  comment  that  continues  to  immediately         character  class  introduces  a  comment  that continues to immediately
4570         after the next newline in the pattern.         after the next newline in the pattern.
4571    
4572    
4573  RECURSIVE PATTERNS  RECURSIVE PATTERNS
4574    
4575         Consider  the problem of matching a string in parentheses, allowing for         Consider the problem of matching a string in parentheses, allowing  for
4576         unlimited nested parentheses. Without the use of  recursion,  the  best         unlimited  nested  parentheses.  Without the use of recursion, the best
4577         that  can  be  done  is  to use a pattern that matches up to some fixed         that can be done is to use a pattern that  matches  up  to  some  fixed
4578         depth of nesting. It is not possible to  handle  an  arbitrary  nesting         depth  of  nesting.  It  is not possible to handle an arbitrary nesting
4579         depth.         depth.
4580    
4581         For some time, Perl has provided a facility that allows regular expres-         For some time, Perl has provided a facility that allows regular expres-
4582         sions to recurse (amongst other things). It does this by  interpolating         sions  to recurse (amongst other things). It does this by interpolating
4583         Perl  code in the expression at run time, and the code can refer to the         Perl code in the expression at run time, and the code can refer to  the
4584         expression itself. A Perl pattern using code interpolation to solve the         expression itself. A Perl pattern using code interpolation to solve the
4585         parentheses problem can be created like this:         parentheses problem can be created like this:
4586    
# Line 4404  RECURSIVE PATTERNS Line 4590  RECURSIVE PATTERNS
4590         refers recursively to the pattern in which it appears.         refers recursively to the pattern in which it appears.
4591    
4592         Obviously, PCRE cannot support the interpolation of Perl code. Instead,         Obviously, PCRE cannot support the interpolation of Perl code. Instead,
4593         it  supports  special  syntax  for recursion of the entire pattern, and         it supports special syntax for recursion of  the  entire  pattern,  and
4594         also for individual subpattern recursion.  After  its  introduction  in         also  for  individual  subpattern  recursion. After its introduction in
4595         PCRE  and  Python,  this  kind of recursion was introduced into Perl at         PCRE and Python, this kind of recursion was  introduced  into  Perl  at
4596         release 5.10.         release 5.10.
4597    
4598         A special item that consists of (? followed by a  number  greater  than         A  special  item  that consists of (? followed by a number greater than
4599         zero and a closing parenthesis is a recursive call of the subpattern of         zero and a closing parenthesis is a recursive call of the subpattern of
4600         the given number, provided that it occurs inside that  subpattern.  (If         the  given  number, provided that it occurs inside that subpattern. (If
4601         not,  it  is  a  "subroutine" call, which is described in the next sec-         not, it is a "subroutine" call, which is described  in  the  next  sec-
4602         tion.) The special item (?R) or (?0) is a recursive call of the  entire         tion.)  The special item (?R) or (?0) is a recursive call of the entire
4603         regular expression.         regular expression.
4604    
4605         In  PCRE (like Python, but unlike Perl), a recursive subpattern call is         In PCRE (like Python, but unlike Perl), a recursive subpattern call  is
4606         always treated as an atomic group. That is, once it has matched some of         always treated as an atomic group. That is, once it has matched some of
4607         the subject string, it is never re-entered, even if it contains untried         the subject string, it is never re-entered, even if it contains untried
4608         alternatives and there is a subsequent matching failure.         alternatives and there is a subsequent matching failure.
4609    
4610         This PCRE pattern solves the nested  parentheses  problem  (assume  the         This  PCRE  pattern  solves  the nested parentheses problem (assume the
4611         PCRE_EXTENDED option is set so that white space is ignored):         PCRE_EXTENDED option is set so that white space is ignored):
4612    
4613           \( ( (?>[^()]+) | (?R) )* \)           \( ( (?>[^()]+) | (?R) )* \)
4614    
4615         First  it matches an opening parenthesis. Then it matches any number of         First it matches an opening parenthesis. Then it matches any number  of
4616         substrings which can either be a  sequence  of  non-parentheses,  or  a         substrings  which  can  either  be  a sequence of non-parentheses, or a
4617         recursive  match  of the pattern itself (that is, a correctly parenthe-         recursive match of the pattern itself (that is, a  correctly  parenthe-
4618         sized substring).  Finally there is a closing parenthesis.         sized substring).  Finally there is a closing parenthesis.
4619    
4620         If this were part of a larger pattern, you would not  want  to  recurse         If  this  were  part of a larger pattern, you would not want to recurse
4621         the entire pattern, so instead you could use this:         the entire pattern, so instead you could use this:
4622    
4623           ( \( ( (?>[^()]+) | (?1) )* \) )           ( \( ( (?>[^()]+) | (?1) )* \) )
4624    
4625         We  have  put the pattern into parentheses, and caused the recursion to         We have put the pattern into parentheses, and caused the  recursion  to
4626         refer to them instead of the whole pattern.         refer to them instead of the whole pattern.
4627    
4628         In a larger pattern,  keeping  track  of  parenthesis  numbers  can  be         In  a  larger  pattern,  keeping  track  of  parenthesis numbers can be
4629         tricky.  This is made easier by the use of relative references. (A Perl         tricky. This is made easier by the use of relative references. (A  Perl
4630         5.10 feature.)  Instead of (?1) in the  pattern  above  you  can  write         5.10  feature.)   Instead  of  (?1)  in the pattern above you can write
4631         (?-2) to refer to the second most recently opened parentheses preceding         (?-2) to refer to the second most recently opened parentheses preceding
4632         the recursion. In other  words,  a  negative  number  counts  capturing         the  recursion.  In  other  words,  a  negative number counts capturing
4633         parentheses leftwards from the point at which it is encountered.         parentheses leftwards from the point at which it is encountered.
4634    
4635         It  is  also  possible  to refer to subsequently opened parentheses, by         It is also possible to refer to  subsequently  opened  parentheses,  by
4636         writing references such as (?+2). However, these  cannot  be  recursive         writing  references  such  as (?+2). However, these cannot be recursive
4637         because  the  reference  is  not inside the parentheses that are refer-         because the reference is not inside the  parentheses  that  are  refer-
4638         enced. They are always "subroutine" calls, as  described  in  the  next         enced.  They  are  always  "subroutine" calls, as described in the next
4639         section.         section.
4640    
4641         An  alternative  approach is to use named parentheses instead. The Perl         An alternative approach is to use named parentheses instead.  The  Perl
4642         syntax for this is (?&name); PCRE's earlier syntax  (?P>name)  is  also         syntax  for  this  is (?&name); PCRE's earlier syntax (?P>name) is also
4643         supported. We could rewrite the above example as follows:         supported. We could rewrite the above example as follows:
4644    
4645           (?<pn> \( ( (?>[^()]+) | (?&pn) )* \) )           (?<pn> \( ( (?>[^()]+) | (?&pn) )* \) )
4646    
4647         If  there  is more than one subpattern with the same name, the earliest         If there is more than one subpattern with the same name,  the  earliest
4648         one is used.         one is used.
4649    
4650         This particular example pattern that we have been looking  at  contains         This  particular  example pattern that we have been looking at contains
4651         nested  unlimited repeats, and so the use of atomic grouping for match-         nested unlimited repeats, and so the use of atomic grouping for  match-
4652         ing strings of non-parentheses is important when applying  the  pattern         ing  strings  of non-parentheses is important when applying the pattern
4653         to strings that do not match. For example, when this pattern is applied         to strings that do not match. For example, when this pattern is applied
4654         to         to
4655    
4656           (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()           (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
4657    
4658         it yields "no match" quickly. However, if atomic grouping is not  used,         it  yields "no match" quickly. However, if atomic grouping is not used,
4659         the  match  runs  for a very long time indeed because there are so many         the match runs for a very long time indeed because there  are  so  many
4660         different ways the + and * repeats can carve up the  subject,  and  all         different  ways  the  + and * repeats can carve up the subject, and all
4661         have to be tested before failure can be reported.         have to be tested before failure can be reported.
4662    
4663         At the end of a match, the values set for any capturing subpatterns are         At the end of a match, the values set for any capturing subpatterns are
4664         those from the outermost level of the recursion at which the subpattern         those from the outermost level of the recursion at which the subpattern
4665         value  is  set.   If  you want to obtain intermediate values, a callout         value is set.  If you want to obtain  intermediate  values,  a  callout
4666         function can be used (see below and the pcrecallout documentation).  If         function  can be used (see below and the pcrecallout documentation). If
4667         the pattern above is matched against         the pattern above is matched against
4668    
4669           (ab(cd)ef)           (ab(cd)ef)
4670    
4671         the  value  for  the  capturing  parentheses is "ef", which is the last         the value for the capturing parentheses is  "ef",  which  is  the  last
4672         value taken on at the top level. If additional parentheses  are  added,         value  taken  on at the top level. If additional parentheses are added,
4673         giving         giving
4674    
4675           \( ( ( (?>[^()]+) | (?R) )* ) \)           \( ( ( (?>[^()]+) | (?R) )* ) \)
4676              ^                        ^              ^                        ^
4677              ^                        ^              ^                        ^
4678    
4679         the  string  they  capture is "ab(cd)ef", the contents of the top level         the string they capture is "ab(cd)ef", the contents of  the  top  level
4680         parentheses. If there are more than 15 capturing parentheses in a  pat-         parentheses.  If there are more than 15 capturing parentheses in a pat-
4681         tern, PCRE has to obtain extra memory to store data during a recursion,         tern, PCRE has to obtain extra memory to store data during a recursion,
4682         which it does by using pcre_malloc, freeing  it  via  pcre_free  after-         which  it  does  by  using pcre_malloc, freeing it via pcre_free after-
4683         wards.  If  no  memory  can  be  obtained,  the  match  fails  with the         wards. If  no  memory  can  be  obtained,  the  match  fails  with  the
4684         PCRE_ERROR_NOMEMORY error.         PCRE_ERROR_NOMEMORY error.
4685    
4686         Do not confuse the (?R) item with the condition (R),  which  tests  for         Do  not  confuse  the (?R) item with the condition (R), which tests for
4687         recursion.   Consider  this pattern, which matches text in angle brack-         recursion.  Consider this pattern, which matches text in  angle  brack-
4688         ets, allowing for arbitrary nesting. Only digits are allowed in  nested         ets,  allowing for arbitrary nesting. Only digits are allowed in nested
4689         brackets  (that is, when recursing), whereas any characters are permit-         brackets (that is, when recursing), whereas any characters are  permit-
4690         ted at the outer level.         ted at the outer level.
4691    
4692           < (?: (?(R) \d++  | [^<>]*+) | (?R)) * >           < (?: (?(R) \d++  | [^<>]*+) | (?R)) * >
4693    
4694         In this pattern, (?(R) is the start of a conditional  subpattern,  with         In  this  pattern, (?(R) is the start of a conditional subpattern, with
4695         two  different  alternatives for the recursive and non-recursive cases.         two different alternatives for the recursive and  non-recursive  cases.
4696         The (?R) item is the actual recursive call.         The (?R) item is the actual recursive call.
4697    
4698    
4699  SUBPATTERNS AS SUBROUTINES  SUBPATTERNS AS SUBROUTINES
4700    
4701         If the syntax for a recursive subpattern reference (either by number or         If the syntax for a recursive subpattern reference (either by number or
4702         by  name)  is used outside the parentheses to which it refers, it oper-         by name) is used outside the parentheses to which it refers,  it  oper-
4703         ates like a subroutine in a programming language. The "called"  subpat-         ates  like a subroutine in a programming language. The "called" subpat-
4704         tern may be defined before or after the reference. A numbered reference         tern may be defined before or after the reference. A numbered reference
4705         can be absolute or relative, as in these examples:         can be absolute or relative, as in these examples:
4706    
# Line 4526  SUBPATTERNS AS SUBROUTINES Line 4712  SUBPATTERNS AS SUBROUTINES
4712    
4713           (sens|respons)e and \1ibility           (sens|respons)e and \1ibility
4714    
4715         matches "sense and sensibility" and "response and responsibility",  but         matches  "sense and sensibility" and "response and responsibility", but
4716         not "sense and responsibility". If instead the pattern         not "sense and responsibility". If instead the pattern
4717    
4718           (sens|respons)e and (?1)ibility           (sens|respons)e and (?1)ibility
4719    
4720         is  used, it does match "sense and responsibility" as well as the other         is used, it does match "sense and responsibility" as well as the  other
4721         two strings. Another example is  given  in  the  discussion  of  DEFINE         two  strings.  Another  example  is  given  in the discussion of DEFINE
4722         above.         above.
4723    
4724         Like recursive subpatterns, a "subroutine" call is always treated as an         Like recursive subpatterns, a "subroutine" call is always treated as an
4725         atomic group. That is, once it has matched some of the subject  string,         atomic  group. That is, once it has matched some of the subject string,
4726         it  is  never  re-entered, even if it contains untried alternatives and         it is never re-entered, even if it contains  untried  alternatives  and
4727         there is a subsequent matching failure.         there is a subsequent matching failure.
4728    
4729         When a subpattern is used as a subroutine, processing options  such  as         When  a  subpattern is used as a subroutine, processing options such as
4730         case-independence are fixed when the subpattern is defined. They cannot         case-independence are fixed when the subpattern is defined. They cannot
4731         be changed for different calls. For example, consider this pattern:         be changed for different calls. For example, consider this pattern:
4732    
4733           (abc)(?i:(?-1))           (abc)(?i:(?-1))
4734    
4735         It matches "abcabc". It does not match "abcABC" because the  change  of         It  matches  "abcabc". It does not match "abcABC" because the change of
4736         processing option does not affect the called subpattern.         processing option does not affect the called subpattern.
4737    
4738    
4739  CALLOUTS  CALLOUTS
4740    
4741         Perl has a feature whereby using the sequence (?{...}) causes arbitrary         Perl has a feature whereby using the sequence (?{...}) causes arbitrary
4742         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.
4743         This makes it possible, amongst other things, to extract different sub-         This makes it possible, amongst other things, to extract different sub-
4744         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-
4745         tion.         tion.
4746    
4747         PCRE provides a similar feature, but of course it cannot obey arbitrary         PCRE provides a similar feature, but of course it cannot obey arbitrary
4748         Perl code. The feature is called "callout". The caller of PCRE provides         Perl code. The feature is called "callout". The caller of PCRE provides
4749         an  external function by putting its entry point in the global variable         an external function by putting its entry point in the global  variable
4750         pcre_callout.  By default, this variable contains NULL, which  disables         pcre_callout.   By default, this variable contains NULL, which disables
4751         all calling out.         all calling out.
4752    
4753         Within  a  regular  expression,  (?C) indicates the points at which the         Within a regular expression, (?C) indicates the  points  at  which  the
4754         external function is to be called. If you want  to  identify  different         external  function  is  to be called. If you want to identify different
4755         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.
4756         The default value is zero.  For example, this pattern has  two  callout         The  default  value is zero.  For example, this pattern has two callout
4757         points:         points:
4758    
4759           (?C1)abc(?C2)def           (?C1)abc(?C2)def
4760    
4761         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
4762         automatically installed before each item in the pattern. They  are  all         automatically  installed  before each item in the pattern. They are all
4763         numbered 255.         numbered 255.
4764    
4765         During matching, when PCRE reaches a callout point (and pcre_callout is         During matching, when PCRE reaches a callout point (and pcre_callout is
4766         set), the external function is called. It is provided with  the  number         set),  the  external function is called. It is provided with the number
4767         of  the callout, the position in the pattern, and, optionally, one item         of the callout, the position in the pattern, and, optionally, one  item
4768         of data originally supplied by the caller of pcre_exec().  The  callout         of  data  originally supplied by the caller of pcre_exec(). The callout
4769         function  may cause matching to proceed, to backtrack, or to fail alto-         function may cause matching to proceed, to backtrack, or to fail  alto-
4770         gether. A complete description of the interface to the callout function         gether. A complete description of the interface to the callout function
4771         is given in the pcrecallout documentation.         is given in the pcrecallout documentation.
4772    
4773    
4774  BACTRACKING CONTROL  BACKTRACKING CONTROL
4775    
4776         Perl  5.10 introduced a number of "Special Backtracking Control Verbs",         Perl 5.10 introduced a number of "Special Backtracking Control  Verbs",
4777         which are described in the Perl documentation as "experimental and sub-         which are described in the Perl documentation as "experimental and sub-
4778         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
4779         say: "Their usage in production code should be noted to avoid  problems         say:  "Their usage in production code should be noted to avoid problems
4780         during upgrades." The same remarks apply to the PCRE features described         during upgrades." The same remarks apply to the PCRE features described
4781         in this section.         in this section.
4782    
4783         Since these verbs are specifically related to backtracking, they can be         Since these verbs are specifically related to backtracking, they can be
4784         used  only  when  the pattern is to be matched using pcre_exec(), which         used only when the pattern is to be matched  using  pcre_exec(),  which
4785         uses a backtracking algorithm. They cause an error  if  encountered  by         uses  a  backtracking  algorithm. They cause an error if encountered by
4786         pcre_dfa_exec().         pcre_dfa_exec().
4787    
4788         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-
4789         ing parenthesis followed by an asterisk. In Perl, they are generally of         ing parenthesis followed by an asterisk. In Perl, they are generally of
4790         the form (*VERB:ARG) but PCRE does not support the use of arguments, so         the form (*VERB:ARG) but PCRE does not support the use of arguments, so
4791         its general form is just (*VERB). Any number of these verbs  may  occur         its  general  form is just (*VERB). Any number of these verbs may occur
4792         in a pattern. There are two kinds:         in a pattern. There are two kinds:
4793    
4794     Verbs that act immediately     Verbs that act immediately
# Line 4611  BACTRACKING CONTROL Line 4797  BACTRACKING CONTROL
4797    
4798            (*ACCEPT)            (*ACCEPT)
4799    
4800         This  verb causes the match to end successfully, skipping the remainder         This verb causes the match to end successfully, skipping the  remainder
4801         of the pattern. When inside a recursion, only the innermost pattern  is         of  the pattern. When inside a recursion, only the innermost pattern is
4802         ended  immediately.  PCRE  differs  from  Perl  in  what happens if the         ended immediately. PCRE differs  from  Perl  in  what  happens  if  the
4803         (*ACCEPT) is inside capturing parentheses. In Perl, the data so far  is         (*ACCEPT)  is inside capturing parentheses. In Perl, the data so far is
4804         captured: in PCRE no data is captured. For example:         captured: in PCRE no data is captured. For example:
4805    
4806           A(A|B(*ACCEPT)|C)D           A(A|B(*ACCEPT)|C)D
4807    
4808         This  matches  "AB", "AAD", or "ACD", but when it matches "AB", no data         This matches "AB", "AAD", or "ACD", but when it matches "AB",  no  data
4809         is captured.         is captured.
4810    
4811           (*FAIL) or (*F)           (*FAIL) or (*F)
4812    
4813         This verb causes the match to fail, forcing backtracking to  occur.  It         This  verb  causes the match to fail, forcing backtracking to occur. It
4814         is  equivalent to (?!) but easier to read. The Perl documentation notes         is equivalent to (?!) but easier to read. The Perl documentation  notes
4815         that it is probably useful only when combined  with  (?{})  or  (??{}).         that  it  is  probably  useful only when combined with (?{}) or (??{}).
4816         Those  are,  of course, Perl features that are not present in PCRE. The         Those are, of course, Perl features that are not present in  PCRE.  The
4817         nearest equivalent is the callout feature, as for example in this  pat-         nearest  equivalent is the callout feature, as for example in this pat-
4818         tern:         tern:
4819    
4820           a+(?C)(*FAIL)           a+(?C)(*FAIL)
4821    
4822         A  match  with the string "aaaa" always fails, but the callout is taken         A match with the string "aaaa" always fails, but the callout  is  taken
4823         before each backtrack happens (in this example, 10 times).         before each backtrack happens (in this example, 10 times).
4824    
4825     Verbs that act after backtracking     Verbs that act after backtracking
4826    
4827         The following verbs do nothing when they are encountered. Matching con-         The following verbs do nothing when they are encountered. Matching con-
4828         tinues  with what follows, but if there is no subsequent match, a fail-         tinues with what follows, but if there is no subsequent match, a  fail-
4829         ure is forced.  The verbs  differ  in  exactly  what  kind  of  failure         ure  is  forced.   The  verbs  differ  in  exactly what kind of failure
4830         occurs.         occurs.
4831    
4832           (*COMMIT)           (*COMMIT)
4833    
4834         This  verb  causes  the whole match to fail outright if the rest of the         This verb causes the whole match to fail outright if the  rest  of  the
4835         pattern does not match. Even if the pattern is unanchored,  no  further         pattern  does  not match. Even if the pattern is unanchored, no further
4836         attempts  to find a match by advancing the start point take place. Once         attempts to find a match by advancing the start point take place.  Once
4837         (*COMMIT) has been passed, pcre_exec() is committed to finding a  match         (*COMMIT)  has been passed, pcre_exec() is committed to finding a match
4838         at the current starting point, or not at all. For example:         at the current starting point, or not at all. For example:
4839    
4840           a+(*COMMIT)b           a+(*COMMIT)b
4841    
4842         This  matches  "xxaab" but not "aacaab". It can be thought of as a kind         This matches "xxaab" but not "aacaab". It can be thought of as  a  kind
4843         of dynamic anchor, or "I've started, so I must finish."         of dynamic anchor, or "I've started, so I must finish."
4844    
4845           (*PRUNE)           (*PRUNE)
4846    
4847         This verb causes the match to fail at the current position if the  rest         This  verb causes the match to fail at the current position if the rest
4848         of the pattern does not match. If the pattern is unanchored, the normal         of the pattern does not match. If the pattern is unanchored, the normal
4849         "bumpalong" advance to the next starting character then happens.  Back-         "bumpalong"  advance to the next starting character then happens. Back-
4850         tracking  can  occur as usual to the left of (*PRUNE), or when matching         tracking can occur as usual to the left of (*PRUNE), or  when  matching
4851         to the right of (*PRUNE), but if there is no match to the right,  back-         to  the right of (*PRUNE), but if there is no match to the right, back-
4852         tracking  cannot  cross (*PRUNE).  In simple cases, the use of (*PRUNE)         tracking cannot cross (*PRUNE).  In simple cases, the use  of  (*PRUNE)
4853         is just an alternative to an atomic group or possessive quantifier, but         is just an alternative to an atomic group or possessive quantifier, but
4854         there  are  some uses of (*PRUNE) that cannot be expressed in any other         there are some uses of (*PRUNE) that cannot be expressed in  any  other
4855         way.         way.
4856    
4857           (*SKIP)           (*SKIP)
4858    
4859         This verb is like (*PRUNE), except that if the pattern  is  unanchored,         This  verb  is like (*PRUNE), except that if the pattern is unanchored,
4860         the  "bumpalong" advance is not to the next character, but to the posi-         the "bumpalong" advance is not to the next character, but to the  posi-
4861         tion in the subject where (*SKIP) was  encountered.  (*SKIP)  signifies         tion  in  the  subject where (*SKIP) was encountered. (*SKIP) signifies
4862         that  whatever  text  was  matched leading up to it cannot be part of a         that whatever text was matched leading up to it cannot  be  part  of  a
4863         successful match. Consider:         successful match. Consider:
4864    
4865           a+(*SKIP)b           a+(*SKIP)b
4866    
4867         If the subject is "aaaac...",  after  the  first  match  attempt  fails         If  the  subject  is  "aaaac...",  after  the first match attempt fails
4868         (starting  at  the  first  character in the string), the starting point         (starting at the first character in the  string),  the  starting  point
4869         skips on to start the next attempt at "c". Note that a possessive quan-         skips on to start the next attempt at "c". Note that a possessive quan-
4870         tifer  does not have the same effect in this example; although it would         tifer does not have the same effect in this example; although it  would
4871         suppress backtracking  during  the  first  match  attempt,  the  second         suppress  backtracking  during  the  first  match  attempt,  the second
4872         attempt  would  start at the second character instead of skipping on to         attempt would start at the second character instead of skipping  on  to
4873         "c".         "c".
4874    
4875           (*THEN)           (*THEN)
4876    
4877         This verb causes a skip to the next alternation if the rest of the pat-         This verb causes a skip to the next alternation if the rest of the pat-
4878         tern does not match. That is, it cancels pending backtracking, but only         tern does not match. That is, it cancels pending backtracking, but only
4879         within the current alternation. Its name  comes  from  the  observation         within  the  current  alternation.  Its name comes from the observation
4880         that it can be used for a pattern-based if-then-else block:         that it can be used for a pattern-based if-then-else block:
4881    
4882           ( COND1 (*THEN) FOO | COND2 (*THEN) BAR | COND3 (*THEN) BAZ ) ...           ( COND1 (*THEN) FOO | COND2 (*THEN) BAR | COND3 (*THEN) BAZ ) ...
4883    
4884         If  the COND1 pattern matches, FOO is tried (and possibly further items         If the COND1 pattern matches, FOO is tried (and possibly further  items
4885         after the end of the group if FOO succeeds);  on  failure  the  matcher         after  the  end  of  the group if FOO succeeds); on failure the matcher
4886         skips  to  the second alternative and tries COND2, without backtracking         skips to the second alternative and tries COND2,  without  backtracking
4887         into COND1. If (*THEN) is used outside  of  any  alternation,  it  acts         into  COND1.  If  (*THEN)  is  used outside of any alternation, it acts
4888         exactly like (*PRUNE).         exactly like (*PRUNE).
4889    
4890    
# Line 4716  AUTHOR Line 4902  AUTHOR
4902    
4903  REVISION  REVISION
4904    
4905         Last updated: 09 August 2007         Last updated: 17 September 2007
4906         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
4907  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
4908    
# Line 4845  CHARACTER CLASSES Line 5031  CHARACTER CLASSES
5031           [^...]      negative character class           [^...]      negative character class
5032           [x-y]       range (can be used for hex characters)           [x-y]       range (can be used for hex characters)
5033           [[:xxx:]]   positive POSIX named set           [[:xxx:]]   positive POSIX named set
5034           [[^:xxx:]]  negative POSIX named set           [[:^xxx:]]  negative POSIX named set
5035    
5036           alnum       alphanumeric           alnum       alphanumeric
5037           alpha       alphabetic           alpha       alphabetic
# Line 5013  BACKTRACKING CONTROL Line 5199  BACKTRACKING CONTROL
5199           (*THEN)        local failure, backtrack to next alternation           (*THEN)        local failure, backtrack to next alternation
5200    
5201    
5202    NEWLINE CONVENTIONS
5203    
5204           These  are  recognized only at the very start of the pattern or after a
5205           (*BSR_...) option.
5206    
5207             (*CR)
5208             (*LF)
5209             (*CRLF)
5210             (*ANYCRLF)
5211             (*ANY)
5212    
5213    
5214    WHAT \R MATCHES
5215    
5216           These are recognized only at the very start of the pattern or  after  a
5217           (*...) option that sets the newline convention.
5218    
5219             (*BSR_ANYCRLF)
5220             (*BSR_UNICODE)
5221    
5222    
5223  CALLOUTS  CALLOUTS
5224    
5225           (?C)      callout           (?C)      callout
# Line 5033  AUTHOR Line 5240  AUTHOR
5240    
5241  REVISION  REVISION
5242    
5243         Last updated: 08 August 2007         Last updated: 14 November 2007
5244         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
5245  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
5246    
# Line 5837  MATCHING INTERFACE Line 6044  MATCHING INTERFACE
6044    
6045           c. The "i"th argument has a suitable type for holding the           c. The "i"th argument has a suitable type for holding the
6046              string captured as the "i"th sub-pattern. If you pass in              string captured as the "i"th sub-pattern. If you pass in
6047              NULL for the "i"th argument, or pass fewer arguments than              void * NULL for the "i"th argument, or a non-void * NULL
6048                of the correct type, or pass fewer arguments than the
6049              number of sub-patterns, "i"th captured sub-pattern is              number of sub-patterns, "i"th captured sub-pattern is
6050              ignored.              ignored.
6051    
# Line 6085  AUTHOR Line 6293  AUTHOR
6293    
6294  REVISION  REVISION
6295    
6296         Last updated: 06 March 2007         Last updated: 12 November 2007
6297  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
6298    
6299    
# Line 6113  PCRE SAMPLE PROGRAM Line 6321  PCRE SAMPLE PROGRAM
6321         bility  of  matching an empty string. Comments in the code explain what         bility  of  matching an empty string. Comments in the code explain what
6322         is going on.         is going on.
6323    
6324         The demonstration program is automatically built if you use  "./config-         If PCRE is installed in the standard include  and  library  directories
6325         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-
6326         dard include and library directories for your  system,  you  should  be         gram using this command:
        able to compile the demonstration program using this command:  
6327    
6328           gcc -o pcredemo pcredemo.c -lpcre           gcc -o pcredemo pcredemo.c -lpcre
6329    
6330         If  PCRE is installed elsewhere, you may need to add additional options         If PCRE is installed elsewhere, you may need to add additional  options
6331         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
6332         installed  in  /usr/local,  you  can  compile the demonstration program         installe