/[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 1319 by ph10, Fri Mar 22 16:13:13 2013 UTC revision 1320 by ph10, Wed May 1 16:39:35 2013 UTC
# Line 106  SECURITY CONSIDERATIONS Line 106  SECURITY CONSIDERATIONS
106         ciently many resources as to cause your  application  to  lose  perfor-         ciently many resources as to cause your  application  to  lose  perfor-
107         mance.         mance.
108    
109         The  best  way  of  guarding  against  this  possibility  is to use the         One   way   of   guarding  against  this  possibility  is  to  use  the
110         pcre_fullinfo() function to check the compiled  pattern's  options  for         pcre_fullinfo() function to check the compiled  pattern's  options  for
111         UTF.         UTF.   Alternatively, from release 8.33, you can set the PCRE_NEVER_UTF
112           option at compile time. This causes an compile time error if a  pattern
113           contains a UTF-setting sequence.
114    
115         If  your  application  is one that supports UTF, be aware that validity         If  your  application  is one that supports UTF, be aware that validity
116         checking can take time. If the same data string is to be  matched  many         checking can take time. If the same data string is to be  matched  many
# Line 174  AUTHOR Line 176  AUTHOR
176    
177  REVISION  REVISION
178    
179         Last updated: 11 November 2012         Last updated: 26 April 2013
180         Copyright (c) 1997-2012 University of Cambridge.         Copyright (c) 1997-2013 University of Cambridge.
181  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
182    
183    
# Line 2204  COMPILING A PATTERN Line 2206  COMPILING A PATTERN
2206         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,
2207         setting PCRE_MULTILINE has no effect.         setting PCRE_MULTILINE has no effect.
2208    
2209             PCRE_NEVER_UTF
2210    
2211           This option locks out interpretation of the pattern as UTF-8 (or UTF-16
2212           or  UTF-32  in the 16-bit and 32-bit libraries). In particular, it pre-
2213           vents the creator of the pattern from switching to  UTF  interpretation
2214           by starting the pattern with (*UTF). This may be useful in applications
2215           that  process  patterns  from  external  sources.  The  combination  of
2216           PCRE_UTF8 and PCRE_NEVER_UTF also causes an error.
2217    
2218           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
2219           PCRE_NEWLINE_LF           PCRE_NEWLINE_LF
2220           PCRE_NEWLINE_CRLF           PCRE_NEWLINE_CRLF
2221           PCRE_NEWLINE_ANYCRLF           PCRE_NEWLINE_ANYCRLF
2222           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
2223    
2224         These options override the default newline definition that  was  chosen         These  options  override the default newline definition that was chosen
2225         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
2226         newline is indicated by a single character (CR  or  LF,  respectively).         newline  is  indicated  by a single character (CR or LF, respectively).
2227         Setting  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the         Setting PCRE_NEWLINE_CRLF specifies that a newline is indicated by  the
2228         two-character CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF  specifies         two-character  CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF specifies
2229         that any of the three preceding sequences should be recognized. Setting         that any of the three preceding sequences should be recognized. Setting
2230         PCRE_NEWLINE_ANY specifies that any Unicode newline sequence should  be         PCRE_NEWLINE_ANY  specifies that any Unicode newline sequence should be
2231         recognized.         recognized.
2232    
2233         In  an ASCII/Unicode environment, the Unicode newline sequences are the         In an ASCII/Unicode environment, the Unicode newline sequences are  the
2234         three just mentioned, plus the  single  characters  VT  (vertical  tab,         three  just  mentioned,  plus  the  single characters VT (vertical tab,
2235         U+000B), FF (form feed, U+000C), NEL (next line, U+0085), LS (line sep-         U+000B), FF (form feed, U+000C), NEL (next line, U+0085), LS (line sep-
2236         arator, U+2028), and PS (paragraph separator, U+2029).  For  the  8-bit         arator,  U+2028),  and  PS (paragraph separator, U+2029). For the 8-bit
2237         library, the last two are recognized only in UTF-8 mode.         library, the last two are recognized only in UTF-8 mode.
2238    
2239         When  PCRE is compiled to run in an EBCDIC (mainframe) environment, the         When PCRE is compiled to run in an EBCDIC (mainframe) environment,  the
2240         code for CR is 0x0d, the same as ASCII. However, the character code for         code for CR is 0x0d, the same as ASCII. However, the character code for
2241         LF  is  normally 0x15, though in some EBCDIC environments 0x25 is used.         LF is normally 0x15, though in some EBCDIC environments 0x25  is  used.
2242         Whichever of these is not LF is made to  correspond  to  Unicode's  NEL         Whichever  of  these  is  not LF is made to correspond to Unicode's NEL
2243         character.  EBCDIC  codes  are all less than 256. For more details, see         character. EBCDIC codes are all less than 256. For  more  details,  see
2244         the pcrebuild documentation.         the pcrebuild documentation.
2245    
2246         The newline setting in the  options  word  uses  three  bits  that  are         The  newline  setting  in  the  options  word  uses three bits that are
2247         treated as a number, giving eight possibilities. Currently only six are         treated as a number, giving eight possibilities. Currently only six are
2248         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
2249         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-
2250         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
2251         PCRE_NEWLINE_CRLF,  but other combinations may yield unused numbers and         PCRE_NEWLINE_CRLF, but other combinations may yield unused numbers  and
2252         cause an error.         cause an error.
2253    
2254         The only time that a line break in a pattern  is  specially  recognized         The  only  time  that a line break in a pattern is specially recognized
2255         when  compiling is when PCRE_EXTENDED is set. CR and LF are white space         when compiling is when PCRE_EXTENDED is set. CR and LF are white  space
2256         characters, and so are ignored in this mode. Also, an unescaped #  out-         characters,  and so are ignored in this mode. Also, an unescaped # out-
2257         side  a  character class indicates a comment that lasts until after the         side a character class indicates a comment that lasts until  after  the
2258         next line break sequence. In other circumstances, line break  sequences         next  line break sequence. In other circumstances, line break sequences
2259         in patterns are treated as literal data.         in patterns are treated as literal data.
2260    
2261         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
# Line 2253  COMPILING A PATTERN Line 2264  COMPILING A PATTERN
2264           PCRE_NO_AUTO_CAPTURE           PCRE_NO_AUTO_CAPTURE
2265    
2266         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-
2267         theses  in the pattern. Any opening parenthesis that is not followed by         theses in the pattern. Any opening parenthesis that is not followed  by
2268         ? behaves as if it were followed by ?: but named parentheses can  still         ?  behaves as if it were followed by ?: but named parentheses can still
2269         be  used  for  capturing  (and  they acquire numbers in the usual way).         be used for capturing (and they acquire  numbers  in  the  usual  way).
2270         There is no equivalent of this option in Perl.         There is no equivalent of this option in Perl.
2271    
2272           NO_START_OPTIMIZE           PCRE_NO_START_OPTIMIZE
2273    
2274         This is an option that acts at matching time; that is, it is really  an         This  is an option that acts at matching time; that is, it is really an
2275         option  for  pcre_exec()  or  pcre_dfa_exec().  If it is set at compile         option for pcre_exec() or pcre_dfa_exec(). If  it  is  set  at  compile
2276         time, it is remembered with the compiled pattern and assumed at  match-         time,  it is remembered with the compiled pattern and assumed at match-
2277         ing  time.  For  details  see  the discussion of PCRE_NO_START_OPTIMIZE         ing time. This is necessary if you want to use JIT  execution,  because
2278         below.         the  JIT  compiler needs to know whether or not this option is set. For
2279           details see the discussion of PCRE_NO_START_OPTIMIZE below.
2280    
2281           PCRE_UCP           PCRE_UCP
2282    
# Line 2379  COMPILATION ERROR CODES Line 2391  COMPILATION ERROR CODES
2391                 name/number or by a plain number                 name/number or by a plain number
2392           58  a numbered reference must not be zero           58  a numbered reference must not be zero
2393           59  an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)           59  an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)
2394           60  (*VERB) not recognized           60  (*VERB) not recognized or malformed
2395           61  number is too big           61  number is too big
2396           62  subpattern name expected           62  subpattern name expected
2397           63  digit expected after (?+           63  digit expected after (?+
# Line 2500  STUDYING A PATTERN Line 2512  STUDYING A PATTERN
2512    
2513         These two optimizations apply to both pcre_exec() and  pcre_dfa_exec(),         These two optimizations apply to both pcre_exec() and  pcre_dfa_exec(),
2514         and  the  information  is also used by the JIT compiler.  The optimiza-         and  the  information  is also used by the JIT compiler.  The optimiza-
2515         tions can be disabled by setting the PCRE_NO_START_OPTIMIZE option when         tions can be disabled by  setting  the  PCRE_NO_START_OPTIMIZE  option.
2516         calling pcre_exec() or pcre_dfa_exec(), but if this is done, JIT execu-         You  might want to do this if your pattern contains callouts or (*MARK)
2517         tion is also disabled. You might want to do this if your  pattern  con-         and you want to make use of these facilities in  cases  where  matching
2518         tains  callouts or (*MARK) and you want to make use of these facilities         fails.
2519         in   cases   where   matching   fails.   See    the    discussion    of  
2520         PCRE_NO_START_OPTIMIZE below.         PCRE_NO_START_OPTIMIZE  can be specified at either compile time or exe-
2521           cution  time.  However,  if   PCRE_NO_START_OPTIMIZE   is   passed   to
2522           pcre_exec(), (that is, after any JIT compilation has happened) JIT exe-
2523           cution is disabled. For JIT execution to work with  PCRE_NO_START_OPTI-
2524           MIZE, the option must be set at compile time.
2525    
2526           There is a longer discussion of PCRE_NO_START_OPTIMIZE below.
2527    
2528    
2529  LOCALE SUPPORT  LOCALE SUPPORT
# Line 2588  INFORMATION ABOUT A PATTERN Line 2606  INFORMATION ABOUT A PATTERN
2606           PCRE_ERROR_BADENDIANNESS  the pattern was compiled with different           PCRE_ERROR_BADENDIANNESS  the pattern was compiled with different
2607                                     endianness                                     endianness
2608           PCRE_ERROR_BADOPTION      the value of what was invalid           PCRE_ERROR_BADOPTION      the value of what was invalid
2609             PCRE_ERROR_UNSET          the requested field is not set
2610    
2611         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
2612         an simple check against passing an arbitrary memory pointer. The  endi-         an simple check against passing an arbitrary memory pointer. The  endi-
# Line 2707  INFORMATION ABOUT A PATTERN Line 2726  INFORMATION ABOUT A PATTERN
2726         is   deprecated;   instead    the    PCRE_INFO_REQUIREDCHARFLAGS    and         is   deprecated;   instead    the    PCRE_INFO_REQUIREDCHARFLAGS    and
2727         PCRE_INFO_REQUIREDCHAR values should be used.         PCRE_INFO_REQUIREDCHAR values should be used.
2728    
2729             PCRE_INFO_MATCHLIMIT
2730    
2731           If  the  pattern  set  a  match  limit by including an item of the form
2732           (*LIMIT_MATCH=nnnn) at the start, the value  is  returned.  The  fourth
2733           argument  should  point to an unsigned 32-bit integer. If no such value
2734           has  been  set,  the  call  to  pcre_fullinfo()   returns   the   error
2735           PCRE_ERROR_UNSET.
2736    
2737           PCRE_INFO_MAXLOOKBEHIND           PCRE_INFO_MAXLOOKBEHIND
2738    
2739         Return  the  number of characters (NB not bytes) in the longest lookbe-         Return  the  number of characters (NB not bytes) in the longest lookbe-
# Line 2820  INFORMATION ABOUT A PATTERN Line 2847  INFORMATION ABOUT A PATTERN
2847         For such patterns, the PCRE_ANCHORED bit is set in the options returned         For such patterns, the PCRE_ANCHORED bit is set in the options returned
2848         by pcre_fullinfo().         by pcre_fullinfo().
2849    
2850             PCRE_INFO_RECURSIONLIMIT
2851    
2852           If the pattern set a recursion limit by including an item of  the  form
2853           (*LIMIT_RECURSION=nnnn) at the start, the value is returned. The fourth
2854           argument should point to an unsigned 32-bit integer. If no  such  value
2855           has   been   set,   the  call  to  pcre_fullinfo()  returns  the  error
2856           PCRE_ERROR_UNSET.
2857    
2858           PCRE_INFO_SIZE           PCRE_INFO_SIZE
2859    
2860         Return the size of the compiled pattern in bytes (for both  libraries).         Return the size of the compiled pattern in bytes (for both  libraries).
# Line 3036  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 3071  MATCHING A PATTERN: THE TRADITIONAL FUNC
3071         PCRE_EXTRA_MATCH_LIMIT is set in the  flags  field.  If  the  limit  is         PCRE_EXTRA_MATCH_LIMIT is set in the  flags  field.  If  the  limit  is
3072         exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT.         exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT.
3073    
3074         The  match_limit_recursion field is similar to match_limit, but instead         A  value  for  the  match  limit may also be supplied by an item at the
3075           start of a pattern of the form
3076    
3077             (*LIMIT_MATCH=d)
3078    
3079           where d is a decimal number. However, such a setting is ignored  unless
3080           d  is  less  than  the limit set by the caller of pcre_exec() or, if no
3081           such limit is set, less than the default.
3082    
3083           The match_limit_recursion field is similar to match_limit, but  instead
3084         of limiting the total number of times that match() is called, it limits         of limiting the total number of times that match() is called, it limits
3085         the  depth  of  recursion. The recursion depth is a smaller number than         the depth of recursion. The recursion depth is a  smaller  number  than
3086         the total number of calls, because not all calls to match() are  recur-         the  total number of calls, because not all calls to match() are recur-
3087         sive.  This limit is of use only if it is set smaller than match_limit.         sive.  This limit is of use only if it is set smaller than match_limit.
3088    
3089         Limiting  the  recursion  depth limits the amount of machine stack that         Limiting the recursion depth limits the amount of  machine  stack  that
3090         can be used, or, when PCRE has been compiled to use memory on the  heap         can  be used, or, when PCRE has been compiled to use memory on the heap
3091         instead  of the stack, the amount of heap memory that can be used. This         instead of the stack, the amount of heap memory that can be used.  This
3092         limit is not relevant, and is ignored, when matching is done using  JIT         limit  is not relevant, and is ignored, when matching is done using JIT
3093         compiled code.         compiled code.
3094    
3095         The  default  value  for  match_limit_recursion can be set when PCRE is         The default value for match_limit_recursion can be  set  when  PCRE  is
3096         built; the default default  is  the  same  value  as  the  default  for         built;  the  default  default  is  the  same  value  as the default for
3097         match_limit.  You can override the default by suppling pcre_exec() with         match_limit. You can override the default by suppling pcre_exec()  with
3098         a  pcre_extra  block  in  which  match_limit_recursion  is   set,   and         a   pcre_extra   block  in  which  match_limit_recursion  is  set,  and
3099         PCRE_EXTRA_MATCH_LIMIT_RECURSION  is  set  in  the  flags field. If the         PCRE_EXTRA_MATCH_LIMIT_RECURSION is set in  the  flags  field.  If  the
3100         limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT.         limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT.
3101    
3102           A  value for the recursion limit may also be supplied by an item at the
3103           start of a pattern of the form
3104    
3105             (*LIMIT_RECURSION=d)
3106    
3107           where d is a decimal number. However, such a setting is ignored  unless
3108           d  is  less  than  the limit set by the caller of pcre_exec() or, if no
3109           such limit is set, less than the default.
3110    
3111         The callout_data field is used in conjunction with the  "callout"  fea-         The callout_data field is used in conjunction with the  "callout"  fea-
3112         ture, and is described in the pcrecallout documentation.         ture, and is described in the pcrecallout documentation.
3113    
# Line 3207  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 3260  MATCHING A PATTERN: THE TRADITIONAL FUNC
3260         cannot find it, without actually running the  main  matching  function.         cannot find it, without actually running the  main  matching  function.
3261         This means that a special item such as (*COMMIT) at the start of a pat-         This means that a special item such as (*COMMIT) at the start of a pat-
3262         tern is not considered until after a suitable starting  point  for  the         tern is not considered until after a suitable starting  point  for  the
3263         match  has been found. When callouts or (*MARK) items are in use, these         match  has been found. Also, when callouts or (*MARK) items are in use,
3264         "start-up" optimizations can cause them to be skipped if the pattern is         these "start-up" optimizations can cause them to be skipped if the pat-
3265         never  actually  used.  The start-up optimizations are in effect a pre-         tern is never actually used. The start-up optimizations are in effect a
3266         scan of the subject that takes place before the pattern is run.         pre-scan of the subject that takes place before the pattern is run.
3267    
3268         The PCRE_NO_START_OPTIMIZE option disables the start-up  optimizations,         The PCRE_NO_START_OPTIMIZE option disables the start-up  optimizations,
3269         possibly  causing  performance  to  suffer,  but ensuring that in cases         possibly  causing  performance  to  suffer,  but ensuring that in cases
# Line 3218  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 3271  MATCHING A PATTERN: THE TRADITIONAL FUNC
3271         such as (*COMMIT) and (*MARK) are considered at every possible starting         such as (*COMMIT) and (*MARK) are considered at every possible starting
3272         position in the subject string. If  PCRE_NO_START_OPTIMIZE  is  set  at         position in the subject string. If  PCRE_NO_START_OPTIMIZE  is  set  at
3273         compile  time,  it  cannot  be  unset  at  matching  time.  The  use of         compile  time,  it  cannot  be  unset  at  matching  time.  The  use of
3274         PCRE_NO_START_OPTIMIZE disables JIT execution; when it is set, matching         PCRE_NO_START_OPTIMIZE  at  matching  time  (that  is,  passing  it  to
3275         is always done using interpretively.         pcre_exec())  disables  JIT  execution;  in this situation, matching is
3276           always done using interpretively.
3277    
3278         Setting  PCRE_NO_START_OPTIMIZE  can  change  the outcome of a matching         Setting PCRE_NO_START_OPTIMIZE can change the  outcome  of  a  matching
3279         operation.  Consider the pattern         operation.  Consider the pattern
3280    
3281           (*COMMIT)ABC           (*COMMIT)ABC
3282    
3283         When this is compiled, PCRE records the fact that a  match  must  start         When  this  is  compiled, PCRE records the fact that a match must start
3284         with  the  character  "A".  Suppose the subject string is "DEFABC". The         with the character "A". Suppose the subject  string  is  "DEFABC".  The
3285         start-up optimization scans along the subject, finds "A" and  runs  the         start-up  optimization  scans along the subject, finds "A" and runs the
3286         first  match attempt from there. The (*COMMIT) item means that the pat-         first match attempt from there. The (*COMMIT) item means that the  pat-
3287         tern must match the current starting position, which in this  case,  it         tern  must  match the current starting position, which in this case, it
3288         does.  However,  if  the  same match is run with PCRE_NO_START_OPTIMIZE         does. However, if the same match  is  run  with  PCRE_NO_START_OPTIMIZE
3289         set, the initial scan along the subject string  does  not  happen.  The         set,  the  initial  scan  along the subject string does not happen. The
3290         first  match  attempt  is  run  starting  from "D" and when this fails,         first match attempt is run starting  from  "D"  and  when  this  fails,
3291         (*COMMIT) prevents any further matches  being  tried,  so  the  overall         (*COMMIT)  prevents  any  further  matches  being tried, so the overall
3292         result  is  "no  match". If the pattern is studied, more start-up opti-         result is "no match". If the pattern is studied,  more  start-up  opti-
3293         mizations may be used. For example, a minimum length  for  the  subject         mizations  may  be  used. For example, a minimum length for the subject
3294         may be recorded. Consider the pattern         may be recorded. Consider the pattern
3295    
3296           (*MARK:A)(X|Y)           (*MARK:A)(X|Y)
3297    
3298         The  minimum  length  for  a  match is one character. If the subject is         The minimum length for a match is one  character.  If  the  subject  is
3299         "ABC", there will be attempts to  match  "ABC",  "BC",  "C",  and  then         "ABC",  there  will  be  attempts  to  match "ABC", "BC", "C", and then
3300         finally  an empty string.  If the pattern is studied, the final attempt         finally an empty string.  If the pattern is studied, the final  attempt
3301         does not take place, because PCRE knows that the subject is too  short,         does  not take place, because PCRE knows that the subject is too short,
3302         and  so  the  (*MARK) is never encountered.  In this case, studying the         and so the (*MARK) is never encountered.  In this  case,  studying  the
3303         pattern does not affect the overall match result, which  is  still  "no         pattern  does  not  affect the overall match result, which is still "no
3304         match", but it does affect the auxiliary information that is returned.         match", but it does affect the auxiliary information that is returned.
3305    
3306           PCRE_NO_UTF8_CHECK           PCRE_NO_UTF8_CHECK
3307    
3308         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
3309         UTF-8 string is automatically checked when pcre_exec() is  subsequently         UTF-8  string is automatically checked when pcre_exec() is subsequently
3310         called.  The entire string is checked before any other processing takes         called.  The entire string is checked before any other processing takes
3311         place. The value of startoffset is  also  checked  to  ensure  that  it         place.  The  value  of  startoffset  is  also checked to ensure that it
3312         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
3313         the validity of UTF-8 strings in the pcreunicode page.  If  an  invalid         the  validity  of  UTF-8 strings in the pcreunicode page. If an invalid
3314         sequence   of   bytes   is   found,   pcre_exec()   returns  the  error         sequence  of  bytes   is   found,   pcre_exec()   returns   the   error
3315         PCRE_ERROR_BADUTF8 or, if PCRE_PARTIAL_HARD is set and the problem is a         PCRE_ERROR_BADUTF8 or, if PCRE_PARTIAL_HARD is set and the problem is a
3316         truncated character at the end of the subject, PCRE_ERROR_SHORTUTF8. In         truncated character at the end of the subject, PCRE_ERROR_SHORTUTF8. In
3317         both cases, information about the precise nature of the error may  also         both  cases, information about the precise nature of the error may also
3318         be  returned (see the descriptions of these errors in the section enti-         be returned (see the descriptions of these errors in the section  enti-
3319         tled Error return values from pcre_exec() below).  If startoffset  con-         tled  Error return values from pcre_exec() below).  If startoffset con-
3320         tains a value that does not point to the start of a UTF-8 character (or         tains a value that does not point to the start of a UTF-8 character (or
3321         to the end of the subject), PCRE_ERROR_BADUTF8_OFFSET is returned.         to the end of the subject), PCRE_ERROR_BADUTF8_OFFSET is returned.
3322    
3323         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
3324         these    checks    for   performance   reasons,   you   can   set   the         these   checks   for   performance   reasons,   you   can    set    the
3325         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
3326         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
3327         making repeated calls to find all  the  matches  in  a  single  subject         making  repeated  calls  to  find  all  the matches in a single subject
3328         string.  However,  you  should  be  sure  that the value of startoffset         string. However, you should be  sure  that  the  value  of  startoffset
3329         points to the start of a character (or the end of  the  subject).  When         points  to  the  start of a character (or the end of the subject). When
3330         PCRE_NO_UTF8_CHECK is set, the effect of passing an invalid string as a         PCRE_NO_UTF8_CHECK is set, the effect of passing an invalid string as a
3331         subject or an invalid value of startoffset is undefined.  Your  program         subject  or  an invalid value of startoffset is undefined. Your program
3332         may crash.         may crash.
3333    
3334           PCRE_PARTIAL_HARD           PCRE_PARTIAL_HARD
3335           PCRE_PARTIAL_SOFT           PCRE_PARTIAL_SOFT
3336    
3337         These  options turn on the partial matching feature. For backwards com-         These options turn on the partial matching feature. For backwards  com-
3338         patibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A  partial         patibility,  PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial
3339         match  occurs if the end of the subject string is reached successfully,         match occurs if the end of the subject string is reached  successfully,
3340         but there are not enough subject characters to complete the  match.  If         but  there  are not enough subject characters to complete the match. If
3341         this happens when PCRE_PARTIAL_SOFT (but not PCRE_PARTIAL_HARD) is set,         this happens when PCRE_PARTIAL_SOFT (but not PCRE_PARTIAL_HARD) is set,
3342         matching continues by testing any remaining alternatives.  Only  if  no         matching  continues  by  testing any remaining alternatives. Only if no
3343         complete  match  can be found is PCRE_ERROR_PARTIAL returned instead of         complete match can be found is PCRE_ERROR_PARTIAL returned  instead  of
3344         PCRE_ERROR_NOMATCH. In other words,  PCRE_PARTIAL_SOFT  says  that  the         PCRE_ERROR_NOMATCH.  In  other  words,  PCRE_PARTIAL_SOFT says that the
3345         caller  is  prepared to handle a partial match, but only if no complete         caller is prepared to handle a partial match, but only if  no  complete
3346         match can be found.         match can be found.
3347    
3348         If PCRE_PARTIAL_HARD is set, it overrides  PCRE_PARTIAL_SOFT.  In  this         If  PCRE_PARTIAL_HARD  is  set, it overrides PCRE_PARTIAL_SOFT. In this
3349         case,  if  a  partial  match  is found, pcre_exec() immediately returns         case, if a partial match  is  found,  pcre_exec()  immediately  returns
3350         PCRE_ERROR_PARTIAL, without  considering  any  other  alternatives.  In         PCRE_ERROR_PARTIAL,  without  considering  any  other  alternatives. In
3351         other  words, when PCRE_PARTIAL_HARD is set, a partial match is consid-         other words, when PCRE_PARTIAL_HARD is set, a partial match is  consid-
3352         ered to be more important that an alternative complete match.         ered to be more important that an alternative complete match.
3353    
3354         In both cases, the portion of the string that was  inspected  when  the         In  both  cases,  the portion of the string that was inspected when the
3355         partial match was found is set as the first matching string. There is a         partial match was found is set as the first matching string. There is a
3356         more detailed discussion of partial and  multi-segment  matching,  with         more  detailed  discussion  of partial and multi-segment matching, with
3357         examples, in the pcrepartial documentation.         examples, in the pcrepartial documentation.
3358    
3359     The string to be matched by pcre_exec()     The string to be matched by pcre_exec()
3360    
3361         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
3362         length in bytes in length, and a starting byte offset  in  startoffset.         length  in  bytes in length, and a starting byte offset in startoffset.
3363         If  this  is  negative  or  greater  than  the  length  of the subject,         If this is  negative  or  greater  than  the  length  of  the  subject,
3364         pcre_exec() returns PCRE_ERROR_BADOFFSET. When the starting  offset  is         pcre_exec()  returns  PCRE_ERROR_BADOFFSET. When the starting offset is
3365         zero,  the  search  for a match starts at the beginning of the subject,         zero, the search for a match starts at the beginning  of  the  subject,
3366         and this is by far the most common case. In UTF-8 mode, the byte offset         and this is by far the most common case. In UTF-8 mode, the byte offset
3367         must  point  to  the start of a UTF-8 character (or the end of the sub-         must point to the start of a UTF-8 character (or the end  of  the  sub-
3368         ject). Unlike the pattern string, the subject may contain  binary  zero         ject).  Unlike  the pattern string, the subject may contain binary zero
3369         bytes.         bytes.
3370    
3371         A  non-zero  starting offset is useful when searching for another match         A non-zero starting offset is useful when searching for  another  match
3372         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-
3373         cess.   Setting  startoffset differs from just passing over a shortened         cess.  Setting startoffset differs from just passing over  a  shortened
3374         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
3375         with any kind of lookbehind. For example, consider the pattern         with any kind of lookbehind. For example, consider the pattern
3376    
3377           \Biss\B           \Biss\B
3378    
3379         which  finds  occurrences  of "iss" in the middle of words. (\B matches         which finds occurrences of "iss" in the middle of  words.  (\B  matches
3380         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.)
3381         When  applied  to the string "Mississipi" the first call to pcre_exec()         When applied to the string "Mississipi" the first call  to  pcre_exec()
3382         finds the first occurrence. If pcre_exec() is called  again  with  just         finds  the  first  occurrence. If pcre_exec() is called again with just
3383         the  remainder  of  the  subject,  namely  "issipi", it does not match,         the remainder of the subject,  namely  "issipi",  it  does  not  match,
3384         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
3385         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
3386         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-
3387         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
3388         discover that it is preceded by a letter.         discover that it is preceded by a letter.
3389    
3390         Finding all the matches in a subject is tricky  when  the  pattern  can         Finding  all  the  matches  in a subject is tricky when the pattern can
3391         match an empty string. It is possible to emulate Perl's /g behaviour by         match an empty string. It is possible to emulate Perl's /g behaviour by
3392         first  trying  the  match  again  at  the   same   offset,   with   the         first   trying   the   match   again  at  the  same  offset,  with  the
3393         PCRE_NOTEMPTY_ATSTART  and  PCRE_ANCHORED  options,  and  then  if that         PCRE_NOTEMPTY_ATSTART and  PCRE_ANCHORED  options,  and  then  if  that
3394         fails, advancing the starting  offset  and  trying  an  ordinary  match         fails,  advancing  the  starting  offset  and  trying an ordinary match
3395         again. There is some code that demonstrates how to do this in the pcre-         again. There is some code that demonstrates how to do this in the pcre-
3396         demo sample program. In the most general case, you have to check to see         demo sample program. In the most general case, you have to check to see
3397         if  the newline convention recognizes CRLF as a newline, and if so, and         if the newline convention recognizes CRLF as a newline, and if so,  and
3398         the current character is CR followed by LF, advance the starting offset         the current character is CR followed by LF, advance the starting offset
3399         by two characters instead of one.         by two characters instead of one.
3400    
3401         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,
3402         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
3403         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
3404         subject.         subject.
3405    
3406     How pcre_exec() returns captured substrings     How pcre_exec() returns captured substrings
3407    
3408         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
3409         addition,  further  substrings  from  the  subject may be picked out by         addition, further substrings from the subject  may  be  picked  out  by
3410         parts of the pattern. Following the usage  in  Jeffrey  Friedl's  book,         parts  of  the  pattern.  Following the usage in Jeffrey Friedl's book,
3411         this  is  called "capturing" in what follows, and the phrase "capturing         this is called "capturing" in what follows, and the  phrase  "capturing
3412         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-
3413         string.  PCRE  supports several other kinds of parenthesized subpattern         string. PCRE supports several other kinds of  parenthesized  subpattern
3414         that do not cause substrings to be captured.         that do not cause substrings to be captured.
3415    
3416         Captured substrings are returned to the caller via a vector of integers         Captured substrings are returned to the caller via a vector of integers
3417         whose  address is passed in ovector. The number of elements in the vec-         whose address is passed in ovector. The number of elements in the  vec-
3418         tor is passed in ovecsize, which must be a non-negative  number.  Note:         tor  is  passed in ovecsize, which must be a non-negative number. Note:
3419         this argument is NOT the size of ovector in bytes.         this argument is NOT the size of ovector in bytes.
3420    
3421         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-
3422         strings, each substring using a pair of integers. The  remaining  third         strings,  each  substring using a pair of integers. The remaining third
3423         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-
3424         turing subpatterns, and is not available for passing back  information.         turing  subpatterns, and is not available for passing back information.
3425         The  number passed in ovecsize should always be a multiple of three. If         The number passed in ovecsize should always be a multiple of three.  If
3426         it is not, it is rounded down.         it is not, it is rounded down.
3427    
3428         When a match is successful, information about  captured  substrings  is         When  a  match  is successful, information about captured substrings is
3429         returned  in  pairs  of integers, starting at the beginning of ovector,         returned in pairs of integers, starting at the  beginning  of  ovector,
3430         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
3431         element  of  each pair is set to the byte offset of the first character         element of each pair is set to the byte offset of the  first  character
3432         in a substring, and the second is set to the byte offset of  the  first         in  a  substring, and the second is set to the byte offset of the first
3433         character  after  the end of a substring. Note: these values are always         character after the end of a substring. Note: these values  are  always
3434         byte offsets, even in UTF-8 mode. They are not character counts.         byte offsets, even in UTF-8 mode. They are not character counts.
3435    
3436         The first pair of integers, ovector[0]  and  ovector[1],  identify  the         The  first  pair  of  integers, ovector[0] and ovector[1], identify the
3437         portion  of  the subject string matched by the entire pattern. The next         portion of the subject string matched by the entire pattern.  The  next
3438         pair is used for the first capturing subpattern, and so on.  The  value         pair  is  used for the first capturing subpattern, and so on. The value
3439         returned by pcre_exec() is one more than the highest numbered pair that         returned by pcre_exec() is one more than the highest numbered pair that
3440         has been set.  For example, if two substrings have been  captured,  the         has  been  set.  For example, if two substrings have been captured, the
3441         returned  value is 3. If there are no capturing subpatterns, the return         returned value is 3. If there are no capturing subpatterns, the  return
3442         value from a successful match is 1, indicating that just the first pair         value from a successful match is 1, indicating that just the first pair
3443         of offsets has been set.         of offsets has been set.
3444    
3445         If a capturing subpattern is matched repeatedly, it is the last portion         If a capturing subpattern is matched repeatedly, it is the last portion
3446         of the string that it matched that is returned.         of the string that it matched that is returned.
3447    
3448         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,
3449         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
3450         function returns a value of zero. If neither the actual string  matched         function  returns a value of zero. If neither the actual string matched
3451         nor  any captured substrings are of interest, pcre_exec() may be called         nor any captured substrings are of interest, pcre_exec() may be  called
3452         with ovector passed as NULL and ovecsize as zero. However, if the  pat-         with  ovector passed as NULL and ovecsize as zero. However, if the pat-
3453         tern  contains  back  references  and  the ovector is not big enough to         tern contains back references and the ovector  is  not  big  enough  to
3454         remember the related substrings, PCRE has to get additional memory  for         remember  the related substrings, PCRE has to get additional memory for
3455         use  during matching. Thus it is usually advisable to supply an ovector         use during matching. Thus it is usually advisable to supply an  ovector
3456         of reasonable size.         of reasonable size.
3457    
3458         There are some cases where zero is returned  (indicating  vector  over-         There  are  some  cases where zero is returned (indicating vector over-
3459         flow)  when  in fact the vector is exactly the right size for the final         flow) when in fact the vector is exactly the right size for  the  final
3460         match. For example, consider the pattern         match. For example, consider the pattern
3461    
3462           (a)(?:(b)c|bd)           (a)(?:(b)c|bd)
3463    
3464         If a vector of 6 elements (allowing for only 1 captured  substring)  is         If  a  vector of 6 elements (allowing for only 1 captured substring) is
3465         given with subject string "abd", pcre_exec() will try to set the second         given with subject string "abd", pcre_exec() will try to set the second
3466         captured string, thereby recording a vector overflow, before failing to         captured string, thereby recording a vector overflow, before failing to
3467         match  "c"  and  backing  up  to  try  the second alternative. The zero         match "c" and backing up  to  try  the  second  alternative.  The  zero
3468         return, however, does correctly indicate that  the  maximum  number  of         return,  however,  does  correctly  indicate that the maximum number of
3469         slots (namely 2) have been filled. In similar cases where there is tem-         slots (namely 2) have been filled. In similar cases where there is tem-
3470         porary overflow, but the final number of used slots  is  actually  less         porary  overflow,  but  the final number of used slots is actually less
3471         than the maximum, a non-zero value is returned.         than the maximum, a non-zero value is returned.
3472    
3473         The pcre_fullinfo() function can be used to find out how many capturing         The pcre_fullinfo() function can be used to find out how many capturing
3474         subpatterns there are in a compiled  pattern.  The  smallest  size  for         subpatterns  there  are  in  a  compiled pattern. The smallest size for
3475         ovector  that  will allow for n captured substrings, in addition to the         ovector that will allow for n captured substrings, in addition  to  the
3476         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.
3477    
3478         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
3479         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,
3480         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
3481         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
3482         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-
3483         sponding to unused subpatterns are set to -1.         sponding to unused subpatterns are set to -1.
3484    
3485         Offset  values  that correspond to unused subpatterns at the end of the         Offset values that correspond to unused subpatterns at the end  of  the
3486         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
3487         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
3488         matched. The return from the function is 2, because  the  highest  used         matched.  The  return  from the function is 2, because the highest used
3489         capturing  subpattern  number  is 1, and the offsets for for the second         capturing subpattern number is 1, and the offsets for  for  the  second
3490         and third capturing subpatterns (assuming the vector is  large  enough,         and  third  capturing subpatterns (assuming the vector is large enough,
3491         of course) are set to -1.         of course) are set to -1.
3492    
3493         Note:  Elements  in  the first two-thirds of ovector that do not corre-         Note: Elements in the first two-thirds of ovector that  do  not  corre-
3494         spond to capturing parentheses in the pattern are never  changed.  That         spond  to  capturing parentheses in the pattern are never changed. That
3495         is,  if  a pattern contains n capturing parentheses, no more than ovec-         is, if a pattern contains n capturing parentheses, no more  than  ovec-
3496         tor[0] to ovector[2n+1] are set by pcre_exec(). The other elements  (in         tor[0]  to ovector[2n+1] are set by pcre_exec(). The other elements (in
3497         the first two-thirds) retain whatever values they previously had.         the first two-thirds) retain whatever values they previously had.
3498    
3499         Some  convenience  functions  are  provided for extracting the captured         Some convenience functions are provided  for  extracting  the  captured
3500         substrings as separate strings. These are described below.         substrings as separate strings. These are described below.
3501    
3502     Error return values from pcre_exec()     Error return values from pcre_exec()
3503    
3504         If pcre_exec() fails, it returns a negative number. The  following  are         If  pcre_exec()  fails, it returns a negative number. The following are
3505         defined in the header file:         defined in the header file:
3506    
3507           PCRE_ERROR_NOMATCH        (-1)           PCRE_ERROR_NOMATCH        (-1)
# Line 3456  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 3510  MATCHING A PATTERN: THE TRADITIONAL FUNC
3510    
3511           PCRE_ERROR_NULL           (-2)           PCRE_ERROR_NULL           (-2)
3512    
3513         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
3514         ovecsize was not zero.         ovecsize was not zero.
3515    
3516           PCRE_ERROR_BADOPTION      (-3)           PCRE_ERROR_BADOPTION      (-3)
# Line 3465  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 3519  MATCHING A PATTERN: THE TRADITIONAL FUNC
3519    
3520           PCRE_ERROR_BADMAGIC       (-4)           PCRE_ERROR_BADMAGIC       (-4)
3521    
3522         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,
3523         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
3524         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
3525         an  environment  with the other endianness. This is the error that PCRE         an environment with the other endianness. This is the error  that  PCRE
3526         gives when the magic number is not present.         gives when the magic number is not present.
3527    
3528           PCRE_ERROR_UNKNOWN_OPCODE (-5)           PCRE_ERROR_UNKNOWN_OPCODE (-5)
3529    
3530         While running the pattern match, an unknown item was encountered in the         While running the pattern match, an unknown item was encountered in the
3531         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
3532         overwriting of the compiled pattern.         overwriting of the compiled pattern.
3533    
3534           PCRE_ERROR_NOMEMORY       (-6)           PCRE_ERROR_NOMEMORY       (-6)
3535    
3536         If a pattern contains back references, but the ovector that  is  passed         If  a  pattern contains back references, but the ovector that is passed
3537         to pcre_exec() is not big enough to remember the referenced substrings,         to pcre_exec() is not big enough to remember the referenced substrings,
3538         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
3539         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
3540         memory is automatically freed at the end of matching.         memory is automatically freed at the end of matching.
3541    
3542         This error is also given if pcre_stack_malloc() fails  in  pcre_exec().         This  error  is also given if pcre_stack_malloc() fails in pcre_exec().
3543         This  can happen only when PCRE has been compiled with --disable-stack-         This can happen only when PCRE has been compiled with  --disable-stack-
3544         for-recursion.         for-recursion.
3545    
3546           PCRE_ERROR_NOSUBSTRING    (-7)           PCRE_ERROR_NOSUBSTRING    (-7)
3547    
3548         This error is used by the pcre_copy_substring(),  pcre_get_substring(),         This  error is used by the pcre_copy_substring(), pcre_get_substring(),
3549         and  pcre_get_substring_list()  functions  (see  below).  It  is  never         and  pcre_get_substring_list()  functions  (see  below).  It  is  never
3550         returned by pcre_exec().         returned by pcre_exec().
3551    
3552           PCRE_ERROR_MATCHLIMIT     (-8)           PCRE_ERROR_MATCHLIMIT     (-8)
3553    
3554         The backtracking limit, as specified by  the  match_limit  field  in  a         The  backtracking  limit,  as  specified  by the match_limit field in a
3555         pcre_extra  structure  (or  defaulted) was reached. See the description         pcre_extra structure (or defaulted) was reached.  See  the  description
3556         above.         above.
3557    
3558           PCRE_ERROR_CALLOUT        (-9)           PCRE_ERROR_CALLOUT        (-9)
3559    
3560         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
3561         use  by  callout functions that want to yield a distinctive error code.         use by callout functions that want to yield a distinctive  error  code.
3562         See the pcrecallout documentation for details.         See the pcrecallout documentation for details.
3563    
3564           PCRE_ERROR_BADUTF8        (-10)           PCRE_ERROR_BADUTF8        (-10)
3565    
3566         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
3567         subject,  and the PCRE_NO_UTF8_CHECK option was not set. If the size of         subject, and the PCRE_NO_UTF8_CHECK option was not set. If the size  of
3568         the output vector (ovecsize) is at least 2,  the  byte  offset  to  the         the  output  vector  (ovecsize)  is  at least 2, the byte offset to the
3569         start  of  the  the invalid UTF-8 character is placed in the first ele-         start of the the invalid UTF-8 character is placed in  the  first  ele-
3570         ment, and a reason code is placed in the  second  element.  The  reason         ment,  and  a  reason  code is placed in the second element. The reason
3571         codes are listed in the following section.  For backward compatibility,         codes are listed in the following section.  For backward compatibility,
3572         if PCRE_PARTIAL_HARD is set and the problem is a truncated UTF-8  char-         if  PCRE_PARTIAL_HARD is set and the problem is a truncated UTF-8 char-
3573         acter   at   the   end   of   the   subject  (reason  codes  1  to  5),         acter  at  the  end  of  the   subject   (reason   codes   1   to   5),
3574         PCRE_ERROR_SHORTUTF8 is returned instead of PCRE_ERROR_BADUTF8.         PCRE_ERROR_SHORTUTF8 is returned instead of PCRE_ERROR_BADUTF8.
3575    
3576           PCRE_ERROR_BADUTF8_OFFSET (-11)           PCRE_ERROR_BADUTF8_OFFSET (-11)
3577    
3578         The UTF-8 byte sequence that was passed as a subject  was  checked  and         The  UTF-8  byte  sequence that was passed as a subject was checked and
3579         found  to be valid (the PCRE_NO_UTF8_CHECK option was not set), but the         found to be valid (the PCRE_NO_UTF8_CHECK option was not set), but  the
3580         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-
3581         ter or the end of the subject.         ter or the end of the subject.
3582    
3583           PCRE_ERROR_PARTIAL        (-12)           PCRE_ERROR_PARTIAL        (-12)
3584    
3585         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
3586         pcrepartial documentation for details of partial matching.         pcrepartial documentation for details of partial matching.
3587    
3588           PCRE_ERROR_BADPARTIAL     (-13)           PCRE_ERROR_BADPARTIAL     (-13)
3589    
3590         This code is no longer in  use.  It  was  formerly  returned  when  the         This  code  is  no  longer  in  use.  It was formerly returned when the
3591         PCRE_PARTIAL  option  was used with a compiled pattern containing items         PCRE_PARTIAL option was used with a compiled pattern  containing  items
3592         that were  not  supported  for  partial  matching.  From  release  8.00         that  were  not  supported  for  partial  matching.  From  release 8.00
3593         onwards, there are no restrictions on partial matching.         onwards, there are no restrictions on partial matching.
3594    
3595           PCRE_ERROR_INTERNAL       (-14)           PCRE_ERROR_INTERNAL       (-14)
3596    
3597         An  unexpected  internal error has occurred. This error could be caused         An unexpected internal error has occurred. This error could  be  caused
3598         by a bug in PCRE or by overwriting of the compiled pattern.         by a bug in PCRE or by overwriting of the compiled pattern.
3599    
3600           PCRE_ERROR_BADCOUNT       (-15)           PCRE_ERROR_BADCOUNT       (-15)
# Line 3550  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 3604  MATCHING A PATTERN: THE TRADITIONAL FUNC
3604           PCRE_ERROR_RECURSIONLIMIT (-21)           PCRE_ERROR_RECURSIONLIMIT (-21)
3605    
3606         The internal recursion limit, as specified by the match_limit_recursion         The internal recursion limit, as specified by the match_limit_recursion
3607         field  in  a  pcre_extra  structure (or defaulted) was reached. See the         field in a pcre_extra structure (or defaulted)  was  reached.  See  the
3608         description above.         description above.
3609    
3610           PCRE_ERROR_BADNEWLINE     (-23)           PCRE_ERROR_BADNEWLINE     (-23)
# Line 3564  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 3618  MATCHING A PATTERN: THE TRADITIONAL FUNC
3618    
3619           PCRE_ERROR_SHORTUTF8      (-25)           PCRE_ERROR_SHORTUTF8      (-25)
3620    
3621         This  error  is returned instead of PCRE_ERROR_BADUTF8 when the subject         This error is returned instead of PCRE_ERROR_BADUTF8 when  the  subject
3622         string ends with a truncated UTF-8 character and the  PCRE_PARTIAL_HARD         string  ends with a truncated UTF-8 character and the PCRE_PARTIAL_HARD
3623         option  is  set.   Information  about  the  failure  is returned as for         option is set.  Information  about  the  failure  is  returned  as  for
3624         PCRE_ERROR_BADUTF8. It is in fact sufficient to detect this  case,  but         PCRE_ERROR_BADUTF8.  It  is in fact sufficient to detect this case, but
3625         this  special error code for PCRE_PARTIAL_HARD precedes the implementa-         this special error code for PCRE_PARTIAL_HARD precedes the  implementa-
3626         tion of returned information; it is retained for backwards  compatibil-         tion  of returned information; it is retained for backwards compatibil-
3627         ity.         ity.
3628    
3629           PCRE_ERROR_RECURSELOOP    (-26)           PCRE_ERROR_RECURSELOOP    (-26)
3630    
3631         This error is returned when pcre_exec() detects a recursion loop within         This error is returned when pcre_exec() detects a recursion loop within
3632         the pattern. Specifically, it means that either the whole pattern or  a         the  pattern. Specifically, it means that either the whole pattern or a
3633         subpattern  has been called recursively for the second time at the same         subpattern has been called recursively for the second time at the  same
3634         position in the subject string. Some simple patterns that might do this         position in the subject string. Some simple patterns that might do this
3635         are  detected  and faulted at compile time, but more complicated cases,         are detected and faulted at compile time, but more  complicated  cases,
3636         in particular mutual recursions between two different subpatterns, can-         in particular mutual recursions between two different subpatterns, can-
3637         not be detected until run time.         not be detected until run time.
3638    
3639           PCRE_ERROR_JIT_STACKLIMIT (-27)           PCRE_ERROR_JIT_STACKLIMIT (-27)
3640    
3641         This  error  is  returned  when a pattern that was successfully studied         This error is returned when a pattern  that  was  successfully  studied
3642         using a JIT compile option is being matched, but the  memory  available         using  a  JIT compile option is being matched, but the memory available
3643         for  the  just-in-time  processing  stack  is not large enough. See the         for the just-in-time processing stack is  not  large  enough.  See  the
3644         pcrejit documentation for more details.         pcrejit documentation for more details.
3645    
3646           PCRE_ERROR_BADMODE        (-28)           PCRE_ERROR_BADMODE        (-28)
# Line 3596  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 3650  MATCHING A PATTERN: THE TRADITIONAL FUNC
3650    
3651           PCRE_ERROR_BADENDIANNESS  (-29)           PCRE_ERROR_BADENDIANNESS  (-29)
3652    
3653         This  error  is  given  if  a  pattern  that  was compiled and saved is         This error is given if  a  pattern  that  was  compiled  and  saved  is
3654         reloaded on a host with  different  endianness.  The  utility  function         reloaded  on  a  host  with  different endianness. The utility function
3655         pcre_pattern_to_host_byte_order() can be used to convert such a pattern         pcre_pattern_to_host_byte_order() can be used to convert such a pattern
3656         so that it runs on the new host.         so that it runs on the new host.
3657    
3658           PCRE_ERROR_JIT_BADOPTION           PCRE_ERROR_JIT_BADOPTION
3659    
3660         This error is returned when a pattern  that  was  successfully  studied         This  error  is  returned  when a pattern that was successfully studied
3661         using  a  JIT  compile  option  is being matched, but the matching mode         using a JIT compile option is being  matched,  but  the  matching  mode
3662         (partial or complete match) does not correspond to any JIT  compilation         (partial  or complete match) does not correspond to any JIT compilation
3663         mode.  When  the JIT fast path function is used, this error may be also         mode. When the JIT fast path function is used, this error may  be  also
3664         given for invalid options.  See  the  pcrejit  documentation  for  more         given  for  invalid  options.  See  the  pcrejit documentation for more
3665         details.         details.
3666    
3667           PCRE_ERROR_BADLENGTH      (-32)           PCRE_ERROR_BADLENGTH      (-32)
3668    
3669         This  error is given if pcre_exec() is called with a negative value for         This error is given if pcre_exec() is called with a negative value  for
3670         the length argument.         the length argument.
3671    
3672         Error numbers -16 to -20, -22, and 30 are not used by pcre_exec().         Error numbers -16 to -20, -22, and 30 are not used by pcre_exec().
3673    
3674     Reason codes for invalid UTF-8 strings     Reason codes for invalid UTF-8 strings
3675    
3676         This section applies only  to  the  8-bit  library.  The  corresponding         This  section  applies  only  to  the  8-bit library. The corresponding
3677         information  for the 16-bit and 32-bit libraries is given in the pcre16         information for the 16-bit and 32-bit libraries is given in the  pcre16
3678         and pcre32 pages.         and pcre32 pages.
3679    
3680         When pcre_exec() returns either PCRE_ERROR_BADUTF8 or PCRE_ERROR_SHORT-         When pcre_exec() returns either PCRE_ERROR_BADUTF8 or PCRE_ERROR_SHORT-
3681         UTF8,  and  the size of the output vector (ovecsize) is at least 2, the         UTF8, and the size of the output vector (ovecsize) is at least  2,  the
3682         offset of the start of the invalid UTF-8 character  is  placed  in  the         offset  of  the  start  of the invalid UTF-8 character is placed in the
3683         first output vector element (ovector[0]) and a reason code is placed in         first output vector element (ovector[0]) and a reason code is placed in
3684         the second element (ovector[1]). The reason codes are  given  names  in         the  second  element  (ovector[1]). The reason codes are given names in
3685         the pcre.h header file:         the pcre.h header file:
3686    
3687           PCRE_UTF8_ERR1           PCRE_UTF8_ERR1
# Line 3636  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 3690  MATCHING A PATTERN: THE TRADITIONAL FUNC
3690           PCRE_UTF8_ERR4           PCRE_UTF8_ERR4
3691           PCRE_UTF8_ERR5           PCRE_UTF8_ERR5
3692    
3693         The  string  ends  with a truncated UTF-8 character; the code specifies         The string ends with a truncated UTF-8 character;  the  code  specifies
3694         how many bytes are missing (1 to 5). Although RFC 3629 restricts  UTF-8         how  many bytes are missing (1 to 5). Although RFC 3629 restricts UTF-8
3695         characters  to  be  no longer than 4 bytes, the encoding scheme (origi-         characters to be no longer than 4 bytes, the  encoding  scheme  (origi-
3696         nally defined by RFC 2279) allows for  up  to  6  bytes,  and  this  is         nally  defined  by  RFC  2279)  allows  for  up to 6 bytes, and this is
3697         checked first; hence the possibility of 4 or 5 missing bytes.         checked first; hence the possibility of 4 or 5 missing bytes.
3698    
3699           PCRE_UTF8_ERR6           PCRE_UTF8_ERR6
# Line 3649  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 3703  MATCHING A PATTERN: THE TRADITIONAL FUNC
3703           PCRE_UTF8_ERR10           PCRE_UTF8_ERR10
3704    
3705         The two most significant bits of the 2nd, 3rd, 4th, 5th, or 6th byte of         The two most significant bits of the 2nd, 3rd, 4th, 5th, or 6th byte of
3706         the character do not have the binary value 0b10 (that  is,  either  the         the  character  do  not have the binary value 0b10 (that is, either the
3707         most significant bit is 0, or the next bit is 1).         most significant bit is 0, or the next bit is 1).
3708    
3709           PCRE_UTF8_ERR11           PCRE_UTF8_ERR11
3710           PCRE_UTF8_ERR12           PCRE_UTF8_ERR12
3711    
3712         A  character that is valid by the RFC 2279 rules is either 5 or 6 bytes         A character that is valid by the RFC 2279 rules is either 5 or 6  bytes
3713         long; these code points are excluded by RFC 3629.         long; these code points are excluded by RFC 3629.
3714    
3715           PCRE_UTF8_ERR13           PCRE_UTF8_ERR13
3716    
3717         A 4-byte character has a value greater than 0x10fff; these code  points         A  4-byte character has a value greater than 0x10fff; these code points
3718         are excluded by RFC 3629.         are excluded by RFC 3629.
3719    
3720           PCRE_UTF8_ERR14           PCRE_UTF8_ERR14
3721    
3722         A  3-byte  character  has  a  value in the range 0xd800 to 0xdfff; this         A 3-byte character has a value in the  range  0xd800  to  0xdfff;  this
3723         range of code points are reserved by RFC 3629 for use with UTF-16,  and         range  of code points are reserved by RFC 3629 for use with UTF-16, and
3724         so are excluded from UTF-8.         so are excluded from UTF-8.
3725    
3726           PCRE_UTF8_ERR15           PCRE_UTF8_ERR15
# Line 3675  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 3729  MATCHING A PATTERN: THE TRADITIONAL FUNC
3729           PCRE_UTF8_ERR18           PCRE_UTF8_ERR18
3730           PCRE_UTF8_ERR19           PCRE_UTF8_ERR19
3731    
3732         A  2-, 3-, 4-, 5-, or 6-byte character is "overlong", that is, it codes         A 2-, 3-, 4-, 5-, or 6-byte character is "overlong", that is, it  codes
3733         for a value that can be represented by fewer bytes, which  is  invalid.         for  a  value that can be represented by fewer bytes, which is invalid.
3734         For  example,  the two bytes 0xc0, 0xae give the value 0x2e, whose cor-         For example, the two bytes 0xc0, 0xae give the value 0x2e,  whose  cor-
3735         rect coding uses just one byte.         rect coding uses just one byte.
3736    
3737           PCRE_UTF8_ERR20           PCRE_UTF8_ERR20
3738    
3739         The two most significant bits of the first byte of a character have the         The two most significant bits of the first byte of a character have the
3740         binary  value 0b10 (that is, the most significant bit is 1 and the sec-         binary value 0b10 (that is, the most significant bit is 1 and the  sec-
3741         ond is 0). Such a byte can only validly occur as the second  or  subse-         ond  is  0). Such a byte can only validly occur as the second or subse-
3742         quent byte of a multi-byte character.         quent byte of a multi-byte character.
3743    
3744           PCRE_UTF8_ERR21           PCRE_UTF8_ERR21
3745    
3746         The  first byte of a character has the value 0xfe or 0xff. These values         The first byte of a character has the value 0xfe or 0xff. These  values
3747         can never occur in a valid UTF-8 string.         can never occur in a valid UTF-8 string.
3748    
3749           PCRE_UTF8_ERR22           PCRE_UTF8_ERR22
3750    
3751         This error code was formerly used when  the  presence  of  a  so-called         This  error  code  was  formerly  used when the presence of a so-called
3752         "non-character"  caused an error. Unicode corrigendum #9 makes it clear         "non-character" caused an error. Unicode corrigendum #9 makes it  clear
3753         that such characters should not cause a string to be rejected,  and  so         that  such  characters should not cause a string to be rejected, and so
3754         this code is no longer in use and is never returned.         this code is no longer in use and is never returned.
3755    
3756    
# Line 3713  EXTRACTING CAPTURED SUBSTRINGS BY NUMBER Line 3767  EXTRACTING CAPTURED SUBSTRINGS BY NUMBER
3767         int pcre_get_substring_list(const char *subject,         int pcre_get_substring_list(const char *subject,
3768              int *ovector, int stringcount, const char ***listptr);              int *ovector, int stringcount, const char ***listptr);
3769    
3770         Captured  substrings  can  be  accessed  directly  by using the offsets         Captured substrings can be  accessed  directly  by  using  the  offsets
3771         returned by pcre_exec() in  ovector.  For  convenience,  the  functions         returned  by  pcre_exec()  in  ovector.  For convenience, the functions
3772         pcre_copy_substring(),    pcre_get_substring(),    and    pcre_get_sub-         pcre_copy_substring(),    pcre_get_substring(),    and    pcre_get_sub-
3773         string_list() are provided for extracting captured substrings  as  new,         string_list()  are  provided for extracting captured substrings as new,
3774         separate,  zero-terminated strings. These functions identify substrings         separate, zero-terminated strings. These functions identify  substrings
3775         by number. The next section describes functions  for  extracting  named         by  number.  The  next section describes functions for extracting named
3776         substrings.         substrings.
3777    
3778         A  substring that contains a binary zero is correctly extracted and has         A substring that contains a binary zero is correctly extracted and  has
3779         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
3780         string.   However,  you  can  process such a string by referring to the         string.  However, you can process such a string  by  referring  to  the
3781         length that is  returned  by  pcre_copy_substring()  and  pcre_get_sub-         length  that  is  returned  by  pcre_copy_substring() and pcre_get_sub-
3782         string().  Unfortunately, the interface to pcre_get_substring_list() is         string().  Unfortunately, the interface to pcre_get_substring_list() is
3783         not adequate for handling strings containing binary zeros, because  the         not  adequate for handling strings containing binary zeros, because the
3784         end of the final string is not independently indicated.         end of the final string is not independently indicated.
3785    
3786         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-
3787         tions: subject is the subject string that has  just  been  successfully         tions:  subject  is  the subject string that has just been successfully
3788         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
3789         passed to pcre_exec(), and stringcount is the number of substrings that         passed to pcre_exec(), and stringcount is the number of substrings that
3790         were  captured  by  the match, including the substring that matched the         were captured by the match, including the substring  that  matched  the
3791         entire regular expression. This is the value returned by pcre_exec() if         entire regular expression. This is the value returned by pcre_exec() if
3792         it  is greater than zero. If pcre_exec() returned zero, indicating that         it is greater than zero. If pcre_exec() returned zero, indicating  that
3793         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
3794         be the number of elements in the vector divided by three.         be the number of elements in the vector divided by three.
3795    
3796         The  functions pcre_copy_substring() and pcre_get_substring() extract a         The functions pcre_copy_substring() and pcre_get_substring() extract  a
3797         single substring, whose number is given as  stringnumber.  A  value  of         single  substring,  whose  number  is given as stringnumber. A value of
3798         zero  extracts  the  substring that matched the entire pattern, whereas         zero extracts the substring that matched the  entire  pattern,  whereas
3799         higher values  extract  the  captured  substrings.  For  pcre_copy_sub-         higher  values  extract  the  captured  substrings.  For pcre_copy_sub-
3800         string(),  the  string  is  placed  in buffer, whose length is given by         string(), the string is placed in buffer,  whose  length  is  given  by
3801         buffersize, while for pcre_get_substring() a new  block  of  memory  is         buffersize,  while  for  pcre_get_substring()  a new block of memory is
3802         obtained  via  pcre_malloc,  and its address is returned via stringptr.         obtained via pcre_malloc, and its address is  returned  via  stringptr.
3803         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
3804         the terminating zero, or one of these error codes:         the terminating zero, or one of these error codes:
3805    
3806           PCRE_ERROR_NOMEMORY       (-6)           PCRE_ERROR_NOMEMORY       (-6)
3807    
3808         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
3809         get memory failed for pcre_get_substring().         get memory failed for pcre_get_substring().
3810    
3811           PCRE_ERROR_NOSUBSTRING    (-7)           PCRE_ERROR_NOSUBSTRING    (-7)
3812    
3813         There is no substring whose number is stringnumber.         There is no substring whose number is stringnumber.
3814    
3815         The pcre_get_substring_list()  function  extracts  all  available  sub-         The  pcre_get_substring_list()  function  extracts  all  available sub-
3816         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
3817         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
3818         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
3819         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
3820         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
3821         error code         error code
3822    
3823           PCRE_ERROR_NOMEMORY       (-6)           PCRE_ERROR_NOMEMORY       (-6)
3824    
3825         if the attempt to get the memory block failed.         if the attempt to get the memory block failed.
3826    
3827         When any of these functions encounter a substring that is unset,  which         When  any of these functions encounter a substring that is unset, which
3828         can  happen  when  capturing subpattern number n+1 matches some part of         can happen when capturing subpattern number n+1 matches  some  part  of
3829         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
3830         empty string. This can be distinguished from a genuine zero-length sub-         empty string. This can be distinguished from a genuine zero-length sub-
3831         string by inspecting the appropriate offset in ovector, which is  nega-         string  by inspecting the appropriate offset in ovector, which is nega-
3832         tive for unset substrings.         tive for unset substrings.
3833    
3834         The  two convenience functions pcre_free_substring() and pcre_free_sub-         The two convenience functions pcre_free_substring() and  pcre_free_sub-
3835         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
3836         call  of  pcre_get_substring()  or  pcre_get_substring_list(),  respec-         call  of  pcre_get_substring()  or  pcre_get_substring_list(),  respec-
3837         tively. They do nothing more than  call  the  function  pointed  to  by         tively.  They  do  nothing  more  than  call the function pointed to by
3838         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.
3839         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-
3840         cial   interface  to  another  programming  language  that  cannot  use         cial  interface  to  another  programming  language  that  cannot   use
3841         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-
3842         vided.         vided.
3843    
3844    
# Line 3803  EXTRACTING CAPTURED SUBSTRINGS BY NAME Line 3857  EXTRACTING CAPTURED SUBSTRINGS BY NAME
3857              int stringcount, const char *stringname,              int stringcount, const char *stringname,
3858              const char **stringptr);              const char **stringptr);
3859    
3860         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-
3861         ber.  For example, for this pattern         ber.  For example, for this pattern
3862    
3863           (a+)b(?<xxx>\d+)...           (a+)b(?<xxx>\d+)...
# Line 3812  EXTRACTING CAPTURED SUBSTRINGS BY NAME Line 3866  EXTRACTING CAPTURED SUBSTRINGS BY NAME
3866         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
3867         name by calling pcre_get_stringnumber(). The first argument is the com-         name by calling pcre_get_stringnumber(). The first argument is the com-
3868         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
3869         the subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if  there  is  no         the  subpattern  number,  or PCRE_ERROR_NOSUBSTRING (-7) if there is no
3870         subpattern of that name.         subpattern of that name.
3871    
3872         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
3873         the functions described in the previous section. For convenience, there         the functions described in the previous section. For convenience, there
3874         are also two functions that do the whole job.         are also two functions that do the whole job.
3875    
3876         Most    of    the    arguments   of   pcre_copy_named_substring()   and         Most   of   the   arguments    of    pcre_copy_named_substring()    and
3877         pcre_get_named_substring() are the same  as  those  for  the  similarly         pcre_get_named_substring()  are  the  same  as  those for the similarly
3878         named  functions  that extract by number. As these are described in the         named functions that extract by number. As these are described  in  the
3879         previous section, they are not re-described here. There  are  just  two         previous  section,  they  are not re-described here. There are just two
3880         differences:         differences:
3881    
3882         First,  instead  of a substring number, a substring name is given. Sec-         First, instead of a substring number, a substring name is  given.  Sec-
3883         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
3884         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
3885         name-to-number translation table.         name-to-number translation table.
3886    
3887         These functions call pcre_get_stringnumber(), and if it succeeds,  they         These  functions call pcre_get_stringnumber(), and if it succeeds, they
3888         then  call  pcre_copy_substring() or pcre_get_substring(), as appropri-         then call pcre_copy_substring() or pcre_get_substring(),  as  appropri-
3889         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
3890         behaviour may not be what you want (see the next section).         behaviour may not be what you want (see the next section).
3891    
3892         Warning: If the pattern uses the (?| feature to set up multiple subpat-         Warning: If the pattern uses the (?| feature to set up multiple subpat-
3893         terns with the same number, as described in the  section  on  duplicate         terns  with  the  same number, as described in the section on duplicate
3894         subpattern  numbers  in  the  pcrepattern page, you cannot use names to         subpattern numbers in the pcrepattern page, you  cannot  use  names  to
3895         distinguish the different subpatterns, because names are  not  included         distinguish  the  different subpatterns, because names are not included
3896         in  the compiled code. The matching process uses only numbers. For this         in the compiled code. The matching process uses only numbers. For  this
3897         reason, the use of different names for subpatterns of the  same  number         reason,  the  use of different names for subpatterns of the same number
3898         causes an error at compile time.         causes an error at compile time.
3899    
3900    
# Line 3849  DUPLICATE SUBPATTERN NAMES Line 3903  DUPLICATE SUBPATTERN NAMES
3903         int pcre_get_stringtable_entries(const pcre *code,         int pcre_get_stringtable_entries(const pcre *code,
3904              const char *name, char **first, char **last);              const char *name, char **first, char **last);
3905    
3906         When  a  pattern  is  compiled with the PCRE_DUPNAMES option, names for         When a pattern is compiled with the  PCRE_DUPNAMES  option,  names  for
3907         subpatterns are not required to be unique. (Duplicate names are  always         subpatterns  are not required to be unique. (Duplicate names are always
3908         allowed  for subpatterns with the same number, created by using the (?|         allowed for subpatterns with the same number, created by using the  (?|
3909         feature. Indeed, if such subpatterns are named, they  are  required  to         feature.  Indeed,  if  such subpatterns are named, they are required to
3910         use the same names.)         use the same names.)
3911    
3912         Normally, patterns with duplicate names are such that in any one match,         Normally, patterns with duplicate names are such that in any one match,
3913         only one of the named subpatterns participates. An example is shown  in         only  one of the named subpatterns participates. An example is shown in
3914         the pcrepattern documentation.         the pcrepattern documentation.
3915    
3916         When    duplicates   are   present,   pcre_copy_named_substring()   and         When   duplicates   are   present,   pcre_copy_named_substring()    and
3917         pcre_get_named_substring() return the first substring corresponding  to         pcre_get_named_substring()  return the first substring corresponding to
3918         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
3919         (-7) is returned; no  data  is  returned.  The  pcre_get_stringnumber()         (-7)  is  returned;  no  data  is returned. The pcre_get_stringnumber()
3920         function  returns one of the numbers that are associated with the name,         function returns one of the numbers that are associated with the  name,
3921         but it is not defined which it is.         but it is not defined which it is.
3922    
3923         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
3924         name,  you  must  use  the pcre_get_stringtable_entries() function. The         name, you must use  the  pcre_get_stringtable_entries()  function.  The
3925         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
3926         third  and  fourth  are  pointers to variables which are updated by the         third and fourth are pointers to variables which  are  updated  by  the
3927         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
3928         the  name-to-number  table  for  the  given  name.  The function itself         the name-to-number table  for  the  given  name.  The  function  itself
3929         returns the length of each entry,  or  PCRE_ERROR_NOSUBSTRING  (-7)  if         returns  the  length  of  each entry, or PCRE_ERROR_NOSUBSTRING (-7) if
3930         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-
3931         tion entitled Information about a pattern above.  Given all  the  rele-         tion  entitled  Information about a pattern above.  Given all the rele-
3932         vant  entries  for the name, you can extract each of their numbers, and         vant entries for the name, you can extract each of their  numbers,  and
3933         hence the captured data, if any.         hence the captured data, if any.
3934    
3935    
3936  FINDING ALL POSSIBLE MATCHES  FINDING ALL POSSIBLE MATCHES
3937    
3938         The traditional matching function uses a  similar  algorithm  to  Perl,         The  traditional  matching  function  uses a similar algorithm to Perl,
3939         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
3940         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
3941         possible  match,  consider using the alternative matching function (see         possible match, consider using the alternative matching  function  (see
3942         below) instead. If you cannot use the alternative function,  but  still         below)  instead.  If you cannot use the alternative function, but still
3943         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
3944         of the callout facility, which is described in the pcrecallout documen-         of the callout facility, which is described in the pcrecallout documen-
3945         tation.         tation.
3946    
3947         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-
3948         tern.  When your callout function is called, extract and save the  cur-         tern.   When your callout function is called, extract and save the cur-
3949         rent  matched  substring.  Then  return  1, which forces pcre_exec() to         rent matched substring. Then return  1,  which  forces  pcre_exec()  to
3950         backtrack and try other alternatives. Ultimately, when it runs  out  of         backtrack  and  try other alternatives. Ultimately, when it runs out of
3951         matches, pcre_exec() will yield PCRE_ERROR_NOMATCH.         matches, pcre_exec() will yield PCRE_ERROR_NOMATCH.
3952    
3953    
3954  OBTAINING AN ESTIMATE OF STACK USAGE  OBTAINING AN ESTIMATE OF STACK USAGE
3955    
3956         Matching  certain  patterns  using pcre_exec() can use a lot of process         Matching certain patterns using pcre_exec() can use a  lot  of  process
3957         stack, which in certain environments can be  rather  limited  in  size.         stack,  which  in  certain  environments can be rather limited in size.
3958         Some  users  find it helpful to have an estimate of the amount of stack         Some users find it helpful to have an estimate of the amount  of  stack
3959         that is used by pcre_exec(), to help  them  set  recursion  limits,  as         that  is  used  by  pcre_exec(),  to help them set recursion limits, as
3960         described  in  the pcrestack documentation. The estimate that is output         described in the pcrestack documentation. The estimate that  is  output
3961         by pcretest when called with the -m and -C options is obtained by call-         by pcretest when called with the -m and -C options is obtained by call-
3962         ing  pcre_exec with the values NULL, NULL, NULL, -999, and -999 for its         ing pcre_exec with the values NULL, NULL, NULL, -999, and -999 for  its
3963         first five arguments.         first five arguments.
3964    
3965         Normally, if  its  first  argument  is  NULL,  pcre_exec()  immediately         Normally,  if  its  first  argument  is  NULL,  pcre_exec() immediately
3966         returns  the negative error code PCRE_ERROR_NULL, but with this special         returns the negative error code PCRE_ERROR_NULL, but with this  special
3967         combination of arguments, it returns instead a  negative  number  whose         combination  of  arguments,  it returns instead a negative number whose
3968         absolute  value  is the approximate stack frame size in bytes. (A nega-         absolute value is the approximate stack frame size in bytes.  (A  nega-
3969         tive number is used so that it is clear that no  match  has  happened.)         tive  number  is  used so that it is clear that no match has happened.)
3970         The  value  is  approximate  because  in some cases, recursive calls to         The value is approximate because in  some  cases,  recursive  calls  to
3971         pcre_exec() occur when there are one or two additional variables on the         pcre_exec() occur when there are one or two additional variables on the
3972         stack.         stack.
3973    
3974         If  PCRE  has  been  compiled  to use the heap instead of the stack for         If PCRE has been compiled to use the heap  instead  of  the  stack  for
3975         recursion, the value returned  is  the  size  of  each  block  that  is         recursion,  the  value  returned  is  the  size  of  each block that is
3976         obtained from the heap.         obtained from the heap.
3977    
3978    
# Line 3929  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 3983  MATCHING A PATTERN: THE ALTERNATIVE FUNC
3983              int options, int *ovector, int ovecsize,              int options, int *ovector, int ovecsize,
3984              int *workspace, int wscount);              int *workspace, int wscount);
3985    
3986         The  function  pcre_dfa_exec()  is  called  to  match  a subject string         The function pcre_dfa_exec()  is  called  to  match  a  subject  string
3987         against a compiled pattern, using a matching algorithm that  scans  the         against  a  compiled pattern, using a matching algorithm that scans the
3988         subject  string  just  once, and does not backtrack. This has different         subject string just once, and does not backtrack.  This  has  different
3989         characteristics to the normal algorithm, and  is  not  compatible  with         characteristics  to  the  normal  algorithm, and is not compatible with
3990         Perl.  Some  of the features of PCRE patterns are not supported. Never-         Perl. Some of the features of PCRE patterns are not  supported.  Never-
3991         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
3992         a  discussion  of  the  two matching algorithms, and a list of features         a discussion of the two matching algorithms, and  a  list  of  features
3993         that pcre_dfa_exec() does not support, see the pcrematching  documenta-         that  pcre_dfa_exec() does not support, see the pcrematching documenta-
3994         tion.         tion.
3995    
3996         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
3997         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-
3998         ent  way,  and  this is described below. The other common arguments are         ent way, and this is described below. The other  common  arguments  are
3999         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
4000         repeated here.         repeated here.
4001    
4002         The  two  additional  arguments provide workspace for the function. The         The two additional arguments provide workspace for  the  function.  The
4003         workspace vector should contain at least 20 elements. It  is  used  for         workspace  vector  should  contain at least 20 elements. It is used for
4004         keeping  track  of  multiple  paths  through  the  pattern  tree.  More         keeping  track  of  multiple  paths  through  the  pattern  tree.  More
4005         workspace will be needed for patterns and subjects where  there  are  a         workspace  will  be  needed for patterns and subjects where there are a
4006         lot of potential matches.         lot of potential matches.
4007    
4008         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 3970  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 4024  MATCHING A PATTERN: THE ALTERNATIVE FUNC
4024    
4025     Option bits for pcre_dfa_exec()     Option bits for pcre_dfa_exec()
4026    
4027         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
4028         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-
4029         LINE_xxx,        PCRE_NOTBOL,        PCRE_NOTEOL,        PCRE_NOTEMPTY,         LINE_xxx,        PCRE_NOTBOL,        PCRE_NOTEOL,        PCRE_NOTEMPTY,
4030         PCRE_NOTEMPTY_ATSTART,      PCRE_NO_UTF8_CHECK,       PCRE_BSR_ANYCRLF,         PCRE_NOTEMPTY_ATSTART,       PCRE_NO_UTF8_CHECK,      PCRE_BSR_ANYCRLF,
4031         PCRE_BSR_UNICODE,  PCRE_NO_START_OPTIMIZE, PCRE_PARTIAL_HARD, PCRE_PAR-         PCRE_BSR_UNICODE, PCRE_NO_START_OPTIMIZE, PCRE_PARTIAL_HARD,  PCRE_PAR-
4032         TIAL_SOFT, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART.  All but  the  last         TIAL_SOFT,  PCRE_DFA_SHORTEST,  and PCRE_DFA_RESTART.  All but the last
4033         four  of  these  are  exactly  the  same  as  for pcre_exec(), so their         four of these are  exactly  the  same  as  for  pcre_exec(),  so  their
4034         description is not repeated here.         description is not repeated here.
4035    
4036           PCRE_PARTIAL_HARD           PCRE_PARTIAL_HARD
4037           PCRE_PARTIAL_SOFT           PCRE_PARTIAL_SOFT
4038    
4039         These have the same general effect as they do for pcre_exec(), but  the         These  have the same general effect as they do for pcre_exec(), but the
4040         details  are  slightly  different.  When  PCRE_PARTIAL_HARD  is set for         details are slightly  different.  When  PCRE_PARTIAL_HARD  is  set  for
4041         pcre_dfa_exec(), it returns PCRE_ERROR_PARTIAL if the end of  the  sub-         pcre_dfa_exec(),  it  returns PCRE_ERROR_PARTIAL if the end of the sub-
4042         ject  is  reached  and there is still at least one matching possibility         ject is reached and there is still at least  one  matching  possibility
4043         that requires additional characters. This happens even if some complete         that requires additional characters. This happens even if some complete
4044         matches have also been found. When PCRE_PARTIAL_SOFT is set, the return         matches have also been found. When PCRE_PARTIAL_SOFT is set, the return
4045         code PCRE_ERROR_NOMATCH is converted into PCRE_ERROR_PARTIAL if the end         code PCRE_ERROR_NOMATCH is converted into PCRE_ERROR_PARTIAL if the end
4046         of  the  subject  is  reached, there have been no complete matches, but         of the subject is reached, there have been  no  complete  matches,  but
4047         there is still at least one matching possibility. The  portion  of  the         there  is  still  at least one matching possibility. The portion of the
4048         string  that  was inspected when the longest partial match was found is         string that was inspected when the longest partial match was  found  is
4049         set as the first matching string  in  both  cases.   There  is  a  more         set  as  the  first  matching  string  in  both cases.  There is a more
4050         detailed  discussion  of partial and multi-segment matching, with exam-         detailed discussion of partial and multi-segment matching,  with  exam-
4051         ples, in the pcrepartial documentation.         ples, in the pcrepartial documentation.
4052    
4053           PCRE_DFA_SHORTEST           PCRE_DFA_SHORTEST
4054    
4055         Setting the PCRE_DFA_SHORTEST option causes the matching  algorithm  to         Setting  the  PCRE_DFA_SHORTEST option causes the matching algorithm to
4056         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-
4057         tive algorithm works, this is necessarily the shortest  possible  match         tive  algorithm  works, this is necessarily the shortest possible match
4058         at the first possible matching point in the subject string.         at the first possible matching point in the subject string.
4059    
4060           PCRE_DFA_RESTART           PCRE_DFA_RESTART
4061    
4062         When pcre_dfa_exec() returns a partial match, it is possible to call it         When pcre_dfa_exec() returns a partial match, it is possible to call it
4063         again, with additional subject characters, and have  it  continue  with         again,  with  additional  subject characters, and have it continue with
4064         the  same match. The PCRE_DFA_RESTART option requests this action; when         the same match. The PCRE_DFA_RESTART option requests this action;  when
4065         it is set, the workspace and wscount options must  reference  the  same         it  is  set,  the workspace and wscount options must reference the same
4066         vector  as  before  because data about the match so far is left in them         vector as before because data about the match so far is  left  in  them
4067         after a partial match. There is more discussion of this facility in the         after a partial match. There is more discussion of this facility in the
4068         pcrepartial documentation.         pcrepartial documentation.
4069    
4070     Successful returns from pcre_dfa_exec()     Successful returns from pcre_dfa_exec()
4071    
4072         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-
4073         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
4074         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
4075         matches are all initial substrings of the longer matches. For  example,         matches  are all initial substrings of the longer matches. For example,
4076         if the pattern         if the pattern
4077    
4078           <.*>           <.*>
# Line 4033  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 4087  MATCHING A PATTERN: THE ALTERNATIVE FUNC
4087           <something> <something else>           <something> <something else>
4088           <something> <something else> <something further>           <something> <something else> <something further>
4089    
4090         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,
4091         which is the number of matched substrings.  The  substrings  themselves         which  is  the  number of matched substrings. The substrings themselves
4092         are  returned  in  ovector. Each string uses two elements; the first is         are returned in ovector. Each string uses two elements;  the  first  is
4093         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
4094         fact,  all  the  strings  have the same start offset. (Space could have         fact, all the strings have the same start  offset.  (Space  could  have
4095         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
4096         compatibility  with  the  way pcre_exec() returns data, even though the         compatibility with the way pcre_exec() returns data,  even  though  the
4097         meaning of the strings is different.)         meaning of the strings is different.)
4098    
4099         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-
4100         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
4101         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
4102         filled  with  the  longest matches. Unlike pcre_exec(), pcre_dfa_exec()         filled with the longest matches.  Unlike  pcre_exec(),  pcre_dfa_exec()
4103         can use the entire ovector for returning matched strings.         can use the entire ovector for returning matched strings.
4104    
4105     Error returns from pcre_dfa_exec()     Error returns from pcre_dfa_exec()
4106    
4107         The pcre_dfa_exec() function returns a negative number when  it  fails.         The  pcre_dfa_exec()  function returns a negative number when it fails.
4108         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
4109         described above.  There are in addition the following errors  that  are         described  above.   There are in addition the following errors that are
4110         specific to pcre_dfa_exec():         specific to pcre_dfa_exec():
4111    
4112           PCRE_ERROR_DFA_UITEM      (-16)           PCRE_ERROR_DFA_UITEM      (-16)
4113    
4114         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-
4115         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
4116         reference.         reference.
4117    
4118           PCRE_ERROR_DFA_UCOND      (-17)           PCRE_ERROR_DFA_UCOND      (-17)
4119    
4120         This  return  is  given  if pcre_dfa_exec() encounters a condition item         This return is given if pcre_dfa_exec()  encounters  a  condition  item
4121         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
4122         in a specific group. These are not supported.         in a specific group. These are not supported.
4123    
4124           PCRE_ERROR_DFA_UMLIMIT    (-18)           PCRE_ERROR_DFA_UMLIMIT    (-18)
4125    
4126         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
4127         that contains a setting of  the  match_limit  or  match_limit_recursion         that  contains  a  setting  of the match_limit or match_limit_recursion
4128         fields.  This  is  not  supported (these fields are meaningless for DFA         fields. This is not supported (these fields  are  meaningless  for  DFA
4129         matching).         matching).
4130    
4131           PCRE_ERROR_DFA_WSSIZE     (-19)           PCRE_ERROR_DFA_WSSIZE     (-19)
4132    
4133         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
4134         workspace vector.         workspace vector.
4135    
4136           PCRE_ERROR_DFA_RECURSE    (-20)           PCRE_ERROR_DFA_RECURSE    (-20)
4137    
4138         When  a  recursive subpattern is processed, the matching function calls         When a recursive subpattern is processed, the matching  function  calls
4139         itself recursively, using private vectors for  ovector  and  workspace.         itself  recursively,  using  private vectors for ovector and workspace.
4140         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
4141         should be extremely rare, as a vector of size 1000 is used.         should be extremely rare, as a vector of size 1000 is used.
4142    
4143           PCRE_ERROR_DFA_BADRESTART (-30)           PCRE_ERROR_DFA_BADRESTART (-30)
4144    
4145         When pcre_dfa_exec() is called with the PCRE_DFA_RESTART  option,  some         When  pcre_dfa_exec()  is called with the PCRE_DFA_RESTART option, some
4146         plausibility  checks  are  made on the contents of the workspace, which         plausibility checks are made on the contents of  the  workspace,  which
4147         should contain data about the previous partial match. If any  of  these         should  contain  data about the previous partial match. If any of these
4148         checks fail, this error is given.         checks fail, this error is given.
4149    
4150    
4151  SEE ALSO  SEE ALSO
4152    
4153         pcre16(3),   pcre32(3),  pcrebuild(3),  pcrecallout(3),  pcrecpp(3)(3),         pcre16(3),  pcre32(3),  pcrebuild(3),  pcrecallout(3),   pcrecpp(3)(3),
4154         pcrematching(3), pcrepartial(3), pcreposix(3), pcreprecompile(3), pcre-         pcrematching(3), pcrepartial(3), pcreposix(3), pcreprecompile(3), pcre-
4155         sample(3), pcrestack(3).         sample(3), pcrestack(3).
4156    
# Line 4110  AUTHOR Line 4164  AUTHOR
4164    
4165  REVISION  REVISION
4166    
4167         Last updated: 27 February 2013         Last updated: 26 April 2013
4168         Copyright (c) 1997-2013 University of Cambridge.         Copyright (c) 1997-2013 University of Cambridge.
4169  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
4170    
# Line 4546  PCRE REGULAR EXPRESSION DETAILS Line 4600  PCRE REGULAR EXPRESSION DETAILS
4600         great  detail.  This  description  of  PCRE's  regular  expressions  is         great  detail.  This  description  of  PCRE's  regular  expressions  is
4601         intended as reference material.         intended as reference material.
4602    
4603           This document discusses the patterns that are supported  by  PCRE  when
4604           one    its    main   matching   functions,   pcre_exec()   (8-bit)   or
4605           pcre[16|32]_exec() (16- or 32-bit), is used. PCRE also has  alternative
4606           matching  functions,  pcre_dfa_exec()  and pcre[16|32_dfa_exec(), which
4607           match using a different algorithm that is not Perl-compatible. Some  of
4608           the  features  discussed  below  are not available when DFA matching is
4609           used. The advantages and disadvantages of  the  alternative  functions,
4610           and  how  they  differ  from the normal functions, are discussed in the
4611           pcrematching page.
4612    
4613    
4614    SPECIAL START-OF-PATTERN ITEMS
4615    
4616           A number of options that can be passed to pcre_compile()  can  also  be
4617           set by special items at the start of a pattern. These are not Perl-com-
4618           patible, but are provided to make these options accessible  to  pattern
4619           writers  who are not able to change the program that processes the pat-
4620           tern. Any number of these items  may  appear,  but  they  must  all  be
4621           together right at the start of the pattern string, and the letters must
4622           be in upper case.
4623    
4624       UTF support
4625    
4626         The original operation of PCRE was on strings of  one-byte  characters.         The original operation of PCRE was on strings of  one-byte  characters.
4627         However,  there  is  now also support for UTF-8 strings in the original         However,  there  is  now also support for UTF-8 strings in the original
4628         library, an extra library that supports  16-bit  and  UTF-16  character         library, an extra library that supports  16-bit  and  UTF-16  character
# Line 4562  PCRE REGULAR EXPRESSION DETAILS Line 4639  PCRE REGULAR EXPRESSION DETAILS
4639    
4640         (*UTF)  is  a  generic  sequence  that  can  be  used  with  any of the         (*UTF)  is  a  generic  sequence  that  can  be  used  with  any of the
4641         libraries.  Starting a pattern with such a sequence  is  equivalent  to         libraries.  Starting a pattern with such a sequence  is  equivalent  to
4642         setting  the  relevant option. This feature is not Perl-compatible. How         setting  the  relevant  option.  How setting a UTF mode affects pattern
4643         setting a UTF mode affects pattern matching  is  mentioned  in  several         matching is mentioned in several places below. There is also a  summary
4644         places  below.  There  is also a summary of features in the pcreunicode         of features in the pcreunicode page.
4645         page.  
4646           Some applications that allow their users to supply patterns may wish to
4647           restrict  them  to  non-UTF  data  for   security   reasons.   If   the
4648           PCRE_NEVER_UTF  option  is  set  at  compile  time, (*UTF) etc. are not
4649           allowed, and their appearance causes an error.
4650    
4651       Unicode property support
4652    
4653         Another special sequence that may appear at the start of a  pattern  or         Another special sequence that may appear at the start of a pattern is
        in combination with (*UTF8), (*UTF16), (*UTF32) or (*UTF) is:  
4654    
4655           (*UCP)           (*UCP)
4656    
4657         This  has  the  same  effect  as setting the PCRE_UCP option: it causes         This has the same effect as setting  the  PCRE_UCP  option:  it  causes
4658         sequences such as \d and \w to  use  Unicode  properties  to  determine         sequences  such  as  \d  and  \w to use Unicode properties to determine
4659         character types, instead of recognizing only characters with codes less         character types, instead of recognizing only characters with codes less
4660         than 128 via a lookup table.         than 128 via a lookup table.
4661    
4662         If a pattern starts with (*NO_START_OPT), it has  the  same  effect  as     Disabling start-up optimizations
        setting the PCRE_NO_START_OPTIMIZE option either at compile or matching  
        time. There are also some more of these special sequences that are con-  
        cerned with the handling of newlines; they are described below.  
   
        The  remainder  of  this  document discusses the patterns that are sup-  
        ported by PCRE  when  one  its  main  matching  functions,  pcre_exec()  
        (8-bit)  or  pcre[16|32]_exec() (16- or 32-bit), is used. PCRE also has  
        alternative      matching      functions,      pcre_dfa_exec()      and  
        pcre[16|32_dfa_exec(),  which match using a different algorithm that is  
        not Perl-compatible. Some of  the  features  discussed  below  are  not  
        available  when  DFA matching is used. The advantages and disadvantages  
        of the alternative functions, and how they differ from the normal func-  
        tions, are discussed in the pcrematching page.  
   
   
 EBCDIC CHARACTER CODES  
   
        PCRE  can  be compiled to run in an environment that uses EBCDIC as its  
        character code rather than ASCII or Unicode (typically a mainframe sys-  
        tem).  In  the  sections below, character code values are ASCII or Uni-  
        code; in an EBCDIC environment these characters may have different code  
        values, and there are no code points greater than 255.  
4663    
4664           If  a  pattern  starts  with (*NO_START_OPT), it has the same effect as
4665           setting the PCRE_NO_START_OPTIMIZE option either at compile or matching
4666           time.
4667    
4668  NEWLINE CONVENTIONS     Newline conventions
4669    
4670         PCRE  supports five different conventions for indicating line breaks in         PCRE  supports five different conventions for indicating line breaks in
4671         strings: a single CR (carriage return) character, a  single  LF  (line-         strings: a single CR (carriage return) character, a  single  LF  (line-
# Line 4627  NEWLINE CONVENTIONS Line 4690  NEWLINE CONVENTIONS
4690           (*CR)a.b           (*CR)a.b
4691    
4692         changes the convention to CR. That pattern matches "a\nb" because LF is         changes the convention to CR. That pattern matches "a\nb" because LF is
4693         no longer a newline. Note that these special settings,  which  are  not         no longer a newline. If more than one of these settings is present, the
4694         Perl-compatible,  are  recognized  only at the very start of a pattern,         last one is used.
        and that they must be in upper case.  If  more  than  one  of  them  is  
        present, the last one is used.  
4695    
4696         The  newline  convention affects where the circumflex and dollar asser-         The  newline  convention affects where the circumflex and dollar asser-
4697         tions are true. It also affects the interpretation of the dot metachar-         tions are true. It also affects the interpretation of the dot metachar-
# Line 4641  NEWLINE CONVENTIONS Line 4702  NEWLINE CONVENTIONS
4702         line  sequences"  below.  A change of \R setting can be combined with a         line  sequences"  below.  A change of \R setting can be combined with a
4703         change of newline convention.         change of newline convention.
4704    
4705       Setting match and recursion limits
4706    
4707           The caller of pcre_exec() can set a limit on the number  of  times  the
4708           internal  match() function is called and on the maximum depth of recur-
4709           sive calls. These facilities are provided to catch runaway matches that
4710           are provoked by patterns with huge matching trees (a typical example is
4711           a pattern with nested unlimited repeats) and to avoid  running  out  of
4712           system  stack  by  too  much  recursion.  When  one  of these limits is
4713           reached, pcre_exec() gives an error return. The limits can also be  set
4714           by items at the start of the pattern of the form
4715    
4716             (*LIMIT_MATCH=d)
4717             (*LIMIT_RECURSION=d)
4718    
4719           where d is any number of decimal digits. However, the value of the set-
4720           ting must be less than the value set by the caller of  pcre_exec()  for
4721           it to have any effect. In other words, the pattern writer can lower the
4722           limit set by the programmer, but not raise it. If there  is  more  than
4723           one setting of one of these limits, the lower value is used.
4724    
4725    
4726    EBCDIC CHARACTER CODES
4727    
4728           PCRE  can  be compiled to run in an environment that uses EBCDIC as its
4729           character code rather than ASCII or Unicode (typically a mainframe sys-
4730           tem).  In  the  sections below, character code values are ASCII or Uni-
4731           code; in an EBCDIC environment these characters may have different code
4732           values, and there are no code points greater than 255.
4733    
4734    
4735  CHARACTERS AND METACHARACTERS  CHARACTERS AND METACHARACTERS
4736    
4737         A regular expression is a pattern that is  matched  against  a  subject         A  regular  expression  is  a pattern that is matched against a subject
4738         string  from  left  to right. Most characters stand for themselves in a         string from left to right. Most characters stand for  themselves  in  a
4739         pattern, and match the corresponding characters in the  subject.  As  a         pattern,  and  match  the corresponding characters in the subject. As a
4740         trivial example, the pattern         trivial example, the pattern
4741    
4742           The quick brown fox           The quick brown fox
4743    
4744         matches a portion of a subject string that is identical to itself. When         matches a portion of a subject string that is identical to itself. When
4745         caseless matching is specified (the PCRE_CASELESS option), letters  are         caseless  matching is specified (the PCRE_CASELESS option), letters are
4746         matched  independently  of case. In a UTF mode, PCRE always understands         matched independently of case. In a UTF mode, PCRE  always  understands
4747         the concept of case for characters whose values are less than  128,  so         the  concept  of case for characters whose values are less than 128, so
4748         caseless  matching  is always possible. For characters with higher val-         caseless matching is always possible. For characters with  higher  val-
4749         ues, the concept of case is supported if PCRE is compiled with  Unicode         ues,  the concept of case is supported if PCRE is compiled with Unicode
4750         property  support,  but  not  otherwise.   If  you want to use caseless         property support, but not otherwise.   If  you  want  to  use  caseless
4751         matching for characters 128 and above, you must  ensure  that  PCRE  is         matching  for  characters  128  and above, you must ensure that PCRE is
4752         compiled with Unicode property support as well as with UTF support.         compiled with Unicode property support as well as with UTF support.
4753    
4754         The  power  of  regular  expressions  comes from the ability to include         The power of regular expressions comes  from  the  ability  to  include
4755         alternatives and repetitions in the pattern. These are encoded  in  the         alternatives  and  repetitions in the pattern. These are encoded in the
4756         pattern by the use of metacharacters, which do not stand for themselves         pattern by the use of metacharacters, which do not stand for themselves
4757         but instead are interpreted in some special way.         but instead are interpreted in some special way.
4758    
4759         There are two different sets of metacharacters: those that  are  recog-         There  are  two different sets of metacharacters: those that are recog-
4760         nized  anywhere in the pattern except within square brackets, and those         nized anywhere in the pattern except within square brackets, and  those
4761         that are recognized within square brackets.  Outside  square  brackets,         that  are  recognized  within square brackets. Outside square brackets,
4762         the metacharacters are as follows:         the metacharacters are as follows:
4763    
4764           \      general escape character with several uses           \      general escape character with several uses
# Line 4687  CHARACTERS AND METACHARACTERS Line 4777  CHARACTERS AND METACHARACTERS
4777                  also "possessive quantifier"                  also "possessive quantifier"
4778           {      start min/max quantifier           {      start min/max quantifier
4779    
4780         Part  of  a  pattern  that is in square brackets is called a "character         Part of a pattern that is in square brackets  is  called  a  "character
4781         class". In a character class the only metacharacters are:         class". In a character class the only metacharacters are:
4782    
4783           \      general escape character           \      general escape character
# Line 4704  BACKSLASH Line 4794  BACKSLASH
4794    
4795         The backslash character has several uses. Firstly, if it is followed by         The backslash character has several uses. Firstly, if it is followed by
4796         a character that is not a number or a letter, it takes away any special         a character that is not a number or a letter, it takes away any special
4797         meaning that character may have. This use of  backslash  as  an  escape         meaning  that  character  may  have. This use of backslash as an escape
4798         character applies both inside and outside character classes.         character applies both inside and outside character classes.
4799    
4800         For  example,  if  you want to match a * character, you write \* in the         For example, if you want to match a * character, you write  \*  in  the
4801         pattern.  This escaping action applies whether  or  not  the  following         pattern.   This  escaping  action  applies whether or not the following
4802         character  would  otherwise be interpreted as a metacharacter, so it is         character would otherwise be interpreted as a metacharacter, so  it  is
4803         always safe to precede a non-alphanumeric  with  backslash  to  specify         always  safe  to  precede  a non-alphanumeric with backslash to specify
4804         that  it stands for itself. In particular, if you want to match a back-         that it stands for itself. In particular, if you want to match a  back-
4805         slash, you write \\.         slash, you write \\.
4806    
4807         In a UTF mode, only ASCII numbers and letters have any special  meaning         In  a UTF mode, only ASCII numbers and letters have any special meaning
4808         after  a  backslash.  All  other characters (in particular, those whose         after a backslash. All other characters  (in  particular,  those  whose
4809         codepoints are greater than 127) are treated as literals.         codepoints are greater than 127) are treated as literals.
4810    
4811         If a pattern is compiled with the PCRE_EXTENDED option, white space  in         If  a pattern is compiled with the PCRE_EXTENDED option, white space in
4812         the  pattern (other than in a character class) and characters between a         the pattern (other than in a character class) and characters between  a
4813         # outside a character class and the next newline are ignored. An escap-         # outside a character class and the next newline are ignored. An escap-
4814         ing  backslash  can  be used to include a white space or # character as         ing backslash can be used to include a white space or  #  character  as
4815         part of the pattern.         part of the pattern.
4816    
4817         If you want to remove the special meaning from a  sequence  of  charac-         If  you  want  to remove the special meaning from a sequence of charac-
4818         ters,  you can do so by putting them between \Q and \E. This is differ-         ters, you can do so by putting them between \Q and \E. This is  differ-
4819         ent from Perl in that $ and  @  are  handled  as  literals  in  \Q...\E         ent  from  Perl  in  that  $  and  @ are handled as literals in \Q...\E
4820         sequences  in  PCRE, whereas in Perl, $ and @ cause variable interpola-         sequences in PCRE, whereas in Perl, $ and @ cause  variable  interpola-
4821         tion. Note the following examples:         tion. Note the following examples:
4822    
4823           Pattern            PCRE matches   Perl matches           Pattern            PCRE matches   Perl matches
# Line 4737  BACKSLASH Line 4827  BACKSLASH
4827           \Qabc\$xyz\E       abc\$xyz       abc\$xyz           \Qabc\$xyz\E       abc\$xyz       abc\$xyz
4828           \Qabc\E\$\Qxyz\E   abc$xyz        abc$xyz           \Qabc\E\$\Qxyz\E   abc$xyz        abc$xyz
4829    
4830         The \Q...\E sequence is recognized both inside  and  outside  character         The  \Q...\E  sequence  is recognized both inside and outside character
4831         classes.   An  isolated \E that is not preceded by \Q is ignored. If \Q         classes.  An isolated \E that is not preceded by \Q is ignored.  If  \Q
4832         is not followed by \E later in the pattern, the literal  interpretation         is  not followed by \E later in the pattern, the literal interpretation
4833         continues  to  the  end  of  the pattern (that is, \E is assumed at the         continues to the end of the pattern (that is,  \E  is  assumed  at  the
4834         end). If the isolated \Q is inside a character class,  this  causes  an         end).  If  the  isolated \Q is inside a character class, this causes an
4835         error, because the character class is not terminated.         error, because the character class is not terminated.
4836    
4837     Non-printing characters     Non-printing characters
4838    
4839         A second use of backslash provides a way of encoding non-printing char-         A second use of backslash provides a way of encoding non-printing char-
4840         acters in patterns in a visible manner. There is no restriction on  the         acters  in patterns in a visible manner. There is no restriction on the
4841         appearance  of non-printing characters, apart from the binary zero that         appearance of non-printing characters, apart from the binary zero  that
4842         terminates a pattern, but when a pattern  is  being  prepared  by  text         terminates  a  pattern,  but  when  a pattern is being prepared by text
4843         editing,  it  is  often  easier  to  use  one  of  the following escape         editing, it is  often  easier  to  use  one  of  the  following  escape
4844         sequences than the binary character it represents:         sequences than the binary character it represents:
4845    
4846           \a        alarm, that is, the BEL character (hex 07)           \a        alarm, that is, the BEL character (hex 07)
# Line 4765  BACKSLASH Line 4855  BACKSLASH
4855           \x{hhh..} character with hex code hhh.. (non-JavaScript mode)           \x{hhh..} character with hex code hhh.. (non-JavaScript mode)
4856           \uhhhh    character with hex code hhhh (JavaScript mode only)           \uhhhh    character with hex code hhhh (JavaScript mode only)
4857    
4858         The precise effect of \cx on ASCII characters is as follows: if x is  a         The  precise effect of \cx on ASCII characters is as follows: if x is a
4859         lower  case  letter,  it  is converted to upper case. Then bit 6 of the         lower case letter, it is converted to upper case. Then  bit  6  of  the
4860         character (hex 40) is inverted. Thus \cA to \cZ become hex 01 to hex 1A         character (hex 40) is inverted. Thus \cA to \cZ become hex 01 to hex 1A
4861         (A  is  41, Z is 5A), but \c{ becomes hex 3B ({ is 7B), and \c; becomes         (A is 41, Z is 5A), but \c{ becomes hex 3B ({ is 7B), and  \c;  becomes
4862         hex 7B (; is 3B). If the data item (byte or 16-bit value) following  \c         hex  7B (; is 3B). If the data item (byte or 16-bit value) following \c
4863         has  a  value greater than 127, a compile-time error occurs. This locks         has a value greater than 127, a compile-time error occurs.  This  locks
4864         out non-ASCII characters in all modes.         out non-ASCII characters in all modes.
4865    
4866         The \c facility was designed for use with ASCII  characters,  but  with         The  \c  facility  was designed for use with ASCII characters, but with
4867         the  extension  to  Unicode it is even less useful than it once was. It         the extension to Unicode it is even less useful than it  once  was.  It
4868         is, however, recognized when PCRE is compiled  in  EBCDIC  mode,  where         is,  however,  recognized  when  PCRE is compiled in EBCDIC mode, where
4869         data  items  are always bytes. In this mode, all values are valid after         data items are always bytes. In this mode, all values are  valid  after
4870         \c. If the next character is a lower case letter, it  is  converted  to         \c.  If  the  next character is a lower case letter, it is converted to
4871         upper  case.  Then  the  0xc0  bits  of the byte are inverted. Thus \cA         upper case. Then the 0xc0 bits of  the  byte  are  inverted.  Thus  \cA
4872         becomes hex 01, as in ASCII (A is C1), but because the  EBCDIC  letters         becomes  hex  01, as in ASCII (A is C1), but because the EBCDIC letters
4873         are  disjoint,  \cZ becomes hex 29 (Z is E9), and other characters also         are disjoint, \cZ becomes hex 29 (Z is E9), and other  characters  also
4874         generate different values.         generate different values.
4875    
4876         By default, after \x, from zero to  two  hexadecimal  digits  are  read         By  default,  after  \x,  from  zero to two hexadecimal digits are read
4877         (letters can be in upper or lower case). Any number of hexadecimal dig-         (letters can be in upper or lower case). Any number of hexadecimal dig-
4878         its may appear between \x{ and }, but the character code is constrained         its may appear between \x{ and }, but the character code is constrained
4879         as follows:         as follows:
# Line 4795  BACKSLASH Line 4885  BACKSLASH
4885           32-bit non-UTF mode   less than 0x80000000           32-bit non-UTF mode   less than 0x80000000
4886           32-bit UTF-32 mode    less than 0x10ffff and a valid codepoint           32-bit UTF-32 mode    less than 0x10ffff and a valid codepoint
4887    
4888         Invalid  Unicode  codepoints  are  the  range 0xd800 to 0xdfff (the so-         Invalid Unicode codepoints are the range  0xd800  to  0xdfff  (the  so-
4889         called "surrogate" codepoints), and 0xffef.         called "surrogate" codepoints), and 0xffef.
4890    
4891         If characters other than hexadecimal digits appear between \x{  and  },         If  characters  other than hexadecimal digits appear between \x{ and },
4892         or if there is no terminating }, this form of escape is not recognized.         or if there is no terminating }, this form of escape is not recognized.
4893         Instead, the initial \x will be  interpreted  as  a  basic  hexadecimal         Instead,  the  initial  \x  will  be interpreted as a basic hexadecimal
4894         escape,  with  no  following  digits, giving a character whose value is         escape, with no following digits, giving a  character  whose  value  is
4895         zero.         zero.
4896    
4897         If the PCRE_JAVASCRIPT_COMPAT option is set, the interpretation  of  \x         If  the  PCRE_JAVASCRIPT_COMPAT option is set, the interpretation of \x
4898         is  as  just described only when it is followed by two hexadecimal dig-         is as just described only when it is followed by two  hexadecimal  dig-
4899         its.  Otherwise, it matches a  literal  "x"  character.  In  JavaScript         its.   Otherwise,  it  matches  a  literal "x" character. In JavaScript
4900         mode, support for code points greater than 256 is provided by \u, which         mode, support for code points greater than 256 is provided by \u, which
4901         must be followed by four hexadecimal digits;  otherwise  it  matches  a         must  be  followed  by  four hexadecimal digits; otherwise it matches a
4902         literal  "u"  character.  Character codes specified by \u in JavaScript         literal "u" character.  Character codes specified by \u  in  JavaScript
4903         mode are constrained in the same was as those specified by \x  in  non-         mode  are  constrained in the same was as those specified by \x in non-
4904         JavaScript mode.         JavaScript mode.
4905    
4906         Characters whose value is less than 256 can be defined by either of the         Characters whose value is less than 256 can be defined by either of the
4907         two syntaxes for \x (or by \u in JavaScript mode). There is no  differ-         two  syntaxes for \x (or by \u in JavaScript mode). There is no differ-
4908         ence in the way they are handled. For example, \xdc is exactly the same         ence in the way they are handled. For example, \xdc is exactly the same
4909         as \x{dc} (or \u00dc in JavaScript mode).         as \x{dc} (or \u00dc in JavaScript mode).
4910    
4911         After \0 up to two further octal digits are read. If  there  are  fewer         After  \0  up  to two further octal digits are read. If there are fewer
4912         than  two  digits,  just  those  that  are  present  are used. Thus the         than two digits, just  those  that  are  present  are  used.  Thus  the
4913         sequence \0\x\07 specifies two binary zeros followed by a BEL character         sequence \0\x\07 specifies two binary zeros followed by a BEL character
4914         (code  value 7). Make sure you supply two digits after the initial zero         (code value 7). Make sure you supply two digits after the initial  zero
4915         if the pattern character that follows is itself an octal digit.         if the pattern character that follows is itself an octal digit.
4916    
4917         The handling of a backslash followed by a digit other than 0 is compli-         The handling of a backslash followed by a digit other than 0 is compli-
4918         cated.  Outside a character class, PCRE reads it and any following dig-         cated.  Outside a character class, PCRE reads it and any following dig-
4919         its as a decimal number. If the number is less than  10,  or  if  there         its  as  a  decimal  number. If the number is less than 10, or if there
4920         have been at least that many previous capturing left parentheses in the         have been at least that many previous capturing left parentheses in the
4921         expression, the entire  sequence  is  taken  as  a  back  reference.  A         expression,  the  entire  sequence  is  taken  as  a  back reference. A
4922         description  of how this works is given later, following the discussion         description of how this works is given later, following the  discussion
4923         of parenthesized subpatterns.         of parenthesized subpatterns.
4924    
4925         Inside a character class, or if the decimal number is  greater  than  9         Inside  a  character  class, or if the decimal number is greater than 9
4926         and  there have not been that many capturing subpatterns, PCRE re-reads         and there have not been that many capturing subpatterns, PCRE  re-reads
4927         up to three octal digits following the backslash, and uses them to gen-         up to three octal digits following the backslash, and uses them to gen-
4928         erate a data character. Any subsequent digits stand for themselves. The         erate a data character. Any subsequent digits stand for themselves. The
4929         value of the character is constrained in the  same  way  as  characters         value  of  the  character  is constrained in the same way as characters
4930         specified in hexadecimal.  For example:         specified in hexadecimal.  For example:
4931    
4932           \040   is another way of writing an ASCII space           \040   is another way of writing an ASCII space
# Line 4854  BACKSLASH Line 4944  BACKSLASH
4944           \81    is either a back reference, or a binary zero           \81    is either a back reference, or a binary zero
4945                     followed by the two characters "8" and "1"                     followed by the two characters "8" and "1"
4946    
4947         Note  that  octal  values of 100 or greater must not be introduced by a         Note that octal values of 100 or greater must not be  introduced  by  a
4948         leading zero, because no more than three octal digits are ever read.         leading zero, because no more than three octal digits are ever read.
4949    
4950         All the sequences that define a single character value can be used both         All the sequences that define a single character value can be used both
4951         inside  and  outside character classes. In addition, inside a character         inside and outside character classes. In addition, inside  a  character
4952         class, \b is interpreted as the backspace character (hex 08).         class, \b is interpreted as the backspace character (hex 08).
4953    
4954         \N is not allowed in a character class. \B, \R, and \X are not  special         \N  is not allowed in a character class. \B, \R, and \X are not special
4955         inside  a  character  class.  Like other unrecognized escape sequences,         inside a character class. Like  other  unrecognized  escape  sequences,
4956         they are treated as  the  literal  characters  "B",  "R",  and  "X"  by         they  are  treated  as  the  literal  characters  "B",  "R", and "X" by
4957         default,  but cause an error if the PCRE_EXTRA option is set. Outside a         default, but cause an error if the PCRE_EXTRA option is set. Outside  a
4958         character class, these sequences have different meanings.         character class, these sequences have different meanings.
4959    
4960     Unsupported escape sequences     Unsupported escape sequences
4961    
4962         In Perl, the sequences \l, \L, \u, and \U are recognized by its  string         In  Perl, the sequences \l, \L, \u, and \U are recognized by its string
4963         handler  and  used  to  modify  the  case  of  following characters. By         handler and used  to  modify  the  case  of  following  characters.  By
4964         default, PCRE does not support these escape sequences. However, if  the         default,  PCRE does not support these escape sequences. However, if the
4965         PCRE_JAVASCRIPT_COMPAT  option  is set, \U matches a "U" character, and         PCRE_JAVASCRIPT_COMPAT option is set, \U matches a "U"  character,  and
4966         \u can be used to define a character by code point, as described in the         \u can be used to define a character by code point, as described in the
4967         previous section.         previous section.
4968    
4969     Absolute and relative back references     Absolute and relative back references
4970    
4971         The  sequence  \g followed by an unsigned or a negative number, option-         The sequence \g followed by an unsigned or a negative  number,  option-
4972         ally enclosed in braces, is an absolute or relative back  reference.  A         ally  enclosed  in braces, is an absolute or relative back reference. A
4973         named back reference can be coded as \g{name}. Back references are dis-         named back reference can be coded as \g{name}. Back references are dis-
4974         cussed later, following the discussion of parenthesized subpatterns.         cussed later, following the discussion of parenthesized subpatterns.
4975    
4976     Absolute and relative subroutine calls     Absolute and relative subroutine calls
4977    
4978         For compatibility with Oniguruma, the non-Perl syntax \g followed by  a         For  compatibility with Oniguruma, the non-Perl syntax \g followed by a
4979         name or a number enclosed either in angle brackets or single quotes, is         name or a number enclosed either in angle brackets or single quotes, is
4980         an alternative syntax for referencing a subpattern as  a  "subroutine".         an  alternative  syntax for referencing a subpattern as a "subroutine".
4981         Details  are  discussed  later.   Note  that  \g{...} (Perl syntax) and         Details are discussed later.   Note  that  \g{...}  (Perl  syntax)  and
4982         \g<...> (Oniguruma syntax) are not synonymous. The  former  is  a  back         \g<...>  (Oniguruma  syntax)  are  not synonymous. The former is a back
4983         reference; the latter is a subroutine call.         reference; the latter is a subroutine call.
4984    
4985     Generic character types     Generic character types
# Line 4908  BACKSLASH Line 4998  BACKSLASH
4998           \W     any "non-word" character           \W     any "non-word" character
4999    
5000         There is also the single sequence \N, which matches a non-newline char-         There is also the single sequence \N, which matches a non-newline char-
5001         acter.  This is the same as the "." metacharacter when  PCRE_DOTALL  is         acter.   This  is the same as the "." metacharacter when PCRE_DOTALL is
5002         not  set.  Perl also uses \N to match characters by name; PCRE does not         not set. Perl also uses \N to match characters by name; PCRE  does  not
5003         support this.         support this.
5004    
5005         Each pair of lower and upper case escape sequences partitions the  com-         Each  pair of lower and upper case escape sequences partitions the com-
5006         plete  set  of  characters  into two disjoint sets. Any given character         plete set of characters into two disjoint  sets.  Any  given  character
5007         matches one, and only one, of each pair. The sequences can appear  both         matches  one, and only one, of each pair. The sequences can appear both
5008         inside  and outside character classes. They each match one character of         inside and outside character classes. They each match one character  of
5009         the appropriate type. If the current matching point is at  the  end  of         the  appropriate  type.  If the current matching point is at the end of
5010         the  subject string, all of them fail, because there is no character to         the subject string, all of them fail, because there is no character  to
5011         match.         match.
5012    
5013         For compatibility with Perl, \s does not match the VT  character  (code         For  compatibility  with Perl, \s does not match the VT character (code
5014         11).   This makes it different from the the POSIX "space" class. The \s         11).  This makes it different from the the POSIX "space" class. The  \s
5015         characters are HT (9), LF (10), FF (12), CR (13), and  space  (32).  If         characters  are  HT  (9), LF (10), FF (12), CR (13), and space (32). If
5016         "use locale;" is included in a Perl script, \s may match the VT charac-         "use locale;" is included in a Perl script, \s may match the VT charac-
5017         ter. In PCRE, it never does.         ter. In PCRE, it never does.
5018    
5019         A "word" character is an underscore or any character that is  a  letter         A  "word"  character is an underscore or any character that is a letter
5020         or  digit.   By  default,  the definition of letters and digits is con-         or digit.  By default, the definition of letters  and  digits  is  con-
5021         trolled by PCRE's low-valued character tables, and may vary if  locale-         trolled  by PCRE's low-valued character tables, and may vary if locale-
5022         specific  matching is taking place (see "Locale support" in the pcreapi         specific matching is taking place (see "Locale support" in the  pcreapi
5023         page). For example, in a French locale such  as  "fr_FR"  in  Unix-like         page).  For  example,  in  a French locale such as "fr_FR" in Unix-like
5024         systems,  or "french" in Windows, some character codes greater than 128         systems, or "french" in Windows, some character codes greater than  128
5025         are used for accented letters, and these are then matched  by  \w.  The         are  used  for  accented letters, and these are then matched by \w. The
5026         use of locales with Unicode is discouraged.         use of locales with Unicode is discouraged.
5027    
5028         By  default,  in  a  UTF  mode, characters with values greater than 128         By default, in a UTF mode, characters  with  values  greater  than  128
5029         never match \d, \s, or \w, and always  match  \D,  \S,  and  \W.  These         never  match  \d,  \s,  or  \w,  and always match \D, \S, and \W. These
5030         sequences  retain  their  original meanings from before UTF support was         sequences retain their original meanings from before  UTF  support  was
5031         available, mainly for efficiency reasons. However, if PCRE is  compiled         available,  mainly for efficiency reasons. However, if PCRE is compiled
5032         with  Unicode property support, and the PCRE_UCP option is set, the be-         with Unicode property support, and the PCRE_UCP option is set, the  be-
5033         haviour is changed so that Unicode properties  are  used  to  determine         haviour  is  changed  so  that Unicode properties are used to determine
5034         character types, as follows:         character types, as follows:
5035    
5036           \d  any character that \p{Nd} matches (decimal digit)           \d  any character that \p{Nd} matches (decimal digit)
5037           \s  any character that \p{Z} matches, plus HT, LF, FF, CR           \s  any character that \p{Z} matches, plus HT, LF, FF, CR
5038           \w  any character that \p{L} or \p{N} matches, plus underscore           \w  any character that \p{L} or \p{N} matches, plus underscore
5039    
5040         The  upper case escapes match the inverse sets of characters. Note that         The upper case escapes match the inverse sets of characters. Note  that
5041         \d matches only decimal digits, whereas \w matches any  Unicode  digit,         \d  matches  only decimal digits, whereas \w matches any Unicode digit,
5042         as  well as any Unicode letter, and underscore. Note also that PCRE_UCP         as well as any Unicode letter, and underscore. Note also that  PCRE_UCP
5043         affects \b, and \B because they are defined in  terms  of  \w  and  \W.         affects  \b,  and  \B  because  they are defined in terms of \w and \W.
5044         Matching these sequences is noticeably slower when PCRE_UCP is set.         Matching these sequences is noticeably slower when PCRE_UCP is set.
5045    
5046         The  sequences  \h, \H, \v, and \V are features that were added to Perl         The sequences \h, \H, \v, and \V are features that were added  to  Perl
5047         at release 5.10. In contrast to the other sequences, which  match  only         at  release  5.10. In contrast to the other sequences, which match only
5048         ASCII  characters  by  default,  these always match certain high-valued         ASCII characters by default, these  always  match  certain  high-valued
5049         codepoints, whether or not PCRE_UCP is set. The horizontal space  char-         codepoints,  whether or not PCRE_UCP is set. The horizontal space char-
5050         acters are:         acters are:
5051    
5052           U+0009     Horizontal tab (HT)           U+0009     Horizontal tab (HT)
# Line 4994  BACKSLASH Line 5084  BACKSLASH
5084    
5085     Newline sequences     Newline sequences
5086    
5087         Outside a character class, by default, the escape sequence  \R  matches         Outside  a  character class, by default, the escape sequence \R matches
5088         any  Unicode newline sequence. In 8-bit non-UTF-8 mode \R is equivalent         any Unicode newline sequence. In 8-bit non-UTF-8 mode \R is  equivalent
5089         to the following:         to the following:
5090    
5091           (?>\r\n|\n|\x0b|\f|\r|\x85)           (?>\r\n|\n|\x0b|\f|\r|\x85)
5092    
5093         This is an example of an "atomic group", details  of  which  are  given         This  is  an  example  of an "atomic group", details of which are given
5094         below.  This particular group matches either the two-character sequence         below.  This particular group matches either the two-character sequence
5095         CR followed by LF, or  one  of  the  single  characters  LF  (linefeed,         CR  followed  by  LF,  or  one  of  the single characters LF (linefeed,
5096         U+000A),  VT  (vertical  tab, U+000B), FF (form feed, U+000C), CR (car-         U+000A), VT (vertical tab, U+000B), FF (form feed,  U+000C),  CR  (car-
5097         riage return, U+000D), or NEL (next line,  U+0085).  The  two-character         riage  return,  U+000D),  or NEL (next line, U+0085). The two-character
5098         sequence is treated as a single unit that cannot be split.         sequence is treated as a single unit that cannot be split.
5099    
5100         In  other modes, two additional characters whose codepoints are greater         In other modes, two additional characters whose codepoints are  greater
5101         than 255 are added: LS (line separator, U+2028) and PS (paragraph sepa-         than 255 are added: LS (line separator, U+2028) and PS (paragraph sepa-
5102         rator,  U+2029).   Unicode character property support is not needed for         rator, U+2029).  Unicode character property support is not  needed  for
5103         these characters to be recognized.         these characters to be recognized.
5104    
5105         It is possible to restrict \R to match only CR, LF, or CRLF (instead of         It is possible to restrict \R to match only CR, LF, or CRLF (instead of
5106         the  complete  set  of  Unicode  line  endings)  by  setting the option         the complete set  of  Unicode  line  endings)  by  setting  the  option
5107         PCRE_BSR_ANYCRLF either at compile time or when the pattern is matched.         PCRE_BSR_ANYCRLF either at compile time or when the pattern is matched.
5108         (BSR is an abbrevation for "backslash R".) This can be made the default         (BSR is an abbrevation for "backslash R".) This can be made the default
5109         when PCRE is built; if this is the case, the  other  behaviour  can  be         when  PCRE  is  built;  if this is the case, the other behaviour can be
5110         requested  via  the  PCRE_BSR_UNICODE  option.   It is also possible to         requested via the PCRE_BSR_UNICODE option.   It  is  also  possible  to
5111         specify these settings by starting a pattern string  with  one  of  the         specify  these  settings  by  starting a pattern string with one of the
5112         following sequences:         following sequences:
5113    
5114           (*BSR_ANYCRLF)   CR, LF, or CRLF only           (*BSR_ANYCRLF)   CR, LF, or CRLF only
5115           (*BSR_UNICODE)   any Unicode newline sequence           (*BSR_UNICODE)   any Unicode newline sequence
5116    
5117         These override the default and the options given to the compiling func-         These override the default and the options given to the compiling func-
5118         tion, but they can themselves be  overridden  by  options  given  to  a         tion,  but  they  can  themselves  be  overridden by options given to a
5119         matching  function.  Note  that  these  special settings, which are not         matching function. Note that these  special  settings,  which  are  not
5120         Perl-compatible, are recognized only at the very start  of  a  pattern,         Perl-compatible,  are  recognized  only at the very start of a pattern,
5121         and  that  they  must  be  in  upper  case. If more than one of them is         and that they must be in upper case.  If  more  than  one  of  them  is
5122         present, the last one is used. They can be combined with  a  change  of         present,  the  last  one is used. They can be combined with a change of
5123         newline convention; for example, a pattern can start with:         newline convention; for example, a pattern can start with:
5124    
5125           (*ANY)(*BSR_ANYCRLF)           (*ANY)(*BSR_ANYCRLF)
5126    
5127         They  can also be combined with the (*UTF8), (*UTF16), (*UTF32), (*UTF)         They can also be combined with the (*UTF8), (*UTF16), (*UTF32),  (*UTF)
5128         or (*UCP) special sequences. Inside a character class, \R is treated as         or (*UCP) special sequences. Inside a character class, \R is treated as
5129         an  unrecognized  escape  sequence,  and  so  matches the letter "R" by         an unrecognized escape sequence, and  so  matches  the  letter  "R"  by
5130         default, but causes an error if PCRE_EXTRA is set.         default, but causes an error if PCRE_EXTRA is set.
5131    
5132     Unicode character properties     Unicode character properties
5133    
5134         When PCRE is built with Unicode character property support, three addi-         When PCRE is built with Unicode character property support, three addi-
5135         tional  escape sequences that match characters with specific properties         tional escape sequences that match characters with specific  properties
5136         are available.  When in 8-bit non-UTF-8 mode, these  sequences  are  of         are  available.   When  in 8-bit non-UTF-8 mode, these sequences are of
5137         course  limited  to  testing  characters whose codepoints are less than         course limited to testing characters whose  codepoints  are  less  than
5138         256, but they do work in this mode.  The extra escape sequences are:         256, but they do work in this mode.  The extra escape sequences are:
5139    
5140           \p{xx}   a character with the xx property           \p{xx}   a character with the xx property
5141           \P{xx}   a character without the xx property           \P{xx}   a character without the xx property
5142           \X       a Unicode extended grapheme cluster           \X       a Unicode extended grapheme cluster
5143    
5144         The property names represented by xx above are limited to  the  Unicode         The  property  names represented by xx above are limited to the Unicode
5145         script names, the general category properties, "Any", which matches any         script names, the general category properties, "Any", which matches any
5146         character  (including  newline),  and  some  special  PCRE   properties         character   (including  newline),  and  some  special  PCRE  properties
5147         (described  in the next section).  Other Perl properties such as "InMu-         (described in the next section).  Other Perl properties such as  "InMu-
5148         sicalSymbols" are not currently supported by PCRE.  Note  that  \P{Any}         sicalSymbols"  are  not  currently supported by PCRE. Note that \P{Any}
5149         does not match any characters, so always causes a match failure.         does not match any characters, so always causes a match failure.
5150    
5151         Sets of Unicode characters are defined as belonging to certain scripts.         Sets of Unicode characters are defined as belonging to certain scripts.
5152         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.
5153         For example:         For example:
5154    
5155           \p{Greek}           \p{Greek}
5156           \P{Han}           \P{Han}
5157    
5158         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
5159         "Common". The current list of scripts is:         "Common". The current list of scripts is:
5160    
5161         Arabic, Armenian, Avestan, Balinese, Bamum, Batak,  Bengali,  Bopomofo,         Arabic,  Armenian,  Avestan, Balinese, Bamum, Batak, Bengali, Bopomofo,
5162         Brahmi,  Braille, Buginese, Buhid, Canadian_Aboriginal, Carian, Chakma,         Brahmi, Braille, Buginese, Buhid, Canadian_Aboriginal, Carian,  Chakma,
5163         Cham, Cherokee, Common, Coptic, Cuneiform, Cypriot, Cyrillic,  Deseret,         Cham,  Cherokee, Common, Coptic, Cuneiform, Cypriot, Cyrillic, Deseret,
5164         Devanagari,   Egyptian_Hieroglyphs,   Ethiopic,  Georgian,  Glagolitic,         Devanagari,  Egyptian_Hieroglyphs,  Ethiopic,   Georgian,   Glagolitic,
5165         Gothic, Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew,  Hira-         Gothic,  Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hira-
5166         gana,   Imperial_Aramaic,  Inherited,  Inscriptional_Pahlavi,  Inscrip-         gana,  Imperial_Aramaic,  Inherited,  Inscriptional_Pahlavi,   Inscrip-
5167         tional_Parthian,  Javanese,  Kaithi,   Kannada,   Katakana,   Kayah_Li,         tional_Parthian,   Javanese,   Kaithi,   Kannada,  Katakana,  Kayah_Li,
5168         Kharoshthi,  Khmer,  Lao, Latin, Lepcha, Limbu, Linear_B, Lisu, Lycian,         Kharoshthi, Khmer, Lao, Latin, Lepcha, Limbu, Linear_B,  Lisu,  Lycian,
5169         Lydian,    Malayalam,    Mandaic,    Meetei_Mayek,    Meroitic_Cursive,         Lydian,    Malayalam,    Mandaic,    Meetei_Mayek,    Meroitic_Cursive,
5170         Meroitic_Hieroglyphs,   Miao,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,         Meroitic_Hieroglyphs,  Miao,  Mongolian,  Myanmar,  New_Tai_Lue,   Nko,
5171         Ogham,   Old_Italic,   Old_Persian,   Old_South_Arabian,    Old_Turkic,         Ogham,    Old_Italic,   Old_Persian,   Old_South_Arabian,   Old_Turkic,
5172         Ol_Chiki,  Oriya, Osmanya, Phags_Pa, Phoenician, Rejang, Runic, Samari-         Ol_Chiki, Oriya, Osmanya, Phags_Pa, Phoenician, Rejang, Runic,  Samari-
5173         tan, Saurashtra, Sharada, Shavian,  Sinhala,  Sora_Sompeng,  Sundanese,         tan,  Saurashtra,  Sharada,  Shavian, Sinhala, Sora_Sompeng, Sundanese,
5174         Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa, Tai_Le, Tai_Tham, Tai_Viet,         Syloti_Nagri, Syriac, Tagalog, Tagbanwa,  Tai_Le,  Tai_Tham,  Tai_Viet,
5175         Takri, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh,  Ugaritic,  Vai,         Takri,  Tamil,  Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Vai,
5176         Yi.         Yi.
5177    
5178         Each character has exactly one Unicode general category property, spec-         Each character has exactly one Unicode general category property, spec-
5179         ified by a two-letter abbreviation. For compatibility with Perl,  nega-         ified  by a two-letter abbreviation. For compatibility with Perl, nega-
5180         tion  can  be  specified  by including a circumflex between the opening         tion can be specified by including a  circumflex  between  the  opening
5181         brace and the property name.  For  example,  \p{^Lu}  is  the  same  as         brace  and  the  property  name.  For  example,  \p{^Lu} is the same as
5182         \P{Lu}.         \P{Lu}.
5183    
5184         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-
5185         eral category properties that start with that letter. In this case,  in         eral  category properties that start with that letter. In this case, in
5186         the  absence of negation, the curly brackets in the escape sequence are         the absence of negation, the curly brackets in the escape sequence  are
5187         optional; these two examples have the same effect:         optional; these two examples have the same effect:
5188    
5189           \p{L}           \p{L}
# Line 5145  BACKSLASH Line 5235  BACKSLASH
5235           Zp    Paragraph separator           Zp    Paragraph separator
5236           Zs    Space separator           Zs    Space separator
5237    
5238         The special property L& is also supported: it matches a character  that         The  special property L& is also supported: it matches a character that
5239         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
5240         classified as a modifier or "other".         classified as a modifier or "other".
5241    
5242         The Cs (Surrogate) property applies only to  characters  in  the  range         The  Cs  (Surrogate)  property  applies only to characters in the range
5243         U+D800  to U+DFFF. Such characters are not valid in Unicode strings and         U+D800 to U+DFFF. Such characters are not valid in Unicode strings  and
5244         so cannot be tested by PCRE, unless  UTF  validity  checking  has  been         so  cannot  be  tested  by  PCRE, unless UTF validity checking has been
5245         turned    off    (see    the    discussion    of    PCRE_NO_UTF8_CHECK,         turned    off    (see    the    discussion    of    PCRE_NO_UTF8_CHECK,
5246         PCRE_NO_UTF16_CHECK and PCRE_NO_UTF32_CHECK in the pcreapi page).  Perl         PCRE_NO_UTF16_CHECK  and PCRE_NO_UTF32_CHECK in the pcreapi page). Perl
5247         does not support the Cs property.         does not support the Cs property.
5248    
5249         The  long  synonyms  for  property  names  that  Perl supports (such as         The long synonyms for  property  names  that  Perl  supports  (such  as
5250         \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
5251         any of these properties with "Is".         any of these properties with "Is".
5252    
5253         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-
5254         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
5255         in the Unicode table.         in the Unicode table.
5256    
5257         Specifying  caseless  matching  does not affect these escape sequences.         Specifying caseless matching does not affect  these  escape  sequences.
5258         For example, \p{Lu} always matches only upper  case  letters.  This  is         For  example,  \p{Lu}  always  matches only upper case letters. This is
5259         different from the behaviour of current versions of Perl.         different from the behaviour of current versions of Perl.
5260    
5261         Matching  characters  by Unicode property is not fast, because PCRE has         Matching characters by Unicode property is not fast, because  PCRE  has
5262         to do a multistage table lookup in order to find  a  character's  prop-         to  do  a  multistage table lookup in order to find a character's prop-
5263         erty. That is why the traditional escape sequences such as \d and \w do         erty. That is why the traditional escape sequences such as \d and \w do
5264         not use Unicode properties in PCRE by default, though you can make them         not use Unicode properties in PCRE by default, though you can make them
5265         do  so  by  setting the PCRE_UCP option or by starting the pattern with         do so by setting the PCRE_UCP option or by starting  the  pattern  with
5266         (*UCP).         (*UCP).
5267    
5268     Extended grapheme clusters     Extended grapheme clusters
5269    
5270         The \X escape matches any number of Unicode  characters  that  form  an         The  \X  escape  matches  any number of Unicode characters that form an
5271         "extended grapheme cluster", and treats the sequence as an atomic group         "extended grapheme cluster", and treats the sequence as an atomic group
5272         (see below).  Up to and including release 8.31, PCRE  matched  an  ear-         (see  below).   Up  to and including release 8.31, PCRE matched an ear-
5273         lier, simpler definition that was equivalent to         lier, simpler definition that was equivalent to
5274    
5275           (?>\PM\pM*)           (?>\PM\pM*)
5276    
5277         That  is,  it matched a character without the "mark" property, followed         That is, it matched a character without the "mark"  property,  followed
5278         by zero or more characters with the "mark"  property.  Characters  with         by  zero  or  more characters with the "mark" property. Characters with
5279         the  "mark"  property are typically non-spacing accents that affect the         the "mark" property are typically non-spacing accents that  affect  the
5280         preceding character.         preceding character.
5281    
5282         This simple definition was extended in Unicode to include more  compli-         This  simple definition was extended in Unicode to include more compli-
5283         cated  kinds of composite character by giving each character a grapheme         cated kinds of composite character by giving each character a  grapheme
5284         breaking property, and creating rules  that  use  these  properties  to         breaking  property,  and  creating  rules  that use these properties to
5285         define  the  boundaries  of  extended grapheme clusters. In releases of         define the boundaries of extended grapheme  clusters.  In  releases  of
5286         PCRE later than 8.31, \X matches one of these clusters.         PCRE later than 8.31, \X matches one of these clusters.
5287    
5288         \X always matches at least one character. Then it  decides  whether  to         \X  always  matches  at least one character. Then it decides whether to
5289         add additional characters according to the following rules for ending a         add additional characters according to the following rules for ending a
5290         cluster:         cluster:
5291    
5292         1. End at the end of the subject string.         1. End at the end of the subject string.
5293    
5294         2. Do not end between CR and LF; otherwise end after any control  char-         2.  Do not end between CR and LF; otherwise end after any control char-
5295         acter.         acter.
5296    
5297         3.  Do  not  break  Hangul (a Korean script) syllable sequences. Hangul         3. Do not break Hangul (a Korean  script)  syllable  sequences.  Hangul
5298         characters are of five types: L, V, T, LV, and LVT. An L character  may         characters  are of five types: L, V, T, LV, and LVT. An L character may
5299         be  followed by an L, V, LV, or LVT character; an LV or V character may         be followed by an L, V, LV, or LVT character; an LV or V character  may
5300         be followed by a V or T character; an LVT or T character may be follwed         be followed by a V or T character; an LVT or T character may be follwed
5301         only by a T character.         only by a T character.
5302    
5303         4.  Do not end before extending characters or spacing marks. Characters         4. Do not end before extending characters or spacing marks.  Characters
5304         with the "mark" property always have  the  "extend"  grapheme  breaking         with  the  "mark"  property  always have the "extend" grapheme breaking
5305         property.         property.
5306    
5307         5. Do not end after prepend characters.         5. Do not end after prepend characters.
# Line 5220  BACKSLASH Line 5310  BACKSLASH
5310    
5311     PCRE's additional properties     PCRE's additional properties
5312    
5313         As  well  as the standard Unicode properties described above, PCRE sup-         As well as the standard Unicode properties described above,  PCRE  sup-
5314         ports four more that make it possible  to  convert  traditional  escape         ports  four  more  that  make it possible to convert traditional escape
5315         sequences  such as \w and \s and POSIX character classes to use Unicode         sequences such as \w and \s and POSIX character classes to use  Unicode
5316         properties. PCRE uses these non-standard,  non-Perl  properties  inter-         properties.  PCRE  uses  these non-standard, non-Perl properties inter-
5317         nally  when PCRE_UCP is set. However, they may also be used explicitly.         nally when PCRE_UCP is set. However, they may also be used  explicitly.
5318         These properties are:         These properties are:
5319    
5320           Xan   Any alphanumeric character           Xan   Any alphanumeric character
# Line 5232  BACKSLASH Line 5322  BACKSLASH
5322           Xsp   Any Perl space character           Xsp   Any Perl space character
5323           Xwd   Any Perl "word" character           Xwd   Any Perl "word" character
5324    
5325         Xan matches characters that have either the L (letter) or the  N  (num-         Xan  matches  characters that have either the L (letter) or the N (num-
5326         ber)  property. Xps matches the characters tab, linefeed, vertical tab,         ber) property. Xps matches the characters tab, linefeed, vertical  tab,
5327         form feed, or carriage return, and any other character that has  the  Z         form  feed,  or carriage return, and any other character that has the Z
5328         (separator) property.  Xsp is the same as Xps, except that vertical tab         (separator) property.  Xsp is the same as Xps, except that vertical tab
5329         is excluded. Xwd matches the same characters as Xan, plus underscore.         is excluded. Xwd matches the same characters as Xan, plus underscore.
5330    
5331         There is another non-standard property, Xuc, which matches any  charac-         There  is another non-standard property, Xuc, which matches any charac-
5332         ter  that  can  be represented by a Universal Character Name in C++ and         ter that can be represented by a Universal Character Name  in  C++  and
5333         other programming languages. These are the characters $,  @,  `  (grave         other  programming  languages.  These are the characters $, @, ` (grave
5334         accent),  and  all  characters with Unicode code points greater than or         accent), and all characters with Unicode code points  greater  than  or
5335         equal to U+00A0, except for the surrogates U+D800 to U+DFFF. Note  that         equal  to U+00A0, except for the surrogates U+D800 to U+DFFF. Note that
5336         most  base  (ASCII) characters are excluded. (Universal Character Names         most base (ASCII) characters are excluded. (Universal  Character  Names
5337         are of the form \uHHHH or \UHHHHHHHH where H is  a  hexadecimal  digit.         are  of  the  form \uHHHH or \UHHHHHHHH where H is a hexadecimal digit.
5338         Note that the Xuc property does not match these sequences but the char-         Note that the Xuc property does not match these sequences but the char-
5339         acters that they represent.)         acters that they represent.)
5340    
5341     Resetting the match start     Resetting the match start
5342    
5343         The escape sequence \K causes any previously matched characters not  to         The  escape sequence \K causes any previously matched characters not to
5344         be included in the final matched sequence. For example, the pattern:         be included in the final matched sequence. For example, the pattern:
5345    
5346           foo\Kbar           foo\Kbar
5347    
5348         matches  "foobar",  but reports that it has matched "bar". This feature         matches "foobar", but reports that it has matched "bar".  This  feature
5349         is similar to a lookbehind assertion (described  below).   However,  in         is  similar  to  a lookbehind assertion (described below).  However, in
5350         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
5351         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
5352         not  interfere  with  the setting of captured substrings.  For example,         not interfere with the setting of captured  substrings.   For  example,
5353         when the pattern         when the pattern
5354    
5355           (foo)\Kbar           (foo)\Kbar
5356    
5357         matches "foobar", the first substring is still set to "foo".         matches "foobar", the first substring is still set to "foo".
5358    
5359         Perl documents that the use  of  \K  within  assertions  is  "not  well         Perl  documents  that  the  use  of  \K  within assertions is "not well
5360         defined".  In  PCRE,  \K  is  acted upon when it occurs inside positive         defined". In PCRE, \K is acted upon  when  it  occurs  inside  positive
5361         assertions, but is ignored in negative assertions.         assertions, but is ignored in negative assertions.
5362    
5363     Simple assertions     Simple assertions
5364    
5365         The final use of backslash is for certain simple assertions. An  asser-         The  final use of backslash is for certain simple assertions. An asser-
5366         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
5367         a match, without consuming any characters from the subject string.  The         a  match, without consuming any characters from the subject string. The
5368         use  of subpatterns for more complicated assertions is described below.         use of subpatterns for more complicated assertions is described  below.
5369         The backslashed assertions are:         The backslashed assertions are:
5370    
5371           \b     matches at a word boundary           \b     matches at a word boundary
# Line 5286  BACKSLASH Line 5376  BACKSLASH
5376           \z     matches only at the end of the subject           \z     matches only at the end of the subject
5377           \G     matches at the first matching position in the subject           \G     matches at the first matching position in the subject
5378    
5379         Inside a character class, \b has a different meaning;  it  matches  the         Inside  a  character  class, \b has a different meaning; it matches the
5380         backspace  character.  If  any  other  of these assertions appears in a         backspace character. If any other of  these  assertions  appears  in  a
5381         character class, by default it matches the corresponding literal  char-         character  class, by default it matches the corresponding literal char-
5382         acter  (for  example,  \B  matches  the  letter  B).  However,  if  the         acter  (for  example,  \B  matches  the  letter  B).  However,  if  the
5383         PCRE_EXTRA option is set, an "invalid escape sequence" error is  gener-         PCRE_EXTRA  option is set, an "invalid escape sequence" error is gener-
5384         ated instead.         ated instead.
5385    
5386         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
5387         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.
5388         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
5389         string if the first or last character matches \w,  respectively.  In  a         string  if  the  first or last character matches \w, respectively. In a
5390         UTF  mode,  the  meanings  of  \w  and \W can be changed by setting the         UTF mode, the meanings of \w and \W  can  be  changed  by  setting  the
5391         PCRE_UCP option. When this is done, it also affects \b and \B.  Neither         PCRE_UCP  option. When this is done, it also affects \b and \B. Neither
5392         PCRE  nor  Perl has a separate "start of word" or "end of word" metase-         PCRE nor Perl has a separate "start of word" or "end of  word"  metase-
5393         quence. However, whatever follows \b normally determines which  it  is.         quence.  However,  whatever follows \b normally determines which it is.
5394         For example, the fragment \ba matches "a" at the start of a word.         For example, the fragment \ba matches "a" at the start of a word.
5395    
5396         The  \A,  \Z,  and \z assertions differ from the traditional circumflex         The \A, \Z, and \z assertions differ from  the  traditional  circumflex
5397         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
5398         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
5399         set. Thus, they are independent of multiline mode. These  three  asser-         set.  Thus,  they are independent of multiline mode. These three asser-
5400         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
5401         affect only the behaviour of the circumflex and dollar  metacharacters.         affect  only the behaviour of the circumflex and dollar metacharacters.
5402         However,  if the startoffset argument of pcre_exec() is non-zero, indi-         However, if the startoffset argument of pcre_exec() is non-zero,  indi-
5403         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
5404         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
5405         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
5406         the very end, whereas \z matches only at the end.         the very end, whereas \z matches only at the end.
5407    
5408         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
5409         the start point of the match, as specified by the startoffset  argument         the  start point of the match, as specified by the startoffset argument
5410         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
5411         non-zero. By calling pcre_exec() multiple times with appropriate  argu-         non-zero.  By calling pcre_exec() multiple times with appropriate argu-
5412         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-
5413         mentation where \G can be useful.         mentation where \G can be useful.
5414    
5415         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
5416         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
5417         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
5418         previously  matched  string was empty. Because PCRE does just one match         previously matched string was empty. Because PCRE does just  one  match
5419         at a time, it cannot reproduce this behaviour.         at a time, it cannot reproduce this behaviour.
5420    
5421         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
5422         anchored to the starting match position, and the "anchored" flag is set         anchored to the starting match position, and the "anchored" flag is set
5423         in the compiled regular expression.         in the compiled regular expression.
5424    
5425    
5426  CIRCUMFLEX AND DOLLAR  CIRCUMFLEX AND DOLLAR
5427    
5428         The circumflex and dollar  metacharacters  are  zero-width  assertions.         The  circumflex  and  dollar  metacharacters are zero-width assertions.
5429         That  is,  they test for a particular condition being true without con-         That is, they test for a particular condition being true  without  con-
5430         suming any characters from the subject string.         suming any characters from the subject string.
5431    
5432         Outside a character class, in the default matching mode, the circumflex         Outside a character class, in the default matching mode, the circumflex
5433         character  is  an  assertion  that is true only if the current matching         character is an assertion that is true only  if  the  current  matching
5434         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-
5435         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
5436         PCRE_MULTILINE option is unset. Inside a  character  class,  circumflex         PCRE_MULTILINE  option  is  unset. Inside a character class, circumflex
5437         has an entirely different meaning (see below).         has an entirely different meaning (see below).
5438    
5439         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
5440         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
5441         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
5442         branch. If all possible alternatives start with a circumflex, that  is,         branch.  If all possible alternatives start with a circumflex, that is,
5443         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-
5444         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
5445         constructs that can cause a pattern to be anchored.)         constructs that can cause a pattern to be anchored.)
5446    
5447         The  dollar  character is an assertion that is true only if the current         The dollar character is an assertion that is true only if  the  current
5448         matching point is at the end of  the  subject  string,  or  immediately         matching  point  is  at  the  end of the subject string, or immediately
5449         before  a newline at the end of the string (by default). Note, however,         before a newline at the end of the string (by default). Note,  however,
5450         that it does not actually match the newline. Dollar  need  not  be  the         that  it  does  not  actually match the newline. Dollar need not be the
5451         last character of the pattern if a number of alternatives are involved,         last character of the pattern if a number of alternatives are involved,
5452         but it should be the last item in any branch in which it appears.  Dol-         but  it should be the last item in any branch in which it appears. Dol-
5453         lar has no special meaning in a character class.         lar has no special meaning in a character class.
5454    
5455         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
5456         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
5457         compile time. This does not affect the \Z assertion.         compile time. This does not affect the \Z assertion.
5458    
5459         The meanings of the circumflex and dollar characters are changed if the         The meanings of the circumflex and dollar characters are changed if the
5460         PCRE_MULTILINE option is set. When  this  is  the  case,  a  circumflex         PCRE_MULTILINE  option  is  set.  When  this  is the case, a circumflex
5461         matches  immediately after internal newlines as well as at the start of         matches immediately after internal newlines as well as at the start  of
5462         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
5463         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
5464         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
5465         as  the  two-character  sequence CRLF, isolated CR and LF characters do         as the two-character sequence CRLF, isolated CR and  LF  characters  do
5466         not indicate newlines.         not indicate newlines.
5467    
5468         For example, the pattern /^abc$/ matches the subject string  "def\nabc"         For  example, the pattern /^abc$/ matches the subject string "def\nabc"
5469         (where  \n  represents a newline) in multiline mode, but not otherwise.         (where \n represents a newline) in multiline mode, but  not  otherwise.
5470         Consequently, patterns that are anchored in single  line  mode  because         Consequently,  patterns  that  are anchored in single line mode because
5471         all  branches  start  with  ^ are not anchored in multiline mode, and a         all branches start with ^ are not anchored in  multiline  mode,  and  a
5472         match for circumflex is  possible  when  the  startoffset  argument  of         match  for  circumflex  is  possible  when  the startoffset argument of
5473         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
5474         PCRE_MULTILINE is set.         PCRE_MULTILINE is set.
5475    
5476         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
5477         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
5478         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
5479         set.         set.
5480    
5481    
5482  FULL STOP (PERIOD, DOT) AND \N  FULL STOP (PERIOD, DOT) AND \N
5483    
5484         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-
5485         ter in the subject string except (by default) a character  that  signi-         ter  in  the subject string except (by default) a character that signi-
5486         fies the end of a line.         fies the end of a line.
5487    
5488         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
5489         that character; when the two-character sequence CRLF is used, dot  does         that  character; when the two-character sequence CRLF is used, dot does
5490         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
5491         matches all characters (including isolated CRs and LFs). When any  Uni-         matches  all characters (including isolated CRs and LFs). When any Uni-
5492         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
5493         any of the other line ending characters.         any of the other line ending characters.
5494    
5495         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
5496         PCRE_DOTALL  option  is  set,  a dot matches any one character, without         PCRE_DOTALL option is set, a dot matches  any  one  character,  without
5497         exception. If the two-character sequence CRLF is present in the subject         exception. If the two-character sequence CRLF is present in the subject
5498         string, it takes two dots to match it.         string, it takes two dots to match it.
5499    
5500         The  handling of dot is entirely independent of the handling of circum-         The handling of dot is entirely independent of the handling of  circum-
5501         flex and dollar, the only relationship being  that  they  both  involve         flex  and  dollar,  the  only relationship being that they both involve
5502         newlines. Dot has no special meaning in a character class.         newlines. Dot has no special meaning in a character class.
5503    
5504         The  escape  sequence  \N  behaves  like  a  dot, except that it is not         The escape sequence \N behaves like  a  dot,  except  that  it  is  not
5505         affected by the PCRE_DOTALL option. In  other  words,  it  matches  any         affected  by  the  PCRE_DOTALL  option.  In other words, it matches any
5506         character  except  one that signifies the end of a line. Perl also uses         character except one that signifies the end of a line. Perl  also  uses
5507         \N to match characters by name; PCRE does not support this.         \N to match characters by name; PCRE does not support this.
5508    
5509    
5510  MATCHING A SINGLE DATA UNIT  MATCHING A SINGLE DATA UNIT
5511    
5512         Outside a character class, the escape sequence \C matches any one  data         Outside  a character class, the escape sequence \C matches any one data
5513         unit,  whether or not a UTF mode is set. In the 8-bit library, one data         unit, whether or not a UTF mode is set. In the 8-bit library, one  data
5514         unit is one byte; in the 16-bit library it is a  16-bit  unit;  in  the         unit  is  one  byte;  in the 16-bit library it is a 16-bit unit; in the
5515         32-bit  library  it  is  a 32-bit unit. Unlike a dot, \C always matches         32-bit library it is a 32-bit unit. Unlike a  dot,  \C  always  matches
5516         line-ending characters. The feature is provided in  Perl  in  order  to         line-ending  characters.  The  feature  is provided in Perl in order to
5517         match individual bytes in UTF-8 mode, but it is unclear how it can use-         match individual bytes in UTF-8 mode, but it is unclear how it can use-
5518         fully be used. Because \C breaks up  characters  into  individual  data         fully  be  used.  Because  \C breaks up characters into individual data
5519         units,  matching  one unit with \C in a UTF mode means that the rest of         units, matching one unit with \C in a UTF mode means that the  rest  of
5520         the string may start with a malformed UTF character. This has undefined         the string may start with a malformed UTF character. This has undefined
5521         results, because PCRE assumes that it is dealing with valid UTF strings         results, because PCRE assumes that it is dealing with valid UTF strings
5522         (and by default it checks this at the start of  processing  unless  the         (and  by  default  it checks this at the start of processing unless the
5523         PCRE_NO_UTF8_CHECK,  PCRE_NO_UTF16_CHECK  or PCRE_NO_UTF32_CHECK option         PCRE_NO_UTF8_CHECK, PCRE_NO_UTF16_CHECK or  PCRE_NO_UTF32_CHECK  option
5524         is used).         is used).
5525    
5526         PCRE does not allow \C to appear in  lookbehind  assertions  (described         PCRE  does  not  allow \C to appear in lookbehind assertions (described
5527         below)  in  a UTF mode, because this would make it impossible to calcu-         below) in a UTF mode, because this would make it impossible  to  calcu-
5528         late the length of the lookbehind.         late the length of the lookbehind.
5529    
5530         In general, the \C escape sequence is best avoided. However, one way of         In general, the \C escape sequence is best avoided. However, one way of
5531         using  it that avoids the problem of malformed UTF characters is to use         using it that avoids the problem of malformed UTF characters is to  use
5532         a lookahead to check the length of the next character, as in this  pat-         a  lookahead to check the length of the next character, as in this pat-
5533         tern,  which  could be used with a UTF-8 string (ignore white space and         tern, which could be used with a UTF-8 string (ignore white  space  and
5534         line breaks):         line breaks):
5535    
5536           (?| (?=[\x00-\x7f])(\C) |           (?| (?=[\x00-\x7f])(\C) |
# Line 5448  MATCHING A SINGLE DATA UNIT Line 5538  MATCHING A SINGLE DATA UNIT
5538               (?=[\x{800}-\x{ffff}])(\C)(\C)(\C) |               (?=[\x{800}-\x{ffff}])(\C)(\C)(\C) |
5539               (?=[\x{10000}-\x{1fffff}])(\C)(\C)(\C)(\C))               (?=[\x{10000}-\x{1fffff}])(\C)(\C)(\C)(\C))
5540    
5541         A group that starts with (?| resets the capturing  parentheses  numbers         A  group  that starts with (?| resets the capturing parentheses numbers
5542         in  each  alternative  (see  "Duplicate Subpattern Numbers" below). The         in each alternative (see "Duplicate  Subpattern  Numbers"  below).  The
5543         assertions at the start of each branch check the next  UTF-8  character         assertions  at  the start of each branch check the next UTF-8 character
5544         for  values  whose encoding uses 1, 2, 3, or 4 bytes, respectively. The         for values whose encoding uses 1, 2, 3, or 4 bytes,  respectively.  The
5545         character's individual bytes are then captured by the appropriate  num-         character's  individual bytes are then captured by the appropriate num-
5546         ber of groups.         ber of groups.
5547    
5548    
# Line 5462  SQUARE BRACKETS AND CHARACTER CLASSES Line 5552  SQUARE BRACKETS AND CHARACTER CLASSES
5552         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-
5553         cial by default.  However, if the PCRE_JAVASCRIPT_COMPAT option is set,         cial by default.  However, if the PCRE_JAVASCRIPT_COMPAT option is set,
5554         a lone closing square bracket causes a compile-time error. If a closing         a lone closing square bracket causes a compile-time error. If a closing
5555         square  bracket  is required as a member of the class, it should be the         square bracket is required as a member of the class, it should  be  the
5556         first data character in the class  (after  an  initial  circumflex,  if         first  data  character  in  the  class (after an initial circumflex, if
5557         present) or escaped with a backslash.         present) or escaped with a backslash.
5558    
5559         A  character  class matches a single character in the subject. In a UTF         A character class matches a single character in the subject. In  a  UTF
5560         mode, the character may be more than one  data  unit  long.  A  matched         mode,  the  character  may  be  more than one data unit long. A matched
5561         character must be in the set of characters defined by the class, unless         character must be in the set of characters defined by the class, unless
5562         the first character in the class definition is a circumflex,  in  which         the  first  character in the class definition is a circumflex, in which
5563         case the subject character must not be in the set defined by the class.         case the subject character must not be in the set defined by the class.
5564         If a circumflex is actually required as a member of the  class,  ensure         If  a  circumflex is actually required as a member of the class, ensure
5565         it is not the first character, or escape it with a backslash.         it is not the first character, or escape it with a backslash.
5566    
5567         For  example, the character class [aeiou] matches any lower case vowel,         For example, the character class [aeiou] matches any lower case  vowel,
5568         while [^aeiou] matches any character that is not a  lower  case  vowel.         while  [^aeiou]  matches  any character that is not a lower case vowel.
5569         Note that a circumflex is just a convenient notation for specifying the         Note that a circumflex is just a convenient notation for specifying the
5570         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
5571         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-
5572         sumes a character from the subject string, and therefore  it  fails  if         sumes  a  character  from the subject string, and therefore it fails if
5573         the current pointer is at the end of the string.         the current pointer is at the end of the string.
5574    
5575         In UTF-8 (UTF-16, UTF-32) mode, characters with values greater than 255         In UTF-8 (UTF-16, UTF-32) mode, characters with values greater than 255
5576         (0xffff) can be included in a class as a literal string of data  units,         (0xffff)  can be included in a class as a literal string of data units,
5577         or by using the \x{ escaping mechanism.         or by using the \x{ escaping mechanism.
5578    
5579         When  caseless  matching  is set, any letters in a class represent both         When caseless matching is set, any letters in a  class  represent  both
5580         their upper case and lower case versions, so for  example,  a  caseless         their  upper  case  and lower case versions, so for example, a caseless
5581         [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
5582         match "A", whereas a caseful version would. In a UTF mode, PCRE  always         match  "A", whereas a caseful version would. In a UTF mode, PCRE always
5583         understands  the  concept  of case for characters whose values are less         understands the concept of case for characters whose  values  are  less
5584         than 128, so caseless matching is always possible. For characters  with         than  128, so caseless matching is always possible. For characters with
5585         higher  values,  the  concept  of case is supported if PCRE is compiled         higher values, the concept of case is supported  if  PCRE  is  compiled
5586         with Unicode property support, but not otherwise.  If you want  to  use         with  Unicode  property support, but not otherwise.  If you want to use
5587         caseless  matching in a UTF mode for characters 128 and above, you must         caseless matching in a UTF mode for characters 128 and above, you  must
5588         ensure that PCRE is compiled with Unicode property support as  well  as         ensure  that  PCRE is compiled with Unicode property support as well as
5589         with UTF support.         with UTF support.
5590    
5591         Characters  that  might  indicate  line breaks are never treated in any         Characters that might indicate line breaks are  never  treated  in  any
5592         special way  when  matching  character  classes,  whatever  line-ending         special  way  when  matching  character  classes,  whatever line-ending
5593         sequence  is  in  use,  and  whatever  setting  of  the PCRE_DOTALL and         sequence is in  use,  and  whatever  setting  of  the  PCRE_DOTALL  and
5594         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
5595         of these characters.         of these characters.
5596    
5597         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-
5598         ters in a character  class.  For  example,  [d-m]  matches  any  letter         ters  in  a  character  class.  For  example,  [d-m] matches any letter
5599         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
5600         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
5601         where  it cannot be interpreted as indicating a range, typically as the         where it cannot be interpreted as indicating a range, typically as  the
5602         first or last character in the class.         first or last character in the class.
5603    
5604         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-
5605         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
5606         two characters ("W" and "-") followed by a literal string "46]", so  it         two  characters ("W" and "-") followed by a literal string "46]", so it
5607         would  match  "W46]"  or  "-46]". However, if the "]" is escaped with a         would match "W46]" or "-46]". However, if the "]"  is  escaped  with  a
5608         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-
5609         preted  as a class containing a range followed by two other characters.         preted as a class containing a range followed by two other  characters.
5610         The octal or hexadecimal representation of "]" can also be used to  end         The  octal or hexadecimal representation of "]" can also be used to end
5611         a range.         a range.
5612    
5613         Ranges  operate in the collating sequence of character values. They can         Ranges operate in the collating sequence of character values. They  can
5614         also  be  used  for  characters  specified  numerically,  for   example         also   be  used  for  characters  specified  numerically,  for  example
5615         [\000-\037].  Ranges  can include any characters that are valid for the         [\000-\037]. Ranges can include any characters that are valid  for  the
5616         current mode.         current mode.
5617    
5618         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,
5619         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
5620         to [][\\^_`wxyzabc], matched caselessly, and  in  a  non-UTF  mode,  if         to  [][\\^_`wxyzabc],  matched  caselessly,  and  in a non-UTF mode, if
5621         character  tables  for  a French locale are in use, [\xc8-\xcb] matches         character tables for a French locale are in  use,  [\xc8-\xcb]  matches
5622         accented E characters in both cases. In UTF modes,  PCRE  supports  the         accented  E  characters  in both cases. In UTF modes, PCRE supports the
5623         concept  of  case for characters with values greater than 128 only when         concept of case for characters with values greater than 128  only  when
5624         it is compiled with Unicode property support.         it is compiled with Unicode property support.
5625    
5626         The character escape sequences \d, \D, \h, \H, \p, \P, \s, \S, \v,  \V,         The  character escape sequences \d, \D, \h, \H, \p, \P, \s, \S, \v, \V,
5627         \w, and \W may appear in a character class, and add the characters that         \w, and \W may appear in a character class, and add the characters that
5628         they match to the class. For example, [\dABCDEF] matches any  hexadeci-         they  match to the class. For example, [\dABCDEF] matches any hexadeci-
5629         mal  digit.  In  UTF modes, the PCRE_UCP option affects the meanings of         mal digit. In UTF modes, the PCRE_UCP option affects  the  meanings  of
5630         \d, \s, \w and their upper case partners, just as  it  does  when  they         \d,  \s,  \w  and  their upper case partners, just as it does when they
5631         appear  outside a character class, as described in the section entitled         appear outside a character class, as described in the section  entitled
5632         "Generic character types" above. The escape sequence \b has a different         "Generic character types" above. The escape sequence \b has a different
5633         meaning  inside  a character class; it matches the backspace character.         meaning inside a character class; it matches the  backspace  character.
5634         The sequences \B, \N, \R, and \X are not  special  inside  a  character         The  sequences  \B,  \N,  \R, and \X are not special inside a character
5635         class.  Like  any other unrecognized escape sequences, they are treated         class. Like any other unrecognized escape sequences, they  are  treated
5636         as the literal characters "B", "N", "R", and "X" by default, but  cause         as  the literal characters "B", "N", "R", and "X" by default, but cause
5637         an error if the PCRE_EXTRA option is set.         an error if the PCRE_EXTRA option is set.
5638    
5639         A  circumflex  can  conveniently  be used with the upper case character         A circumflex can conveniently be used with  the  upper  case  character
5640         types to specify a more restricted set of characters than the  matching         types  to specify a more restricted set of characters than the matching
5641         lower  case  type.  For example, the class [^\W_] matches any letter or         lower case type.  For example, the class [^\W_] matches any  letter  or
5642         digit, but not underscore, whereas [\w] includes underscore. A positive         digit, but not underscore, whereas [\w] includes underscore. A positive
5643         character class should be read as "something OR something OR ..." and a         character class should be read as "something OR something OR ..." and a
5644         negative class as "NOT something AND NOT something AND NOT ...".         negative class as "NOT something AND NOT something AND NOT ...".
5645    
5646         The only metacharacters that are recognized in  character  classes  are         The  only  metacharacters  that are recognized in character classes are
5647         backslash,  hyphen  (only  where  it can be interpreted as specifying a         backslash, hyphen (only where it can be  interpreted  as  specifying  a
5648         range), circumflex (only at the start), opening  square  bracket  (only         range),  circumflex  (only  at the start), opening square bracket (only
5649         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
5650         next section), and the terminating  closing  square  bracket.  However,         next  section),  and  the  terminating closing square bracket. However,
5651         escaping other non-alphanumeric characters does no harm.         escaping other non-alphanumeric characters does no harm.
5652    
5653    
5654  POSIX CHARACTER CLASSES  POSIX CHARACTER CLASSES
5655    
5656         Perl supports the POSIX notation for character classes. This uses names         Perl supports the POSIX notation for character classes. This uses names
5657         enclosed by [: and :] within the enclosing square brackets.  PCRE  also         enclosed  by  [: and :] within the enclosing square brackets. PCRE also
5658         supports this notation. For example,         supports this notation. For example,
5659    
5660           [01[:alpha:]%]           [01[:alpha:]%]
# Line 5587  POSIX CHARACTER CLASSES Line 5677  POSIX CHARACTER CLASSES
5677           word     "word" characters (same as \w)           word     "word" characters (same as \w)
5678           xdigit   hexadecimal digits           xdigit   hexadecimal digits
5679    
5680         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),
5681         and  space  (32). Notice that this list includes the VT character (code         and space (32). Notice that this list includes the VT  character  (code
5682         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
5683         Perl compatibility).         Perl compatibility).
5684    
5685         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
5686         from Perl 5.8. Another Perl extension is negation, which  is  indicated         from  Perl  5.8. Another Perl extension is negation, which is indicated
5687         by a ^ character after the colon. For example,         by a ^ character after the colon. For example,
5688    
5689           [12[:^digit:]]           [12[:^digit:]]
5690    
5691         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
5692         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but
5693         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.
5694    
5695         By  default,  in  UTF modes, characters with values greater than 128 do         By default, in UTF modes, characters with values greater  than  128  do
5696         not match any of the POSIX character classes. However, if the  PCRE_UCP         not  match any of the POSIX character classes. However, if the PCRE_UCP
5697         option  is passed to pcre_compile(), some of the classes are changed so         option is passed to pcre_compile(), some of the classes are changed  so
5698         that Unicode character properties are used. This is achieved by replac-         that Unicode character properties are used. This is achieved by replac-
5699         ing the POSIX classes by other sequences, as follows:         ing the POSIX classes by other sequences, as follows:
5700    
# Line 5617  POSIX CHARACTER CLASSES Line 5707  POSIX CHARACTER CLASSES
5707           [:upper:]  becomes  \p{Lu}           [:upper:]  becomes  \p{Lu}
5708           [:word:]   becomes  \p{Xwd}           [:word:]   becomes  \p{Xwd}
5709    
5710         Negated  versions,  such  as [:^alpha:] use \P instead of \p. The other         Negated versions, such as [:^alpha:] use \P instead of  \p.  The  other
5711         POSIX classes are unchanged, and match only characters with code points         POSIX classes are unchanged, and match only characters with code points
5712         less than 128.         less than 128.
5713    
5714    
5715  VERTICAL BAR  VERTICAL BAR
5716    
5717         Vertical  bar characters are used to separate alternative patterns. For         Vertical bar characters are used to separate alternative patterns.  For
5718         example, the pattern         example, the pattern
5719    
5720           gilbert|sullivan           gilbert|sullivan
5721    
5722         matches either "gilbert" or "sullivan". Any number of alternatives  may         matches  either "gilbert" or "sullivan". Any number of alternatives may
5723         appear,  and  an  empty  alternative  is  permitted (matching the empty         appear, and an empty  alternative  is  permitted  (matching  the  empty
5724         string). The matching process tries each alternative in turn, from left         string). The matching process tries each alternative in turn, from left
5725         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
5726         are within a subpattern (defined below), "succeeds" means matching  the         are  within a subpattern (defined below), "succeeds" means matching the
5727         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.
5728    
5729    
5730  INTERNAL OPTION SETTING  INTERNAL OPTION SETTING
5731    
5732         The  settings  of  the  PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and         The settings of the  PCRE_CASELESS,  PCRE_MULTILINE,  PCRE_DOTALL,  and
5733         PCRE_EXTENDED options (which are Perl-compatible) can be  changed  from         PCRE_EXTENDED  options  (which are Perl-compatible) can be changed from
5734         within  the  pattern  by  a  sequence  of  Perl option letters enclosed         within the pattern by  a  sequence  of  Perl  option  letters  enclosed
5735         between "(?" and ")".  The option letters are         between "(?" and ")".  The option letters are
5736    
5737           i  for PCRE_CASELESS           i  for PCRE_CASELESS
# Line 5651  INTERNAL OPTION SETTING Line 5741  INTERNAL OPTION SETTING
5741    
5742         For example, (?im) sets caseless, multiline matching. It is also possi-         For example, (?im) sets caseless, multiline matching. It is also possi-
5743         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
5744         combined setting and unsetting such as (?im-sx), which sets  PCRE_CASE-         combined  setting and unsetting such as (?im-sx), which sets PCRE_CASE-
5745         LESS  and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED,         LESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and  PCRE_EXTENDED,
5746         is also permitted. If a  letter  appears  both  before  and  after  the         is  also  permitted.  If  a  letter  appears  both before and after the
5747         hyphen, the option is unset.         hyphen, the option is unset.
5748    
5749         The  PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA         The PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and  PCRE_EXTRA
5750         can be changed in the same way as the Perl-compatible options by  using         can  be changed in the same way as the Perl-compatible options by using
5751         the characters J, U and X respectively.         the characters J, U and X respectively.
5752    
5753         When  one  of  these  option  changes occurs at top level (that is, not         When one of these option changes occurs at  top  level  (that  is,  not
5754         inside subpattern parentheses), the change applies to the remainder  of         inside  subpattern parentheses), the change applies to the remainder of
5755         the pattern that follows. If the change is placed right at the start of         the pattern that follows. If the change is placed right at the start of
5756         a pattern, PCRE extracts it into the global options (and it will there-         a pattern, PCRE extracts it into the global options (and it will there-
5757         fore show up in data extracted by the pcre_fullinfo() function).         fore show up in data extracted by the pcre_fullinfo() function).
5758    
5759         An  option  change  within a subpattern (see below for a description of         An option change within a subpattern (see below for  a  description  of
5760         subpatterns) affects only that part of the subpattern that follows  it,         subpatterns)  affects only that part of the subpattern that follows it,
5761         so         so
5762    
5763           (a(?i)b)c           (a(?i)b)c
5764    
5765         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
5766         used).  By this means, options can be made to have  different  settings         used).   By  this means, options can be made to have different settings
5767         in  different parts of the pattern. Any changes made in one alternative         in different parts of the pattern. Any changes made in one  alternative
5768         do carry on into subsequent branches within the  same  subpattern.  For         do  carry  on  into subsequent branches within the same subpattern. For
5769         example,         example,
5770    
5771           (a(?i)b|c)           (a(?i)b|c)
5772    
5773         matches  "ab",  "aB",  "c",  and "C", even though when matching "C" the         matches "ab", "aB", "c", and "C", even though  when  matching  "C"  the
5774         first branch is abandoned before the option setting.  This  is  because         first  branch  is  abandoned before the option setting. This is because
5775         the  effects  of option settings happen at compile time. There would be         the effects of option settings happen at compile time. There  would  be
5776         some very weird behaviour otherwise.         some very weird behaviour otherwise.
5777    
5778         Note: There are other PCRE-specific options that  can  be  set  by  the         Note:  There  are  other  PCRE-specific  options that can be set by the
5779         application  when  the  compiling  or matching functions are called. In         application when the compiling or matching  functions  are  called.  In
5780         some cases the pattern can contain special leading  sequences  such  as         some  cases  the  pattern can contain special leading sequences such as
5781         (*CRLF)  to  override  what  the  application  has set or what has been         (*CRLF) to override what the application  has  set  or  what  has  been
5782         defaulted.  Details  are  given  in  the  section   entitled   "Newline         defaulted.   Details   are  given  in  the  section  entitled  "Newline
5783         sequences"  above.  There  are also the (*UTF8), (*UTF16),(*UTF32), and         sequences" above. There are also the  (*UTF8),  (*UTF16),(*UTF32),  and
5784         (*UCP) leading sequences that can be used to set UTF and Unicode  prop-         (*UCP)  leading sequences that can be used to set UTF and Unicode prop-
5785         erty  modes;  they are equivalent to setting the PCRE_UTF8, PCRE_UTF16,         erty modes; they are equivalent to setting the  PCRE_UTF8,  PCRE_UTF16,
5786         PCRE_UTF32 and the PCRE_UCP options, respectively. The (*UTF)  sequence         PCRE_UTF32  and the PCRE_UCP options, respectively. The (*UTF) sequence
5787         is a generic version that can be used with any of the libraries.         is a generic version that can be used with any of the  libraries.  How-
5788           ever,  the  application  can set the PCRE_NEVER_UTF option, which locks
5789           out the use of the (*UTF) sequences.
5790    
5791    
5792  SUBPATTERNS  SUBPATTERNS
# Line 5706  SUBPATTERNS Line 5798  SUBPATTERNS
5798    
5799           cat(aract|erpillar|)           cat(aract|erpillar|)
5800    
5801         matches "cataract", "caterpillar", or "cat". Without  the  parentheses,         matches  "cataract",  "caterpillar", or "cat". Without the parentheses,
5802         it would match "cataract", "erpillar" or an empty string.         it would match "cataract", "erpillar" or an empty string.
5803    
5804         2.  It  sets  up  the  subpattern as a capturing subpattern. This means         2. It sets up the subpattern as  a  capturing  subpattern.  This  means
5805         that, when the whole pattern  matches,  that  portion  of  the  subject         that,  when  the  whole  pattern  matches,  that portion of the subject
5806         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
5807         ovector argument of the matching function. (This applies  only  to  the         ovector  argument  of  the matching function. (This applies only to the
5808         traditional  matching functions; the DFA matching functions do not sup-         traditional matching functions; the DFA matching functions do not  sup-
5809         port capturing.)         port capturing.)
5810    
5811         Opening parentheses are counted from left to right (starting from 1) to         Opening parentheses are counted from left to right (starting from 1) to
5812         obtain  numbers  for  the  capturing  subpatterns.  For example, if the         obtain numbers for the  capturing  subpatterns.  For  example,  if  the
5813         string "the red king" is matched against the pattern         string "the red king" is matched against the pattern
5814    
5815           the ((red|white) (king|queen))           the ((red|white) (king|queen))
# Line 5725  SUBPATTERNS Line 5817  SUBPATTERNS
5817         the captured substrings are "red king", "red", and "king", and are num-         the captured substrings are "red king", "red", and "king", and are num-
5818         bered 1, 2, and 3, respectively.         bered 1, 2, and 3, respectively.
5819    
5820         The  fact  that  plain  parentheses  fulfil two functions is not always         The fact that plain parentheses fulfil  two  functions  is  not  always
5821         helpful.  There are often times when a grouping subpattern is  required         helpful.   There are often times when a grouping subpattern is required
5822         without  a capturing requirement. If an opening parenthesis is followed         without a capturing requirement. If an opening parenthesis is  followed
5823         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-
5824         ing,  and  is  not  counted when computing the number of any subsequent         ing, and is not counted when computing the  number  of  any  subsequent
5825         capturing subpatterns. For example, if the string "the white queen"  is         capturing  subpatterns. For example, if the string "the white queen" is
5826         matched against the pattern         matched against the pattern
5827    
5828           the ((?:red|white) (king|queen))           the ((?:red|white) (king|queen))
# Line 5738  SUBPATTERNS Line 5830  SUBPATTERNS
5830         the captured substrings are "white queen" and "queen", and are numbered         the captured substrings are "white queen" and "queen", and are numbered
5831         1 and 2. The maximum number of capturing subpatterns is 65535.         1 and 2. The maximum number of capturing subpatterns is 65535.
5832    
5833         As a convenient shorthand, if any option settings are required  at  the         As  a  convenient shorthand, if any option settings are required at the
5834         start  of  a  non-capturing  subpattern,  the option letters may appear         start of a non-capturing subpattern,  the  option  letters  may  appear
5835         between the "?" and the ":". Thus the two patterns         between the "?" and the ":". Thus the two patterns
5836    
5837           (?i:saturday|sunday)           (?i:saturday|sunday)
5838           (?:(?i)saturday|sunday)           (?:(?i)saturday|sunday)
5839    
5840         match exactly the same set of strings. Because alternative branches are         match exactly the same set of strings. Because alternative branches are
5841         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
5842         the subpattern is reached, an option setting in one branch does  affect         the  subpattern is reached, an option setting in one branch does affect
5843         subsequent  branches,  so  the above patterns match "SUNDAY" as well as         subsequent branches, so the above patterns match "SUNDAY"  as  well  as
5844         "Saturday".         "Saturday".
5845    
5846    
5847  DUPLICATE SUBPATTERN NUMBERS  DUPLICATE SUBPATTERN NUMBERS
5848    
5849         Perl 5.10 introduced a feature whereby each alternative in a subpattern         Perl 5.10 introduced a feature whereby each alternative in a subpattern
5850         uses  the same numbers for its capturing parentheses. Such a subpattern         uses the same numbers for its capturing parentheses. Such a  subpattern
5851         starts with (?| and is itself a non-capturing subpattern. For  example,         starts  with (?| and is itself a non-capturing subpattern. For example,
5852         consider this pattern:         consider this pattern:
5853    
5854           (?|(Sat)ur|(Sun))day           (?|(Sat)ur|(Sun))day
5855    
5856         Because  the two alternatives are inside a (?| group, both sets of cap-         Because the two alternatives are inside a (?| group, both sets of  cap-
5857         turing parentheses are numbered one. Thus, when  the  pattern  matches,         turing  parentheses  are  numbered one. Thus, when the pattern matches,
5858         you  can  look  at captured substring number one, whichever alternative         you can look at captured substring number  one,  whichever  alternative
5859         matched. This construct is useful when you want to  capture  part,  but         matched.  This  construct  is useful when you want to capture part, but
5860         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-
5861         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
5862         each  branch.  The numbers of any capturing parentheses that follow the         each branch. The numbers of any capturing parentheses that  follow  the
5863         subpattern start after the highest number used in any branch. The  fol-         subpattern  start after the highest number used in any branch. The fol-
5864         lowing example is taken from the Perl documentation. The numbers under-         lowing example is taken from the Perl documentation. The numbers under-
5865         neath show in which buffer the captured content will be stored.         neath show in which buffer the captured content will be stored.
5866    
# Line 5776  DUPLICATE SUBPATTERN NUMBERS Line 5868  DUPLICATE SUBPATTERN NUMBERS
5868           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
5869           # 1            2         2  3        2     3     4           # 1            2         2  3        2     3     4
5870    
5871         A back reference to a numbered subpattern uses the  most  recent  value         A  back  reference  to a numbered subpattern uses the most recent value
5872         that  is  set  for that number by any subpattern. The following pattern         that is set for that number by any subpattern.  The  following  pattern
5873         matches "abcabc" or "defdef":         matches "abcabc" or "defdef":
5874    
5875           /(?|(abc)|(def))\1/           /(?|(abc)|(def))\1/
5876    
5877         In contrast, a subroutine call to a numbered subpattern  always  refers         In  contrast,  a subroutine call to a numbered subpattern always refers
5878         to  the  first  one in the pattern with the given number. The following         to the first one in the pattern with the given  number.  The  following
5879         pattern matches "abcabc" or "defabc":         pattern matches "abcabc" or "defabc":
5880    
5881           /(?|(abc)|(def))(?1)/           /(?|(abc)|(def))(?1)/
5882    
5883         If a condition test for a subpattern's having matched refers to a  non-         If  a condition test for a subpattern's having matched refers to a non-
5884         unique  number, the test is true if any of the subpatterns of that num-         unique number, the test is true if any of the subpatterns of that  num-
5885         ber have matched.         ber have matched.
5886    
5887         An alternative approach to using this "branch reset" feature is to  use         An  alternative approach to using this "branch reset" feature is to use
5888         duplicate named subpatterns, as described in the next section.         duplicate named subpatterns, as described in the next section.
5889    
5890    
5891  NAMED SUBPATTERNS  NAMED SUBPATTERNS
5892    
5893         Identifying  capturing  parentheses  by number is simple, but it can be         Identifying capturing parentheses by number is simple, but  it  can  be
5894         very hard to keep track of the numbers in complicated  regular  expres-         very  hard  to keep track of the numbers in complicated regular expres-
5895         sions.  Furthermore,  if  an  expression  is  modified, the numbers may         sions. Furthermore, if an  expression  is  modified,  the  numbers  may
5896         change. To help with this difficulty, PCRE supports the naming of  sub-         change.  To help with this difficulty, PCRE supports the naming of sub-
5897         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
5898         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
5899         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-
5900         tax. Perl allows identically numbered  subpatterns  to  have  different         tax.  Perl  allows  identically  numbered subpatterns to have different
5901         names, but PCRE does not.         names, but PCRE does not.
5902    
5903         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>...)
5904         or (?'name'...) as in Perl, or (?P<name>...) as in  Python.  References         or  (?'name'...)  as in Perl, or (?P<name>...) as in Python. References
5905         to  capturing parentheses from other parts of the pattern, such as back         to capturing parentheses from other parts of the pattern, such as  back
5906         references, recursion, and conditions, can be made by name as  well  as         references,  recursion,  and conditions, can be made by name as well as
5907         by number.         by number.
5908    
5909         Names  consist  of  up  to  32 alphanumeric characters and underscores.         Names consist of up to  32  alphanumeric  characters  and  underscores.
5910         Named capturing parentheses are still  allocated  numbers  as  well  as         Named  capturing  parentheses  are  still  allocated numbers as well as
5911         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
5912         function calls for extracting the name-to-number translation table from         function calls for extracting the name-to-number translation table from
5913         a compiled pattern. There is also a convenience function for extracting         a compiled pattern. There is also a convenience function for extracting
5914         a captured substring by name.         a captured substring by name.
5915    
5916         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
5917         to relax this constraint by setting the PCRE_DUPNAMES option at compile         to relax this constraint by setting the PCRE_DUPNAMES option at compile
5918         time. (Duplicate names are also always permitted for  subpatterns  with         time.  (Duplicate  names are also always permitted for subpatterns with
5919         the  same  number, set up as described in the previous section.) Dupli-         the same number, set up as described in the previous  section.)  Dupli-
5920         cate names can be useful for patterns where only one  instance  of  the         cate  names  can  be useful for patterns where only one instance of the
5921         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
5922         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
5923         both cases you want to extract the abbreviation. This pattern (ignoring         both cases you want to extract the abbreviation. This pattern (ignoring
5924         the line breaks) does the job:         the line breaks) does the job:
5925    
# Line 5837  NAMED SUBPATTERNS Line 5929  NAMED SUBPATTERNS
5929           (?<DN>Thu)(?:rsday)?|           (?<DN>Thu)(?:rsday)?|
5930           (?<DN>Sat)(?:urday)?           (?<DN>Sat)(?:urday)?
5931    
5932         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
5933         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
5934         reset" subpattern, as described in the previous section.)         reset" subpattern, as described in the previous section.)
5935    
5936         The convenience function for extracting the data by  name  returns  the         The  convenience  function  for extracting the data by name returns the
5937         substring  for  the first (and in this example, the only) subpattern of         substring for the first (and in this example, the only)  subpattern  of
5938         that name that matched. This saves searching  to  find  which  numbered         that  name  that  matched.  This saves searching to find which numbered
5939         subpattern it was.         subpattern it was.
5940    
5941         If  you  make  a  back  reference to a non-unique named subpattern from         If you make a back reference to  a  non-unique  named  subpattern  from
5942         elsewhere in the pattern, the one that corresponds to the first  occur-         elsewhere  in the pattern, the one that corresponds to the first occur-
5943         rence of the name is used. In the absence of duplicate numbers (see the         rence of the name is used. In the absence of duplicate numbers (see the
5944         previous section) this is the one with the lowest number. If you use  a         previous  section) this is the one with the lowest number. If you use a
5945         named  reference  in a condition test (see the section about conditions         named reference in a condition test (see the section  about  conditions
5946         below), either to check whether a subpattern has matched, or  to  check         below),  either  to check whether a subpattern has matched, or to check
5947         for  recursion,  all  subpatterns with the same name are tested. If the         for recursion, all subpatterns with the same name are  tested.  If  the
5948         condition is true for any one of them, the overall condition  is  true.         condition  is  true for any one of them, the overall condition is true.
5949         This is the same behaviour as testing by number. For further details of         This is the same behaviour as testing by number. For further details of
5950         the interfaces for handling named subpatterns, see the pcreapi documen-         the interfaces for handling named subpatterns, see the pcreapi documen-
5951         tation.         tation.
5952    
5953         Warning: You cannot use different names to distinguish between two sub-         Warning: You cannot use different names to distinguish between two sub-
5954         patterns with the same number because PCRE uses only the  numbers  when         patterns  with  the same number because PCRE uses only the numbers when
5955         matching. For this reason, an error is given at compile time if differ-         matching. For this reason, an error is given at compile time if differ-
5956         ent names are given to subpatterns with the same number.  However,  you         ent  names  are given to subpatterns with the same number. However, you
5957         can  give  the same name to subpatterns with the same number, even when         can give the same name to subpatterns with the same number,  even  when
5958         PCRE_DUPNAMES is not set.         PCRE_DUPNAMES is not set.
5959    
5960    
5961  REPETITION  REPETITION
5962    
5963         Repetition is specified by quantifiers, which can  follow  any  of  the         Repetition  is  specified  by  quantifiers, which can follow any of the
5964         following items:         following items:
5965    
5966           a literal data character           a literal data character
# Line 5882  REPETITION Line 5974  REPETITION
5974           a parenthesized subpattern (including assertions)           a parenthesized subpattern (including assertions)
5975           a subroutine call to a subpattern (recursive or otherwise)           a subroutine call to a subpattern (recursive or otherwise)
5976    
5977         The  general repetition quantifier specifies a minimum and maximum num-         The general repetition quantifier specifies a minimum and maximum  num-
5978         ber of permitted matches, by giving the two numbers in  curly  brackets         ber  of  permitted matches, by giving the two numbers in curly brackets
5979         (braces),  separated  by  a comma. The numbers must be less than 65536,         (braces), separated by a comma. The numbers must be  less  than  65536,
5980         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:
5981    
5982           z{2,4}           z{2,4}
5983    
5984         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
5985         special  character.  If  the second number is omitted, but the comma is         special character. If the second number is omitted, but  the  comma  is
5986         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
5987         are  both omitted, the quantifier specifies an exact number of required         are both omitted, the quantifier specifies an exact number of  required
5988         matches. Thus         matches. Thus
5989    
5990           [aeiou]{3,}           [aeiou]{3,}
# Line 5901  REPETITION Line 5993  REPETITION
5993    
5994           \d{8}           \d{8}
5995    
5996         matches exactly 8 digits. An opening curly bracket that  appears  in  a         matches  exactly  8  digits. An opening curly bracket that appears in a
5997         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
5998         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-
5999         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.
6000    
6001         In UTF modes, quantifiers apply to characters rather than to individual         In UTF modes, quantifiers apply to characters rather than to individual
6002         data units. Thus, for example, \x{100}{2} matches two characters,  each         data  units. Thus, for example, \x{100}{2} matches two characters, each
6003         of which is represented by a two-byte sequence in a UTF-8 string. Simi-         of which is represented by a two-byte sequence in a UTF-8 string. Simi-
6004         larly, \X{3} matches three Unicode extended grapheme clusters, each  of         larly,  \X{3} matches three Unicode extended grapheme clusters, each of
6005         which  may  be  several  data  units long (and they may be of different         which may be several data units long (and  they  may  be  of  different
6006         lengths).         lengths).
6007    
6008         The quantifier {0} is permitted, causing the expression to behave as if         The quantifier {0} is permitted, causing the expression to behave as if
6009         the previous item and the quantifier were not present. This may be use-         the previous item and the quantifier were not present. This may be use-
6010         ful for subpatterns that are referenced as subroutines  from  elsewhere         ful  for  subpatterns that are referenced as subroutines from elsewhere
6011         in the pattern (but see also the section entitled "Defining subpatterns         in the pattern (but see also the section entitled "Defining subpatterns
6012         for use by reference only" below). Items other  than  subpatterns  that         for  use  by  reference only" below). Items other than subpatterns that
6013         have a {0} quantifier are omitted from the compiled pattern.         have a {0} quantifier are omitted from the compiled pattern.
6014    
6015         For  convenience, the three most common quantifiers have single-charac-         For convenience, the three most common quantifiers have  single-charac-
6016         ter abbreviations:         ter abbreviations:
6017    
6018           *    is equivalent to {0,}           *    is equivalent to {0,}
6019           +    is equivalent to {1,}           +    is equivalent to {1,}
6020           ?    is equivalent to {0,1}           ?    is equivalent to {0,1}
6021    
6022         It is possible to construct infinite loops by  following  a  subpattern         It  is  possible  to construct infinite loops by following a subpattern
6023         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,
6024         for example:         for example:
6025    
6026           (a?)*           (a?)*
6027    
6028         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
6029         for  such  patterns. However, because there are cases where this can be         for such patterns. However, because there are cases where this  can  be
6030         useful, such patterns are now accepted, but if any  repetition  of  the         useful,  such  patterns  are now accepted, but if any repetition of the
6031         subpattern  does in fact match no characters, the loop is forcibly bro-         subpattern does in fact match no characters, the loop is forcibly  bro-
6032         ken.         ken.
6033    
6034         By default, the quantifiers are "greedy", that is, they match  as  much         By  default,  the quantifiers are "greedy", that is, they match as much
6035         as  possible  (up  to  the  maximum number of permitted times), without         as possible (up to the maximum  number  of  permitted  times),  without
6036         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
6037         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
6038         appear between /* and */ and within the comment,  individual  *  and  /         appear  between  /*  and  */ and within the comment, individual * and /
6039         characters  may  appear. An attempt to match C comments by applying the         characters may appear. An attempt to match C comments by  applying  the
6040         pattern         pattern
6041    
6042           /\*.*\*/           /\*.*\*/
# Line 5953  REPETITION Line 6045  REPETITION
6045    
6046           /* first comment */  not comment  /* second comment */           /* first comment */  not comment  /* second comment */
6047    
6048         fails, because it matches the entire string owing to the greediness  of         fails,  because it matches the entire string owing to the greediness of
6049         the .*  item.         the .*  item.
6050    
6051         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
6052         be greedy, and instead matches the minimum number of times possible, so         be greedy, and instead matches the minimum number of times possible, so
6053         the pattern         the pattern
6054    
6055           /\*.*?\*/           /\*.*?\*/
6056    
6057         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
6058         quantifiers is not otherwise changed,  just  the  preferred  number  of         quantifiers  is  not  otherwise  changed,  just the preferred number of
6059         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
6060         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
6061         appear doubled, as in         appear doubled, as in
6062    
6063           \d??\d           \d??\d
# Line 5973  REPETITION Line 6065  REPETITION
6065         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
6066         only way the rest of the pattern matches.         only way the rest of the pattern matches.
6067    
6068         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
6069         Perl),  the  quantifiers are not greedy by default, but individual ones         Perl), the quantifiers are not greedy by default, but  individual  ones
6070         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
6071         words, it inverts the default behaviour.         words, it inverts the default behaviour.
6072    
6073         When  a  parenthesized  subpattern  is quantified with a minimum repeat         When a parenthesized subpattern is quantified  with  a  minimum  repeat
6074         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
6075         required  for  the  compiled  pattern, in proportion to the size of the         required for the compiled pattern, in proportion to  the  size  of  the
6076         minimum or maximum.         minimum or maximum.
6077    
6078         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-
6079         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,
6080         the pattern is implicitly anchored, because whatever  follows  will  be         the  pattern  is  implicitly anchored, because whatever follows will be
6081         tried  against every character position in the subject string, so there         tried against every character position in the subject string, so  there
6082         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
6083         first.  PCRE  normally treats such a pattern as though it were preceded         first. PCRE normally treats such a pattern as though it  were  preceded
6084         by \A.         by \A.
6085    
6086         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-
6087         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-
6088         mization, or alternatively using ^ to indicate anchoring explicitly.         mization, or alternatively using ^ to indicate anchoring explicitly.
6089    
6090         However, there are some cases where the optimization  cannot  be  used.         However,  there  are  some cases where the optimization cannot be used.
6091         When .*  is inside capturing parentheses that are the subject of a back         When .*  is inside capturing parentheses that are the subject of a back
6092         reference elsewhere in the pattern, a match at the start may fail where         reference elsewhere in the pattern, a match at the start may fail where
6093         a later one succeeds. Consider, for example:         a later one succeeds. Consider, for example:
6094    
6095           (.*)abc\1           (.*)abc\1
6096    
6097         If  the subject is "xyz123abc123" the match point is the fourth charac-         If the subject is "xyz123abc123" the match point is the fourth  charac-
6098         ter. For this reason, such a pattern is not implicitly anchored.         ter. For this reason, such a pattern is not implicitly anchored.
6099    
6100         Another case where implicit anchoring is not applied is when the  lead-         Another  case where implicit anchoring is not applied is when the lead-
6101         ing  .* is inside an atomic group. Once again, a match at the start may         ing .* is inside an atomic group. Once again, a match at the start  may
6102         fail where a later one succeeds. Consider this pattern:         fail where a later one succeeds. Consider this pattern:
6103    
6104           (?>.*?a)b           (?>.*?a)b
6105    
6106         It matches "ab" in the subject "aab". The use of the backtracking  con-         It  matches "ab" in the subject "aab". The use of the backtracking con-
6107         trol verbs (*PRUNE) and (*SKIP) also disable this optimization.         trol verbs (*PRUNE) and (*SKIP) also disable this optimization.
6108    
6109         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 6020  REPETITION Line 6112  REPETITION
6112           (tweedle[dume]{3}\s*)+           (tweedle[dume]{3}\s*)+
6113    
6114         has matched "tweedledum tweedledee" the value of the captured substring         has matched "tweedledum tweedledee" the value of the captured substring
6115         is  "tweedledee".  However,  if there are nested capturing subpatterns,         is "tweedledee". However, if there are  nested  capturing  subpatterns,
6116         the corresponding captured values may have been set in previous  itera-         the  corresponding captured values may have been set in previous itera-
6117         tions. For example, after         tions. For example, after
6118    
6119           /(a|(b))+/           /(a|(b))+/
# Line 6031  REPETITION Line 6123  REPETITION
6123    
6124  ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS  ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS
6125    
6126         With  both  maximizing ("greedy") and minimizing ("ungreedy" or "lazy")         With both maximizing ("greedy") and minimizing ("ungreedy"  or  "lazy")
6127         repetition, failure of what follows normally causes the  repeated  item         repetition,  failure  of what follows normally causes the repeated item
6128         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
6129         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,
6130         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
6131         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
6132         no point in carrying on.         no point in carrying on.
6133    
6134         Consider,  for  example, the pattern \d+foo when applied to the subject         Consider, for example, the pattern \d+foo when applied to  the  subject
6135         line         line
6136    
6137           123456bar           123456bar
6138    
6139         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
6140         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
6141         \d+ item, and then with  4,  and  so  on,  before  ultimately  failing.         \d+  item,  and  then  with  4,  and  so on, before ultimately failing.
6142         "Atomic  grouping"  (a  term taken from Jeffrey Friedl's book) provides         "Atomic grouping" (a term taken from Jeffrey  Friedl's  book)  provides
6143         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
6144         to be re-evaluated in this way.         to be re-evaluated in this way.
6145    
6146         If  we  use atomic grouping for the previous example, the matcher gives         If we use atomic grouping for the previous example, the  matcher  gives
6147         up immediately on failing to match "foo" the first time.  The  notation         up  immediately  on failing to match "foo" the first time. The notation
6148         is a kind of special parenthesis, starting with (?> as in this example:         is a kind of special parenthesis, starting with (?> as in this example:
6149    
6150           (?>\d+)foo           (?>\d+)foo
6151    
6152         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-
6153         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
6154         prevented  from  backtracking into it. Backtracking past it to previous         prevented from backtracking into it. Backtracking past it  to  previous
6155         items, however, works as normal.         items, however, works as normal.
6156    
6157         An alternative description is that a subpattern of  this  type  matches         An  alternative  description  is that a subpattern of this type matches
6158         the  string  of  characters  that an identical standalone pattern would         the string of characters that an  identical  standalone  pattern  would
6159         match, if anchored at the current point in the subject string.         match, if anchored at the current point in the subject string.
6160    
6161         Atomic grouping subpatterns are not capturing subpatterns. Simple cases         Atomic grouping subpatterns are not capturing subpatterns. Simple cases
6162         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
6163         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-
6164         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
6165         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
6166         digits.         digits.
6167    
6168         Atomic  groups in general can of course contain arbitrarily complicated         Atomic groups in general can of course contain arbitrarily  complicated
6169         subpatterns, and can be nested. However, when  the  subpattern  for  an         subpatterns,  and  can  be  nested. However, when the subpattern for an
6170         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
6171         simpler notation, called a "possessive quantifier" can  be  used.  This         simpler  notation,  called  a "possessive quantifier" can be used. This
6172         consists  of  an  additional  + character following a quantifier. Using         consists of an additional + character  following  a  quantifier.  Using
6173         this notation, the previous example can be rewritten as         this notation, the previous example can be rewritten as
6174    
6175           \d++foo           \d++foo
# Line 6087  ATOMIC GROUPING AND POSSESSIVE QUANTIFIE Line 6179  ATOMIC GROUPING AND POSSESSIVE QUANTIFIE
6179    
6180           (abc|xyz){2,3}+           (abc|xyz){2,3}+
6181    
6182         Possessive   quantifiers   are   always  greedy;  the  setting  of  the         Possessive  quantifiers  are  always  greedy;  the   setting   of   the
6183         PCRE_UNGREEDY option is ignored. They are a convenient notation for the         PCRE_UNGREEDY option is ignored. They are a convenient notation for the
6184         simpler  forms  of atomic group. However, there is no difference in the         simpler forms of atomic group. However, there is no difference  in  the
6185         meaning of a possessive quantifier and  the  equivalent  atomic  group,         meaning  of  a  possessive  quantifier and the equivalent atomic group,
6186         though  there  may  be a performance difference; possessive quantifiers         though there may be a performance  difference;  possessive  quantifiers
6187         should be slightly faster.         should be slightly faster.
6188    
6189         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-
6190         tax.   Jeffrey  Friedl  originated the idea (and the name) in the first         tax.  Jeffrey Friedl originated the idea (and the name)  in  the  first
6191         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
6192         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
6193         found its way into Perl at release 5.10.         found its way into Perl at release 5.10.
6194    
6195         PCRE has an optimization that automatically "possessifies" certain sim-         PCRE has an optimization that automatically "possessifies" certain sim-
6196         ple  pattern  constructs.  For  example, the sequence A+B is treated as         ple pattern constructs. For example, the sequence  A+B  is  treated  as
6197         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
6198         when B must follow.         when B must follow.
6199    
6200         When  a  pattern  contains an unlimited repeat inside a subpattern that         When a pattern contains an unlimited repeat inside  a  subpattern  that
6201         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
6202         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
6203         very long time indeed. The pattern         very long time indeed. The pattern
6204    
6205           (\D+|<\d+>)*[!?]           (\D+|<\d+>)*[!?]
6206    
6207         matches an unlimited number of substrings that either consist  of  non-         matches  an  unlimited number of substrings that either consist of non-
6208         digits,  or  digits  enclosed in <>, followed by either ! or ?. When it         digits, or digits enclosed in <>, followed by either ! or  ?.  When  it
6209         matches, it runs quickly. However, if it is applied to         matches, it runs quickly. However, if it is applied to
6210    
6211           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
6212    
6213         it takes a long time before reporting  failure.  This  is  because  the         it  takes  a  long  time  before reporting failure. This is because the
6214         string  can be divided between the internal \D+ repeat and the external         string can be divided between the internal \D+ repeat and the  external
6215         * 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
6216         example  uses  [!?]  rather than a single character at the end, because         example uses [!?] rather than a single character at  the  end,  because
6217         both PCRE and Perl have an optimization that allows  for  fast  failure         both  PCRE  and  Perl have an optimization that allows for fast failure
6218         when  a single character is used. They remember the last single charac-         when a single character is used. They remember the last single  charac-
6219         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
6220         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
6221         group, like this:         group, like this:
6222    
6223           ((?>\D+)|<\d+>)*[!?]           ((?>\D+)|<\d+>)*[!?]
# Line 6137  BACK REFERENCES Line 6229  BACK REFERENCES
6229    
6230         Outside a character class, a backslash followed by a digit greater than         Outside a character class, a backslash followed by a digit greater than
6231         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-
6232         pattern earlier (that is, to its left) in the pattern,  provided  there         pattern  earlier  (that is, to its left) in the pattern, provided there
6233         have been that many previous capturing left parentheses.         have been that many previous capturing left parentheses.
6234    
6235         However, if the decimal number following the backslash is less than 10,         However, if the decimal number following the backslash is less than 10,
6236         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
6237         there  are  not that many capturing left parentheses in the entire pat-         there are not that many capturing left parentheses in the  entire  pat-
6238         tern. In other words, the parentheses that are referenced need  not  be         tern.  In  other words, the parentheses that are referenced need not be
6239         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
6240         reference" of this type can make sense when a  repetition  is  involved         reference"  of  this  type can make sense when a repetition is involved
6241         and  the  subpattern to the right has participated in an earlier itera-         and the subpattern to the right has participated in an  earlier  itera-
6242         tion.         tion.
6243    
6244         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
6245         subpattern  whose  number  is  10  or  more using this syntax because a         subpattern whose number is 10 or  more  using  this  syntax  because  a
6246         sequence such as \50 is interpreted as a character  defined  in  octal.         sequence  such  as  \50 is interpreted as a character defined in octal.
6247         See the subsection entitled "Non-printing characters" above for further         See the subsection entitled "Non-printing characters" above for further
6248         details of the handling of digits following a backslash.  There  is  no         details  of  the  handling of digits following a backslash. There is no
6249         such  problem  when named parentheses are used. A back reference to any         such problem when named parentheses are used. A back reference  to  any
6250         subpattern is possible using named parentheses (see below).         subpattern is possible using named parentheses (see below).
6251    
6252         Another way of avoiding the ambiguity inherent in  the  use  of  digits         Another  way  of  avoiding  the ambiguity inherent in the use of digits
6253         following  a  backslash  is  to use the \g escape sequence. This escape         following a backslash is to use the \g  escape  sequence.  This  escape
6254         must be followed by an unsigned number or a negative number, optionally         must be followed by an unsigned number or a negative number, optionally
6255         enclosed in braces. These examples are all identical:         enclosed in braces. These examples are all identical:
6256    
# Line 6166  BACK REFERENCES Line 6258  BACK REFERENCES
6258           (ring), \g1           (ring), \g1
6259           (ring), \g{1}           (ring), \g{1}
6260    
6261         An  unsigned number specifies an absolute reference without the ambigu-         An unsigned number specifies an absolute reference without the  ambigu-
6262         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
6263         digits follow the reference. A negative number is a relative reference.         digits follow the reference. A negative number is a relative reference.
6264         Consider this example:         Consider this example:
# Line 6175  BACK REFERENCES Line 6267  BACK REFERENCES
6267    
6268         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-
6269         ing subpattern before \g, that is, is it equivalent to \2 in this exam-         ing subpattern before \g, that is, is it equivalent to \2 in this exam-
6270         ple.  Similarly, \g{-2} would be equivalent to \1. The use of  relative         ple.   Similarly, \g{-2} would be equivalent to \1. The use of relative
6271         references  can  be helpful in long patterns, and also in patterns that         references can be helpful in long patterns, and also in  patterns  that
6272         are created by  joining  together  fragments  that  contain  references         are  created  by  joining  together  fragments  that contain references
6273         within themselves.         within themselves.
6274    
6275         A  back  reference matches whatever actually matched the capturing sub-         A back reference matches whatever actually matched the  capturing  sub-
6276         pattern in the current subject string, rather  than  anything  matching         pattern  in  the  current subject string, rather than anything matching
6277         the subpattern itself (see "Subpatterns as subroutines" below for a way         the subpattern itself (see "Subpatterns as subroutines" below for a way
6278         of doing that). So the pattern         of doing that). So the pattern
6279    
6280           (sens|respons)e and \1ibility           (sens|respons)e and \1ibility
6281    
6282         matches "sense and sensibility" and "response and responsibility",  but         matches  "sense and sensibility" and "response and responsibility", but
6283         not  "sense and responsibility". If caseful matching is in force at the         not "sense and responsibility". If caseful matching is in force at  the
6284         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-
6285         ple,         ple,
6286    
6287           ((?i)rah)\s+\1           ((?i)rah)\s+\1
6288    
6289         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
6290         original capturing subpattern is matched caselessly.         original capturing subpattern is matched caselessly.
6291    
6292         There are several different ways of writing back  references  to  named         There  are  several  different ways of writing back references to named
6293         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
6294         \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
6295         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
6296         and named references, is also supported. We  could  rewrite  the  above         and  named  references,  is  also supported. We could rewrite the above
6297         example in any of the following ways:         example in any of the following ways:
6298    
6299           (?<p1>(?i)rah)\s+\k<p1>           (?<p1>(?i)rah)\s+\k<p1>
# Line 6209  BACK REFERENCES Line 6301  BACK REFERENCES
6301           (?P<p1>(?i)rah)\s+(?P=p1)           (?P<p1>(?i)rah)\s+(?P=p1)
6302           (?<p1>(?i)rah)\s+\g{p1}           (?<p1>(?i)rah)\s+\g{p1}
6303    
6304         A  subpattern  that  is  referenced  by  name may appear in the pattern         A subpattern that is referenced by  name  may  appear  in  the  pattern
6305         before or after the reference.         before or after the reference.
6306    
6307         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
6308         subpattern  has  not actually been used in a particular match, any back         subpattern has not actually been used in a particular match,  any  back
6309         references to it always fail by default. For example, the pattern         references to it always fail by default. For example, the pattern
6310    
6311           (a|(bc))\2           (a|(bc))\2
6312    
6313         always fails if it starts to match "a" rather than  "bc".  However,  if         always  fails  if  it starts to match "a" rather than "bc". However, if
6314         the PCRE_JAVASCRIPT_COMPAT option is set at compile time, a back refer-         the PCRE_JAVASCRIPT_COMPAT option is set at compile time, a back refer-
6315         ence to an unset value matches an empty string.         ence to an unset value matches an empty string.
6316    
6317         Because there may be many capturing parentheses in a pattern, all  dig-         Because  there may be many capturing parentheses in a pattern, all dig-
6318         its  following a backslash are taken as part of a potential back refer-         its following a backslash are taken as part of a potential back  refer-
6319         ence number.  If the pattern continues with  a  digit  character,  some         ence  number.   If  the  pattern continues with a digit character, some
6320         delimiter  must  be  used  to  terminate  the  back  reference.  If the         delimiter must  be  used  to  terminate  the  back  reference.  If  the
6321         PCRE_EXTENDED option is set, this can be white  space.  Otherwise,  the         PCRE_EXTENDED  option  is  set, this can be white space. Otherwise, the
6322         \g{ syntax or an empty comment (see "Comments" below) can be used.         \g{ syntax or an empty comment (see "Comments" below) can be used.
6323    
6324     Recursive back references     Recursive back references
6325    
6326         A  back reference that occurs inside the parentheses to which it refers         A back reference that occurs inside the parentheses to which it  refers
6327         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
6328         matches.   However,  such references can be useful inside repeated sub-         matches.  However, such references can be useful inside  repeated  sub-
6329         patterns. For example, the pattern         patterns. For example, the pattern
6330    
6331           (a|b\1)+           (a|b\1)+
6332    
6333         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-
6334         ation  of  the  subpattern,  the  back  reference matches the character         ation of the subpattern,  the  back  reference  matches  the  character
6335         string corresponding to the previous iteration. In order  for  this  to         string  corresponding  to  the previous iteration. In order for this to
6336         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
6337         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
6338         the example above, or by a quantifier with a minimum of zero.         the example above, or by a quantifier with a minimum of zero.
6339    
6340         Back  references of this type cause the group that they reference to be         Back references of this type cause the group that they reference to  be
6341         treated as an atomic group.  Once the whole group has been  matched,  a         treated  as  an atomic group.  Once the whole group has been matched, a
6342         subsequent  matching  failure cannot cause backtracking into the middle         subsequent matching failure cannot cause backtracking into  the  middle
6343         of the group.         of the group.
6344    
6345    
6346  ASSERTIONS  ASSERTIONS
6347    
6348         An assertion is a test on the characters  following  or  preceding  the         An  assertion  is  a  test on the characters following or preceding the
6349         current  matching  point that does not actually consume any characters.         current matching point that does not actually consume  any  characters.
6350         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
6351         described above.         described above.
6352    
6353         More  complicated  assertions  are  coded as subpatterns. There are two         More complicated assertions are coded as  subpatterns.  There  are  two
6354         kinds: those that look ahead of the current  position  in  the  subject         kinds:  those  that  look  ahead of the current position in the subject
6355         string,  and  those  that  look  behind  it. An assertion subpattern is         string, and those that look  behind  it.  An  assertion  subpattern  is
6356         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
6357         matching position to be changed.         matching position to be changed.
6358    
6359         Assertion  subpatterns are not capturing subpatterns. If such an asser-         Assertion subpatterns are not capturing subpatterns. If such an  asser-
6360         tion contains capturing subpatterns within it, these  are  counted  for         tion  contains  capturing  subpatterns within it, these are counted for
6361         the  purposes  of numbering the capturing subpatterns in the whole pat-         the purposes of numbering the capturing subpatterns in the  whole  pat-
6362         tern. However, substring capturing is carried  out  only  for  positive         tern.  However,  substring  capturing  is carried out only for positive
6363         assertions. (Perl sometimes, but not always, does do capturing in nega-         assertions. (Perl sometimes, but not always, does do capturing in nega-
6364         tive assertions.)         tive assertions.)
6365    
6366         For compatibility with Perl, assertion  subpatterns  may  be  repeated;         For  compatibility  with  Perl,  assertion subpatterns may be repeated;
6367         though  it  makes  no sense to assert the same thing several times, the         though it makes no sense to assert the same thing  several  times,  the
6368         side effect of capturing parentheses may  occasionally  be  useful.  In         side  effect  of  capturing  parentheses may occasionally be useful. In
6369         practice, there only three cases:         practice, there only three cases:
6370    
6371         (1)  If  the  quantifier  is  {0}, the assertion is never obeyed during         (1) If the quantifier is {0}, the  assertion  is  never  obeyed  during
6372         matching.  However, it may  contain  internal  capturing  parenthesized         matching.   However,  it  may  contain internal capturing parenthesized
6373         groups that are called from elsewhere via the subroutine mechanism.         groups that are called from elsewhere via the subroutine mechanism.
6374    
6375         (2)  If quantifier is {0,n} where n is greater than zero, it is treated         (2) If quantifier is {0,n} where n is greater than zero, it is  treated
6376         as if it were {0,1}. At run time, the rest  of  the  pattern  match  is         as  if  it  were  {0,1}.  At run time, the rest of the pattern match is
6377         tried with and without the assertion, the order depending on the greed-         tried with and without the assertion, the order depending on the greed-
6378         iness of the quantifier.         iness of the quantifier.
6379    
6380         (