/[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 517 by ph10, Tue Mar 30 11:11:52 2010 UTC revision 518 by ph10, Tue May 18 15:47:01 2010 UTC
# Line 2  Line 2 
2  This file contains a concatenation of the PCRE man pages, converted to plain  This file contains a concatenation of the PCRE man pages, converted to plain
3  text format for ease of searching with a text editor, or for use on systems  text format for ease of searching with a text editor, or for use on systems
4  that do not have a man page processor. The small individual files that give  that do not have a man page processor. The small individual files that give
5  synopses of each function in the library have not been included. Neither has  synopses of each function in the library have not been included. Neither has
6  the pcredemo program. There are separate text files for the pcregrep and  the pcredemo program. There are separate text files for the pcregrep and
7  pcretest commands.  pcretest commands.
8  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
# Line 26  INTRODUCTION Line 26  INTRODUCTION
26         give better JavaScript compatibility.         give better JavaScript compatibility.
27    
28         The  current implementation of PCRE corresponds approximately with Perl         The  current implementation of PCRE corresponds approximately with Perl
29         5.10, including support for UTF-8 encoded strings and  Unicode  general         5.10/5.11, including support for UTF-8 encoded strings and Unicode gen-
30         category  properties.  However,  UTF-8  and  Unicode  support has to be         eral  category properties. However, UTF-8 and Unicode support has to be
31         explicitly enabled; it is not the default. The  Unicode  tables  corre-         explicitly enabled; it is not the default. The  Unicode  tables  corre-
32         spond to Unicode release 5.2.0.         spond to Unicode release 5.2.0.
33    
# Line 222  UTF-8 AND UNICODE PROPERTY SUPPORT Line 222  UTF-8 AND UNICODE PROPERTY SUPPORT
222         not available in the alternative matching function, pcre_dfa_exec().         not available in the alternative matching function, pcre_dfa_exec().
223    
224         6.  The  character escapes \b, \B, \d, \D, \s, \S, \w, and \W correctly         6.  The  character escapes \b, \B, \d, \D, \s, \S, \w, and \W correctly
225         test characters of any code value, but the characters that PCRE  recog-         test characters of any code value, but, by default, the characters that
226         nizes  as  digits,  spaces,  or  word characters remain the same set as         PCRE  recognizes  as digits, spaces, or word characters remain the same
227         before, all with values less than 256. This remains true even when PCRE         set as before, all with values less than 256. This  remains  true  even
228         includes  Unicode  property support, because to do otherwise would slow         when  PCRE  is built to include Unicode property support, because to do
229         down PCRE in many common cases. If you really want to test for a  wider         otherwise would slow down PCRE in many common  cases.  Note  that  this
230         sense  of,  say,  "digit",  you must use Unicode property tests such as         also applies to \b, because it is defined in terms of \w and \W. If you
231         \p{Nd}. Note that this also applies to \b, because  it  is  defined  in         really want to test for a wider sense of, say,  "digit",  you  can  use
232         terms of \w and \W.         explicit  Unicode property tests such as \p{Nd}.  Alternatively, if you
233           set the PCRE_UCP option, the way that the  character  escapes  work  is
234           changed  so that Unicode properties are used to determine which charac-
235           ters match. There are more details in the section on generic  character
236           types in the pcrepattern documentation.
237    
238         7.  Similarly,  characters that match the POSIX named character classes         7.  Similarly,  characters that match the POSIX named character classes
239         are all low-valued characters.         are all low-valued characters, unless the PCRE_UCP option is set.
240    
241         8. However, the Perl 5.10 horizontal and vertical  whitespace  matching         8. However, the Perl 5.10 horizontal and vertical  whitespace  matching
242         escapes (\h, \H, \v, and \V) do match all the appropriate Unicode char-         escapes (\h, \H, \v, and \V) do match all the appropriate Unicode char-
243         acters.         acters, whether or not PCRE_UCP is set.
244    
245         9. Case-insensitive matching applies only to  characters  whose  values         9. Case-insensitive matching applies only to  characters  whose  values
246         are  less than 128, unless PCRE is built with Unicode property support.         are  less than 128, unless PCRE is built with Unicode property support.
# Line 263  AUTHOR Line 267  AUTHOR
267    
268  REVISION  REVISION
269    
270         Last updated: 01 March 2010         Last updated: 12 May 2010
271         Copyright (c) 1997-2010 University of Cambridge.         Copyright (c) 1997-2010 University of Cambridge.
272  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
273    
274    
275  PCREBUILD(3)                                                      PCREBUILD(3)  PCREBUILD(3)                                                      PCREBUILD(3)
276    
277    
# Line 597  REVISION Line 601  REVISION
601         Last updated: 29 September 2009         Last updated: 29 September 2009
602         Copyright (c) 1997-2009 University of Cambridge.         Copyright (c) 1997-2009 University of Cambridge.
603  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
604    
605    
606  PCREMATCHING(3)                                                PCREMATCHING(3)  PCREMATCHING(3)                                                PCREMATCHING(3)
607    
608    
# Line 797  REVISION Line 801  REVISION
801         Last updated: 29 September 2009         Last updated: 29 September 2009
802         Copyright (c) 1997-2009 University of Cambridge.         Copyright (c) 1997-2009 University of Cambridge.
803  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
804    
805    
806  PCREAPI(3)                                                          PCREAPI(3)  PCREAPI(3)                                                          PCREAPI(3)
807    
808    
# Line 1281  COMPILING A PATTERN Line 1285  COMPILING A PATTERN
1285         letter that has no special meaning  causes  an  error,  thus  reserving         letter that has no special meaning  causes  an  error,  thus  reserving
1286         these  combinations  for  future  expansion.  By default, as in Perl, a         these  combinations  for  future  expansion.  By default, as in Perl, a
1287         backslash followed by a letter with no special meaning is treated as  a         backslash followed by a letter with no special meaning is treated as  a
1288         literal.  (Perl can, however, be persuaded to give a warning for this.)         literal. (Perl can, however, be persuaded to give an error for this, by
1289         There are at present no other features controlled by  this  option.  It         running it with the -w option.) There are at present no other  features
1290         can also be set by a (?X) option setting within a pattern.         controlled  by this option. It can also be set by a (?X) option setting
1291           within a pattern.
1292    
1293           PCRE_FIRSTLINE           PCRE_FIRSTLINE
1294    
1295         If  this  option  is  set,  an  unanchored pattern is required to match         If this option is set, an  unanchored  pattern  is  required  to  match
1296         before or at the first  newline  in  the  subject  string,  though  the         before  or  at  the  first  newline  in  the subject string, though the
1297         matched text may continue over the newline.         matched text may continue over the newline.
1298    
1299           PCRE_JAVASCRIPT_COMPAT           PCRE_JAVASCRIPT_COMPAT
1300    
1301         If this option is set, PCRE's behaviour is changed in some ways so that         If this option is set, PCRE's behaviour is changed in some ways so that
1302         it is compatible with JavaScript rather than Perl. The changes  are  as         it  is  compatible with JavaScript rather than Perl. The changes are as
1303         follows:         follows:
1304    
1305         (1)  A  lone  closing square bracket in a pattern causes a compile-time         (1) A lone closing square bracket in a pattern  causes  a  compile-time
1306         error, because this is illegal in JavaScript (by default it is  treated         error,  because this is illegal in JavaScript (by default it is treated
1307         as a data character). Thus, the pattern AB]CD becomes illegal when this         as a data character). Thus, the pattern AB]CD becomes illegal when this
1308         option is set.         option is set.
1309    
1310         (2) At run time, a back reference to an unset subpattern group  matches         (2)  At run time, a back reference to an unset subpattern group matches
1311         an  empty  string (by default this causes the current matching alterna-         an empty string (by default this causes the current  matching  alterna-
1312         tive to fail). A pattern such as (\1)(a) succeeds when this  option  is         tive  to  fail). A pattern such as (\1)(a) succeeds when this option is
1313         set  (assuming  it can find an "a" in the subject), whereas it fails by         set (assuming it can find an "a" in the subject), whereas it  fails  by
1314         default, for Perl compatibility.         default, for Perl compatibility.
1315    
1316           PCRE_MULTILINE           PCRE_MULTILINE
1317    
1318         By default, PCRE treats the subject string as consisting  of  a  single         By  default,  PCRE  treats the subject string as consisting of a single
1319         line  of characters (even if it actually contains newlines). The "start         line of characters (even if it actually contains newlines). The  "start
1320         of line" metacharacter (^) matches only at the  start  of  the  string,         of  line"  metacharacter  (^)  matches only at the start of the string,
1321         while  the  "end  of line" metacharacter ($) matches only at the end of         while the "end of line" metacharacter ($) matches only at  the  end  of
1322         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY
1323         is set). This is the same as Perl.         is set). This is the same as Perl.
1324    
1325         When  PCRE_MULTILINE  it  is set, the "start of line" and "end of line"         When PCRE_MULTILINE it is set, the "start of line" and  "end  of  line"
1326         constructs match immediately following or immediately  before  internal         constructs  match  immediately following or immediately before internal
1327         newlines  in  the  subject string, respectively, as well as at the very         newlines in the subject string, respectively, as well as  at  the  very
1328         start and end. This is equivalent to Perl's /m option, and  it  can  be         start  and  end.  This is equivalent to Perl's /m option, and it can be
1329         changed within a pattern by a (?m) option setting. If there are no new-         changed within a pattern by a (?m) option setting. If there are no new-
1330         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,
1331         setting PCRE_MULTILINE has no effect.         setting PCRE_MULTILINE has no effect.
1332    
1333           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
# Line 1331  COMPILING A PATTERN Line 1336  COMPILING A PATTERN
1336           PCRE_NEWLINE_ANYCRLF           PCRE_NEWLINE_ANYCRLF
1337           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
1338    
1339         These  options  override the default newline definition that was chosen         These options override the default newline definition that  was  chosen
1340         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
1341         newline  is  indicated  by a single character (CR or LF, respectively).         newline is indicated by a single character (CR  or  LF,  respectively).
1342         Setting PCRE_NEWLINE_CRLF specifies that a newline is indicated by  the         Setting  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the
1343         two-character  CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF specifies         two-character CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF  specifies
1344         that any of the three preceding sequences should be recognized. Setting         that any of the three preceding sequences should be recognized. Setting
1345         PCRE_NEWLINE_ANY  specifies that any Unicode newline sequence should be         PCRE_NEWLINE_ANY specifies that any Unicode newline sequence should  be
1346         recognized. The Unicode newline sequences are the three just mentioned,         recognized. The Unicode newline sequences are the three just mentioned,
1347         plus  the  single  characters  VT (vertical tab, U+000B), FF (formfeed,         plus the single characters VT (vertical  tab,  U+000B),  FF  (formfeed,
1348         U+000C), NEL (next line, U+0085), LS (line separator, U+2028),  and  PS         U+000C),  NEL  (next line, U+0085), LS (line separator, U+2028), and PS
1349         (paragraph  separator,  U+2029).  The  last  two are recognized only in         (paragraph separator, U+2029). The last  two  are  recognized  only  in
1350         UTF-8 mode.         UTF-8 mode.
1351    
1352         The newline setting in the  options  word  uses  three  bits  that  are         The  newline  setting  in  the  options  word  uses three bits that are
1353         treated as a number, giving eight possibilities. Currently only six are         treated as a number, giving eight possibilities. Currently only six are
1354         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
1355         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-
1356         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
1357         PCRE_NEWLINE_CRLF,  but other combinations may yield unused numbers and         PCRE_NEWLINE_CRLF, but other combinations may yield unused numbers  and
1358         cause an error.         cause an error.
1359    
1360         The only time that a line break is specially recognized when  compiling         The  only time that a line break is specially recognized when compiling
1361         a  pattern  is  if  PCRE_EXTENDED  is set, and an unescaped # outside a         a pattern is if PCRE_EXTENDED is set, and  an  unescaped  #  outside  a
1362         character class is encountered. This indicates  a  comment  that  lasts         character  class  is  encountered.  This indicates a comment that lasts
1363         until  after the next line break sequence. In other circumstances, line         until after the next line break sequence. In other circumstances,  line
1364         break  sequences  are  treated  as  literal  data,   except   that   in         break   sequences   are   treated  as  literal  data,  except  that  in
1365         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters
1366         and are therefore ignored.         and are therefore ignored.
1367    
# Line 1366  COMPILING A PATTERN Line 1371  COMPILING A PATTERN
1371           PCRE_NO_AUTO_CAPTURE           PCRE_NO_AUTO_CAPTURE
1372    
1373         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-
1374         theses in the pattern. Any opening parenthesis that is not followed  by         theses  in the pattern. Any opening parenthesis that is not followed by
1375         ?  behaves as if it were followed by ?: but named parentheses can still         ? behaves as if it were followed by ?: but named parentheses can  still
1376         be used for capturing (and they acquire  numbers  in  the  usual  way).         be  used  for  capturing  (and  they acquire numbers in the usual way).
1377         There is no equivalent of this option in Perl.         There is no equivalent of this option in Perl.
1378    
1379           PCRE_UNGREEDY           PCRE_UNGREEDY
1380    
1381         This  option  inverts  the "greediness" of the quantifiers so that they         This option inverts the "greediness" of the quantifiers  so  that  they
1382         are not greedy by default, but become greedy if followed by "?". It  is         are  not greedy by default, but become greedy if followed by "?". It is
1383         not  compatible  with Perl. It can also be set by a (?U) option setting         not compatible with Perl. It can also be set by a (?U)  option  setting
1384         within the pattern.         within the pattern.
1385    
1386           PCRE_UTF8           PCRE_UTF8
1387    
1388         This option causes PCRE to regard both the pattern and the  subject  as         This  option  causes PCRE to regard both the pattern and the subject as
1389         strings  of  UTF-8 characters instead of single-byte character strings.         strings of UTF-8 characters instead of single-byte  character  strings.
1390         However, it is available only when PCRE is built to include UTF-8  sup-         However,  it is available only when PCRE is built to include UTF-8 sup-
1391         port.  If not, the use of this option provokes an error. Details of how         port. If not, the use of this option provokes an error. Details of  how
1392         this option changes the behaviour of PCRE are given in the  section  on         this  option  changes the behaviour of PCRE are given in the section on
1393         UTF-8 support in the main pcre page.         UTF-8 support in the main pcre page.
1394    
1395           PCRE_NO_UTF8_CHECK           PCRE_NO_UTF8_CHECK
1396    
1397         When PCRE_UTF8 is set, the validity of the pattern as a UTF-8 string is         When PCRE_UTF8 is set, the validity of the pattern as a UTF-8 string is
1398         automatically checked. There is a  discussion  about  the  validity  of         automatically  checked.  There  is  a  discussion about the validity of
1399         UTF-8  strings  in  the main pcre page. If an invalid UTF-8 sequence of         UTF-8 strings in the main pcre page. If an invalid  UTF-8  sequence  of
1400         bytes is found, pcre_compile() returns an error. If  you  already  know         bytes  is  found,  pcre_compile() returns an error. If you already know
1401         that your pattern is valid, and you want to skip this check for perfor-         that your pattern is valid, and you want to skip this check for perfor-
1402         mance reasons, you can set the PCRE_NO_UTF8_CHECK option.  When  it  is         mance  reasons,  you  can set the PCRE_NO_UTF8_CHECK option. When it is
1403         set,  the  effect  of  passing  an invalid UTF-8 string as a pattern is         set, the effect of passing an invalid UTF-8  string  as  a  pattern  is
1404         undefined. It may cause your program to crash. Note  that  this  option         undefined.  It  may  cause your program to crash. Note that this option
1405         can  also be passed to pcre_exec() and pcre_dfa_exec(), to suppress the         can also be passed to pcre_exec() and pcre_dfa_exec(), to suppress  the
1406         UTF-8 validity checking of subject strings.         UTF-8 validity checking of subject strings.
1407    
1408    
1409  COMPILATION ERROR CODES  COMPILATION ERROR CODES
1410    
1411         The following table lists the error  codes  than  may  be  returned  by         The  following  table  lists  the  error  codes than may be returned by
1412         pcre_compile2(),  along with the error messages that may be returned by         pcre_compile2(), along with the error messages that may be returned  by
1413         both compiling functions. As PCRE has developed, some error codes  have         both  compiling functions. As PCRE has developed, some error codes have
1414         fallen out of use. To avoid confusion, they have not been re-used.         fallen out of use. To avoid confusion, they have not been re-used.
1415    
1416            0  no error            0  no error
# Line 1461  COMPILATION ERROR CODES Line 1466  COMPILATION ERROR CODES
1466           50  [this code is not in use]           50  [this code is not in use]
1467           51  octal value is greater than \377 (not in UTF-8 mode)           51  octal value is greater than \377 (not in UTF-8 mode)
1468           52  internal error: overran compiling workspace           52  internal error: overran compiling workspace
1469           53   internal  error:  previously-checked  referenced  subpattern not           53  internal  error:  previously-checked  referenced  subpattern  not
1470         found         found
1471           54  DEFINE group contains more than one branch           54  DEFINE group contains more than one branch
1472           55  repeating a DEFINE group is not allowed           55  repeating a DEFINE group is not allowed
# Line 1475  COMPILATION ERROR CODES Line 1480  COMPILATION ERROR CODES
1480           62  subpattern name expected           62  subpattern name expected
1481           63  digit expected after (?+           63  digit expected after (?+
1482           64  ] is an invalid data character in JavaScript compatibility mode           64  ] is an invalid data character in JavaScript compatibility mode
1483           65  different names for  subpatterns  of  the  same  number  are  not           65   different  names  for  subpatterns  of  the  same number are not
1484         allowed         allowed
1485           66  (*MARK) must have an argument           66  (*MARK) must have an argument
1486    
1487         The  numbers  32  and 10000 in errors 48 and 49 are defaults; different         The numbers 32 and 10000 in errors 48 and 49  are  defaults;  different
1488         values may be used if the limits were changed when PCRE was built.         values may be used if the limits were changed when PCRE was built.
1489    
1490    
# Line 1488  STUDYING A PATTERN Line 1493  STUDYING A PATTERN
1493         pcre_extra *pcre_study(const pcre *code, int options         pcre_extra *pcre_study(const pcre *code, int options
1494              const char **errptr);              const char **errptr);
1495    
1496         If a compiled pattern is going to be used several times,  it  is  worth         If  a  compiled  pattern is going to be used several times, it is worth
1497         spending more time analyzing it in order to speed up the time taken for         spending more time analyzing it in order to speed up the time taken for
1498         matching. The function pcre_study() takes a pointer to a compiled  pat-         matching.  The function pcre_study() takes a pointer to a compiled pat-
1499         tern as its first argument. If studying the pattern produces additional         tern as its first argument. If studying the pattern produces additional
1500         information that will help speed up matching,  pcre_study()  returns  a         information  that  will  help speed up matching, pcre_study() returns a
1501         pointer  to a pcre_extra block, in which the study_data field points to         pointer to a pcre_extra block, in which the study_data field points  to
1502         the results of the study.         the results of the study.
1503    
1504         The  returned  value  from  pcre_study()  can  be  passed  directly  to         The  returned  value  from  pcre_study()  can  be  passed  directly  to
1505         pcre_exec()  or  pcre_dfa_exec(). However, a pcre_extra block also con-         pcre_exec() or pcre_dfa_exec(). However, a pcre_extra block  also  con-
1506         tains other fields that can be set by the caller before  the  block  is         tains  other  fields  that can be set by the caller before the block is
1507         passed; these are described below in the section on matching a pattern.         passed; these are described below in the section on matching a pattern.
1508    
1509         If  studying  the  pattern  does  not  produce  any useful information,         If studying the  pattern  does  not  produce  any  useful  information,
1510         pcre_study() returns NULL. In that circumstance, if the calling program         pcre_study() returns NULL. In that circumstance, if the calling program
1511         wants   to   pass   any   of   the   other  fields  to  pcre_exec()  or         wants  to  pass  any  of   the   other   fields   to   pcre_exec()   or
1512         pcre_dfa_exec(), it must set up its own pcre_extra block.         pcre_dfa_exec(), it must set up its own pcre_extra block.
1513    
1514         The second argument of pcre_study() contains option bits.  At  present,         The  second  argument of pcre_study() contains option bits. At present,
1515         no options are defined, and this argument should always be zero.         no options are defined, and this argument should always be zero.
1516    
1517         The  third argument for pcre_study() is a pointer for an error message.         The third argument for pcre_study() is a pointer for an error  message.
1518         If studying succeeds (even if no data is  returned),  the  variable  it         If  studying  succeeds  (even  if no data is returned), the variable it
1519         points  to  is  set  to NULL. Otherwise it is set to point to a textual         points to is set to NULL. Otherwise it is set to  point  to  a  textual
1520         error message. This is a static string that is part of the library. You         error message. This is a static string that is part of the library. You
1521         must  not  try  to  free it. You should test the error pointer for NULL         must not try to free it. You should test the  error  pointer  for  NULL
1522         after calling pcre_study(), to be sure that it has run successfully.         after calling pcre_study(), to be sure that it has run successfully.
1523    
1524         This is a typical call to pcre_study():         This is a typical call to pcre_study():
# Line 1527  STUDYING A PATTERN Line 1532  STUDYING A PATTERN
1532         Studying a pattern does two things: first, a lower bound for the length         Studying a pattern does two things: first, a lower bound for the length
1533         of subject string that is needed to match the pattern is computed. This         of subject string that is needed to match the pattern is computed. This
1534         does not mean that there are any strings of that length that match, but         does not mean that there are any strings of that length that match, but
1535         it  does  guarantee that no shorter strings match. The value is used by         it does guarantee that no shorter strings match. The value is  used  by
1536         pcre_exec() and pcre_dfa_exec() to avoid  wasting  time  by  trying  to         pcre_exec()  and  pcre_dfa_exec()  to  avoid  wasting time by trying to
1537         match  strings  that are shorter than the lower bound. You can find out         match strings that are shorter than the lower bound. You can  find  out
1538         the value in a calling program via the pcre_fullinfo() function.         the value in a calling program via the pcre_fullinfo() function.
1539    
1540         Studying a pattern is also useful for non-anchored patterns that do not         Studying a pattern is also useful for non-anchored patterns that do not
1541         have  a  single fixed starting character. A bitmap of possible starting         have a single fixed starting character. A bitmap of  possible  starting
1542         bytes is created. This speeds up finding a position in the  subject  at         bytes  is  created. This speeds up finding a position in the subject at
1543         which to start matching.         which to start matching.
1544    
1545    
1546  LOCALE SUPPORT  LOCALE SUPPORT
1547    
1548         PCRE  handles  caseless matching, and determines whether characters are         PCRE handles caseless matching, and determines whether  characters  are
1549         letters, digits, or whatever, by reference to a set of tables,  indexed         letters,  digits, or whatever, by reference to a set of tables, indexed
1550         by  character  value.  When running in UTF-8 mode, this applies only to         by character value. When running in UTF-8 mode, this  applies  only  to
1551         characters with codes less than 128. Higher-valued  codes  never  match         characters  with  codes  less than 128. Higher-valued codes never match
1552         escapes  such  as  \w or \d, but can be tested with \p if PCRE is built         escapes such as \w or \d, but can be tested with \p if  PCRE  is  built
1553         with Unicode character property support. The use of locales  with  Uni-         with  Unicode  character property support. The use of locales with Uni-
1554         code  is discouraged. If you are handling characters with codes greater         code is discouraged. If you are handling characters with codes  greater
1555         than 128, you should either use UTF-8 and Unicode, or use locales,  but         than  128, you should either use UTF-8 and Unicode, or use locales, but
1556         not try to mix the two.         not try to mix the two.
1557    
1558         PCRE  contains  an  internal set of tables that are used when the final         PCRE contains an internal set of tables that are used  when  the  final
1559         argument of pcre_compile() is  NULL.  These  are  sufficient  for  many         argument  of  pcre_compile()  is  NULL.  These  are sufficient for many
1560         applications.  Normally, the internal tables recognize only ASCII char-         applications.  Normally, the internal tables recognize only ASCII char-
1561         acters. However, when PCRE is built, it is possible to cause the inter-         acters. However, when PCRE is built, it is possible to cause the inter-
1562         nal tables to be rebuilt in the default "C" locale of the local system,         nal tables to be rebuilt in the default "C" locale of the local system,
1563         which may cause them to be different.         which may cause them to be different.
1564    
1565         The internal tables can always be overridden by tables supplied by  the         The  internal tables can always be overridden by tables supplied by the
1566         application that calls PCRE. These may be created in a different locale         application that calls PCRE. These may be created in a different locale
1567         from the default. As more and more applications change  to  using  Uni-         from  the  default.  As more and more applications change to using Uni-
1568         code, the need for this locale support is expected to die away.         code, the need for this locale support is expected to die away.
1569    
1570         External  tables  are  built by calling the pcre_maketables() function,         External tables are built by calling  the  pcre_maketables()  function,
1571         which has no arguments, in the relevant locale. The result can then  be         which  has no arguments, in the relevant locale. The result can then be
1572         passed  to  pcre_compile()  or  pcre_exec()  as often as necessary. For         passed to pcre_compile() or pcre_exec()  as  often  as  necessary.  For
1573         example, to build and use tables that are appropriate  for  the  French         example,  to  build  and use tables that are appropriate for the French
1574         locale  (where  accented  characters  with  values greater than 128 are         locale (where accented characters with  values  greater  than  128  are
1575         treated as letters), the following code could be used:         treated as letters), the following code could be used:
1576    
1577           setlocale(LC_CTYPE, "fr_FR");           setlocale(LC_CTYPE, "fr_FR");
1578           tables = pcre_maketables();           tables = pcre_maketables();
1579           re = pcre_compile(..., tables);           re = pcre_compile(..., tables);
1580    
1581         The locale name "fr_FR" is used on Linux and other  Unix-like  systems;         The  locale  name "fr_FR" is used on Linux and other Unix-like systems;
1582         if you are using Windows, the name for the French locale is "french".         if you are using Windows, the name for the French locale is "french".
1583    
1584         When  pcre_maketables()  runs,  the  tables are built in memory that is         When pcre_maketables() runs, the tables are built  in  memory  that  is
1585         obtained via pcre_malloc. It is the caller's responsibility  to  ensure         obtained  via  pcre_malloc. It is the caller's responsibility to ensure
1586         that  the memory containing the tables remains available for as long as         that the memory containing the tables remains available for as long  as
1587         it is needed.         it is needed.
1588    
1589         The pointer that is passed to pcre_compile() is saved with the compiled         The pointer that is passed to pcre_compile() is saved with the compiled
1590         pattern,  and the same tables are used via this pointer by pcre_study()         pattern, and the same tables are used via this pointer by  pcre_study()
1591         and normally also by pcre_exec(). Thus, by default, for any single pat-         and normally also by pcre_exec(). Thus, by default, for any single pat-
1592         tern, compilation, studying and matching all happen in the same locale,         tern, compilation, studying and matching all happen in the same locale,
1593         but different patterns can be compiled in different locales.         but different patterns can be compiled in different locales.
1594    
1595         It is possible to pass a table pointer or NULL (indicating the  use  of         It  is  possible to pass a table pointer or NULL (indicating the use of
1596         the  internal  tables)  to  pcre_exec(). Although not intended for this         the internal tables) to pcre_exec(). Although  not  intended  for  this
1597         purpose, this facility could be used to match a pattern in a  different         purpose,  this facility could be used to match a pattern in a different
1598         locale from the one in which it was compiled. Passing table pointers at         locale from the one in which it was compiled. Passing table pointers at
1599         run time is discussed below in the section on matching a pattern.         run time is discussed below in the section on matching a pattern.
1600    
# Line 1599  INFORMATION ABOUT A PATTERN Line 1604  INFORMATION ABOUT A PATTERN
1604         int pcre_fullinfo(const pcre *code, const pcre_extra *extra,         int pcre_fullinfo(const pcre *code, const pcre_extra *extra,
1605              int what, void *where);              int what, void *where);
1606    
1607         The pcre_fullinfo() function returns information about a compiled  pat-         The  pcre_fullinfo() function returns information about a compiled pat-
1608         tern. It replaces the obsolete pcre_info() function, which is neverthe-         tern. It replaces the obsolete pcre_info() function, which is neverthe-
1609         less retained for backwards compability (and is documented below).         less retained for backwards compability (and is documented below).
1610    
1611         The first argument for pcre_fullinfo() is a  pointer  to  the  compiled         The  first  argument  for  pcre_fullinfo() is a pointer to the compiled
1612         pattern.  The second argument is the result of pcre_study(), or NULL if         pattern. The second argument is the result of pcre_study(), or NULL  if
1613         the pattern was not studied. The third argument specifies  which  piece         the  pattern  was not studied. The third argument specifies which piece
1614         of  information  is required, and the fourth argument is a pointer to a         of information is required, and the fourth argument is a pointer  to  a
1615         variable to receive the data. The yield of the  function  is  zero  for         variable  to  receive  the  data. The yield of the function is zero for
1616         success, or one of the following negative numbers:         success, or one of the following negative numbers:
1617    
1618           PCRE_ERROR_NULL       the argument code was NULL           PCRE_ERROR_NULL       the argument code was NULL
# Line 1615  INFORMATION ABOUT A PATTERN Line 1620  INFORMATION ABOUT A PATTERN
1620           PCRE_ERROR_BADMAGIC   the "magic number" was not found           PCRE_ERROR_BADMAGIC   the "magic number" was not found
1621           PCRE_ERROR_BADOPTION  the value of what was invalid           PCRE_ERROR_BADOPTION  the value of what was invalid
1622    
1623         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
1624         an simple check against passing an arbitrary memory pointer. Here is  a         an  simple check against passing an arbitrary memory pointer. Here is a
1625         typical  call  of pcre_fullinfo(), to obtain the length of the compiled         typical call of pcre_fullinfo(), to obtain the length of  the  compiled
1626         pattern:         pattern:
1627    
1628           int rc;           int rc;
# Line 1628  INFORMATION ABOUT A PATTERN Line 1633  INFORMATION ABOUT A PATTERN
1633             PCRE_INFO_SIZE,   /* what is required */             PCRE_INFO_SIZE,   /* what is required */
1634             &length);         /* where to put the data */             &length);         /* where to put the data */
1635    
1636         The possible values for the third argument are defined in  pcre.h,  and         The  possible  values for the third argument are defined in pcre.h, and
1637         are as follows:         are as follows:
1638    
1639           PCRE_INFO_BACKREFMAX           PCRE_INFO_BACKREFMAX
1640    
1641         Return  the  number  of  the highest back reference in the pattern. The         Return the number of the highest back reference  in  the  pattern.  The
1642         fourth argument should point to an int variable. Zero  is  returned  if         fourth  argument  should  point to an int variable. Zero is returned if
1643         there are no back references.         there are no back references.
1644    
1645           PCRE_INFO_CAPTURECOUNT           PCRE_INFO_CAPTURECOUNT
1646    
1647         Return  the  number of capturing subpatterns in the pattern. The fourth         Return the number of capturing subpatterns in the pattern.  The  fourth
1648         argument should point to an int variable.         argument should point to an int variable.
1649    
1650           PCRE_INFO_DEFAULT_TABLES           PCRE_INFO_DEFAULT_TABLES
1651    
1652         Return a pointer to the internal default character tables within  PCRE.         Return  a pointer to the internal default character tables within PCRE.
1653         The  fourth  argument should point to an unsigned char * variable. This         The fourth argument should point to an unsigned char *  variable.  This
1654         information call is provided for internal use by the pcre_study() func-         information call is provided for internal use by the pcre_study() func-
1655         tion.  External  callers  can  cause PCRE to use its internal tables by         tion. External callers can cause PCRE to use  its  internal  tables  by
1656         passing a NULL table pointer.         passing a NULL table pointer.
1657    
1658           PCRE_INFO_FIRSTBYTE           PCRE_INFO_FIRSTBYTE
1659    
1660         Return information about the first byte of any matched  string,  for  a         Return  information  about  the first byte of any matched string, for a
1661         non-anchored  pattern. The fourth argument should point to an int vari-         non-anchored pattern. The fourth argument should point to an int  vari-
1662         able. (This option used to be called PCRE_INFO_FIRSTCHAR; the old  name         able.  (This option used to be called PCRE_INFO_FIRSTCHAR; the old name
1663         is still recognized for backwards compatibility.)         is still recognized for backwards compatibility.)
1664    
1665         If  there  is  a  fixed first byte, for example, from a pattern such as         If there is a fixed first byte, for example, from  a  pattern  such  as
1666         (cat|cow|coyote), its value is returned. Otherwise, if either         (cat|cow|coyote), its value is returned. Otherwise, if either
1667    
1668         (a) the pattern was compiled with the PCRE_MULTILINE option, and  every         (a)  the pattern was compiled with the PCRE_MULTILINE option, and every
1669         branch starts with "^", or         branch starts with "^", or
1670    
1671         (b) every branch of the pattern starts with ".*" and PCRE_DOTALL is not         (b) every branch of the pattern starts with ".*" and PCRE_DOTALL is not
1672         set (if it were set, the pattern would be anchored),         set (if it were set, the pattern would be anchored),
1673    
1674         -1 is returned, indicating that the pattern matches only at  the  start         -1  is  returned, indicating that the pattern matches only at the start
1675         of  a  subject string or after any newline within the string. Otherwise         of a subject string or after any newline within the  string.  Otherwise
1676         -2 is returned. For anchored patterns, -2 is returned.         -2 is returned. For anchored patterns, -2 is returned.
1677    
1678           PCRE_INFO_FIRSTTABLE           PCRE_INFO_FIRSTTABLE
1679    
1680         If the pattern was studied, and this resulted in the construction of  a         If  the pattern was studied, and this resulted in the construction of a
1681         256-bit table indicating a fixed set of bytes for the first byte in any         256-bit table indicating a fixed set of bytes for the first byte in any
1682         matching string, a pointer to the table is returned. Otherwise NULL  is         matching  string, a pointer to the table is returned. Otherwise NULL is
1683         returned.  The fourth argument should point to an unsigned char * vari-         returned. The fourth argument should point to an unsigned char *  vari-
1684         able.         able.
1685    
1686           PCRE_INFO_HASCRORLF           PCRE_INFO_HASCRORLF
1687    
1688         Return 1 if the pattern contains any explicit  matches  for  CR  or  LF         Return  1  if  the  pattern  contains any explicit matches for CR or LF
1689         characters,  otherwise  0.  The  fourth argument should point to an int         characters, otherwise 0. The fourth argument should  point  to  an  int
1690         variable. An explicit match is either a literal CR or LF character,  or         variable.  An explicit match is either a literal CR or LF character, or
1691         \r or \n.         \r or \n.
1692    
1693           PCRE_INFO_JCHANGED           PCRE_INFO_JCHANGED
1694    
1695         Return  1  if  the (?J) or (?-J) option setting is used in the pattern,         Return 1 if the (?J) or (?-J) option setting is used  in  the  pattern,
1696         otherwise 0. The fourth argument should point to an int variable.  (?J)         otherwise  0. The fourth argument should point to an int variable. (?J)
1697         and (?-J) set and unset the local PCRE_DUPNAMES option, respectively.         and (?-J) set and unset the local PCRE_DUPNAMES option, respectively.
1698    
1699           PCRE_INFO_LASTLITERAL           PCRE_INFO_LASTLITERAL
1700    
1701         Return  the  value of the rightmost literal byte that must exist in any         Return the value of the rightmost literal byte that must exist  in  any
1702         matched string, other than at its  start,  if  such  a  byte  has  been         matched  string,  other  than  at  its  start,  if such a byte has been
1703         recorded. The fourth argument should point to an int variable. If there         recorded. The fourth argument should point to an int variable. If there
1704         is no such byte, -1 is returned. For anchored patterns, a last  literal         is  no such byte, -1 is returned. For anchored patterns, a last literal
1705         byte  is  recorded only if it follows something of variable length. For         byte is recorded only if it follows something of variable  length.  For
1706         example, for the pattern /^a\d+z\d+/ the returned value is "z", but for         example, for the pattern /^a\d+z\d+/ the returned value is "z", but for
1707         /^a\dz\d/ the returned value is -1.         /^a\dz\d/ the returned value is -1.
1708    
1709           PCRE_INFO_MINLENGTH           PCRE_INFO_MINLENGTH
1710    
1711         If  the  pattern  was studied and a minimum length for matching subject         If the pattern was studied and a minimum length  for  matching  subject
1712         strings was computed, its value is  returned.  Otherwise  the  returned         strings  was  computed,  its  value is returned. Otherwise the returned
1713         value  is  -1. The value is a number of characters, not bytes (this may         value is -1. The value is a number of characters, not bytes  (this  may
1714         be relevant in UTF-8 mode). The fourth argument should point to an  int         be  relevant in UTF-8 mode). The fourth argument should point to an int
1715         variable.  A  non-negative  value is a lower bound to the length of any         variable. A non-negative value is a lower bound to the  length  of  any
1716         matching string. There may not be any strings of that  length  that  do         matching  string.  There  may not be any strings of that length that do
1717         actually match, but every string that does match is at least that long.         actually match, but every string that does match is at least that long.
1718    
1719           PCRE_INFO_NAMECOUNT           PCRE_INFO_NAMECOUNT
1720           PCRE_INFO_NAMEENTRYSIZE           PCRE_INFO_NAMEENTRYSIZE
1721           PCRE_INFO_NAMETABLE           PCRE_INFO_NAMETABLE
1722    
1723         PCRE  supports the use of named as well as numbered capturing parenthe-         PCRE supports the use of named as well as numbered capturing  parenthe-
1724         ses. The names are just an additional way of identifying the  parenthe-         ses.  The names are just an additional way of identifying the parenthe-
1725         ses, which still acquire numbers. Several convenience functions such as         ses, which still acquire numbers. Several convenience functions such as
1726         pcre_get_named_substring() are provided for  extracting  captured  sub-         pcre_get_named_substring()  are  provided  for extracting captured sub-
1727         strings  by  name. It is also possible to extract the data directly, by         strings by name. It is also possible to extract the data  directly,  by
1728         first converting the name to a number in order to  access  the  correct         first  converting  the  name to a number in order to access the correct
1729         pointers in the output vector (described with pcre_exec() below). To do         pointers in the output vector (described with pcre_exec() below). To do
1730         the conversion, you need  to  use  the  name-to-number  map,  which  is         the  conversion,  you  need  to  use  the  name-to-number map, which is
1731         described by these three values.         described by these three values.
1732    
1733         The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT         The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT
1734         gives the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size         gives the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size
1735         of  each  entry;  both  of  these  return  an int value. The entry size         of each entry; both of these  return  an  int  value.  The  entry  size
1736         depends on the length of the longest name. PCRE_INFO_NAMETABLE  returns         depends  on the length of the longest name. PCRE_INFO_NAMETABLE returns
1737         a  pointer  to  the  first  entry of the table (a pointer to char). The         a pointer to the first entry of the table  (a  pointer  to  char).  The
1738         first two bytes of each entry are the number of the capturing parenthe-         first two bytes of each entry are the number of the capturing parenthe-
1739         sis,  most  significant byte first. The rest of the entry is the corre-         sis, most significant byte first. The rest of the entry is  the  corre-
1740         sponding name, zero terminated.         sponding name, zero terminated.
1741    
1742         The names are in alphabetical order. Duplicate names may appear if  (?|         The  names are in alphabetical order. Duplicate names may appear if (?|
1743         is used to create multiple groups with the same number, as described in         is used to create multiple groups with the same number, as described in
1744         the section on duplicate subpattern numbers in  the  pcrepattern  page.         the  section  on  duplicate subpattern numbers in the pcrepattern page.
1745         Duplicate  names  for  subpatterns with different numbers are permitted         Duplicate names for subpatterns with different  numbers  are  permitted
1746         only if PCRE_DUPNAMES is set. In all cases  of  duplicate  names,  they         only  if  PCRE_DUPNAMES  is  set. In all cases of duplicate names, they
1747         appear  in  the table in the order in which they were found in the pat-         appear in the table in the order in which they were found in  the  pat-
1748         tern. In the absence of (?| this is the  order  of  increasing  number;         tern.  In  the  absence  of (?| this is the order of increasing number;
1749         when (?| is used this is not necessarily the case because later subpat-         when (?| is used this is not necessarily the case because later subpat-
1750         terns may have lower numbers.         terns may have lower numbers.
1751    
1752         As a simple example of the name/number table,  consider  the  following         As  a  simple  example of the name/number table, consider the following
1753         pattern  (assume  PCRE_EXTENDED is set, so white space - including new-         pattern (assume PCRE_EXTENDED is set, so white space -  including  new-
1754         lines - is ignored):         lines - is ignored):
1755    
1756           (?<date> (?<year>(\d\d)?\d\d) -           (?<date> (?<year>(\d\d)?\d\d) -
1757           (?<month>\d\d) - (?<day>\d\d) )           (?<month>\d\d) - (?<day>\d\d) )
1758    
1759         There are four named subpatterns, so the table has  four  entries,  and         There  are  four  named subpatterns, so the table has four entries, and
1760         each  entry  in the table is eight bytes long. The table is as follows,         each entry in the table is eight bytes long. The table is  as  follows,
1761         with non-printing bytes shows in hexadecimal, and undefined bytes shown         with non-printing bytes shows in hexadecimal, and undefined bytes shown
1762         as ??:         as ??:
1763    
# Line 1761  INFORMATION ABOUT A PATTERN Line 1766  INFORMATION ABOUT A PATTERN
1766           00 04 m  o  n  t  h  00           00 04 m  o  n  t  h  00
1767           00 02 y  e  a  r  00 ??           00 02 y  e  a  r  00 ??
1768    
1769         When  writing  code  to  extract  data from named subpatterns using the         When writing code to extract data  from  named  subpatterns  using  the
1770         name-to-number map, remember that the length of the entries  is  likely         name-to-number  map,  remember that the length of the entries is likely
1771         to be different for each compiled pattern.         to be different for each compiled pattern.
1772    
1773           PCRE_INFO_OKPARTIAL           PCRE_INFO_OKPARTIAL
1774    
1775         Return  1  if  the  pattern  can  be  used  for  partial  matching with         Return 1  if  the  pattern  can  be  used  for  partial  matching  with
1776         pcre_exec(), otherwise 0. The fourth argument should point  to  an  int         pcre_exec(),  otherwise  0.  The fourth argument should point to an int
1777         variable.  From  release  8.00,  this  always  returns  1,  because the         variable. From  release  8.00,  this  always  returns  1,  because  the
1778         restrictions that previously applied  to  partial  matching  have  been         restrictions  that  previously  applied  to  partial matching have been
1779         lifted.  The  pcrepartial documentation gives details of partial match-         lifted. The pcrepartial documentation gives details of  partial  match-
1780         ing.         ing.
1781    
1782           PCRE_INFO_OPTIONS           PCRE_INFO_OPTIONS
1783    
1784         Return a copy of the options with which the pattern was  compiled.  The         Return  a  copy of the options with which the pattern was compiled. The
1785         fourth  argument  should  point to an unsigned long int variable. These         fourth argument should point to an unsigned long  int  variable.  These
1786         option bits are those specified in the call to pcre_compile(), modified         option bits are those specified in the call to pcre_compile(), modified
1787         by any top-level option settings at the start of the pattern itself. In         by any top-level option settings at the start of the pattern itself. In
1788         other words, they are the options that will be in force  when  matching         other  words,  they are the options that will be in force when matching
1789         starts.  For  example, if the pattern /(?im)abc(?-i)d/ is compiled with         starts. For example, if the pattern /(?im)abc(?-i)d/ is  compiled  with
1790         the PCRE_EXTENDED option, the result is PCRE_CASELESS,  PCRE_MULTILINE,         the  PCRE_EXTENDED option, the result is PCRE_CASELESS, PCRE_MULTILINE,
1791         and PCRE_EXTENDED.         and PCRE_EXTENDED.
1792    
1793         A  pattern  is  automatically  anchored by PCRE if all of its top-level         A pattern is automatically anchored by PCRE if  all  of  its  top-level
1794         alternatives begin with one of the following:         alternatives begin with one of the following:
1795    
1796           ^     unless PCRE_MULTILINE is set           ^     unless PCRE_MULTILINE is set
# Line 1799  INFORMATION ABOUT A PATTERN Line 1804  INFORMATION ABOUT A PATTERN
1804    
1805           PCRE_INFO_SIZE           PCRE_INFO_SIZE
1806    
1807         Return  the  size  of the compiled pattern, that is, the value that was         Return the size of the compiled pattern, that is, the  value  that  was
1808         passed as the argument to pcre_malloc() when PCRE was getting memory in         passed as the argument to pcre_malloc() when PCRE was getting memory in
1809         which to place the compiled data. The fourth argument should point to a         which to place the compiled data. The fourth argument should point to a
1810         size_t variable.         size_t variable.
# Line 1807  INFORMATION ABOUT A PATTERN Line 1812  INFORMATION ABOUT A PATTERN
1812           PCRE_INFO_STUDYSIZE           PCRE_INFO_STUDYSIZE
1813    
1814         Return the size of the data block pointed to by the study_data field in         Return the size of the data block pointed to by the study_data field in
1815         a  pcre_extra  block.  That  is,  it  is  the  value that was passed to         a pcre_extra block. That is,  it  is  the  value  that  was  passed  to
1816         pcre_malloc() when PCRE was getting memory into which to place the data         pcre_malloc() when PCRE was getting memory into which to place the data
1817         created  by  pcre_study().  If pcre_extra is NULL, or there is no study         created by pcre_study(). If pcre_extra is NULL, or there  is  no  study
1818         data, zero is returned. The fourth argument should point  to  a  size_t         data,  zero  is  returned. The fourth argument should point to a size_t
1819         variable.         variable.
1820    
1821    
# Line 1818  OBSOLETE INFO FUNCTION Line 1823  OBSOLETE INFO FUNCTION
1823    
1824         int pcre_info(const pcre *code, int *optptr, int *firstcharptr);         int pcre_info(const pcre *code, int *optptr, int *firstcharptr);
1825    
1826         The  pcre_info()  function is now obsolete because its interface is too         The pcre_info() function is now obsolete because its interface  is  too
1827         restrictive to return all the available data about a compiled  pattern.         restrictive  to return all the available data about a compiled pattern.
1828         New   programs   should  use  pcre_fullinfo()  instead.  The  yield  of         New  programs  should  use  pcre_fullinfo()  instead.  The   yield   of
1829         pcre_info() is the number of capturing subpatterns, or one of the  fol-         pcre_info()  is the number of capturing subpatterns, or one of the fol-
1830         lowing negative numbers:         lowing negative numbers:
1831    
1832           PCRE_ERROR_NULL       the argument code was NULL           PCRE_ERROR_NULL       the argument code was NULL
1833           PCRE_ERROR_BADMAGIC   the "magic number" was not found           PCRE_ERROR_BADMAGIC   the "magic number" was not found
1834    
1835         If  the  optptr  argument is not NULL, a copy of the options with which         If the optptr argument is not NULL, a copy of the  options  with  which
1836         the pattern was compiled is placed in the integer  it  points  to  (see         the  pattern  was  compiled  is placed in the integer it points to (see
1837         PCRE_INFO_OPTIONS above).         PCRE_INFO_OPTIONS above).
1838    
1839         If  the  pattern  is  not anchored and the firstcharptr argument is not         If the pattern is not anchored and the  firstcharptr  argument  is  not
1840         NULL, it is used to pass back information about the first character  of         NULL,  it is used to pass back information about the first character of
1841         any matched string (see PCRE_INFO_FIRSTBYTE above).         any matched string (see PCRE_INFO_FIRSTBYTE above).
1842    
1843    
# Line 1840  REFERENCE COUNTS Line 1845  REFERENCE COUNTS
1845    
1846         int pcre_refcount(pcre *code, int adjust);         int pcre_refcount(pcre *code, int adjust);
1847    
1848         The  pcre_refcount()  function is used to maintain a reference count in         The pcre_refcount() function is used to maintain a reference  count  in
1849         the data block that contains a compiled pattern. It is provided for the         the data block that contains a compiled pattern. It is provided for the
1850         benefit  of  applications  that  operate  in an object-oriented manner,         benefit of applications that  operate  in  an  object-oriented  manner,
1851         where different parts of the application may be using the same compiled         where different parts of the application may be using the same compiled
1852         pattern, but you want to free the block when they are all done.         pattern, but you want to free the block when they are all done.
1853    
1854         When a pattern is compiled, the reference count field is initialized to         When a pattern is compiled, the reference count field is initialized to
1855         zero.  It is changed only by calling this function, whose action is  to         zero.   It is changed only by calling this function, whose action is to
1856         add  the  adjust  value  (which may be positive or negative) to it. The         add the adjust value (which may be positive or  negative)  to  it.  The
1857         yield of the function is the new value. However, the value of the count         yield of the function is the new value. However, the value of the count
1858         is  constrained to lie between 0 and 65535, inclusive. If the new value         is constrained to lie between 0 and 65535, inclusive. If the new  value
1859         is outside these limits, it is forced to the appropriate limit value.         is outside these limits, it is forced to the appropriate limit value.
1860    
1861         Except when it is zero, the reference count is not correctly  preserved         Except  when it is zero, the reference count is not correctly preserved
1862         if  a  pattern  is  compiled on one host and then transferred to a host         if a pattern is compiled on one host and then  transferred  to  a  host
1863         whose byte-order is different. (This seems a highly unlikely scenario.)         whose byte-order is different. (This seems a highly unlikely scenario.)
1864    
1865    
# Line 1864  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1869  MATCHING A PATTERN: THE TRADITIONAL FUNC
1869              const char *subject, int length, int startoffset,              const char *subject, int length, int startoffset,
1870              int options, int *ovector, int ovecsize);              int options, int *ovector, int ovecsize);
1871    
1872         The function pcre_exec() is called to match a subject string against  a         The  function pcre_exec() is called to match a subject string against a
1873         compiled  pattern, which is passed in the code argument. If the pattern         compiled pattern, which is passed in the code argument. If the  pattern
1874         was studied, the result of the study should  be  passed  in  the  extra         was  studied,  the  result  of  the study should be passed in the extra
1875         argument.  This  function is the main matching facility of the library,         argument. This function is the main matching facility of  the  library,
1876         and it operates in a Perl-like manner. For specialist use there is also         and it operates in a Perl-like manner. For specialist use there is also
1877         an  alternative matching function, which is described below in the sec-         an alternative matching function, which is described below in the  sec-
1878         tion about the pcre_dfa_exec() function.         tion about the pcre_dfa_exec() function.
1879    
1880         In most applications, the pattern will have been compiled (and  option-         In  most applications, the pattern will have been compiled (and option-
1881         ally  studied)  in the same process that calls pcre_exec(). However, it         ally studied) in the same process that calls pcre_exec().  However,  it
1882         is possible to save compiled patterns and study data, and then use them         is possible to save compiled patterns and study data, and then use them
1883         later  in  different processes, possibly even on different hosts. For a         later in different processes, possibly even on different hosts.  For  a
1884         discussion about this, see the pcreprecompile documentation.         discussion about this, see the pcreprecompile documentation.
1885    
1886         Here is an example of a simple call to pcre_exec():         Here is an example of a simple call to pcre_exec():
# Line 1894  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1899  MATCHING A PATTERN: THE TRADITIONAL FUNC
1899    
1900     Extra data for pcre_exec()     Extra data for pcre_exec()
1901    
1902         If the extra argument is not NULL, it must point to a  pcre_extra  data         If  the  extra argument is not NULL, it must point to a pcre_extra data
1903         block.  The pcre_study() function returns such a block (when it doesn't         block. The pcre_study() function returns such a block (when it  doesn't
1904         return NULL), but you can also create one for yourself, and pass  addi-         return  NULL), but you can also create one for yourself, and pass addi-
1905         tional  information  in it. The pcre_extra block contains the following         tional information in it. The pcre_extra block contains  the  following
1906         fields (not necessarily in this order):         fields (not necessarily in this order):
1907    
1908           unsigned long int flags;           unsigned long int flags;
# Line 1908  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1913  MATCHING A PATTERN: THE TRADITIONAL FUNC
1913           const unsigned char *tables;           const unsigned char *tables;
1914           unsigned char **mark;           unsigned char **mark;
1915    
1916         The flags field is a bitmap that specifies which of  the  other  fields         The  flags  field  is a bitmap that specifies which of the other fields
1917         are set. The flag bits are:         are set. The flag bits are:
1918    
1919           PCRE_EXTRA_STUDY_DATA           PCRE_EXTRA_STUDY_DATA
# Line 1918  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1923  MATCHING A PATTERN: THE TRADITIONAL FUNC
1923           PCRE_EXTRA_TABLES           PCRE_EXTRA_TABLES
1924           PCRE_EXTRA_MARK           PCRE_EXTRA_MARK
1925    
1926         Other  flag  bits should be set to zero. The study_data field is set in         Other flag bits should be set to zero. The study_data field is  set  in
1927         the pcre_extra block that is returned by  pcre_study(),  together  with         the  pcre_extra  block  that is returned by pcre_study(), together with
1928         the appropriate flag bit. You should not set this yourself, but you may         the appropriate flag bit. You should not set this yourself, but you may
1929         add to the block by setting the other fields  and  their  corresponding         add  to  the  block by setting the other fields and their corresponding
1930         flag bits.         flag bits.
1931    
1932         The match_limit field provides a means of preventing PCRE from using up         The match_limit field provides a means of preventing PCRE from using up
1933         a vast amount of resources when running patterns that are not going  to         a  vast amount of resources when running patterns that are not going to
1934         match,  but  which  have  a very large number of possibilities in their         match, but which have a very large number  of  possibilities  in  their
1935         search trees. The classic example is a pattern that uses nested  unlim-         search  trees. The classic example is a pattern that uses nested unlim-
1936         ited repeats.         ited repeats.
1937    
1938         Internally,  PCRE uses a function called match() which it calls repeat-         Internally, PCRE uses a function called match() which it calls  repeat-
1939         edly (sometimes recursively). The limit set by match_limit  is  imposed         edly  (sometimes  recursively). The limit set by match_limit is imposed
1940         on  the  number  of times this function is called during a match, which         on the number of times this function is called during  a  match,  which
1941         has the effect of limiting the amount of  backtracking  that  can  take         has  the  effect  of  limiting the amount of backtracking that can take
1942         place. For patterns that are not anchored, the count restarts from zero         place. For patterns that are not anchored, the count restarts from zero
1943         for each position in the subject string.         for each position in the subject string.
1944    
1945         The default value for the limit can be set  when  PCRE  is  built;  the         The  default  value  for  the  limit can be set when PCRE is built; the
1946         default  default  is 10 million, which handles all but the most extreme         default default is 10 million, which handles all but the  most  extreme
1947         cases. You can override the default  by  suppling  pcre_exec()  with  a         cases.  You  can  override  the  default by suppling pcre_exec() with a
1948         pcre_extra     block    in    which    match_limit    is    set,    and         pcre_extra    block    in    which    match_limit    is    set,     and
1949         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
1950         exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT.         exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT.
1951    
1952         The  match_limit_recursion field is similar to match_limit, but instead         The match_limit_recursion field is similar to match_limit, but  instead
1953         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
1954         the  depth  of  recursion. The recursion depth is a smaller number than         the depth of recursion. The recursion depth is a  smaller  number  than
1955         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-
1956         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.
1957    
1958         Limiting  the  recursion  depth  limits the amount of stack that can be         Limiting the recursion depth limits the amount of  stack  that  can  be
1959         used, or, when PCRE has been compiled to use memory on the heap instead         used, or, when PCRE has been compiled to use memory on the heap instead
1960         of the stack, the amount of heap memory that can be used.         of the stack, the amount of heap memory that can be used.
1961    
1962         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
1963         built; the default default  is  the  same  value  as  the  default  for         built;  the  default  default  is  the  same  value  as the default for
1964         match_limit.  You can override the default by suppling pcre_exec() with         match_limit. You can override the default by suppling pcre_exec()  with
1965         a  pcre_extra  block  in  which  match_limit_recursion  is   set,   and         a   pcre_extra   block  in  which  match_limit_recursion  is  set,  and
1966         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
1967         limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT.         limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT.
1968    
1969         The callout_data field is used in conjunction with the  "callout"  fea-         The  callout_data  field is used in conjunction with the "callout" fea-
1970         ture, and is described in the pcrecallout documentation.         ture, and is described in the pcrecallout documentation.
1971    
1972         The  tables  field  is  used  to  pass  a  character  tables pointer to         The tables field  is  used  to  pass  a  character  tables  pointer  to
1973         pcre_exec(); this overrides the value that is stored with the  compiled         pcre_exec();  this overrides the value that is stored with the compiled
1974         pattern.  A  non-NULL value is stored with the compiled pattern only if         pattern. A non-NULL value is stored with the compiled pattern  only  if
1975         custom tables were supplied to pcre_compile() via  its  tableptr  argu-         custom  tables  were  supplied to pcre_compile() via its tableptr argu-
1976         ment.  If NULL is passed to pcre_exec() using this mechanism, it forces         ment.  If NULL is passed to pcre_exec() using this mechanism, it forces
1977         PCRE's internal tables to be used. This facility is  helpful  when  re-         PCRE's  internal  tables  to be used. This facility is helpful when re-
1978         using  patterns  that  have been saved after compiling with an external         using patterns that have been saved after compiling  with  an  external
1979         set of tables, because the external tables  might  be  at  a  different         set  of  tables,  because  the  external tables might be at a different
1980         address  when  pcre_exec() is called. See the pcreprecompile documenta-         address when pcre_exec() is called. See the  pcreprecompile  documenta-
1981         tion for a discussion of saving compiled patterns for later use.         tion for a discussion of saving compiled patterns for later use.
1982    
1983         If PCRE_EXTRA_MARK is set in the flags field, the mark  field  must  be         If  PCRE_EXTRA_MARK  is  set in the flags field, the mark field must be
1984         set  to  point  to a char * variable. If the pattern contains any back-         set to point to a char * variable. If the pattern  contains  any  back-
1985         tracking control verbs such as (*MARK:NAME), and the execution ends  up         tracking  control verbs such as (*MARK:NAME), and the execution ends up
1986         with  a  name  to  pass back, a pointer to the name string (zero termi-         with a name to pass back, a pointer to the  name  string  (zero  termi-
1987         nated) is placed in the variable pointed to  by  the  mark  field.  The         nated)  is  placed  in  the  variable pointed to by the mark field. The
1988         names  are  within  the  compiled pattern; if you wish to retain such a         names are within the compiled pattern; if you wish  to  retain  such  a
1989         name you must copy it before freeing the memory of a compiled  pattern.         name  you must copy it before freeing the memory of a compiled pattern.
1990         If  there  is no name to pass back, the variable pointed to by the mark         If there is no name to pass back, the variable pointed to by  the  mark
1991         field set to NULL. For details of the backtracking control  verbs,  see         field  set  to NULL. For details of the backtracking control verbs, see
1992         the section entitled "Backtracking control" in the pcrepattern documen-         the section entitled "Backtracking control" in the pcrepattern documen-
1993         tation.         tation.
1994    
1995     Option bits for pcre_exec()     Option bits for pcre_exec()
1996    
1997         The unused bits of the options argument for pcre_exec() must  be  zero.         The  unused  bits of the options argument for pcre_exec() must be zero.
1998         The  only  bits  that  may  be set are PCRE_ANCHORED, PCRE_NEWLINE_xxx,         The only bits that may  be  set  are  PCRE_ANCHORED,  PCRE_NEWLINE_xxx,
1999         PCRE_NOTBOL,   PCRE_NOTEOL,    PCRE_NOTEMPTY,    PCRE_NOTEMPTY_ATSTART,         PCRE_NOTBOL,    PCRE_NOTEOL,    PCRE_NOTEMPTY,   PCRE_NOTEMPTY_ATSTART,
2000         PCRE_NO_START_OPTIMIZE,   PCRE_NO_UTF8_CHECK,   PCRE_PARTIAL_SOFT,  and         PCRE_NO_START_OPTIMIZE,  PCRE_NO_UTF8_CHECK,   PCRE_PARTIAL_SOFT,   and
2001         PCRE_PARTIAL_HARD.         PCRE_PARTIAL_HARD.
2002    
2003           PCRE_ANCHORED           PCRE_ANCHORED
2004    
2005         The PCRE_ANCHORED option limits pcre_exec() to matching  at  the  first         The  PCRE_ANCHORED  option  limits pcre_exec() to matching at the first
2006         matching  position.  If  a  pattern was compiled with PCRE_ANCHORED, or         matching position. If a pattern was  compiled  with  PCRE_ANCHORED,  or
2007         turned out to be anchored by virtue of its contents, it cannot be  made         turned  out to be anchored by virtue of its contents, it cannot be made
2008         unachored at matching time.         unachored at matching time.
2009    
2010           PCRE_BSR_ANYCRLF           PCRE_BSR_ANYCRLF
2011           PCRE_BSR_UNICODE           PCRE_BSR_UNICODE
2012    
2013         These options (which are mutually exclusive) control what the \R escape         These options (which are mutually exclusive) control what the \R escape
2014         sequence matches. The choice is either to match only CR, LF,  or  CRLF,         sequence  matches.  The choice is either to match only CR, LF, or CRLF,
2015         or  to  match  any Unicode newline sequence. These options override the         or to match any Unicode newline sequence. These  options  override  the
2016         choice that was made or defaulted when the pattern was compiled.         choice that was made or defaulted when the pattern was compiled.
2017    
2018           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
# Line 2016  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 2021  MATCHING A PATTERN: THE TRADITIONAL FUNC
2021           PCRE_NEWLINE_ANYCRLF           PCRE_NEWLINE_ANYCRLF
2022           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
2023    
2024         These options override  the  newline  definition  that  was  chosen  or         These  options  override  the  newline  definition  that  was chosen or
2025         defaulted  when the pattern was compiled. For details, see the descrip-         defaulted when the pattern was compiled. For details, see the  descrip-
2026         tion of pcre_compile()  above.  During  matching,  the  newline  choice         tion  of  pcre_compile()  above.  During  matching,  the newline choice
2027         affects  the  behaviour  of the dot, circumflex, and dollar metacharac-         affects the behaviour of the dot, circumflex,  and  dollar  metacharac-
2028         ters. It may also alter the way the match position is advanced after  a         ters.  It may also alter the way the match position is advanced after a
2029         match failure for an unanchored pattern.         match failure for an unanchored pattern.
2030    
2031         When  PCRE_NEWLINE_CRLF,  PCRE_NEWLINE_ANYCRLF,  or PCRE_NEWLINE_ANY is         When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF,  or  PCRE_NEWLINE_ANY  is
2032         set, and a match attempt for an unanchored pattern fails when the  cur-         set,  and a match attempt for an unanchored pattern fails when the cur-
2033         rent  position  is  at  a  CRLF  sequence,  and the pattern contains no         rent position is at a  CRLF  sequence,  and  the  pattern  contains  no
2034         explicit matches for  CR  or  LF  characters,  the  match  position  is         explicit  matches  for  CR  or  LF  characters,  the  match position is
2035         advanced by two characters instead of one, in other words, to after the         advanced by two characters instead of one, in other words, to after the
2036         CRLF.         CRLF.
2037    
2038         The above rule is a compromise that makes the most common cases work as         The above rule is a compromise that makes the most common cases work as
2039         expected.  For  example,  if  the  pattern  is .+A (and the PCRE_DOTALL         expected. For example, if the  pattern  is  .+A  (and  the  PCRE_DOTALL
2040         option is not set), it does not match the string "\r\nA" because, after         option is not set), it does not match the string "\r\nA" because, after
2041         failing  at the start, it skips both the CR and the LF before retrying.         failing at the start, it skips both the CR and the LF before  retrying.
2042         However, the pattern [\r\n]A does match that string,  because  it  con-         However,  the  pattern  [\r\n]A does match that string, because it con-
2043         tains an explicit CR or LF reference, and so advances only by one char-         tains an explicit CR or LF reference, and so advances only by one char-
2044         acter after the first failure.         acter after the first failure.
2045    
2046         An explicit match for CR of LF is either a literal appearance of one of         An explicit match for CR of LF is either a literal appearance of one of
2047         those  characters,  or  one  of the \r or \n escape sequences. Implicit         those characters, or one of the \r or  \n  escape  sequences.  Implicit
2048         matches such as [^X] do not count, nor does \s (which includes  CR  and         matches  such  as [^X] do not count, nor does \s (which includes CR and
2049         LF in the characters that it matches).         LF in the characters that it matches).
2050    
2051         Notwithstanding  the above, anomalous effects may still occur when CRLF         Notwithstanding the above, anomalous effects may still occur when  CRLF
2052         is a valid newline sequence and explicit \r or \n escapes appear in the         is a valid newline sequence and explicit \r or \n escapes appear in the
2053         pattern.         pattern.
2054    
2055           PCRE_NOTBOL           PCRE_NOTBOL
2056    
2057         This option specifies that first character of the subject string is not         This option specifies that first character of the subject string is not
2058         the beginning of a line, so the  circumflex  metacharacter  should  not         the  beginning  of  a  line, so the circumflex metacharacter should not
2059         match  before it. Setting this without PCRE_MULTILINE (at compile time)         match before it. Setting this without PCRE_MULTILINE (at compile  time)
2060         causes circumflex never to match. This option affects only  the  behav-         causes  circumflex  never to match. This option affects only the behav-
2061         iour of the circumflex metacharacter. It does not affect \A.         iour of the circumflex metacharacter. It does not affect \A.
2062    
2063           PCRE_NOTEOL           PCRE_NOTEOL
2064    
2065         This option specifies that the end of the subject string is not the end         This option specifies that the end of the subject string is not the end
2066         of a line, so the dollar metacharacter should not match it nor  (except         of  a line, so the dollar metacharacter should not match it nor (except
2067         in  multiline mode) a newline immediately before it. Setting this with-         in multiline mode) a newline immediately before it. Setting this  with-
2068         out PCRE_MULTILINE (at compile time) causes dollar never to match. This         out PCRE_MULTILINE (at compile time) causes dollar never to match. This
2069         option  affects only the behaviour of the dollar metacharacter. It does         option affects only the behaviour of the dollar metacharacter. It  does
2070         not affect \Z or \z.         not affect \Z or \z.
2071    
2072           PCRE_NOTEMPTY           PCRE_NOTEMPTY
2073    
2074         An empty string is not considered to be a valid match if this option is         An empty string is not considered to be a valid match if this option is
2075         set.  If  there are alternatives in the pattern, they are tried. If all         set. If there are alternatives in the pattern, they are tried.  If  all
2076         the alternatives match the empty string, the entire  match  fails.  For         the  alternatives  match  the empty string, the entire match fails. For
2077         example, if the pattern         example, if the pattern
2078    
2079           a?b?           a?b?
2080    
2081         is  applied  to  a  string not beginning with "a" or "b", it matches an         is applied to a string not beginning with "a" or  "b",  it  matches  an
2082         empty string at the start of the subject. With PCRE_NOTEMPTY set,  this         empty  string at the start of the subject. With PCRE_NOTEMPTY set, this
2083         match is not valid, so PCRE searches further into the string for occur-         match is not valid, so PCRE searches further into the string for occur-
2084         rences of "a" or "b".         rences of "a" or "b".
2085    
2086           PCRE_NOTEMPTY_ATSTART           PCRE_NOTEMPTY_ATSTART
2087    
2088         This is like PCRE_NOTEMPTY, except that an empty string match  that  is         This  is  like PCRE_NOTEMPTY, except that an empty string match that is
2089         not  at  the  start  of  the  subject  is  permitted. If the pattern is         not at the start of  the  subject  is  permitted.  If  the  pattern  is
2090         anchored, such a match can occur only if the pattern contains \K.         anchored, such a match can occur only if the pattern contains \K.
2091    
2092         Perl    has    no    direct    equivalent    of    PCRE_NOTEMPTY     or         Perl     has    no    direct    equivalent    of    PCRE_NOTEMPTY    or
2093         PCRE_NOTEMPTY_ATSTART,  but  it  does  make a special case of a pattern         PCRE_NOTEMPTY_ATSTART, but it does make a special  case  of  a  pattern
2094         match of the empty string within its split() function, and  when  using         match  of  the empty string within its split() function, and when using
2095         the  /g  modifier.  It  is  possible  to emulate Perl's behaviour after         the /g modifier. It is  possible  to  emulate  Perl's  behaviour  after
2096         matching a null string by first trying the match again at the same off-         matching a null string by first trying the match again at the same off-
2097         set  with  PCRE_NOTEMPTY_ATSTART  and  PCRE_ANCHORED,  and then if that         set with PCRE_NOTEMPTY_ATSTART and  PCRE_ANCHORED,  and  then  if  that
2098         fails, by advancing the starting offset (see below) and trying an ordi-         fails, by advancing the starting offset (see below) and trying an ordi-
2099         nary  match  again. There is some code that demonstrates how to do this         nary match again. There is some code that demonstrates how to  do  this
2100         in the pcredemo sample program.         in the pcredemo sample program.
2101    
2102           PCRE_NO_START_OPTIMIZE           PCRE_NO_START_OPTIMIZE
2103    
2104         There are a number of optimizations that pcre_exec() uses at the  start         There  are a number of optimizations that pcre_exec() uses at the start
2105         of  a  match,  in  order to speed up the process. For example, if it is         of a match, in order to speed up the process. For  example,  if  it  is
2106         known that a match must start with a specific  character,  it  searches         known  that  a  match must start with a specific character, it searches
2107         the subject for that character, and fails immediately if it cannot find         the subject for that character, and fails immediately if it cannot find
2108         it, without actually running the main matching function. When  callouts         it,  without actually running the main matching function. When callouts
2109         are  in  use,  these  optimizations  can cause them to be skipped. This         are in use, these optimizations can cause  them  to  be  skipped.  This
2110         option disables the "start-up" optimizations,  causing  performance  to         option  disables  the  "start-up" optimizations, causing performance to
2111         suffer, but ensuring that the callouts do occur.         suffer, but ensuring that the callouts do occur.
2112    
2113           PCRE_NO_UTF8_CHECK           PCRE_NO_UTF8_CHECK
2114    
2115         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
2116         UTF-8 string is automatically checked when pcre_exec() is  subsequently         UTF-8  string is automatically checked when pcre_exec() is subsequently
2117         called.   The  value  of  startoffset is also checked to ensure that it         called.  The value of startoffset is also checked  to  ensure  that  it
2118         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
2119         the  validity  of  UTF-8 strings in the section on UTF-8 support in the         the validity of UTF-8 strings in the section on UTF-8  support  in  the
2120         main pcre page. If  an  invalid  UTF-8  sequence  of  bytes  is  found,         main  pcre  page.  If  an  invalid  UTF-8  sequence  of bytes is found,
2121         pcre_exec()  returns  the error PCRE_ERROR_BADUTF8. If startoffset con-         pcre_exec() returns the error PCRE_ERROR_BADUTF8. If  startoffset  con-
2122         tains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned.         tains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned.
2123    
2124         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
2125         these    checks    for   performance   reasons,   you   can   set   the         these   checks   for   performance   reasons,   you   can    set    the
2126         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
2127         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
2128         making repeated calls to find all  the  matches  in  a  single  subject         making  repeated  calls  to  find  all  the matches in a single subject
2129         string.  However,  you  should  be  sure  that the value of startoffset         string. However, you should be  sure  that  the  value  of  startoffset
2130         points to the start of a UTF-8 character.  When  PCRE_NO_UTF8_CHECK  is         points  to  the  start of a UTF-8 character. When PCRE_NO_UTF8_CHECK is
2131         set,  the  effect of passing an invalid UTF-8 string as a subject, or a         set, the effect of passing an invalid UTF-8 string as a subject,  or  a
2132         value of startoffset that does not point to the start of a UTF-8  char-         value  of startoffset that does not point to the start of a UTF-8 char-
2133         acter, is undefined. Your program may crash.         acter, is undefined. Your program may crash.
2134    
2135           PCRE_PARTIAL_HARD           PCRE_PARTIAL_HARD
2136           PCRE_PARTIAL_SOFT           PCRE_PARTIAL_SOFT
2137    
2138         These  options turn on the partial matching feature. For backwards com-         These options turn on the partial matching feature. For backwards  com-
2139         patibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A  partial         patibility,  PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial
2140         match  occurs if the end of the subject string is reached successfully,         match occurs if the end of the subject string is reached  successfully,
2141         but there are not enough subject characters to complete the  match.  If         but  there  are not enough subject characters to complete the match. If
2142         this  happens  when  PCRE_PARTIAL_HARD  is set, pcre_exec() immediately         this happens when PCRE_PARTIAL_HARD  is  set,  pcre_exec()  immediately
2143         returns PCRE_ERROR_PARTIAL. Otherwise,  if  PCRE_PARTIAL_SOFT  is  set,         returns  PCRE_ERROR_PARTIAL.  Otherwise,  if  PCRE_PARTIAL_SOFT is set,
2144         matching  continues by testing any other alternatives. Only if they all         matching continues by testing any other alternatives. Only if they  all
2145         fail is PCRE_ERROR_PARTIAL returned  (instead  of  PCRE_ERROR_NOMATCH).         fail  is  PCRE_ERROR_PARTIAL  returned (instead of PCRE_ERROR_NOMATCH).
2146         The portion of the string that was inspected when the partial match was         The portion of the string that was inspected when the partial match was
2147         found is set as the first matching string. There  is  a  more  detailed         found  is  set  as  the first matching string. There is a more detailed
2148         discussion in the pcrepartial documentation.         discussion in the pcrepartial documentation.
2149    
2150     The string to be matched by pcre_exec()     The string to be matched by pcre_exec()
2151    
2152         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
2153         length (in bytes) in length, and a starting byte offset in startoffset.         length (in bytes) in length, and a starting byte offset in startoffset.
2154         In UTF-8 mode, the byte offset must point to the start of a UTF-8 char-         In UTF-8 mode, the byte offset must point to the start of a UTF-8 char-
2155         acter. Unlike the pattern string, the subject may contain  binary  zero         acter.  Unlike  the pattern string, the subject may contain binary zero
2156         bytes.  When the starting offset is zero, the search for a match starts         bytes. When the starting offset is zero, the search for a match  starts
2157         at the beginning of the subject, and this is by  far  the  most  common         at  the  beginning  of  the subject, and this is by far the most common
2158         case.         case.
2159    
2160         A  non-zero  starting offset is useful when searching for another match         A non-zero starting offset is useful when searching for  another  match
2161         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-
2162         cess.   Setting  startoffset differs from just passing over a shortened         cess.  Setting startoffset differs from just passing over  a  shortened
2163         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
2164         with any kind of lookbehind. For example, consider the pattern         with any kind of lookbehind. For example, consider the pattern
2165    
2166           \Biss\B           \Biss\B
2167    
2168         which  finds  occurrences  of "iss" in the middle of words. (\B matches         which finds occurrences of "iss" in the middle of  words.  (\B  matches
2169         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.)
2170         When  applied  to the string "Mississipi" the first call to pcre_exec()         When applied to the string "Mississipi" the first call  to  pcre_exec()
2171         finds the first occurrence. If pcre_exec() is called  again  with  just         finds  the  first  occurrence. If pcre_exec() is called again with just
2172         the  remainder  of  the  subject,  namely  "issipi", it does not match,         the remainder of the subject,  namely  "issipi",  it  does  not  match,
2173         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
2174         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
2175         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-
2176         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
2177         discover that it is preceded by a letter.         discover that it is preceded by a letter.
2178    
2179         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,
2180         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
2181         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
2182         subject.         subject.
2183    
2184     How pcre_exec() returns captured substrings     How pcre_exec() returns captured substrings
2185    
2186         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
2187         addition, further substrings from the subject  may  be  picked  out  by         addition,  further  substrings  from  the  subject may be picked out by
2188         parts  of  the  pattern.  Following the usage in Jeffrey Friedl's book,         parts of the pattern. Following the usage  in  Jeffrey  Friedl's  book,
2189         this is called "capturing" in what follows, and the  phrase  "capturing         this  is  called "capturing" in what follows, and the phrase "capturing
2190         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-
2191         string. PCRE supports several other kinds of  parenthesized  subpattern         string.  PCRE  supports several other kinds of parenthesized subpattern
2192         that do not cause substrings to be captured.         that do not cause substrings to be captured.
2193    
2194         Captured substrings are returned to the caller via a vector of integers         Captured substrings are returned to the caller via a vector of integers
2195         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-
2196         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:
2197         this argument is NOT the size of ovector in bytes.         this argument is NOT the size of ovector in bytes.
2198    
2199         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-
2200         strings,  each  substring using a pair of integers. The remaining third         strings, each substring using a pair of integers. The  remaining  third
2201         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-
2202         turing  subpatterns, and is not available for passing back information.         turing subpatterns, and is not available for passing back  information.
2203         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
2204         it is not, it is rounded down.         it is not, it is rounded down.
2205    
2206         When  a  match  is successful, information about captured substrings is         When a match is successful, information about  captured  substrings  is
2207         returned in pairs of integers, starting at the  beginning  of  ovector,         returned  in  pairs  of integers, starting at the beginning of ovector,
2208         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
2209         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
2210         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
2211         character after the end of a substring. Note: these values  are  always         character  after  the end of a substring. Note: these values are always
2212         byte offsets, even in UTF-8 mode. They are not character counts.         byte offsets, even in UTF-8 mode. They are not character counts.
2213    
2214         The  first  pair  of  integers, ovector[0] and ovector[1], identify the         The first pair of integers, ovector[0]  and  ovector[1],  identify  the
2215         portion of the subject string matched by the entire pattern.  The  next         portion  of  the subject string matched by the entire pattern. The next
2216         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
2217         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
2218         has  been  set.  For example, if two substrings have been captured, the         has been set.  For example, if two substrings have been  captured,  the
2219         returned value is 3. If there are no capturing subpatterns, the  return         returned  value is 3. If there are no capturing subpatterns, the return
2220         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
2221         of offsets has been set.         of offsets has been set.
2222    
2223         If a capturing subpattern is matched repeatedly, it is the last portion         If a capturing subpattern is matched repeatedly, it is the last portion
2224         of the string that it matched that is returned.         of the string that it matched that is returned.
2225    
2226         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,
2227         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
2228         function  returns  a value of zero. If the substring offsets are not of         function returns a value of zero. If the substring offsets are  not  of
2229         interest, pcre_exec() may be called with ovector  passed  as  NULL  and         interest,  pcre_exec()  may  be  called with ovector passed as NULL and
2230         ovecsize  as zero. However, if the pattern contains back references and         ovecsize as zero. However, if the pattern contains back references  and
2231         the ovector is not big enough to remember the related substrings,  PCRE         the  ovector is not big enough to remember the related substrings, PCRE
2232         has  to  get additional memory for use during matching. Thus it is usu-         has to get additional memory for use during matching. Thus it  is  usu-
2233         ally advisable to supply an ovector.         ally advisable to supply an ovector.
2234    
2235         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
2236         subpatterns  there  are  in  a  compiled pattern. The smallest size for         subpatterns there are in a compiled  pattern.  The  smallest  size  for
2237         ovector that will allow for n captured substrings, in addition  to  the         ovector  that  will allow for n captured substrings, in addition to the
2238         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.
2239    
2240         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
2241         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,
2242         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
2243         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
2244         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-
2245         sponding to unused subpatterns are set to -1.         sponding to unused subpatterns are set to -1.
2246    
2247         Offset values that correspond to unused subpatterns at the end  of  the         Offset  values  that correspond to unused subpatterns at the end of the
2248         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
2249         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
2250         matched.  The  return  from the function is 2, because the highest used         matched. The return from the function is 2, because  the  highest  used
2251         capturing subpattern number is 1. However, you can refer to the offsets         capturing subpattern number is 1. However, you can refer to the offsets
2252         for  the  second  and third capturing subpatterns if you wish (assuming         for the second and third capturing subpatterns if  you  wish  (assuming
2253         the vector is large enough, of course).         the vector is large enough, of course).
2254    
2255         Some convenience functions are provided  for  extracting  the  captured         Some  convenience  functions  are  provided for extracting the captured
2256         substrings as separate strings. These are described below.         substrings as separate strings. These are described below.
2257    
2258     Error return values from pcre_exec()     Error return values from pcre_exec()
2259    
2260         If  pcre_exec()  fails, it returns a negative number. The following are         If pcre_exec() fails, it returns a negative number. The  following  are
2261         defined in the header file:         defined in the header file:
2262    
2263           PCRE_ERROR_NOMATCH        (-1)           PCRE_ERROR_NOMATCH        (-1)
# Line 2261  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 2266  MATCHING A PATTERN: THE TRADITIONAL FUNC
2266    
2267           PCRE_ERROR_NULL           (-2)           PCRE_ERROR_NULL           (-2)
2268    
2269         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
2270         ovecsize was not zero.         ovecsize was not zero.
2271    
2272           PCRE_ERROR_BADOPTION      (-3)           PCRE_ERROR_BADOPTION      (-3)
# Line 2270  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 2275  MATCHING A PATTERN: THE TRADITIONAL FUNC
2275    
2276           PCRE_ERROR_BADMAGIC       (-4)           PCRE_ERROR_BADMAGIC       (-4)
2277    
2278         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,
2279         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
2280         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
2281         an environment with the other endianness. This is the error  that  PCRE         an  environment  with the other endianness. This is the error that PCRE
2282         gives when the magic number is not present.         gives when the magic number is not present.
2283    
2284           PCRE_ERROR_UNKNOWN_OPCODE (-5)           PCRE_ERROR_UNKNOWN_OPCODE (-5)
2285    
2286         While running the pattern match, an unknown item was encountered in the         While running the pattern match, an unknown item was encountered in the
2287         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
2288         overwriting of the compiled pattern.         overwriting of the compiled pattern.
2289    
2290           PCRE_ERROR_NOMEMORY       (-6)           PCRE_ERROR_NOMEMORY       (-6)
2291    
2292         If  a  pattern contains back references, but the ovector that is passed         If a pattern contains back references, but the ovector that  is  passed
2293         to pcre_exec() is not big enough to remember the referenced substrings,         to pcre_exec() is not big enough to remember the referenced substrings,
2294         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
2295         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
2296         memory is automatically freed at the end of matching.         memory is automatically freed at the end of matching.
2297    
2298           PCRE_ERROR_NOSUBSTRING    (-7)           PCRE_ERROR_NOSUBSTRING    (-7)
2299    
2300         This  error is used by the pcre_copy_substring(), pcre_get_substring(),         This error is used by the pcre_copy_substring(),  pcre_get_substring(),
2301         and  pcre_get_substring_list()  functions  (see  below).  It  is  never         and  pcre_get_substring_list()  functions  (see  below).  It  is  never
2302         returned by pcre_exec().         returned by pcre_exec().
2303    
2304           PCRE_ERROR_MATCHLIMIT     (-8)           PCRE_ERROR_MATCHLIMIT     (-8)
2305    
2306         The  backtracking  limit,  as  specified  by the match_limit field in a         The backtracking limit, as specified by  the  match_limit  field  in  a
2307         pcre_extra structure (or defaulted) was reached.  See  the  description         pcre_extra  structure  (or  defaulted) was reached. See the description
2308         above.         above.
2309    
2310           PCRE_ERROR_CALLOUT        (-9)           PCRE_ERROR_CALLOUT        (-9)
2311    
2312         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
2313         use by callout functions that want to yield a distinctive  error  code.         use  by  callout functions that want to yield a distinctive error code.
2314         See the pcrecallout documentation for details.         See the pcrecallout documentation for details.
2315    
2316           PCRE_ERROR_BADUTF8        (-10)           PCRE_ERROR_BADUTF8        (-10)
2317    
2318         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
2319         subject.         subject.
2320    
2321           PCRE_ERROR_BADUTF8_OFFSET (-11)           PCRE_ERROR_BADUTF8_OFFSET (-11)
2322    
2323         The UTF-8 byte sequence that was passed as a subject was valid, but the         The UTF-8 byte sequence that was passed as a subject was valid, but the
2324         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-
2325         ter.         ter.
2326    
2327           PCRE_ERROR_PARTIAL        (-12)           PCRE_ERROR_PARTIAL        (-12)
2328    
2329         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
2330         pcrepartial documentation for details of partial matching.         pcrepartial documentation for details of partial matching.
2331    
2332           PCRE_ERROR_BADPARTIAL     (-13)           PCRE_ERROR_BADPARTIAL     (-13)
2333    
2334         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
2335         PCRE_PARTIAL option was used with a compiled pattern  containing  items         PCRE_PARTIAL  option  was used with a compiled pattern containing items
2336         that  were  not  supported  for  partial  matching.  From  release 8.00         that were  not  supported  for  partial  matching.  From  release  8.00
2337         onwards, there are no restrictions on partial matching.         onwards, there are no restrictions on partial matching.
2338    
2339           PCRE_ERROR_INTERNAL       (-14)           PCRE_ERROR_INTERNAL       (-14)
2340    
2341         An unexpected internal error has occurred. This error could  be  caused         An  unexpected  internal error has occurred. This error could be caused
2342         by a bug in PCRE or by overwriting of the compiled pattern.         by a bug in PCRE or by overwriting of the compiled pattern.
2343    
2344           PCRE_ERROR_BADCOUNT       (-15)           PCRE_ERROR_BADCOUNT       (-15)
# Line 2343  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 2348  MATCHING A PATTERN: THE TRADITIONAL FUNC
2348           PCRE_ERROR_RECURSIONLIMIT (-21)           PCRE_ERROR_RECURSIONLIMIT (-21)
2349    
2350         The internal recursion limit, as specified by the match_limit_recursion         The internal recursion limit, as specified by the match_limit_recursion
2351         field in a pcre_extra structure (or defaulted)  was  reached.  See  the         field  in  a  pcre_extra  structure (or defaulted) was reached. See the
2352         description above.         description above.
2353    
2354           PCRE_ERROR_BADNEWLINE     (-23)           PCRE_ERROR_BADNEWLINE     (-23)
# Line 2366  EXTRACTING CAPTURED SUBSTRINGS BY NUMBER Line 2371  EXTRACTING CAPTURED SUBSTRINGS BY NUMBER
2371         int pcre_get_substring_list(const char *subject,         int pcre_get_substring_list(const char *subject,
2372              int *ovector, int stringcount, const char ***listptr);              int *ovector, int stringcount, const char ***listptr);
2373    
2374         Captured  substrings  can  be  accessed  directly  by using the offsets         Captured substrings can be  accessed  directly  by  using  the  offsets
2375         returned by pcre_exec() in  ovector.  For  convenience,  the  functions         returned  by  pcre_exec()  in  ovector.  For convenience, the functions
2376         pcre_copy_substring(),    pcre_get_substring(),    and    pcre_get_sub-         pcre_copy_substring(),    pcre_get_substring(),    and    pcre_get_sub-
2377         string_list() are provided for extracting captured substrings  as  new,         string_list()  are  provided for extracting captured substrings as new,
2378         separate,  zero-terminated strings. These functions identify substrings         separate, zero-terminated strings. These functions identify  substrings
2379         by number. The next section describes functions  for  extracting  named         by  number.  The  next section describes functions for extracting named
2380         substrings.         substrings.
2381    
2382         A  substring that contains a binary zero is correctly extracted and has         A substring that contains a binary zero is correctly extracted and  has
2383         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
2384         string.   However,  you  can  process such a string by referring to the         string.  However, you can process such a string  by  referring  to  the
2385         length that is  returned  by  pcre_copy_substring()  and  pcre_get_sub-         length  that  is  returned  by  pcre_copy_substring() and pcre_get_sub-
2386         string().  Unfortunately, the interface to pcre_get_substring_list() is         string().  Unfortunately, the interface to pcre_get_substring_list() is
2387         not adequate for handling strings containing binary zeros, because  the         not  adequate for handling strings containing binary zeros, because the
2388         end of the final string is not independently indicated.         end of the final string is not independently indicated.
2389    
2390         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-
2391         tions: subject is the subject string that has  just  been  successfully         tions:  subject  is  the subject string that has just been successfully
2392         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
2393         passed to pcre_exec(), and stringcount is the number of substrings that         passed to pcre_exec(), and stringcount is the number of substrings that
2394         were  captured  by  the match, including the substring that matched the         were captured by the match, including the substring  that  matched  the
2395         entire regular expression. This is the value returned by pcre_exec() if         entire regular expression. This is the value returned by pcre_exec() if
2396         it  is greater than zero. If pcre_exec() returned zero, indicating that         it is greater than zero. If pcre_exec() returned zero, indicating  that
2397         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
2398         be the number of elements in the vector divided by three.         be the number of elements in the vector divided by three.
2399    
2400         The  functions pcre_copy_substring() and pcre_get_substring() extract a         The functions pcre_copy_substring() and pcre_get_substring() extract  a
2401         single substring, whose number is given as  stringnumber.  A  value  of         single  substring,  whose  number  is given as stringnumber. A value of
2402         zero  extracts  the  substring that matched the entire pattern, whereas         zero extracts the substring that matched the  entire  pattern,  whereas
2403         higher values  extract  the  captured  substrings.  For  pcre_copy_sub-         higher  values  extract  the  captured  substrings.  For pcre_copy_sub-
2404         string(),  the  string  is  placed  in buffer, whose length is given by         string(), the string is placed in buffer,  whose  length  is  given  by
2405         buffersize, while for pcre_get_substring() a new  block  of  memory  is         buffersize,  while  for  pcre_get_substring()  a new block of memory is
2406         obtained  via  pcre_malloc,  and its address is returned via stringptr.         obtained via pcre_malloc, and its address is  returned  via  stringptr.
2407         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
2408         the terminating zero, or one of these error codes:         the terminating zero, or one of these error codes:
2409    
2410           PCRE_ERROR_NOMEMORY       (-6)           PCRE_ERROR_NOMEMORY       (-6)
2411    
2412         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
2413         get memory failed for pcre_get_substring().         get memory failed for pcre_get_substring().
2414    
2415           PCRE_ERROR_NOSUBSTRING    (-7)           PCRE_ERROR_NOSUBSTRING    (-7)
2416    
2417         There is no substring whose number is stringnumber.         There is no substring whose number is stringnumber.
2418    
2419         The pcre_get_substring_list()  function  extracts  all  available  sub-         The  pcre_get_substring_list()  function  extracts  all  available sub-
2420         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
2421         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
2422         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
2423         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
2424         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
2425         error code         error code
2426    
2427           PCRE_ERROR_NOMEMORY       (-6)           PCRE_ERROR_NOMEMORY       (-6)
2428    
2429         if the attempt to get the memory block failed.         if the attempt to get the memory block failed.
2430    
2431         When any of these functions encounter a substring that is unset,  which         When  any of these functions encounter a substring that is unset, which
2432         can  happen  when  capturing subpattern number n+1 matches some part of         can happen when capturing subpattern number n+1 matches  some  part  of
2433         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
2434         empty string. This can be distinguished from a genuine zero-length sub-         empty string. This can be distinguished from a genuine zero-length sub-
2435         string by inspecting the appropriate offset in ovector, which is  nega-         string  by inspecting the appropriate offset in ovector, which is nega-
2436         tive for unset substrings.         tive for unset substrings.
2437    
2438         The  two convenience functions pcre_free_substring() and pcre_free_sub-         The two convenience functions pcre_free_substring() and  pcre_free_sub-
2439         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
2440         call  of  pcre_get_substring()  or  pcre_get_substring_list(),  respec-         call  of  pcre_get_substring()  or  pcre_get_substring_list(),  respec-
2441         tively. They do nothing more than  call  the  function  pointed  to  by         tively.  They  do  nothing  more  than  call the function pointed to by
2442         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.
2443         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-
2444         cial   interface  to  another  programming  language  that  cannot  use         cial  interface  to  another  programming  language  that  cannot   use
2445         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-
2446         vided.         vided.
2447    
2448    
# Line 2456  EXTRACTING CAPTURED SUBSTRINGS BY NAME Line 2461  EXTRACTING CAPTURED SUBSTRINGS BY NAME
2461              int stringcount, const char *stringname,              int stringcount, const char *stringname,
2462              const char **stringptr);              const char **stringptr);
2463    
2464         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-
2465         ber.  For example, for this pattern         ber.  For example, for this pattern
2466    
2467           (a+)b(?<xxx>\d+)...           (a+)b(?<xxx>\d+)...
# Line 2465  EXTRACTING CAPTURED SUBSTRINGS BY NAME Line 2470  EXTRACTING CAPTURED SUBSTRINGS BY NAME
2470         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
2471         name by calling pcre_get_stringnumber(). The first argument is the com-         name by calling pcre_get_stringnumber(). The first argument is the com-
2472         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
2473         the subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if  there  is  no         the  subpattern  number,  or PCRE_ERROR_NOSUBSTRING (-7) if there is no
2474         subpattern of that name.         subpattern of that name.
2475    
2476         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
2477         the functions described in the previous section. For convenience, there         the functions described in the previous section. For convenience, there
2478         are also two functions that do the whole job.         are also two functions that do the whole job.
2479    
2480         Most    of    the    arguments   of   pcre_copy_named_substring()   and         Most   of   the   arguments    of    pcre_copy_named_substring()    and
2481         pcre_get_named_substring() are the same  as  those  for  the  similarly         pcre_get_named_substring()  are  the  same  as  those for the similarly
2482         named  functions  that extract by number. As these are described in the         named functions that extract by number. As these are described  in  the
2483         previous section, they are not re-described here. There  are  just  two         previous  section,  they  are not re-described here. There are just two
2484         differences:         differences:
2485    
2486         First,  instead  of a substring number, a substring name is given. Sec-         First, instead of a substring number, a substring name is  given.  Sec-
2487         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
2488         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
2489         name-to-number translation table.         name-to-number translation table.
2490    
2491         These functions call pcre_get_stringnumber(), and if it succeeds,  they         These  functions call pcre_get_stringnumber(), and if it succeeds, they
2492         then  call  pcre_copy_substring() or pcre_get_substring(), as appropri-         then call pcre_copy_substring() or pcre_get_substring(),  as  appropri-
2493         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
2494         behaviour may not be what you want (see the next section).         behaviour may not be what you want (see the next section).
2495    
2496         Warning: If the pattern uses the (?| feature to set up multiple subpat-         Warning: If the pattern uses the (?| feature to set up multiple subpat-
2497         terns with the same number, as described in the  section  on  duplicate         terns  with  the  same number, as described in the section on duplicate
2498         subpattern  numbers  in  the  pcrepattern page, you cannot use names to         subpattern numbers in the pcrepattern page, you  cannot  use  names  to
2499         distinguish the different subpatterns, because names are  not  included         distinguish  the  different subpatterns, because names are not included
2500         in  the compiled code. The matching process uses only numbers. For this         in the compiled code. The matching process uses only numbers. For  this
2501         reason, the use of different names for subpatterns of the  same  number         reason,  the  use of different names for subpatterns of the same number
2502         causes an error at compile time.         causes an error at compile time.
2503    
2504    
# Line 2502  DUPLICATE SUBPATTERN NAMES Line 2507  DUPLICATE SUBPATTERN NAMES
2507         int pcre_get_stringtable_entries(const pcre *code,         int pcre_get_stringtable_entries(const pcre *code,
2508              const char *name, char **first, char **last);              const char *name, char **first, char **last);
2509    
2510         When  a  pattern  is  compiled with the PCRE_DUPNAMES option, names for         When a pattern is compiled with the  PCRE_DUPNAMES  option,  names  for
2511         subpatterns are not required to be unique. (Duplicate names are  always         subpatterns  are not required to be unique. (Duplicate names are always
2512         allowed  for subpatterns with the same number, created by using the (?|         allowed for subpatterns with the same number, created by using the  (?|
2513         feature. Indeed, if such subpatterns are named, they  are  required  to         feature.  Indeed,  if  such subpatterns are named, they are required to
2514         use the same names.)         use the same names.)
2515    
2516         Normally, patterns with duplicate names are such that in any one match,         Normally, patterns with duplicate names are such that in any one match,
2517         only one of the named subpatterns participates. An example is shown  in         only  one of the named subpatterns participates. An example is shown in
2518         the pcrepattern documentation.         the pcrepattern documentation.
2519    
2520         When    duplicates   are   present,   pcre_copy_named_substring()   and         When   duplicates   are   present,   pcre_copy_named_substring()    and
2521         pcre_get_named_substring() return the first substring corresponding  to         pcre_get_named_substring()  return the first substring corresponding to
2522         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
2523         (-7) is returned; no  data  is  returned.  The  pcre_get_stringnumber()         (-7)  is  returned;  no  data  is returned. The pcre_get_stringnumber()
2524         function  returns one of the numbers that are associated with the name,         function returns one of the numbers that are associated with the  name,
2525         but it is not defined which it is.         but it is not defined which it is.
2526    
2527         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
2528         name,  you  must  use  the pcre_get_stringtable_entries() function. The         name, you must use  the  pcre_get_stringtable_entries()  function.  The
2529         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
2530         third  and  fourth  are  pointers to variables which are updated by the         third and fourth are pointers to variables which  are  updated  by  the
2531         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
2532         the  name-to-number  table  for  the  given  name.  The function itself         the name-to-number table  for  the  given  name.  The  function  itself
2533         returns the length of each entry,  or  PCRE_ERROR_NOSUBSTRING  (-7)  if         returns  the  length  of  each entry, or PCRE_ERROR_NOSUBSTRING (-7) if
2534         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-
2535         tion entitled Information about a  pattern.   Given  all  the  relevant         tion  entitled  Information  about  a  pattern.  Given all the relevant
2536         entries  for the name, you can extract each of their numbers, and hence         entries for the name, you can extract each of their numbers, and  hence
2537         the captured data, if any.         the captured data, if any.
2538    
2539    
2540  FINDING ALL POSSIBLE MATCHES  FINDING ALL POSSIBLE MATCHES
2541    
2542         The traditional matching function uses a  similar  algorithm  to  Perl,         The  traditional  matching  function  uses a similar algorithm to Perl,
2543         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
2544         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
2545         possible  match,  consider using the alternative matching function (see         possible match, consider using the alternative matching  function  (see
2546         below) instead. If you cannot use the alternative function,  but  still         below)  instead.  If you cannot use the alternative function, but still
2547         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
2548         of the callout facility, which is described in the pcrecallout documen-         of the callout facility, which is described in the pcrecallout documen-
2549         tation.         tation.
2550    
2551         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-
2552         tern.  When your callout function is called, extract and save the  cur-         tern.   When your callout function is called, extract and save the cur-
2553         rent  matched  substring.  Then  return  1, which forces pcre_exec() to         rent matched substring. Then return  1,  which  forces  pcre_exec()  to
2554         backtrack and try other alternatives. Ultimately, when it runs  out  of         backtrack  and  try other alternatives. Ultimately, when it runs out of
2555         matches, pcre_exec() will yield PCRE_ERROR_NOMATCH.         matches, pcre_exec() will yield PCRE_ERROR_NOMATCH.
2556    
2557    
# Line 2557  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 2562  MATCHING A PATTERN: THE ALTERNATIVE FUNC
2562              int options, int *ovector, int ovecsize,              int options, int *ovector, int ovecsize,
2563              int *workspace, int wscount);              int *workspace, int wscount);
2564    
2565         The  function  pcre_dfa_exec()  is  called  to  match  a subject string         The function pcre_dfa_exec()  is  called  to  match  a  subject  string
2566         against a compiled pattern, using a matching algorithm that  scans  the         against  a  compiled pattern, using a matching algorithm that scans the
2567         subject  string  just  once, and does not backtrack. This has different         subject string just once, and does not backtrack.  This  has  different
2568         characteristics to the normal algorithm, and  is  not  compatible  with         characteristics  to  the  normal  algorithm, and is not compatible with
2569         Perl.  Some  of the features of PCRE patterns are not supported. Never-         Perl. Some of the features of PCRE patterns are not  supported.  Never-
2570         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
2571         a  discussion  of  the  two matching algorithms, and a list of features         a discussion of the two matching algorithms, and  a  list  of  features
2572         that pcre_dfa_exec() does not support, see the pcrematching  documenta-         that  pcre_dfa_exec() does not support, see the pcrematching documenta-
2573         tion.         tion.
2574    
2575         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
2576         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-
2577         ent  way,  and  this is described below. The other common arguments are         ent way, and this is described below. The other  common  arguments  are
2578         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
2579         repeated here.         repeated here.
2580    
2581         The  two  additional  arguments provide workspace for the function. The         The two additional arguments provide workspace for  the  function.  The
2582         workspace vector should contain at least 20 elements. It  is  used  for         workspace  vector  should  contain at least 20 elements. It is used for
2583         keeping  track  of  multiple  paths  through  the  pattern  tree.  More         keeping  track  of  multiple  paths  through  the  pattern  tree.  More
2584         workspace will be needed for patterns and subjects where  there  are  a         workspace  will  be  needed for patterns and subjects where there are a
2585         lot of potential matches.         lot of potential matches.
2586    
2587         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 2598  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 2603  MATCHING A PATTERN: THE ALTERNATIVE FUNC
2603    
2604     Option bits for pcre_dfa_exec()     Option bits for pcre_dfa_exec()
2605    
2606         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
2607         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-
2608         LINE_xxx,        PCRE_NOTBOL,        PCRE_NOTEOL,        PCRE_NOTEMPTY,         LINE_xxx,        PCRE_NOTBOL,        PCRE_NOTEOL,        PCRE_NOTEMPTY,
2609         PCRE_NOTEMPTY_ATSTART, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_HARD, PCRE_PAR-         PCRE_NOTEMPTY_ATSTART, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_HARD, PCRE_PAR-
2610         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
2611         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
2612         description is not repeated here.         description is not repeated here.
2613    
2614           PCRE_PARTIAL_HARD           PCRE_PARTIAL_HARD
2615           PCRE_PARTIAL_SOFT           PCRE_PARTIAL_SOFT
2616    
2617         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
2618         details are slightly  different.  When  PCRE_PARTIAL_HARD  is  set  for         details  are  slightly  different.  When  PCRE_PARTIAL_HARD  is set for
2619         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-
2620         ject is reached and there is still at least  one  matching  possibility         ject  is  reached  and there is still at least one matching possibility
2621         that requires additional characters. This happens even if some complete         that requires additional characters. This happens even if some complete
2622         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
2623         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
2624         of the subject is reached, there have been  no  complete  matches,  but         of  the  subject  is  reached, there have been no complete matches, but
2625         there  is  still  at least one matching possibility. The portion of the         there is still at least one matching possibility. The  portion  of  the
2626         string that was inspected when the longest partial match was  found  is         string  that  was inspected when the longest partial match was found is
2627         set as the first matching string in both cases.         set as the first matching string in both cases.
2628    
2629           PCRE_DFA_SHORTEST           PCRE_DFA_SHORTEST
2630    
2631         Setting  the  PCRE_DFA_SHORTEST option causes the matching algorithm to         Setting the PCRE_DFA_SHORTEST option causes the matching  algorithm  to
2632         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-
2633         tive  algorithm  works, this is necessarily the shortest possible match         tive algorithm works, this is necessarily the shortest  possible  match
2634         at the first possible matching point in the subject string.         at the first possible matching point in the subject string.
2635    
2636           PCRE_DFA_RESTART           PCRE_DFA_RESTART
2637    
2638         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
2639         again,  with  additional  subject characters, and have it continue with         again, with additional subject characters, and have  it  continue  with
2640         the same match. The PCRE_DFA_RESTART option requests this action;  when         the  same match. The PCRE_DFA_RESTART option requests this action; when
2641         it  is  set,  the workspace and wscount options must reference the same         it is set, the workspace and wscount options must  reference  the  same
2642         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
2643         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
2644         pcrepartial documentation.         pcrepartial documentation.
2645    
2646     Successful returns from pcre_dfa_exec()     Successful returns from pcre_dfa_exec()
2647    
2648         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-
2649         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
2650         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
2651         matches  are all initial substrings of the longer matches. For example,         matches are all initial substrings of the longer matches. For  example,
2652         if the pattern         if the pattern
2653    
2654           <.*>           <.*>
# Line 2658  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 2663  MATCHING A PATTERN: THE ALTERNATIVE FUNC
2663           <something> <something else>           <something> <something else>
2664           <something> <something else> <something further>           <something> <something else> <something further>
2665    
2666         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,
2667         which  is  the  number of matched substrings. The substrings themselves         which is the number of matched substrings.  The  substrings  themselves
2668         are returned in ovector. Each string uses two elements;  the  first  is         are  returned  in  ovector. Each string uses two elements; the first is
2669         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
2670         fact, all the strings have the same start  offset.  (Space  could  have         fact,  all  the  strings  have the same start offset. (Space could have
2671         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
2672         compatibility with the way pcre_exec() returns data,  even  though  the         compatibility  with  the  way pcre_exec() returns data, even though the
2673         meaning of the strings is different.)         meaning of the strings is different.)
2674    
2675         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-
2676         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
2677         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
2678         filled with the longest matches.         filled with the longest matches.
2679    
2680     Error returns from pcre_dfa_exec()     Error returns from pcre_dfa_exec()
2681    
2682         The pcre_dfa_exec() function returns a negative number when  it  fails.         The  pcre_dfa_exec()  function returns a negative number when it fails.
2683         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
2684         described above.  There are in addition the following errors  that  are         described  above.   There are in addition the following errors that are
2685         specific to pcre_dfa_exec():         specific to pcre_dfa_exec():
2686    
2687           PCRE_ERROR_DFA_UITEM      (-16)           PCRE_ERROR_DFA_UITEM      (-16)
2688    
2689         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-
2690         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
2691         reference.         reference.
2692    
2693           PCRE_ERROR_DFA_UCOND      (-17)           PCRE_ERROR_DFA_UCOND      (-17)
2694    
2695         This  return  is  given  if pcre_dfa_exec() encounters a condition item         This return is given if pcre_dfa_exec()  encounters  a  condition  item
2696         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
2697         in a specific group. These are not supported.         in a specific group. These are not supported.
2698    
2699           PCRE_ERROR_DFA_UMLIMIT    (-18)           PCRE_ERROR_DFA_UMLIMIT    (-18)
2700    
2701         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
2702         that contains a setting of the match_limit field. This is not supported         that contains a setting of the match_limit field. This is not supported
2703         (it is meaningless).         (it is meaningless).
2704    
2705           PCRE_ERROR_DFA_WSSIZE     (-19)           PCRE_ERROR_DFA_WSSIZE     (-19)
2706    
2707         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
2708         workspace vector.         workspace vector.
2709    
2710           PCRE_ERROR_DFA_RECURSE    (-20)           PCRE_ERROR_DFA_RECURSE    (-20)
2711    
2712         When a recursive subpattern is processed, the matching  function  calls         When  a  recursive subpattern is processed, the matching function calls
2713         itself  recursively,  using  private vectors for ovector and workspace.         itself recursively, using private vectors for  ovector  and  workspace.
2714         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
2715         should be extremely rare, as a vector of size 1000 is used.         should be extremely rare, as a vector of size 1000 is used.
2716    
2717    
2718  SEE ALSO  SEE ALSO
2719    
2720         pcrebuild(3),  pcrecallout(3), pcrecpp(3)(3), pcrematching(3), pcrepar-         pcrebuild(3), pcrecallout(3), pcrecpp(3)(3), pcrematching(3),  pcrepar-
2721         tial(3), pcreposix(3), pcreprecompile(3), pcresample(3), pcrestack(3).         tial(3), pcreposix(3), pcreprecompile(3), pcresample(3), pcrestack(3).
2722    
2723    
# Line 2725  AUTHOR Line 2730  AUTHOR
2730    
2731  REVISION  REVISION
2732    
2733         Last updated: 26 March 2010         Last updated: 03 May 2010
2734         Copyright (c) 1997-2010 University of Cambridge.         Copyright (c) 1997-2010 University of Cambridge.
2735  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2736    
2737    
2738  PCRECALLOUT(3)                                                  PCRECALLOUT(3)  PCRECALLOUT(3)                                                  PCRECALLOUT(3)
2739    
2740    
# Line 2909  REVISION Line 2914  REVISION
2914         Last updated: 29 September 2009         Last updated: 29 September 2009
2915         Copyright (c) 1997-2009 University of Cambridge.         Copyright (c) 1997-2009 University of Cambridge.
2916  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2917    
2918    
2919  PCRECOMPAT(3)                                                    PCRECOMPAT(3)  PCRECOMPAT(3)                                                    PCRECOMPAT(3)
2920    
2921    
# Line 3066  REVISION Line 3071  REVISION
3071         Last updated: 04 October 2009         Last updated: 04 October 2009
3072         Copyright (c) 1997-2009 University of Cambridge.         Copyright (c) 1997-2009 University of Cambridge.
3073  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
3074    
3075    
3076  PCREPATTERN(3)                                                  PCREPATTERN(3)  PCREPATTERN(3)                                                  PCREPATTERN(3)
3077    
3078    
# Line 3146  NEWLINE CONVENTIONS Line 3151  NEWLINE CONVENTIONS
3151         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
3152         present, the last one is used.         present, the last one is used.
3153    
3154         The  newline  convention  does  not  affect what the \R escape sequence         The  newline convention affects the interpretation of the dot metachar-
3155         matches. By default, this is any Unicode  newline  sequence,  for  Perl         acter when PCRE_DOTALL is not set, and also the behaviour of  \N.  How-
3156         compatibility.  However, this can be changed; see the description of \R         ever,  it  does  not  affect  what  the  \R escape sequence matches. By
3157         in the section entitled "Newline sequences" below. A change of \R  set-         default, this is any Unicode newline sequence, for Perl  compatibility.
3158         ting can be combined with a change of newline convention.         However,  this can be changed; see the description of \R in the section
3159           entitled "Newline sequences" below. A change of \R setting can be  com-
3160           bined with a change of newline convention.
3161    
3162    
3163  CHARACTERS AND METACHARACTERS  CHARACTERS AND METACHARACTERS
# Line 3332  BACKSLASH Line 3339  BACKSLASH
3339         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
3340         inside  and  outside character classes. In addition, inside a character         inside  and  outside character classes. In addition, inside a character
3341         class, the sequence \b is interpreted as the backspace  character  (hex         class, the sequence \b is interpreted as the backspace  character  (hex
3342         08),  and the sequences \R and \X are interpreted as the characters "R"         08).  The sequences \B, \N, \R, and \X are not special inside a charac-
3343         and "X", respectively. Outside a character class, these sequences  have         ter class. Like any  other  unrecognized  escape  sequences,  they  are
3344         different meanings (see below).         treated  as  the  literal characters "B", "N", "R", and "X" by default,
3345           but cause an error if the PCRE_EXTRA option is set. Outside a character
3346           class, these sequences have different meanings.
3347    
3348     Absolute and relative back references     Absolute and relative back references
3349    
# Line 3354  BACKSLASH Line 3363  BACKSLASH
3363    
3364     Generic character types     Generic character types
3365    
3366         Another use of backslash is for specifying generic character types. The         Another use of backslash is for specifying generic character types:
        following are always recognized:  
3367    
3368           \d     any decimal digit           \d     any decimal digit
3369           \D     any character that is not a decimal digit           \D     any character that is not a decimal digit
# Line 3368  BACKSLASH Line 3376  BACKSLASH
3376           \w     any "word" character           \w     any "word" character
3377           \W     any "non-word" character           \W     any "non-word" character
3378    
3379         Each pair of escape sequences partitions the complete set of characters         There is also the single sequence \N, which matches a non-newline char-
3380         into  two disjoint sets. Any given character matches one, and only one,         acter.  This is the same as the "." metacharacter when  PCRE_DOTALL  is
3381         of each pair.         not set.
3382    
3383           Each  pair of lower and upper case escape sequences partitions the com-
3384           plete set of characters into two disjoint  sets.  Any  given  character
3385           matches one, and only one, of each pair.
3386    
3387         These character type sequences can appear both inside and outside char-         These character type sequences can appear both inside and outside char-
3388         acter  classes.  They each match one character of the appropriate type.         acter classes. They each match one character of the  appropriate  type.
3389         If the current matching point is at the end of the subject string,  all         If  the current matching point is at the end of the subject string, all
3390         of them fail, since there is no character to match.         of them fail, since there is no character to match.
3391    
3392         For  compatibility  with Perl, \s does not match the VT character (code         For compatibility with Perl, \s does not match the VT  character  (code
3393         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
3394         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
3395         "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-
3396         ter. In PCRE, it never does.         ter. In PCRE, it never does.
3397    
3398         In  UTF-8 mode, characters with values greater than 128 never match \d,         In UTF-8 mode, characters with values greater than 128 never match  \d,
3399         \s, or \w, and always match \D, \S, and \W. This is true even when Uni-         \s, or \w, and always match \D, \S, and \W. This is true even when Uni-
3400         code  character  property  support is available. These sequences retain         code character property support is available.  These  sequences  retain
3401         their original meanings from before UTF-8 support was available, mainly         their original meanings from before UTF-8 support was available, mainly
3402         for  efficiency  reasons. Note that this also affects \b, because it is         for efficiency reasons. Note that this also affects \b, because  it  is
3403         defined in terms of \w and \W.         defined in terms of \w and \W.
3404    
3405         The sequences \h, \H, \v, and \V are Perl 5.10 features. In contrast to         The sequences \h, \H, \v, and \V are Perl 5.10 features. In contrast to
3406         the  other  sequences, these do match certain high-valued codepoints in         the other sequences, these do match certain high-valued  codepoints  in
3407         UTF-8 mode.  The horizontal space characters are:         UTF-8 mode.  The horizontal space characters are:
3408    
3409           U+0009     Horizontal tab           U+0009     Horizontal tab
# Line 3425  BACKSLASH Line 3437  BACKSLASH
3437           U+2029     Paragraph separator           U+2029     Paragraph separator
3438    
3439         A "word" character is an underscore or any character less than 256 that         A "word" character is an underscore or any character less than 256 that
3440         is  a  letter  or  digit.  The definition of letters and digits is con-         is a letter or digit. The definition of  letters  and  digits  is  con-
3441         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-
3442         specific  matching is taking place (see "Locale support" in the pcreapi         specific matching is taking place (see "Locale support" in the  pcreapi
3443         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
3444         systems,  or "french" in Windows, some character codes greater than 128         systems, or "french" in Windows, some character codes greater than  128
3445         are used for accented letters, and these are matched by \w. The use  of         are  used for accented letters, and these are matched by \w. The use of
3446         locales with Unicode is discouraged.         locales with Unicode is discouraged.
3447    
3448     Newline sequences     Newline sequences
3449    
3450         Outside  a  character class, by default, the escape sequence \R matches         Outside a character class, by default, the escape sequence  \R  matches
3451         any Unicode newline sequence. This is a Perl 5.10 feature. In non-UTF-8         any Unicode newline sequence. This is a Perl 5.10 feature. In non-UTF-8
3452         mode \R is equivalent to the following:         mode \R is equivalent to the following:
3453    
3454           (?>\r\n|\n|\x0b|\f|\r|\x85)           (?>\r\n|\n|\x0b|\f|\r|\x85)
3455    
3456         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
3457         below.  This particular group matches either the two-character sequence         below.  This particular group matches either the two-character sequence
3458         CR  followed  by  LF,  or  one  of  the single characters LF (linefeed,         CR followed by LF, or  one  of  the  single  characters  LF  (linefeed,
3459         U+000A), VT (vertical tab, U+000B), FF (formfeed, U+000C), CR (carriage         U+000A), VT (vertical tab, U+000B), FF (formfeed, U+000C), CR (carriage
3460         return, U+000D), or NEL (next line, U+0085). The two-character sequence         return, U+000D), or NEL (next line, U+0085). The two-character sequence
3461         is treated as a single unit that cannot be split.         is treated as a single unit that cannot be split.
3462    
3463         In UTF-8 mode, two additional characters whose codepoints  are  greater         In  UTF-8  mode, two additional characters whose codepoints are greater
3464         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-
3465         rator, U+2029).  Unicode character property support is not  needed  for         rator,  U+2029).   Unicode character property support is not needed for
3466         these characters to be recognized.         these characters to be recognized.
3467    
3468         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
3469         the complete set  of  Unicode  line  endings)  by  setting  the  option         the  complete  set  of  Unicode  line  endings)  by  setting the option
3470         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.
3471         (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
3472         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
3473         requested via the PCRE_BSR_UNICODE option.   It  is  also  possible  to         requested  via  the  PCRE_BSR_UNICODE  option.   It is also possible to
3474         specify  these  settings  by  starting a pattern string with one of the         specify these settings by starting a pattern string  with  one  of  the
3475         following sequences:         following sequences:
3476    
3477           (*BSR_ANYCRLF)   CR, LF, or CRLF only           (*BSR_ANYCRLF)   CR, LF, or CRLF only
3478           (*BSR_UNICODE)   any Unicode newline sequence           (*BSR_UNICODE)   any Unicode newline sequence
3479    
3480         These override the default and the options given to  pcre_compile()  or         These  override  the default and the options given to pcre_compile() or
3481         pcre_compile2(),  but  they  can  be  overridden  by  options  given to         pcre_compile2(), but  they  can  be  overridden  by  options  given  to
3482         pcre_exec() or pcre_dfa_exec(). Note that these special settings, which         pcre_exec() or pcre_dfa_exec(). Note that these special settings, which
3483         are  not  Perl-compatible,  are  recognized only at the very start of a         are not Perl-compatible, are recognized only at the  very  start  of  a
3484         pattern, and that they must be in upper case. If more than one of  them         pattern,  and that they must be in upper case. If more than one of them
3485         is present, the last one is used. They can be combined with a change of         is present, the last one is used. They can be combined with a change of
3486         newline convention, for example, a pattern can start with:         newline convention, for example, a pattern can start with:
3487    
3488           (*ANY)(*BSR_ANYCRLF)           (*ANY)(*BSR_ANYCRLF)
3489    
3490         Inside a character class, \R matches the letter "R".         Inside  a  character  class,  \R  is  treated as an unrecognized escape
3491           sequence, and so matches the letter "R" by default, but causes an error
3492           if PCRE_EXTRA is set.
3493    
3494     Unicode character properties     Unicode character properties
3495    
3496         When PCRE is built with Unicode character property support, three addi-         When PCRE is built with Unicode character property support, three addi-
3497         tional  escape sequences that match characters with specific properties         tional escape sequences that match characters with specific  properties
3498         are available.  When not in UTF-8 mode, these sequences are  of  course         are  available.   When not in UTF-8 mode, these sequences are of course
3499         limited  to  testing characters whose codepoints are less than 256, but         limited to testing characters whose codepoints are less than  256,  but
3500         they do work in this mode.  The extra escape sequences are:         they do work in this mode.  The extra escape sequences are:
3501    
3502           \p{xx}   a character with the xx property           \p{xx}   a character with the xx property
3503           \P{xx}   a character without the xx property           \P{xx}   a character without the xx property
3504           \X       an extended Unicode sequence           \X       an extended Unicode sequence
3505    
3506         The property names represented by xx above are limited to  the  Unicode         The  property  names represented by xx above are limited to the Unicode
3507         script names, the general category properties, and "Any", which matches         script names, the general category properties, "Any", which matches any
3508         any character (including newline). Other properties such as "InMusical-         character   (including  newline),  and  some  special  PCRE  properties
3509         Symbols"  are  not  currently supported by PCRE. Note that \P{Any} does         (described in the next section).  Other Perl properties such as  "InMu-
3510         not match any characters, so always causes a match failure.         sicalSymbols"  are  not  currently supported by PCRE. Note that \P{Any}
3511           does not match any characters, so always causes a match failure.
3512    
3513         Sets of Unicode characters are defined as belonging to certain scripts.         Sets of Unicode characters are defined as belonging to certain scripts.
3514         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.
# Line 3520  BACKSLASH Line 3535  BACKSLASH
3535         Tai_Tham,  Tai_Viet,  Tamil,  Telugu,  Thaana, Thai, Tibetan, Tifinagh,         Tai_Tham,  Tai_Viet,  Tamil,  Telugu,  Thaana, Thai, Tibetan, Tifinagh,
3536         Ugaritic, Vai, Yi.         Ugaritic, Vai, Yi.
3537    
3538         Each character has exactly one general category property, specified  by         Each character has exactly one Unicode general category property, spec-
3539         a two-letter abbreviation. For compatibility with Perl, negation can be         ified  by a two-letter abbreviation. For compatibility with Perl, nega-
3540         specified by including a circumflex between the opening brace  and  the         tion can be specified by including a  circumflex  between  the  opening
3541         property name. For example, \p{^Lu} is the same as \P{Lu}.         brace  and  the  property  name.  For  example,  \p{^Lu} is the same as
3542           \P{Lu}.
3543    
3544         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-
3545         eral category properties that start with that letter. In this case,  in         eral  category properties that start with that letter. In this case, in
3546         the  absence of negation, the curly brackets in the escape sequence are         the absence of negation, the curly brackets in the escape sequence  are
3547         optional; these two examples have the same effect:         optional; these two examples have the same effect:
3548    
3549           \p{L}           \p{L}
# Line 3579  BACKSLASH Line 3595  BACKSLASH
3595           Zp    Paragraph separator           Zp    Paragraph separator
3596           Zs    Space separator           Zs    Space separator
3597    
3598         The special property L& is also supported: it matches a character  that         The  special property L& is also supported: it matches a character that
3599         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
3600         classified as a modifier or "other".         classified as a modifier or "other".
3601    
3602         The Cs (Surrogate) property applies only to  characters  in  the  range         The  Cs  (Surrogate)  property  applies only to characters in the range
3603         U+D800  to  U+DFFF. Such characters are not valid in UTF-8 strings (see         U+D800 to U+DFFF. Such characters are not valid in UTF-8  strings  (see
3604         RFC 3629) and so cannot be tested by PCRE, unless UTF-8 validity check-         RFC 3629) and so cannot be tested by PCRE, unless UTF-8 validity check-
3605         ing  has  been  turned off (see the discussion of PCRE_NO_UTF8_CHECK in         ing has been turned off (see the discussion  of  PCRE_NO_UTF8_CHECK  in
3606         the pcreapi page). Perl does not support the Cs property.         the pcreapi page). Perl does not support the Cs property.
3607    
3608         The long synonyms for  property  names  that  Perl  supports  (such  as         The  long  synonyms  for  property  names  that  Perl supports (such as
3609         \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
3610         any of these properties with "Is".         any of these properties with "Is".
3611    
3612         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-
3613         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
3614         in the Unicode table.         in the Unicode table.
3615    
3616         Specifying caseless matching does not affect  these  escape  sequences.         Specifying  caseless  matching  does not affect these escape sequences.
3617         For example, \p{Lu} always matches only upper case letters.         For example, \p{Lu} always matches only upper case letters.
3618    
3619         The  \X  escape  matches  any number of Unicode characters that form an         The \X escape matches any number of Unicode  characters  that  form  an
3620         extended Unicode sequence. \X is equivalent to         extended Unicode sequence. \X is equivalent to
3621    
3622           (?>\PM\pM*)           (?>\PM\pM*)
3623    
3624         That is, it matches a character without the "mark"  property,  followed         That  is,  it matches a character without the "mark" property, followed
3625         by  zero  or  more  characters with the "mark" property, and treats the         by zero or more characters with the "mark"  property,  and  treats  the
3626         sequence as an atomic group (see below).  Characters  with  the  "mark"         sequence  as  an  atomic group (see below).  Characters with the "mark"
3627         property  are  typically  accents  that affect the preceding character.         property are typically accents that  affect  the  preceding  character.
3628         None of them have codepoints less than 256, so  in  non-UTF-8  mode  \X         None  of  them  have  codepoints less than 256, so in non-UTF-8 mode \X
3629         matches any one character.         matches any one character.
3630    
3631         Matching  characters  by Unicode property is not fast, because PCRE has         Matching characters by Unicode property is not fast, because  PCRE  has
3632         to search a structure that contains  data  for  over  fifteen  thousand         to  search  a  structure  that  contains data for over fifteen thousand
3633         characters. That is why the traditional escape sequences such as \d and         characters. That is why the traditional escape sequences such as \d and
3634         \w do not use Unicode properties in PCRE.         \w do not use Unicode properties in PCRE.
3635    
3636       PCRE's additional properties
3637    
3638           As  well  as  the standard Unicode properties described in the previous
3639           section, PCRE supports four more that make it possible to convert  tra-
3640           ditional escape sequences such as \w and \s and POSIX character classes
3641           to use Unicode properties. These are:
3642    
3643             Xan   Any alphanumeric character
3644             Xps   Any POSIX space character
3645             Xsp   Any Perl space character
3646             Xwd   Any Perl "word" character
3647    
3648           Xan matches characters that have either the L (letter) or the  N  (num-
3649           ber)  property. Xps matches the characters tab, linefeed, vertical tab,
3650           formfeed, or carriage return, and any other character that  has  the  Z
3651           (separator) property.  Xsp is the same as Xps, except that vertical tab
3652           is excluded. Xwd matches the same characters as Xan, plus underscore.
3653    
3654     Resetting the match start     Resetting the match start
3655    
3656         The escape sequence \K, which is a Perl 5.10 feature, causes any previ-         The escape sequence \K, which is a Perl 5.10 feature, causes any previ-
# Line 3656  BACKSLASH Line 3690  BACKSLASH
3690           \z     matches only at the end of the subject           \z     matches only at the end of the subject
3691           \G     matches at the first matching position in the subject           \G     matches at the first matching position in the subject
3692    
3693         These  assertions may not appear in character classes (but note that \b         Inside  a  character  class, \b has a different meaning; it matches the
3694         has a different meaning, namely the backspace character, inside a char-         backspace character. If any other of  these  assertions  appears  in  a
3695         acter class).         character  class, by default it matches the corresponding literal char-
3696           acter  (for  example,  \B  matches  the  letter  B).  However,  if  the
3697         A  word  boundary is a position in the subject string where the current         PCRE_EXTRA  option is set, an "invalid escape sequence" error is gener-
3698         character and the previous character do not both match \w or  \W  (i.e.         ated instead.
3699         one  matches  \w  and the other matches \W), or the start or end of the  
3700           A word boundary is a position in the subject string where  the  current
3701           character  and  the previous character do not both match \w or \W (i.e.
3702           one matches \w and the other matches \W), or the start or  end  of  the
3703         string if the first or last character matches \w, respectively. Neither         string if the first or last character matches \w, respectively. Neither
3704         PCRE  nor  Perl  has a separte "start of word" or "end of word" metase-         PCRE nor Perl has a separte "start of word" or "end  of  word"  metase-
3705         quence. However, whatever follows \b normally determines which  it  is.         quence.  However,  whatever follows \b normally determines which it is.
3706         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.
3707    
3708         The  \A,  \Z,  and \z assertions differ from the traditional circumflex         The \A, \Z, and \z assertions differ from  the  traditional  circumflex
3709         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
3710         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
3711         set. Thus, they are independent of multiline mode. These  three  asser-         set.  Thus,  they are independent of multiline mode. These three asser-
3712         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
3713         affect only the behaviour of the circumflex and dollar  metacharacters.         affect  only the behaviour of the circumflex and dollar metacharacters.
3714         However,  if the startoffset argument of pcre_exec() is non-zero, indi-         However, if the startoffset argument of pcre_exec() is non-zero,  indi-
3715         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
3716         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
3717         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
3718         the very end, whereas \z matches only at the end.         the very end, whereas \z matches only at the end.
3719    
3720         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
3721         the start point of the match, as specified by the startoffset  argument         the  start point of the match, as specified by the startoffset argument
3722         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
3723         non-zero. By calling pcre_exec() multiple times with appropriate  argu-         non-zero.  By calling pcre_exec() multiple times with appropriate argu-
3724         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-
3725         mentation where \G can be useful.         mentation where \G can be useful.
3726    
3727         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
3728         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
3729         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
3730         previously  matched  string was empty. Because PCRE does just one match         previously matched string was empty. Because PCRE does just  one  match
3731         at a time, it cannot reproduce this behaviour.         at a time, it cannot reproduce this behaviour.
3732    
3733         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
3734         anchored to the starting match position, and the "anchored" flag is set         anchored to the starting match position, and the "anchored" flag is set
3735         in the compiled regular expression.         in the compiled regular expression.
3736    
# Line 3701  BACKSLASH Line 3738  BACKSLASH
3738  CIRCUMFLEX AND DOLLAR  CIRCUMFLEX AND DOLLAR
3739    
3740         Outside a character class, in the default matching mode, the circumflex         Outside a character class, in the default matching mode, the circumflex
3741         character  is  an  assertion  that is true only if the current matching         character is an assertion that is true only  if  the  current  matching
3742         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-
3743         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
3744         PCRE_MULTILINE option is unset. Inside a  character  class,  circumflex         PCRE_MULTILINE  option  is  unset. Inside a character class, circumflex
3745         has an entirely different meaning (see below).         has an entirely different meaning (see below).
3746    
3747         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
3748         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
3749         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
3750         branch. If all possible alternatives start with a circumflex, that  is,         branch.  If all possible alternatives start with a circumflex, that is,
3751         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-
3752         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
3753         constructs that can cause a pattern to be anchored.)         constructs that can cause a pattern to be anchored.)
3754    
3755         A  dollar  character  is  an assertion that is true only if the current         A dollar character is an assertion that is true  only  if  the  current
3756         matching point is at the end of  the  subject  string,  or  immediately         matching  point  is  at  the  end of the subject string, or immediately
3757         before a newline at the end of the string (by default). Dollar need not         before a newline at the end of the string (by default). Dollar need not
3758         be the last character of the pattern if a number  of  alternatives  are         be  the  last  character of the pattern if a number of alternatives are
3759         involved,  but  it  should  be  the last item in any branch in which it         involved, but it should be the last item in  any  branch  in  which  it
3760         appears. Dollar has no special meaning in a character class.         appears. Dollar has no special meaning in a character class.
3761    
3762         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
3763         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
3764         compile time. This does not affect the \Z assertion.         compile time. This does not affect the \Z assertion.
3765    
3766         The meanings of the circumflex and dollar characters are changed if the         The meanings of the circumflex and dollar characters are changed if the
3767         PCRE_MULTILINE  option  is  set.  When  this  is the case, a circumflex         PCRE_MULTILINE option is set. When  this  is  the  case,  a  circumflex
3768         matches immediately after internal newlines as well as at the start  of         matches  immediately after internal newlines as well as at the start of
3769         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
3770         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
3771         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
3772         as the two-character sequence CRLF, isolated CR and  LF  characters  do         as  the  two-character  sequence CRLF, isolated CR and LF characters do
3773         not indicate newlines.         not indicate newlines.
3774    
3775         For  example, the pattern /^abc$/ matches the subject string "def\nabc"         For example, the pattern /^abc$/ matches the subject string  "def\nabc"
3776         (where \n represents a newline) in multiline mode, but  not  otherwise.         (where  \n  represents a newline) in multiline mode, but not otherwise.
3777         Consequently,  patterns  that  are anchored in single line mode because         Consequently, patterns that are anchored in single  line  mode  because
3778         all branches start with ^ are not anchored in  multiline  mode,  and  a         all  branches  start  with  ^ are not anchored in multiline mode, and a
3779         match  for  circumflex  is  possible  when  the startoffset argument of         match for circumflex is  possible  when  the  startoffset  argument  of
3780         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
3781         PCRE_MULTILINE is set.         PCRE_MULTILINE is set.
3782    
3783         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
3784         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
3785         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
3786         set.         set.
3787    
3788    
3789  FULL STOP (PERIOD, DOT)  FULL STOP (PERIOD, DOT) AND \N
3790    
3791         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-
3792         ter  in  the subject string except (by default) a character that signi-         ter in the subject string except (by default) a character  that  signi-
3793         fies the end of a line. In UTF-8 mode, the  matched  character  may  be         fies  the  end  of  a line. In UTF-8 mode, the matched character may be
3794         more than one byte long.         more than one byte long.
3795    
3796         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
3797         that character; when the two-character sequence CRLF is used, dot  does         that  character; when the two-character sequence CRLF is used, dot does
3798         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
3799         matches all characters (including isolated CRs and LFs). When any  Uni-         matches  all characters (including isolated CRs and LFs). When any Uni-
3800         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
3801         any of the other line ending characters.         any of the other line ending characters.
3802    
3803         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
3804         PCRE_DOTALL  option  is  set,  a dot matches any one character, without         PCRE_DOTALL option is set, a dot matches  any  one  character,  without
3805         exception. If the two-character sequence CRLF is present in the subject         exception. If the two-character sequence CRLF is present in the subject
3806         string, it takes two dots to match it.         string, it takes two dots to match it.
3807    
3808         The  handling of dot is entirely independent of the handling of circum-         The handling of dot is entirely independent of the handling of  circum-
3809         flex and dollar, the only relationship being  that  they  both  involve         flex  and  dollar,  the  only relationship being that they both involve
3810         newlines. Dot has no special meaning in a character class.         newlines. Dot has no special meaning in a character class.
3811    
3812           The escape sequence \N always behaves as a dot does when PCRE_DOTALL is
3813           not  set.  In other words, it matches any one character except one that
3814           signifies the end of a line.
3815    
3816    
3817  MATCHING A SINGLE BYTE  MATCHING A SINGLE BYTE
3818    
3819         Outside a character class, the escape sequence \C matches any one byte,         Outside a character class, the escape sequence \C matches any one byte,
3820         both in and out of UTF-8 mode. Unlike a  dot,  it  always  matches  any         both  in  and  out  of  UTF-8 mode. Unlike a dot, it always matches any
3821         line-ending  characters.  The  feature  is provided in Perl in order to         line-ending characters. The feature is provided in  Perl  in  order  to
3822         match individual bytes in UTF-8 mode. Because it breaks up UTF-8  char-         match  individual bytes in UTF-8 mode. Because it breaks up UTF-8 char-
3823         acters  into individual bytes, what remains in the string may be a mal-         acters into individual bytes, what remains in the string may be a  mal-
3824         formed UTF-8 string. For this reason, the \C escape  sequence  is  best         formed  UTF-8  string.  For this reason, the \C escape sequence is best
3825         avoided.         avoided.
3826    
3827         PCRE  does  not  allow \C to appear in lookbehind assertions (described         PCRE does not allow \C to appear in  lookbehind  assertions  (described
3828         below), because in UTF-8 mode this would make it impossible  to  calcu-         below),  because  in UTF-8 mode this would make it impossible to calcu-
3829         late the length of the lookbehind.         late the length of the lookbehind.
3830    
3831    
# Line 3794  SQUARE BRACKETS AND CHARACTER CLASSES Line 3835  SQUARE BRACKETS AND CHARACTER CLASSES
3835         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-
3836         cial by default.  However, if the PCRE_JAVASCRIPT_COMPAT option is set,         cial by default.  However, if the PCRE_JAVASCRIPT_COMPAT option is set,
3837         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
3838         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
3839         first data character in the class  (after  an  initial  circumflex,  if         first  data  character  in  the  class (after an initial circumflex, if
3840         present) or escaped with a backslash.         present) or escaped with a backslash.
3841    
3842         A  character  class matches a single character in the subject. In UTF-8         A character class matches a single character in the subject.  In  UTF-8
3843         mode, the character may be more than one byte long. A matched character         mode, the character may be more than one byte long. A matched character
3844         must be in the set of characters defined by the class, unless the first         must be in the set of characters defined by the class, unless the first
3845         character in the class definition is a circumflex, in  which  case  the         character  in  the  class definition is a circumflex, in which case the
3846         subject  character  must  not  be in the set defined by the class. If a         subject character must not be in the set defined by  the  class.  If  a
3847         circumflex is actually required as a member of the class, ensure it  is         circumflex  is actually required as a member of the class, ensure it is
3848         not the first character, or escape it with a backslash.         not the first character, or escape it with a backslash.
3849    
3850         For  example, the character class [aeiou] matches any lower case vowel,         For example, the character class [aeiou] matches any lower case  vowel,
3851         while [^aeiou] matches any character that is not a  lower  case  vowel.         while  [^aeiou]  matches  any character that is not a lower case vowel.
3852         Note that a circumflex is just a convenient notation for specifying the         Note that a circumflex is just a convenient notation for specifying the
3853         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
3854         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-
3855         sumes a character from the subject string, and therefore  it  fails  if         sumes  a  character  from the subject string, and therefore it fails if
3856         the current pointer is at the end of the string.         the current pointer is at the end of the string.
3857    
3858         In  UTF-8 mode, characters with values greater than 255 can be included         In UTF-8 mode, characters with values greater than 255 can be  included
3859         in a class as a literal string of bytes, or by using the  \x{  escaping         in  a  class as a literal string of bytes, or by using the \x{ escaping
3860         mechanism.         mechanism.
3861    
3862         When  caseless  matching  is set, any letters in a class represent both         When caseless matching is set, any letters in a  class  represent  both
3863         their upper case and lower case versions, so for  example,  a  caseless         their  upper  case  and lower case versions, so for example, a caseless
3864         [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
3865         match "A", whereas a caseful version would. In UTF-8 mode, PCRE  always         match  "A", whereas a caseful version would. In UTF-8 mode, PCRE always
3866         understands  the  concept  of case for characters whose values are less         understands the concept of case for characters whose  values  are  less
3867         than 128, so caseless matching is always possible. For characters  with         than  128, so caseless matching is always possible. For characters with
3868         higher  values,  the  concept  of case is supported if PCRE is compiled         higher values, the concept of case is supported  if  PCRE  is  compiled
3869         with Unicode property support, but not otherwise.  If you want  to  use         with  Unicode  property support, but not otherwise.  If you want to use
3870         caseless  matching  in UTF8-mode for characters 128 and above, you must         caseless matching in UTF8-mode for characters 128 and above,  you  must
3871         ensure that PCRE is compiled with Unicode property support as  well  as         ensure  that  PCRE is compiled with Unicode property support as well as
3872         with UTF-8 support.         with UTF-8 support.
3873    
3874         Characters  that  might  indicate  line breaks are never treated in any         Characters that might indicate line breaks are  never  treated  in  any
3875         special way  when  matching  character  classes,  whatever  line-ending         special  way  when  matching  character  classes,  whatever line-ending
3876         sequence  is  in  use,  and  whatever  setting  of  the PCRE_DOTALL and         sequence is in  use,  and  whatever  setting  of  the  PCRE_DOTALL  and
3877         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
3878         of these characters.         of these characters.
3879    
3880         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-
3881         ters in a character  class.  For  example,  [d-m]  matches  any  letter         ters  in  a  character  class.  For  example,  [d-m] matches any letter
3882         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
3883         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
3884         where  it cannot be interpreted as indicating a range, typically as the         where it cannot be interpreted as indicating a range, typically as  the
3885         first or last character in the class.         first or last character in the class.
3886    
3887         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-
3888         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
3889         two characters ("W" and "-") followed by a literal string "46]", so  it         two  characters ("W" and "-") followed by a literal string "46]", so it
3890         would  match  "W46]"  or  "-46]". However, if the "]" is escaped with a         would match "W46]" or "-46]". However, if the "]"  is  escaped  with  a
3891         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-
3892         preted  as a class containing a range followed by two other characters.         preted as a class containing a range followed by two other  characters.
3893         The octal or hexadecimal representation of "]" can also be used to  end         The  octal or hexadecimal representation of "]" can also be used to end
3894         a range.         a range.
3895    
3896         Ranges  operate in the collating sequence of character values. They can         Ranges operate in the collating sequence of character values. They  can
3897         also  be  used  for  characters  specified  numerically,  for   example         also   be  used  for  characters  specified  numerically,  for  example
3898         [\000-\037].  In UTF-8 mode, ranges can include characters whose values         [\000-\037]. In UTF-8 mode, ranges can include characters whose  values
3899         are greater than 255, for example [\x{100}-\x{2ff}].         are greater than 255, for example [\x{100}-\x{2ff}].
3900    
3901         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,
3902         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
3903         to [][\\^_`wxyzabc], matched caselessly,  and  in  non-UTF-8  mode,  if         to  [][\\^_`wxyzabc],  matched  caselessly,  and  in non-UTF-8 mode, if
3904         character  tables  for  a French locale are in use, [\xc8-\xcb] matches         character tables for a French locale are in  use,  [\xc8-\xcb]  matches
3905         accented E characters in both cases. In UTF-8 mode, PCRE  supports  the         accented  E  characters in both cases. In UTF-8 mode, PCRE supports the
3906         concept  of  case for characters with values greater than 128 only when         concept of case for characters with values greater than 128  only  when
3907         it is compiled with Unicode property support.         it is compiled with Unicode property support.
3908    
3909         The character types \d, \D, \p, \P, \s, \S, \w, and \W may also  appear         The  character types \d, \D, \p, \P, \s, \S, \w, and \W may also appear
3910         in  a  character  class,  and add the characters that they match to the         in a character class, and add the characters that  they  match  to  the
3911         class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-         class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-
3912         flex  can  conveniently  be used with the upper case character types to         flex can conveniently be used with the upper case  character  types  to
3913         specify a more restricted set of characters  than  the  matching  lower         specify  a  more  restricted  set of characters than the matching lower
3914         case  type.  For example, the class [^\W_] matches any letter or digit,         case type. For example, the class [^\W_] matches any letter  or  digit,
3915         but not underscore.         but not underscore.
3916    
3917         The only metacharacters that are recognized in  character  classes  are         The  only  metacharacters  that are recognized in character classes are
3918         backslash,  hyphen  (only  where  it can be interpreted as specifying a         backslash, hyphen (only where it can be  interpreted  as  specifying  a
3919         range), circumflex (only at the start), opening  square  bracket  (only         range),  circumflex  (only  at the start), opening square bracket (only
3920         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
3921         next section), and the terminating  closing  square  bracket.  However,         next  section),  and  the  terminating closing square bracket. However,
3922         escaping other non-alphanumeric characters does no harm.         escaping other non-alphanumeric characters does no harm.
3923    
3924    
3925  POSIX CHARACTER CLASSES  POSIX CHARACTER CLASSES
3926    
3927         Perl supports the POSIX notation for character classes. This uses names         Perl supports the POSIX notation for character classes. This uses names
3928         enclosed by [: and :] within the enclosing square brackets.  PCRE  also         enclosed  by  [: and :] within the enclosing square brackets. PCRE also
3929         supports this notation. For example,         supports this notation. For example,
3930    
3931           [01[:alpha:]%]           [01[:alpha:]%]
# Line 3907  POSIX CHARACTER CLASSES Line 3948  POSIX CHARACTER CLASSES
3948           word     "word" characters (same as \w)           word     "word" characters (same as \w)
3949           xdigit   hexadecimal digits           xdigit   hexadecimal digits
3950    
3951         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),
3952         and  space  (32). Notice that this list includes the VT character (code         and space (32). Notice that this list includes the VT  character  (code
3953         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
3954         Perl compatibility).         Perl compatibility).
3955    
3956         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
3957         from Perl 5.8. Another Perl extension is negation, which  is  indicated         from  Perl  5.8. Another Perl extension is negation, which is indicated
3958         by a ^ character after the colon. For example,         by a ^ character after the colon. For example,
3959    
3960           [12[:^digit:]]           [12[:^digit:]]
3961    
3962         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
3963         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but
3964         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.
3965    
# Line 3928  POSIX CHARACTER CLASSES Line 3969  POSIX CHARACTER CLASSES
3969    
3970  VERTICAL BAR  VERTICAL BAR
3971    
3972         Vertical bar characters are used to separate alternative patterns.  For         Vertical  bar characters are used to separate alternative patterns. For
3973         example, the pattern         example, the pattern
3974    
3975           gilbert|sullivan           gilbert|sullivan
3976    
3977         matches  either "gilbert" or "sullivan". Any number of alternatives may         matches either "gilbert" or "sullivan". Any number of alternatives  may
3978         appear, and an empty  alternative  is  permitted  (matching  the  empty         appear,  and  an  empty  alternative  is  permitted (matching the empty
3979         string). The matching process tries each alternative in turn, from left         string). The matching process tries each alternative in turn, from left
3980         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
3981         are  within a subpattern (defined below), "succeeds" means matching the         are within a subpattern (defined below), "succeeds" means matching  the
3982         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.
3983    
3984    
3985  INTERNAL OPTION SETTING  INTERNAL OPTION SETTING
3986    
3987         The settings of the  PCRE_CASELESS,  PCRE_MULTILINE,  PCRE_DOTALL,  and         The  settings  of  the  PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and
3988         PCRE_EXTENDED  options  (which are Perl-compatible) can be changed from         PCRE_EXTENDED options (which are Perl-compatible) can be  changed  from
3989         within the pattern by  a  sequence  of  Perl  option  letters  enclosed         within  the  pattern  by  a  sequence  of  Perl option letters enclosed
3990         between "(?" and ")".  The option letters are         between "(?" and ")".  The option letters are
3991    
3992           i  for PCRE_CASELESS           i  for PCRE_CASELESS
# Line 3955  INTERNAL OPTION SETTING Line 3996  INTERNAL OPTION SETTING
3996    
3997         For example, (?im) sets caseless, multiline matching. It is also possi-         For example, (?im) sets caseless, multiline matching. It is also possi-
3998         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
3999         combined  setting and unsetting such as (?im-sx), which sets PCRE_CASE-         combined setting and unsetting such as (?im-sx), which sets  PCRE_CASE-
4000         LESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and  PCRE_EXTENDED,         LESS  and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED,
4001         is  also  permitted.  If  a  letter  appears  both before and after the         is also permitted. If a  letter  appears  both  before  and  after  the
4002         hyphen, the option is unset.         hyphen, the option is unset.
4003    
4004         The PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and  PCRE_EXTRA         The  PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA
4005         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
4006         the characters J, U and X respectively.         the characters J, U and X respectively.
4007    
4008         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
4009         inside  subpattern parentheses), the change applies to the remainder of         inside subpattern parentheses), the change applies to the remainder  of
4010         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
4011         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-
4012         fore show up in data extracted by the pcre_fullinfo() function).         fore show up in data extracted by the pcre_fullinfo() function).
4013    
4014         An option change within a subpattern (see below for  a  description  of         An  option  change  within a subpattern (see below for a description of
4015         subpatterns) affects only that part of the current pattern that follows         subpatterns) affects only that part of the current pattern that follows
4016         it, so         it, so
4017    
4018           (a(?i)b)c           (a(?i)b)c
4019    
4020         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
4021         used).   By  this means, options can be made to have different settings         used).  By this means, options can be made to have  different  settings
4022         in different parts of the pattern. Any changes made in one  alternative         in  different parts of the pattern. Any changes made in one alternative
4023         do  carry  on  into subsequent branches within the same subpattern. For         do carry on into subsequent branches within the  same  subpattern.  For
4024         example,         example,
4025    
4026           (a(?i)b|c)           (a(?i)b|c)
4027    
4028         matches "ab", "aB", "c", and "C", even though  when  matching  "C"  the         matches  "ab",  "aB",  "c",  and "C", even though when matching "C" the
4029         first  branch  is  abandoned before the option setting. This is because         first branch is abandoned before the option setting.  This  is  because
4030         the effects of option settings happen at compile time. There  would  be         the  effects  of option settings happen at compile time. There would be
4031         some very weird behaviour otherwise.         some very weird behaviour otherwise.
4032    
4033         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
4034         application when the compile or match functions  are  called.  In  some         application  when  the  compile  or match functions are called. In some
4035         cases the pattern can contain special leading sequences such as (*CRLF)         cases the pattern can contain special leading sequences such as (*CRLF)
4036         to override what the application has set or what  has  been  defaulted.         to  override  what  the application has set or what has been defaulted.
4037         Details  are  given  in the section entitled "Newline sequences" above.         Details are given in the section entitled  "Newline  sequences"  above.
4038         There is also the (*UTF8) leading sequence that  can  be  used  to  set         There  is  also  the  (*UTF8)  leading sequence that can be used to set
4039         UTF-8 mode; this is equivalent to setting the PCRE_UTF8 option.         UTF-8 mode; this is equivalent to setting the PCRE_UTF8 option.
4040    
4041    
# Line 4007  SUBPATTERNS Line 4048  SUBPATTERNS
4048    
4049           cat(aract|erpillar|)           cat(aract|erpillar|)
4050    
4051         matches one of the words "cat", "cataract", or  "caterpillar".  Without         matches  one  of the words "cat", "cataract", or "caterpillar". Without
4052         the  parentheses,  it  would  match  "cataract", "erpillar" or an empty         the parentheses, it would match  "cataract",  "erpillar"  or  an  empty
4053         string.         string.
4054    
4055         2. It sets up the subpattern as  a  capturing  subpattern.  This  means         2.  It  sets  up  the  subpattern as a capturing subpattern. This means
4056         that,  when  the  whole  pattern  matches,  that portion of the subject         that, when the whole pattern  matches,  that  portion  of  the  subject
4057         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
4058         ovector  argument  of pcre_exec(). Opening parentheses are counted from         ovector argument of pcre_exec(). Opening parentheses are  counted  from
4059         left to right (starting from 1) to obtain  numbers  for  the  capturing         left  to  right  (starting  from 1) to obtain numbers for the capturing
4060         subpatterns.         subpatterns.
4061    
4062         For  example,  if the string "the red king" is matched against the pat-         For example, if the string "the red king" is matched against  the  pat-
4063         tern         tern
4064    
4065           the ((red|white) (king|queen))           the ((red|white) (king|queen))
# Line 4026  SUBPATTERNS Line 4067  SUBPATTERNS
4067         the captured substrings are "red king", "red", and "king", and are num-         the captured substrings are "red king", "red", and "king", and are num-
4068         bered 1, 2, and 3, respectively.         bered 1, 2, and 3, respectively.
4069    
4070         The  fact  that  plain  parentheses  fulfil two functions is not always         The fact that plain parentheses fulfil  two  functions  is  not  always
4071         helpful.  There are often times when a grouping subpattern is  required         helpful.   There are often times when a grouping subpattern is required
4072         without  a capturing requirement. If an opening parenthesis is followed         without a capturing requirement. If an opening parenthesis is  followed
4073         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-
4074         ing,  and  is  not  counted when computing the number of any subsequent         ing, and is not counted when computing the  number  of  any  subsequent
4075         capturing subpatterns. For example, if the string "the white queen"  is         capturing  subpatterns. For example, if the string "the white queen" is
4076         matched against the pattern         matched against the pattern
4077    
4078           the ((?:red|white) (king|queen))           the ((?:red|white) (king|queen))
# Line 4039  SUBPATTERNS Line 4080  SUBPATTERNS
4080         the captured substrings are "white queen" and "queen", and are numbered         the captured substrings are "white queen" and "queen", and are numbered
4081         1 and 2. The maximum number of capturing subpatterns is 65535.         1 and 2. The maximum number of capturing subpatterns is 65535.
4082    
4083         As a convenient shorthand, if any option settings are required  at  the         As  a  convenient shorthand, if any option settings are required at the
4084         start  of  a  non-capturing  subpattern,  the option letters may appear         start of a non-capturing subpattern,  the  option  letters  may  appear
4085         between the "?" and the ":". Thus the two patterns         between the "?" and the ":". Thus the two patterns
4086    
4087           (?i:saturday|sunday)           (?i:saturday|sunday)
4088           (?:(?i)saturday|sunday)           (?:(?i)saturday|sunday)
4089    
4090         match exactly the same set of strings. Because alternative branches are         match exactly the same set of strings. Because alternative branches are
4091         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
4092         the subpattern is reached, an option setting in one branch does  affect         the  subpattern is reached, an option setting in one branch does affect
4093         subsequent  branches,  so  the above patterns match "SUNDAY" as well as         subsequent branches, so the above patterns match "SUNDAY"  as  well  as
4094         "Saturday".         "Saturday".
4095    
4096    
4097  DUPLICATE SUBPATTERN NUMBERS  DUPLICATE SUBPATTERN NUMBERS
4098    
4099         Perl 5.10 introduced a feature whereby each alternative in a subpattern         Perl 5.10 introduced a feature whereby each alternative in a subpattern
4100         uses  the same numbers for its capturing parentheses. Such a subpattern         uses the same numbers for its capturing parentheses. Such a  subpattern
4101         starts with (?| and is itself a non-capturing subpattern. For  example,         starts  with (?| and is itself a non-capturing subpattern. For example,
4102         consider this pattern:         consider this pattern:
4103    
4104           (?|(Sat)ur|(Sun))day           (?|(Sat)ur|(Sun))day
4105    
4106         Because  the two alternatives are inside a (?| group, both sets of cap-         Because the two alternatives are inside a (?| group, both sets of  cap-
4107         turing parentheses are numbered one. Thus, when  the  pattern  matches,         turing  parentheses  are  numbered one. Thus, when the pattern matches,
4108         you  can  look  at captured substring number one, whichever alternative         you can look at captured substring number  one,  whichever  alternative
4109         matched. This construct is useful when you want to  capture  part,  but         matched.  This  construct  is useful when you want to capture part, but
4110         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-
4111         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
4112         each  branch. The numbers of any capturing buffers that follow the sub-         each branch. The numbers of any capturing buffers that follow the  sub-
4113         pattern start after the highest number used in any branch. The  follow-         pattern  start after the highest number used in any branch. The follow-
4114         ing  example  is taken from the Perl documentation.  The numbers under-         ing example is taken from the Perl documentation.  The  numbers  under-
4115         neath show in which buffer the captured content will be stored.         neath show in which buffer the captured content will be stored.
4116    
4117           # before  ---------------branch-reset----------- after           # before  ---------------branch-reset----------- after
4118           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
4119           # 1            2         2  3        2     3     4           # 1            2         2  3        2     3     4
4120    
4121         A back reference to a numbered subpattern uses the  most  recent  value         A  back  reference  to a numbered subpattern uses the most recent value
4122         that  is  set  for that number by any subpattern. The following pattern         that is set for that number by any subpattern.  The  following  pattern
4123         matches "abcabc" or "defdef":         matches "abcabc" or "defdef":
4124    
4125           /(?|(abc)|(def))\1/           /(?|(abc)|(def))\1/
4126    
4127         In contrast, a recursive or "subroutine" call to a numbered  subpattern         In  contrast, a recursive or "subroutine" call to a numbered subpattern
4128         always  refers  to  the first one in the pattern with the given number.         always refers to the first one in the pattern with  the  given  number.
4129         The following pattern matches "abcabc" or "defabc":         The following pattern matches "abcabc" or "defabc":
4130    
4131           /(?|(abc)|(def))(?1)/           /(?|(abc)|(def))(?1)/
4132    
4133         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-
4134         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-
4135         ber have matched.         ber have matched.
4136    
4137         An alternative approach to using this "branch reset" feature is to  use         An  alternative approach to using this "branch reset" feature is to use
4138         duplicate named subpatterns, as described in the next section.         duplicate named subpatterns, as described in the next section.
4139    
4140    
4141  NAMED SUBPATTERNS  NAMED SUBPATTERNS
4142    
4143         Identifying  capturing  parentheses  by number is simple, but it can be         Identifying capturing parentheses by number is simple, but  it  can  be
4144         very hard to keep track of the numbers in complicated  regular  expres-         very  hard  to keep track of the numbers in complicated regular expres-
4145         sions.  Furthermore,  if  an  expression  is  modified, the numbers may         sions. Furthermore, if an  expression  is  modified,  the  numbers  may
4146         change. To help with this difficulty, PCRE supports the naming of  sub-         change.  To help with this difficulty, PCRE supports the naming of sub-
4147         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
4148         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
4149         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-
4150         tax. Perl allows identically numbered  subpatterns  to  have  different         tax.  Perl  allows  identically  numbered subpatterns to have different
4151         names, but PCRE does not.         names, but PCRE does not.
4152    
4153         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>...)
4154         or (?'name'...) as in Perl, or (?P<name>...) as in  Python.  References         or  (?'name'...)  as in Perl, or (?P<name>...) as in Python. References
4155         to  capturing parentheses from other parts of the pattern, such as back         to capturing parentheses from other parts of the pattern, such as  back
4156         references, recursion, and conditions, can be made by name as  well  as         references,  recursion,  and conditions, can be made by name as well as
4157         by number.         by number.
4158    
4159         Names  consist  of  up  to  32 alphanumeric characters and underscores.         Names consist of up to  32  alphanumeric  characters  and  underscores.
4160         Named capturing parentheses are still  allocated  numbers  as  well  as         Named  capturing  parentheses  are  still  allocated numbers as well as
4161         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
4162         function calls for extracting the name-to-number translation table from         function calls for extracting the name-to-number translation table from
4163         a compiled pattern. There is also a convenience function for extracting         a compiled pattern. There is also a convenience function for extracting
4164         a captured substring by name.         a captured substring by name.
4165    
4166         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
4167         to relax this constraint by setting the PCRE_DUPNAMES option at compile         to relax this constraint by setting the PCRE_DUPNAMES option at compile
4168         time. (Duplicate names are also always permitted for  subpatterns  with         time.  (Duplicate  names are also always permitted for subpatterns with
4169         the  same  number, set up as described in the previous section.) Dupli-         the same number, set up as described in the previous  section.)  Dupli-
4170         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
4171         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
4172         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
4173         both cases you want to extract the abbreviation. This pattern (ignoring         both cases you want to extract the abbreviation. This pattern (ignoring
4174         the line breaks) does the job:         the line breaks) does the job:
4175    
# Line 4138  NAMED SUBPATTERNS Line 4179  NAMED SUBPATTERNS
4179           (?<DN>Thu)(?:rsday)?|           (?<DN>Thu)(?:rsday)?|
4180           (?<DN>Sat)(?:urday)?           (?<DN>Sat)(?:urday)?
4181    
4182         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
4183         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
4184         reset" subpattern, as described in the previous section.)         reset" subpattern, as described in the previous section.)
4185    
4186         The convenience function for extracting the data by  name  returns  the         The  convenience  function  for extracting the data by name returns the
4187         substring  for  the first (and in this example, the only) subpattern of         substring for the first (and in this example, the only)  subpattern  of
4188         that name that matched. This saves searching  to  find  which  numbered         that  name  that  matched.  This saves searching to find which numbered
4189         subpattern it was.         subpattern it was.
4190    
4191         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
4192         elsewhere in the pattern, the one that corresponds to the first  occur-         elsewhere  in the pattern, the one that corresponds to the first occur-
4193         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
4194         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
4195         named  reference  in a condition test (see the section about conditions         named reference in a condition test (see the section  about  conditions
4196         below), either to check whether a subpattern has matched, or  to  check         below),  either  to check whether a subpattern has matched, or to check
4197         for  recursion,  all  subpatterns with the same name are tested. If the         for recursion, all subpatterns with the same name are  tested.  If  the
4198         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.
4199         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
4200         the interfaces for handling named subpatterns, see the pcreapi documen-         the interfaces for handling named subpatterns, see the pcreapi documen-
4201         tation.         tation.
4202    
4203         Warning: You cannot use different names to distinguish between two sub-         Warning: You cannot use different names to distinguish between two sub-
4204         patterns with the same number because PCRE uses only the  numbers  when         patterns  with  the same number because PCRE uses only the numbers when
4205         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-
4206         ent names are given to subpatterns with the same number.  However,  you         ent  names  are given to subpatterns with the same number. However, you
4207         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
4208         PCRE_DUPNAMES is not set.         PCRE_DUPNAMES is not set.
4209    
4210    
4211  REPETITION  REPETITION
4212    
4213         Repetition is specified by quantifiers, which can  follow  any  of  the         Repetition  is  specified  by  quantifiers, which can follow any of the
4214         following items:         following items:
4215    
4216           a literal data character           a literal data character
# Line 4183  REPETITION Line 4224  REPETITION
4224           a parenthesized subpattern (unless it is an assertion)           a parenthesized subpattern (unless it is an assertion)
4225           a recursive or "subroutine" call to a subpattern           a recursive or "subroutine" call to a subpattern
4226    
4227         The  general repetition quantifier specifies a minimum and maximum num-         The general repetition quantifier specifies a minimum and maximum  num-
4228         ber of permitted matches, by giving the two numbers in  curly  brackets         ber  of  permitted matches, by giving the two numbers in curly brackets
4229         (braces),  separated  by  a comma. The numbers must be less than 65536,         (braces), separated by a comma. The numbers must be  less  than  65536,
4230         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:
4231    
4232           z{2,4}           z{2,4}
4233    
4234         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
4235         special  character.  If  the second number is omitted, but the comma is         special character. If the second number is omitted, but  the  comma  is
4236         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
4237         are  both omitted, the quantifier specifies an exact number of required         are both omitted, the quantifier specifies an exact number of  required
4238         matches. Thus         matches. Thus
4239    
4240           [aeiou]{3,}           [aeiou]{3,}
# Line 4202  REPETITION Line 4243  REPETITION
4243    
4244           \d{8}           \d{8}
4245    
4246         matches exactly 8 digits. An opening curly bracket that  appears  in  a         matches  exactly  8  digits. An opening curly bracket that appears in a
4247         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
4248         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-
4249         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.
4250    
4251         In  UTF-8  mode,  quantifiers  apply to UTF-8 characters rather than to         In UTF-8 mode, quantifiers apply to UTF-8  characters  rather  than  to
4252         individual bytes. Thus, for example, \x{100}{2} matches two UTF-8 char-         individual bytes. Thus, for example, \x{100}{2} matches two UTF-8 char-
4253         acters, each of which is represented by a two-byte sequence. Similarly,         acters, each of which is represented by a two-byte sequence. Similarly,
4254         when Unicode property support is available, \X{3} matches three Unicode         when Unicode property support is available, \X{3} matches three Unicode
4255         extended  sequences,  each of which may be several bytes long (and they         extended sequences, each of which may be several bytes long  (and  they
4256         may be of different lengths).         may be of different lengths).
4257    
4258         The quantifier {0} is permitted, causing the expression to behave as if         The quantifier {0} is permitted, causing the expression to behave as if
4259         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-
4260         ful for subpatterns that are referenced as subroutines  from  elsewhere         ful  for  subpatterns that are referenced as subroutines from elsewhere
4261         in the pattern. Items other than subpatterns that have a {0} quantifier         in the pattern. Items other than subpatterns that have a {0} quantifier
4262         are omitted from the compiled pattern.         are omitted from the compiled pattern.
4263    
4264         For convenience, the three most common quantifiers have  single-charac-         For  convenience, the three most common quantifiers have single-charac-
4265         ter abbreviations:         ter abbreviations:
4266    
4267           *    is equivalent to {0,}           *    is equivalent to {0,}
4268           +    is equivalent to {1,}           +    is equivalent to {1,}
4269           ?    is equivalent to {0,1}           ?    is equivalent to {0,1}
4270    
4271         It  is  possible  to construct infinite loops by following a subpattern         It is possible to construct infinite loops by  following  a  subpattern
4272         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,
4273         for example:         for example:
4274    
4275           (a?)*           (a?)*
4276    
4277         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
4278         for such patterns. However, because there are cases where this  can  be         for  such  patterns. However, because there are cases where this can be
4279         useful,  such  patterns  are now accepted, but if any repetition of the         useful, such patterns are now accepted, but if any  repetition  of  the
4280         subpattern does in fact match no characters, the loop is forcibly  bro-         subpattern  does in fact match no characters, the loop is forcibly bro-
4281         ken.         ken.
4282    
4283         By  default,  the quantifiers are "greedy", that is, they match as much         By default, the quantifiers are "greedy", that is, they match  as  much
4284         as possible (up to the maximum  number  of  permitted  times),  without         as  possible  (up  to  the  maximum number of permitted times), without
4285         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
4286         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
4287         appear  between  /*  and  */ and within the comment, individual * and /         appear between /* and */ and within the comment,  individual  *  and  /
4288         characters may appear. An attempt to match C comments by  applying  the         characters  may  appear. An attempt to match C comments by applying the
4289         pattern         pattern
4290    
4291           /\*.*\*/           /\*.*\*/
# Line 4253  REPETITION Line 4294  REPETITION
4294    
4295           /* first comment */  not comment  /* second comment */           /* first comment */  not comment  /* second comment */
4296    
4297         fails,  because it matches the entire string owing to the greediness of         fails, because it matches the entire string owing to the greediness  of
4298         the .*  item.         the .*  item.
4299    
4300         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
4301         be greedy, and instead matches the minimum number of times possible, so         be greedy, and instead matches the minimum number of times possible, so
4302         the pattern         the pattern
4303    
4304           /\*.*?\*/           /\*.*?\*/
4305    
4306         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
4307         quantifiers  is  not  otherwise  changed,  just the preferred number of         quantifiers is not otherwise changed,  just  the  preferred  number  of
4308         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
4309         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
4310         appear doubled, as in         appear doubled, as in
4311    
4312           \d??\d           \d??\d
# Line 4273  REPETITION Line 4314  REPETITION
4314         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
4315         only way the rest of the pattern matches.         only way the rest of the pattern matches.
4316    
4317         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
4318         Perl), the quantifiers are not greedy by default, but  individual  ones         Perl),  the  quantifiers are not greedy by default, but individual ones
4319         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
4320         words, it inverts the default behaviour.         words, it inverts the default behaviour.
4321    
4322         When a parenthesized subpattern is quantified  with  a  minimum  repeat         When  a  parenthesized  subpattern  is quantified with a minimum repeat
4323         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
4324         required for the compiled pattern, in proportion to  the  size  of  the         required  for  the  compiled  pattern, in proportion to the size of the
4325         minimum or maximum.         minimum or maximum.
4326    
4327         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-
4328         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,
4329         the  pattern  is  implicitly anchored, because whatever follows will be         the pattern is implicitly anchored, because whatever  follows  will  be
4330         tried against every character position in the subject string, so  there         tried  against every character position in the subject string, so there
4331         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
4332         first. PCRE normally treats such a pattern as though it  were  preceded         first.  PCRE  normally treats such a pattern as though it were preceded
4333         by \A.         by \A.
4334    
4335         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-
4336         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-
4337         mization, or alternatively using ^ to indicate anchoring explicitly.         mization, or alternatively using ^ to indicate anchoring explicitly.
4338    
4339         However,  there is one situation where the optimization cannot be used.         However, there is one situation where the optimization cannot be  used.
4340         When .*  is inside capturing parentheses that are the subject of a back         When .*  is inside capturing parentheses that are the subject of a back
4341         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
4342         a later one succeeds. Consider, for example:         a later one succeeds. Consider, for example:
4343    
4344           (.*)abc\1           (.*)abc\1
4345    
4346         If the subject is "xyz123abc123" the match point is the fourth  charac-         If  the subject is "xyz123abc123" the match point is the fourth charac-
4347         ter. For this reason, such a pattern is not implicitly anchored.         ter. For this reason, such a pattern is not implicitly anchored.
4348    
4349         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 4311  REPETITION Line 4352  REPETITION
4352           (tweedle[dume]{3}\s*)+           (tweedle[dume]{3}\s*)+
4353    
4354         has matched "tweedledum tweedledee" the value of the captured substring         has matched "tweedledum tweedledee" the value of the captured substring
4355         is  "tweedledee".  However,  if there are nested capturing subpatterns,         is "tweedledee". However, if there are  nested  capturing  subpatterns,
4356         the corresponding captured values may have been set in previous  itera-         the  corresponding captured values may have been set in previous itera-
4357         tions. For example, after         tions. For example, after
4358    
4359           /(a|(b))+/           /(a|(b))+/
# Line 4322  REPETITION Line 4363  REPETITION
4363    
4364  ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS  ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS
4365    
4366         With  both  maximizing ("greedy") and minimizing ("ungreedy" or "lazy")         With both maximizing ("greedy") and minimizing ("ungreedy"  or  "lazy")
4367         repetition, failure of what follows normally causes the  repeated  item         repetition,  failure  of what follows normally causes the repeated item
4368         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
4369         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,
4370         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
4371         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
4372         no point in carrying on.         no point in carrying on.
4373    
4374         Consider,  for  example, the pattern \d+foo when applied to the subject         Consider, for example, the pattern \d+foo when applied to  the  subject
4375         line         line
4376    
4377           123456bar           123456bar
4378    
4379         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
4380         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
4381         \d+ item, and then with  4,  and  so  on,  before  ultimately  failing.         \d+  item,  and  then  with  4,  and  so on, before ultimately failing.
4382         "Atomic  grouping"  (a  term taken from Jeffrey Friedl's book) provides         "Atomic grouping" (a term taken from Jeffrey  Friedl's  book)  provides
4383         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
4384         to be re-evaluated in this way.         to be re-evaluated in this way.
4385    
4386         If  we  use atomic grouping for the previous example, the matcher gives         If we use atomic grouping for the previous example, the  matcher  gives
4387         up immediately on failing to match "foo" the first time.  The  notation         up  immediately  on failing to match "foo" the first time. The notation
4388         is a kind of special parenthesis, starting with (?> as in this example:         is a kind of special parenthesis, starting with (?> as in this example:
4389    
4390           (?>\d+)foo           (?>\d+)foo
4391    
4392         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-
4393         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
4394         prevented  from  backtracking into it. Backtracking past it to previous         prevented from backtracking into it. Backtracking past it  to  previous
4395         items, however, works as normal.         items, however, works as normal.
4396    
4397         An alternative description is that a subpattern of  this  type  matches         An  alternative  description  is that a subpattern of this type matches
4398         the  string  of  characters  that an identical standalone pattern would         the string of characters that an  identical  standalone  pattern  would
4399         match, if anchored at the current point in the subject string.         match, if anchored at the current point in the subject string.
4400    
4401         Atomic grouping subpatterns are not capturing subpatterns. Simple cases         Atomic grouping subpatterns are not capturing subpatterns. Simple cases
4402         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
4403         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-
4404         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
4405         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
4406         digits.         digits.
4407    
4408         Atomic  groups in general can of course contain arbitrarily complicated         Atomic groups in general can of course contain arbitrarily  complicated
4409         subpatterns, and can be nested. However, when  the  subpattern  for  an         subpatterns,  and  can  be  nested. However, when the subpattern for an
4410         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
4411         simpler notation, called a "possessive quantifier" can  be  used.  This         simpler  notation,  called  a "possessive quantifier" can be used. This
4412         consists  of  an  additional  + character following a quantifier. Using         consists of an additional + character  following  a  quantifier.  Using
4413         this notation, the previous example can be rewritten as         this notation, the previous example can be rewritten as
4414    
4415           \d++foo           \d++foo
# Line 4378  ATOMIC GROUPING AND POSSESSIVE QUANTIFIE Line 4419  ATOMIC GROUPING AND POSSESSIVE QUANTIFIE
4419    
4420           (abc|xyz){2,3}+           (abc|xyz){2,3}+
4421    
4422         Possessive   quantifiers   are   always  greedy;  the  setting  of  the         Possessive  quantifiers  are  always  greedy;  the   setting   of   the
4423         PCRE_UNGREEDY option is ignored. They are a convenient notation for the         PCRE_UNGREEDY option is ignored. They are a convenient notation for the
4424         simpler  forms  of atomic group. However, there is no difference in the         simpler forms of atomic group. However, there is no difference  in  the
4425         meaning of a possessive quantifier and  the  equivalent  atomic  group,         meaning  of  a  possessive  quantifier and the equivalent atomic group,
4426         though  there  may  be a performance difference; possessive quantifiers         though there may be a performance  difference;  possessive  quantifiers
4427         should be slightly faster.         should be slightly faster.
4428    
4429         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-
4430         tax.   Jeffrey  Friedl  originated the idea (and the name) in the first         tax.  Jeffrey Friedl originated the idea (and the name)  in  the  first
4431         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
4432         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
4433         found its way into Perl at release 5.10.         found its way into Perl at release 5.10.
4434    
4435         PCRE has an optimization that automatically "possessifies" certain sim-         PCRE has an optimization that automatically "possessifies" certain sim-
4436         ple  pattern  constructs.  For  example, the sequence A+B is treated as         ple pattern constructs. For example, the sequence  A+B  is  treated  as
4437         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
4438         when B must follow.         when B must follow.
4439    
4440         When  a  pattern  contains an unlimited repeat inside a subpattern that         When a pattern contains an unlimited repeat inside  a  subpattern  that
4441         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
4442         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
4443         very long time indeed. The pattern         very long time indeed. The pattern
4444    
4445           (\D+|<\d+>)*[!?]           (\D+|<\d+>)*[!?]
4446    
4447         matches an unlimited number of substrings that either consist  of  non-         matches  an  unlimited number of substrings that either consist of non-
4448         digits,  or  digits  enclosed in <>, followed by either ! or ?. When it         digits, or digits enclosed in <>, followed by either ! or  ?.  When  it
4449         matches, it runs quickly. However, if it is applied to         matches, it runs quickly. However, if it is applied to
4450    
4451           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
4452    
4453         it takes a long time before reporting  failure.  This  is  because  the         it  takes  a  long  time  before reporting failure. This is because the
4454         string  can be divided between the internal \D+ repeat and the external         string can be divided between the internal \D+ repeat and the  external
4455         * 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
4456         example  uses  [!?]  rather than a single character at the end, because         example uses [!?] rather than a single character at  the  end,  because
4457         both PCRE and Perl have an optimization that allows  for  fast  failure         both  PCRE  and  Perl have an optimization that allows for fast failure
4458         when  a single character is used. They remember the last single charac-         when a single character is used. They remember the last single  charac-
4459         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
4460         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
4461         group, like this:         group, like this:
4462    
4463           ((?>\D+)|<\d+>)*[!?]           ((?>\D+)|<\d+>)*[!?]
# Line 4428  BACK REFERENCES Line 4469  BACK REFERENCES
4469    
4470         Outside a character class, a backslash followed by a digit greater than         Outside a character class, a backslash followed by a digit greater than
4471         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-
4472         pattern earlier (that is, to its left) in the pattern,  provided  there         pattern  earlier  (that is, to its left) in the pattern, provided there
4473         have been that many previous capturing left parentheses.         have been that many previous capturing left parentheses.
4474    
4475         However, if the decimal number following the backslash is less than 10,         However, if the decimal number following the backslash is less than 10,
4476         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
4477         there  are  not that many capturing left parentheses in the entire pat-         there are not that many capturing left parentheses in the  entire  pat-
4478         tern. In other words, the parentheses that are referenced need  not  be         tern.  In  other words, the parentheses that are referenced need not be
4479         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
4480         reference" of this type can make sense when a  repetition  is  involved         reference"  of  this  type can make sense when a repetition is involved
4481         and  the  subpattern to the right has participated in an earlier itera-         and the subpattern to the right has participated in an  earlier  itera-
4482         tion.         tion.
4483    
4484         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
4485         subpattern  whose  number  is  10  or  more using this syntax because a         subpattern whose number is 10 or  more  using  this  syntax  because  a
4486         sequence such as \50 is interpreted as a character  defined  in  octal.         sequence  such  as  \50 is interpreted as a character defined in octal.
4487         See the subsection entitled "Non-printing characters" above for further         See the subsection entitled "Non-printing characters" above for further
4488         details of the handling of digits following a backslash.  There  is  no         details  of  the  handling of digits following a backslash. There is no
4489         such  problem  when named parentheses are used. A back reference to any         such problem when named parentheses are used. A back reference  to  any
4490         subpattern is possible using named parentheses (see below).         subpattern is possible using named parentheses (see below).
4491    
4492         Another way of avoiding the ambiguity inherent in  the  use  of  digits         Another  way  of  avoiding  the ambiguity inherent in the use of digits
4493         following a backslash is to use the \g escape sequence, which is a fea-         following a backslash is to use the \g escape sequence, which is a fea-
4494         ture introduced in Perl 5.10.  This  escape  must  be  followed  by  an         ture  introduced  in  Perl  5.10.  This  escape  must be followed by an
4495         unsigned  number  or  a negative number, optionally enclosed in braces.         unsigned number or a negative number, optionally  enclosed  in  braces.
4496         These examples are all identical:         These examples are all identical:
4497    
4498           (ring), \1           (ring), \1
4499           (ring), \g1           (ring), \g1
4500           (ring), \g{1}           (ring), \g{1}
4501    
4502         An unsigned number specifies an absolute reference without the  ambigu-         An  unsigned number specifies an absolute reference without the ambigu-
4503         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
4504         digits follow the reference. A negative number is a relative reference.         digits follow the reference. A negative number is a relative reference.
4505         Consider this example:         Consider this example:
# Line 4466  BACK REFERENCES Line 4507  BACK REFERENCES
4507           (abc(def)ghi)\g{-1}           (abc(def)ghi)\g{-1}
4508    
4509         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-
4510         ing subpattern before \g, that is, is it equivalent to  \2.  Similarly,         ing  subpattern  before \g, that is, is it equivalent to \2. Similarly,
4511         \g{-2} would be equivalent to \1. The use of relative references can be         \g{-2} would be equivalent to \1. The use of relative references can be
4512         helpful in long patterns, and also in  patterns  that  are  created  by         helpful  in  long  patterns,  and  also in patterns that are created by
4513         joining together fragments that contain references within themselves.         joining together fragments that contain references within themselves.
4514    
4515         A  back  reference matches whatever actually matched the capturing sub-         A back reference matches whatever actually matched the  capturing  sub-
4516         pattern in the current subject string, rather  than  anything  matching         pattern  in  the  current subject string, rather than anything matching
4517         the subpattern itself (see "Subpatterns as subroutines" below for a way         the subpattern itself (see "Subpatterns as subroutines" below for a way
4518         of doing that). So the pattern         of doing that). So the pattern
4519    
4520           (sens|respons)e and \1ibility           (sens|respons)e and \1ibility
4521    
4522         matches "sense and sensibility" and "response and responsibility",  but         matches  "sense and sensibility" and "response and responsibility", but
4523         not  "sense and responsibility". If caseful matching is in force at the         not "sense and responsibility". If caseful matching is in force at  the
4524         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-
4525         ple,         ple,
4526    
4527           ((?i)rah)\s+\1           ((?i)rah)\s+\1
4528    
4529         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
4530         original capturing subpattern is matched caselessly.         original capturing subpattern is matched caselessly.
4531    
4532         There are several different ways of writing back  references  to  named         There  are  several  different ways of writing back references to named
4533         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
4534         \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
4535         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
4536         and named references, is also supported. We  could  rewrite  the  above         and  named  references,  is  also supported. We could rewrite the above
4537         example in any of the following ways:         example in any of the following ways:
4538    
4539           (?<p1>(?i)rah)\s+\k<p1>           (?<p1>(?i)rah)\s+\k<p1>
# Line 4500  BACK REFERENCES Line 4541  BACK REFERENCES
4541           (?P<p1>(?i)rah)\s+(?P=p1)           (?P<p1>(?i)rah)\s+(?P=p1)
4542           (?<p1>(?i)rah)\s+\g{p1}           (?<p1>(?i)rah)\s+\g{p1}
4543    
4544         A  subpattern  that  is  referenced  by  name may appear in the pattern         A subpattern that is referenced by  name  may  appear  in  the  pattern
4545         before or after the reference.         before or after the reference.
4546    
4547         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
4548         subpattern  has  not actually been used in a particular match, any back         subpattern has not actually been used in a particular match,  any  back
4549         references to it always fail by default. For example, the pattern         references to it always fail by default. For example, the pattern
4550    
4551           (a|(bc))\2           (a|(bc))\2
4552    
4553         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
4554         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-
4555         ence to an unset value matches an empty string.         ence to an unset value matches an empty string.
4556    
4557         Because there may be many capturing parentheses in a pattern, all  dig-         Because  there may be many capturing parentheses in a pattern, all dig-
4558         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-
4559         ence number.  If the pattern continues with  a  digit  character,  some         ence  number.   If  the  pattern continues with a digit character, some
4560         delimiter  must  be  used  to  terminate  the  back  reference.  If the         delimiter must  be  used  to  terminate  the  back  reference.  If  the
4561         PCRE_EXTENDED option is set, this can be whitespace. Otherwise, the \g{         PCRE_EXTENDED option is set, this can be whitespace. Otherwise, the \g{
4562         syntax or an empty comment (see "Comments" below) can be used.         syntax or an empty comment (see "Comments" below) can be used.
4563    
4564     Recursive back references     Recursive back references
4565    
4566         A  back reference that occurs inside the parentheses to which it refers         A back reference that occurs inside the parentheses to which it  refers
4567         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
4568         matches.   However,  such references can be useful inside repeated sub-         matches.  However, such references can be useful inside  repeated  sub-
4569         patterns. For example, the pattern         patterns. For example, the pattern
4570    
4571           (a|b\1)+           (a|b\1)+
4572    
4573         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-
4574         ation  of  the  subpattern,  the  back  reference matches the character         ation of the subpattern,  the  back  reference  matches  the  character
4575         string corresponding to the previous iteration. In order  for  this  to         string  corresponding  to  the previous iteration. In order for this to
4576         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
4577         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
4578         the example above, or by a quantifier with a minimum of zero.         the example above, or by a quantifier with a minimum of zero.
4579    
4580         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
4581         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
4582         subsequent  matching  failure cannot cause backtracking into the middle         subsequent matching failure cannot cause backtracking into  the  middle
4583         of the group.         of the group.
4584    
4585    
4586  ASSERTIONS  ASSERTIONS
4587    
4588         An assertion is a test on the characters  following  or  preceding  the         An  assertion  is  a  test on the characters following or preceding the
4589         current  matching  point that does not actually consume any characters.         current matching point that does not actually consume  any  characters.
4590         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
4591         described above.         described above.
4592    
4593         More  complicated  assertions  are  coded as subpatterns. There are two         More complicated assertions are coded as  subpatterns.  There  are  two
4594         kinds: those that look ahead of the current  position  in  the  subject         kinds:  those  that  look  ahead of the current position in the subject
4595         string,  and  those  that  look  behind  it. An assertion subpattern is         string, and those that look  behind  it.  An  assertion  subpattern  is
4596         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
4597         matching position to be changed.         matching position to be changed.
4598    
4599         Assertion  subpatterns  are  not  capturing subpatterns, and may not be         Assertion subpatterns are not capturing subpatterns,  and  may  not  be
4600         repeated, because it makes no sense to assert the  same  thing  several         repeated,  because  it  makes no sense to assert the same thing several
4601         times.  If  any kind of assertion contains capturing subpatterns within         times. If any kind of assertion contains capturing  subpatterns  within
4602         it, these are counted for the purposes of numbering the capturing  sub-         it,  these are counted for the purposes of numbering the capturing sub-
4603         patterns in the whole pattern.  However, substring capturing is carried         patterns in the whole pattern.  However, substring capturing is carried
4604         out only for positive assertions, because it does not  make  sense  for         out  only  for  positive assertions, because it does not make sense for
4605         negative assertions.         negative assertions.
4606    
4607     Lookahead assertions     Lookahead assertions
# Line 4570  ASSERTIONS Line 4611  ASSERTIONS
4611    
4612           \w+(?=;)           \w+(?=;)
4613    
4614         matches a word followed by a semicolon, but does not include the  semi-         matches  a word followed by a semicolon, but does not include the semi-
4615         colon in the match, and         colon in the match, and
4616    
4617           foo(?!bar)           foo(?!bar)
4618    
4619         matches  any  occurrence  of  "foo" that is not followed by "bar". Note         matches any occurrence of "foo" that is not  followed  by  "bar".  Note
4620         that the apparently similar pattern         that the apparently similar pattern
4621    
4622           (?!foo)bar           (?!foo)bar
4623    
4624         does not find an occurrence of "bar"  that  is  preceded  by  something         does  not  find  an  occurrence  of "bar" that is preceded by something
4625         other  than "foo"; it finds any occurrence of "bar" whatsoever, because         other than "foo"; it finds any occurrence of "bar" whatsoever,  because
4626         the assertion (?!foo) is always true when the next three characters are         the assertion (?!foo) is always true when the next three characters are
4627         "bar". A lookbehind assertion is needed to achieve the other effect.         "bar". A lookbehind assertion is needed to achieve the other effect.
4628    
4629         If you want to force a matching failure at some point in a pattern, the         If you want to force a matching failure at some point in a pattern, the
4630         most convenient way to do it is  with  (?!)  because  an  empty  string         most  convenient  way  to  do  it  is with (?!) because an empty string
4631         always  matches, so an assertion that requires there not to be an empty         always matches, so an assertion that requires there not to be an  empty
4632         string must always fail.   The  Perl  5.10  backtracking  control  verb         string  must  always  fail.   The  Perl  5.10 backtracking control verb
4633         (*FAIL) or (*F) is essentially a synonym for (?!).         (*FAIL) or (*F) is essentially a synonym for (?!).
4634    
4635     Lookbehind assertions     Lookbehind assertions
4636    
4637         Lookbehind  assertions start with (?<= for positive assertions and (?<!         Lookbehind assertions start with (?<= for positive assertions and  (?<!
4638         for negative assertions. For example,         for negative assertions. For example,
4639    
4640           (?<!foo)bar           (?<!foo)bar
4641    
4642         does find an occurrence of "bar" that is not  preceded  by  "foo".  The         does  find  an  occurrence  of "bar" that is not preceded by "foo". The
4643         contents  of  a  lookbehind  assertion are restricted such that all the         contents of a lookbehind assertion are restricted  such  that  all  the
4644         strings it matches must have a fixed length. However, if there are sev-         strings it matches must have a fixed length. However, if there are sev-
4645         eral  top-level  alternatives,  they  do  not all have to have the same         eral top-level alternatives, they do not all  have  to  have  the  same
4646         fixed length. Thus         fixed length. Thus
4647    
4648           (?<=bullock|donkey)           (?<=bullock|donkey)
# Line 4610  ASSERTIONS Line 4651  ASSERTIONS
4651    
4652           (?<!dogs?|cats?)           (?<!dogs?|cats?)
4653    
4654         causes an error at compile time. Branches that match  different  length         causes  an  error at compile time. Branches that match different length
4655         strings  are permitted only at the top level of a lookbehind assertion.         strings are permitted only at the top level of a lookbehind  assertion.
4656         This is an extension compared with Perl (5.8 and 5.10), which  requires         This  is an extension compared with Perl (5.8 and 5.10), which requires
4657         all branches to match the same length of string. An assertion such as         all branches to match the same length of string. An assertion such as
4658    
4659           (?<=ab(c|de))           (?<=ab(c|de))
4660    
4661         is  not  permitted,  because  its single top-level branch can match two         is not permitted, because its single top-level  branch  can  match  two
4662         different lengths, but it is acceptable to PCRE if rewritten to use two         different lengths, but it is acceptable to PCRE if rewritten to use two
4663         top-level branches:         top-level branches:
4664    
4665           (?<=abc|abde)           (?<=abc|abde)
4666    
4667         In some cases, the Perl 5.10 escape sequence \K (see above) can be used         In some cases, the Perl 5.10 escape sequence \K (see above) can be used
4668         instead of  a  lookbehind  assertion  to  get  round  the  fixed-length         instead  of  a  lookbehind  assertion  to  get  round  the fixed-length
4669         restriction.         restriction.
4670    
4671         The  implementation  of lookbehind assertions is, for each alternative,         The implementation of lookbehind assertions is, for  each  alternative,
4672         to temporarily move the current position back by the fixed  length  and         to  temporarily  move the current position back by the fixed length and
4673         then try to match. If there are insufficient characters before the cur-         then try to match. If there are insufficient characters before the cur-
4674         rent position, the assertion fails.         rent position, the assertion fails.
4675    
4676         PCRE does not allow the \C escape (which matches a single byte in UTF-8         PCRE does not allow the \C escape (which matches a single byte in UTF-8
4677         mode)  to appear in lookbehind assertions, because it makes it impossi-         mode) to appear in lookbehind assertions, because it makes it  impossi-
4678         ble to calculate the length of the lookbehind. The \X and  \R  escapes,         ble  to  calculate the length of the lookbehind. The \X and \R escapes,
4679         which can match different numbers of bytes, are also not permitted.         which can match different numbers of bytes, are also not permitted.
4680    
4681         "Subroutine"  calls  (see below) such as (?2) or (?&X) are permitted in         "Subroutine" calls (see below) such as (?2) or (?&X) are  permitted  in
4682         lookbehinds, as long as the subpattern matches a  fixed-length  string.         lookbehinds,  as  long as the subpattern matches a fixed-length string.
4683         Recursion, however, is not supported.         Recursion, however, is not supported.
4684    
4685         Possessive  quantifiers  can  be  used  in  conjunction with lookbehind         Possessive quantifiers can  be  used  in  conjunction  with  lookbehind
4686         assertions to specify efficient matching of fixed-length strings at the         assertions to specify efficient matching of fixed-length strings at the
4687         end of subject strings. Consider a simple pattern such as         end of subject strings. Consider a simple pattern such as
4688    
4689           abcd$           abcd$
4690    
4691         when  applied  to  a  long string that does not match. Because matching         when applied to a long string that does  not  match.  Because  matching
4692         proceeds from left to right, PCRE will look for each "a" in the subject         proceeds from left to right, PCRE will look for each "a" in the subject
4693         and  then  see  if what follows matches the rest of the pattern. If the         and then see if what follows matches the rest of the  pattern.  If  the
4694         pattern is specified as         pattern is specified as
4695    
4696           ^.*abcd$           ^.*abcd$
4697    
4698         the initial .* matches the entire string at first, but when this  fails         the  initial .* matches the entire string at first, but when this fails
4699         (because there is no following "a"), it backtracks to match all but the         (because there is no following "a"), it backtracks to match all but the
4700         last character, then all but the last two characters, and so  on.  Once         last  character,  then all but the last two characters, and so on. Once
4701         again  the search for "a" covers the entire string, from right to left,         again the search for "a" covers the entire string, from right to  left,
4702         so we are no better off. However, if the pattern is written as         so we are no better off. However, if the pattern is written as
4703    
4704           ^.*+(?<=abcd)           ^.*+(?<=abcd)
4705    
4706         there can be no backtracking for the .*+ item; it can  match  only  the         there  can  be  no backtracking for the .*+ item; it can match only the
4707         entire  string.  The subsequent lookbehind assertion does a single test         entire string. The subsequent lookbehind assertion does a  single  test
4708         on the last four characters. If it fails, the match fails  immediately.         on  the last four characters. If it fails, the match fails immediately.
4709         For  long  strings, this approach makes a significant difference to the         For long strings, this approach makes a significant difference  to  the
4710         processing time.         processing time.
4711    
4712     Using multiple assertions     Using multiple assertions
# Line 4674  ASSERTIONS Line 4715  ASSERTIONS
4715    
4716           (?<=\d{3})(?<!999)foo           (?<=\d{3})(?<!999)foo
4717    
4718         matches "foo" preceded by three digits that are not "999". Notice  that         matches  "foo" preceded by three digits that are not "999". Notice that
4719         each  of  the  assertions is applied independently at the same point in         each of the assertions is applied independently at the  same  point  in
4720         the subject string. First there is a  check  that  the  previous  three         the  subject  string.  First  there  is a check that the previous three
4721         characters  are  all  digits,  and  then there is a check that the same         characters are all digits, and then there is  a  check  that  the  same
4722         three characters are not "999".  This pattern does not match "foo" pre-         three characters are not "999".  This pattern does not match "foo" pre-
4723         ceded  by  six  characters,  the first of which are digits and the last         ceded by six characters, the first of which are  digits  and  the  last
4724         three of which are not "999". For example, it  doesn't  match  "123abc-         three  of  which  are not "999". For example, it doesn't match "123abc-
4725         foo". A pattern to do that is         foo". A pattern to do that is
4726    
4727           (?<=\d{3}...)(?<!999)foo           (?<=\d{3}...)(?<!999)foo
4728    
4729         This  time  the  first assertion looks at the preceding six characters,         This time the first assertion looks at the  preceding  six  characters,
4730         checking that the first three are digits, and then the second assertion         checking that the first three are digits, and then the second assertion
4731         checks that the preceding three characters are not "999".         checks that the preceding three characters are not "999".
4732    
# Line 4693  ASSERTIONS Line 4734  ASSERTIONS
4734    
4735           (?<=(?<!foo)bar)baz           (?<=(?<!foo)bar)baz
4736    
4737         matches  an occurrence of "baz" that is preceded by "bar" which in turn         matches an occurrence of "baz" that is preceded by "bar" which in  turn
4738         is not preceded by "foo", while         is not preceded by "foo", while
4739    
4740           (?<=\d{3}(?!999)...)foo           (?<=\d{3}(?!999)...)foo
4741    
4742         is another pattern that matches "foo" preceded by three digits and  any         is  another pattern that matches "foo" preceded by three digits and any
4743         three characters that are not "999".         three characters that are not "999".
4744    
4745    
4746  CONDITIONAL SUBPATTERNS  CONDITIONAL SUBPATTERNS
4747    
4748         It  is possible to cause the matching process to obey a subpattern con-         It is possible to cause the matching process to obey a subpattern  con-
4749         ditionally or to choose between two alternative subpatterns,  depending         ditionally  or to choose between two alternative subpatterns, depending
4750         on  the result of an assertion, or whether a specific capturing subpat-         on the result of an assertion, or whether a specific capturing  subpat-
4751         tern has already been matched. The two possible  forms  of  conditional         tern  has  already  been matched. The two possible forms of conditional
4752         subpattern are:         subpattern are:
4753    
4754           (?(condition)yes-pattern)           (?(condition)yes-pattern)
4755           (?(condition)yes-pattern|no-pattern)           (?(condition)yes-pattern|no-pattern)
4756    
4757         If  the  condition is satisfied, the yes-pattern is used; otherwise the         If the condition is satisfied, the yes-pattern is used;  otherwise  the
4758         no-pattern (if present) is used. If there are more  than  two  alterna-         no-pattern  (if  present)  is used. If there are more than two alterna-
4759         tives in the subpattern, a compile-time error occurs.         tives in the subpattern, a compile-time error occurs.
4760    
4761         There  are  four  kinds of condition: references to subpatterns, refer-         There are four kinds of condition: references  to  subpatterns,  refer-
4762         ences to recursion, a pseudo-condition called DEFINE, and assertions.         ences to recursion, a pseudo-condition called DEFINE, and assertions.
4763    
4764     Checking for a used subpattern by number     Checking for a used subpattern by number
4765    
4766         If the text between the parentheses consists of a sequence  of  digits,         If  the  text between the parentheses consists of a sequence of digits,
4767         the condition is true if a capturing subpattern of that number has pre-         the condition is true if a capturing subpattern of that number has pre-
4768         viously matched. If there is more than one  capturing  subpattern  with         viously  matched.  If  there is more than one capturing subpattern with
4769         the  same  number  (see  the earlier section about duplicate subpattern         the same number (see the earlier  section  about  duplicate  subpattern
4770         numbers), the condition is true if any of them have been set. An alter-         numbers), the condition is true if any of them have been set. An alter-
4771         native  notation is to precede the digits with a plus or minus sign. In         native notation is to precede the digits with a plus or minus sign.  In
4772         this case, the subpattern number is relative rather than absolute.  The         this  case, the subpattern number is relative rather than absolute. The
4773         most  recently opened parentheses can be referenced by (?(-1), the next         most recently opened parentheses can be referenced by (?(-1), the  next
4774         most recent by (?(-2), and so on. In looping  constructs  it  can  also<