/[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 261 by ph10, Fri Sep 21 08:37:48 2007 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    
# Line 513  AUTHOR Line 531  AUTHOR
531    
532  REVISION  REVISION
533    
534         Last updated: 30 July 2007         Last updated: 21 September 2007
535         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
536  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
537    
# Line 908  NEWLINES Line 926  NEWLINES
926         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
927         pattern is compiled, or when it is matched.         pattern is compiled, or when it is matched.
928    
929           At compile time, the newline convention can be specified by the options
930           argument of pcre_compile(), or it can be specified by special  text  at
931           the start of the pattern itself; this overrides any other settings. See
932           the pcrepattern page for details of the special character sequences.
933    
934         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-
935         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
936         newline  convention  affects  the  handling of the dot, circumflex, and         newline convention affects the handling of  the  dot,  circumflex,  and
937         dollar metacharacters, the handling of #-comments in /x mode, and, when         dollar metacharacters, the handling of #-comments in /x mode, and, when
938         CRLF  is a recognized line ending sequence, the match position advance-         CRLF is a recognized line ending sequence, the match position  advance-
939         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
940         not affect the interpretation of the \n or \r escape sequences.         section on pcre_exec() options below.
941    
942           The choice of newline convention does not affect the interpretation  of
943           the  \n  or  \r  escape  sequences, nor does it affect what \R matches,
944           which is controlled in a similar way, but by separate options.
945    
946    
947  MULTITHREADING  MULTITHREADING
948    
949         The  PCRE  functions  can be used in multi-threading applications, with         The PCRE functions can be used in  multi-threading  applications,  with
950         the  proviso  that  the  memory  management  functions  pointed  to  by         the  proviso  that  the  memory  management  functions  pointed  to  by
951         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
952         callout function pointed to by pcre_callout, are shared by all threads.         callout function pointed to by pcre_callout, are shared by all threads.
953    
954         The  compiled form of a regular expression is not altered during match-         The compiled form of a regular expression is not altered during  match-
955         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
956         at once.         at once.
957    
# Line 932  MULTITHREADING Line 959  MULTITHREADING
959  SAVING PRECOMPILED PATTERNS FOR LATER USE  SAVING PRECOMPILED PATTERNS FOR LATER USE
960    
961         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
962         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
963         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
964         pcreprecompile documentation. However, compiling a  regular  expression         pcreprecompile  documentation.  However, compiling a regular expression
965         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-
966         anteed to work and may cause crashes.         anteed to work and may cause crashes.
967    
968    
# Line 943  CHECKING BUILD-TIME OPTIONS Line 970  CHECKING BUILD-TIME OPTIONS
970    
971         int pcre_config(int what, void *where);         int pcre_config(int what, void *where);
972    
973         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-
974         cover which optional features have been compiled into the PCRE library.         cover which optional features have been compiled into the PCRE library.
975         The pcrebuild documentation has more details about these optional  fea-         The  pcrebuild documentation has more details about these optional fea-
976         tures.         tures.
977    
978         The  first  argument  for pcre_config() is an integer, specifying which         The first argument for pcre_config() is an  integer,  specifying  which
979         information is required; the second argument is a pointer to a variable         information is required; the second argument is a pointer to a variable
980         into  which  the  information  is  placed. The following information is         into which the information is  placed.  The  following  information  is
981         available:         available:
982    
983           PCRE_CONFIG_UTF8           PCRE_CONFIG_UTF8
984    
985         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-
986         able; otherwise it is set to zero.         able; otherwise it is set to zero.
987    
988           PCRE_CONFIG_UNICODE_PROPERTIES           PCRE_CONFIG_UNICODE_PROPERTIES
989    
990         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
991         character properties is available; otherwise it is set to zero.         character properties is available; otherwise it is set to zero.
992    
993           PCRE_CONFIG_NEWLINE           PCRE_CONFIG_NEWLINE
994    
995         The output is an integer whose value specifies  the  default  character         The  output  is  an integer whose value specifies the default character
996         sequence  that is recognized as meaning "newline". The four values that         sequence that is recognized as meaning "newline". The four values  that
997         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,
998         and  -1  for  ANY. The default should normally be the standard sequence         and -1 for ANY. The default should normally be  the  standard  sequence
999         for your operating system.         for your operating system.
1000    
1001             PCRE_CONFIG_BSR
1002    
1003           The output is an integer whose value indicates what character sequences
1004           the \R escape sequence matches by default. A value of 0 means  that  \R
1005           matches  any  Unicode  line ending sequence; a value of 1 means that \R
1006           matches only CR, LF, or CRLF. The default can be overridden when a pat-
1007           tern is compiled or matched.
1008    
1009           PCRE_CONFIG_LINK_SIZE           PCRE_CONFIG_LINK_SIZE
1010    
1011         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
1012         internal linkage in compiled regular expressions. The value is 2, 3, or         internal linkage in compiled regular expressions. The value is 2, 3, or
1013         4. Larger values allow larger regular expressions to  be  compiled,  at         4.  Larger  values  allow larger regular expressions to be compiled, at
1014         the  expense  of  slower matching. The default value of 2 is sufficient         the expense of slower matching. The default value of  2  is  sufficient
1015         for all but the most massive patterns, since  it  allows  the  compiled         for  all  but  the  most massive patterns, since it allows the compiled
1016         pattern to be up to 64K in size.         pattern to be up to 64K in size.
1017    
1018           PCRE_CONFIG_POSIX_MALLOC_THRESHOLD           PCRE_CONFIG_POSIX_MALLOC_THRESHOLD
1019    
1020         The  output  is  an integer that contains the threshold above which the         The output is an integer that contains the threshold  above  which  the
1021         POSIX interface uses malloc() for output vectors. Further  details  are         POSIX  interface  uses malloc() for output vectors. Further details are
1022         given in the pcreposix documentation.         given in the pcreposix documentation.
1023    
1024           PCRE_CONFIG_MATCH_LIMIT           PCRE_CONFIG_MATCH_LIMIT
1025    
1026         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
1027         internal matching function calls in a  pcre_exec()  execution.  Further         internal  matching  function  calls in a pcre_exec() execution. Further
1028         details are given with pcre_exec() below.         details are given with pcre_exec() below.
1029    
1030           PCRE_CONFIG_MATCH_LIMIT_RECURSION           PCRE_CONFIG_MATCH_LIMIT_RECURSION
1031    
1032         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
1033         recursion when calling the internal matching function in a  pcre_exec()         recursion  when calling the internal matching function in a pcre_exec()
1034         execution. Further details are given with pcre_exec() below.         execution. Further details are given with pcre_exec() below.
1035    
1036           PCRE_CONFIG_STACKRECURSE           PCRE_CONFIG_STACKRECURSE
1037    
1038         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
1039         running pcre_exec() is implemented by recursive function calls that use         running pcre_exec() is implemented by recursive function calls that use
1040         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
1041         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
1042         on  the  heap  instead  of  recursive  function  calls.  In  this case,         on the  heap  instead  of  recursive  function  calls.  In  this  case,
1043         pcre_stack_malloc and  pcre_stack_free  are  called  to  manage  memory         pcre_stack_malloc  and  pcre_stack_free  are  called  to  manage memory
1044         blocks on the heap, thus avoiding the use of the stack.         blocks on the heap, thus avoiding the use of the stack.
1045    
1046    
# Line 1022  COMPILING A PATTERN Line 1057  COMPILING A PATTERN
1057    
1058         Either of the functions pcre_compile() or pcre_compile2() can be called         Either of the functions pcre_compile() or pcre_compile2() can be called
1059         to compile a pattern into an internal form. The only difference between         to compile a pattern into an internal form. The only difference between
1060         the  two interfaces is that pcre_compile2() has an additional argument,         the two interfaces is that pcre_compile2() has an additional  argument,
1061         errorcodeptr, via which a numerical error code can be returned.         errorcodeptr, via which a numerical error code can be returned.
1062    
1063         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
1064         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
1065         obtained via pcre_malloc is returned. This contains the  compiled  code         obtained  via  pcre_malloc is returned. This contains the compiled code
1066         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
1067         is a typedef for a structure whose contents are not externally defined.         is a typedef for a structure whose contents are not externally defined.
1068         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
1069         longer required.         longer required.
1070    
1071         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
1072         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
1073         fully relocatable, because it may contain a copy of the tableptr  argu-         fully  relocatable, because it may contain a copy of the tableptr argu-
1074         ment, which is an address (see below).         ment, which is an address (see below).
1075    
1076         The options argument contains various bit settings that affect the com-         The options argument contains various bit settings that affect the com-
1077         pilation. It should be zero if no options are required.  The  available         pilation.  It  should be zero if no options are required. The available
1078         options  are  described  below. Some of them, in particular, those that         options are described below. Some of them, in  particular,  those  that
1079         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
1080         pattern  (see  the  detailed  description in the pcrepattern documenta-         pattern (see the detailed description  in  the  pcrepattern  documenta-
1081         tion). For these options, the contents of the options  argument  speci-         tion).  For  these options, the contents of the options argument speci-
1082         fies  their initial settings at the start of compilation and execution.         fies their initial settings at the start of compilation and  execution.
1083         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
1084         of matching as well as at compile time.         of matching as well as at compile time.
1085    
1086         If errptr is NULL, pcre_compile() returns NULL immediately.  Otherwise,         If errptr is NULL, pcre_compile() returns NULL immediately.  Otherwise,
1087         if compilation of a pattern fails,  pcre_compile()  returns  NULL,  and         if  compilation  of  a  pattern fails, pcre_compile() returns NULL, and
1088         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-
1089         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
1090         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-
1091         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
1092         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
1093         given.         given.
1094    
1095         If pcre_compile2() is used instead of pcre_compile(),  and  the  error-         If  pcre_compile2()  is  used instead of pcre_compile(), and the error-
1096         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
1097         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
1098         textual error message. Error codes and messages are listed below.         textual error message. Error codes and messages are listed below.
1099    
1100         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
1101         character tables that are  built  when  PCRE  is  compiled,  using  the         character  tables  that  are  built  when  PCRE  is compiled, using the
1102         default  C  locale.  Otherwise, tableptr must be an address that is the         default C locale. Otherwise, tableptr must be an address  that  is  the
1103         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
1104         compiled  pattern,  and used again by pcre_exec(), unless another table         compiled pattern, and used again by pcre_exec(), unless  another  table
1105         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
1106         support below.         support below.
1107    
1108         This  code  fragment  shows a typical straightforward call to pcre_com-         This code fragment shows a typical straightforward  call  to  pcre_com-
1109         pile():         pile():
1110    
1111           pcre *re;           pcre *re;
# Line 1083  COMPILING A PATTERN Line 1118  COMPILING A PATTERN
1118             &erroffset,       /* for error offset */             &erroffset,       /* for error offset */
1119             NULL);            /* use default character tables */             NULL);            /* use default character tables */
1120    
1121         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
1122         file:         file:
1123    
1124           PCRE_ANCHORED           PCRE_ANCHORED
1125    
1126         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
1127         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
1128         that  is being searched (the "subject string"). This effect can also be         that is being searched (the "subject string"). This effect can also  be
1129         achieved by appropriate constructs in the pattern itself, which is  the         achieved  by appropriate constructs in the pattern itself, which is the
1130         only way to do it in Perl.         only way to do it in Perl.
1131    
1132           PCRE_AUTO_CALLOUT           PCRE_AUTO_CALLOUT
1133    
1134         If this bit is set, pcre_compile() automatically inserts callout items,         If this bit is set, pcre_compile() automatically inserts callout items,
1135         all with number 255, before each pattern item. For  discussion  of  the         all  with  number  255, before each pattern item. For discussion of the
1136         callout facility, see the pcrecallout documentation.         callout facility, see the pcrecallout documentation.
1137    
1138             PCRE_BSR_ANYCRLF
1139             PCRE_BSR_UNICODE
1140    
1141           These options (which are mutually exclusive) control what the \R escape
1142           sequence  matches.  The choice is either to match only CR, LF, or CRLF,
1143           or to match any Unicode newline sequence. The default is specified when
1144           PCRE is built. It can be overridden from within the pattern, or by set-
1145           ting an option when a compiled pattern is matched.
1146    
1147           PCRE_CASELESS           PCRE_CASELESS
1148    
1149         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
1150         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
1151         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
1152         always understands the concept of case for characters whose values  are         always  understands the concept of case for characters whose values are
1153         less  than 128, so caseless matching is always possible. For characters         less than 128, so caseless matching is always possible. For  characters
1154         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-
1155         piled  with Unicode property support, but not otherwise. If you want to         piled with Unicode property support, but not otherwise. If you want  to
1156         use caseless matching for characters 128 and  above,  you  must  ensure         use  caseless  matching  for  characters 128 and above, you must ensure
1157         that  PCRE  is  compiled  with Unicode property support as well as with         that PCRE is compiled with Unicode property support  as  well  as  with
1158         UTF-8 support.         UTF-8 support.
1159    
1160           PCRE_DOLLAR_ENDONLY           PCRE_DOLLAR_ENDONLY
1161    
1162         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
1163         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
1164         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
1165         before  any  other newlines). The PCRE_DOLLAR_ENDONLY option is ignored         before any other newlines). The PCRE_DOLLAR_ENDONLY option  is  ignored
1166         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
1167         Perl, and no way to set it within a pattern.         Perl, and no way to set it within a pattern.
1168    
1169           PCRE_DOTALL           PCRE_DOTALL
1170    
1171         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-
1172         acters, including those that indicate newline. Without it, a  dot  does         acters,  including  those that indicate newline. Without it, a dot does
1173         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
1174         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
1175         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
1176         newline characters, independent of the setting of this option.         newline characters, independent of the setting of this option.
1177    
1178           PCRE_DUPNAMES           PCRE_DUPNAMES
1179    
1180         If this bit is set, names used to identify capturing  subpatterns  need         If  this  bit is set, names used to identify capturing subpatterns need
1181         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
1182         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
1183         matched.  There  are  more details of named subpatterns below; see also         matched. There are more details of named subpatterns  below;  see  also
1184         the pcrepattern documentation.         the pcrepattern documentation.
1185    
1186           PCRE_EXTENDED           PCRE_EXTENDED
1187    
1188         If this bit is set, whitespace  data  characters  in  the  pattern  are         If  this  bit  is  set,  whitespace  data characters in the pattern are
1189         totally ignored except when escaped or inside a character class. White-         totally ignored except when escaped or inside a character class. White-
1190         space does not include the VT character (code 11). In addition, charac-         space does not include the VT character (code 11). In addition, charac-
1191         ters between an unescaped # outside a character class and the next new-         ters between an unescaped # outside a character class and the next new-
1192         line, inclusive, are also ignored. This  is  equivalent  to  Perl's  /x         line,  inclusive,  are  also  ignored.  This is equivalent to Perl's /x
1193         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-
1194         ting.         ting.
1195    
1196         This option makes it possible to include  comments  inside  complicated         This  option  makes  it possible to include comments inside complicated
1197         patterns.   Note,  however,  that this applies only to data characters.         patterns.  Note, however, that this applies only  to  data  characters.
1198         Whitespace  characters  may  never  appear  within  special   character         Whitespace   characters  may  never  appear  within  special  character
1199         sequences  in  a  pattern,  for  example  within the sequence (?( which         sequences in a pattern, for  example  within  the  sequence  (?(  which
1200         introduces a conditional subpattern.         introduces a conditional subpattern.
1201    
1202           PCRE_EXTRA           PCRE_EXTRA
1203    
1204         This option was invented in order to turn on  additional  functionality         This  option  was invented in order to turn on additional functionality
1205         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
1206         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
1207         letter  that  has  no  special  meaning causes an error, thus reserving         letter that has no special meaning  causes  an  error,  thus  reserving
1208         these combinations for future expansion. By  default,  as  in  Perl,  a         these  combinations  for  future  expansion.  By default, as in Perl, a
1209         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
1210         literal. (Perl can, however, be persuaded to give a warning for  this.)         literal.  (Perl can, however, be persuaded to give a warning for this.)
1211         There  are  at  present no other features controlled by this option. It         There are at present no other features controlled by  this  option.  It
1212         can also be set by a (?X) option setting within a pattern.         can also be set by a (?X) option setting within a pattern.
1213    
1214           PCRE_FIRSTLINE           PCRE_FIRSTLINE
1215    
1216         If this option is set, an  unanchored  pattern  is  required  to  match         If  this  option  is  set,  an  unanchored pattern is required to match
1217         before  or  at  the  first  newline  in  the subject string, though the         before or at the first  newline  in  the  subject  string,  though  the
1218         matched text may continue over the newline.         matched text may continue over the newline.
1219    
1220           PCRE_MULTILINE           PCRE_MULTILINE
1221    
1222         By default, PCRE treats the subject string as consisting  of  a  single         By  default,  PCRE  treats the subject string as consisting of a single
1223         line  of characters (even if it actually contains newlines). The "start         line of characters (even if it actually contains newlines). The  "start
1224         of line" metacharacter (^) matches only at the  start  of  the  string,         of  line"  metacharacter  (^)  matches only at the start of the string,
1225         while  the  "end  of line" metacharacter ($) matches only at the end of         while the "end of line" metacharacter ($) matches only at  the  end  of
1226         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY
1227         is set). This is the same as Perl.         is set). This is the same as Perl.
1228    
1229         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"
1230         constructs match immediately following or immediately  before  internal         constructs  match  immediately following or immediately before internal
1231         newlines  in  the  subject string, respectively, as well as at the very         newlines in the subject string, respectively, as well as  at  the  very
1232         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
1233         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-
1234         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,
1235         setting PCRE_MULTILINE has no effect.         setting PCRE_MULTILINE has no effect.
1236    
1237           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
# Line 1196  COMPILING A PATTERN Line 1240  COMPILING A PATTERN
1240           PCRE_NEWLINE_ANYCRLF           PCRE_NEWLINE_ANYCRLF
1241           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
1242    
1243         These  options  override the default newline definition that was chosen         These options override the default newline definition that  was  chosen
1244         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
1245         newline  is  indicated  by a single character (CR or LF, respectively).         newline is indicated by a single character (CR  or  LF,  respectively).
1246         Setting PCRE_NEWLINE_CRLF specifies that a newline is indicated by  the         Setting  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the
1247         two-character  CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF specifies         two-character CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF  specifies
1248         that any of the three preceding sequences should be recognized. Setting         that any of the three preceding sequences should be recognized. Setting
1249         PCRE_NEWLINE_ANY  specifies that any Unicode newline sequence should be         PCRE_NEWLINE_ANY specifies that any Unicode newline sequence should  be
1250         recognized. The Unicode newline sequences are the three just mentioned,         recognized. The Unicode newline sequences are the three just mentioned,
1251         plus  the  single  characters  VT (vertical tab, U+000B), FF (formfeed,         plus the single characters VT (vertical  tab,  U+000B),  FF  (formfeed,
1252         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
1253         (paragraph  separator,  U+2029).  The  last  two are recognized only in         (paragraph separator, U+2029). The last  two  are  recognized  only  in
1254         UTF-8 mode.         UTF-8 mode.
1255    
1256         The newline setting in the  options  word  uses  three  bits  that  are         The  newline  setting  in  the  options  word  uses three bits that are
1257         treated as a number, giving eight possibilities. Currently only six are         treated as a number, giving eight possibilities. Currently only six are
1258         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
1259         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-
1260         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
1261         PCRE_NEWLINE_CRLF,  but other combinations may yield unused numbers and         PCRE_NEWLINE_CRLF, but other combinations may yield unused numbers  and
1262         cause an error.         cause an error.
1263    
1264         The only time that a line break is specially recognized when  compiling         The  only time that a line break is specially recognized when compiling
1265         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
1266         character class is encountered. This indicates  a  comment  that  lasts         character  class  is  encountered.  This indicates a comment that lasts
1267         until  after the next line break sequence. In other circumstances, line         until after the next line break sequence. In other circumstances,  line
1268         break  sequences  are  treated  as  literal  data,   except   that   in         break   sequences   are   treated  as  literal  data,  except  that  in
1269         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters
1270         and are therefore ignored.         and are therefore ignored.
1271    
1272         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
1273         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.
1274    
1275           PCRE_NO_AUTO_CAPTURE           PCRE_NO_AUTO_CAPTURE
1276    
1277         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-
1278         theses  in the pattern. Any opening parenthesis that is not followed by         theses in the pattern. Any opening parenthesis that is not followed  by
1279         ? behaves as if it were followed by ?: but named parentheses can  still         ?  behaves as if it were followed by ?: but named parentheses can still
1280         be  used  for  capturing  (and  they acquire numbers in the usual way).         be used for capturing (and they acquire  numbers  in  the  usual  way).
1281         There is no equivalent of this option in Perl.         There is no equivalent of this option in Perl.
1282    
1283           PCRE_UNGREEDY           PCRE_UNGREEDY
1284    
1285         This option inverts the "greediness" of the quantifiers  so  that  they         This  option  inverts  the "greediness" of the quantifiers so that they
1286         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
1287         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
1288         within the pattern.         within the pattern.
1289    
1290           PCRE_UTF8           PCRE_UTF8
1291    
1292         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
1293         strings of UTF-8 characters instead of single-byte  character  strings.         strings  of  UTF-8 characters instead of single-byte character strings.
1294         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-
1295         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
1296         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
1297         UTF-8 support in the main pcre page.         UTF-8 support in the main pcre page.
1298    
1299           PCRE_NO_UTF8_CHECK           PCRE_NO_UTF8_CHECK
1300    
1301         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
1302         automatically  checked.  There  is  a  discussion about the validity of         automatically checked. There is a  discussion  about  the  validity  of
1303         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
1304         bytes  is  found,  pcre_compile() returns an error. If you already know         bytes is found, pcre_compile() returns an error. If  you  already  know
1305         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-
1306         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
1307         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
1308         undefined.  It  may  cause your program to crash. Note that this option         undefined. It may cause your program to crash. Note  that  this  option
1309         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
1310         UTF-8 validity checking of subject strings.         UTF-8 validity checking of subject strings.
1311    
1312    
1313  COMPILATION ERROR CODES  COMPILATION ERROR CODES
1314    
1315         The  following  table  lists  the  error  codes than may be returned by         The following table lists the error  codes  than  may  be  returned  by
1316         pcre_compile2(), along with the error messages that may be returned  by         pcre_compile2(),  along with the error messages that may be returned by
1317         both  compiling functions. As PCRE has developed, some error codes have         both compiling functions. As PCRE has developed, some error codes  have
1318         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.
1319    
1320            0  no error            0  no error
# Line 1326  COMPILATION ERROR CODES Line 1370  COMPILATION ERROR CODES
1370           50  [this code is not in use]           50  [this code is not in use]
1371           51  octal value is greater than \377 (not in UTF-8 mode)           51  octal value is greater than \377 (not in UTF-8 mode)
1372           52  internal error: overran compiling workspace           52  internal error: overran compiling workspace
1373           53  internal  error:  previously-checked  referenced  subpattern  not           53   internal  error:  previously-checked  referenced  subpattern not
1374         found         found
1375           54  DEFINE group contains more than one branch           54  DEFINE group contains more than one branch
1376           55  repeating a DEFINE group is not allowed           55  repeating a DEFINE group is not allowed
1377           56  inconsistent NEWLINE options"           56  inconsistent NEWLINE options
1378           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
1379                 non-zero number                 non-zero number
1380           58  (?+ or (?- or (?(+ or (?(- must be followed by a non-zero number           58  (?+ or (?- or (?(+ or (?(- must be followed by a non-zero number
# Line 1341  STUDYING A PATTERN Line 1385  STUDYING A PATTERN
1385         pcre_extra *pcre_study(const pcre *code, int options         pcre_extra *pcre_study(const pcre *code, int options
1386              const char **errptr);              const char **errptr);
1387    
1388         If  a  compiled  pattern is going to be used several times, it is worth         If a compiled pattern is going to be used several times,  it  is  worth
1389         spending more time analyzing it in order to speed up the time taken for         spending more time analyzing it in order to speed up the time taken for
1390         matching.  The function pcre_study() takes a pointer to a compiled pat-         matching. The function pcre_study() takes a pointer to a compiled  pat-
1391         tern as its first argument. If studying the pattern produces additional         tern as its first argument. If studying the pattern produces additional
1392         information  that  will  help speed up matching, pcre_study() returns a         information that will help speed up matching,  pcre_study()  returns  a
1393         pointer to a pcre_extra block, in which the study_data field points  to         pointer  to a pcre_extra block, in which the study_data field points to
1394         the results of the study.         the results of the study.
1395    
1396         The  returned  value  from  pcre_study()  can  be  passed  directly  to         The  returned  value  from  pcre_study()  can  be  passed  directly  to
1397         pcre_exec(). However, a pcre_extra block  also  contains  other  fields         pcre_exec().  However,  a  pcre_extra  block also contains other fields
1398         that  can  be  set  by the caller before the block is passed; these are         that can be set by the caller before the block  is  passed;  these  are
1399         described below in the section on matching a pattern.         described below in the section on matching a pattern.
1400    
1401         If studying the pattern does not  produce  any  additional  information         If  studying  the  pattern  does not produce any additional information
1402         pcre_study() returns NULL. In that circumstance, if the calling program         pcre_study() returns NULL. In that circumstance, if the calling program
1403         wants to pass any of the other fields to pcre_exec(), it  must  set  up         wants  to  pass  any of the other fields to pcre_exec(), it must set up
1404         its own pcre_extra block.         its own pcre_extra block.
1405    
1406         The  second  argument of pcre_study() contains option bits. At present,         The second argument of pcre_study() contains option bits.  At  present,
1407         no options are defined, and this argument should always be zero.         no options are defined, and this argument should always be zero.
1408    
1409         The third argument for pcre_study() is a pointer for an error  message.         The  third argument for pcre_study() is a pointer for an error message.
1410         If  studying  succeeds  (even  if no data is returned), the variable it         If studying succeeds (even if no data is  returned),  the  variable  it
1411         points to is set to NULL. Otherwise it is set to  point  to  a  textual         points  to  is  set  to NULL. Otherwise it is set to point to a textual
1412         error message. This is a static string that is part of the library. You         error message. This is a static string that is part of the library. You
1413         must not try to free it. You should test the  error  pointer  for  NULL         must  not  try  to  free it. You should test the error pointer for NULL
1414         after calling pcre_study(), to be sure that it has run successfully.         after calling pcre_study(), to be sure that it has run successfully.
1415    
1416         This is a typical call to pcre_study():         This is a typical call to pcre_study():
# Line 1378  STUDYING A PATTERN Line 1422  STUDYING A PATTERN
1422             &error);        /* set to NULL or points to a message */             &error);        /* set to NULL or points to a message */
1423    
1424         At present, studying a pattern is useful only for non-anchored patterns         At present, studying a pattern is useful only for non-anchored patterns
1425         that do not have a single fixed starting character. A bitmap of  possi-         that  do not have a single fixed starting character. A bitmap of possi-
1426         ble starting bytes is created.         ble starting bytes is created.
1427    
1428    
1429  LOCALE SUPPORT  LOCALE SUPPORT
1430    
1431         PCRE  handles  caseless matching, and determines whether characters are         PCRE handles caseless matching, and determines whether  characters  are
1432         letters, digits, or whatever, by reference to a set of tables,  indexed         letters,  digits, or whatever, by reference to a set of tables, indexed
1433         by  character  value.  When running in UTF-8 mode, this applies only to         by character value. When running in UTF-8 mode, this  applies  only  to
1434         characters with codes less than 128. Higher-valued  codes  never  match         characters  with  codes  less than 128. Higher-valued codes never match
1435         escapes  such  as  \w or \d, but can be tested with \p if PCRE is built         escapes such as \w or \d, but can be tested with \p if  PCRE  is  built
1436         with Unicode character property support. The use of locales  with  Uni-         with  Unicode  character property support. The use of locales with Uni-
1437         code  is discouraged. If you are handling characters with codes greater         code is discouraged. If you are handling characters with codes  greater
1438         than 128, you should either use UTF-8 and Unicode, or use locales,  but         than  128, you should either use UTF-8 and Unicode, or use locales, but
1439         not try to mix the two.         not try to mix the two.
1440    
1441         PCRE  contains  an  internal set of tables that are used when the final         PCRE contains an internal set of tables that are used  when  the  final
1442         argument of pcre_compile() is  NULL.  These  are  sufficient  for  many         argument  of  pcre_compile()  is  NULL.  These  are sufficient for many
1443         applications.  Normally, the internal tables recognize only ASCII char-         applications.  Normally, the internal tables recognize only ASCII char-
1444         acters. However, when PCRE is built, it is possible to cause the inter-         acters. However, when PCRE is built, it is possible to cause the inter-
1445         nal tables to be rebuilt in the default "C" locale of the local system,         nal tables to be rebuilt in the default "C" locale of the local system,
1446         which may cause them to be different.         which may cause them to be different.
1447    
1448         The internal tables can always be overridden by tables supplied by  the         The  internal tables can always be overridden by tables supplied by the
1449         application that calls PCRE. These may be created in a different locale         application that calls PCRE. These may be created in a different locale
1450         from the default. As more and more applications change  to  using  Uni-         from  the  default.  As more and more applications change to using Uni-
1451         code, the need for this locale support is expected to die away.         code, the need for this locale support is expected to die away.
1452    
1453         External  tables  are  built by calling the pcre_maketables() function,         External tables are built by calling  the  pcre_maketables()  function,
1454         which has no arguments, in the relevant locale. The result can then  be         which  has no arguments, in the relevant locale. The result can then be
1455         passed  to  pcre_compile()  or  pcre_exec()  as often as necessary. For         passed to pcre_compile() or pcre_exec()  as  often  as  necessary.  For
1456         example, to build and use tables that are appropriate  for  the  French         example,  to  build  and use tables that are appropriate for the French
1457         locale  (where  accented  characters  with  values greater than 128 are         locale (where accented characters with  values  greater  than  128  are
1458         treated as letters), the following code could be used:         treated as letters), the following code could be used:
1459    
1460           setlocale(LC_CTYPE, "fr_FR");           setlocale(LC_CTYPE, "fr_FR");
1461           tables = pcre_maketables();           tables = pcre_maketables();
1462           re = pcre_compile(..., tables);           re = pcre_compile(..., tables);
1463    
1464         The locale name "fr_FR" is used on Linux and other  Unix-like  systems;         The  locale  name "fr_FR" is used on Linux and other Unix-like systems;
1465         if you are using Windows, the name for the French locale is "french".         if you are using Windows, the name for the French locale is "french".
1466    
1467         When  pcre_maketables()  runs,  the  tables are built in memory that is         When pcre_maketables() runs, the tables are built  in  memory  that  is
1468         obtained via pcre_malloc. It is the caller's responsibility  to  ensure         obtained  via  pcre_malloc. It is the caller's responsibility to ensure
1469         that  the memory containing the tables remains available for as long as         that the memory containing the tables remains available for as long  as
1470         it is needed.         it is needed.
1471    
1472         The pointer that is passed to pcre_compile() is saved with the compiled         The pointer that is passed to pcre_compile() is saved with the compiled
1473         pattern,  and the same tables are used via this pointer by pcre_study()         pattern, and the same tables are used via this pointer by  pcre_study()
1474         and normally also by pcre_exec(). Thus, by default, for any single pat-         and normally also by pcre_exec(). Thus, by default, for any single pat-
1475         tern, compilation, studying and matching all happen in the same locale,         tern, compilation, studying and matching all happen in the same locale,
1476         but different patterns can be compiled in different locales.         but different patterns can be compiled in different locales.
1477    
1478         It is possible to pass a table pointer or NULL (indicating the  use  of         It  is  possible to pass a table pointer or NULL (indicating the use of
1479         the  internal  tables)  to  pcre_exec(). Although not intended for this         the internal tables) to pcre_exec(). Although  not  intended  for  this
1480         purpose, this facility could be used to match a pattern in a  different         purpose,  this facility could be used to match a pattern in a different
1481         locale from the one in which it was compiled. Passing table pointers at         locale from the one in which it was compiled. Passing table pointers at
1482         run time is discussed below in the section on matching a pattern.         run time is discussed below in the section on matching a pattern.
1483    
# Line 1443  INFORMATION ABOUT A PATTERN Line 1487  INFORMATION ABOUT A PATTERN
1487         int pcre_fullinfo(const pcre *code, const pcre_extra *extra,         int pcre_fullinfo(const pcre *code, const pcre_extra *extra,
1488              int what, void *where);              int what, void *where);
1489    
1490         The pcre_fullinfo() function returns information about a compiled  pat-         The  pcre_fullinfo() function returns information about a compiled pat-
1491         tern. It replaces the obsolete pcre_info() function, which is neverthe-         tern. It replaces the obsolete pcre_info() function, which is neverthe-
1492         less retained for backwards compability (and is documented below).         less retained for backwards compability (and is documented below).
1493    
1494         The first argument for pcre_fullinfo() is a  pointer  to  the  compiled         The  first  argument  for  pcre_fullinfo() is a pointer to the compiled
1495         pattern.  The second argument is the result of pcre_study(), or NULL if         pattern. The second argument is the result of pcre_study(), or NULL  if
1496         the pattern was not studied. The third argument specifies  which  piece         the  pattern  was not studied. The third argument specifies which piece
1497         of  information  is required, and the fourth argument is a pointer to a         of information is required, and the fourth argument is a pointer  to  a
1498         variable to receive the data. The yield of the  function  is  zero  for         variable  to  receive  the  data. The yield of the function is zero for
1499         success, or one of the following negative numbers:         success, or one of the following negative numbers:
1500    
1501           PCRE_ERROR_NULL       the argument code was NULL           PCRE_ERROR_NULL       the argument code was NULL
# Line 1459  INFORMATION ABOUT A PATTERN Line 1503  INFORMATION ABOUT A PATTERN
1503           PCRE_ERROR_BADMAGIC   the "magic number" was not found           PCRE_ERROR_BADMAGIC   the "magic number" was not found
1504           PCRE_ERROR_BADOPTION  the value of what was invalid           PCRE_ERROR_BADOPTION  the value of what was invalid
1505    
1506         The  "magic  number" is placed at the start of each compiled pattern as         The "magic number" is placed at the start of each compiled  pattern  as
1507         an simple check against passing an arbitrary memory pointer. Here is  a         an  simple check against passing an arbitrary memory pointer. Here is a
1508         typical  call  of pcre_fullinfo(), to obtain the length of the compiled         typical call of pcre_fullinfo(), to obtain the length of  the  compiled
1509         pattern:         pattern:
1510    
1511           int rc;           int rc;
# Line 1472  INFORMATION ABOUT A PATTERN Line 1516  INFORMATION ABOUT A PATTERN
1516             PCRE_INFO_SIZE,   /* what is required */             PCRE_INFO_SIZE,   /* what is required */
1517             &length);         /* where to put the data */             &length);         /* where to put the data */
1518    
1519         The possible values for the third argument are defined in  pcre.h,  and         The  possible  values for the third argument are defined in pcre.h, and
1520         are as follows:         are as follows:
1521    
1522           PCRE_INFO_BACKREFMAX           PCRE_INFO_BACKREFMAX
1523    
1524         Return  the  number  of  the highest back reference in the pattern. The         Return the number of the highest back reference  in  the  pattern.  The
1525         fourth argument should point to an int variable. Zero  is  returned  if         fourth  argument  should  point to an int variable. Zero is returned if
1526         there are no back references.         there are no back references.
1527    
1528           PCRE_INFO_CAPTURECOUNT           PCRE_INFO_CAPTURECOUNT
1529    
1530         Return  the  number of capturing subpatterns in the pattern. The fourth         Return the number of capturing subpatterns in the pattern.  The  fourth
1531         argument should point to an int variable.         argument should point to an int variable.
1532    
1533           PCRE_INFO_DEFAULT_TABLES           PCRE_INFO_DEFAULT_TABLES
1534    
1535         Return a pointer to the internal default character tables within  PCRE.         Return  a pointer to the internal default character tables within PCRE.
1536         The  fourth  argument should point to an unsigned char * variable. This         The fourth argument should point to an unsigned char *  variable.  This
1537         information call is provided for internal use by the pcre_study() func-         information call is provided for internal use by the pcre_study() func-
1538         tion.  External  callers  can  cause PCRE to use its internal tables by         tion. External callers can cause PCRE to use  its  internal  tables  by
1539         passing a NULL table pointer.         passing a NULL table pointer.
1540    
1541           PCRE_INFO_FIRSTBYTE           PCRE_INFO_FIRSTBYTE
1542    
1543         Return information about the first byte of any matched  string,  for  a         Return  information  about  the first byte of any matched string, for a
1544         non-anchored  pattern. The fourth argument should point to an int vari-         non-anchored pattern. The fourth argument should point to an int  vari-
1545         able. (This option used to be called PCRE_INFO_FIRSTCHAR; the old  name         able.  (This option used to be called PCRE_INFO_FIRSTCHAR; the old name
1546         is still recognized for backwards compatibility.)         is still recognized for backwards compatibility.)
1547    
1548         If  there  is  a  fixed first byte, for example, from a pattern such as         If there is a fixed first byte, for example, from  a  pattern  such  as
1549         (cat|cow|coyote), its value is returned. Otherwise, if either         (cat|cow|coyote), its value is returned. Otherwise, if either
1550    
1551         (a) the pattern was compiled with the PCRE_MULTILINE option, and  every         (a)  the pattern was compiled with the PCRE_MULTILINE option, and every
1552         branch starts with "^", or         branch starts with "^", or
1553    
1554         (b) every branch of the pattern starts with ".*" and PCRE_DOTALL is not         (b) every branch of the pattern starts with ".*" and PCRE_DOTALL is not
1555         set (if it were set, the pattern would be anchored),         set (if it were set, the pattern would be anchored),
1556    
1557         -1 is returned, indicating that the pattern matches only at  the  start         -1  is  returned, indicating that the pattern matches only at the start
1558         of  a  subject string or after any newline within the string. Otherwise         of a subject string or after any newline within the  string.  Otherwise
1559         -2 is returned. For anchored patterns, -2 is returned.         -2 is returned. For anchored patterns, -2 is returned.
1560    
1561           PCRE_INFO_FIRSTTABLE           PCRE_INFO_FIRSTTABLE
1562    
1563         If the pattern was studied, and this resulted in the construction of  a         If  the pattern was studied, and this resulted in the construction of a
1564         256-bit table indicating a fixed set of bytes for the first byte in any         256-bit table indicating a fixed set of bytes for the first byte in any
1565         matching string, a pointer to the table is returned. Otherwise NULL  is         matching  string, a pointer to the table is returned. Otherwise NULL is
1566         returned.  The fourth argument should point to an unsigned char * vari-         returned. The fourth argument should point to an unsigned char *  vari-
1567         able.         able.
1568    
1569             PCRE_INFO_HASCRORLF
1570    
1571           Return  1  if  the  pattern  contains any explicit matches for CR or LF
1572           characters, otherwise 0. The fourth argument should  point  to  an  int
1573           variable.  An explicit match is either a literal CR or LF character, or
1574           \r or \n.
1575    
1576           PCRE_INFO_JCHANGED           PCRE_INFO_JCHANGED
1577    
1578         Return 1 if the (?J) option setting is used in the  pattern,  otherwise         Return 1 if the (?J) option setting is used in the  pattern,  otherwise
# Line 1801  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1852  MATCHING A PATTERN: THE TRADITIONAL FUNC
1852         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
1853         unachored at matching time.         unachored at matching time.
1854    
1855             PCRE_BSR_ANYCRLF
1856             PCRE_BSR_UNICODE
1857    
1858           These options (which are mutually exclusive) control what the \R escape
1859           sequence  matches.  The choice is either to match only CR, LF, or CRLF,
1860           or to match any Unicode newline sequence. These  options  override  the
1861           choice that was made or defaulted when the pattern was compiled.
1862    
1863           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
1864           PCRE_NEWLINE_LF           PCRE_NEWLINE_LF
1865           PCRE_NEWLINE_CRLF           PCRE_NEWLINE_CRLF
1866           PCRE_NEWLINE_ANYCRLF           PCRE_NEWLINE_ANYCRLF
1867           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
1868    
1869         These options override  the  newline  definition  that  was  chosen  or         These  options  override  the  newline  definition  that  was chosen or
1870         defaulted  when the pattern was compiled. For details, see the descrip-         defaulted when the pattern was compiled. For details, see the  descrip-
1871         tion of pcre_compile()  above.  During  matching,  the  newline  choice         tion  of  pcre_compile()  above.  During  matching,  the newline choice
1872         affects  the  behaviour  of the dot, circumflex, and dollar metacharac-         affects the behaviour of the dot, circumflex,  and  dollar  metacharac-
1873         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
1874         match  failure  for  an  unanchored  pattern.  When  PCRE_NEWLINE_CRLF,         match failure for an unanchored pattern.
1875         PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is set, and a  match  attempt  
1876         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
1877         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-
1878         after the CRLF.         rent position is at a  CRLF  sequence,  and  the  pattern  contains  no
1879           explicit  matches  for  CR  or  LF  characters,  the  match position is
1880           advanced by two characters instead of one, in other words, to after the
1881           CRLF.
1882    
1883           The above rule is a compromise that makes the most common cases work as
1884           expected. For example, if the  pattern  is  .+A  (and  the  PCRE_DOTALL
1885           option is not set), it does not match the string "\r\nA" because, after
1886           failing at the start, it skips both the CR and the LF before  retrying.
1887           However,  the  pattern  [\r\n]A does match that string, because it con-
1888           tains an explicit CR or LF reference, and so advances only by one char-
1889           acter after the first failure.
1890    
1891           An explicit match for CR of LF is either a literal appearance of one of
1892           those characters, or one of the \r or  \n  escape  sequences.  Implicit
1893           matches  such  as [^X] do not count, nor does \s (which includes CR and
1894           LF in the characters that it matches).
1895    
1896           Notwithstanding the above, anomalous effects may still occur when  CRLF
1897           is a valid newline sequence and explicit \r or \n escapes appear in the
1898           pattern.
1899    
1900           PCRE_NOTBOL           PCRE_NOTBOL
1901    
1902         This option specifies that first character of the subject string is not         This option specifies that first character of the subject string is not
1903         the beginning of a line, so the  circumflex  metacharacter  should  not         the  beginning  of  a  line, so the circumflex metacharacter should not
1904         match  before it. Setting this without PCRE_MULTILINE (at compile time)         match before it. Setting this without PCRE_MULTILINE (at compile  time)
1905         causes circumflex never to match. This option affects only  the  behav-         causes  circumflex  never to match. This option affects only the behav-
1906         iour of the circumflex metacharacter. It does not affect \A.         iour of the circumflex metacharacter. It does not affect \A.
1907    
1908           PCRE_NOTEOL           PCRE_NOTEOL
1909    
1910         This option specifies that the end of the subject string is not the end         This option specifies that the end of the subject string is not the end
1911         of a line, so the dollar metacharacter should not match it nor  (except         of  a line, so the dollar metacharacter should not match it nor (except
1912         in  multiline mode) a newline immediately before it. Setting this with-         in multiline mode) a newline immediately before it. Setting this  with-
1913         out PCRE_MULTILINE (at compile time) causes dollar never to match. This         out PCRE_MULTILINE (at compile time) causes dollar never to match. This
1914         option  affects only the behaviour of the dollar metacharacter. It does         option affects only the behaviour of the dollar metacharacter. It  does
1915         not affect \Z or \z.         not affect \Z or \z.
1916    
1917           PCRE_NOTEMPTY           PCRE_NOTEMPTY
1918    
1919         An empty string is not considered to be a valid match if this option is         An empty string is not considered to be a valid match if this option is
1920         set.  If  there are alternatives in the pattern, they are tried. If all         set. If there are alternatives in the pattern, they are tried.  If  all
1921         the alternatives match the empty string, the entire  match  fails.  For         the  alternatives  match  the empty string, the entire match fails. For
1922         example, if the pattern         example, if the pattern
1923    
1924           a?b?           a?b?
1925    
1926         is  applied  to  a string not beginning with "a" or "b", it matches the         is applied to a string not beginning with "a" or "b",  it  matches  the
1927         empty string at the start of the subject. With PCRE_NOTEMPTY set,  this         empty  string at the start of the subject. With PCRE_NOTEMPTY set, this
1928         match is not valid, so PCRE searches further into the string for occur-         match is not valid, so PCRE searches further into the string for occur-
1929         rences of "a" or "b".         rences of "a" or "b".
1930    
1931         Perl has no direct equivalent of PCRE_NOTEMPTY, but it does make a spe-         Perl has no direct equivalent of PCRE_NOTEMPTY, but it does make a spe-
1932         cial  case  of  a  pattern match of the empty string within its split()         cial case of a pattern match of the empty  string  within  its  split()
1933         function, and when using the /g modifier. It  is  possible  to  emulate         function,  and  when  using  the /g modifier. It is possible to emulate
1934         Perl's behaviour after matching a null string by first trying the match         Perl's behaviour after matching a null string by first trying the match
1935         again at the same offset with PCRE_NOTEMPTY and PCRE_ANCHORED, and then         again at the same offset with PCRE_NOTEMPTY and PCRE_ANCHORED, and then
1936         if  that  fails by advancing the starting offset (see below) and trying         if that fails by advancing the starting offset (see below)  and  trying
1937         an ordinary match again. There is some code that demonstrates how to do         an ordinary match again. There is some code that demonstrates how to do
1938         this in the pcredemo.c sample program.         this in the pcredemo.c sample program.
1939    
1940           PCRE_NO_UTF8_CHECK           PCRE_NO_UTF8_CHECK
1941    
1942         When PCRE_UTF8 is set at compile time, the validity of the subject as a         When PCRE_UTF8 is set at compile time, the validity of the subject as a
1943         UTF-8 string is automatically checked when pcre_exec() is  subsequently         UTF-8  string is automatically checked when pcre_exec() is subsequently
1944         called.   The  value  of  startoffset is also checked to ensure that it         called.  The value of startoffset is also checked  to  ensure  that  it
1945         points to the start of a UTF-8 character. There is a  discussion  about         points  to  the start of a UTF-8 character. There is a discussion about
1946         the  validity  of  UTF-8 strings in the section on UTF-8 support in the         the validity of UTF-8 strings in the section on UTF-8  support  in  the
1947         main pcre page. If  an  invalid  UTF-8  sequence  of  bytes  is  found,         main  pcre  page.  If  an  invalid  UTF-8  sequence  of bytes is found,
1948         pcre_exec()  returns  the error PCRE_ERROR_BADUTF8. If startoffset con-         pcre_exec() returns the error PCRE_ERROR_BADUTF8. If  startoffset  con-
1949         tains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned.         tains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned.
1950    
1951         If you already know that your subject is valid, and you  want  to  skip         If  you  already  know that your subject is valid, and you want to skip
1952         these    checks    for   performance   reasons,   you   can   set   the         these   checks   for   performance   reasons,   you   can    set    the
1953         PCRE_NO_UTF8_CHECK option when calling pcre_exec(). You might  want  to         PCRE_NO_UTF8_CHECK  option  when calling pcre_exec(). You might want to
1954         do  this  for the second and subsequent calls to pcre_exec() if you are         do this for the second and subsequent calls to pcre_exec() if  you  are
1955         making repeated calls to find all  the  matches  in  a  single  subject         making  repeated  calls  to  find  all  the matches in a single subject
1956         string.  However,  you  should  be  sure  that the value of startoffset         string. However, you should be  sure  that  the  value  of  startoffset
1957         points to the start of a UTF-8 character.  When  PCRE_NO_UTF8_CHECK  is         points  to  the  start of a UTF-8 character. When PCRE_NO_UTF8_CHECK is
1958         set,  the  effect of passing an invalid UTF-8 string as a subject, or a         set, the effect of passing an invalid UTF-8 string as a subject,  or  a
1959         value of startoffset that does not point to the start of a UTF-8  char-         value  of startoffset that does not point to the start of a UTF-8 char-
1960         acter, is undefined. Your program may crash.         acter, is undefined. Your program may crash.
1961    
1962           PCRE_PARTIAL           PCRE_PARTIAL
1963    
1964         This  option  turns  on  the  partial  matching feature. If the subject         This option turns on the  partial  matching  feature.  If  the  subject
1965         string fails to match the pattern, but at some point during the  match-         string  fails to match the pattern, but at some point during the match-
1966         ing  process  the  end of the subject was reached (that is, the subject         ing process the end of the subject was reached (that  is,  the  subject
1967         partially matches the pattern and the failure to  match  occurred  only         partially  matches  the  pattern and the failure to match occurred only
1968         because  there were not enough subject characters), pcre_exec() returns         because there were not enough subject characters), pcre_exec()  returns
1969         PCRE_ERROR_PARTIAL instead of PCRE_ERROR_NOMATCH. When PCRE_PARTIAL  is         PCRE_ERROR_PARTIAL  instead of PCRE_ERROR_NOMATCH. When PCRE_PARTIAL is
1970         used,  there  are restrictions on what may appear in the pattern. These         used, there are restrictions on what may appear in the  pattern.  These
1971         are discussed in the pcrepartial documentation.         are discussed in the pcrepartial documentation.
1972    
1973     The string to be matched by pcre_exec()     The string to be matched by pcre_exec()
1974    
1975         The subject string is passed to pcre_exec() as a pointer in subject,  a         The  subject string is passed to pcre_exec() as a pointer in subject, a
1976         length  in  length, and a starting byte offset in startoffset. In UTF-8         length in length, and a starting byte offset in startoffset.  In  UTF-8
1977         mode, the byte offset must point to the start  of  a  UTF-8  character.         mode,  the  byte  offset  must point to the start of a UTF-8 character.
1978         Unlike  the  pattern string, the subject may contain binary zero bytes.         Unlike the pattern string, the subject may contain binary  zero  bytes.
1979         When the starting offset is zero, the search for a match starts at  the         When  the starting offset is zero, the search for a match starts at the
1980         beginning of the subject, and this is by far the most common case.         beginning of the subject, and this is by far the most common case.
1981    
1982         A  non-zero  starting offset is useful when searching for another match         A non-zero starting offset is useful when searching for  another  match
1983         in the same subject by calling pcre_exec() again after a previous  suc-         in  the same subject by calling pcre_exec() again after a previous suc-
1984         cess.   Setting  startoffset differs from just passing over a shortened         cess.  Setting startoffset differs from just passing over  a  shortened
1985         string and setting PCRE_NOTBOL in the case of  a  pattern  that  begins         string  and  setting  PCRE_NOTBOL  in the case of a pattern that begins
1986         with any kind of lookbehind. For example, consider the pattern         with any kind of lookbehind. For example, consider the pattern
1987    
1988           \Biss\B           \Biss\B
1989    
1990         which  finds  occurrences  of "iss" in the middle of words. (\B matches         which finds occurrences of "iss" in the middle of  words.  (\B  matches
1991         only if the current position in the subject is not  a  word  boundary.)         only  if  the  current position in the subject is not a word boundary.)
1992         When  applied  to the string "Mississipi" the first call to pcre_exec()         When applied to the string "Mississipi" the first call  to  pcre_exec()
1993         finds the first occurrence. If pcre_exec() is called  again  with  just         finds  the  first  occurrence. If pcre_exec() is called again with just
1994         the  remainder  of  the  subject,  namely  "issipi", it does not match,         the remainder of the subject,  namely  "issipi",  it  does  not  match,
1995         because \B is always false at the start of the subject, which is deemed         because \B is always false at the start of the subject, which is deemed
1996         to  be  a  word  boundary. However, if pcre_exec() is passed the entire         to be a word boundary. However, if pcre_exec()  is  passed  the  entire
1997         string again, but with startoffset set to 4, it finds the second occur-         string again, but with startoffset set to 4, it finds the second occur-
1998         rence  of "iss" because it is able to look behind the starting point to         rence of "iss" because it is able to look behind the starting point  to
1999         discover that it is preceded by a letter.         discover that it is preceded by a letter.
2000    
2001         If a non-zero starting offset is passed when the pattern  is  anchored,         If  a  non-zero starting offset is passed when the pattern is anchored,
2002         one attempt to match at the given offset is made. This can only succeed         one attempt to match at the given offset is made. This can only succeed
2003         if the pattern does not require the match to be at  the  start  of  the         if  the  pattern  does  not require the match to be at the start of the
2004         subject.         subject.
2005    
2006     How pcre_exec() returns captured substrings     How pcre_exec() returns captured substrings
2007    
2008         In  general, a pattern matches a certain portion of the subject, and in         In general, a pattern matches a certain portion of the subject, and  in
2009         addition, further substrings from the subject  may  be  picked  out  by         addition,  further  substrings  from  the  subject may be picked out by
2010         parts  of  the  pattern.  Following the usage in Jeffrey Friedl's book,         parts of the pattern. Following the usage  in  Jeffrey  Friedl's  book,
2011         this is called "capturing" in what follows, and the  phrase  "capturing         this  is  called "capturing" in what follows, and the phrase "capturing
2012         subpattern"  is  used for a fragment of a pattern that picks out a sub-         subpattern" is used for a fragment of a pattern that picks out  a  sub-
2013         string. PCRE supports several other kinds of  parenthesized  subpattern         string.  PCRE  supports several other kinds of parenthesized subpattern
2014         that do not cause substrings to be captured.         that do not cause substrings to be captured.
2015    
2016         Captured  substrings are returned to the caller via a vector of integer         Captured substrings are returned to the caller via a vector of  integer
2017         offsets whose address is passed in ovector. The number of  elements  in         offsets  whose  address is passed in ovector. The number of elements in
2018         the  vector is passed in ovecsize, which must be a non-negative number.         the vector is passed in ovecsize, which must be a non-negative  number.
2019         Note: this argument is NOT the size of ovector in bytes.         Note: this argument is NOT the size of ovector in bytes.
2020    
2021         The first two-thirds of the vector is used to pass back  captured  sub-         The  first  two-thirds of the vector is used to pass back captured sub-
2022         strings,  each  substring using a pair of integers. The remaining third         strings, each substring using a pair of integers. The  remaining  third
2023         of the vector is used as workspace by pcre_exec() while  matching  cap-         of  the  vector is used as workspace by pcre_exec() while matching cap-
2024         turing  subpatterns, and is not available for passing back information.         turing subpatterns, and is not available for passing back  information.
2025         The length passed in ovecsize should always be a multiple of three.  If         The  length passed in ovecsize should always be a multiple of three. If
2026         it is not, it is rounded down.         it is not, it is rounded down.
2027    
2028         When  a  match  is successful, information about captured substrings is         When a match is successful, information about  captured  substrings  is
2029         returned in pairs of integers, starting at the  beginning  of  ovector,         returned  in  pairs  of integers, starting at the beginning of ovector,
2030         and  continuing  up  to two-thirds of its length at the most. The first         and continuing up to two-thirds of its length at the  most.  The  first
2031         element of a pair is set to the offset of the first character in a sub-         element of a pair is set to the offset of the first character in a sub-
2032         string,  and  the  second  is  set to the offset of the first character         string, and the second is set to the  offset  of  the  first  character
2033         after the end of a substring. The  first  pair,  ovector[0]  and  ovec-         after  the  end  of  a  substring. The first pair, ovector[0] and ovec-
2034         tor[1],  identify  the  portion  of  the  subject string matched by the         tor[1], identify the portion of  the  subject  string  matched  by  the
2035         entire pattern. The next pair is used for the first  capturing  subpat-         entire  pattern.  The next pair is used for the first capturing subpat-
2036         tern, and so on. The value returned by pcre_exec() is one more than the         tern, and so on. The value returned by pcre_exec() is one more than the
2037         highest numbered pair that has been set. For example, if two substrings         highest numbered pair that has been set. For example, if two substrings
2038         have  been captured, the returned value is 3. If there are no capturing         have been captured, the returned value is 3. If there are no  capturing
2039         subpatterns, the return value from a successful match is 1,  indicating         subpatterns,  the return value from a successful match is 1, indicating
2040         that just the first pair of offsets has been set.         that just the first pair of offsets has been set.
2041    
2042         If a capturing subpattern is matched repeatedly, it is the last portion         If a capturing subpattern is matched repeatedly, it is the last portion
2043         of the string that it matched that is returned.         of the string that it matched that is returned.
2044    
2045         If the vector is too small to hold all the captured substring  offsets,         If  the vector is too small to hold all the captured substring offsets,
2046         it is used as far as possible (up to two-thirds of its length), and the         it is used as far as possible (up to two-thirds of its length), and the
2047         function returns a value of zero. In particular, if the substring  off-         function  returns a value of zero. In particular, if the substring off-
2048         sets are not of interest, pcre_exec() may be called with ovector passed         sets are not of interest, pcre_exec() may be called with ovector passed
2049         as NULL and ovecsize as zero. However, if  the  pattern  contains  back         as  NULL  and  ovecsize  as zero. However, if the pattern contains back
2050         references  and  the  ovector is not big enough to remember the related         references and the ovector is not big enough to  remember  the  related
2051         substrings, PCRE has to get additional memory for use during  matching.         substrings,  PCRE has to get additional memory for use during matching.
2052         Thus it is usually advisable to supply an ovector.         Thus it is usually advisable to supply an ovector.
2053    
2054         The  pcre_info()  function  can  be used to find out how many capturing         The pcre_info() function can be used to find  out  how  many  capturing
2055         subpatterns there are in a compiled  pattern.  The  smallest  size  for         subpatterns  there  are  in  a  compiled pattern. The smallest size for
2056         ovector  that  will allow for n captured substrings, in addition to the         ovector that will allow for n captured substrings, in addition  to  the
2057         offsets of the substring matched by the whole pattern, is (n+1)*3.         offsets of the substring matched by the whole pattern, is (n+1)*3.
2058    
2059         It is possible for capturing subpattern number n+1 to match  some  part         It  is  possible for capturing subpattern number n+1 to match some part
2060         of the subject when subpattern n has not been used at all. For example,         of the subject when subpattern n has not been used at all. For example,
2061         if the string "abc" is matched  against  the  pattern  (a|(z))(bc)  the         if  the  string  "abc"  is  matched against the pattern (a|(z))(bc) the
2062         return from the function is 4, and subpatterns 1 and 3 are matched, but         return from the function is 4, and subpatterns 1 and 3 are matched, but
2063         2 is not. When this happens, both values in  the  offset  pairs  corre-         2  is  not.  When  this happens, both values in the offset pairs corre-
2064         sponding to unused subpatterns are set to -1.         sponding to unused subpatterns are set to -1.
2065    
2066         Offset  values  that correspond to unused subpatterns at the end of the         Offset values that correspond to unused subpatterns at the end  of  the
2067         expression are also set to -1. For example,  if  the  string  "abc"  is         expression  are  also  set  to  -1. For example, if the string "abc" is
2068         matched  against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not         matched against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are  not
2069         matched. The return from the function is 2, because  the  highest  used         matched.  The  return  from the function is 2, because the highest used
2070         capturing subpattern number is 1. However, you can refer to the offsets         capturing subpattern number is 1. However, you can refer to the offsets
2071         for the second and third capturing subpatterns if  you  wish  (assuming         for  the  second  and third capturing subpatterns if you wish (assuming
2072         the vector is large enough, of course).         the vector is large enough, of course).
2073    
2074         Some  convenience  functions  are  provided for extracting the captured         Some convenience functions are provided  for  extracting  the  captured
2075         substrings as separate strings. These are described below.         substrings as separate strings. These are described below.
2076    
2077     Error return values from pcre_exec()     Error return values from pcre_exec()
2078    
2079         If pcre_exec() fails, it returns a negative number. The  following  are         If  pcre_exec()  fails, it returns a negative number. The following are
2080         defined in the header file:         defined in the header file:
2081    
2082           PCRE_ERROR_NOMATCH        (-1)           PCRE_ERROR_NOMATCH        (-1)
# Line 2006  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 2085  MATCHING A PATTERN: THE TRADITIONAL FUNC
2085    
2086           PCRE_ERROR_NULL           (-2)           PCRE_ERROR_NULL           (-2)
2087    
2088         Either  code  or  subject  was  passed as NULL, or ovector was NULL and         Either code or subject was passed as NULL,  or  ovector  was  NULL  and
2089         ovecsize was not zero.         ovecsize was not zero.
2090    
2091           PCRE_ERROR_BADOPTION      (-3)           PCRE_ERROR_BADOPTION      (-3)
# Line 2015  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 2094  MATCHING A PATTERN: THE TRADITIONAL FUNC
2094    
2095           PCRE_ERROR_BADMAGIC       (-4)           PCRE_ERROR_BADMAGIC       (-4)
2096    
2097         PCRE stores a 4-byte "magic number" at the start of the compiled  code,         PCRE  stores a 4-byte "magic number" at the start of the compiled code,
2098         to catch the case when it is passed a junk pointer and to detect when a         to catch the case when it is passed a junk pointer and to detect when a
2099         pattern that was compiled in an environment of one endianness is run in         pattern that was compiled in an environment of one endianness is run in
2100         an  environment  with the other endianness. This is the error that PCRE         an environment with the other endianness. This is the error  that  PCRE
2101         gives when the magic number is not present.         gives when the magic number is not present.
2102    
2103           PCRE_ERROR_UNKNOWN_OPCODE (-5)           PCRE_ERROR_UNKNOWN_OPCODE (-5)
2104    
2105         While running the pattern match, an unknown item was encountered in the         While running the pattern match, an unknown item was encountered in the
2106         compiled  pattern.  This  error  could be caused by a bug in PCRE or by         compiled pattern. This error could be caused by a bug  in  PCRE  or  by
2107         overwriting of the compiled pattern.         overwriting of the compiled pattern.
2108    
2109           PCRE_ERROR_NOMEMORY       (-6)           PCRE_ERROR_NOMEMORY       (-6)
2110    
2111         If a pattern contains back references, but the ovector that  is  passed         If  a  pattern contains back references, but the ovector that is passed
2112         to pcre_exec() is not big enough to remember the referenced substrings,         to pcre_exec() is not big enough to remember the referenced substrings,
2113         PCRE gets a block of memory at the start of matching to  use  for  this         PCRE  gets  a  block of memory at the start of matching to use for this
2114         purpose.  If the call via pcre_malloc() fails, this error is given. The         purpose. If the call via pcre_malloc() fails, this error is given.  The
2115         memory is automatically freed at the end of matching.         memory is automatically freed at the end of matching.
2116    
2117           PCRE_ERROR_NOSUBSTRING    (-7)           PCRE_ERROR_NOSUBSTRING    (-7)
2118    
2119         This error is used by the pcre_copy_substring(),  pcre_get_substring(),         This  error is used by the pcre_copy_substring(), pcre_get_substring(),
2120         and  pcre_get_substring_list()  functions  (see  below).  It  is  never         and  pcre_get_substring_list()  functions  (see  below).  It  is  never
2121         returned by pcre_exec().         returned by pcre_exec().
2122    
2123           PCRE_ERROR_MATCHLIMIT     (-8)           PCRE_ERROR_MATCHLIMIT     (-8)
2124    
2125         The backtracking limit, as specified by  the  match_limit  field  in  a         The  backtracking  limit,  as  specified  by the match_limit field in a
2126         pcre_extra  structure  (or  defaulted) was reached. See the description         pcre_extra structure (or defaulted) was reached.  See  the  description
2127         above.         above.
2128    
2129           PCRE_ERROR_CALLOUT        (-9)           PCRE_ERROR_CALLOUT        (-9)
2130    
2131         This error is never generated by pcre_exec() itself. It is provided for         This error is never generated by pcre_exec() itself. It is provided for
2132         use  by  callout functions that want to yield a distinctive error code.         use by callout functions that want to yield a distinctive  error  code.
2133         See the pcrecallout documentation for details.         See the pcrecallout documentation for details.
2134    
2135           PCRE_ERROR_BADUTF8        (-10)           PCRE_ERROR_BADUTF8        (-10)
2136    
2137         A string that contains an invalid UTF-8 byte sequence was passed  as  a         A  string  that contains an invalid UTF-8 byte sequence was passed as a
2138         subject.         subject.
2139    
2140           PCRE_ERROR_BADUTF8_OFFSET (-11)           PCRE_ERROR_BADUTF8_OFFSET (-11)
2141    
2142         The UTF-8 byte sequence that was passed as a subject was valid, but the         The UTF-8 byte sequence that was passed as a subject was valid, but the
2143         value of startoffset did not point to the beginning of a UTF-8  charac-         value  of startoffset did not point to the beginning of a UTF-8 charac-
2144         ter.         ter.
2145    
2146           PCRE_ERROR_PARTIAL        (-12)           PCRE_ERROR_PARTIAL        (-12)
2147    
2148         The  subject  string did not match, but it did match partially. See the         The subject string did not match, but it did match partially.  See  the
2149         pcrepartial documentation for details of partial matching.         pcrepartial documentation for details of partial matching.
2150    
2151           PCRE_ERROR_BADPARTIAL     (-13)           PCRE_ERROR_BADPARTIAL     (-13)
2152    
2153         The PCRE_PARTIAL option was used with  a  compiled  pattern  containing         The  PCRE_PARTIAL  option  was  used with a compiled pattern containing
2154         items  that are not supported for partial matching. See the pcrepartial         items that are not supported for partial matching. See the  pcrepartial
2155         documentation for details of partial matching.         documentation for details of partial matching.
2156    
2157           PCRE_ERROR_INTERNAL       (-14)           PCRE_ERROR_INTERNAL       (-14)
2158    
2159         An unexpected internal error has occurred. This error could  be  caused         An  unexpected  internal error has occurred. This error could be caused
2160         by a bug in PCRE or by overwriting of the compiled pattern.         by a bug in PCRE or by overwriting of the compiled pattern.
2161    
2162           PCRE_ERROR_BADCOUNT       (-15)           PCRE_ERROR_BADCOUNT       (-15)
2163    
2164         This  error is given if the value of the ovecsize argument is negative.         This error is given if the value of the ovecsize argument is  negative.
2165    
2166           PCRE_ERROR_RECURSIONLIMIT (-21)           PCRE_ERROR_RECURSIONLIMIT (-21)
2167    
2168         The internal recursion limit, as specified by the match_limit_recursion         The internal recursion limit, as specified by the match_limit_recursion
2169         field  in  a  pcre_extra  structure (or defaulted) was reached. See the         field in a pcre_extra structure (or defaulted)  was  reached.  See  the
2170         description above.         description above.
2171    
2172           PCRE_ERROR_BADNEWLINE     (-23)           PCRE_ERROR_BADNEWLINE     (-23)
# Line 2110  EXTRACTING CAPTURED SUBSTRINGS BY NUMBER Line 2189  EXTRACTING CAPTURED SUBSTRINGS BY NUMBER
2189         int pcre_get_substring_list(const char *subject,         int pcre_get_substring_list(const char *subject,
2190              int *ovector, int stringcount, const char ***listptr);              int *ovector, int stringcount, const char ***listptr);
2191    
2192         Captured substrings can be  accessed  directly  by  using  the  offsets         Captured  substrings  can  be  accessed  directly  by using the offsets
2193         returned  by  pcre_exec()  in  ovector.  For convenience, the functions         returned by pcre_exec() in  ovector.  For  convenience,  the  functions
2194         pcre_copy_substring(),    pcre_get_substring(),    and    pcre_get_sub-         pcre_copy_substring(),    pcre_get_substring(),    and    pcre_get_sub-
2195         string_list()  are  provided for extracting captured substrings as new,         string_list() are provided for extracting captured substrings  as  new,
2196         separate, zero-terminated strings. These functions identify  substrings         separate,  zero-terminated strings. These functions identify substrings
2197         by  number.  The  next section describes functions for extracting named         by number. The next section describes functions  for  extracting  named
2198         substrings.         substrings.
2199    
2200         A substring that contains a binary zero is correctly extracted and  has         A  substring that contains a binary zero is correctly extracted and has
2201         a  further zero added on the end, but the result is not, of course, a C         a further zero added on the end, but the result is not, of course, a  C
2202         string.  However, you can process such a string  by  referring  to  the         string.   However,  you  can  process such a string by referring to the
2203         length  that  is  returned  by  pcre_copy_substring() and pcre_get_sub-         length that is  returned  by  pcre_copy_substring()  and  pcre_get_sub-
2204         string().  Unfortunately, the interface to pcre_get_substring_list() is         string().  Unfortunately, the interface to pcre_get_substring_list() is
2205         not  adequate for handling strings containing binary zeros, because the         not adequate for handling strings containing binary zeros, because  the
2206         end of the final string is not independently indicated.         end of the final string is not independently indicated.
2207    
2208         The first three arguments are the same for all  three  of  these  func-         The  first  three  arguments  are the same for all three of these func-
2209         tions:  subject  is  the subject string that has just been successfully         tions: subject is the subject string that has  just  been  successfully
2210         matched, ovector is a pointer to the vector of integer offsets that was         matched, ovector is a pointer to the vector of integer offsets that was
2211         passed to pcre_exec(), and stringcount is the number of substrings that         passed to pcre_exec(), and stringcount is the number of substrings that
2212         were captured by the match, including the substring  that  matched  the         were  captured  by  the match, including the substring that matched the
2213         entire regular expression. This is the value returned by pcre_exec() if         entire regular expression. This is the value returned by pcre_exec() if
2214         it is greater than zero. If pcre_exec() returned zero, indicating  that         it  is greater than zero. If pcre_exec() returned zero, indicating that
2215         it  ran out of space in ovector, the value passed as stringcount should         it ran out of space in ovector, the value passed as stringcount  should
2216         be the number of elements in the vector divided by three.         be the number of elements in the vector divided by three.
2217    
2218         The functions pcre_copy_substring() and pcre_get_substring() extract  a         The  functions pcre_copy_substring() and pcre_get_substring() extract a
2219         single  substring,  whose  number  is given as stringnumber. A value of         single substring, whose number is given as  stringnumber.  A  value  of
2220         zero extracts the substring that matched the  entire  pattern,  whereas         zero  extracts  the  substring that matched the entire pattern, whereas
2221         higher  values  extract  the  captured  substrings.  For pcre_copy_sub-         higher values  extract  the  captured  substrings.  For  pcre_copy_sub-
2222         string(), the string is placed in buffer,  whose  length  is  given  by         string(),  the  string  is  placed  in buffer, whose length is given by
2223         buffersize,  while  for  pcre_get_substring()  a new block of memory is         buffersize, while for pcre_get_substring() a new  block  of  memory  is
2224         obtained via pcre_malloc, and its address is  returned  via  stringptr.         obtained  via  pcre_malloc,  and its address is returned via stringptr.
2225         The  yield  of  the function is the length of the string, not including         The yield of the function is the length of the  string,  not  including
2226         the terminating zero, or one of these error codes:         the terminating zero, or one of these error codes:
2227    
2228           PCRE_ERROR_NOMEMORY       (-6)           PCRE_ERROR_NOMEMORY       (-6)
2229    
2230         The buffer was too small for pcre_copy_substring(), or the  attempt  to         The  buffer  was too small for pcre_copy_substring(), or the attempt to
2231         get memory failed for pcre_get_substring().         get memory failed for pcre_get_substring().
2232    
2233           PCRE_ERROR_NOSUBSTRING    (-7)           PCRE_ERROR_NOSUBSTRING    (-7)
2234    
2235         There is no substring whose number is stringnumber.         There is no substring whose number is stringnumber.
2236    
2237         The  pcre_get_substring_list()  function  extracts  all  available sub-         The pcre_get_substring_list()  function  extracts  all  available  sub-
2238         strings and builds a list of pointers to them. All this is  done  in  a         strings  and  builds  a list of pointers to them. All this is done in a
2239         single block of memory that is obtained via pcre_malloc. The address of         single block of memory that is obtained via pcre_malloc. The address of
2240         the memory block is returned via listptr, which is also  the  start  of         the  memory  block  is returned via listptr, which is also the start of
2241         the  list  of  string pointers. The end of the list is marked by a NULL         the list of string pointers. The end of the list is marked  by  a  NULL
2242         pointer. The yield of the function is zero if all  went  well,  or  the         pointer.  The  yield  of  the function is zero if all went well, or the
2243         error code         error code
2244    
2245           PCRE_ERROR_NOMEMORY       (-6)           PCRE_ERROR_NOMEMORY       (-6)
2246    
2247         if the attempt to get the memory block failed.         if the attempt to get the memory block failed.
2248    
2249         When  any of these functions encounter a substring that is unset, which         When any of these functions encounter a substring that is unset,  which
2250         can happen when capturing subpattern number n+1 matches  some  part  of         can  happen  when  capturing subpattern number n+1 matches some part of
2251         the  subject, but subpattern n has not been used at all, they return an         the subject, but subpattern n has not been used at all, they return  an
2252         empty string. This can be distinguished from a genuine zero-length sub-         empty string. This can be distinguished from a genuine zero-length sub-
2253         string  by inspecting the appropriate offset in ovector, which is nega-         string by inspecting the appropriate offset in ovector, which is  nega-
2254         tive for unset substrings.         tive for unset substrings.
2255    
2256         The two convenience functions pcre_free_substring() and  pcre_free_sub-         The  two convenience functions pcre_free_substring() and pcre_free_sub-
2257         string_list()  can  be  used  to free the memory returned by a previous         string_list() can be used to free the memory  returned  by  a  previous
2258         call  of  pcre_get_substring()  or  pcre_get_substring_list(),  respec-         call  of  pcre_get_substring()  or  pcre_get_substring_list(),  respec-
2259         tively.  They  do  nothing  more  than  call the function pointed to by         tively. They do nothing more than  call  the  function  pointed  to  by
2260         pcre_free, which of course could be called directly from a  C  program.         pcre_free,  which  of course could be called directly from a C program.
2261         However,  PCRE is used in some situations where it is linked via a spe-         However, PCRE is used in some situations where it is linked via a  spe-
2262         cial  interface  to  another  programming  language  that  cannot   use         cial   interface  to  another  programming  language  that  cannot  use
2263         pcre_free  directly;  it is for these cases that the functions are pro-         pcre_free directly; it is for these cases that the functions  are  pro-
2264         vided.         vided.
2265    
2266    
# Line 2200  EXTRACTING CAPTURED SUBSTRINGS BY NAME Line 2279  EXTRACTING CAPTURED SUBSTRINGS BY NAME
2279              int stringcount, const char *stringname,              int stringcount, const char *stringname,
2280              const char **stringptr);              const char **stringptr);
2281    
2282         To extract a substring by name, you first have to find associated  num-         To  extract a substring by name, you first have to find associated num-
2283         ber.  For example, for this pattern         ber.  For example, for this pattern
2284    
2285           (a+)b(?<xxx>\d+)...           (a+)b(?<xxx>\d+)...
# Line 2209  EXTRACTING CAPTURED SUBSTRINGS BY NAME Line 2288  EXTRACTING CAPTURED SUBSTRINGS BY NAME
2288         be unique (PCRE_DUPNAMES was not set), you can find the number from the         be unique (PCRE_DUPNAMES was not set), you can find the number from the
2289         name by calling pcre_get_stringnumber(). The first argument is the com-         name by calling pcre_get_stringnumber(). The first argument is the com-
2290         piled pattern, and the second is the name. The yield of the function is         piled pattern, and the second is the name. The yield of the function is
2291         the  subpattern  number,  or PCRE_ERROR_NOSUBSTRING (-7) if there is no         the subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if  there  is  no
2292         subpattern of that name.         subpattern of that name.
2293    
2294         Given the number, you can extract the substring directly, or use one of         Given the number, you can extract the substring directly, or use one of
2295         the functions described in the previous section. For convenience, there         the functions described in the previous section. For convenience, there
2296         are also two functions that do the whole job.         are also two functions that do the whole job.
2297    
2298         Most   of   the   arguments    of    pcre_copy_named_substring()    and         Most    of    the    arguments   of   pcre_copy_named_substring()   and
2299         pcre_get_named_substring()  are  the  same  as  those for the similarly         pcre_get_named_substring() are the same  as  those  for  the  similarly
2300         named functions that extract by number. As these are described  in  the         named  functions  that extract by number. As these are described in the
2301         previous  section,  they  are not re-described here. There are just two         previous section, they are not re-described here. There  are  just  two
2302         differences:         differences:
2303    
2304         First, instead of a substring number, a substring name is  given.  Sec-         First,  instead  of a substring number, a substring name is given. Sec-
2305         ond, there is an extra argument, given at the start, which is a pointer         ond, there is an extra argument, given at the start, which is a pointer
2306         to the compiled pattern. This is needed in order to gain access to  the         to  the compiled pattern. This is needed in order to gain access to the
2307         name-to-number translation table.         name-to-number translation table.
2308    
2309         These  functions call pcre_get_stringnumber(), and if it succeeds, they         These functions call pcre_get_stringnumber(), and if it succeeds,  they
2310         then call pcre_copy_substring() or pcre_get_substring(),  as  appropri-         then  call  pcre_copy_substring() or pcre_get_substring(), as appropri-
2311         ate.  NOTE:  If PCRE_DUPNAMES is set and there are duplicate names, the         ate. NOTE: If PCRE_DUPNAMES is set and there are duplicate  names,  the
2312         behaviour may not be what you want (see the next section).         behaviour may not be what you want (see the next section).
2313    
2314    
# Line 2238  DUPLICATE SUBPATTERN NAMES Line 2317  DUPLICATE SUBPATTERN NAMES
2317         int pcre_get_stringtable_entries(const pcre *code,         int pcre_get_stringtable_entries(const pcre *code,
2318              const char *name, char **first, char **last);              const char *name, char **first, char **last);
2319    
2320         When a pattern is compiled with the  PCRE_DUPNAMES  option,  names  for         When  a  pattern  is  compiled with the PCRE_DUPNAMES option, names for
2321         subpatterns  are  not  required  to  be unique. Normally, patterns with         subpatterns are not required to  be  unique.  Normally,  patterns  with
2322         duplicate names are such that in any one match, only one of  the  named         duplicate  names  are such that in any one match, only one of the named
2323         subpatterns  participates. An example is shown in the pcrepattern docu-         subpatterns participates. An example is shown in the pcrepattern  docu-
2324         mentation.         mentation.
2325    
2326         When   duplicates   are   present,   pcre_copy_named_substring()    and         When    duplicates   are   present,   pcre_copy_named_substring()   and
2327         pcre_get_named_substring()  return the first substring corresponding to         pcre_get_named_substring() return the first substring corresponding  to
2328         the given name that is set. If  none  are  set,  PCRE_ERROR_NOSUBSTRING         the  given  name  that  is set. If none are set, PCRE_ERROR_NOSUBSTRING
2329         (-7)  is  returned;  no  data  is returned. The pcre_get_stringnumber()         (-7) is returned; no  data  is  returned.  The  pcre_get_stringnumber()
2330         function returns one of the numbers that are associated with the  name,         function  returns one of the numbers that are associated with the name,
2331         but it is not defined which it is.         but it is not defined which it is.
2332    
2333         If  you want to get full details of all captured substrings for a given         If you want to get full details of all captured substrings for a  given
2334         name, you must use  the  pcre_get_stringtable_entries()  function.  The         name,  you  must  use  the pcre_get_stringtable_entries() function. The
2335         first argument is the compiled pattern, and the second is the name. The         first argument is the compiled pattern, and the second is the name. The
2336         third and fourth are pointers to variables which  are  updated  by  the         third  and  fourth  are  pointers to variables which are updated by the
2337         function. After it has run, they point to the first and last entries in         function. After it has run, they point to the first and last entries in
2338         the name-to-number table  for  the  given  name.  The  function  itself         the  name-to-number  table  for  the  given  name.  The function itself
2339         returns  the  length  of  each entry, or PCRE_ERROR_NOSUBSTRING (-7) if         returns the length of each entry,  or  PCRE_ERROR_NOSUBSTRING  (-7)  if
2340         there are none. The format of the table is described above in the  sec-         there  are none. The format of the table is described above in the sec-
2341         tion  entitled  Information  about  a  pattern.  Given all the relevant         tion entitled Information about a  pattern.   Given  all  the  relevant
2342         entries for the name, you can extract each of their numbers, and  hence         entries  for the name, you can extract each of their numbers, and hence
2343         the captured data, if any.         the captured data, if any.
2344    
2345    
2346  FINDING ALL POSSIBLE MATCHES  FINDING ALL POSSIBLE MATCHES
2347    
2348         The  traditional  matching  function  uses a similar algorithm to Perl,         The traditional matching function uses a  similar  algorithm  to  Perl,
2349         which stops when it finds the first match, starting at a given point in         which stops when it finds the first match, starting at a given point in
2350         the  subject.  If you want to find all possible matches, or the longest         the subject. If you want to find all possible matches, or  the  longest
2351         possible match, consider using the alternative matching  function  (see         possible  match,  consider using the alternative matching function (see
2352         below)  instead.  If you cannot use the alternative function, but still         below) instead. If you cannot use the alternative function,  but  still
2353         need to find all possible matches, you can kludge it up by  making  use         need  to  find all possible matches, you can kludge it up by making use
2354         of the callout facility, which is described in the pcrecallout documen-         of the callout facility, which is described in the pcrecallout documen-
2355         tation.         tation.
2356    
2357         What you have to do is to insert a callout right at the end of the pat-         What you have to do is to insert a callout right at the end of the pat-
2358         tern.   When your callout function is called, extract and save the cur-         tern.  When your callout function is called, extract and save the  cur-
2359         rent matched substring. Then return  1,  which  forces  pcre_exec()  to         rent  matched  substring.  Then  return  1, which forces pcre_exec() to
2360         backtrack  and  try other alternatives. Ultimately, when it runs out of         backtrack and try other alternatives. Ultimately, when it runs  out  of
2361         matches, pcre_exec() will yield PCRE_ERROR_NOMATCH.         matches, pcre_exec() will yield PCRE_ERROR_NOMATCH.
2362    
2363    
# Line 2289  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 2368  MATCHING A PATTERN: THE ALTERNATIVE FUNC
2368              int options, int *ovector, int ovecsize,              int options, int *ovector, int ovecsize,
2369              int *workspace, int wscount);              int *workspace, int wscount);
2370    
2371         The function pcre_dfa_exec()  is  called  to  match  a  subject  string         The  function  pcre_dfa_exec()  is  called  to  match  a subject string
2372         against  a  compiled pattern, using a matching algorithm that scans the         against a compiled pattern, using a matching algorithm that  scans  the
2373         subject string just once, and does not backtrack.  This  has  different         subject  string  just  once, and does not backtrack. This has different
2374         characteristics  to  the  normal  algorithm, and is not compatible with         characteristics to the normal algorithm, and  is  not  compatible  with
2375         Perl. Some of the features of PCRE patterns are not  supported.  Never-         Perl.  Some  of the features of PCRE patterns are not supported. Never-
2376         theless,  there are times when this kind of matching can be useful. For         theless, there are times when this kind of matching can be useful.  For
2377         a discussion of the two matching algorithms, see the pcrematching docu-         a discussion of the two matching algorithms, see the pcrematching docu-
2378         mentation.         mentation.
2379    
2380         The  arguments  for  the  pcre_dfa_exec()  function are the same as for         The arguments for the pcre_dfa_exec() function  are  the  same  as  for
2381         pcre_exec(), plus two extras. The ovector argument is used in a differ-         pcre_exec(), plus two extras. The ovector argument is used in a differ-
2382         ent  way,  and  this is described below. The other common arguments are         ent way, and this is described below. The other  common  arguments  are
2383         used in the same way as for pcre_exec(), so their  description  is  not         used  in  the  same way as for pcre_exec(), so their description is not
2384         repeated here.         repeated here.
2385    
2386         The  two  additional  arguments provide workspace for the function. The         The two additional arguments provide workspace for  the  function.  The
2387         workspace vector should contain at least 20 elements. It  is  used  for         workspace  vector  should  contain at least 20 elements. It is used for
2388         keeping  track  of  multiple  paths  through  the  pattern  tree.  More         keeping  track  of  multiple  paths  through  the  pattern  tree.  More
2389         workspace will be needed for patterns and subjects where  there  are  a         workspace  will  be  needed for patterns and subjects where there are a
2390         lot of potential matches.         lot of potential matches.
2391    
2392         Here is an example of a simple call to pcre_dfa_exec():         Here is an example of a simple call to pcre_dfa_exec():
# Line 2329  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 2408  MATCHING A PATTERN: THE ALTERNATIVE FUNC
2408    
2409     Option bits for pcre_dfa_exec()     Option bits for pcre_dfa_exec()
2410    
2411         The  unused  bits  of  the options argument for pcre_dfa_exec() must be         The unused bits of the options argument  for  pcre_dfa_exec()  must  be
2412         zero. The only bits  that  may  be  set  are  PCRE_ANCHORED,  PCRE_NEW-         zero.  The  only  bits  that  may  be  set are PCRE_ANCHORED, PCRE_NEW-
2413         LINE_xxx,  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK,         LINE_xxx, PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY,  PCRE_NO_UTF8_CHECK,
2414         PCRE_PARTIAL, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last         PCRE_PARTIAL, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last
2415         three of these are the same as for pcre_exec(), so their description is         three of these are the same as for pcre_exec(), so their description is
2416         not repeated here.         not repeated here.
2417    
2418           PCRE_PARTIAL           PCRE_PARTIAL
2419    
2420         This has the same general effect as it does for  pcre_exec(),  but  the         This  has  the  same general effect as it does for pcre_exec(), but the
2421         details   are   slightly   different.  When  PCRE_PARTIAL  is  set  for         details  are  slightly  different.  When  PCRE_PARTIAL   is   set   for
2422         pcre_dfa_exec(), the return code PCRE_ERROR_NOMATCH is  converted  into         pcre_dfa_exec(),  the  return code PCRE_ERROR_NOMATCH is converted into
2423         PCRE_ERROR_PARTIAL  if  the  end  of the subject is reached, there have         PCRE_ERROR_PARTIAL if the end of the subject  is  reached,  there  have
2424         been no complete matches, but there is still at least one matching pos-         been no complete matches, but there is still at least one matching pos-
2425         sibility.  The portion of the string that provided the partial match is         sibility. The portion of the string that provided the partial match  is
2426         set as the first matching string.         set as the first matching string.
2427    
2428           PCRE_DFA_SHORTEST           PCRE_DFA_SHORTEST
2429    
2430         Setting the PCRE_DFA_SHORTEST option causes the matching  algorithm  to         Setting  the  PCRE_DFA_SHORTEST option causes the matching algorithm to
2431         stop as soon as it has found one match. Because of the way the alterna-         stop as soon as it has found one match. Because of the way the alterna-
2432         tive algorithm works, this is necessarily the shortest  possible  match         tive  algorithm  works, this is necessarily the shortest possible match
2433         at the first possible matching point in the subject string.         at the first possible matching point in the subject string.
2434    
2435           PCRE_DFA_RESTART           PCRE_DFA_RESTART
2436    
2437         When  pcre_dfa_exec()  is  called  with  the  PCRE_PARTIAL  option, and         When pcre_dfa_exec()  is  called  with  the  PCRE_PARTIAL  option,  and
2438         returns a partial match, it is possible to call it  again,  with  addi-         returns  a  partial  match, it is possible to call it again, with addi-
2439         tional  subject  characters,  and have it continue with the same match.         tional subject characters, and have it continue with  the  same  match.
2440         The PCRE_DFA_RESTART option requests this action; when it is  set,  the         The  PCRE_DFA_RESTART  option requests this action; when it is set, the
2441         workspace  and wscount options must reference the same vector as before         workspace and wscount options must reference the same vector as  before
2442         because data about the match so far is left in  them  after  a  partial         because  data  about  the  match so far is left in them after a partial
2443         match.  There  is  more  discussion of this facility in the pcrepartial         match. There is more discussion of this  facility  in  the  pcrepartial
2444         documentation.         documentation.
2445    
2446     Successful returns from pcre_dfa_exec()     Successful returns from pcre_dfa_exec()
2447    
2448         When pcre_dfa_exec() succeeds, it may have matched more than  one  sub-         When  pcre_dfa_exec()  succeeds, it may have matched more than one sub-
2449         string in the subject. Note, however, that all the matches from one run         string in the subject. Note, however, that all the matches from one run
2450         of the function start at the same point in  the  subject.  The  shorter         of  the  function  start  at the same point in the subject. The shorter
2451         matches  are all initial substrings of the longer matches. For example,         matches are all initial substrings of the longer matches. For  example,
2452         if the pattern         if the pattern
2453    
2454           <.*>           <.*>
# Line 2384  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 2463  MATCHING A PATTERN: THE ALTERNATIVE FUNC
2463           <something> <something else>           <something> <something else>
2464           <something> <something else> <something further>           <something> <something else> <something further>
2465    
2466         On success, the yield of the function is a number  greater  than  zero,         On  success,  the  yield of the function is a number greater than zero,
2467         which  is  the  number of matched substrings. The substrings themselves         which is the number of matched substrings.  The  substrings  themselves
2468         are returned in ovector. Each string uses two elements;  the  first  is         are  returned  in  ovector. Each string uses two elements; the first is
2469         the  offset  to  the start, and the second is the offset to the end. In         the offset to the start, and the second is the offset to  the  end.  In
2470         fact, all the strings have the same start  offset.  (Space  could  have         fact,  all  the  strings  have the same start offset. (Space could have
2471         been  saved by giving this only once, but it was decided to retain some         been saved by giving this only once, but it was decided to retain  some
2472         compatibility with the way pcre_exec() returns data,  even  though  the         compatibility  with  the  way pcre_exec() returns data, even though the
2473         meaning of the strings is different.)         meaning of the strings is different.)
2474    
2475         The strings are returned in reverse order of length; that is, the long-         The strings are returned in reverse order of length; that is, the long-
2476         est matching string is given first. If there were too many  matches  to         est  matching  string is given first. If there were too many matches to
2477         fit  into ovector, the yield of the function is zero, and the vector is         fit into ovector, the yield of the function is zero, and the vector  is
2478         filled with the longest matches.         filled with the longest matches.
2479    
2480     Error returns from pcre_dfa_exec()     Error returns from pcre_dfa_exec()
2481    
2482         The pcre_dfa_exec() function returns a negative number when  it  fails.         The  pcre_dfa_exec()  function returns a negative number when it fails.
2483         Many  of  the  errors  are  the  same as for pcre_exec(), and these are         Many of the errors are the same  as  for  pcre_exec(),  and  these  are
2484         described above.  There are in addition the following errors  that  are         described  above.   There are in addition the following errors that are
2485         specific to pcre_dfa_exec():         specific to pcre_dfa_exec():
2486    
2487           PCRE_ERROR_DFA_UITEM      (-16)           PCRE_ERROR_DFA_UITEM      (-16)
2488    
2489         This  return is given if pcre_dfa_exec() encounters an item in the pat-         This return is given if pcre_dfa_exec() encounters an item in the  pat-
2490         tern that it does not support, for instance, the use of \C  or  a  back         tern  that  it  does not support, for instance, the use of \C or a back
2491         reference.         reference.
2492    
2493           PCRE_ERROR_DFA_UCOND      (-17)           PCRE_ERROR_DFA_UCOND      (-17)
2494    
2495         This  return  is  given  if pcre_dfa_exec() encounters a condition item         This return is given if pcre_dfa_exec()  encounters  a  condition  item
2496         that uses a back reference for the condition, or a test  for  recursion         that  uses  a back reference for the condition, or a test for recursion
2497         in a specific group. These are not supported.         in a specific group. These are not supported.
2498    
2499           PCRE_ERROR_DFA_UMLIMIT    (-18)           PCRE_ERROR_DFA_UMLIMIT    (-18)
2500    
2501         This  return  is given if pcre_dfa_exec() is called with an extra block         This return is given if pcre_dfa_exec() is called with an  extra  block
2502         that contains a setting of the match_limit field. This is not supported         that contains a setting of the match_limit field. This is not supported
2503         (it is meaningless).         (it is meaningless).
2504    
2505           PCRE_ERROR_DFA_WSSIZE     (-19)           PCRE_ERROR_DFA_WSSIZE     (-19)
2506    
2507         This  return  is  given  if  pcre_dfa_exec()  runs  out of space in the         This return is given if  pcre_dfa_exec()  runs  out  of  space  in  the
2508         workspace vector.         workspace vector.
2509    
2510           PCRE_ERROR_DFA_RECURSE    (-20)           PCRE_ERROR_DFA_RECURSE    (-20)
2511    
2512         When a recursive subpattern is processed, the matching  function  calls         When  a  recursive subpattern is processed, the matching function calls
2513         itself  recursively,  using  private vectors for ovector and workspace.         itself recursively, using private vectors for  ovector  and  workspace.
2514         This error is given if the output vector  is  not  large  enough.  This         This  error  is  given  if  the output vector is not large enough. This
2515         should be extremely rare, as a vector of size 1000 is used.         should be extremely rare, as a vector of size 1000 is used.
2516    
2517    
2518  SEE ALSO  SEE ALSO
2519    
2520         pcrebuild(3),  pcrecallout(3), pcrecpp(3)(3), pcrematching(3), pcrepar-         pcrebuild(3), pcrecallout(3), pcrecpp(3)(3), pcrematching(3),  pcrepar-
2521         tial(3), pcreposix(3), pcreprecompile(3), pcresample(3),  pcrestack(3).         tial(3),  pcreposix(3), pcreprecompile(3), pcresample(3), pcrestack(3).
2522    
2523    
2524  AUTHOR  AUTHOR
# Line 2451  AUTHOR Line 2530  AUTHOR
2530    
2531  REVISION  REVISION
2532    
2533         Last updated: 09 August 2007         Last updated: 11 September 2007
2534         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
2535  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2536    
# Line 2736  DIFFERENCES BETWEEN PCRE AND PERL Line 2815  DIFFERENCES BETWEEN PCRE AND PERL
2815         (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-
2816         TURE options for pcre_exec() have no Perl equivalents.         TURE options for pcre_exec() have no Perl equivalents.
2817    
2818         (g) The callout facility is PCRE-specific.         (g) The \R escape sequence can be restricted to match only CR,  LF,  or
2819           CRLF by the PCRE_BSR_ANYCRLF option.
2820    
2821         (h) The partial matching facility is PCRE-specific.         (h) The callout facility is PCRE-specific.
2822    
2823         (i) Patterns compiled by PCRE can be saved and re-used at a later time,         (i) The partial matching facility is PCRE-specific.
2824    
2825           (j) Patterns compiled by PCRE can be saved and re-used at a later time,
2826         even on different hosts that have the other endianness.         even on different hosts that have the other endianness.
2827    
2828         (j)  The  alternative  matching function (pcre_dfa_exec()) matches in a         (k) The alternative matching function (pcre_dfa_exec())  matches  in  a
2829         different way and is not Perl-compatible.         different way and is not Perl-compatible.
2830    
2831           (l)  PCRE  recognizes some special sequences such as (*CR) at the start
2832           of a pattern that set overall options that cannot be changed within the
2833           pattern.
2834    
2835    
2836  AUTHOR  AUTHOR
2837    
# Line 2756  AUTHOR Line 2842  AUTHOR
2842    
2843  REVISION  REVISION
2844    
2845         Last updated: 08 August 2007         Last updated: 11 September 2007
2846         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.
2847  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2848    
# Line 2797  PCRE REGULAR EXPRESSION DETAILS Line 2883  PCRE REGULAR EXPRESSION DETAILS
2883         discussed in the pcrematching page.         discussed in the pcrematching page.
2884    
2885    
2886    NEWLINE CONVENTIONS
2887    
2888           PCRE  supports five different conventions for indicating line breaks in
2889           strings: a single CR (carriage return) character, a  single  LF  (line-
2890           feed) character, the two-character sequence CRLF, any of the three pre-
2891           ceding, or any Unicode newline sequence. The pcreapi page  has  further
2892           discussion  about newlines, and shows how to set the newline convention
2893           in the options arguments for the compiling and matching functions.
2894    
2895           It is also possible to specify a newline convention by starting a  pat-
2896           tern string with one of the following five sequences:
2897    
2898             (*CR)        carriage return
2899             (*LF)        linefeed
2900             (*CRLF)      carriage return, followed by linefeed
2901             (*ANYCRLF)   any of the three above
2902             (*ANY)       all Unicode newline sequences
2903    
2904           These override the default and the options given to pcre_compile(). For
2905           example, on a Unix system where LF is the default newline sequence, the
2906           pattern
2907    
2908             (*CR)a.b
2909    
2910           changes the convention to CR. That pattern matches "a\nb" because LF is
2911           no longer a newline. Note that these special settings,  which  are  not
2912           Perl-compatible,  are  recognized  only at the very start of a pattern,
2913           and that they must be in upper case.  If  more  than  one  of  them  is
2914           present, the last one is used.
2915    
2916           The  newline  convention  does  not  affect what the \R escape sequence
2917           matches. By default, this is any Unicode  newline  sequence,  for  Perl
2918           compatibility.  However, this can be changed; see the description of \R
2919           in the section entitled "Newline sequences" below. A change of \R  set-
2920           ting can be combined with a change of newline convention.
2921    
2922    
2923  CHARACTERS AND METACHARACTERS  CHARACTERS AND METACHARACTERS
2924    
2925         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 3027  BACKSLASH
3027           \cx       "control-x", where x is any character           \cx       "control-x", where x is any character
3028           \e        escape (hex 1B)           \e        escape (hex 1B)
3029           \f        formfeed (hex 0C)           \f        formfeed (hex 0C)
3030           \n        newline (hex 0A)           \n        linefeed (hex 0A)
3031           \r        carriage return (hex 0D)           \r        carriage return (hex 0D)
3032           \t        tab (hex 09)           \t        tab (hex 09)
3033           \ddd      character with octal code ddd, or backreference           \ddd      character with octal code ddd, or backreference
# Line 3069  BACKSLASH Line 3192  BACKSLASH
3192    
3193     Newline sequences     Newline sequences
3194    
3195         Outside a character class, the escape sequence \R matches  any  Unicode         Outside a character class, by default, the escape sequence  \R  matches
3196         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
3197         equivalent to the following:         mode \R is equivalent to the following:
3198    
3199           (?>\r\n|\n|\x0b|\f|\r|\x85)           (?>\r\n|\n|\x0b|\f|\r|\x85)
3200    
# Line 3087  BACKSLASH Line 3210  BACKSLASH
3210         rator,  U+2029).   Unicode character property support is not needed for         rator,  U+2029).   Unicode character property support is not needed for
3211         these characters to be recognized.         these characters to be recognized.
3212    
3213           It is possible to restrict \R to match only CR, LF, or CRLF (instead of
3214           the  complete  set  of  Unicode  line  endings)  by  setting the option
3215           PCRE_BSR_ANYCRLF either at compile time or when the pattern is matched.
3216           (BSR is an abbrevation for "backslash R".) This can be made the default
3217           when PCRE is built; if this is the case, the  other  behaviour  can  be
3218           requested  via  the  PCRE_BSR_UNICODE  option.   It is also possible to
3219           specify these settings by starting a pattern string  with  one  of  the
3220           following sequences:
3221    
3222             (*BSR_ANYCRLF)   CR, LF, or CRLF only
3223             (*BSR_UNICODE)   any Unicode newline sequence
3224    
3225           These override the default and the options given to pcre_compile(), but
3226           they can be overridden by options given to pcre_exec(). Note that these
3227           special settings, which are not Perl-compatible, are recognized only at
3228           the very start of a pattern, and that they must be in  upper  case.  If
3229           more  than  one  of  them is present, the last one is used. They can be
3230           combined with a change of newline convention, for  example,  a  pattern
3231           can start with:
3232    
3233             (*ANY)(*BSR_ANYCRLF)
3234    
3235         Inside a character class, \R matches the letter "R".         Inside a character class, \R matches the letter "R".
3236    
3237     Unicode character properties     Unicode character properties
3238    
3239         When PCRE is built with Unicode character property support, three addi-         When PCRE is built with Unicode character property support, three addi-
3240         tional  escape sequences that match characters with specific properties         tional escape sequences that match characters with specific  properties
3241         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
3242         limited  to  testing characters whose codepoints are less than 256, but         limited to testing characters whose codepoints are less than  256,  but
3243         they do work in this mode.  The extra escape sequences are:         they do work in this mode.  The extra escape sequences are:
3244    
3245           \p{xx}   a character with the xx property           \p{xx}   a character with the xx property
3246           \P{xx}   a character without the xx property           \P{xx}   a character without the xx property
3247           \X       an extended Unicode sequence           \X       an extended Unicode sequence
3248    
3249         The property names represented by xx above are limited to  the  Unicode         The  property  names represented by xx above are limited to the Unicode
3250         script names, the general category properties, and "Any", which matches         script names, the general category properties, and "Any", which matches
3251         any character (including newline). Other properties such as "InMusical-         any character (including newline). Other properties such as "InMusical-
3252         Symbols"  are  not  currently supported by PCRE. Note that \P{Any} does         Symbols" are not currently supported by PCRE. Note  that  \P{Any}  does
3253         not match any characters, so always causes a match failure.         not match any characters, so always causes a match failure.
3254    
3255         Sets of Unicode characters are defined as belonging to certain scripts.         Sets of Unicode characters are defined as belonging to certain scripts.
3256         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.
3257         For example:         For example:
3258    
3259           \p{Greek}           \p{Greek}
3260           \P{Han}           \P{Han}
3261    
3262         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
3263         "Common". The current list of scripts is:         "Common". The current list of scripts is:
3264    
3265         Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,         Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,
3266         Buhid,  Canadian_Aboriginal,  Cherokee,  Common,   Coptic,   Cuneiform,         Buhid,   Canadian_Aboriginal,   Cherokee,  Common,  Coptic,  Cuneiform,
3267         Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,         Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,
3268         Gothic, Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew,  Hira-         Gothic,  Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hira-
3269         gana,  Inherited,  Kannada,  Katakana,  Kharoshthi,  Khmer, Lao, Latin,         gana, Inherited, Kannada,  Katakana,  Kharoshthi,  Khmer,  Lao,  Latin,
3270         Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,         Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,
3271         Ogham,  Old_Italic,  Old_Persian, Oriya, Osmanya, Phags_Pa, Phoenician,         Ogham, Old_Italic, Old_Persian, Oriya, Osmanya,  Phags_Pa,  Phoenician,
3272         Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,         Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,
3273         Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.         Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.
3274    
3275         Each  character has exactly one general category property, specified by         Each character has exactly one general category property, specified  by
3276         a two-letter abbreviation. For compatibility with Perl, negation can be         a two-letter abbreviation. For compatibility with Perl, negation can be
3277         specified  by  including a circumflex between the opening brace and the         specified by including a circumflex between the opening brace  and  the
3278         property name. For example, \p{^Lu} is the same as \P{Lu}.         property name. For example, \p{^Lu} is the same as \P{Lu}.
3279    
3280         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-
3281         eral  category properties that start with that letter. In this case, in         eral category properties that start with that letter. In this case,  in
3282         the absence of negation, the curly brackets in the escape sequence  are         the  absence of negation, the curly brackets in the escape sequence are
3283         optional; these two examples have the same effect:         optional; these two examples have the same effect:
3284    
3285           \p{L}           \p{L}
# Line 3186  BACKSLASH Line 3331  BACKSLASH
3331           Zp    Paragraph separator           Zp    Paragraph separator
3332           Zs    Space separator           Zs    Space separator
3333    
3334         The  special property L& is also supported: it matches a character that         The special property L& is also supported: it matches a character  that
3335         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
3336         classified as a modifier or "other".         classified as a modifier or "other".
3337    
3338         The  Cs  (Surrogate)  property  applies only to characters in the range         The Cs (Surrogate) property applies only to  characters  in  the  range
3339         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
3340         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-
3341         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
3342         the pcreapi page).         the pcreapi page).
3343    
3344         The  long  synonyms  for  these  properties that Perl supports (such as         The long synonyms for these properties  that  Perl  supports  (such  as
3345         \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
3346         any of these properties with "Is".         any of these properties with "Is".
3347    
3348         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-
3349         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
3350         in the Unicode table.         in the Unicode table.
3351    
3352         Specifying  caseless  matching  does not affect these escape sequences.         Specifying caseless matching does not affect  these  escape  sequences.
3353         For example, \p{Lu} always matches only upper case letters.         For example, \p{Lu} always matches only upper case letters.
3354    
3355         The \X escape matches any number of Unicode  characters  that  form  an         The  \X  escape  matches  any number of Unicode characters that form an
3356         extended Unicode sequence. \X is equivalent to         extended Unicode sequence. \X is equivalent to
3357    
3358           (?>\PM\pM*)           (?>\PM\pM*)
3359    
3360         That  is,  it matches a character without the "mark" property, followed         That is, it matches a character without the "mark"  property,  followed
3361         by zero or more characters with the "mark"  property,  and  treats  the         by  zero  or  more  characters with the "mark" property, and treats the
3362         sequence  as  an  atomic group (see below).  Characters with the "mark"         sequence as an atomic group (see below).  Characters  with  the  "mark"
3363         property are typically accents that  affect  the  preceding  character.         property  are  typically  accents  that affect the preceding character.
3364         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
3365         matches any one character.         matches any one character.
3366    
3367         Matching characters by Unicode property is not fast, because  PCRE  has         Matching  characters  by Unicode property is not fast, because PCRE has
3368         to  search  a  structure  that  contains data for over fifteen thousand         to search a structure that contains  data  for  over  fifteen  thousand
3369         characters. That is why the traditional escape sequences such as \d and         characters. That is why the traditional escape sequences such as \d and
3370         \w do not use Unicode properties in PCRE.         \w do not use Unicode properties in PCRE.
3371    
3372     Resetting the match start     Resetting the match start
3373    
3374         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-
3375         ously matched characters not  to  be  included  in  the  final  matched         ously  matched  characters  not  to  be  included  in the final matched
3376         sequence. For example, the pattern:         sequence. For example, the pattern:
3377    
3378           foo\Kbar           foo\Kbar
3379    
3380         matches  "foobar",  but reports that it has matched "bar". This feature         matches "foobar", but reports that it has matched "bar".  This  feature
3381         is similar to a lookbehind assertion (described  below).   However,  in         is  similar  to  a lookbehind assertion (described below).  However, in
3382         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
3383         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
3384         not  interfere  with  the setting of captured substrings.  For example,         not interfere with the setting of captured  substrings.   For  example,
3385         when the pattern         when the pattern
3386    
3387           (foo)\Kbar           (foo)\Kbar
# Line 3245  BACKSLASH Line 3390  BACKSLASH
3390    
3391     Simple assertions     Simple assertions
3392    
3393         The final use of backslash is for certain simple assertions. An  asser-         The  final use of backslash is for certain simple assertions. An asser-
3394         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
3395         a match, without consuming any characters from the subject string.  The         a  match, without consuming any characters from the subject string. The
3396         use  of subpatterns for more complicated assertions is described below.         use of subpatterns for more complicated assertions is described  below.
3397         The backslashed assertions are:         The backslashed assertions are:
3398    
3399           \b     matches at a word boundary           \b     matches at a word boundary
# Line 3259  BACKSLASH Line 3404  BACKSLASH
3404           \z     matches only at the end of the subject           \z     matches only at the end of the subject
3405           \G     matches at the first matching position in the subject           \G     matches at the first matching position in the subject
3406    
3407         These assertions may not appear in character classes (but note that  \b         These  assertions may not appear in character classes (but note that \b
3408         has a different meaning, namely the backspace character, inside a char-         has a different meaning, namely the backspace character, inside a char-
3409         acter class).         acter class).
3410    
3411         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
3412         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.
3413         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
3414         string if the first or last character matches \w, respectively.         string if the first or last character matches \w, respectively.
3415    
3416         The  \A,  \Z,  and \z assertions differ from the traditional circumflex         The \A, \Z, and \z assertions differ from  the  traditional  circumflex
3417         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
3418         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
3419         set. Thus, they are independent of multiline mode. These  three  asser-         set.  Thus,  they are independent of multiline mode. These three asser-
3420         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
3421         affect only the behaviour of the circumflex and dollar  metacharacters.         affect  only the behaviour of the circumflex and dollar metacharacters.
3422         However,  if the startoffset argument of pcre_exec() is non-zero, indi-         However, if the startoffset argument of pcre_exec() is non-zero,  indi-
3423         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
3424         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
3425         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
3426         the very end, whereas \z matches only at the end.         the very end, whereas \z matches only at the end.
3427    
3428         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
3429         the start point of the match, as specified by the startoffset  argument         the  start point of the match, as specified by the startoffset argument
3430         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
3431         non-zero. By calling pcre_exec() multiple times with appropriate  argu-         non-zero.  By calling pcre_exec() multiple times with appropriate argu-
3432         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-
3433         mentation where \G can be useful.         mentation where \G can be useful.
3434    
3435         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
3436         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
3437         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
3438         previously  matched  string was empty. Because PCRE does just one match         previously matched string was empty. Because PCRE does just  one  match
3439         at a time, it cannot reproduce this behaviour.         at a time, it cannot reproduce this behaviour.
3440    
3441         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
3442         anchored to the starting match position, and the "anchored" flag is set         anchored to the starting match position, and the "anchored" flag is set
3443         in the compiled regular expression.         in the compiled regular expression.
3444    
# Line 3301  BACKSLASH Line 3446  BACKSLASH
3446  CIRCUMFLEX AND DOLLAR  CIRCUMFLEX AND DOLLAR
3447    
3448         Outside a character class, in the default matching mode, the circumflex         Outside a character class, in the default matching mode, the circumflex
3449         character  is  an  assertion  that is true only if the current matching         character is an assertion that is true only  if  the  current  matching
3450         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-
3451         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
3452         PCRE_MULTILINE option is unset. Inside a  character  class,  circumflex         PCRE_MULTILINE  option  is  unset. Inside a character class, circumflex
3453         has an entirely different meaning (see below).         has an entirely different meaning (see below).
3454    
3455         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
3456         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
3457         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
3458         branch. If all possible alternatives start with a circumflex, that  is,         branch.  If all possible alternatives start with a circumflex, that is,
3459         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-
3460         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
3461         constructs that can cause a pattern to be anchored.)         constructs that can cause a pattern to be anchored.)
3462    
3463         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
3464         matching point is at the end of  the  subject  string,  or  immediately         matching  point  is  at  the  end of the subject string, or immediately
3465         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
3466         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
3467         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
3468         appears. Dollar has no special meaning in a character class.         appears. Dollar has no special meaning in a character class.
3469    
3470         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
3471         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
3472         compile time. This does not affect the \Z assertion.         compile time. This does not affect the \Z assertion.
3473    
3474         The meanings of the circumflex and dollar characters are changed if the         The meanings of the circumflex and dollar characters are changed if the
3475         PCRE_MULTILINE  option  is  set.  When  this  is the case, a circumflex         PCRE_MULTILINE option is set. When  this  is  the  case,  a  circumflex
3476         matches immediately after internal newlines as well as at the start  of         matches  immediately after internal newlines as well as at the start of
3477         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
3478         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
3479         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
3480         as the two-character sequence CRLF, isolated CR and  LF  characters  do         as  the  two-character  sequence CRLF, isolated CR and LF characters do
3481         not indicate newlines.         not indicate newlines.
3482    
3483         For  example, the pattern /^abc$/ matches the subject string "def\nabc"         For example, the pattern /^abc$/ matches the subject string  "def\nabc"
3484         (where \n represents a newline) in multiline mode, but  not  otherwise.         (where  \n  represents a newline) in multiline mode, but not otherwise.
3485         Consequently,  patterns  that  are anchored in single line mode because         Consequently, patterns that are anchored in single  line  mode  because
3486         all branches start with ^ are not anchored in  multiline  mode,  and  a         all  branches  start  with  ^ are not anchored in multiline mode, and a
3487         match  for  circumflex  is  possible  when  the startoffset argument of         match for circumflex is  possible  when  the  startoffset  argument  of
3488         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
3489         PCRE_MULTILINE is set.         PCRE_MULTILINE is set.
3490    
3491         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
3492         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
3493         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
3494         set.         set.
3495    
3496    
3497  FULL STOP (PERIOD, DOT)  FULL STOP (PERIOD, DOT)
3498    
3499         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-
3500         ter  in  the subject string except (by default) a character that signi-         ter in the subject string except (by default) a character  that  signi-
3501         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
3502         more than one byte long.         more than one byte long.
3503    
3504         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
3505         that character; when the two-character sequence CRLF is used, dot  does         that  character; when the two-character sequence CRLF is used, dot does
3506         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
3507         matches all characters (including isolated CRs and LFs). When any  Uni-         matches  all characters (including isolated CRs and LFs). When any Uni-
3508         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
3509         any of the other line ending characters.         any of the other line ending characters.
3510    
3511         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
3512         PCRE_DOTALL  option  is  set,  a dot matches any one character, without         PCRE_DOTALL option is set, a dot matches  any  one  character,  without
3513         exception. If the two-character sequence CRLF is present in the subject         exception. If the two-character sequence CRLF is present in the subject
3514         string, it takes two dots to match it.         string, it takes two dots to match it.
3515    
3516         The  handling of dot is entirely independent of the handling of circum-         The handling of dot is entirely independent of the handling of  circum-
3517         flex and dollar, the only relationship being  that  they  both  involve         flex  and  dollar,  the  only relationship being that they both involve
3518         newlines. Dot has no special meaning in a character class.         newlines. Dot has no special meaning in a character class.
3519    
3520    
3521  MATCHING A SINGLE BYTE  MATCHING A SINGLE BYTE
3522    
3523         Outside a character class, the escape sequence \C matches any one byte,         Outside a character class, the escape sequence \C matches any one byte,
3524         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
3525         line-ending  characters.  The  feature  is provided in Perl in order to         line-ending characters. The feature is provided in  Perl  in  order  to
3526         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-
3527         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-
3528         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
3529         avoided.         avoided.
3530    
3531         PCRE  does  not  allow \C to appear in lookbehind assertions (described         PCRE does not allow \C to appear in  lookbehind  assertions  (described
3532         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-
3533         late the length of the lookbehind.         late the length of the lookbehind.
3534    
3535    
# Line 3393  SQUARE BRACKETS AND CHARACTER CLASSES Line 3538  SQUARE BRACKETS AND CHARACTER CLASSES
3538         An opening square bracket introduces a character class, terminated by a         An opening square bracket introduces a character class, terminated by a
3539         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-
3540         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,
3541         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
3542         circumflex, if present) or escaped with a backslash.         circumflex, if present) or escaped with a backslash.
3543    
3544         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
3545         mode, the character may occupy more than one byte. A matched  character         mode,  the character may occupy more than one byte. A matched character
3546         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
3547         character in the class definition is a circumflex, in  which  case  the         character  in  the  class definition is a circumflex, in which case the
3548         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
3549         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
3550         not the first character, or escape it with a backslash.         not the first character, or escape it with a backslash.
3551    
3552         For  example, the character class [aeiou] matches any lower case vowel,         For example, the character class [aeiou] matches any lower case  vowel,
3553         while [^aeiou] matches any character that is not a  lower  case  vowel.         while  [^aeiou]  matches  any character that is not a lower case vowel.
3554         Note that a circumflex is just a convenient notation for specifying the         Note that a circumflex is just a convenient notation for specifying the
3555         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
3556         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-
3557         sumes a character from the subject string, and therefore  it  fails  if         sumes  a  character  from the subject string, and therefore it fails if
3558         the current pointer is at the end of the string.         the current pointer is at the end of the string.
3559    
3560         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
3561         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
3562         mechanism.         mechanism.
3563    
3564         When  caseless  matching  is set, any letters in a class represent both         When caseless matching is set, any letters in a  class  represent  both
3565         their upper case and lower case versions, so for  example,  a  caseless         their  upper  case  and lower case versions, so for example, a caseless
3566         [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
3567         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
3568         understands  the  concept  of case for characters whose values are less         understands the concept of case for characters whose  values  are  less
3569         than 128, so caseless matching is always possible. For characters  with         than  128, so caseless matching is always possible. For characters with
3570         higher  values,  the  concept  of case is supported if PCRE is compiled         higher values, the concept of case is supported  if  PCRE  is  compiled
3571         with Unicode property support, but not otherwise.  If you want  to  use         with  Unicode  property support, but not otherwise.  If you want to use
3572         caseless  matching  for  characters 128 and above, you must ensure that         caseless matching for characters 128 and above, you  must  ensure  that
3573         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
3574         support.         support.
3575    
3576         Characters  that  might  indicate  line breaks are never treated in any         Characters that might indicate line breaks are  never  treated  in  any
3577         special way  when  matching  character  classes,  whatever  line-ending         special  way  when  matching  character  classes,  whatever line-ending
3578         sequence  is  in  use,  and  whatever  setting  of  the PCRE_DOTALL and         sequence is in  use,  and  whatever  setting  of  the  PCRE_DOTALL  and
3579         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
3580         of these characters.         of these characters.
3581    
3582         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-
3583         ters in a character  class.  For  example,  [d-m]  matches  any  letter         ters  in  a  character  class.  For  example,  [d-m] matches any letter
3584         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
3585         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
3586         where  it cannot be interpreted as indicating a range, typically as the         where it cannot be interpreted as indicating a range, typically as  the
3587         first or last character in the class.         first or last character in the class.
3588    
3589         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-
3590         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
3591         two characters ("W" and "-") followed by a literal string "46]", so  it         two  characters ("W" and "-") followed by a literal string "46]", so it
3592         would  match  "W46]"  or  "-46]". However, if the "]" is escaped with a         would match "W46]" or "-46]". However, if the "]"  is  escaped  with  a
3593         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-
3594         preted  as a class containing a range followed by two other characters.         preted as a class containing a range followed by two other  characters.
3595         The octal or hexadecimal representation of "]" can also be used to  end         The  octal or hexadecimal representation of "]" can also be used to end
3596         a range.         a range.
3597    
3598         Ranges  operate in the collating sequence of character values. They can         Ranges operate in the collating sequence of character values. They  can
3599         also  be  used  for  characters  specified  numerically,  for   example         also   be  used  for  characters  specified  numerically,  for  example
3600         [\000-\037].  In UTF-8 mode, ranges can include characters whose values         [\000-\037]. In UTF-8 mode, ranges can include characters whose  values
3601         are greater than 255, for example [\x{100}-\x{2ff}].         are greater than 255, for example [\x{100}-\x{2ff}].
3602    
3603         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,
3604         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
3605         to [][\\^_`wxyzabc], matched caselessly,  and  in  non-UTF-8  mode,  if         to  [][\\^_`wxyzabc],  matched  caselessly,  and  in non-UTF-8 mode, if
3606         character  tables  for  a French locale are in use, [\xc8-\xcb] matches         character tables for a French locale are in  use,  [\xc8-\xcb]  matches
3607         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
3608         concept  of  case for characters with values greater than 128 only when         concept of case for characters with values greater than 128  only  when
3609         it is compiled with Unicode property support.         it is compiled with Unicode property support.
3610    
3611         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
3612         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
3613         class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-         class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-
3614         flex  can  conveniently  be used with the upper case character types to         flex can conveniently be used with the upper case  character  types  to
3615         specify a more restricted set of characters  than  the  matching  lower         specify  a  more  restricted  set of characters than the matching lower
3616         case  type.  For example, the class [^\W_] matches any letter or digit,         case type. For example, the class [^\W_] matches any letter  or  digit,
3617         but not underscore.         but not underscore.
3618    
3619         The only metacharacters that are recognized in  character  classes  are         The  only  metacharacters  that are recognized in character classes are
3620         backslash,  hyphen  (only  where  it can be interpreted as specifying a         backslash, hyphen (only where it can be  interpreted  as  specifying  a
3621         range), circumflex (only at the start), opening  square  bracket  (only         range),  circumflex  (only  at the start), opening square bracket (only
3622         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
3623         next section), and the terminating  closing  square  bracket.  However,         next  section),  and  the  terminating closing square bracket. However,
3624         escaping other non-alphanumeric characters does no harm.         escaping other non-alphanumeric characters does no harm.
3625    
3626    
3627  POSIX CHARACTER CLASSES  POSIX CHARACTER CLASSES
3628    
3629         Perl supports the POSIX notation for character classes. This uses names         Perl supports the POSIX notation for character classes. This uses names
3630         enclosed by [: and :] within the enclosing square brackets.  PCRE  also         enclosed  by  [: and :] within the enclosing square brackets. PCRE also
3631         supports this notation. For example,         supports this notation. For example,
3632    
3633           [01[:alpha:]%]           [01[:alpha:]%]
# Line 3505  POSIX CHARACTER CLASSES Line 3650  POSIX CHARACTER CLASSES
3650           word     "word" characters (same as \w)           word     "word" characters (same as \w)
3651           xdigit   hexadecimal digits           xdigit   hexadecimal digits
3652    
3653         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),
3654         and  space  (32). Notice that this list includes the VT character (code         and space (32). Notice that this list includes the VT  character  (code
3655         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
3656         Perl compatibility).         Perl compatibility).
3657    
3658         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
3659         from Perl 5.8. Another Perl extension is negation, which  is  indicated         from  Perl  5.8. Another Perl extension is negation, which is indicated
3660         by a ^ character after the colon. For example,         by a ^ character after the colon. For example,
3661    
3662           [12[:^digit:]]           [12[:^digit:]]
3663    
3664         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
3665         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but
3666         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.
3667    
# Line 3526  POSIX CHARACTER CLASSES Line 3671  POSIX CHARACTER CLASSES
3671    
3672  VERTICAL BAR  VERTICAL BAR
3673    
3674         Vertical  bar characters are used to separate alternative patterns. For         Vertical bar characters are used to separate alternative patterns.  For
3675         example, the pattern         example, the pattern
3676    
3677           gilbert|sullivan           gilbert|sullivan
3678    
3679         matches either "gilbert" or "sullivan". Any number of alternatives  may         matches  either "gilbert" or "sullivan". Any number of alternatives may
3680         appear,  and  an  empty  alternative  is  permitted (matching the empty         appear, and an empty  alternative  is  permitted  (matching  the  empty
3681         string). The matching process tries each alternative in turn, from left         string). The matching process tries each alternative in turn, from left
3682         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
3683         are within a subpattern (defined below), "succeeds" means matching  the         are  within a subpattern (defined below), "succeeds" means matching the
3684         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.
3685    
3686    
3687  INTERNAL OPTION SETTING  INTERNAL OPTION SETTING
3688    
3689         The settings of the  PCRE_CASELESS,  PCRE_MULTILINE,  PCRE_DOTALL,  and         The  settings  of  the  PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and
3690         PCRE_EXTENDED  options  can  be  changed  from  within the pattern by a         PCRE_EXTENDED options (which are Perl-compatible) can be  changed  from
3691         sequence of Perl option letters enclosed  between  "(?"  and  ")".  The         within  the  pattern  by  a  sequence  of  Perl option letters enclosed
3692         option letters are         between "(?" and ")".  The option letters are
3693    
3694           i  for PCRE_CASELESS           i  for PCRE_CASELESS
3695           m  for PCRE_MULTILINE           m  for PCRE_MULTILINE
# Line 3553  INTERNAL OPTION SETTING Line 3698  INTERNAL OPTION SETTING
3698    
3699         For example, (?im) sets caseless, multiline matching. It is also possi-         For example, (?im) sets caseless, multiline matching. It is also possi-
3700         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
3701         combined  setting and unsetting such as (?im-sx), which sets PCRE_CASE-         combined setting and unsetting such as (?im-sx), which sets  PCRE_CASE-
3702         LESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and  PCRE_EXTENDED,         LESS  and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED,
3703         is  also  permitted.  If  a  letter  appears  both before and after the         is also permitted. If a  letter  appears  both  before  and  after  the
3704         hyphen, the option is unset.         hyphen, the option is unset.
3705    
3706         When an option change occurs at top level (that is, not inside  subpat-         The  PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA
3707         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
3708           the characters J, U and X respectively.
3709    
3710           When  an option change occurs at top level (that is, not inside subpat-
3711           tern parentheses), the change applies to the remainder of  the  pattern
3712         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,
3713         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
3714         in data extracted by the pcre_fullinfo() function).         in data extracted by the pcre_fullinfo() function).
3715    
3716         An option change within a subpattern (see below for  a  description  of         An  option  change  within a subpattern (see below for a description of
3717         subpatterns) affects only that part of the current pattern that follows         subpatterns) affects only that part of the current pattern that follows
3718         it, so         it, so
3719    
3720           (a(?i)b)c           (a(?i)b)c
3721    
3722         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
3723         used).   By  this means, options can be made to have different settings         used).  By this means, options can be made to have  different  settings
3724         in different parts of the pattern. Any changes made in one  alternative         in  different parts of the pattern. Any changes made in one alternative
3725         do  carry  on  into subsequent branches within the same subpattern. For         do carry on into subsequent branches within the  same  subpattern.  For
3726         example,         example,
3727    
3728           (a(?i)b|c)           (a(?i)b|c)
3729    
3730         matches "ab", "aB", "c", and "C", even though  when  matching  "C"  the         matches  "ab",  "aB",  "c",  and "C", even though when matching "C" the
3731         first  branch  is  abandoned before the option setting. This is because         first branch is abandoned before the option setting.  This  is  because
3732         the effects of option settings happen at compile time. There  would  be         the  effects  of option settings happen at compile time. There would be
3733         some very weird behaviour otherwise.         some very weird behaviour otherwise.
3734    
3735         The  PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA         Note: There are other PCRE-specific options that  can  be  set  by  the
3736         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
3737         the characters J, U and X respectively.         cases the pattern can contain special  leading  sequences  to  override
3738           what  the  application  has set or what has been defaulted. Details are
3739           given in the section entitled "Newline sequences" above.
3740    
3741    
3742  SUBPATTERNS  SUBPATTERNS
# Line 3597  SUBPATTERNS Line 3748  SUBPATTERNS
3748    
3749           cat(aract|erpillar|)           cat(aract|erpillar|)
3750    
3751         matches one of the words "cat", "cataract", or  "caterpillar".  Without         matches  one  of the words "cat", "cataract", or "caterpillar". Without
3752         the  parentheses,  it  would  match  "cataract", "erpillar" or an empty         the parentheses, it would match  "cataract",  "erpillar"  or  an  empty
3753         string.         string.
3754    
3755         2. It sets up the subpattern as  a  capturing  subpattern.  This  means         2.  It  sets  up  the  subpattern as a capturing subpattern. This means
3756         that,  when  the  whole  pattern  matches,  that portion of the subject         that, when the whole pattern  matches,  that  portion  of  the  subject
3757         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
3758         ovector  argument  of pcre_exec(). Opening parentheses are counted from         ovector argument of pcre_exec(). Opening parentheses are  counted  from
3759         left to right (starting from 1) to obtain  numbers  for  the  capturing         left  to  right  (starting  from 1) to obtain numbers for the capturing
3760         subpatterns.         subpatterns.
3761    
3762         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-
3763         tern         tern
3764    
3765           the ((red|white) (king|queen))           the ((red|white) (king|queen))
# Line 3616  SUBPATTERNS Line 3767  SUBPATTERNS
3767         the captured substrings are "red king", "red", and "king", and are num-         the captured substrings are "red king", "red", and "king", and are num-
3768         bered 1, 2, and 3, respectively.         bered 1, 2, and 3, respectively.
3769    
3770         The  fact  that  plain  parentheses  fulfil two functions is not always         The fact that plain parentheses fulfil  two  functions  is  not  always
3771         helpful.  There are often times when a grouping subpattern is  required         helpful.   There are often times when a grouping subpattern is required
3772         without  a capturing requirement. If an opening parenthesis is followed         without a capturing requirement. If an opening parenthesis is  followed
3773         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-
3774         ing,  and  is  not  counted when computing the number of any subsequent         ing, and is not counted when computing the  number  of  any  subsequent
3775         capturing subpatterns. For example, if the string "the white queen"  is         capturing  subpatterns. For example, if the string "the white queen" is
3776         matched against the pattern         matched against the pattern
3777    
3778           the ((?:red|white) (king|queen))           the ((?:red|white) (king|queen))
# Line 3629  SUBPATTERNS Line 3780  SUBPATTERNS
3780         the captured substrings are "white queen" and "queen", and are numbered         the captured substrings are "white queen" and "queen", and are numbered
3781         1 and 2. The maximum number of capturing subpatterns is 65535.         1 and 2. The maximum number of capturing subpatterns is 65535.
3782    
3783         As a convenient shorthand, if any option settings are required  at  the         As  a  convenient shorthand, if any option settings are required at the
3784         start  of  a  non-capturing  subpattern,  the option letters may appear         start of a non-capturing subpattern,  the  option  letters  may  appear
3785         between the "?" and the ":". Thus the two patterns         between the "?" and the ":". Thus the two patterns
3786    
3787           (?i:saturday|sunday)           (?i:saturday|sunday)
3788           (?:(?i)saturday|sunday)           (?:(?i)saturday|sunday)
3789    
3790         match exactly the same set of strings. Because alternative branches are         match exactly the same set of strings. Because alternative branches are
3791         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
3792         the subpattern is reached, an option setting in one branch does  affect         the  subpattern is reached, an option setting in one branch does affect
3793         subsequent  branches,  so  the above patterns match "SUNDAY" as well as         subsequent branches, so the above patterns match "SUNDAY"  as  well  as
3794         "Saturday".         "Saturday".
3795    
3796    
3797  DUPLICATE SUBPATTERN NUMBERS  DUPLICATE SUBPATTERN NUMBERS
3798    
3799         Perl 5.10 introduced a feature whereby each alternative in a subpattern         Perl 5.10 introduced a feature whereby each alternative in a subpattern
3800         uses  the same numbers for its capturing parentheses. Such a subpattern         uses the same numbers for its capturing parentheses. Such a  subpattern
3801         starts with (?| and is itself a non-capturing subpattern. For  example,         starts  with (?| and is itself a non-capturing subpattern. For example,
3802         consider this pattern:         consider this pattern:
3803    
3804           (?|(Sat)ur|(Sun))day           (?|(Sat)ur|(Sun))day
3805    
3806         Because  the two alternatives are inside a (?| group, both sets of cap-         Because the two alternatives are inside a (?| group, both sets of  cap-
3807         turing parentheses are numbered one. Thus, when  the  pattern  matches,         turing  parentheses  are  numbered one. Thus, when the pattern matches,
3808         you  can  look  at captured substring number one, whichever alternative         you can look at captured substring number  one,  whichever  alternative
3809         matched. This construct is useful when you want to  capture  part,  but         matched.  This  construct  is useful when you want to capture part, but
3810         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-
3811         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
3812         each  branch. The numbers of any capturing buffers that follow the sub-         each branch. The numbers of any capturing buffers that follow the  sub-
3813         pattern start after the highest number used in any branch. The  follow-         pattern  start after the highest number used in any branch. The follow-
3814         ing  example  is taken from the Perl documentation.  The numbers under-         ing example is taken from the Perl documentation.  The  numbers  under-
3815         neath show in which buffer the captured content will be stored.         neath show in which buffer the captured content will be stored.
3816    
3817           # before  ---------------branch-reset----------- after           # before  ---------------branch-reset----------- after
3818           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
3819           # 1            2         2  3        2     3     4           # 1            2         2  3        2     3     4
3820    
3821         A backreference or a recursive call to  a  numbered  subpattern  always         A  backreference  or  a  recursive call to a numbered subpattern always
3822         refers to the first one in the pattern with the given number.         refers to the first one in the pattern with the given number.
3823    
3824         An  alternative approach to using this "branch reset" feature is to use         An alternative approach to using this "branch reset" feature is to  use
3825         duplicate named subpatterns, as described in the next section.         duplicate named subpatterns, as described in the next section.
3826    
3827    
3828  NAMED SUBPATTERNS  NAMED SUBPATTERNS
3829    
3830         Identifying capturing parentheses by number is simple, but  it  can  be         Identifying  capturing  parentheses  by number is simple, but it can be
3831         very  hard  to keep track of the numbers in complicated regular expres-         very hard to keep track of the numbers in complicated  regular  expres-
3832         sions. Furthermore, if an  expression  is  modified,  the  numbers  may         sions.  Furthermore,  if  an  expression  is  modified, the numbers may
3833         change.  To help with this difficulty, PCRE supports the naming of sub-         change. To help with this difficulty, PCRE supports the naming of  sub-
3834         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
3835         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
3836         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-
3837         tax.         tax.
3838    
3839         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>...)
3840         or (?'name'...) as in Perl, or (?P<name>...) as in  Python.  References         or  (?'name'...)  as in Perl, or (?P<name>...) as in Python. References
3841         to capturing parentheses from other parts of the pattern, such as back-         to capturing parentheses from other parts of the pattern, such as back-
3842         references, recursion, and conditions, can be made by name as  well  as         references,  recursion,  and conditions, can be made by name as well as
3843         by number.         by number.
3844    
3845         Names  consist  of  up  to  32 alphanumeric characters and underscores.         Names consist of up to  32  alphanumeric  characters  and  underscores.
3846         Named capturing parentheses are still  allocated  numbers  as  well  as         Named  capturing  parentheses  are  still  allocated numbers as well as
3847         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
3848         function calls for extracting the name-to-number translation table from         function calls for extracting the name-to-number translation table from
3849         a compiled pattern. There is also a convenience function for extracting         a compiled pattern. There is also a convenience function for extracting
3850         a captured substring by name.         a captured substring by name.
3851    
3852         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
3853         to relax this constraint by setting the PCRE_DUPNAMES option at compile         to relax this constraint by setting the PCRE_DUPNAMES option at compile
3854         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
3855         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
3856         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
3857         both cases you want to extract the abbreviation. This pattern (ignoring         both cases you want to extract the abbreviation. This pattern (ignoring
3858         the line breaks) does the job:         the line breaks) does the job:
3859    
# Line 3712  NAMED SUBPATTERNS Line 3863  NAMED SUBPATTERNS
3863           (?<DN>Thu)(?:rsday)?|           (?<DN>Thu)(?:rsday)?|
3864           (?<DN>Sat)(?:urday)?           (?<DN>Sat)(?:urday)?
3865    
3866         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
3867         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
3868         reset" subpattern, as described in the previous section.)         reset" subpattern, as described in the previous section.)
3869    
3870         The convenience function for extracting the data by  name  returns  the         The  convenience  function  for extracting the data by name returns the
3871         substring  for  the first (and in this example, the only) subpattern of         substring for the first (and in this example, the only)  subpattern  of
3872         that name that matched. This saves searching  to  find  which  numbered         that  name  that  matched.  This saves searching to find which numbered
3873         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-
3874         pattern from elsewhere in the pattern, the one that corresponds to  the         pattern  from elsewhere in the pattern, the one that corresponds to the
3875         lowest  number  is used. For further details of the interfaces for han-         lowest number is used. For further details of the interfaces  for  han-
3876         dling named subpatterns, see the pcreapi documentation.         dling named subpatterns, see the pcreapi documentation.
3877    
3878    
3879  REPETITION  REPETITION
3880    
3881         Repetition is specified by quantifiers, which can  follow  any  of  the         Repetition  is  specified  by  quantifiers, which can follow any of the
3882         following items:         following items:
3883    
3884           a literal data character           a literal data character
# Line 3740  REPETITION Line 3891  REPETITION
3891           a back reference (see next section)           a back reference (see next section)
3892           a parenthesized subpattern (unless it is an assertion)           a parenthesized subpattern (unless it is an assertion)
3893    
3894         The  general repetition quantifier specifies a minimum and maximum num-         The general repetition quantifier specifies a minimum and maximum  num-
3895         ber of permitted matches, by giving the two numbers in  curly  brackets         ber  of  permitted matches, by giving the two numbers in curly brackets
3896         (braces),  separated  by  a comma. The numbers must be less than 65536,         (braces), separated by a comma. The numbers must be  less  than  65536,
3897         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:
3898    
3899           z{2,4}           z{2,4}
3900    
3901         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
3902         special  character.  If  the second number is omitted, but the comma is         special character. If the second number is omitted, but  the  comma  is
3903         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
3904         are  both omitted, the quantifier specifies an exact number of required         are both omitted, the quantifier specifies an exact number of  required
3905         matches. Thus         matches. Thus
3906    
3907           [aeiou]{3,}           [aeiou]{3,}
# Line 3759  REPETITION Line 3910  REPETITION
3910    
3911           \d{8}           \d{8}
3912    
3913         matches exactly 8 digits. An opening curly bracket that  appears  in  a         matches  exactly  8  digits. An opening curly bracket that appears in a
3914         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
3915         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-
3916         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.
3917    
3918         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
3919         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-
3920         acters, each of which is represented by a two-byte sequence. Similarly,         acters, each of which is represented by a two-byte sequence. Similarly,
3921         when Unicode property support is available, \X{3} matches three Unicode         when Unicode property support is available, \X{3} matches three Unicode
3922         extended sequences, each of which may be several bytes long  (and  they         extended  sequences,  each of which may be several bytes long (and they
3923         may be of different lengths).         may be of different lengths).
3924    
3925         The quantifier {0} is permitted, causing the expression to behave as if         The quantifier {0} is permitted, causing the expression to behave as if
3926         the previous item and the quantifier were not present.         the previous item and the quantifier were not present.
3927    
3928         For convenience, the three most common quantifiers have  single-charac-         For  convenience, the three most common quantifiers have single-charac-
3929         ter abbreviations:         ter abbreviations:
3930    
3931           *    is equivalent to {0,}           *    is equivalent to {0,}
3932           +    is equivalent to {1,}           +    is equivalent to {1,}
3933           ?    is equivalent to {0,1}           ?    is equivalent to {0,1}
3934    
3935         It  is  possible  to construct infinite loops by following a subpattern         It is possible to construct infinite loops by  following  a  subpattern
3936         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,
3937         for example:         for example:
3938    
3939           (a?)*           (a?)*
3940    
3941         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
3942         for such patterns. However, because there are cases where this  can  be         for  such  patterns. However, because there are cases where this can be
3943         useful,  such  patterns  are now accepted, but if any repetition of the         useful, such patterns are now accepted, but if any  repetition  of  the
3944         subpattern does in fact match no characters, the loop is forcibly  bro-         subpattern  does in fact match no characters, the loop is forcibly bro-
3945         ken.         ken.
3946    
3947         By  default,  the quantifiers are "greedy", that is, they match as much         By default, the quantifiers are "greedy", that is, they match  as  much
3948         as possible (up to the maximum  number  of  permitted  times),  without         as  possible  (up  to  the  maximum number of permitted times), without
3949         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
3950         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
3951         appear  between  /*  and  */ and within the comment, individual * and /         appear between /* and */ and within the comment,  individual  *  and  /
3952         characters may appear. An attempt to match C comments by  applying  the         characters  may  appear. An attempt to match C comments by applying the
3953         pattern         pattern
3954    
3955           /\*.*\*/           /\*.*\*/
# Line 3807  REPETITION Line 3958  REPETITION
3958    
3959           /* first comment */  not comment  /* second comment */           /* first comment */  not comment  /* second comment */
3960    
3961         fails,  because it matches the entire string owing to the greediness of         fails, because it matches the entire string owing to the greediness  of
3962         the .*  item.         the .*  item.
3963    
3964         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
3965         be greedy, and instead matches the minimum number of times possible, so         be greedy, and instead matches the minimum number of times possible, so
3966         the pattern         the pattern
3967    
3968           /\*.*?\*/           /\*.*?\*/
3969    
3970         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
3971         quantifiers  is  not  otherwise  changed,  just the preferred number of         quantifiers is not otherwise changed,  just  the  preferred  number  of
3972         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
3973         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
3974         appear doubled, as in         appear doubled, as in
3975    
3976           \d??\d           \d??\d
# Line 3827  REPETITION Line 3978  REPETITION
3978         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
3979         only way the rest of the pattern matches.         only way the rest of the pattern matches.
3980    
3981         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
3982         Perl), the quantifiers are not greedy by default, but  individual  ones         Perl),  the  quantifiers are not greedy by default, but individual ones
3983         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
3984         words, it inverts the default behaviour.         words, it inverts the default behaviour.
3985    
3986         When a parenthesized subpattern is quantified  with  a  minimum  repeat         When  a  parenthesized  subpattern  is quantified with a minimum repeat
3987         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
3988         required for the compiled pattern, in proportion to  the  size  of  the         required  for  the  compiled  pattern, in proportion to the size of the
3989         minimum or maximum.         minimum or maximum.
3990    
3991         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-
3992         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,
3993         the  pattern  is  implicitly anchored, because whatever follows will be         the pattern is implicitly anchored, because whatever  follows  will  be
3994         tried against every character position in the subject string, so  there         tried  against every character position in the subject string, so there
3995         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
3996         first. PCRE normally treats such a pattern as though it  were  preceded         first.  PCRE  normally treats such a pattern as though it were preceded
3997         by \A.         by \A.
3998    
3999         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-
4000         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-
4001         mization, or alternatively using ^ to indicate anchoring explicitly.         mization, or alternatively using ^ to indicate anchoring explicitly.
4002    
4003         However,  there is one situation where the optimization cannot be used.         However, there is one situation where the optimization cannot be  used.
4004         When .*  is inside capturing parentheses that  are  the  subject  of  a         When  .*   is  inside  capturing  parentheses that are the subject of a
4005         backreference  elsewhere  in the pattern, a match at the start may fail         backreference elsewhere in the pattern, a match at the start  may  fail
4006         where a later one succeeds. Consider, for example:         where a later one succeeds. Consider, for example:
4007    
4008           (.*)abc\1           (.*)abc\1
4009    
4010         If the subject is "xyz123abc123" the match point is the fourth  charac-         If  the subject is "xyz123abc123" the match point is the fourth charac-
4011         ter. For this reason, such a pattern is not implicitly anchored.         ter. For this reason, such a pattern is not implicitly anchored.
4012    
4013         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 4016  REPETITION
4016           (tweedle[dume]{3}\s*)+           (tweedle[dume]{3}\s*)+
4017    
4018         has matched "tweedledum tweedledee" the value of the captured substring         has matched "tweedledum tweedledee" the value of the captured substring
4019         is  "tweedledee".  However,  if there are nested capturing subpatterns,         is "tweedledee". However, if there are  nested  capturing  subpatterns,
4020         the corresponding captured values may have been set in previous  itera-         the  corresponding captured values may have been set in previous itera-
4021         tions. For example, after         tions. For example, after
4022    
4023           /(a|(b))+/           /(a|(b))+/
# Line 3876  REPETITION Line 4027  REPETITION
4027    
4028  ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS  ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS
4029    
4030         With  both  maximizing ("greedy") and minimizing ("ungreedy" or "lazy")         With both maximizing ("greedy") and minimizing ("ungreedy"  or  "lazy")
4031         repetition, failure of what follows normally causes the  repeated  item         repetition,  failure  of what follows normally causes the repeated item
4032         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
4033         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,
4034         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
4035         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
4036         no point in carrying on.         no point in carrying on.
4037    
4038         Consider,  for  example, the pattern \d+foo when applied to the subject         Consider, for example, the pattern \d+foo when applied to  the  subject
4039         line         line
4040    
4041           123456bar           123456bar
4042    
4043         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
4044         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
4045         \d+ item, and then with  4,  and  so  on,  before  ultimately  failing.         \d+  item,  and  then  with  4,  and  so on, before ultimately failing.
4046         "Atomic  grouping"  (a  term taken from Jeffrey Friedl's book) provides         "Atomic grouping" (a term taken from Jeffrey  Friedl's  book)  provides
4047         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
4048         to be re-evaluated in this way.         to be re-evaluated in this way.
4049    
4050         If  we  use atomic grouping for the previous example, the matcher gives         If we use atomic grouping for the previous example, the  matcher  gives
4051         up immediately on failing to match "foo" the first time.  The  notation         up  immediately  on failing to match "foo" the first time. The notation
4052         is a kind of special parenthesis, starting with (?> as in this example:         is a kind of special parenthesis, starting with (?> as in this example:
4053    
4054           (?>\d+)foo           (?>\d+)foo
4055    
4056         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-
4057         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
4058         prevented from backtracking into it. Backtracking past it  to  previous         prevented  from  backtracking into it. Backtracking past it to previous
4059         items, however, works as normal.         items, however, works as normal.
4060    
4061         An  alternative  description  is that a subpattern of this type matches         An alternative description is that a subpattern of  this  type  matches
4062         the string of characters that an  identical  standalone  pattern  would         the  string  of  characters  that an identical standalone pattern would
4063         match, if anchored at the current point in the subject string.         match, if anchored at the current point in the subject string.
4064    
4065         Atomic grouping subpatterns are not capturing subpatterns. Simple cases         Atomic grouping subpatterns are not capturing subpatterns. Simple cases
4066         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
4067         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-
4068         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
4069         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
4070         digits.         digits.
4071    
4072         Atomic groups in general can of course contain arbitrarily  complicated         Atomic  groups in general can of course contain arbitrarily complicated
4073         subpatterns,  and  can  be  nested. However, when the subpattern for an         subpatterns, and can be nested. However, when  the  subpattern  for  an
4074         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
4075         simpler  notation,  called  a "possessive quantifier" can be used. This         simpler notation, called a "possessive quantifier" can  be  used.  This
4076         consists of an additional + character  following  a  quantifier.  Using         consists  of  an  additional  + character following a quantifier. Using
4077         this notation, the previous example can be rewritten as         this notation, the previous example can be rewritten as
4078    
4079           \d++foo           \d++foo
# Line 3932  ATOMIC GROUPING AND POSSESSIVE QUANTIFIE Line 4083  ATOMIC GROUPING AND POSSESSIVE QUANTIFIE
4083    
4084           (abc|xyz){2,3}+           (abc|xyz){2,3}+
4085    
4086         Possessive  quantifiers  are  always  greedy;  the   setting   of   the         Possessive   quantifiers   are   always  greedy;  the  setting  of  the
4087         PCRE_UNGREEDY option is ignored. They are a convenient notation for the         PCRE_UNGREEDY option is ignored. They are a convenient notation for the
4088         simpler forms of atomic group. However, there is no difference  in  the         simpler  forms  of atomic group. However, there is no difference in the
4089         meaning  of  a  possessive  quantifier and the equivalent atomic group,         meaning of a possessive quantifier and  the  equivalent  atomic  group,
4090         though there may be a performance  difference;  possessive  quantifiers         though  there  may  be a performance difference; possessive quantifiers
4091         should be slightly faster.         should be slightly faster.
4092    
4093         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-
4094         tax.  Jeffrey Friedl originated the idea (and the name)  in  the  first         tax.   Jeffrey  Friedl  originated the idea (and the name) in the first
4095         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
4096         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
4097         found its way into Perl at release 5.10.         found its way into Perl at release 5.10.
4098    
4099         PCRE has an optimization that automatically "possessifies" certain sim-         PCRE has an optimization that automatically "possessifies" certain sim-
4100         ple pattern constructs. For example, the sequence  A+B  is  treated  as         ple  pattern  constructs.  For  example, the sequence A+B is treated as
4101         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
4102         when B must follow.         when B must follow.
4103    
4104         When a pattern contains an unlimited repeat inside  a  subpattern  that         When  a  pattern  contains an unlimited repeat inside a subpattern that
4105         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
4106         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
4107         very long time indeed. The pattern         very long time indeed. The pattern
4108    
4109           (\D+|<\d+>)*[!?]           (\D+|<\d+>)*[!?]
4110    
4111         matches  an  unlimited number of substrings that either consist of non-         matches an unlimited number of substrings that either consist  of  non-
4112         digits, or digits enclosed in <>, followed by either ! or  ?.  When  it         digits,  or  digits  enclosed in <>, followed by either ! or ?. When it
4113         matches, it runs quickly. However, if it is applied to         matches, it runs quickly. However, if it is applied to
4114    
4115           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
4116    
4117         it  takes  a  long  time  before reporting failure. This is because the         it takes a long time before reporting  failure.  This  is  because  the
4118         string can be divided between the internal \D+ repeat and the  external         string  can be divided between the internal \D+ repeat and the external
4119         *  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
4120         example uses [!?] rather than a single character at  the  end,  because         example  uses  [!?]  rather than a single character at the end, because
4121         both  PCRE  and  Perl have an optimization that allows for fast failure         both PCRE and Perl have an optimization that allows  for  fast  failure
4122         when a single character is used. They remember the last single  charac-         when  a single character is used. They remember the last single charac-
4123         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
4124         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
4125         group, like this:         group, like this:
4126    
4127           ((?>\D+)|<\d+>)*[!?]           ((?>\D+)|<\d+>)*[!?]
4128    
4129         sequences  of non-digits cannot be broken, and failure happens quickly.         sequences of non-digits cannot be broken, and failure happens  quickly.
4130    
4131    
4132  BACK REFERENCES  BACK REFERENCES
4133    
4134         Outside a character class, a backslash followed by a digit greater than         Outside a character class, a backslash followed by a digit greater than
4135         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-
4136         pattern earlier (that is, to its left) in the pattern,  provided  there         pattern  earlier  (that is, to its left) in the pattern, provided there
4137         have been that many previous capturing left parentheses.         have been that many previous capturing left parentheses.
4138    
4139         However, if the decimal number following the backslash is less than 10,         However, if the decimal number following the backslash is less than 10,
4140         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
4141         there  are  not that many capturing left parentheses in the entire pat-         there are not that many capturing left parentheses in the  entire  pat-
4142         tern. In other words, the parentheses that are referenced need  not  be         tern.  In  other words, the parentheses that are referenced need not be
4143         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
4144         reference" of this type can make sense when a  repetition  is  involved         reference"  of  this  type can make sense when a repetition is involved
4145         and  the  subpattern to the right has participated in an earlier itera-         and the subpattern to the right has participated in an  earlier  itera-
4146         tion.         tion.
4147    
4148         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
4149         subpattern  whose  number  is  10  or  more using this syntax because a         subpattern whose number is 10 or  more  using  this  syntax  because  a
4150         sequence such as \50 is interpreted as a character  defined  in  octal.         sequence  such  as  \50 is interpreted as a character defined in octal.
4151         See the subsection entitled "Non-printing characters" above for further         See the subsection entitled "Non-printing characters" above for further
4152         details of the handling of digits following a backslash.  There  is  no         details  of  the  handling of digits following a backslash. There is no
4153         such  problem  when named parentheses are used. A back reference to any         such problem when named parentheses are used. A back reference  to  any
4154         subpattern is possible using named parentheses (see below).         subpattern is possible using named parentheses (see below).
4155    
4156         Another way of avoiding the ambiguity inherent in  the  use  of  digits         Another  way  of  avoiding  the ambiguity inherent in the use of digits
4157         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-
4158         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
4159         unsigned  number  or  a negative number, optionally enclosed in braces.         unsigned number or a negative number, optionally  enclosed  in  braces.
4160         These examples are all identical:         These examples are all identical:
4161    
4162           (ring), \1           (ring), \1
4163           (ring), \g1           (ring), \g1
4164           (ring), \g{1}           (ring), \g{1}
4165    
4166         An unsigned number specifies an absolute reference without the  ambigu-         An  unsigned number specifies an absolute reference without the ambigu-
4167         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
4168         digits follow the reference. A negative number is a relative reference.         digits follow the reference. A negative number is a relative reference.
4169         Consider this example:         Consider this example:
# Line 4020  BACK REFERENCES Line 4171  BACK REFERENCES
4171           (abc(def)ghi)\g{-1}           (abc(def)ghi)\g{-1}
4172    
4173         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-
4174         ing subpattern before \g, that is, is it equivalent to  \2.  Similarly,         ing  subpattern  before \g, that is, is it equivalent to \2. Similarly,
4175         \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
4176         helpful in long patterns, and also in  patterns  that  are  created  by         helpful  in  long  patterns,  and  also in patterns that are created by
4177         joining together fragments that contain references within themselves.         joining together fragments that contain references within themselves.
4178    
4179         A  back  reference matches whatever actually matched the capturing sub-         A back reference matches whatever actually matched the  capturing  sub-
4180         pattern in the current subject string, rather  than  anything  matching         pattern  in  the  current subject string, rather than anything matching
4181         the subpattern itself (see "Subpatterns as subroutines" below for a way         the subpattern itself (see "Subpatterns as subroutines" below for a way
4182         of doing that). So the pattern         of doing that). So the pattern
4183    
4184           (sens|respons)e and \1ibility           (sens|respons)e and \1ibility
4185    
4186         matches "sense and sensibility" and "response and responsibility",  but         matches  "sense and sensibility" and "response and responsibility", but
4187         not  "sense and responsibility". If caseful matching is in force at the         not "sense and responsibility". If caseful matching is in force at  the
4188         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-
4189         ple,         ple,
4190    
4191           ((?i)rah)\s+\1           ((?i)rah)\s+\1
4192    
4193         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
4194         original capturing subpattern is matched caselessly.         original capturing subpattern is matched caselessly.
4195    
4196         There are several different ways of writing back  references  to  named         There  are  several  different ways of writing back references to named
4197         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
4198         \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
4199         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
4200         and named references, is also supported. We  could  rewrite  the  above         and  named  references,  is  also supported. We could rewrite the above
4201         example in any of the following ways:         example in any of the following ways:
4202    
4203           (?<p1>(?i)rah)\s+\k<p1>           (?<p1>(?i)rah)\s+\k<p1>
# Line 4054  BACK REFERENCES Line 4205  BACK REFERENCES
4205           (?P<p1>(?i)rah)\s+(?P=p1)           (?P<p1>(?i)rah)\s+(?P=p1)
4206           (?<p1>(?i)rah)\s+\g{p1}           (?<p1>(?i)rah)\s+\g{p1}
4207    
4208         A  subpattern  that  is  referenced  by  name may appear in the pattern         A subpattern that is referenced by  name  may  appear  in  the  pattern
4209         before or after the reference.         before or after the reference.
4210    
4211         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
4212         subpattern  has  not actually been used in a particular match, any back         subpattern has not actually been used in a particular match,  any  back
4213         references to it always fail. For example, the pattern         references to it always fail. For example, the pattern
4214    
4215           (a|(bc))\2           (a|(bc))\2
4216    
4217         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
4218         may  be  many  capturing parentheses in a pattern, all digits following         may be many capturing parentheses in a pattern,  all  digits  following
4219         the backslash are taken as part of a potential back  reference  number.         the  backslash  are taken as part of a potential back reference number.
4220         If the pattern continues with a digit character, some delimiter must be         If the pattern continues with a digit character, some delimiter must be
4221         used to terminate the back reference. If the  PCRE_EXTENDED  option  is         used  to  terminate  the back reference. If the PCRE_EXTENDED option is
4222         set,  this  can  be  whitespace.  Otherwise an empty comment (see "Com-         set, this can be whitespace.  Otherwise an  empty  comment  (see  "Com-
4223         ments" below) can be used.         ments" below) can be used.
4224    
4225         A back reference that occurs inside the parentheses to which it  refers         A  back reference that occurs inside the parentheses to which it refers
4226         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
4227         matches.  However, such references can be useful inside  repeated  sub-         matches.   However,  such references can be useful inside repeated sub-
4228         patterns. For example, the pattern         patterns. For example, the pattern
4229    
4230           (a|b\1)+           (a|b\1)+
4231    
4232         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-
4233         ation of the subpattern,  the  back  reference  matches  the  character         ation  of  the  subpattern,  the  back  reference matches the character
4234         string  corresponding  to  the previous iteration. In order for this to         string corresponding to the previous iteration. In order  for  this  to
4235         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
4236         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
4237         the example above, or by a quantifier with a minimum of zero.         the example above, or by a quantifier with a minimum of zero.
4238    
4239    
4240  ASSERTIONS  ASSERTIONS
4241    
4242         An assertion is a test on the characters  following  or  preceding  the         An  assertion  is  a  test on the characters following or preceding the
4243         current  matching  point that does not actually consume any characters.         current matching point that does not actually consume  any  characters.
4244         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
4245         described above.         described above.
4246    
4247         More  complicated  assertions  are  coded as subpatterns. There are two         More complicated assertions are coded as  subpatterns.  There  are  two
4248         kinds: those that look ahead of the current  position  in  the  subject         kinds:  those  that  look  ahead of the current position in the subject
4249         string,  and  those  that  look  behind  it. An assertion subpattern is         string, and those that look  behind  it.  An  assertion  subpattern  is
4250         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
4251         matching position to be changed.         matching position to be changed.
4252    
4253         Assertion  subpatterns  are  not  capturing subpatterns, and may not be         Assertion subpatterns are not capturing subpatterns,  and  may  not  be
4254         repeated, because it makes no sense to assert the  same  thing  several         repeated,  because  it  makes no sense to assert the same thing several
4255         times.  If  any kind of assertion contains capturing subpatterns within         times. If any kind of assertion contains capturing  subpatterns  within
4256         it, these are counted for the purposes of numbering the capturing  sub-         it,  these are counted for the purposes of numbering the capturing sub-
4257         patterns in the whole pattern.  However, substring capturing is carried         patterns in the whole pattern.  However, substring capturing is carried
4258         out only for positive assertions, because it does not  make  sense  for         out  only  for  positive assertions, because it does not make sense for
4259         negative assertions.         negative assertions.
4260    
4261     Lookahead assertions     Lookahead assertions
# Line 4114  ASSERTIONS Line 4265  ASSERTIONS
4265    
4266           \w+(?=;)           \w+(?=;)
4267    
4268         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-
4269         colon in the match, and         colon in the match, and
4270    
4271           foo(?!bar)           foo(?!bar)
4272    
4273         matches  any  occurrence  of  "foo" that is not followed by "bar". Note         matches any occurrence of "foo" that is not  followed  by  "bar".  Note
4274         that the apparently similar pattern         that the apparently similar pattern
4275    
4276           (?!foo)bar           (?!foo)bar
4277    
4278         does not find an occurrence of "bar"  that  is  preceded  by  something         does  not  find  an  occurrence  of "bar" that is preceded by something
4279         other  than "foo"; it finds any occurrence of "bar" whatsoever, because         other than "foo"; it finds any occurrence of "bar" whatsoever,  because
4280         the assertion (?!foo) is always true when the next three characters are         the assertion (?!foo) is always true when the next three characters are
4281         "bar". A lookbehind assertion is needed to achieve the other effect.         "bar". A lookbehind assertion is needed to achieve the other effect.
4282    
4283         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
4284         most convenient way to do it is  with  (?!)  because  an  empty  string         most  convenient  way  to  do  it  is with (?!) because an empty string
4285         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
4286         string must always fail.         string must always fail.
4287    
4288     Lookbehind assertions     Lookbehind assertions
4289    
4290         Lookbehind assertions start with (?<= for positive assertions and  (?<!         Lookbehind  assertions start with (?<= for positive assertions and (?<!
4291         for negative assertions. For example,         for negative assertions. For example,
4292    
4293           (?<!foo)bar           (?<!foo)bar
4294    
4295         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
4296         contents of a lookbehind assertion are restricted  such  that  all  the         contents  of  a  lookbehind  assertion are restricted such that all the
4297         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-
4298         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
4299         fixed length. Thus         fixed length. Thus
4300    
4301           (?<=bullock|donkey)           (?<=bullock|donkey)
# Line 4153  ASSERTIONS Line 4304  ASSERTIONS
4304    
4305           (?<!dogs?|cats?)           (?<!dogs?|cats?)
4306    
4307         causes  an  error at compile time. Branches that match different length         causes an error at compile time. Branches that match  different  length
4308         strings are permitted only at the top level of a lookbehind  assertion.         strings  are permitted only at the top level of a lookbehind assertion.
4309         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
4310         requires all branches to match the same length of string. An  assertion         requires  all branches to match the same length of string. An assertion
4311         such as         such as
4312    
4313           (?<=ab(c|de))           (?<=ab(c|de))
4314    
4315         is  not  permitted,  because  its single top-level branch can match two         is not permitted, because its single top-level  branch  can  match  two
4316         different lengths, but it is acceptable if rewritten to  use  two  top-         different  lengths,  but  it is acceptable if rewritten to use two top-
4317         level branches:         level branches:
4318    
4319           (?<=abc|abde)           (?<=abc|abde)
4320    
4321         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
4322         instead of a lookbehind assertion; this is not restricted to  a  fixed-         instead  of  a lookbehind assertion; this is not restricted to a fixed-
4323         length.         length.
4324    
4325         The  implementation  of lookbehind assertions is, for each alternative,         The implementation of lookbehind assertions is, for  each  alternative,
4326         to temporarily move the current position back by the fixed  length  and         to  temporarily  move the current position back by the fixed length and
4327         then try to match. If there are insufficient characters before the cur-         then try to match. If there are insufficient characters before the cur-
4328         rent position, the assertion fails.         rent position, the assertion fails.
4329    
4330         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
4331         mode)  to appear in lookbehind assertions, because it makes it impossi-         mode) to appear in lookbehind assertions, because it makes it  impossi-
4332         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,
4333         which can match different numbers of bytes, are also not permitted.         which can match different numbers of bytes, are also not permitted.
4334    
4335         Possessive  quantifiers  can  be  used  in  conjunction with lookbehind         Possessive quantifiers can  be  used  in  conjunction  with  lookbehind
4336         assertions to specify efficient matching at  the  end  of  the  subject         assertions  to  specify  efficient  matching  at the end of the subject
4337         string. Consider a simple pattern such as         string. Consider a simple pattern such as
4338    
4339           abcd$           abcd$
4340    
4341         when  applied  to  a  long string that does not match. Because matching         when applied to a long string that does  not  match.  Because  matching
4342         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
4343         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
4344         pattern is specified as         pattern is specified as
4345    
4346           ^.*abcd$           ^.*abcd$
4347    
4348         the initial .* matches the entire string at first, but when this  fails         the  initial .* matches the entire string at first, but when this fails
4349         (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
4350         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
4351         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,
4352         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
4353    
4354           ^.*+(?<=abcd)           ^.*+(?<=abcd)
4355    
4356         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
4357         entire  string.  The subsequent lookbehind assertion does a single test         entire string. The subsequent lookbehind assertion does a  single  test
4358         on the last four characters. If it fails, the match fails  immediately.         on  the last four characters. If it fails, the match fails immediately.
4359         For  long  strings, this approach makes a significant difference to the         For long strings, this approach makes a significant difference  to  the
4360         processing time.         processing time.
4361    
4362     Using multiple assertions     Using multiple assertions
# Line 4214  ASSERTIONS Line 4365  ASSERTIONS
4365    
4366           (?<=\d{3})(?<!999)foo           (?<=\d{3})(?<!999)foo
4367    
4368         matches "foo" preceded by three digits that are not "999". Notice  that         matches  "foo" preceded by three digits that are not "999". Notice that
4369         each  of  the  assertions is applied independently at the same point in         each of the assertions is applied independently at the  same  point  in
4370         the subject string. First there is a  check  that  the  previous  three         the  subject  string.  First  there  is a check that the previous three
4371         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
4372         three characters are not "999".  This pattern does not match "foo" pre-         three characters are not "999".  This pattern does not match "foo" pre-
4373         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
4374         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-
4375         foo". A pattern to do that is         foo". A pattern to do that is
4376    
4377           (?<=\d{3}...)(?<!999)foo           (?<=\d{3}...)(?<!999)foo
4378    
4379         This  time  the  first assertion looks at the preceding six characters,         This time the first assertion looks at the  preceding  six  characters,
4380         checking that the first three are digits, and then the second assertion         checking that the first three are digits, and then the second assertion
4381         checks that the preceding three characters are not "999".         checks that the preceding three characters are not "999".
4382    
# Line 4233  ASSERTIONS Line 4384  ASSERTIONS
4384    
4385           (?<=(?<!foo)bar)baz           (?<=(?<!foo)bar)baz
4386    
4387         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
4388         is not preceded by "foo", while         is not preceded by "foo", while
4389    
4390           (?<=\d{3}(?!999)...)foo           (?<=\d{3}(?!999)...)foo
4391    
4392         is another pattern that matches "foo" preceded by three digits and  any         is  another pattern that matches "foo" preceded by three digits and any
4393         three characters that are not "999".         three characters that are not "999".
4394    
4395    
4396  CONDITIONAL SUBPATTERNS  CONDITIONAL SUBPATTERNS
4397    
4398         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-
4399         ditionally or to choose between two alternative subpatterns,  depending         ditionally  or to choose between two alternative subpatterns, depending
4400         on  the result of an assertion, or whether a previous capturing subpat-         on the result of an assertion, or whether a previous capturing  subpat-
4401         tern matched or not. The two possible forms of  conditional  subpattern         tern  matched  or not. The two possible forms of conditional subpattern
4402         are         are
4403    
4404           (?(condition)yes-pattern)           (?(condition)yes-pattern)
4405           (?(condition)yes-pattern|no-pattern)           (?(condition)yes-pattern|no-pattern)
4406    
4407         If  the  condition is satisfied, the yes-pattern is used; otherwise the         If the condition is satisfied, the yes-pattern is used;  otherwise  the
4408         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-
4409         tives in the subpattern, a compile-time error occurs.         tives in the subpattern, a compile-time error occurs.
4410    
4411         There  are  four  kinds of condition: references to subpatterns, refer-         There are four kinds of condition: references  to  subpatterns,  refer-
4412         ences to recursion, a pseudo-condition called DEFINE, and assertions.         ences to recursion, a pseudo-condition called DEFINE, and assertions.
4413    
4414     Checking for a used subpattern by number     Checking for a used subpattern by number
4415    
4416         If the text between the parentheses consists of a sequence  of  digits,         If  the  text between the parentheses consists of a sequence of digits,
4417         the  condition  is  true if the capturing subpattern of that number has         the condition is true if the capturing subpattern of  that  number  has
4418         previously matched. An alternative notation is to  precede  the  digits         previously  matched.  An  alternative notation is to precede the digits
4419         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-
4420         tive rather than absolute.  The most recently opened parentheses can be         tive rather than absolute.  The most recently opened parentheses can be
4421         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
4422         looping constructs it can also make sense to refer to subsequent groups         looping constructs it can also make sense to refer to subsequent groups
4423         with constructs such as (?(+2).         with constructs such as (?(+2).
4424    
4425         Consider  the  following  pattern, which contains non-significant white         Consider the following pattern, which  contains  non-significant  white
4426         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
4427         divide it into three parts for ease of discussion:         divide it into three parts for ease of discussion:
4428    
4429           ( \( )?    [^()]+    (?(1) \) )           ( \( )?    [^()]+    (?(1) \) )
4430    
4431         The  first  part  matches  an optional opening parenthesis, and if that         The first part matches an optional opening  parenthesis,  and  if  that
4432         character is present, sets it as the first captured substring. The sec-         character is present, sets it as the first captured substring. The sec-
4433         ond  part  matches one or more characters that are not parentheses. The         ond part matches one or more characters that are not  parentheses.  The
4434         third part is a conditional subpattern that tests whether the first set         third part is a conditional subpattern that tests whether the first set
4435         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
4436         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-
4437         tern  is  executed  and  a  closing parenthesis is required. Otherwise,         tern is executed and a  closing  parenthesis  is  required.  Otherwise,
4438         since no-pattern is not present, the  subpattern  matches  nothing.  In         since  no-pattern  is  not  present, the subpattern matches nothing. In
4439         other  words,  this  pattern  matches  a  sequence  of non-parentheses,         other words,  this  pattern  matches  a  sequence  of  non-parentheses,
4440         optionally enclosed in parentheses.         optionally enclosed in parentheses.
4441    
4442         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
4443         relative reference:         relative reference:
4444    
4445           ...other stuff... ( \( )?    [^()]+    (?(-1) \) ) ...           ...other stuff... ( \( )?    [^()]+    (?(-1) \) ) ...
4446    
4447         This  makes  the  fragment independent of the parentheses in the larger         This makes the fragment independent of the parentheses  in  the  larger
4448         pattern.         pattern.
4449    
4450     Checking for a used subpattern by name     Checking for a used subpattern by name
4451    
4452         Perl uses the syntax (?(<name>)...) or (?('name')...)  to  test  for  a         Perl  uses  the  syntax  (?(<name>)...) or (?('name')...) to test for a
4453         used  subpattern  by  name.  For compatibility with earlier versions of         used subpattern by name. For compatibility  with  earlier  versions  of
4454         PCRE, which had this facility before Perl, the syntax  (?(name)...)  is         PCRE,  which  had this facility before Perl, the syntax (?(name)...) is
4455         also  recognized. However, there is a possible ambiguity with this syn-         also recognized. However, there is a possible ambiguity with this  syn-
4456         tax, because subpattern names may  consist  entirely  of  digits.  PCRE         tax,  because  subpattern  names  may  consist entirely of digits. PCRE
4457         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
4458         consists entirely of digits, PCRE looks for a subpattern of  that  num-         consists  entirely  of digits, PCRE looks for a subpattern of that num-
4459         ber,  which must be greater than zero. Using subpattern names that con-         ber, which must be greater than zero. Using subpattern names that  con-
4460         sist entirely of digits is not recommended.         sist entirely of digits is not recommended.
4461    
4462         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 4467  CONDITIONAL SUBPATTERNS
4467     Checking for pattern recursion     Checking for pattern recursion
4468    
4469         If the condition is the string (R), and there is no subpattern with the         If t