/[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 507 by ph10, Wed Mar 10 16:08:01 2010 UTC revision 548 by ph10, Fri Jun 25 14:42:00 2010 UTC
# 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    
# Line 902  PCRE API OVERVIEW Line 906  PCRE API OVERVIEW
906         bers for the library.  Applications can use these  to  include  support         bers for the library.  Applications can use these  to  include  support
907         for different releases of PCRE.         for different releases of PCRE.
908    
909           In a Windows environment, if you want to statically link an application
910           program against a non-dll pcre.a  file,  you  must  define  PCRE_STATIC
911           before  including  pcre.h or pcrecpp.h, because otherwise the pcre_mal-
912           loc()   and   pcre_free()   exported   functions   will   be   declared
913           __declspec(dllimport), with unwanted results.
914    
915         The   functions   pcre_compile(),  pcre_compile2(),  pcre_study(),  and         The   functions   pcre_compile(),  pcre_compile2(),  pcre_study(),  and
916         pcre_exec() are used for compiling and matching regular expressions  in         pcre_exec() are used for compiling and matching regular expressions  in
917         a  Perl-compatible  manner. A sample program that demonstrates the sim-         a  Perl-compatible  manner. A sample program that demonstrates the sim-
# Line 1281  COMPILING A PATTERN Line 1291  COMPILING A PATTERN
1291         letter that has no special meaning  causes  an  error,  thus  reserving         letter that has no special meaning  causes  an  error,  thus  reserving
1292         these  combinations  for  future  expansion.  By default, as in Perl, a         these  combinations  for  future  expansion.  By default, as in Perl, a
1293         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
1294         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
1295         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
1296         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
1297           within a pattern.
1298    
1299           PCRE_FIRSTLINE           PCRE_FIRSTLINE
1300    
1301         If  this  option  is  set,  an  unanchored pattern is required to match         If this option is set, an  unanchored  pattern  is  required  to  match
1302         before or at the first  newline  in  the  subject  string,  though  the         before  or  at  the  first  newline  in  the subject string, though the
1303         matched text may continue over the newline.         matched text may continue over the newline.
1304    
1305           PCRE_JAVASCRIPT_COMPAT           PCRE_JAVASCRIPT_COMPAT
1306    
1307         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
1308         it is compatible with JavaScript rather than Perl. The changes  are  as         it  is  compatible with JavaScript rather than Perl. The changes are as
1309         follows:         follows:
1310    
1311         (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
1312         error, because this is illegal in JavaScript (by default it is  treated         error,  because this is illegal in JavaScript (by default it is treated
1313         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
1314         option is set.         option is set.
1315    
1316         (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
1317         an  empty  string (by default this causes the current matching alterna-         an empty string (by default this causes the current  matching  alterna-
1318         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
1319         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
1320         default, for Perl compatibility.         default, for Perl compatibility.
1321    
1322           PCRE_MULTILINE           PCRE_MULTILINE
1323    
1324         By default, PCRE treats the subject string as consisting  of  a  single         By  default,  PCRE  treats the subject string as consisting of a single
1325         line  of characters (even if it actually contains newlines). The "start         line of characters (even if it actually contains newlines). The  "start
1326         of line" metacharacter (^) matches only at the  start  of  the  string,         of  line"  metacharacter  (^)  matches only at the start of the string,
1327         while  the  "end  of line" metacharacter ($) matches only at the end of         while the "end of line" metacharacter ($) matches only at  the  end  of
1328         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY
1329         is set). This is the same as Perl.         is set). This is the same as Perl.
1330    
1331         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"
1332         constructs match immediately following or immediately  before  internal         constructs  match  immediately following or immediately before internal
1333         newlines  in  the  subject string, respectively, as well as at the very         newlines in the subject string, respectively, as well as  at  the  very
1334         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
1335         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-
1336         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,
1337         setting PCRE_MULTILINE has no effect.         setting PCRE_MULTILINE has no effect.
1338    
1339           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
# Line 1331  COMPILING A PATTERN Line 1342  COMPILING A PATTERN
1342           PCRE_NEWLINE_ANYCRLF           PCRE_NEWLINE_ANYCRLF
1343           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
1344    
1345         These  options  override the default newline definition that was chosen         These options override the default newline definition that  was  chosen
1346         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
1347         newline  is  indicated  by a single character (CR or LF, respectively).         newline is indicated by a single character (CR  or  LF,  respectively).
1348         Setting PCRE_NEWLINE_CRLF specifies that a newline is indicated by  the         Setting  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the
1349         two-character  CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF specifies         two-character CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF  specifies
1350         that any of the three preceding sequences should be recognized. Setting         that any of the three preceding sequences should be recognized. Setting
1351         PCRE_NEWLINE_ANY  specifies that any Unicode newline sequence should be         PCRE_NEWLINE_ANY specifies that any Unicode newline sequence should  be
1352         recognized. The Unicode newline sequences are the three just mentioned,         recognized. The Unicode newline sequences are the three just mentioned,
1353         plus  the  single  characters  VT (vertical tab, U+000B), FF (formfeed,         plus the single characters VT (vertical  tab,  U+000B),  FF  (formfeed,
1354         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
1355         (paragraph  separator,  U+2029).  The  last  two are recognized only in         (paragraph separator, U+2029). The last  two  are  recognized  only  in
1356         UTF-8 mode.         UTF-8 mode.
1357    
1358         The newline setting in the  options  word  uses  three  bits  that  are         The  newline  setting  in  the  options  word  uses three bits that are
1359         treated as a number, giving eight possibilities. Currently only six are         treated as a number, giving eight possibilities. Currently only six are
1360         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
1361         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-
1362         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
1363         PCRE_NEWLINE_CRLF,  but other combinations may yield unused numbers and         PCRE_NEWLINE_CRLF, but other combinations may yield unused numbers  and
1364         cause an error.         cause an error.
1365    
1366         The only time that a line break is specially recognized when  compiling         The  only time that a line break is specially recognized when compiling
1367         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
1368         character class is encountered. This indicates  a  comment  that  lasts         character  class  is  encountered.  This indicates a comment that lasts
1369         until  after the next line break sequence. In other circumstances, line         until after the next line break sequence. In other circumstances,  line
1370         break  sequences  are  treated  as  literal  data,   except   that   in         break   sequences   are   treated  as  literal  data,  except  that  in
1371         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters
1372         and are therefore ignored.         and are therefore ignored.
1373    
# Line 1366  COMPILING A PATTERN Line 1377  COMPILING A PATTERN
1377           PCRE_NO_AUTO_CAPTURE           PCRE_NO_AUTO_CAPTURE
1378    
1379         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-
1380         theses in the pattern. Any opening parenthesis that is not followed  by         theses  in the pattern. Any opening parenthesis that is not followed by
1381         ?  behaves as if it were followed by ?: but named parentheses can still         ? behaves as if it were followed by ?: but named parentheses can  still
1382         be used for capturing (and they acquire  numbers  in  the  usual  way).         be  used  for  capturing  (and  they acquire numbers in the usual way).
1383         There is no equivalent of this option in Perl.         There is no equivalent of this option in Perl.
1384    
1385             PCRE_UCP
1386    
1387           This option changes the way PCRE processes \b, \d, \s, \w, and some  of
1388           the POSIX character classes. By default, only ASCII characters are rec-
1389           ognized, but if PCRE_UCP is set, Unicode properties are used instead to
1390           classify  characters.  More details are given in the section on generic
1391           character types in the pcrepattern page. If you set PCRE_UCP,  matching
1392           one  of the items it affects takes much longer. The option is available
1393           only if PCRE has been compiled with Unicode property support.
1394    
1395           PCRE_UNGREEDY           PCRE_UNGREEDY
1396    
1397         This  option  inverts  the "greediness" of the quantifiers so that they         This option inverts the "greediness" of the quantifiers  so  that  they
1398         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
1399         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
1400         within the pattern.         within the pattern.
1401    
1402           PCRE_UTF8           PCRE_UTF8
1403    
1404         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
1405         strings  of  UTF-8 characters instead of single-byte character strings.         strings of UTF-8 characters instead of single-byte  character  strings.
1406         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-
1407         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
1408         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
1409         UTF-8 support in the main pcre page.         UTF-8 support in the main pcre page.
1410    
1411           PCRE_NO_UTF8_CHECK           PCRE_NO_UTF8_CHECK
1412    
1413         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
1414         automatically checked. There is a  discussion  about  the  validity  of         automatically  checked.  There  is  a  discussion about the validity of
1415         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
1416         bytes is found, pcre_compile() returns an error. If  you  already  know         bytes  is  found,  pcre_compile() returns an error. If you already know
1417         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-
1418         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
1419         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
1420         undefined. It may cause your program to crash. Note  that  this  option         undefined.  It  may  cause your program to crash. Note that this option
1421         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
1422         UTF-8 validity checking of subject strings.         UTF-8 validity checking of subject strings.
1423    
1424    
1425  COMPILATION ERROR CODES  COMPILATION ERROR CODES
1426    
1427         The following table lists the error  codes  than  may  be  returned  by         The  following  table  lists  the  error  codes than may be returned by
1428         pcre_compile2(),  along with the error messages that may be returned by         pcre_compile2(), along with the error messages that may be returned  by
1429         both compiling functions. As PCRE has developed, some error codes  have         both  compiling functions. As PCRE has developed, some error codes have
1430         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.
1431    
1432            0  no error            0  no error
# Line 1461  COMPILATION ERROR CODES Line 1482  COMPILATION ERROR CODES
1482           50  [this code is not in use]           50  [this code is not in use]
1483           51  octal value is greater than \377 (not in UTF-8 mode)           51  octal value is greater than \377 (not in UTF-8 mode)
1484           52  internal error: overran compiling workspace           52  internal error: overran compiling workspace
1485           53   internal  error:  previously-checked  referenced  subpattern not           53  internal error: previously-checked referenced subpattern
1486         found                 not found
1487           54  DEFINE group contains more than one branch           54  DEFINE group contains more than one branch
1488           55  repeating a DEFINE group is not allowed           55  repeating a DEFINE group is not allowed
1489           56  inconsistent NEWLINE options           56  inconsistent NEWLINE options
1490           57  \g is not followed by a braced, angle-bracketed, or quoted           57  \g is not followed by a braced, angle-bracketed, or quoted
1491                 name/number or by a plain number                 name/number or by a plain number
1492           58  a numbered reference must not be zero           58  a numbered reference must not be zero
1493           59  (*VERB) with an argument is not supported           59  an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)
1494           60  (*VERB) not recognized           60  (*VERB) not recognized
1495           61  number is too big           61  number is too big
1496           62  subpattern name expected           62  subpattern name expected
1497           63  digit expected after (?+           63  digit expected after (?+
1498           64  ] is an invalid data character in JavaScript compatibility mode           64  ] is an invalid data character in JavaScript compatibility mode
1499             65  different names for subpatterns of the same number are
1500                   not allowed
1501             66  (*MARK) must have an argument
1502             67  this version of PCRE is not compiled with PCRE_UCP support
1503    
1504         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
1505         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.
# Line 1534  STUDYING A PATTERN Line 1559  STUDYING A PATTERN
1559         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
1560         which to start matching.         which to start matching.
1561    
1562           The two optimizations just described can be  disabled  by  setting  the
1563           PCRE_NO_START_OPTIMIZE    option    when    calling    pcre_exec()   or
1564           pcre_dfa_exec(). You might want to do this  if  your  pattern  contains
1565           callouts,  or  make  use of (*MARK), and you make use of these in cases
1566           where matching fails.  See  the  discussion  of  PCRE_NO_START_OPTIMIZE
1567           below.
1568    
1569    
1570  LOCALE SUPPORT  LOCALE SUPPORT
1571    
1572         PCRE handles caseless matching, and determines whether  characters  are         PCRE  handles  caseless matching, and determines whether characters are
1573         letters,  digits, or whatever, by reference to a set of tables, indexed         letters, digits, or whatever, by reference to a set of tables,  indexed
1574         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
1575         characters  with  codes  less than 128. Higher-valued codes never match         characters with codes less than 128. By  default,  higher-valued  codes
1576         escapes such as \w or \d, but can be tested with \p if  PCRE  is  built         never match escapes such as \w or \d, but they can be tested with \p if
1577         with  Unicode  character property support. The use of locales with Uni-         PCRE is built with Unicode character property  support.  Alternatively,
1578         code is discouraged. If you are handling characters with codes  greater         the  PCRE_UCP  option  can  be  set at compile time; this causes \w and
1579         than  128, you should either use UTF-8 and Unicode, or use locales, but         friends to use Unicode property support instead of built-in tables. The
1580         not try to mix the two.         use of locales with Unicode is discouraged. If you are handling charac-
1581           ters with codes greater than 128, you should either use UTF-8 and  Uni-
1582           code, or use locales, but not try to mix the two.
1583    
1584         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
1585         argument  of  pcre_compile()  is  NULL.  These  are sufficient for many         argument of pcre_compile() is  NULL.  These  are  sufficient  for  many
1586         applications.  Normally, the internal tables recognize only ASCII char-         applications.  Normally, the internal tables recognize only ASCII char-
1587         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-
1588         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,
1589         which may cause them to be different.         which may cause them to be different.
1590    
1591         The  internal tables can always be overridden by tables supplied by the         The internal tables can always be overridden by tables supplied by  the
1592         application that calls PCRE. These may be created in a different locale         application that calls PCRE. These may be created in a different locale
1593         from  the  default.  As more and more applications change to using Uni-         from the default. As more and more applications change  to  using  Uni-
1594         code, the need for this locale support is expected to die away.         code, the need for this locale support is expected to die away.
1595    
1596         External tables are built by calling  the  pcre_maketables()  function,         External  tables  are  built by calling the pcre_maketables() function,
1597         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
1598         passed to pcre_compile() or pcre_exec()  as  often  as  necessary.  For         passed  to  pcre_compile()  or  pcre_exec()  as often as necessary. For
1599         example,  to  build  and use tables that are appropriate for the French         example, to build and use tables that are appropriate  for  the  French
1600         locale (where accented characters with  values  greater  than  128  are         locale  (where  accented  characters  with  values greater than 128 are
1601         treated as letters), the following code could be used:         treated as letters), the following code could be used:
1602    
1603           setlocale(LC_CTYPE, "fr_FR");           setlocale(LC_CTYPE, "fr_FR");
1604           tables = pcre_maketables();           tables = pcre_maketables();
1605           re = pcre_compile(..., tables);           re = pcre_compile(..., tables);
1606    
1607         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;
1608         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".
1609    
1610         When pcre_maketables() runs, the tables are built  in  memory  that  is         When  pcre_maketables()  runs,  the  tables are built in memory that is
1611         obtained  via  pcre_malloc. It is the caller's responsibility to ensure         obtained via pcre_malloc. It is the caller's responsibility  to  ensure
1612         that the memory containing the tables remains available for as long  as         that  the memory containing the tables remains available for as long as
1613         it is needed.         it is needed.
1614    
1615         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
1616         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()
1617         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-
1618         tern, compilation, studying and matching all happen in the same locale,         tern, compilation, studying and matching all happen in the same locale,
1619         but different patterns can be compiled in different locales.         but different patterns can be compiled in different locales.
1620    
1621         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
1622         the internal tables) to pcre_exec(). Although  not  intended  for  this         the  internal  tables)  to  pcre_exec(). Although not intended for this
1623         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
1624         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
1625         run time is discussed below in the section on matching a pattern.         run time is discussed below in the section on matching a pattern.
1626    
# Line 1596  INFORMATION ABOUT A PATTERN Line 1630  INFORMATION ABOUT A PATTERN
1630         int pcre_fullinfo(const pcre *code, const pcre_extra *extra,         int pcre_fullinfo(const pcre *code, const pcre_extra *extra,
1631              int what, void *where);              int what, void *where);
1632    
1633         The  pcre_fullinfo() function returns information about a compiled pat-         The pcre_fullinfo() function returns information about a compiled  pat-
1634         tern. It replaces the obsolete pcre_info() function, which is neverthe-         tern. It replaces the obsolete pcre_info() function, which is neverthe-
1635         less retained for backwards compability (and is documented below).         less retained for backwards compability (and is documented below).
1636    
1637         The  first  argument  for  pcre_fullinfo() is a pointer to the compiled         The first argument for pcre_fullinfo() is a  pointer  to  the  compiled
1638         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
1639         the  pattern  was not studied. The third argument specifies which piece         the pattern was not studied. The third argument specifies  which  piece
1640         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
1641         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
1642         success, or one of the following negative numbers:         success, or one of the following negative numbers:
1643    
1644           PCRE_ERROR_NULL       the argument code was NULL           PCRE_ERROR_NULL       the argument code was NULL
# Line 1612  INFORMATION ABOUT A PATTERN Line 1646  INFORMATION ABOUT A PATTERN
1646           PCRE_ERROR_BADMAGIC   the "magic number" was not found           PCRE_ERROR_BADMAGIC   the "magic number" was not found
1647           PCRE_ERROR_BADOPTION  the value of what was invalid           PCRE_ERROR_BADOPTION  the value of what was invalid
1648    
1649         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
1650         an  simple check against passing an arbitrary memory pointer. Here is a         an simple check against passing an arbitrary memory pointer. Here is  a
1651         typical call of pcre_fullinfo(), to obtain the length of  the  compiled         typical  call  of pcre_fullinfo(), to obtain the length of the compiled
1652         pattern:         pattern:
1653    
1654           int rc;           int rc;
# Line 1625  INFORMATION ABOUT A PATTERN Line 1659  INFORMATION ABOUT A PATTERN
1659             PCRE_INFO_SIZE,   /* what is required */             PCRE_INFO_SIZE,   /* what is required */
1660             &length);         /* where to put the data */             &length);         /* where to put the data */
1661    
1662         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
1663         are as follows:         are as follows:
1664    
1665           PCRE_INFO_BACKREFMAX           PCRE_INFO_BACKREFMAX
1666    
1667         Return the number of the highest back reference  in  the  pattern.  The         Return  the  number  of  the highest back reference in the pattern. The
1668         fourth  argument  should  point to an int variable. Zero is returned if         fourth argument should point to an int variable. Zero  is  returned  if
1669         there are no back references.         there are no back references.
1670    
1671           PCRE_INFO_CAPTURECOUNT           PCRE_INFO_CAPTURECOUNT
1672    
1673         Return the number of capturing subpatterns in the pattern.  The  fourth         Return  the  number of capturing subpatterns in the pattern. The fourth
1674         argument should point to an int variable.         argument should point to an int variable.
1675    
1676           PCRE_INFO_DEFAULT_TABLES           PCRE_INFO_DEFAULT_TABLES
1677    
1678         Return  a pointer to the internal default character tables within PCRE.         Return a pointer to the internal default character tables within  PCRE.
1679         The fourth argument should point to an unsigned char *  variable.  This         The  fourth  argument should point to an unsigned char * variable. This
1680         information call is provided for internal use by the pcre_study() func-         information call is provided for internal use by the pcre_study() func-
1681         tion. External callers can cause PCRE to use  its  internal  tables  by         tion.  External  callers  can  cause PCRE to use its internal tables by
1682         passing a NULL table pointer.         passing a NULL table pointer.
1683    
1684           PCRE_INFO_FIRSTBYTE           PCRE_INFO_FIRSTBYTE
1685    
1686         Return  information  about  the first byte of any matched string, for a         Return information about the first byte of any matched  string,  for  a
1687         non-anchored pattern. The fourth argument should point to an int  vari-         non-anchored  pattern. The fourth argument should point to an int vari-
1688         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
1689         is still recognized for backwards compatibility.)         is still recognized for backwards compatibility.)
1690    
1691         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
1692         (cat|cow|coyote), its value is returned. Otherwise, if either         (cat|cow|coyote), its value is returned. Otherwise, if either
1693    
1694         (a)  the pattern was compiled with the PCRE_MULTILINE option, and every         (a) the pattern was compiled with the PCRE_MULTILINE option, and  every
1695         branch starts with "^", or         branch starts with "^", or
1696    
1697         (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
1698         set (if it were set, the pattern would be anchored),         set (if it were set, the pattern would be anchored),
1699    
1700         -1  is  returned, indicating that the pattern matches only at the start         -1 is returned, indicating that the pattern matches only at  the  start
1701         of a subject string or after any newline within the  string.  Otherwise         of  a  subject string or after any newline within the string. Otherwise
1702         -2 is returned. For anchored patterns, -2 is returned.         -2 is returned. For anchored patterns, -2 is returned.
1703    
1704           PCRE_INFO_FIRSTTABLE           PCRE_INFO_FIRSTTABLE
1705    
1706         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
1707         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
1708         matching  string, a pointer to the table is returned. Otherwise NULL is         matching string, a pointer to the table is returned. Otherwise NULL  is
1709         returned. The fourth argument should point to an unsigned char *  vari-         returned.  The fourth argument should point to an unsigned char * vari-
1710         able.         able.
1711    
1712           PCRE_INFO_HASCRORLF           PCRE_INFO_HASCRORLF
1713    
1714         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
1715         characters, otherwise 0. The fourth argument should  point  to  an  int         characters,  otherwise  0.  The  fourth argument should point to an int
1716         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
1717         \r or \n.         \r or \n.
1718    
1719           PCRE_INFO_JCHANGED           PCRE_INFO_JCHANGED
1720    
1721         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,
1722         otherwise  0. The fourth argument should point to an int variable. (?J)         otherwise 0. The fourth argument should point to an int variable.  (?J)
1723         and (?-J) set and unset the local PCRE_DUPNAMES option, respectively.         and (?-J) set and unset the local PCRE_DUPNAMES option, respectively.
1724    
1725           PCRE_INFO_LASTLITERAL           PCRE_INFO_LASTLITERAL
1726    
1727         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
1728         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
1729         recorded. The fourth argument should point to an int variable. If there         recorded. The fourth argument should point to an int variable. If there
1730         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
1731         byte is recorded only if it follows something of variable  length.  For         byte  is  recorded only if it follows something of variable length. For
1732         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
1733         /^a\dz\d/ the returned value is -1.         /^a\dz\d/ the returned value is -1.
1734    
1735           PCRE_INFO_MINLENGTH           PCRE_INFO_MINLENGTH
1736    
1737         If the pattern was studied and a minimum length  for  matching  subject         If  the  pattern  was studied and a minimum length for matching subject
1738         strings  was  computed,  its  value is returned. Otherwise the returned         strings was computed, its value is  returned.  Otherwise  the  returned
1739         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
1740         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
1741         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
1742         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
1743         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.
1744    
1745           PCRE_INFO_NAMECOUNT           PCRE_INFO_NAMECOUNT
1746           PCRE_INFO_NAMEENTRYSIZE           PCRE_INFO_NAMEENTRYSIZE
1747           PCRE_INFO_NAMETABLE           PCRE_INFO_NAMETABLE
1748    
1749         PCRE supports the use of named as well as numbered capturing  parenthe-         PCRE  supports the use of named as well as numbered capturing parenthe-
1750         ses.  The names are just an additional way of identifying the parenthe-         ses. The names are just an additional way of identifying the  parenthe-
1751         ses, which still acquire numbers. Several convenience functions such as         ses, which still acquire numbers. Several convenience functions such as
1752         pcre_get_named_substring()  are  provided  for extracting captured sub-         pcre_get_named_substring() are provided for  extracting  captured  sub-
1753         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
1754         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
1755         pointers in the output vector (described with pcre_exec() below). To do         pointers in the output vector (described with pcre_exec() below). To do
1756         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
1757         described by these three values.         described by these three values.
1758    
1759         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
1760         gives the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size         gives the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size
1761         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
1762         depends  on the length of the longest name. PCRE_INFO_NAMETABLE returns         depends on the length of the longest name. PCRE_INFO_NAMETABLE  returns
1763         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
1764         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-
1765         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-
1766         sponding name, zero terminated.         sponding name, zero terminated.
1767    
1768         The  names are in alphabetical order. Duplicate names may appear if (?|         The names are in alphabetical order. Duplicate names may appear if  (?|
1769         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
1770         the  section  on  duplicate subpattern numbers in the pcrepattern page.         the section on duplicate subpattern numbers in  the  pcrepattern  page.
1771         Duplicate names for subpatterns with different  numbers  are  permitted         Duplicate  names  for  subpatterns with different numbers are permitted
1772         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
1773         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-
1774         tern.  In  the  absence  of (?| this is the order of increasing number;         tern. In the absence of (?| this is the  order  of  increasing  number;
1775         when (?| is used this is not necessarily the case because later subpat-         when (?| is used this is not necessarily the case because later subpat-
1776         terns may have lower numbers.         terns may have lower numbers.
1777    
1778         As  a  simple  example of the name/number table, consider the following         As a simple example of the name/number table,  consider  the  following
1779         pattern (assume PCRE_EXTENDED is set, so white space -  including  new-         pattern  (assume  PCRE_EXTENDED is set, so white space - including new-
1780         lines - is ignored):         lines - is ignored):
1781    
1782           (?<date> (?<year>(\d\d)?\d\d) -           (?<date> (?<year>(\d\d)?\d\d) -
1783           (?<month>\d\d) - (?<day>\d\d) )           (?<month>\d\d) - (?<day>\d\d) )
1784    
1785         There  are  four  named subpatterns, so the table has four entries, and         There are four named subpatterns, so the table has  four  entries,  and
1786         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,
1787         with non-printing bytes shows in hexadecimal, and undefined bytes shown         with non-printing bytes shows in hexadecimal, and undefined bytes shown
1788         as ??:         as ??:
1789    
# Line 1758  INFORMATION ABOUT A PATTERN Line 1792  INFORMATION ABOUT A PATTERN
1792           00 04 m  o  n  t  h  00           00 04 m  o  n  t  h  00
1793           00 02 y  e  a  r  00 ??           00 02 y  e  a  r  00 ??
1794    
1795         When writing code to extract data  from  named  subpatterns  using  the         When  writing  code  to  extract  data from named subpatterns using the
1796         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
1797         to be different for each compiled pattern.         to be different for each compiled pattern.
1798    
1799           PCRE_INFO_OKPARTIAL           PCRE_INFO_OKPARTIAL
1800    
1801         Return 1  if  the  pattern  can  be  used  for  partial  matching  with         Return  1  if  the  pattern  can  be  used  for  partial  matching with
1802         pcre_exec(),  otherwise  0.  The fourth argument should point to an int         pcre_exec(), otherwise 0. The fourth argument should point  to  an  int
1803         variable. From  release  8.00,  this  always  returns  1,  because  the         variable.  From  release  8.00,  this  always  returns  1,  because the
1804         restrictions  that  previously  applied  to  partial matching have been         restrictions that previously applied  to  partial  matching  have  been
1805         lifted. The pcrepartial documentation gives details of  partial  match-         lifted.  The  pcrepartial documentation gives details of partial match-
1806         ing.         ing.
1807    
1808           PCRE_INFO_OPTIONS           PCRE_INFO_OPTIONS
1809    
1810         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
1811         fourth argument should point to an unsigned long  int  variable.  These         fourth  argument  should  point to an unsigned long int variable. These
1812         option bits are those specified in the call to pcre_compile(), modified         option bits are those specified in the call to pcre_compile(), modified
1813         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
1814         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
1815         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
1816         the  PCRE_EXTENDED option, the result is PCRE_CASELESS, PCRE_MULTILINE,         the PCRE_EXTENDED option, the result is PCRE_CASELESS,  PCRE_MULTILINE,
1817         and PCRE_EXTENDED.         and PCRE_EXTENDED.
1818    
1819         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
1820         alternatives begin with one of the following:         alternatives begin with one of the following:
1821    
1822           ^     unless PCRE_MULTILINE is set           ^     unless PCRE_MULTILINE is set
# Line 1796  INFORMATION ABOUT A PATTERN Line 1830  INFORMATION ABOUT A PATTERN
1830    
1831           PCRE_INFO_SIZE           PCRE_INFO_SIZE
1832    
1833         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
1834         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
1835         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
1836         size_t variable.         size_t variable.
# Line 1804  INFORMATION ABOUT A PATTERN Line 1838  INFORMATION ABOUT A PATTERN
1838           PCRE_INFO_STUDYSIZE           PCRE_INFO_STUDYSIZE
1839    
1840         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
1841         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
1842         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
1843         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
1844         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
1845         variable.         variable.
1846    
1847    
# Line 1815  OBSOLETE INFO FUNCTION Line 1849  OBSOLETE INFO FUNCTION
1849    
1850         int pcre_info(const pcre *code, int *optptr, int *firstcharptr);         int pcre_info(const pcre *code, int *optptr, int *firstcharptr);
1851    
1852         The pcre_info() function is now obsolete because its interface  is  too         The  pcre_info()  function is now obsolete because its interface is too
1853         restrictive  to return all the available data about a compiled pattern.         restrictive to return all the available data about a compiled  pattern.
1854         New  programs  should  use  pcre_fullinfo()  instead.  The   yield   of         New   programs   should  use  pcre_fullinfo()  instead.  The  yield  of
1855         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-
1856         lowing negative numbers:         lowing negative numbers:
1857    
1858           PCRE_ERROR_NULL       the argument code was NULL           PCRE_ERROR_NULL       the argument code was NULL
1859           PCRE_ERROR_BADMAGIC   the "magic number" was not found           PCRE_ERROR_BADMAGIC   the "magic number" was not found
1860    
1861         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
1862         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
1863         PCRE_INFO_OPTIONS above).         PCRE_INFO_OPTIONS above).
1864    
1865         If the pattern is not anchored and the  firstcharptr  argument  is  not         If  the  pattern  is  not anchored and the firstcharptr argument is not
1866         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
1867         any matched string (see PCRE_INFO_FIRSTBYTE above).         any matched string (see PCRE_INFO_FIRSTBYTE above).
1868    
1869    
# Line 1837  REFERENCE COUNTS Line 1871  REFERENCE COUNTS
1871    
1872         int pcre_refcount(pcre *code, int adjust);         int pcre_refcount(pcre *code, int adjust);
1873    
1874         The pcre_refcount() function is used to maintain a reference  count  in         The  pcre_refcount()  function is used to maintain a reference count in
1875         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
1876         benefit of applications that  operate  in  an  object-oriented  manner,         benefit  of  applications  that  operate  in an object-oriented manner,
1877         where different parts of the application may be using the same compiled         where different parts of the application may be using the same compiled
1878         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.
1879    
1880         When a pattern is compiled, the reference count field is initialized to         When a pattern is compiled, the reference count field is initialized to
1881         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
1882         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
1883         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
1884         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
1885         is outside these limits, it is forced to the appropriate limit value.         is outside these limits, it is forced to the appropriate limit value.
1886    
1887         Except  when it is zero, the reference count is not correctly preserved         Except when it is zero, the reference count is not correctly  preserved
1888         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
1889         whose byte-order is different. (This seems a highly unlikely scenario.)         whose byte-order is different. (This seems a highly unlikely scenario.)
1890    
1891    
# Line 1861  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1895  MATCHING A PATTERN: THE TRADITIONAL FUNC
1895              const char *subject, int length, int startoffset,              const char *subject, int length, int startoffset,
1896              int options, int *ovector, int ovecsize);              int options, int *ovector, int ovecsize);
1897    
1898         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
1899         compiled pattern, which is passed in the code argument. If the  pattern         compiled  pattern, which is passed in the code argument. If the pattern
1900         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
1901         argument. This function is the main matching facility of  the  library,         argument.  This  function is the main matching facility of the library,
1902         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
1903         an alternative matching function, which is described below in the  sec-         an  alternative matching function, which is described below in the sec-
1904         tion about the pcre_dfa_exec() function.         tion about the pcre_dfa_exec() function.
1905    
1906         In  most applications, the pattern will have been compiled (and option-         In most applications, the pattern will have been compiled (and  option-
1907         ally studied) in the same process that calls pcre_exec().  However,  it         ally  studied)  in the same process that calls pcre_exec(). However, it
1908         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
1909         later in different processes, possibly even on different hosts.  For  a         later  in  different processes, possibly even on different hosts. For a
1910         discussion about this, see the pcreprecompile documentation.         discussion about this, see the pcreprecompile documentation.
1911    
1912         Here is an example of a simple call to pcre_exec():         Here is an example of a simple call to pcre_exec():
# Line 1891  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1925  MATCHING A PATTERN: THE TRADITIONAL FUNC
1925    
1926     Extra data for pcre_exec()     Extra data for pcre_exec()
1927    
1928         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
1929         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
1930         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-
1931         tional information in it. The pcre_extra block contains  the  following         tional  information  in it. The pcre_extra block contains the following
1932         fields (not necessarily in this order):         fields (not necessarily in this order):
1933    
1934           unsigned long int flags;           unsigned long int flags;
# Line 1903  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1937  MATCHING A PATTERN: THE TRADITIONAL FUNC
1937           unsigned long int match_limit_recursion;           unsigned long int match_limit_recursion;
1938           void *callout_data;           void *callout_data;
1939           const unsigned char *tables;           const unsigned char *tables;
1940             unsigned char **mark;
1941    
1942         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
1943         are set. The flag bits are:         are set. The flag bits are:
1944    
1945           PCRE_EXTRA_STUDY_DATA           PCRE_EXTRA_STUDY_DATA
# Line 1912  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 1947  MATCHING A PATTERN: THE TRADITIONAL FUNC
1947           PCRE_EXTRA_MATCH_LIMIT_RECURSION           PCRE_EXTRA_MATCH_LIMIT_RECURSION
1948           PCRE_EXTRA_CALLOUT_DATA           PCRE_EXTRA_CALLOUT_DATA
1949           PCRE_EXTRA_TABLES           PCRE_EXTRA_TABLES
1950             PCRE_EXTRA_MARK
1951    
1952         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
1953         the  pcre_extra  block  that is returned by pcre_study(), together with         the pcre_extra block that is returned by  pcre_study(),  together  with
1954         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
1955         add  to  the  block by setting the other fields and their corresponding         add to the block by setting the other fields  and  their  corresponding
1956         flag bits.         flag bits.
1957    
1958         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
1959         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
1960         match, but which have a very large number  of  possibilities  in  their         match,  but  which  have  a very large number of possibilities in their
1961         search  trees. The classic example is a pattern that uses nested unlim-         search trees. The classic example is a pattern that uses nested  unlim-
1962         ited repeats.         ited repeats.
1963    
1964         Internally, PCRE uses a function called match() which it calls  repeat-         Internally,  PCRE uses a function called match() which it calls repeat-
1965         edly  (sometimes  recursively). The limit set by match_limit is imposed         edly (sometimes recursively). The limit set by match_limit  is  imposed
1966         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
1967         has  the  effect  of  limiting the amount of backtracking that can take         has the effect of limiting the amount of  backtracking  that  can  take
1968         place. For patterns that are not anchored, the count restarts from zero         place. For patterns that are not anchored, the count restarts from zero
1969         for each position in the subject string.         for each position in the subject string.
1970    
1971         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
1972         default default is 10 million, which handles all but the  most  extreme         default  default  is 10 million, which handles all but the most extreme
1973         cases.  You  can  override  the  default by suppling pcre_exec() with a         cases. You can override the default  by  suppling  pcre_exec()  with  a
1974         pcre_extra    block    in    which    match_limit    is    set,     and         pcre_extra     block    in    which    match_limit    is    set,    and
1975         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
1976         exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT.         exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT.
1977    
1978         The match_limit_recursion field is similar to match_limit, but  instead         The  match_limit_recursion field is similar to match_limit, but instead
1979         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
1980         the depth of recursion. The recursion depth is a  smaller  number  than         the  depth  of  recursion. The recursion depth is a smaller number than
1981         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-
1982         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.
1983    
1984         Limiting the recursion depth limits the amount of  stack  that  can  be         Limiting  the  recursion  depth  limits the amount of stack that can be
1985         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
1986         of the stack, the amount of heap memory that can be used.         of the stack, the amount of heap memory that can be used.
1987    
1988         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
1989         built;  the  default  default  is  the  same  value  as the default for         built; the default default  is  the  same  value  as  the  default  for
1990         match_limit. You can override the default by suppling pcre_exec()  with         match_limit.  You can override the default by suppling pcre_exec() with
1991         a   pcre_extra   block  in  which  match_limit_recursion  is  set,  and         a  pcre_extra  block  in  which  match_limit_recursion  is   set,   and
1992         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
1993         limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT.         limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT.
1994    
1995         The  callout_data  field is used in conjunction with the "callout" fea-         The callout_data field is used in conjunction with the  "callout"  fea-
1996         ture, and is described in the pcrecallout documentation.         ture, and is described in the pcrecallout documentation.
1997    
1998         The tables field  is  used  to  pass  a  character  tables  pointer  to         The  tables  field  is  used  to  pass  a  character  tables pointer to
1999         pcre_exec();  this overrides the value that is stored with the compiled         pcre_exec(); this overrides the value that is stored with the  compiled
2000         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
2001         custom  tables  were  supplied to pcre_compile() via its tableptr argu-         custom tables were supplied to pcre_compile() via  its  tableptr  argu-
2002         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
2003         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-
2004         using patterns that have been saved after compiling  with  an  external         using  patterns  that  have been saved after compiling with an external
2005         set  of  tables,  because  the  external tables might be at a different         set of tables, because the external tables  might  be  at  a  different
2006         address when pcre_exec() is called. See the  pcreprecompile  documenta-         address  when  pcre_exec() is called. See the pcreprecompile documenta-
2007         tion for a discussion of saving compiled patterns for later use.         tion for a discussion of saving compiled patterns for later use.
2008    
2009           If PCRE_EXTRA_MARK is set in the flags field, the mark  field  must  be
2010           set  to  point  to a char * variable. If the pattern contains any back-
2011           tracking control verbs such as (*MARK:NAME), and the execution ends  up
2012           with  a  name  to  pass back, a pointer to the name string (zero termi-
2013           nated) is placed in the variable pointed to  by  the  mark  field.  The
2014           names  are  within  the  compiled pattern; if you wish to retain such a
2015           name you must copy it before freeing the memory of a compiled  pattern.
2016           If  there  is no name to pass back, the variable pointed to by the mark
2017           field set to NULL. For details of the backtracking control  verbs,  see
2018           the section entitled "Backtracking control" in the pcrepattern documen-
2019           tation.
2020    
2021     Option bits for pcre_exec()     Option bits for pcre_exec()
2022    
2023         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.
2024         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,
2025         PCRE_NOTBOL,    PCRE_NOTEOL,    PCRE_NOTEMPTY,   PCRE_NOTEMPTY_ATSTART,         PCRE_NOTBOL,   PCRE_NOTEOL,    PCRE_NOTEMPTY,    PCRE_NOTEMPTY_ATSTART,
2026         PCRE_NO_START_OPTIMIZE,  PCRE_NO_UTF8_CHECK,   PCRE_PARTIAL_SOFT,   and         PCRE_NO_START_OPTIMIZE,   PCRE_NO_UTF8_CHECK,   PCRE_PARTIAL_SOFT,  and
2027         PCRE_PARTIAL_HARD.         PCRE_PARTIAL_HARD.
2028    
2029           PCRE_ANCHORED           PCRE_ANCHORED
2030    
2031         The  PCRE_ANCHORED  option  limits pcre_exec() to matching at the first         The PCRE_ANCHORED option limits pcre_exec() to matching  at  the  first
2032         matching position. If a pattern was  compiled  with  PCRE_ANCHORED,  or         matching  position.  If  a  pattern was compiled with PCRE_ANCHORED, or
2033         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
2034         unachored at matching time.         unachored at matching time.
2035    
2036           PCRE_BSR_ANYCRLF           PCRE_BSR_ANYCRLF
2037           PCRE_BSR_UNICODE           PCRE_BSR_UNICODE
2038    
2039         These options (which are mutually exclusive) control what the \R escape         These options (which are mutually exclusive) control what the \R escape
2040         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,
2041         or to match any Unicode newline sequence. These  options  override  the         or  to  match  any Unicode newline sequence. These options override the
2042         choice that was made or defaulted when the pattern was compiled.         choice that was made or defaulted when the pattern was compiled.
2043    
2044           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
# Line 1999  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 2047  MATCHING A PATTERN: THE TRADITIONAL FUNC
2047           PCRE_NEWLINE_ANYCRLF           PCRE_NEWLINE_ANYCRLF
2048           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
2049    
2050         These  options  override  the  newline  definition  that  was chosen or         These options override  the  newline  definition  that  was  chosen  or
2051         defaulted when the pattern was compiled. For details, see the  descrip-         defaulted  when the pattern was compiled. For details, see the descrip-
2052         tion  of  pcre_compile()  above.  During  matching,  the newline choice         tion of pcre_compile()  above.  During  matching,  the  newline  choice
2053         affects the behaviour of the dot, circumflex,  and  dollar  metacharac-         affects  the  behaviour  of the dot, circumflex, and dollar metacharac-
2054         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
2055         match failure for an unanchored pattern.         match failure for an unanchored pattern.
2056    
2057         When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF,  or  PCRE_NEWLINE_ANY  is         When  PCRE_NEWLINE_CRLF,  PCRE_NEWLINE_ANYCRLF,  or PCRE_NEWLINE_ANY is
2058         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-
2059         rent position is at a  CRLF  sequence,  and  the  pattern  contains  no         rent  position  is  at  a  CRLF  sequence,  and the pattern contains no
2060         explicit  matches  for  CR  or  LF  characters,  the  match position is         explicit matches for  CR  or  LF  characters,  the  match  position  is
2061         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
2062         CRLF.         CRLF.
2063    
2064         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
2065         expected. For example, if the  pattern  is  .+A  (and  the  PCRE_DOTALL         expected.  For  example,  if  the  pattern  is .+A (and the PCRE_DOTALL
2066         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
2067         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.
2068         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-
2069         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-
2070         acter after the first failure.         acter after the first failure.
2071    
2072         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
2073         those characters, or one of the \r or  \n  escape  sequences.  Implicit         those  characters,  or  one  of the \r or \n escape sequences. Implicit
2074         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
2075         LF in the characters that it matches).         LF in the characters that it matches).
2076    
2077         Notwithstanding the above, anomalous effects may still occur when  CRLF         Notwithstanding  the above, anomalous effects may still occur when CRLF
2078         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
2079         pattern.         pattern.
2080    
2081           PCRE_NOTBOL           PCRE_NOTBOL
2082    
2083         This option specifies that first character of the subject string is not         This option specifies that first character of the subject string is not
2084         the  beginning  of  a  line, so the circumflex metacharacter should not         the beginning of a line, so the  circumflex  metacharacter  should  not
2085         match before it. Setting this without PCRE_MULTILINE (at compile  time)         match  before it. Setting this without PCRE_MULTILINE (at compile time)
2086         causes  circumflex  never to match. This option affects only the behav-         causes circumflex never to match. This option affects only  the  behav-
2087         iour of the circumflex metacharacter. It does not affect \A.         iour of the circumflex metacharacter. It does not affect \A.
2088    
2089           PCRE_NOTEOL           PCRE_NOTEOL
2090    
2091         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
2092         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
2093         in multiline mode) a newline immediately before it. Setting this  with-         in  multiline mode) a newline immediately before it. Setting this with-
2094         out PCRE_MULTILINE (at compile time) causes dollar never to match. This         out PCRE_MULTILINE (at compile time) causes dollar never to match. This
2095         option affects only the behaviour of the dollar metacharacter. It  does         option  affects only the behaviour of the dollar metacharacter. It does
2096         not affect \Z or \z.         not affect \Z or \z.
2097    
2098           PCRE_NOTEMPTY           PCRE_NOTEMPTY
2099    
2100         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
2101         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
2102         the  alternatives  match  the empty string, the entire match fails. For         the alternatives match the empty string, the entire  match  fails.  For
2103         example, if the pattern         example, if the pattern
2104    
2105           a?b?           a?b?
2106    
2107         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
2108         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
2109         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-
2110         rences of "a" or "b".         rences of "a" or "b".
2111    
2112           PCRE_NOTEMPTY_ATSTART           PCRE_NOTEMPTY_ATSTART
2113    
2114         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
2115         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
2116         anchored, such a match can occur only if the pattern contains \K.         anchored, such a match can occur only if the pattern contains \K.
2117    
2118         Perl     has    no    direct    equivalent    of    PCRE_NOTEMPTY    or         Perl    has    no    direct    equivalent    of    PCRE_NOTEMPTY     or
2119         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
2120         match  of  the empty string within its split() function, and when using         match of the empty string within its split() function, and  when  using
2121         the /g modifier. It is  possible  to  emulate  Perl's  behaviour  after         the  /g  modifier.  It  is  possible  to emulate Perl's behaviour after
2122         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-
2123         set with PCRE_NOTEMPTY_ATSTART and  PCRE_ANCHORED,  and  then  if  that         set  with  PCRE_NOTEMPTY_ATSTART  and  PCRE_ANCHORED,  and then if that
2124         fails, by advancing the starting offset (see below) and trying an ordi-         fails, by advancing the starting offset (see below) and trying an ordi-
2125         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
2126         in the pcredemo sample program.         in the pcredemo sample program.
2127    
2128           PCRE_NO_START_OPTIMIZE           PCRE_NO_START_OPTIMIZE
2129    
2130         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
2131         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
2132         known  that  a  match must start with a specific character, it searches         known that an unanchored match must start with a specific character, it
2133         the subject for that character, and fails immediately if it cannot find         searches  the  subject  for that character, and fails immediately if it
2134         it,  without actually running the main matching function. When callouts         cannot find it, without actually running the  main  matching  function.
2135         are in use, these optimizations can cause  them  to  be  skipped.  This         This means that a special item such as (*COMMIT) at the start of a pat-
2136         option  disables  the  "start-up" optimizations, causing performance to         tern is not considered until after a suitable starting  point  for  the
2137         suffer, but ensuring that the callouts do occur.         match  has been found. When callouts or (*MARK) items are in use, these
2138           "start-up" optimizations can cause them to be skipped if the pattern is
2139           never  actually  used.  The start-up optimizations are in effect a pre-
2140           scan of the subject that takes place before the pattern is run.
2141    
2142           The PCRE_NO_START_OPTIMIZE option disables the start-up  optimizations,
2143           possibly  causing  performance  to  suffer,  but ensuring that in cases
2144           where the result is "no match", the callouts do occur, and  that  items
2145           such as (*COMMIT) and (*MARK) are considered at every possible starting
2146           position in the subject  string.   Setting  PCRE_NO_START_OPTIMIZE  can
2147           change the outcome of a matching operation.  Consider the pattern
2148    
2149             (*COMMIT)ABC
2150    
2151           When  this  is  compiled, PCRE records the fact that a match must start
2152           with the character "A". Suppose the subject  string  is  "DEFABC".  The
2153           start-up  optimization  scans along the subject, finds "A" and runs the
2154           first match attempt from there. The (*COMMIT) item means that the  pat-
2155           tern  must  match the current starting position, which in this case, it
2156           does. However, if the same match  is  run  with  PCRE_NO_START_OPTIMIZE
2157           set,  the  initial  scan  along the subject string does not happen. The
2158           first match attempt is run starting  from  "D"  and  when  this  fails,
2159           (*COMMIT)  prevents  any  further  matches  being tried, so the overall
2160           result is "no match". If the pattern is studied,  more  start-up  opti-
2161           mizations  may  be  used. For example, a minimum length for the subject
2162           may be recorded. Consider the pattern
2163    
2164             (*MARK:A)(X|Y)
2165    
2166           The minimum length for a match is one  character.  If  the  subject  is
2167           "ABC",  there  will  be  attempts  to  match "ABC", "BC", "C", and then
2168           finally an empty string.  If the pattern is studied, the final  attempt
2169           does  not take place, because PCRE knows that the subject is too short,
2170           and so the (*MARK) is never encountered.  In this  case,  studying  the
2171           pattern  does  not  affect the overall match result, which is still "no
2172           match", but it does affect the auxiliary information that is returned.
2173    
2174           PCRE_NO_UTF8_CHECK           PCRE_NO_UTF8_CHECK
2175    
# Line 2273  MATCHING A PATTERN: THE TRADITIONAL FUNC Line 2356  MATCHING A PATTERN: THE TRADITIONAL FUNC
2356         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
2357         memory is automatically freed at the end of matching.         memory is automatically freed at the end of matching.
2358    
2359           This error is also given if pcre_stack_malloc() fails  in  pcre_exec().
2360           This  can happen only when PCRE has been compiled with --disable-stack-
2361           for-recursion.
2362    
2363           PCRE_ERROR_NOSUBSTRING    (-7)           PCRE_ERROR_NOSUBSTRING    (-7)
2364    
2365         This error is used by the pcre_copy_substring(),  pcre_get_substring(),         This error is used by the pcre_copy_substring(),  pcre_get_substring(),
# Line 2584  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 2671  MATCHING A PATTERN: THE ALTERNATIVE FUNC
2671         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
2672         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-
2673         LINE_xxx,        PCRE_NOTBOL,        PCRE_NOTEOL,        PCRE_NOTEMPTY,         LINE_xxx,        PCRE_NOTBOL,        PCRE_NOTEOL,        PCRE_NOTEMPTY,
2674         PCRE_NOTEMPTY_ATSTART, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_HARD, PCRE_PAR-         PCRE_NOTEMPTY_ATSTART,       PCRE_NO_UTF8_CHECK,      PCRE_BSR_ANYCRLF,
2675         TIAL_SOFT, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All  but  the  last         PCRE_BSR_UNICODE, PCRE_NO_START_OPTIMIZE, PCRE_PARTIAL_HARD,  PCRE_PAR-
2676         four  of  these  are  exactly  the  same  as  for pcre_exec(), so their         TIAL_SOFT,  PCRE_DFA_SHORTEST,  and PCRE_DFA_RESTART.  All but the last
2677           four of these are  exactly  the  same  as  for  pcre_exec(),  so  their
2678         description is not repeated here.         description is not repeated here.
2679    
2680           PCRE_PARTIAL_HARD           PCRE_PARTIAL_HARD
2681           PCRE_PARTIAL_SOFT           PCRE_PARTIAL_SOFT
2682    
2683         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
2684         details  are  slightly  different.  When  PCRE_PARTIAL_HARD  is set for         details are slightly  different.  When  PCRE_PARTIAL_HARD  is  set  for
2685         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-
2686         ject  is  reached  and there is still at least one matching possibility         ject is reached and there is still at least  one  matching  possibility
2687         that requires additional characters. This happens even if some complete         that requires additional characters. This happens even if some complete
2688         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
2689         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
2690         of  the  subject  is  reached, there have been no complete matches, but         of the subject is reached, there have been  no  complete  matches,  but
2691         there is still at least one matching possibility. The  portion  of  the         there  is  still  at least one matching possibility. The portion of the
2692         string  that  was inspected when the longest partial match was found is         string that was inspected when the longest partial match was  found  is
2693         set as the first matching string in both cases.         set as the first matching string in both cases.
2694    
2695           PCRE_DFA_SHORTEST           PCRE_DFA_SHORTEST
2696    
2697         Setting the PCRE_DFA_SHORTEST option causes the matching  algorithm  to         Setting  the  PCRE_DFA_SHORTEST option causes the matching algorithm to
2698         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-
2699         tive algorithm works, this is necessarily the shortest  possible  match         tive  algorithm  works, this is necessarily the shortest possible match
2700         at the first possible matching point in the subject string.         at the first possible matching point in the subject string.
2701    
2702           PCRE_DFA_RESTART           PCRE_DFA_RESTART
2703    
2704         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
2705         again, with additional subject characters, and have  it  continue  with         again,  with  additional  subject characters, and have it continue with
2706         the  same match. The PCRE_DFA_RESTART option requests this action; when         the same match. The PCRE_DFA_RESTART option requests this action;  when
2707         it is set, the workspace and wscount options must  reference  the  same         it  is  set,  the workspace and wscount options must reference the same
2708         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
2709         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
2710         pcrepartial documentation.         pcrepartial documentation.
2711    
2712     Successful returns from pcre_dfa_exec()     Successful returns from pcre_dfa_exec()
2713    
2714         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-
2715         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
2716         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
2717         matches are all initial substrings of the longer matches. For  example,         matches  are all initial substrings of the longer matches. For example,
2718         if the pattern         if the pattern
2719    
2720           <.*>           <.*>
# Line 2641  MATCHING A PATTERN: THE ALTERNATIVE FUNC Line 2729  MATCHING A PATTERN: THE ALTERNATIVE FUNC
2729           <something> <something else>           <something> <something else>
2730           <something> <something else> <something further>           <something> <something else> <something further>
2731    
2732         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,
2733         which is the number of matched substrings.  The  substrings  themselves         which  is  the  number of matched substrings. The substrings themselves
2734         are  returned  in  ovector. Each string uses two elements; the first is         are returned in ovector. Each string uses two elements;  the  first  is
2735         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
2736         fact,  all  the  strings  have the same start offset. (Space could have         fact, all the strings have the same start  offset.  (Space  could  have
2737         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
2738         compatibility  with  the  way pcre_exec() returns data, even though the         compatibility with the way pcre_exec() returns data,  even  though  the
2739         meaning of the strings is different.)         meaning of the strings is different.)
2740    
2741         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-
2742         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
2743         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
2744         filled with the longest matches.         filled with the longest matches.
2745    
2746     Error returns from pcre_dfa_exec()     Error returns from pcre_dfa_exec()
2747    
2748         The  pcre_dfa_exec()  function returns a negative number when it fails.         The pcre_dfa_exec() function returns a negative number when  it  fails.
2749         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
2750         described  above.   There are in addition the following errors that are         described above.  There are in addition the following errors  that  are
2751         specific to pcre_dfa_exec():         specific to pcre_dfa_exec():
2752    
2753           PCRE_ERROR_DFA_UITEM      (-16)           PCRE_ERROR_DFA_UITEM      (-16)
2754    
2755         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-
2756         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
2757         reference.         reference.
2758    
2759           PCRE_ERROR_DFA_UCOND      (-17)           PCRE_ERROR_DFA_UCOND      (-17)
2760    
2761         This return is given if pcre_dfa_exec()  encounters  a  condition  item         This  return  is  given  if pcre_dfa_exec() encounters a condition item
2762         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
2763         in a specific group. These are not supported.         in a specific group. These are not supported.
2764    
2765           PCRE_ERROR_DFA_UMLIMIT    (-18)           PCRE_ERROR_DFA_UMLIMIT    (-18)
2766    
2767         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
2768         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
2769         (it is meaningless).         (it is meaningless).
2770    
2771           PCRE_ERROR_DFA_WSSIZE     (-19)           PCRE_ERROR_DFA_WSSIZE     (-19)
2772    
2773         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
2774         workspace vector.         workspace vector.
2775    
2776           PCRE_ERROR_DFA_RECURSE    (-20)           PCRE_ERROR_DFA_RECURSE    (-20)
2777    
2778         When  a  recursive subpattern is processed, the matching function calls         When a recursive subpattern is processed, the matching  function  calls
2779         itself recursively, using private vectors for  ovector  and  workspace.         itself  recursively,  using  private vectors for ovector and workspace.
2780         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
2781         should be extremely rare, as a vector of size 1000 is used.         should be extremely rare, as a vector of size 1000 is used.
2782    
2783    
2784  SEE ALSO  SEE ALSO
2785    
2786         pcrebuild(3), pcrecallout(3), pcrecpp(3)(3), pcrematching(3),  pcrepar-         pcrebuild(3),  pcrecallout(3), pcrecpp(3)(3), pcrematching(3), pcrepar-
2787         tial(3), pcreposix(3), pcreprecompile(3), pcresample(3), pcrestack(3).         tial(3), pcreposix(3), pcreprecompile(3), pcresample(3), pcrestack(3).
2788    
2789    
# Line 2708  AUTHOR Line 2796  AUTHOR
2796    
2797  REVISION  REVISION
2798    
2799         Last updated: 03 October 2009         Last updated: 21 June 2010
2800         Copyright (c) 1997-2009 University of Cambridge.         Copyright (c) 1997-2010 University of Cambridge.
2801  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2802    
2803    
# Line 2905  DIFFERENCES BETWEEN PCRE AND PERL Line 2993  DIFFERENCES BETWEEN PCRE AND PERL
2993    
2994         This  document describes the differences in the ways that PCRE and Perl         This  document describes the differences in the ways that PCRE and Perl
2995         handle regular expressions. The differences  described  here  are  with         handle regular expressions. The differences  described  here  are  with
2996         respect to Perl 5.10.         respect to Perl 5.10/5.11.
2997    
2998         1.  PCRE has only a subset of Perl's UTF-8 and Unicode support. Details         1.  PCRE has only a subset of Perl's UTF-8 and Unicode support. Details
2999         of what it does have are given in the section on UTF-8 support  in  the         of what it does have are given in the section on UTF-8 support  in  the
# Line 2976  DIFFERENCES BETWEEN PCRE AND PERL Line 3064  DIFFERENCES BETWEEN PCRE AND PERL
3064         matching "aba" against the  pattern  /^(a(b)?)+$/  in  Perl  leaves  $2         matching "aba" against the  pattern  /^(a(b)?)+$/  in  Perl  leaves  $2
3065         unset, but in PCRE it is set to "b".         unset, but in PCRE it is set to "b".
3066    
3067         11.  PCRE  does  support  Perl  5.10's  backtracking  verbs  (*ACCEPT),         11.  PCRE's handling of duplicate subpattern numbers and duplicate sub-
        (*FAIL), (*F), (*COMMIT), (*PRUNE), (*SKIP), and (*THEN), but  only  in  
        the forms without an argument. PCRE does not support (*MARK).  
   
        12.  PCRE's handling of duplicate subpattern numbers and duplicate sub-  
3068         pattern names is not as general as Perl's. This is a consequence of the         pattern names is not as general as Perl's. This is a consequence of the
3069         fact the PCRE works internally just with numbers, using an external ta-         fact the PCRE works internally just with numbers, using an external ta-
3070         ble to translate between numbers and names. In  particular,  a  pattern         ble to translate between numbers and names. In  particular,  a  pattern
# Line 2991  DIFFERENCES BETWEEN PCRE AND PERL Line 3075  DIFFERENCES BETWEEN PCRE AND PERL
3075         turing subpattern number 1. To avoid this confusing situation, an error         turing subpattern number 1. To avoid this confusing situation, an error
3076         is given at compile time.         is given at compile time.
3077    
3078         13. PCRE provides some extensions to the Perl regular expression facil-         12. PCRE provides some extensions to the Perl regular expression facil-
3079         ities.   Perl  5.10  includes new features that are not in earlier ver-         ities.   Perl  5.10  includes new features that are not in earlier ver-
3080         sions of Perl, some of which (such as named parentheses) have  been  in         sions of Perl, some of which (such as named parentheses) have  been  in
3081         PCRE for some time. This list is with respect to Perl 5.10:         PCRE for some time. This list is with respect to Perl 5.10:
# Line 3046  AUTHOR Line 3130  AUTHOR
3130    
3131  REVISION  REVISION
3132    
3133         Last updated: 04 October 2009         Last updated: 12 May 2010
3134         Copyright (c) 1997-2009 University of Cambridge.         Copyright (c) 1997-2010 University of Cambridge.
3135  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
3136    
3137    
# Line 3089  PCRE REGULAR EXPRESSION DETAILS Line 3173  PCRE REGULAR EXPRESSION DETAILS
3173         below.  There  is  also  a  summary of UTF-8 features in the section on         below.  There  is  also  a  summary of UTF-8 features in the section on
3174         UTF-8 support in the main pcre page.         UTF-8 support in the main pcre page.
3175    
3176           Another special sequence that may appear at the start of a  pattern  or
3177           in combination with (*UTF8) is:
3178    
3179             (*UCP)
3180    
3181           This  has  the  same  effect  as setting the PCRE_UCP option: it causes
3182           sequences such as \d and \w to  use  Unicode  properties  to  determine
3183           character types, instead of recognizing only characters with codes less
3184           than 128 via a lookup table.
3185    
3186         The remainder of this document discusses the  patterns  that  are  sup-         The remainder of this document discusses the  patterns  that  are  sup-
3187         ported  by  PCRE when its main matching function, pcre_exec(), is used.         ported  by  PCRE when its main matching function, pcre_exec(), is used.
3188         From  release  6.0,   PCRE   offers   a   second   matching   function,         From  release  6.0,   PCRE   offers   a   second   matching   function,
# Line 3129  NEWLINE CONVENTIONS Line 3223  NEWLINE CONVENTIONS
3223         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
3224         present, the last one is used.         present, the last one is used.
3225    
3226         The  newline  convention  does  not  affect what the \R escape sequence         The  newline convention affects the interpretation of the dot metachar-
3227         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-
3228         compatibility.  However, this can be changed; see the description of \R         ever,  it  does  not  affect  what  the  \R escape sequence matches. By
3229         in the section entitled "Newline sequences" below. A change of \R  set-         default, this is any Unicode newline sequence, for Perl  compatibility.
3230         ting can be combined with a change of newline convention.         However,  this can be changed; see the description of \R in the section
3231           entitled "Newline sequences" below. A change of \R setting can be  com-
3232           bined with a change of newline convention.
3233    
3234    
3235  CHARACTERS AND METACHARACTERS  CHARACTERS AND METACHARACTERS
# Line 3315  BACKSLASH Line 3411  BACKSLASH
3411         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
3412         inside  and  outside character classes. In addition, inside a character         inside  and  outside character classes. In addition, inside a character
3413         class, the sequence \b is interpreted as the backspace  character  (hex         class, the sequence \b is interpreted as the backspace  character  (hex
3414         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-
3415         and "X", respectively. Outside a character class, these sequences  have         ter class. Like any  other  unrecognized  escape  sequences,  they  are
3416         different meanings (see below).         treated  as  the  literal characters "B", "N", "R", and "X" by default,
3417           but cause an error if the PCRE_EXTRA option is set. Outside a character
3418           class, these sequences have different meanings.
3419    
3420     Absolute and relative back references     Absolute and relative back references
3421    
# Line 3337  BACKSLASH Line 3435  BACKSLASH
3435    
3436     Generic character types     Generic character types
3437    
3438         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:  
3439    
3440           \d     any decimal digit           \d     any decimal digit
3441           \D     any character that is not a decimal digit           \D     any character that is not a decimal digit
# Line 3351  BACKSLASH Line 3448  BACKSLASH
3448           \w     any "word" character           \w     any "word" character
3449           \W     any "non-word" character           \W     any "non-word" character
3450    
3451         Each pair of escape sequences partitions the complete set of characters         There is also the single sequence \N, which matches a non-newline char-
3452         into  two disjoint sets. Any given character matches one, and only one,         acter.  This is the same as the "." metacharacter when  PCRE_DOTALL  is
3453         of each pair.         not set.
3454    
3455         These character type sequences can appear both inside and outside char-         Each  pair of lower and upper case escape sequences partitions the com-
3456         acter  classes.  They each match one character of the appropriate type.         plete set of characters into two disjoint  sets.  Any  given  character
3457         If the current matching point is at the end of the subject string,  all         matches  one, and only one, of each pair. The sequences can appear both
3458         of them fail, since there is no character to match.         inside and outside character classes. They each match one character  of
3459           the  appropriate  type.  If the current matching point is at the end of
3460           the subject string, all of them fail, because there is no character  to
3461           match.
3462    
3463         For  compatibility  with Perl, \s does not match the VT character (code         For  compatibility  with Perl, \s does not match the VT character (code
3464         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
# Line 3366  BACKSLASH Line 3466  BACKSLASH
3466         "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-
3467         ter. In PCRE, it never does.         ter. In PCRE, it never does.
3468    
3469         In  UTF-8 mode, characters with values greater than 128 never match \d,         A  "word"  character is an underscore or any character that is a letter
3470         \s, or \w, and always match \D, \S, and \W. This is true even when Uni-         or digit.  By default, the definition of letters  and  digits  is  con-
3471         code  character  property  support is available. These sequences retain         trolled  by PCRE's low-valued character tables, and may vary if locale-
3472         their original meanings from before UTF-8 support was available, mainly         specific matching is taking place (see "Locale support" in the  pcreapi
3473         for  efficiency  reasons. Note that this also affects \b, because it is         page).  For  example,  in  a French locale such as "fr_FR" in Unix-like
3474         defined in terms of \w and \W.         systems, or "french" in Windows, some character codes greater than  128
3475           are  used  for  accented letters, and these are then matched by \w. The
3476           use of locales with Unicode is discouraged.
3477    
3478           By default, in UTF-8 mode, characters  with  values  greater  than  128
3479           never  match  \d,  \s,  or  \w,  and always match \D, \S, and \W. These
3480           sequences retain their original meanings from before UTF-8 support  was
3481           available,  mainly for efficiency reasons. However, if PCRE is compiled
3482           with Unicode property support, and the PCRE_UCP option is set, the  be-
3483           haviour  is  changed  so  that Unicode properties are used to determine
3484           character types, as follows:
3485    
3486             \d  any character that \p{Nd} matches (decimal digit)
3487             \s  any character that \p{Z} matches, plus HT, LF, FF, CR
3488             \w  any character that \p{L} or \p{N} matches, plus underscore
3489    
3490           The upper case escapes match the inverse sets of characters. Note  that
3491           \d  matches  only decimal digits, whereas \w matches any Unicode digit,
3492           as well as any Unicode letter, and underscore. Note also that  PCRE_UCP
3493           affects  \b,  and  \B  because  they are defined in terms of \w and \W.
3494           Matching these sequences is noticeably slower when PCRE_UCP is set.
3495    
3496         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
3497         the  other  sequences, these do match certain high-valued codepoints in         the  other  sequences,  which  match  only ASCII characters by default,
3498         UTF-8 mode.  The horizontal space characters are:         these always  match  certain  high-valued  codepoints  in  UTF-8  mode,
3499           whether or not PCRE_UCP is set. The horizontal space characters are:
3500    
3501           U+0009     Horizontal tab           U+0009     Horizontal tab
3502           U+0020     Space           U+0020     Space
# Line 3407  BACKSLASH Line 3528  BACKSLASH
3528           U+2028     Line separator           U+2028     Line separator
3529           U+2029     Paragraph separator           U+2029     Paragraph separator
3530    
        A "word" character is an underscore or any character less than 256 that  
        is  a  letter  or  digit.  The definition of letters and digits is con-  
        trolled by PCRE's low-valued character tables, and may vary if  locale-  
        specific  matching is taking place (see "Locale support" in the pcreapi  
        page). For example, in a French locale such  as  "fr_FR"  in  Unix-like  
        systems,  or "french" in Windows, some character codes greater than 128  
        are used for accented letters, and these are matched by \w. The use  of  
        locales with Unicode is discouraged.  
   
3531     Newline sequences     Newline sequences
3532    
3533         Outside  a  character class, by default, the escape sequence \R matches         Outside  a  character class, by default, the escape sequence \R matches
# Line 3454  BACKSLASH Line 3566  BACKSLASH
3566         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
3567         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
3568         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
3569         newline convention, for example, a pattern can start with:         newline convention; for example, a pattern can start with:
3570    
3571           (*ANY)(*BSR_ANYCRLF)           (*ANY)(*BSR_ANYCRLF)
3572    
3573         Inside a character class, \R matches the letter "R".         They can also be combined with the (*UTF8) or (*UCP) special sequences.
3574           Inside  a  character  class,  \R  is  treated as an unrecognized escape
3575           sequence, and so matches the letter "R" by default, but causes an error
3576           if PCRE_EXTRA is set.
3577    
3578     Unicode character properties     Unicode character properties
3579    
3580         When PCRE is built with Unicode character property support, three addi-         When PCRE is built with Unicode character property support, three addi-
3581         tional  escape sequences that match characters with specific properties         tional escape sequences that match characters with specific  properties
3582         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
3583         limited  to  testing characters whose codepoints are less than 256, but         limited to testing characters whose codepoints are less than  256,  but
3584         they do work in this mode.  The extra escape sequences are:         they do work in this mode.  The extra escape sequences are:
3585    
3586           \p{xx}   a character with the xx property           \p{xx}   a character with the xx property
3587           \P{xx}   a character without the xx property           \P{xx}   a character without the xx property
3588           \X       an extended Unicode sequence           \X       an extended Unicode sequence
3589    
3590         The property names represented by xx above are limited to  the  Unicode         The  property  names represented by xx above are limited to the Unicode
3591         script names, the general category properties, and "Any", which matches         script names, the general category properties, "Any", which matches any
3592         any character (including newline). Other properties such as "InMusical-         character   (including  newline),  and  some  special  PCRE  properties
3593         Symbols"  are  not  currently supported by PCRE. Note that \P{Any} does         (described in the next section).  Other Perl properties such as  "InMu-
3594         not match any characters, so always causes a match failure.         sicalSymbols"  are  not  currently supported by PCRE. Note that \P{Any}
3595           does not match any characters, so always causes a match failure.
3596    
3597         Sets of Unicode characters are defined as belonging to certain scripts.         Sets of Unicode characters are defined as belonging to certain scripts.
3598         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 3503  BACKSLASH Line 3619  BACKSLASH
3619         Tai_Tham,  Tai_Viet,  Tamil,  Telugu,  Thaana, Thai, Tibetan, Tifinagh,         Tai_Tham,  Tai_Viet,  Tamil,  Telugu,  Thaana, Thai, Tibetan, Tifinagh,
3620         Ugaritic, Vai, Yi.         Ugaritic, Vai, Yi.
3621    
3622         Each character has exactly one general category property, specified  by         Each character has exactly one Unicode general category property, spec-
3623         a two-letter abbreviation. For compatibility with Perl, negation can be         ified  by a two-letter abbreviation. For compatibility with Perl, nega-
3624         specified by including a circumflex between the opening brace  and  the         tion can be specified by including a  circumflex  between  the  opening
3625         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
3626           \P{Lu}.
3627    
3628         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-
3629         eral category properties that start with that letter. In this case,  in         eral  category properties that start with that letter. In this case, in
3630         the  absence of negation, the curly brackets in the escape sequence are         the absence of negation, the curly brackets in the escape sequence  are
3631         optional; these two examples have the same effect:         optional; these two examples have the same effect:
3632    
3633           \p{L}           \p{L}
# Line 3562  BACKSLASH Line 3679  BACKSLASH
3679           Zp    Paragraph separator           Zp    Paragraph separator
3680           Zs    Space separator           Zs    Space separator
3681    
3682         The special property L& is also supported: it matches a character  that         The  special property L& is also supported: it matches a character that
3683         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
3684         classified as a modifier or "other".         classified as a modifier or "other".
3685    
3686         The Cs (Surrogate) property applies only to  characters  in  the  range         The  Cs  (Surrogate)  property  applies only to characters in the range
3687         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
3688         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-
3689         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
3690         the pcreapi page). Perl does not support the Cs property.         the pcreapi page). Perl does not support the Cs property.
3691    
3692         The long synonyms for  property  names  that  Perl  supports  (such  as         The  long  synonyms  for  property  names  that  Perl supports (such as
3693         \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
3694         any of these properties with "Is".         any of these properties with "Is".
3695    
3696         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-
3697         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
3698         in the Unicode table.         in the Unicode table.
3699    
3700         Specifying caseless matching does not affect  these  escape  sequences.         Specifying  caseless  matching  does not affect these escape sequences.
3701         For example, \p{Lu} always matches only upper case letters.         For example, \p{Lu} always matches only upper case letters.
3702    
3703         The  \X  escape  matches  any number of Unicode characters that form an         The \X escape matches any number of Unicode  characters  that  form  an
3704         extended Unicode sequence. \X is equivalent to         extended Unicode sequence. \X is equivalent to
3705    
3706           (?>\PM\pM*)           (?>\PM\pM*)
3707    
3708         That is, it matches a character without the "mark"  property,  followed         That  is,  it matches a character without the "mark" property, followed
3709         by  zero  or  more  characters with the "mark" property, and treats the         by zero or more characters with the "mark"  property,  and  treats  the
3710         sequence as an atomic group (see below).  Characters  with  the  "mark"         sequence  as  an  atomic group (see below).  Characters with the "mark"
3711         property  are  typically  accents  that affect the preceding character.         property are typically accents that  affect  the  preceding  character.
3712         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
3713         matches any one character.         matches any one character.
3714    
3715         Matching  characters  by Unicode property is not fast, because PCRE has         Matching characters by Unicode property is not fast, because  PCRE  has
3716         to search a structure that contains  data  for  over  fifteen  thousand         to  search  a  structure  that  contains data for over fifteen thousand
3717         characters. That is why the traditional escape sequences such as \d and         characters. That is why the traditional escape sequences such as \d and
3718         \w do not use Unicode properties in PCRE.         \w  do  not  use  Unicode properties in PCRE by default, though you can
3719           make them do so by setting the PCRE_UCP option for pcre_compile() or by
3720           starting the pattern with (*UCP).
3721    
3722       PCRE's additional properties
3723    
3724           As  well  as  the standard Unicode properties described in the previous
3725           section, PCRE supports four more that make it possible to convert  tra-
3726           ditional escape sequences such as \w and \s and POSIX character classes
3727           to use Unicode properties. PCRE uses these non-standard, non-Perl prop-
3728           erties internally when PCRE_UCP is set. They are:
3729    
3730             Xan   Any alphanumeric character
3731             Xps   Any POSIX space character
3732             Xsp   Any Perl space character
3733             Xwd   Any Perl "word" character
3734    
3735           Xan  matches  characters that have either the L (letter) or the N (num-
3736           ber) property. Xps matches the characters tab, linefeed, vertical  tab,
3737           formfeed,  or  carriage  return, and any other character that has the Z
3738           (separator) property.  Xsp is the same as Xps, except that vertical tab
3739           is excluded. Xwd matches the same characters as Xan, plus underscore.
3740    
3741     Resetting the match start     Resetting the match start
3742    
3743         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-
3744         ously  matched  characters  not  to  be  included  in the final matched         ously matched characters not  to  be  included  in  the  final  matched
3745         sequence. For example, the pattern:         sequence. For example, the pattern:
3746    
3747           foo\Kbar           foo\Kbar
3748    
3749         matches "foobar", but reports that it has matched "bar".  This  feature         matches  "foobar",  but reports that it has matched "bar". This feature
3750         is  similar  to  a lookbehind assertion (described below).  However, in         is similar to a lookbehind assertion (described  below).   However,  in
3751         this case, the part of the subject before the real match does not  have         this  case, the part of the subject before the real match does not have
3752         to  be of fixed length, as lookbehind assertions do. The use of \K does         to be of fixed length, as lookbehind assertions do. The use of \K  does
3753         not interfere with the setting of captured  substrings.   For  example,         not  interfere  with  the setting of captured substrings.  For example,
3754         when the pattern         when the pattern
3755    
3756           (foo)\Kbar           (foo)\Kbar
3757    
3758         matches "foobar", the first substring is still set to "foo".         matches "foobar", the first substring is still set to "foo".
3759    
3760         Perl  documents  that  the  use  of  \K  within assertions is "not well         Perl documents that the use  of  \K  within  assertions  is  "not  well
3761         defined". In PCRE, \K is acted upon  when  it  occurs  inside  positive         defined".  In  PCRE,  \K  is  acted upon when it occurs inside positive
3762         assertions, but is ignored in negative assertions.         assertions, but is ignored in negative assertions.
3763    
3764     Simple assertions     Simple assertions
3765    
3766         The  final use of backslash is for certain simple assertions. An asser-         The final use of backslash is for certain simple assertions. An  asser-
3767         tion specifies a condition that has to be met at a particular point  in         tion  specifies a condition that has to be met at a particular point in
3768         a  match, without consuming any characters from the subject string. The         a match, without consuming any characters from the subject string.  The
3769         use of subpatterns for more complicated assertions is described  below.         use  of subpatterns for more complicated assertions is described below.
3770         The backslashed assertions are:         The backslashed assertions are:
3771    
3772           \b     matches at a word boundary           \b     matches at a word boundary
# Line 3639  BACKSLASH Line 3777  BACKSLASH
3777           \z     matches only at the end of the subject           \z     matches only at the end of the subject
3778           \G     matches at the first matching position in the subject           \G     matches at the first matching position in the subject
3779    
3780         These  assertions may not appear in character classes (but note that \b         Inside a character class, \b has a different meaning;  it  matches  the
3781         has a different meaning, namely the backspace character, inside a char-         backspace  character.  If  any  other  of these assertions appears in a
3782         acter class).         character class, by default it matches the corresponding literal  char-
3783           acter  (for  example,  \B  matches  the  letter  B).  However,  if  the
3784           PCRE_EXTRA option is set, an "invalid escape sequence" error is  gener-
3785           ated instead.
3786    
3787         A  word  boundary is a position in the subject string where the current         A  word  boundary is a position in the subject string where the current
3788         character and the previous character do not both match \w or  \W  (i.e.         character and the previous character do not both match \w or  \W  (i.e.
3789         one  matches  \w  and the other matches \W), or the start or end of the         one  matches  \w  and the other matches \W), or the start or end of the
3790         string if the first or last character matches \w, respectively. Neither         string if the first or last  character  matches  \w,  respectively.  In
3791         PCRE  nor  Perl  has a separte "start of word" or "end of word" metase-         UTF-8  mode,  the  meanings  of \w and \W can be changed by setting the
3792           PCRE_UCP option. When this is done, it also affects \b and \B.  Neither
3793           PCRE  nor  Perl has a separate "start of word" or "end of word" metase-
3794         quence. However, whatever follows \b normally determines which  it  is.         quence. However, whatever follows \b normally determines which  it  is.
3795         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.
3796    
# Line 3732  CIRCUMFLEX AND DOLLAR Line 3875  CIRCUMFLEX AND DOLLAR
3875         set.         set.
3876    
3877    
3878  FULL STOP (PERIOD, DOT)  FULL STOP (PERIOD, DOT) AND \N
3879    
3880         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-
3881         ter  in  the subject string except (by default) a character that signi-         ter  in  the subject string except (by default) a character that signi-
# Line 3755  FULL STOP (PERIOD, DOT) Line 3898  FULL STOP (PERIOD, DOT)
3898         flex and dollar, the only relationship being  that  they  both  involve         flex and dollar, the only relationship being  that  they  both  involve
3899         newlines. Dot has no special meaning in a character class.         newlines. Dot has no special meaning in a character class.
3900    
3901           The escape sequence \N always behaves as a dot does when PCRE_DOTALL is
3902           not set. In other words, it matches any one character except  one  that
3903           signifies the end of a line.
3904    
3905    
3906  MATCHING A SINGLE BYTE  MATCHING A SINGLE BYTE
3907    
# Line 3848  SQUARE BRACKETS AND CHARACTER CLASSES Line 3995  SQUARE BRACKETS AND CHARACTER CLASSES
3995         concept  of  case for characters with values greater than 128 only when         concept  of  case for characters with values greater than 128 only when
3996         it is compiled with Unicode property support.         it is compiled with Unicode property support.
3997    
3998         The character types \d, \D, \p, \P, \s, \S, \w, and \W may also  appear         The character types \d, \D, \h, \H, \p, \P, \s, \S, \v, \V, \w, and  \W
3999         in  a  character  class,  and add the characters that they match to the         may  also appear in a character class, and add the characters that they
4000         class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-         match to the class. For example,  [\dABCDEF]  matches  any  hexadecimal
4001         flex  can  conveniently  be used with the upper case character types to         digit.  A circumflex can conveniently be used with the upper case char-
4002         specify a more restricted set of characters  than  the  matching  lower         acter types to specify a more restricted set  of  characters  than  the
4003         case  type.  For example, the class [^\W_] matches any letter or digit,         matching  lower  case  type.  For example, the class [^\W_] matches any
4004         but not underscore.         letter or digit, but not underscore.
4005    
4006         The only metacharacters that are recognized in  character  classes  are         The only metacharacters that are recognized in  character  classes  are
4007         backslash,  hyphen  (only  where  it can be interpreted as specifying a         backslash,  hyphen  (only  where  it can be interpreted as specifying a
# Line 3873  POSIX CHARACTER CLASSES Line 4020  POSIX CHARACTER CLASSES
4020           [01[:alpha:]%]           [01[:alpha:]%]
4021    
4022         matches "0", "1", any alphabetic character, or "%". The supported class         matches "0", "1", any alphabetic character, or "%". The supported class
4023         names are         names are:
4024    
4025           alnum    letters and digits           alnum    letters and digits
4026           alpha    letters           alpha    letters
# Line 3884  POSIX CHARACTER CLASSES Line 4031  POSIX CHARACTER CLASSES
4031           graph    printing characters, excluding space           graph    printing characters, excluding space
4032           lower    lower case letters           lower    lower case letters
4033           print    printing characters, including space           print    printing characters, including space
4034           punct    printing characters, excluding letters and digits           punct    printing characters, excluding letters and digits and space
4035           space    white space (not quite the same as \s)           space    white space (not quite the same as \s)
4036           upper    upper case letters           upper    upper case letters
4037           word     "word" characters (same as \w)           word     "word" characters (same as \w)
# Line 3905  POSIX CHARACTER CLASSES Line 4052  POSIX CHARACTER CLASSES
4052         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but
4053         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.
4054    
4055         In UTF-8 mode, characters with values greater than 128 do not match any         By  default,  in UTF-8 mode, characters with values greater than 128 do
4056         of the POSIX character classes.         not match any of the POSIX character classes. However, if the  PCRE_UCP
4057           option  is passed to pcre_compile(), some of the classes are changed so
4058           that Unicode character properties are used. This is achieved by replac-
4059           ing the POSIX classes by other sequences, as follows:
4060    
4061             [:alnum:]  becomes  \p{Xan}
4062             [:alpha:]  becomes  \p{L}
4063             [:blank:]  becomes  \h
4064             [:digit:]  becomes  \p{Nd}
4065             [:lower:]  becomes  \p{Ll}
4066             [:space:]  becomes  \p{Xps}
4067             [:upper:]  becomes  \p{Lu}
4068             [:word:]   becomes  \p{Xwd}
4069    
4070           Negated  versions,  such  as [:^alpha:] use \P instead of \p. The other
4071           POSIX classes are unchanged, and match only characters with code points
4072           less than 128.
4073    
4074    
4075  VERTICAL BAR  VERTICAL BAR
4076    
4077         Vertical bar characters are used to separate alternative patterns.  For         Vertical  bar characters are used to separate alternative patterns. For
4078         example, the pattern         example, the pattern
4079    
4080           gilbert|sullivan           gilbert|sullivan
4081    
4082         matches  either "gilbert" or "sullivan". Any number of alternatives may         matches either "gilbert" or "sullivan". Any number of alternatives  may
4083         appear, and an empty  alternative  is  permitted  (matching  the  empty         appear,  and  an  empty  alternative  is  permitted (matching the empty
4084         string). The matching process tries each alternative in turn, from left         string). The matching process tries each alternative in turn, from left
4085         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
4086         are  within a subpattern (defined below), "succeeds" means matching the         are within a subpattern (defined below), "succeeds" means matching  the
4087         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.
4088    
4089    
4090  INTERNAL OPTION SETTING  INTERNAL OPTION SETTING
4091    
4092         The settings of the  PCRE_CASELESS,  PCRE_MULTILINE,  PCRE_DOTALL,  and         The  settings  of  the  PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and
4093         PCRE_EXTENDED  options  (which are Perl-compatible) can be changed from         PCRE_EXTENDED options (which are Perl-compatible) can be  changed  from
4094         within the pattern by  a  sequence  of  Perl  option  letters  enclosed         within  the  pattern  by  a  sequence  of  Perl option letters enclosed
4095         between "(?" and ")".  The option letters are         between "(?" and ")".  The option letters are
4096    
4097           i  for PCRE_CASELESS           i  for PCRE_CASELESS
# Line 3938  INTERNAL OPTION SETTING Line 4101  INTERNAL OPTION SETTING
4101    
4102         For example, (?im) sets caseless, multiline matching. It is also possi-         For example, (?im) sets caseless, multiline matching. It is also possi-
4103         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
4104         combined  setting and unsetting such as (?im-sx), which sets PCRE_CASE-         combined setting and unsetting such as (?im-sx), which sets  PCRE_CASE-
4105         LESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and  PCRE_EXTENDED,         LESS  and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED,
4106         is  also  permitted.  If  a  letter  appears  both before and after the         is also permitted. If a  letter  appears  both  before  and  after  the
4107         hyphen, the option is unset.         hyphen, the option is unset.
4108    
4109         The PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and  PCRE_EXTRA         The  PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA
4110         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
4111         the characters J, U and X respectively.         the characters J, U and X respectively.
4112    
4113         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
4114         inside  subpattern parentheses), the change applies to the remainder of         inside subpattern parentheses), the change applies to the remainder  of
4115         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
4116         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-
4117         fore show up in data extracted by the pcre_fullinfo() function).         fore show up in data extracted by the pcre_fullinfo() function).
4118    
4119         An option change within a subpattern (see below for  a  description  of         An  option  change  within a subpattern (see below for a description of
4120         subpatterns) affects only that part of the current pattern that follows         subpatterns) affects only that part of the current pattern that follows
4121         it, so         it, so
4122    
4123           (a(?i)b)c           (a(?i)b)c
4124    
4125         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
4126         used).   By  this means, options can be made to have different settings         used).  By this means, options can be made to have  different  settings
4127         in different parts of the pattern. Any changes made in one  alternative         in  different parts of the pattern. Any changes made in one alternative
4128         do  carry  on  into subsequent branches within the same subpattern. For         do carry on into subsequent branches within the  same  subpattern.  For
4129         example,         example,
4130    
4131           (a(?i)b|c)           (a(?i)b|c)
4132    
4133         matches "ab", "aB", "c", and "C", even though  when  matching  "C"  the         matches  "ab",  "aB",  "c",  and "C", even though when matching "C" the
4134         first  branch  is  abandoned before the option setting. This is because         first branch is abandoned before the option setting.  This  is  because
4135         the effects of option settings happen at compile time. There  would  be         the  effects  of option settings happen at compile time. There would be
4136         some very weird behaviour otherwise.         some very weird behaviour otherwise.
4137    
4138         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
4139         application when the compile or match functions  are  called.  In  some         application  when  the  compile  or match functions are called. In some
4140         cases the pattern can contain special leading sequences such as (*CRLF)         cases the pattern can contain special leading sequences such as (*CRLF)
4141         to override what the application has set or what  has  been  defaulted.         to  override  what  the application has set or what has been defaulted.
4142         Details  are  given  in the section entitled "Newline sequences" above.         Details are given in the section entitled  "Newline  sequences"  above.
4143         There is also the (*UTF8) leading sequence that  can  be  used  to  set         There  are  also  the  (*UTF8) and (*UCP) leading sequences that can be
4144         UTF-8 mode; this is equivalent to setting the PCRE_UTF8 option.         used to set UTF-8 and Unicode property modes; they  are  equivalent  to
4145           setting the PCRE_UTF8 and the PCRE_UCP options, respectively.
4146    
4147    
4148  SUBPATTERNS  SUBPATTERNS
# Line 5144  BACKTRACKING CONTROL Line 5308  BACKTRACKING CONTROL
5308         tested.         tested.
5309    
5310         The  new verbs make use of what was previously invalid syntax: an open-         The  new verbs make use of what was previously invalid syntax: an open-
5311         ing parenthesis followed by an asterisk. In Perl, they are generally of         ing parenthesis followed by an asterisk. They are generally of the form
5312         the form (*VERB:ARG) but PCRE does not support the use of arguments, so         (*VERB)  or (*VERB:NAME). Some may take either form, with differing be-
5313         its general form is just (*VERB). Any number of these verbs  may  occur         haviour, depending on whether or not an argument is present. An name is
5314         in a pattern. There are two kinds:         a  sequence  of letters, digits, and underscores. If the name is empty,
5315           that is, if the closing parenthesis immediately follows the colon,  the
5316           effect is as if the colon were not there. Any number of these verbs may
5317           occur in a pattern.
5318    
5319           PCRE contains some optimizations that are used to speed up matching  by
5320           running some checks at the start of each match attempt. For example, it
5321           may know the minimum length of matching subject, or that  a  particular
5322           character  must  be present. When one of these optimizations suppresses
5323           the running of a match, any included backtracking verbs  will  not,  of
5324           course, be processed. You can suppress the start-of-match optimizations
5325           by setting the PCRE_NO_START_OPTIMIZE option when calling pcre_exec().
5326    
5327     Verbs that act immediately     Verbs that act immediately
5328    
5329         The following verbs act as soon as they are encountered:         The following verbs act as soon as they are encountered. They  may  not
5330           be followed by a name.
5331    
5332            (*ACCEPT)            (*ACCEPT)
5333    
# Line 5180  BACKTRACKING CONTROL Line 5356  BACKTRACKING CONTROL
5356         A  match  with the string "aaaa" always fails, but the callout is taken         A  match  with the string "aaaa" always fails, but the callout is taken
5357         before each backtrack happens (in this example, 10 times).         before each backtrack happens (in this example, 10 times).
5358    
5359       Recording which path was taken
5360    
5361           There is one verb whose main purpose  is  to  track  how  a  match  was
5362           arrived  at,  though  it  also  has a secondary use in conjunction with
5363           advancing the match starting point (see (*SKIP) below).
5364    
5365             (*MARK:NAME) or (*:NAME)
5366    
5367           A name is always  required  with  this  verb.  There  may  be  as  many
5368           instances  of  (*MARK) as you like in a pattern, and their names do not
5369           have to be unique.
5370    
5371           When a match succeeds, the name  of  the  last-encountered  (*MARK)  is
5372           passed  back  to  the  caller  via  the  pcre_extra  data structure, as
5373           described in the section on pcre_extra in the pcreapi documentation. No
5374           data  is  returned  for a partial match. Here is an example of pcretest
5375           output, where the /K modifier requests the retrieval and outputting  of
5376           (*MARK) data:
5377    
5378             /X(*MARK:A)Y|X(*MARK:B)Z/K
5379             XY
5380              0: XY
5381             MK: A
5382             XZ
5383              0: XZ
5384             MK: B
5385    
5386           The (*MARK) name is tagged with "MK:" in this output, and in this exam-
5387           ple it indicates which of the two alternatives matched. This is a  more
5388           efficient  way of obtaining this information than putting each alterna-
5389           tive in its own capturing parentheses.
5390    
5391           A name may also be returned after a failed  match  if  the  final  path
5392           through  the  pattern involves (*MARK). However, unless (*MARK) used in
5393           conjunction with (*COMMIT), this is unlikely to  happen  for  an  unan-
5394           chored pattern because, as the starting point for matching is advanced,
5395           the final check is often with an empty string, causing a failure before
5396           (*MARK) is reached. For example:
5397    
5398             /X(*MARK:A)Y|X(*MARK:B)Z/K
5399             XP
5400             No match
5401    
5402           There are three potential starting points for this match (starting with
5403           X, starting with P, and with  an  empty  string).  If  the  pattern  is
5404           anchored, the result is different:
5405    
5406             /^X(*MARK:A)Y|^X(*MARK:B)Z/K
5407             XP
5408             No match, mark = B
5409    
5410           PCRE's  start-of-match  optimizations can also interfere with this. For
5411           example, if, as a result of a call to pcre_study(), it knows the  mini-
5412           mum  subject  length for a match, a shorter subject will not be scanned
5413           at all.
5414    
5415           Note that similar anomalies (though different in detail) exist in Perl,
5416           no  doubt  for the same reasons. The use of (*MARK) data after a failed
5417           match of an unanchored pattern is not recommended, unless (*COMMIT)  is
5418           involved.
5419    
5420     Verbs that act after backtracking     Verbs that act after backtracking
5421    
5422         The following verbs do nothing when they are encountered. Matching con-         The following verbs do nothing when they are encountered. Matching con-
5423         tinues  with what follows, but if there is no subsequent match, a fail-         tinues with what follows, but if there is no subsequent match,  causing
5424         ure is forced.  The verbs  differ  in  exactly  what  kind  of  failure         a  backtrack  to  the  verb, a failure is forced. That is, backtracking
5425         occurs.         cannot pass to the left of the verb. However, when one of  these  verbs
5426           appears  inside  an atomic group, its effect is confined to that group,
5427           because once the group has been matched, there is never any  backtrack-
5428           ing  into  it.  In  this situation, backtracking can "jump back" to the
5429           left of the entire atomic group. (Remember also, as stated above,  that
5430           this localization also applies in subroutine calls and assertions.)
5431    
5432           These  verbs  differ  in exactly what kind of failure occurs when back-
5433           tracking reaches them.
5434    
5435           (*COMMIT)           (*COMMIT)
5436    
5437         This  verb  causes  the whole match to fail outright if the rest of the         This verb, which may not be followed by a name, causes the whole  match
5438         pattern does not match. Even if the pattern is unanchored,  no  further         to fail outright if the rest of the pattern does not match. Even if the
5439         attempts  to  find  a match by advancing the starting point take place.         pattern is unanchored, no further attempts to find a match by advancing
5440         Once (*COMMIT) has been passed, pcre_exec() is committed to  finding  a         the  starting  point  take  place.  Once  (*COMMIT)  has  been  passed,
5441         match at the current starting point, or not at all. For example:         pcre_exec() is committed to finding a match  at  the  current  starting
5442           point, or not at all. For example:
5443    
5444           a+(*COMMIT)b           a+(*COMMIT)b
5445    
5446         This  matches  "xxaab" but not "aacaab". It can be thought of as a kind         This  matches  "xxaab" but not "aacaab". It can be thought of as a kind
5447         of dynamic anchor, or "I've started, so I must finish."         of dynamic anchor, or "I've started, so I must finish." The name of the
5448           most  recently passed (*MARK) in the path is passed back when (*COMMIT)
5449           (*PRUNE)         forces a match failure.
5450    
5451           Note that (*COMMIT) at the start of a pattern is not  the  same  as  an
5452           anchor,  unless  PCRE's start-of-match optimizations are turned off, as
5453           shown in this pcretest example:
5454    
5455             /(*COMMIT)abc/
5456             xyzabc
5457              0: abc
5458             xyzabc\Y
5459             No match
5460    
5461         This verb causes the match to fail at the current position if the  rest         PCRE knows that any match must start  with  "a",  so  the  optimization
5462         of the pattern does not match. If the pattern is unanchored, the normal         skips  along the subject to "a" before running the first match attempt,
5463         "bumpalong" advance to the next starting character then happens.  Back-         which succeeds. When the optimization is disabled by the \Y  escape  in
5464         tracking  can  occur as usual to the left of (*PRUNE), or when matching         the second subject, the match starts at "x" and so the (*COMMIT) causes
5465         to the right of (*PRUNE), but if there is no match to the right,  back-         it to fail without trying any other starting points.
5466         tracking  cannot  cross (*PRUNE).  In simple cases, the use of (*PRUNE)  
5467         is just an alternative to an atomic group or possessive quantifier, but           (*PRUNE) or (*PRUNE:NAME)
5468         there  are  some uses of (*PRUNE) that cannot be expressed in any other  
5469         way.         This verb causes the match to fail at the current starting position  in
5470           the  subject  if the rest of the pattern does not match. If the pattern
5471           is unanchored, the normal "bumpalong"  advance  to  the  next  starting
5472           character  then happens. Backtracking can occur as usual to the left of
5473           (*PRUNE), before it is reached,  or  when  matching  to  the  right  of
5474           (*PRUNE),  but  if  there is no match to the right, backtracking cannot
5475           cross (*PRUNE). In simple cases, the use of (*PRUNE) is just an  alter-
5476           native  to an atomic group or possessive quantifier, but there are some
5477           uses of (*PRUNE) that cannot be expressed in any other way.  The behav-
5478           iour  of  (*PRUNE:NAME)  is  the  same as (*MARK:NAME)(*PRUNE) when the
5479           match fails completely; the name is passed back if this  is  the  final
5480           attempt.   (*PRUNE:NAME)  does  not  pass back a name if the match suc-
5481           ceeds. In an anchored pattern (*PRUNE) has the same  effect  as  (*COM-
5482           MIT).
5483    
5484           (*SKIP)           (*SKIP)
5485    
5486         This verb is like (*PRUNE), except that if the pattern  is  unanchored,         This  verb, when given without a name, is like (*PRUNE), except that if
5487         the  "bumpalong" advance is not to the next character, but to the posi-         the pattern is unanchored, the "bumpalong" advance is not to  the  next
5488         tion in the subject where (*SKIP) was  encountered.  (*SKIP)  signifies         character, but to the position in the subject where (*SKIP) was encoun-
5489         that  whatever  text  was  matched leading up to it cannot be part of a         tered. (*SKIP) signifies that whatever text was matched leading  up  to
5490         successful match. Consider:         it cannot be part of a successful match. Consider:
5491    
5492           a+(*SKIP)b           a+(*SKIP)b
5493    
5494         If the subject is "aaaac...",  after  the  first  match  attempt  fails         If  the  subject  is  "aaaac...",  after  the first match attempt fails
5495         (starting  at  the  first  character in the string), the starting point         (starting at the first character in the  string),  the  starting  point
5496         skips on to start the next attempt at "c". Note that a possessive quan-         skips on to start the next attempt at "c". Note that a possessive quan-
5497         tifer  does not have the same effect as this example; although it would         tifer does not have the same effect as this example; although it  would
5498         suppress backtracking  during  the  first  match  attempt,  the  second         suppress  backtracking  during  the  first  match  attempt,  the second
5499         attempt  would  start at the second character instead of skipping on to         attempt would start at the second character instead of skipping  on  to
5500         "c".         "c".
5501    
5502           (*THEN)           (*SKIP:NAME)
5503    
5504           When  (*SKIP) has an associated name, its behaviour is modified. If the
5505           following pattern fails to match, the previous path through the pattern
5506           is  searched for the most recent (*MARK) that has the same name. If one
5507           is found, the "bumpalong" advance is to the subject position that  cor-
5508           responds  to  that (*MARK) instead of to where (*SKIP) was encountered.
5509           If no (*MARK) with a matching name is found, normal "bumpalong" of  one
5510           character happens (the (*SKIP) is ignored).
5511    
5512             (*THEN) or (*THEN:NAME)
5513    
5514         This verb causes a skip to the next alternation if the rest of the pat-         This verb causes a skip to the next alternation if the rest of the pat-
5515         tern does not match. That is, it cancels pending backtracking, but only         tern does not match. That is, it cancels pending backtracking, but only
5516         within the current alternation. Its name  comes  from  the  observation         within  the  current  alternation.  Its name comes from the observation
5517         that it can be used for a pattern-based if-then-else block:         that it can be used for a pattern-based if-then-else block:
5518    
5519           ( COND1 (*THEN) FOO | COND2 (*THEN) BAR | COND3 (*THEN) BAZ ) ...           ( COND1 (*THEN) FOO | COND2 (*THEN) BAR | COND3 (*THEN) BAZ ) ...
5520    
5521         If  the COND1 pattern matches, FOO is tried (and possibly further items         If the COND1 pattern matches, FOO is tried (and possibly further  items
5522         after the end of the group if FOO succeeds);  on  failure  the  matcher         after  the  end  of  the group if FOO succeeds); on failure the matcher
5523         skips  to  the second alternative and tries COND2, without backtracking         skips to the second alternative and tries COND2,  without  backtracking
5524         into COND1. If (*THEN) is used outside  of  any  alternation,  it  acts         into  COND1.  The  behaviour  of  (*THEN:NAME)  is  exactly the same as
5525         exactly like (*PRUNE).         (*MARK:NAME)(*THEN) if the overall  match  fails.  If  (*THEN)  is  not
5526           directly inside an alternation, it acts like (*PRUNE).
5527    
5528    
5529  SEE ALSO  SEE ALSO
# Line 5260  AUTHOR Line 5540  AUTHOR
5540    
5541  REVISION  REVISION
5542    
5543         Last updated: 06 March 2010         Last updated: 18 May 2010
5544         Copyright (c) 1997-2010 University of Cambridge.         Copyright (c) 1997-2010 University of Cambridge.
5545  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
5546    
# Line 5308  CHARACTER TYPES Line 5588  CHARACTER TYPES
5588           \D         a character that is not a decimal digit           \D         a character that is not a decimal digit
5589           \h         a horizontal whitespace character           \h         a horizontal whitespace character
5590           \H         a character that is not a horizontal whitespace character           \H         a character that is not a horizontal whitespace character
5591             \N         a character that is not a newline
5592           \p{xx}     a character with the xx property           \p{xx}     a character with the xx property
5593           \P{xx}     a character without the xx property           \P{xx}     a character without the xx property
5594           \R         a newline sequence           \R         a newline sequence
# Line 5319  CHARACTER TYPES Line 5600  CHARACTER TYPES
5600           \W         a "non-word" character           \W         a "non-word" character
5601           \X         an extended Unicode sequence           \X         an extended Unicode sequence
5602    
5603         In PCRE, \d, \D, \s, \S, \w, and \W recognize only ASCII characters.         In  PCRE,  by  default, \d, \D, \s, \S, \w, and \W recognize only ASCII
5604           characters, even in UTF-8 mode. However, this can be changed by setting
5605           the PCRE_UCP option.
5606    
5607    
5608  GENERAL CATEGORY PROPERTY CODES FOR \p and \P  GENERAL CATEGORY PROPERTIES FOR \p and \P
5609    
5610           C          Other           C          Other
5611           Cc         Control           Cc         Control
# Line 5370  GENERAL CATEGORY PROPERTY CODES FOR \p a Line 5653  GENERAL CATEGORY PROPERTY CODES FOR \p a
5653           Zs         Space separator           Zs         Space separator
5654    
5655    
5656    PCRE SPECIAL CATEGORY PROPERTIES FOR \p and \P
5657    
5658             Xan        Alphanumeric: union of properties L and N
5659             Xps        POSIX space: property Z or tab, NL, VT, FF, CR
5660             Xsp        Perl space: property Z or tab, NL, FF, CR
5661             Xwd        Perl word: property Xan or underscore
5662    
5663    
5664  SCRIPT NAMES FOR \p AND \P  SCRIPT NAMES FOR \p AND \P
5665    
5666         Arabic, Armenian, Avestan, Balinese, Bamum, Bengali, Bopomofo, Braille,         Arabic, Armenian, Avestan, Balinese, Bamum, Bengali, Bopomofo, Braille,
# Line 5411  CHARACTER CLASSES Line 5702  CHARACTER CLASSES
5702           word        same as \w           word        same as \w
5703           xdigit      hexadecimal digit           xdigit      hexadecimal digit
5704    
5705         In PCRE, POSIX character set names recognize only ASCII characters. You         In PCRE, POSIX character set names recognize only ASCII  characters  by
5706         can use \Q...\E inside a character class.         default,  but  some  of them use Unicode properties if PCRE_UCP is set.
5707           You can use \Q...\E inside a character class.
5708    
5709    
5710  QUANTIFIERS  QUANTIFIERS
# Line 5437  QUANTIFIERS Line 5729  QUANTIFIERS
5729    
5730  ANCHORS AND SIMPLE ASSERTIONS  ANCHORS AND SIMPLE ASSERTIONS
5731    
5732           \b          word boundary (only ASCII letters recognized)           \b          word boundary
5733           \B          not a word boundary           \B          not a word boundary
5734           ^           start of subject           ^           start of subject
5735                        also after internal newline in multiline mode                        also after internal newline in multiline mode
# Line 5492  OPTION SETTING Line 5784  OPTION SETTING
5784           (?x)            extended (ignore white space)           (?x)            extended (ignore white space)
5785           (?-...)         unset option(s)           (?-...)         unset option(s)
5786    
5787         The following is recognized only at the start of a pattern or after one         The following are recognized only at the start of a  pattern  or  after
5788         of the newline-setting options with similar syntax:         one of the newline-setting options with similar syntax:
5789    
5790           (*UTF8)         set UTF-8 mode           (*UTF8)         set UTF-8 mode (PCRE_UTF8)
5791             (*UCP)          set PCRE_UCP (use Unicode properties for \d etc)
5792    
5793    
5794  LOOKAHEAD AND LOOKBEHIND ASSERTIONS  LOOKAHEAD AND LOOKBEHIND ASSERTIONS
# Line 5564  BACKTRACKING CONTROL Line 5857  BACKTRACKING CONTROL
5857           (*ACCEPT)       force successful match           (*ACCEPT)       force successful match
5858           (*FAIL)         force backtrack; synonym (*F)           (*FAIL)         force backtrack; synonym (*F)
5859    
5860         The following act only when a subsequent match failure causes  a  back-         The  following  act only when a subsequent match failure causes a back-
5861         track to reach them. They all force a match failure, but they differ in         track to reach them. They all force a match failure, but they differ in
5862         what happens afterwards. Those that advance the start-of-match point do         what happens afterwards. Those that advance the start-of-match point do
5863         so only if the pattern is not anchored.         so only if the pattern is not anchored.
# Line 5577  BACKTRACKING CONTROL Line 5870  BACKTRACKING CONTROL
5870    
5871  NEWLINE CONVENTIONS  NEWLINE CONVENTIONS
5872    
5873         These  are  recognized only at the very start of the pattern or after a         These are recognized only at the very start of the pattern or  after  a
5874         (*BSR_...) or (*UTF8) option.         (*BSR_...) or (*UTF8) or (*UCP) option.
5875    
5876           (*CR)           carriage return only           (*CR)           carriage return only
5877           (*LF)           linefeed only           (*LF)           linefeed only
# Line 5589  NEWLINE CONVENTIONS Line 5882  NEWLINE CONVENTIONS
5882    
5883  WHAT \R MATCHES  WHAT \R MATCHES
5884    
5885         These are recognized only at the very start of the pattern or  after  a         These  are  recognized only at the very start of the pattern or after a
5886         (*...) option that sets the newline convention or UTF-8 mode.         (*...) option that sets the newline convention or UTF-8 or UCP mode.
5887    
5888           (*BSR_ANYCRLF)  CR, LF, or CRLF           (*BSR_ANYCRLF)  CR, LF, or CRLF
5889           (*BSR_UNICODE)  any Unicode newline sequence           (*BSR_UNICODE)  any Unicode newline sequence
# Line 5616  AUTHOR Line 5909  AUTHOR
5909    
5910  REVISION  REVISION
5911    
5912         Last updated: 01 March 2010         Last updated: 12 May 2010
5913         Copyright (c) 1997-2010 University of Cambridge.         Copyright (c) 1997-2010 University of Cambridge.
5914  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
5915    
# Line 6217  PROCESSING TIME Line 6510  PROCESSING TIME
6510         If you can find an alternative pattern  that  does  not  use  character         If you can find an alternative pattern  that  does  not  use  character
6511         properties, it will probably be faster.         properties, it will probably be faster.
6512    
6513           By  default,  the  escape  sequences  \b, \d, \s, and \w, and the POSIX
6514           character classes such as [:alpha:]  do  not  use  Unicode  properties,
6515           partly for backwards compatibility, and partly for performance reasons.
6516           However, you can set PCRE_UCP if you want Unicode character  properties
6517           to  be  used.  This  can double the matching time for items such as \d,
6518           when matched with  pcre_exec();  the  performance  loss  is  less  with
6519           pcre_dfa_exec(), and in both cases there is not much difference for \b.
6520    
6521         When  a  pattern  begins  with .* not in parentheses, or in parentheses         When  a  pattern  begins  with .* not in parentheses, or in parentheses
6522         that are not the subject of a backreference, and the PCRE_DOTALL option         that are not the subject of a backreference, and the PCRE_DOTALL option
6523         is  set, the pattern is implicitly anchored by PCRE, since it can match         is  set, the pattern is implicitly anchored by PCRE, since it can match
# Line 6282  AUTHOR Line 6583  AUTHOR
6583    
6584  REVISION  REVISION
6585    
6586         Last updated: 07 March 2010         Last updated: 16 May 2010
6587         Copyright (c) 1997-2010 University of Cambridge.         Copyright (c) 1997-2010 University of Cambridge.
6588  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
6589    
# Line 6388  COMPILING A PATTERN Line 6689  COMPILING A PATTERN
6689         ing,  the  nmatch  and  pmatch  arguments  are ignored, and no captured         ing,  the  nmatch  and  pmatch  arguments  are ignored, and no captured
6690         strings are returned.         strings are returned.
6691    
6692             REG_UCP
6693    
6694           The PCRE_UCP option is set when the regular expression  is  passed  for
6695           compilation  to  the  native  function. This causes PCRE to use Unicode
6696           properties when matchine \d, \w,  etc.,  instead  of  just  recognizing
6697           ASCII values. Note that REG_UTF8 is not part of the POSIX standard.
6698    
6699           REG_UNGREEDY           REG_UNGREEDY
6700    
6701         The PCRE_UNGREEDY option is set when the regular expression  is  passed         The  PCRE_UNGREEDY  option is set when the regular expression is passed
6702         for  compilation  to the native function. Note that REG_UNGREEDY is not         for compilation to the native function. Note that REG_UNGREEDY  is  not
6703         part of the POSIX standard.         part of the POSIX standard.
6704    
6705           REG_UTF8           REG_UTF8
6706    
6707         The PCRE_UTF8 option is set when the regular expression is  passed  for         The  PCRE_UTF8  option is set when the regular expression is passed for
6708         compilation  to the native function. This causes the pattern itself and         compilation to the native function. This causes the pattern itself  and
6709         all data strings used for matching it to be treated as  UTF-8  strings.         all  data  strings used for matching it to be treated as UTF-8 strings.
6710         Note that REG_UTF8 is not part of the POSIX standard.         Note that REG_UTF8 is not part of the POSIX standard.
6711    
6712         In  the  absence  of  these  flags, no options are passed to the native         In the absence of these flags, no options  are  passed  to  the  native
6713         function.  This means the the  regex  is  compiled  with  PCRE  default         function.   This  means  the  the  regex  is compiled with PCRE default
6714         semantics.  In particular, the way it handles newline characters in the         semantics. In particular, the way it handles newline characters in  the
6715         subject string is the Perl way, not the POSIX way.  Note  that  setting         subject  string  is  the Perl way, not the POSIX way. Note that setting
6716         PCRE_MULTILINE  has only some of the effects specified for REG_NEWLINE.         PCRE_MULTILINE has only some of the effects specified for  REG_NEWLINE.
6717         It does not affect the way newlines are matched by . (they are not)  or         It  does not affect the way newlines are matched by . (they are not) or
6718         by a negative class such as [^a] (they are).         by a negative class such as [^a] (they are).
6719    
6720         The  yield of regcomp() is zero on success, and non-zero otherwise. The         The yield of regcomp() is zero on success, and non-zero otherwise.  The
6721         preg structure is filled in on success, and one member of the structure         preg structure is filled in on success, and one member of the structure
6722         is  public: re_nsub contains the number of capturing subpatterns in the         is public: re_nsub contains the number of capturing subpatterns in  the
6723         regular expression. Various error codes are defined in the header file.         regular expression. Various error codes are defined in the header file.
6724    
6725         NOTE: If the yield of regcomp() is non-zero, you must  not  attempt  to         NOTE:  If  the  yield of regcomp() is non-zero, you must not attempt to
6726         use the contents of the preg structure. If, for example, you pass it to         use the contents of the preg structure. If, for example, you pass it to
6727         regexec(), the result is undefined and your program is likely to crash.         regexec(), the result is undefined and your program is likely to crash.
6728    
# Line 6422  COMPILING A PATTERN Line 6730  COMPILING A PATTERN
6730  MATCHING NEWLINE CHARACTERS  MATCHING NEWLINE CHARACTERS
6731    
6732         This area is not simple, because POSIX and Perl take different views of         This area is not simple, because POSIX and Perl take different views of
6733         things.   It  is  not possible to get PCRE to obey POSIX semantics, but         things.  It is not possible to get PCRE to obey  POSIX  semantics,  but
6734         then PCRE was never intended to be a POSIX engine. The following  table         then  PCRE was never intended to be a POSIX engine. The following table
6735         lists  the  different  possibilities for matching newline characters in         lists the different possibilities for matching  newline  characters  in
6736         PCRE:         PCRE:
6737    
6738                                   Default   Change with                                   Default   Change with
# Line 6446  MATCHING NEWLINE CHARACTERS Line 6754  MATCHING NEWLINE CHARACTERS
6754           ^ matches \n in middle     no     REG_NEWLINE           ^ matches \n in middle     no     REG_NEWLINE
6755    
6756         PCRE's behaviour is the same as Perl's, except that there is no equiva-         PCRE's behaviour is the same as Perl's, except that there is no equiva-
6757         lent  for  PCRE_DOLLAR_ENDONLY in Perl. In both PCRE and Perl, there is         lent for PCRE_DOLLAR_ENDONLY in Perl. In both PCRE and Perl,  there  is
6758         no way to stop newline from matching [^a].         no way to stop newline from matching [^a].
6759    
6760         The  default  POSIX  newline  handling  can  be  obtained  by   setting         The   default  POSIX  newline  handling  can  be  obtained  by  setting
6761         PCRE_DOTALL  and  PCRE_DOLLAR_ENDONLY, but there is no way to make PCRE         PCRE_DOTALL and PCRE_DOLLAR_ENDONLY, but there is no way to  make  PCRE
6762         behave exactly as for the REG_NEWLINE action.         behave exactly as for the REG_NEWLINE action.
6763    
6764    
6765  MATCHING A PATTERN  MATCHING A PATTERN
6766    
6767         The function regexec() is called  to  match  a  compiled  pattern  preg         The  function  regexec()  is  called  to  match a compiled pattern preg
6768         against  a  given string, which is by default terminated by a zero byte         against a given string, which is by default terminated by a  zero  byte
6769         (but see REG_STARTEND below), subject to the options in  eflags.  These         (but  see  REG_STARTEND below), subject to the options in eflags. These
6770         can be:         can be:
6771    
6772           REG_NOTBOL           REG_NOTBOL
# Line 6480  MATCHING A PATTERN Line 6788  MATCHING A PATTERN
6788    
6789           REG_STARTEND           REG_STARTEND
6790    
6791         The string is considered to start at string +  pmatch[0].rm_so  and  to         The  string  is  considered to start at string + pmatch[0].rm_so and to
6792         have  a terminating NUL located at string + pmatch[0].rm_eo (there need         have a terminating NUL located at string + pmatch[0].rm_eo (there  need
6793         not actually be a NUL at that location), regardless  of  the  value  of         not  actually  be  a  NUL at that location), regardless of the value of
6794         nmatch.  This  is a BSD extension, compatible with but not specified by         nmatch. This is a BSD extension, compatible with but not  specified  by
6795         IEEE Standard 1003.2 (POSIX.2), and should  be  used  with  caution  in         IEEE  Standard  1003.2  (POSIX.2),  and  should be used with caution in
6796         software intended to be portable to other systems. Note that a non-zero         software intended to be portable to other systems. Note that a non-zero
6797         rm_so does not imply REG_NOTBOL; REG_STARTEND affects only the location         rm_so does not imply REG_NOTBOL; REG_STARTEND affects only the location
6798         of the string, not how it is matched.         of the string, not how it is matched.
6799    
6800         If  the pattern was compiled with the REG_NOSUB flag, no data about any         If the pattern was compiled with the REG_NOSUB flag, no data about  any
6801         matched strings  is  returned.  The  nmatch  and  pmatch  arguments  of         matched  strings  is  returned.  The  nmatch  and  pmatch  arguments of
6802         regexec() are ignored.         regexec() are ignored.
6803    
6804         If the value of nmatch is zero, or if the value pmatch is NULL, no data         If the value of nmatch is zero, or if the value pmatch is NULL, no data
# Line 6498  MATCHING A PATTERN Line 6806  MATCHING A PATTERN
6806    
6807         Otherwise,the portion of the string that was matched, and also any cap-         Otherwise,the portion of the string that was matched, and also any cap-
6808         tured substrings, are returned via the pmatch argument, which points to         tured substrings, are returned via the pmatch argument, which points to
6809         an array of nmatch structures of type regmatch_t, containing  the  mem-         an  array  of nmatch structures of type regmatch_t, containing the mem-
6810         bers  rm_so  and rm_eo. These contain the offset to the first character         bers rm_so and rm_eo. These contain the offset to the  first  character
6811         of each substring and the offset to the first character after  the  end         of  each  substring and the offset to the first character after the end
6812         of  each substring, respectively. The 0th element of the vector relates         of each substring, respectively. The 0th element of the vector  relates
6813         to the entire portion of string that was matched;  subsequent  elements         to  the  entire portion of string that was matched; subsequent elements
6814         relate  to  the capturing subpatterns of the regular expression. Unused         relate to the capturing subpatterns of the regular  expression.  Unused
6815         entries in the array have both structure members set to -1.         entries in the array have both structure members set to -1.
6816    
6817         A successful match yields  a  zero  return;  various  error  codes  are         A  successful  match  yields  a  zero  return;  various error codes are
6818         defined  in  the  header  file,  of which REG_NOMATCH is the "expected"         defined in the header file, of  which  REG_NOMATCH  is  the  "expected"
6819         failure code.         failure code.
6820    
6821    
6822  ERROR MESSAGES  ERROR MESSAGES
6823    
6824         The regerror() function maps a non-zero errorcode from either regcomp()         The regerror() function maps a non-zero errorcode from either regcomp()
6825         or  regexec()  to  a  printable message. If preg is not NULL, the error         or regexec() to a printable message. If preg is  not  NULL,  the  error
6826         should have arisen from the use of that structure. A message terminated         should have arisen from the use of that structure. A message terminated
6827         by  a  binary  zero  is  placed  in  errbuf. The length of the message,         by a binary zero is placed  in  errbuf.  The  length  of  the  message,
6828         including the zero, is limited to errbuf_size. The yield of  the  func-         including  the  zero, is limited to errbuf_size. The yield of the func-
6829         tion is the size of buffer needed to hold the whole message.         tion is the size of buffer needed to hold the whole message.
6830    
6831    
6832  MEMORY USAGE  MEMORY USAGE
6833    
6834         Compiling  a regular expression causes memory to be allocated and asso-         Compiling a regular expression causes memory to be allocated and  asso-
6835         ciated with the preg structure. The function regfree() frees  all  such         ciated  with  the preg structure. The function regfree() frees all such
6836         memory,  after  which  preg may no longer be used as a compiled expres-         memory, after which preg may no longer be used as  a  compiled  expres-
6837         sion.         sion.
6838    
6839    
# Line 6538  AUTHOR Line 6846  AUTHOR
6846    
6847  REVISION  REVISION
6848    
6849         Last updated: 02 September 2009         Last updated: 16 May 2010
6850         Copyright (c) 1997-2009 University of Cambridge.         Copyright (c) 1997-2010 University of Cambridge.
6851  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
6852    
6853    
# Line 6925  PCRE SAMPLE PROGRAM Line 7233  PCRE SAMPLE PROGRAM
7233           gcc -o pcredemo -I/usr/local/include pcredemo.c \           gcc -o pcredemo -I/usr/local/include pcredemo.c \
7234               -L/usr/local/lib -lpcre               -L/usr/local/lib -lpcre
7235    
7236         Once you have compiled the demonstration program, you  can  run  simple         In a Windows environment, if you want to statically  link  the  program
7237         tests like this:         against a non-dll pcre.a file, you must uncomment the line that defines
7238           PCRE_STATIC before including pcre.h, because  otherwise  the  pcre_mal-
7239           loc()   and   pcre_free()   exported   functions   will   be   declared
7240           __declspec(dllimport), with unwanted results.
7241    
7242           Once you have compiled and linked the demonstration  program,  you  can
7243           run simple tests like this:
7244    
7245           ./pcredemo 'cat|dog' 'the cat sat on the mat'           ./pcredemo 'cat|dog' 'the cat sat on the mat'
7246           ./pcredemo -g 'cat|dog' 'the dog sat on the cat'           ./pcredemo -g 'cat|dog' 'the dog sat on the cat'
# Line 6960  AUTHOR Line 7274  AUTHOR
7274    
7275  REVISION  REVISION
7276    
7277         Last updated: 30 September 2009         Last updated: 26 May 2010
7278         Copyright (c) 1997-2009 University of Cambridge.         Copyright (c) 1997-2010 University of Cambridge.
7279  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
7280  PCRESTACK(3)                                                      PCRESTACK(3)  PCRESTACK(3)                                                      PCRESTACK(3)
7281    

Legend:
Removed from v.507  
changed lines
  Added in v.548

  ViewVC Help
Powered by ViewVC 1.1.5