/[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 289 by ph10, Sun Dec 23 12:17:20 2007 UTC revision 358 by ph10, Wed Jul 9 11:03:07 2008 UTC
# Line 18  INTRODUCTION Line 18  INTRODUCTION
18    
19         The  PCRE  library is a set of functions that implement regular expres-         The  PCRE  library is a set of functions that implement regular expres-
20         sion pattern matching using the same syntax and semantics as Perl, with         sion pattern matching using the same syntax and semantics as Perl, with
21         just  a  few differences. (Certain features that appeared in Python and         just  a  few  differences. Certain features that appeared in Python and
22         PCRE before they appeared in Perl are also available using  the  Python         PCRE before they appeared in Perl are also available using  the  Python
23         syntax.)         syntax.  There is also some support for certain .NET and Oniguruma syn-
24           tax items, and there is an option for  requesting  some  minor  changes
25           that give better JavaScript compatibility.
26    
27         The  current  implementation of PCRE (release 7.x) corresponds approxi-         The  current  implementation of PCRE (release 7.x) corresponds approxi-
28         mately with Perl 5.10, including support for UTF-8 encoded strings  and         mately with Perl 5.10, including support for UTF-8 encoded strings  and
# Line 256  AUTHOR Line 258  AUTHOR
258    
259  REVISION  REVISION
260    
261         Last updated: 09 August 2007         Last updated: 12 April 2008
262         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
263  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
264    
265    
# Line 543  PCRETEST OPTION FOR LIBREADLINE SUPPORT Line 545  PCRETEST OPTION FOR LIBREADLINE SUPPORT
545         Note that libreadline is GPL-licenced, so if you distribute a binary of         Note that libreadline is GPL-licenced, so if you distribute a binary of
546         pcretest linked in this way, there may be licensing issues.         pcretest linked in this way, there may be licensing issues.
547    
548           Setting  this  option  causes  the -lreadline option to be added to the
549           pcretest build. In many operating environments with  a  sytem-installed
550           libreadline this is sufficient. However, in some environments (e.g.  if
551           an unmodified distribution version of readline is in use),  some  extra
552           configuration  may  be necessary. The INSTALL file for libreadline says
553           this:
554    
555             "Readline uses the termcap functions, but does not link with the
556             termcap or curses library itself, allowing applications which link
557             with readline the to choose an appropriate library."
558    
559           If your environment has not been set up so that an appropriate  library
560           is automatically included, you may need to add something like
561    
562             LIBS="-ncurses"
563    
564           immediately before the configure command.
565    
566    
567  SEE ALSO  SEE ALSO
568    
# Line 558  AUTHOR Line 578  AUTHOR
578    
579  REVISION  REVISION
580    
581         Last updated: 18 December 2007         Last updated: 13 April 2008
582         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
583  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
584    
585    
# Line 707  THE ALTERNATIVE MATCHING ALGORITHM Line 727  THE ALTERNATIVE MATCHING ALGORITHM
727         tive algorithm moves through the subject  string  one  character  at  a         tive algorithm moves through the subject  string  one  character  at  a
728         time, for all active paths through the tree.         time, for all active paths through the tree.
729    
730         8.  None  of  the  backtracking control verbs such as (*PRUNE) are sup-         8.  Except for (*FAIL), the backtracking control verbs such as (*PRUNE)
731         ported.         are not supported. (*FAIL) is supported, and  behaves  like  a  failing
732           negative assertion.
733    
734    
735  ADVANTAGES OF THE ALTERNATIVE ALGORITHM  ADVANTAGES OF THE ALTERNATIVE ALGORITHM
736    
737         Using the alternative matching algorithm provides the following  advan-         Using  the alternative matching algorithm provides the following advan-
738         tages:         tages:
739    
740         1. All possible matches (at a single point in the subject) are automat-         1. All possible matches (at a single point in the subject) are automat-
741         ically found, and in particular, the longest match is  found.  To  find         ically  found,  and  in particular, the longest match is found. To find
742         more than one match using the standard algorithm, you have to do kludgy         more than one match using the standard algorithm, you have to do kludgy
743         things with callouts.         things with callouts.
744    
745         2. There is much better support for partial matching. The  restrictions         2.  There is much better support for partial matching. The restrictions
746         on  the content of the pattern that apply when using the standard algo-         on the content of the pattern that apply when using the standard  algo-
747         rithm for partial matching do not apply to the  alternative  algorithm.         rithm  for  partial matching do not apply to the alternative algorithm.
748         For  non-anchored patterns, the starting position of a partial match is         For non-anchored patterns, the starting position of a partial match  is
749         available.         available.
750    
751         3. Because the alternative algorithm  scans  the  subject  string  just         3.  Because  the  alternative  algorithm  scans the subject string just
752         once,  and  never  needs to backtrack, it is possible to pass very long         once, and never needs to backtrack, it is possible to  pass  very  long
753         subject strings to the matching function in  several  pieces,  checking         subject  strings  to  the matching function in several pieces, checking
754         for partial matching each time.         for partial matching each time.
755    
756    
# Line 737  DISADVANTAGES OF THE ALTERNATIVE ALGORIT Line 758  DISADVANTAGES OF THE ALTERNATIVE ALGORIT
758    
759         The alternative algorithm suffers from a number of disadvantages:         The alternative algorithm suffers from a number of disadvantages:
760    
761         1.  It  is  substantially  slower  than the standard algorithm. This is         1. It is substantially slower than  the  standard  algorithm.  This  is
762         partly because it has to search for all possible matches, but  is  also         partly  because  it has to search for all possible matches, but is also
763         because it is less susceptible to optimization.         because it is less susceptible to optimization.
764    
765         2. Capturing parentheses and back references are not supported.         2. Capturing parentheses and back references are not supported.
# Line 756  AUTHOR Line 777  AUTHOR
777    
778  REVISION  REVISION
779    
780         Last updated: 08 August 2007         Last updated: 19 April 2008
781         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
782  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
783    
784    
# Line 869  PCRE API OVERVIEW Line 890  PCRE API OVERVIEW
890         a  Perl-compatible  manner. A sample program that demonstrates the sim-         a  Perl-compatible  manner. A sample program that demonstrates the sim-
891         plest way of using them is provided in the file  called  pcredemo.c  in         plest way of using them is provided in the file  called  pcredemo.c  in
892         the  source distribution. The pcresample documentation describes how to         the  source distribution. The pcresample documentation describes how to
893         run it.         compile and run it.
894    
895         A second matching function, pcre_dfa_exec(), which is not Perl-compati-         A second matching function, pcre_dfa_exec(), which is not Perl-compati-
896         ble,  is  also provided. This uses a different algorithm for the match-         ble,  is  also provided. This uses a different algorithm for the match-
# Line 1244  COMPILING A PATTERN Line 1265  COMPILING A PATTERN
1265         before or at the first  newline  in  the  subject  string,  though  the         before or at the first  newline  in  the  subject  string,  though  the
1266         matched text may continue over the newline.         matched text may continue over the newline.
1267    
1268             PCRE_JAVASCRIPT_COMPAT
1269    
1270           If this option is set, PCRE's behaviour is changed in some ways so that
1271           it is compatible with JavaScript rather than Perl. The changes  are  as
1272           follows:
1273    
1274           (1)  A  lone  closing square bracket in a pattern causes a compile-time
1275           error, because this is illegal in JavaScript (by default it is  treated
1276           as a data character). Thus, the pattern AB]CD becomes illegal when this
1277           option is set.
1278    
1279           (2) At run time, a back reference to an unset subpattern group  matches
1280           an  empty  string (by default this causes the current matching alterna-
1281           tive to fail). A pattern such as (\1)(a) succeeds when this  option  is
1282           set  (assuming  it can find an "a" in the subject), whereas it fails by
1283           default, for Perl compatibility.
1284    
1285           PCRE_MULTILINE           PCRE_MULTILINE
1286    
1287         By  default,  PCRE  treats the subject string as consisting of a single         By default, PCRE treats the subject string as consisting  of  a  single
1288         line of characters (even if it actually contains newlines). The  "start         line  of characters (even if it actually contains newlines). The "start
1289         of  line"  metacharacter  (^)  matches only at the start of the string,         of line" metacharacter (^) matches only at the  start  of  the  string,
1290         while the "end of line" metacharacter ($) matches only at  the  end  of         while  the  "end  of line" metacharacter ($) matches only at the end of
1291         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY         the string, or before a terminating newline (unless PCRE_DOLLAR_ENDONLY
1292         is set). This is the same as Perl.         is set). This is the same as Perl.
1293    
1294         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"
1295         constructs  match  immediately following or immediately before internal         constructs match immediately following or immediately  before  internal
1296         newlines in the subject string, respectively, as well as  at  the  very         newlines  in  the  subject string, respectively, as well as at the very
1297         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
1298         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-
1299         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,
1300         setting PCRE_MULTILINE has no effect.         setting PCRE_MULTILINE has no effect.
1301    
1302           PCRE_NEWLINE_CR           PCRE_NEWLINE_CR
# Line 1267  COMPILING A PATTERN Line 1305  COMPILING A PATTERN
1305           PCRE_NEWLINE_ANYCRLF           PCRE_NEWLINE_ANYCRLF
1306           PCRE_NEWLINE_ANY           PCRE_NEWLINE_ANY
1307    
1308         These options override the default newline definition that  was  chosen         These  options  override the default newline definition that was chosen
1309         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
1310         newline is indicated by a single character (CR  or  LF,  respectively).         newline  is  indicated  by a single character (CR or LF, respectively).
1311         Setting  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the         Setting PCRE_NEWLINE_CRLF specifies that a newline is indicated by  the
1312         two-character CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF  specifies         two-character  CRLF  sequence.  Setting  PCRE_NEWLINE_ANYCRLF specifies
1313         that any of the three preceding sequences should be recognized. Setting         that any of the three preceding sequences should be recognized. Setting
1314         PCRE_NEWLINE_ANY specifies that any Unicode newline sequence should  be         PCRE_NEWLINE_ANY  specifies that any Unicode newline sequence should be
1315         recognized. The Unicode newline sequences are the three just mentioned,         recognized. The Unicode newline sequences are the three just mentioned,
1316         plus the single characters VT (vertical  tab,  U+000B),  FF  (formfeed,         plus  the  single  characters  VT (vertical tab, U+000B), FF (formfeed,
1317         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
1318         (paragraph separator, U+2029). The last  two  are  recognized  only  in         (paragraph  separator,  U+2029).  The  last  two are recognized only in
1319         UTF-8 mode.         UTF-8 mode.
1320    
1321         The  newline  setting  in  the  options  word  uses three bits that are         The newline setting in the  options  word  uses  three  bits  that  are
1322         treated as a number, giving eight possibilities. Currently only six are         treated as a number, giving eight possibilities. Currently only six are
1323         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
1324         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-
1325         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
1326         PCRE_NEWLINE_CRLF, but other combinations may yield unused numbers  and         PCRE_NEWLINE_CRLF,  but other combinations may yield unused numbers and
1327         cause an error.         cause an error.
1328    
1329         The  only time that a line break is specially recognized when compiling         The only time that a line break is specially recognized when  compiling
1330         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
1331         character  class  is  encountered.  This indicates a comment that lasts         character class is encountered. This indicates  a  comment  that  lasts
1332         until after the next line break sequence. In other circumstances,  line         until  after the next line break sequence. In other circumstances, line
1333         break   sequences   are   treated  as  literal  data,  except  that  in         break  sequences  are  treated  as  literal  data,   except   that   in
1334         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters         PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters
1335         and are therefore ignored.         and are therefore ignored.
1336    
1337         The newline option that is set at compile time becomes the default that         The newline option that is set at compile time becomes the default that
1338         is used for pcre_exec() and pcre_dfa_exec(), but it can be  overridden.         is  used for pcre_exec() and pcre_dfa_exec(), but it can be overridden.
1339    
1340           PCRE_NO_AUTO_CAPTURE           PCRE_NO_AUTO_CAPTURE
1341    
1342         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-
1343         theses in the pattern. Any opening parenthesis that is not followed  by         theses  in the pattern. Any opening parenthesis that is not followed by
1344         ?  behaves as if it were followed by ?: but named parentheses can still         ? behaves as if it were followed by ?: but named parentheses can  still
1345         be used for capturing (and they acquire  numbers  in  the  usual  way).         be  used  for  capturing  (and  they acquire numbers in the usual way).
1346         There is no equivalent of this option in Perl.         There is no equivalent of this option in Perl.
1347    
1348           PCRE_UNGREEDY           PCRE_UNGREEDY
1349    
1350         This  option  inverts  the "greediness" of the quantifiers so that they         This option inverts the "greediness" of the quantifiers  so  that  they
1351         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
1352         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
1353         within the pattern.         within the pattern.
1354    
1355           PCRE_UTF8           PCRE_UTF8
1356    
1357         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
1358         strings  of  UTF-8 characters instead of single-byte character strings.         strings of UTF-8 characters instead of single-byte  character  strings.
1359         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-
1360         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
1361         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
1362         UTF-8 support in the main pcre page.         UTF-8 support in the main pcre page.
1363    
1364           PCRE_NO_UTF8_CHECK           PCRE_NO_UTF8_CHECK
1365    
1366         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
1367         automatically checked. There is a  discussion  about  the  validity  of         automatically  checked.  There  is  a  discussion about the validity of
1368         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
1369         bytes is found, pcre_compile() returns an error. If  you  already  know         bytes  is  found,  pcre_compile() returns an error. If you already know
1370         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-
1371         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
1372         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
1373         undefined. It may cause your program to crash. Note  that  this  option         undefined.  It  may  cause your program to crash. Note that this option
1374         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
1375         UTF-8 validity checking of subject strings.         UTF-8 validity checking of subject strings.
1376    
1377    
1378  COMPILATION ERROR CODES  COMPILATION ERROR CODES
1379    
1380         The following table lists the error  codes  than  may  be  returned  by         The  following  table  lists  the  error  codes than may be returned by
1381         pcre_compile2(),  along with the error messages that may be returned by         pcre_compile2(), along with the error messages that may be returned  by
1382         both compiling functions. As PCRE has developed, some error codes  have         both  compiling functions. As PCRE has developed, some error codes have
1383         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.
1384    
1385            0  no error            0  no error
# Line 1356  COMPILATION ERROR CODES Line 1394  COMPILATION ERROR CODES
1394            9  nothing to repeat            9  nothing to repeat
1395           10  [this code is not in use]           10  [this code is not in use]
1396           11  internal error: unexpected repeat           11  internal error: unexpected repeat
1397           12  unrecognized character after (?           12  unrecognized character after (? or (?-
1398           13  POSIX named classes are supported only within a class           13  POSIX named classes are supported only within a class
1399           14  missing )           14  missing )
1400           15  reference to non-existent subpattern           15  reference to non-existent subpattern
# Line 1364  COMPILATION ERROR CODES Line 1402  COMPILATION ERROR CODES
1402           17  unknown option bit(s) set           17  unknown option bit(s) set
1403           18  missing ) after comment           18  missing ) after comment
1404           19  [this code is not in use]           19  [this code is not in use]
1405           20  regular expression too large           20  regular expression is too large
1406           21  failed to get memory           21  failed to get memory
1407           22  unmatched parentheses           22  unmatched parentheses
1408           23  internal error: code overflow           23  internal error: code overflow
# Line 1393  COMPILATION ERROR CODES Line 1431  COMPILATION ERROR CODES
1431           46  malformed \P or \p sequence           46  malformed \P or \p sequence
1432           47  unknown property name after \P or \p           47  unknown property name after \P or \p
1433           48  subpattern name is too long (maximum 32 characters)           48  subpattern name is too long (maximum 32 characters)
1434           49  too many named subpatterns (maximum 10,000)           49  too many named subpatterns (maximum 10000)
1435           50  [this code is not in use]           50  [this code is not in use]
1436           51  octal value is greater than \377 (not in UTF-8 mode)           51  octal value is greater than \377 (not in UTF-8 mode)
1437           52  internal error: overran compiling workspace           52  internal error: overran compiling workspace
1438           53   internal  error:  previously-checked  referenced  subpattern not           53  internal  error:  previously-checked  referenced  subpattern  not
1439         found         found
1440           54  DEFINE group contains more than one branch           54  DEFINE group contains more than one branch
1441           55  repeating a DEFINE group is not allowed           55  repeating a DEFINE group is not allowed
1442           56  inconsistent NEWLINE options           56  inconsistent NEWLINE options
1443           57  \g is not followed by a braced name or an optionally braced           57  \g is not followed by a braced, angle-bracketed, or quoted
1444                 non-zero number                 name/number or by a plain number
1445           58  (?+ or (?- or (?(+ or (?(- must be followed by a non-zero number           58  a numbered reference must not be zero
1446             59  (*VERB) with an argument is not supported
1447             60  (*VERB) not recognized
1448             61  number is too big
1449             62  subpattern name expected
1450             63  digit expected after (?+
1451             64  ] is an invalid data character in JavaScript compatibility mode
1452    
1453           The  numbers  32  and 10000 in errors 48 and 49 are defaults; different
1454           values may be used if the limits were changed when PCRE was built.
1455    
1456    
1457  STUDYING A PATTERN  STUDYING A PATTERN
# Line 2557  AUTHOR Line 2604  AUTHOR
2604    
2605  REVISION  REVISION
2606    
2607         Last updated: 27 November 2007         Last updated: 12 April 2008
2608         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
2609  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
2610    
2611    
# Line 2885  PCRE REGULAR EXPRESSION DETAILS Line 2932  PCRE REGULAR EXPRESSION DETAILS
2932    
2933         The  syntax and semantics of the regular expressions that are supported         The  syntax and semantics of the regular expressions that are supported
2934         by PCRE are described in detail below. There is a quick-reference  syn-         by PCRE are described in detail below. There is a quick-reference  syn-
2935         tax  summary  in  the  pcresyntax  page. Perl's regular expressions are         tax summary in the pcresyntax page. PCRE tries to match Perl syntax and
2936         described in its own documentation, and regular expressions in  general         semantics as closely as it can. PCRE  also  supports  some  alternative
2937         are  covered in a number of books, some of which have copious examples.         regular  expression  syntax (which does not conflict with the Perl syn-
2938         Jeffrey  Friedl's  "Mastering  Regular   Expressions",   published   by         tax) in order to provide some compatibility with regular expressions in
2939         O'Reilly,  covers regular expressions in great detail. This description         Python, .NET, and Oniguruma.
2940         of PCRE's regular expressions is intended as reference material.  
2941           Perl's  regular expressions are described in its own documentation, and
2942           regular expressions in general are covered in a number of  books,  some
2943           of  which  have  copious  examples. Jeffrey Friedl's "Mastering Regular
2944           Expressions", published by  O'Reilly,  covers  regular  expressions  in
2945           great  detail.  This  description  of  PCRE's  regular  expressions  is
2946           intended as reference material.
2947    
2948         The original operation of PCRE was on strings of  one-byte  characters.         The original operation of PCRE was on strings of  one-byte  characters.
2949         However,  there is now also support for UTF-8 character strings. To use         However,  there is now also support for UTF-8 character strings. To use
# Line 3137  BACKSLASH Line 3190  BACKSLASH
3190         named back reference can be coded as \g{name}. Back references are dis-         named back reference can be coded as \g{name}. Back references are dis-
3191         cussed later, following the discussion of parenthesized subpatterns.         cussed later, following the discussion of parenthesized subpatterns.
3192    
3193       Absolute and relative subroutine calls
3194    
3195           For  compatibility with Oniguruma, the non-Perl syntax \g followed by a
3196           name or a number enclosed either in angle brackets or single quotes, is
3197           an  alternative  syntax for referencing a subpattern as a "subroutine".
3198           Details are discussed later.   Note  that  \g{...}  (Perl  syntax)  and
3199           \g<...>  (Oniguruma  syntax)  are  not synonymous. The former is a back
3200           reference; the latter is a subroutine call.
3201    
3202     Generic character types     Generic character types
3203    
3204         Another use of backslash is for specifying generic character types. The         Another use of backslash is for specifying generic character types. The
# Line 3154  BACKSLASH Line 3216  BACKSLASH
3216           \W     any "non-word" character           \W     any "non-word" character
3217    
3218         Each pair of escape sequences partitions the complete set of characters         Each pair of escape sequences partitions the complete set of characters
3219         into  two disjoint sets. Any given character matches one, and only one,         into two disjoint sets. Any given character matches one, and only  one,
3220         of each pair.         of each pair.
3221    
3222         These character type sequences can appear both inside and outside char-         These character type sequences can appear both inside and outside char-
3223         acter  classes.  They each match one character of the appropriate type.         acter classes. They each match one character of the  appropriate  type.
3224         If the current matching point is at the end of the subject string,  all         If  the current matching point is at the end of the subject string, all
3225         of them fail, since there is no character to match.         of them fail, since there is no character to match.
3226    
3227         For  compatibility  with Perl, \s does not match the VT character (code         For compatibility with Perl, \s does not match the VT  character  (code
3228         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
3229         characters  are  HT  (9), LF (10), FF (12), CR (13), and space (32). If         characters are HT (9), LF (10), FF (12), CR (13), and  space  (32).  If
3230         "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-
3231         ter. In PCRE, it never does.         ter. In PCRE, it never does.
3232    
3233         In  UTF-8 mode, characters with values greater than 128 never match \d,         In UTF-8 mode, characters with values greater than 128 never match  \d,
3234         \s, or \w, and always match \D, \S, and \W. This is true even when Uni-         \s, or \w, and always match \D, \S, and \W. This is true even when Uni-
3235         code  character  property  support is available. These sequences retain         code character property support is available.  These  sequences  retain
3236         their original meanings from before UTF-8 support was available, mainly         their original meanings from before UTF-8 support was available, mainly
3237         for efficiency reasons.         for efficiency reasons.
3238    
3239         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
3240         the other sequences, these do match certain high-valued  codepoints  in         the  other  sequences, these do match certain high-valued codepoints in
3241         UTF-8 mode.  The horizontal space characters are:         UTF-8 mode.  The horizontal space characters are:
3242    
3243           U+0009     Horizontal tab           U+0009     Horizontal tab
# Line 3209  BACKSLASH Line 3271  BACKSLASH
3271           U+2029     Paragraph separator           U+2029     Paragraph separator
3272    
3273         A "word" character is an underscore or any character less than 256 that         A "word" character is an underscore or any character less than 256 that
3274         is a letter or digit. The definition of  letters  and  digits  is  con-         is  a  letter  or  digit.  The definition of letters and digits is con-
3275         trolled  by PCRE's low-valued character tables, and may vary if locale-         trolled by PCRE's low-valued character tables, and may vary if  locale-
3276         specific matching is taking place (see "Locale support" in the  pcreapi         specific  matching is taking place (see "Locale support" in the pcreapi
3277         page).  For  example,  in  a French locale such as "fr_FR" in Unix-like         page). For example, in a French locale such  as  "fr_FR"  in  Unix-like
3278         systems, or "french" in Windows, some character codes greater than  128         systems,  or "french" in Windows, some character codes greater than 128
3279         are  used for accented letters, and these are matched by \w. The use of         are used for accented letters, and these are matched by \w. The use  of
3280         locales with Unicode is discouraged.         locales with Unicode is discouraged.
3281    
3282     Newline sequences     Newline sequences
3283    
3284         Outside a character class, by default, the escape sequence  \R  matches         Outside  a  character class, by default, the escape sequence \R matches
3285         any Unicode newline sequence. This is a Perl 5.10 feature. In non-UTF-8         any Unicode newline sequence. This is a Perl 5.10 feature. In non-UTF-8
3286         mode \R is equivalent to the following:         mode \R is equivalent to the following:
3287    
3288           (?>\r\n|\n|\x0b|\f|\r|\x85)           (?>\r\n|\n|\x0b|\f|\r|\x85)
3289    
3290         This is an example of an "atomic group", details  of  which  are  given         This  is  an  example  of an "atomic group", details of which are given
3291         below.  This particular group matches either the two-character sequence         below.  This particular group matches either the two-character sequence
3292         CR followed by LF, or  one  of  the  single  characters  LF  (linefeed,         CR  followed  by  LF,  or  one  of  the single characters LF (linefeed,
3293         U+000A), VT (vertical tab, U+000B), FF (formfeed, U+000C), CR (carriage         U+000A), VT (vertical tab, U+000B), FF (formfeed, U+000C), CR (carriage
3294         return, U+000D), or NEL (next line, U+0085). The two-character sequence         return, U+000D), or NEL (next line, U+0085). The two-character sequence
3295         is treated as a single unit that cannot be split.         is treated as a single unit that cannot be split.
3296    
3297         In  UTF-8  mode, two additional characters whose codepoints are greater         In UTF-8 mode, two additional characters whose codepoints  are  greater
3298         than 255 are added: LS (line separator, U+2028) and PS (paragraph sepa-         than 255 are added: LS (line separator, U+2028) and PS (paragraph sepa-
3299         rator,  U+2029).   Unicode character property support is not needed for         rator, U+2029).  Unicode character property support is not  needed  for
3300         these characters to be recognized.         these characters to be recognized.
3301    
3302         It is possible to restrict \R to match only CR, LF, or CRLF (instead of         It is possible to restrict \R to match only CR, LF, or CRLF (instead of
3303         the  complete  set  of  Unicode  line  endings)  by  setting the option         the complete set  of  Unicode  line  endings)  by  setting  the  option
3304         PCRE_BSR_ANYCRLF either at compile time or when the pattern is matched.         PCRE_BSR_ANYCRLF either at compile time or when the pattern is matched.
3305         (BSR is an abbrevation for "backslash R".) This can be made the default         (BSR is an abbrevation for "backslash R".) This can be made the default
3306         when PCRE is built; if this is the case, the  other  behaviour  can  be         when  PCRE  is  built;  if this is the case, the other behaviour can be
3307         requested  via  the  PCRE_BSR_UNICODE  option.   It is also possible to         requested via the PCRE_BSR_UNICODE option.   It  is  also  possible  to
3308         specify these settings by starting a pattern string  with  one  of  the         specify  these  settings  by  starting a pattern string with one of the
3309         following sequences:         following sequences:
3310    
3311           (*BSR_ANYCRLF)   CR, LF, or CRLF only           (*BSR_ANYCRLF)   CR, LF, or CRLF only
# Line 3252  BACKSLASH Line 3314  BACKSLASH
3314         These override the default and the options given to pcre_compile(), but         These override the default and the options given to pcre_compile(), but
3315         they can be overridden by options given to pcre_exec(). Note that these         they can be overridden by options given to pcre_exec(). Note that these
3316         special settings, which are not Perl-compatible, are recognized only at         special settings, which are not Perl-compatible, are recognized only at
3317         the very start of a pattern, and that they must be in  upper  case.  If         the  very  start  of a pattern, and that they must be in upper case. If
3318         more  than  one  of  them is present, the last one is used. They can be         more than one of them is present, the last one is  used.  They  can  be
3319         combined with a change of newline convention, for  example,  a  pattern         combined  with  a  change of newline convention, for example, a pattern
3320         can start with:         can start with:
3321    
3322           (*ANY)(*BSR_ANYCRLF)           (*ANY)(*BSR_ANYCRLF)
# Line 3264  BACKSLASH Line 3326  BACKSLASH
3326     Unicode character properties     Unicode character properties
3327    
3328         When PCRE is built with Unicode character property support, three addi-         When PCRE is built with Unicode character property support, three addi-
3329         tional escape sequences that match characters with specific  properties         tional  escape sequences that match characters with specific properties
3330         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
3331         limited to testing characters whose codepoints are less than  256,  but         limited  to  testing characters whose codepoints are less than 256, but
3332         they do work in this mode.  The extra escape sequences are:         they do work in this mode.  The extra escape sequences are:
3333    
3334           \p{xx}   a character with the xx property           \p{xx}   a character with the xx property
3335           \P{xx}   a character without the xx property           \P{xx}   a character without the xx property
3336           \X       an extended Unicode sequence           \X       an extended Unicode sequence
3337    
3338         The  property  names represented by xx above are limited to the Unicode         The property names represented by xx above are limited to  the  Unicode
3339         script names, the general category properties, and "Any", which matches         script names, the general category properties, and "Any", which matches
3340         any character (including newline). Other properties such as "InMusical-         any character (including newline). Other properties such as "InMusical-
3341         Symbols" are not currently supported by PCRE. Note  that  \P{Any}  does         Symbols"  are  not  currently supported by PCRE. Note that \P{Any} does
3342         not match any characters, so always causes a match failure.         not match any characters, so always causes a match failure.
3343    
3344         Sets of Unicode characters are defined as belonging to certain scripts.         Sets of Unicode characters are defined as belonging to certain scripts.
3345         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.
3346         For example:         For example:
3347    
3348           \p{Greek}           \p{Greek}
3349           \P{Han}           \P{Han}
3350    
3351         Those  that are not part of an identified script are lumped together as         Those that are not part of an identified script are lumped together  as
3352         "Common". The current list of scripts is:         "Common". The current list of scripts is:
3353    
3354         Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,         Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,
3355         Buhid,   Canadian_Aboriginal,   Cherokee,  Common,  Coptic,  Cuneiform,         Buhid,  Canadian_Aboriginal,  Cherokee,  Common,   Coptic,   Cuneiform,
3356         Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,         Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,
3357         Gothic,  Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hira-         Gothic, Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew,  Hira-
3358         gana, Inherited, Kannada,  Katakana,  Kharoshthi,  Khmer,  Lao,  Latin,         gana,  Inherited,  Kannada,  Katakana,  Kharoshthi,  Khmer, Lao, Latin,
3359         Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,         Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,
3360         Ogham, Old_Italic, Old_Persian, Oriya, Osmanya,  Phags_Pa,  Phoenician,         Ogham,  Old_Italic,  Old_Persian, Oriya, Osmanya, Phags_Pa, Phoenician,
3361         Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,         Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,
3362         Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.         Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.
3363    
3364         Each character has exactly one general category property, specified  by         Each  character has exactly one general category property, specified by
3365         a two-letter abbreviation. For compatibility with Perl, negation can be         a two-letter abbreviation. For compatibility with Perl, negation can be
3366         specified by including a circumflex between the opening brace  and  the         specified  by  including a circumflex between the opening brace and the
3367         property name. For example, \p{^Lu} is the same as \P{Lu}.         property name. For example, \p{^Lu} is the same as \P{Lu}.
3368    
3369         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-
3370         eral category properties that start with that letter. In this case,  in         eral  category properties that start with that letter. In this case, in
3371         the  absence of negation, the curly brackets in the escape sequence are         the absence of negation, the curly brackets in the escape sequence  are
3372         optional; these two examples have the same effect:         optional; these two examples have the same effect:
3373    
3374           \p{L}           \p{L}
# Line 3358  BACKSLASH Line 3420  BACKSLASH
3420           Zp    Paragraph separator           Zp    Paragraph separator
3421           Zs    Space separator           Zs    Space separator
3422    
3423         The special property L& is also supported: it matches a character  that         The  special property L& is also supported: it matches a character that
3424         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
3425         classified as a modifier or "other".         classified as a modifier or "other".
3426    
3427         The Cs (Surrogate) property applies only to  characters  in  the  range         The  Cs  (Surrogate)  property  applies only to characters in the range
3428         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
3429         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-
3430         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
3431         the pcreapi page).         the pcreapi page).
3432    
3433         The long synonyms for these properties  that  Perl  supports  (such  as         The  long  synonyms  for  these  properties that Perl supports (such as
3434         \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
3435         any of these properties with "Is".         any of these properties with "Is".
3436    
3437         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-
3438         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
3439         in the Unicode table.         in the Unicode table.
3440    
3441         Specifying caseless matching does not affect  these  escape  sequences.         Specifying  caseless  matching  does not affect these escape sequences.
3442         For example, \p{Lu} always matches only upper case letters.         For example, \p{Lu} always matches only upper case letters.
3443    
3444         The  \X  escape  matches  any number of Unicode characters that form an         The \X escape matches any number of Unicode  characters  that  form  an
3445         extended Unicode sequence. \X is equivalent to         extended Unicode sequence. \X is equivalent to
3446    
3447           (?>\PM\pM*)           (?>\PM\pM*)
3448    
3449         That is, it matches a character without the "mark"  property,  followed         That  is,  it matches a character without the "mark" property, followed
3450         by  zero  or  more  characters with the "mark" property, and treats the         by zero or more characters with the "mark"  property,  and  treats  the
3451         sequence as an atomic group (see below).  Characters  with  the  "mark"         sequence  as  an  atomic group (see below).  Characters with the "mark"
3452         property  are  typically  accents  that affect the preceding character.         property are typically accents that  affect  the  preceding  character.
3453         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
3454         matches any one character.         matches any one character.
3455    
3456         Matching  characters  by Unicode property is not fast, because PCRE has         Matching characters by Unicode property is not fast, because  PCRE  has
3457         to search a structure that contains  data  for  over  fifteen  thousand         to  search  a  structure  that  contains data for over fifteen thousand
3458         characters. That is why the traditional escape sequences such as \d and         characters. That is why the traditional escape sequences such as \d and
3459         \w do not use Unicode properties in PCRE.         \w do not use Unicode properties in PCRE.
3460    
3461     Resetting the match start     Resetting the match start
3462    
3463         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-
3464         ously  matched  characters  not  to  be  included  in the final matched         ously matched characters not  to  be  included  in  the  final  matched
3465         sequence. For example, the pattern:         sequence. For example, the pattern:
3466    
3467           foo\Kbar           foo\Kbar
3468    
3469         matches "foobar", but reports that it has matched "bar".  This  feature         matches  "foobar",  but reports that it has matched "bar". This feature
3470         is  similar  to  a lookbehind assertion (described below).  However, in         is similar to a lookbehind assertion (described  below).   However,  in
3471         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
3472         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
3473         not interfere with the setting of captured  substrings.   For  example,         not  interfere  with  the setting of captured substrings.  For example,
3474         when the pattern         when the pattern
3475    
3476           (foo)\Kbar           (foo)\Kbar
# Line 3417  BACKSLASH Line 3479  BACKSLASH
3479    
3480     Simple assertions     Simple assertions
3481    
3482         The  final use of backslash is for certain simple assertions. An asser-         The final use of backslash is for certain simple assertions. An  asser-
3483         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
3484         a  match, without consuming any characters from the subject string. The         a match, without consuming any characters from the subject string.  The
3485         use of subpatterns for more complicated assertions is described  below.         use  of subpatterns for more complicated assertions is described below.
3486         The backslashed assertions are:         The backslashed assertions are:
3487    
3488           \b     matches at a word boundary           \b     matches at a word boundary
# Line 3431  BACKSLASH Line 3493  BACKSLASH
3493           \z     matches only at the end of the subject           \z     matches only at the end of the subject
3494           \G     matches at the first matching position in the subject           \G     matches at the first matching position in the subject
3495    
3496         These  assertions may not appear in character classes (but note that \b         These assertions may not appear in character classes (but note that  \b
3497         has a different meaning, namely the backspace character, inside a char-         has a different meaning, namely the backspace character, inside a char-
3498         acter class).         acter class).
3499    
3500         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
3501         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.
3502         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
3503         string if the first or last character matches \w, respectively.         string if the first or last character matches \w, respectively.
3504    
3505         The \A, \Z, and \z assertions differ from  the  traditional  circumflex         The  \A,  \Z,  and \z assertions differ from the traditional circumflex
3506         and dollar (described in the next section) in that they only ever match         and dollar (described in the next section) in that they only ever match
3507         at the very start and end of the subject string, whatever  options  are         at  the  very start and end of the subject string, whatever options are
3508         set.  Thus,  they are independent of multiline mode. These three asser-         set. Thus, they are independent of multiline mode. These  three  asser-
3509         tions are not affected by the PCRE_NOTBOL or PCRE_NOTEOL options, which         tions are not affected by the PCRE_NOTBOL or PCRE_NOTEOL options, which
3510         affect  only the behaviour of the circumflex and dollar metacharacters.         affect only the behaviour of the circumflex and dollar  metacharacters.
3511         However, if the startoffset argument of pcre_exec() is non-zero,  indi-         However,  if the startoffset argument of pcre_exec() is non-zero, indi-
3512         cating that matching is to start at a point other than the beginning of         cating that matching is to start at a point other than the beginning of
3513         the subject, \A can never match. The difference between \Z  and  \z  is         the  subject,  \A  can never match. The difference between \Z and \z is
3514         that \Z matches before a newline at the end of the string as well as at         that \Z matches before a newline at the end of the string as well as at
3515         the very end, whereas \z matches only at the end.         the very end, whereas \z matches only at the end.
3516    
3517         The \G assertion is true only when the current matching position is  at         The  \G assertion is true only when the current matching position is at
3518         the  start point of the match, as specified by the startoffset argument         the start point of the match, as specified by the startoffset  argument
3519         of pcre_exec(). It differs from \A when the  value  of  startoffset  is         of  pcre_exec().  It  differs  from \A when the value of startoffset is
3520         non-zero.  By calling pcre_exec() multiple times with appropriate argu-         non-zero. By calling pcre_exec() multiple times with appropriate  argu-
3521         ments, you can mimic Perl's /g option, and it is in this kind of imple-         ments, you can mimic Perl's /g option, and it is in this kind of imple-
3522         mentation where \G can be useful.         mentation where \G can be useful.
3523    
3524         Note,  however,  that  PCRE's interpretation of \G, as the start of the         Note, however, that PCRE's interpretation of \G, as the  start  of  the
3525         current match, is subtly different from Perl's, which defines it as the         current match, is subtly different from Perl's, which defines it as the
3526         end  of  the  previous  match. In Perl, these can be different when the         end of the previous match. In Perl, these can  be  different  when  the
3527         previously matched string was empty. Because PCRE does just  one  match         previously  matched  string was empty. Because PCRE does just one match
3528         at a time, it cannot reproduce this behaviour.         at a time, it cannot reproduce this behaviour.
3529    
3530         If  all  the alternatives of a pattern begin with \G, the expression is         If all the alternatives of a pattern begin with \G, the  expression  is
3531         anchored to the starting match position, and the "anchored" flag is set         anchored to the starting match position, and the "anchored" flag is set
3532         in the compiled regular expression.         in the compiled regular expression.
3533    
# Line 3473  BACKSLASH Line 3535  BACKSLASH
3535  CIRCUMFLEX AND DOLLAR  CIRCUMFLEX AND DOLLAR
3536    
3537         Outside a character class, in the default matching mode, the circumflex         Outside a character class, in the default matching mode, the circumflex
3538         character is an assertion that is true only  if  the  current  matching         character  is  an  assertion  that is true only if the current matching
3539         point  is  at the start of the subject string. If the startoffset argu-         point is at the start of the subject string. If the  startoffset  argu-
3540         ment of pcre_exec() is non-zero, circumflex  can  never  match  if  the         ment  of  pcre_exec()  is  non-zero,  circumflex can never match if the
3541         PCRE_MULTILINE  option  is  unset. Inside a character class, circumflex         PCRE_MULTILINE option is unset. Inside a  character  class,  circumflex
3542         has an entirely different meaning (see below).         has an entirely different meaning (see below).
3543    
3544         Circumflex need not be the first character of the pattern if  a  number         Circumflex  need  not be the first character of the pattern if a number
3545         of  alternatives are involved, but it should be the first thing in each         of alternatives are involved, but it should be the first thing in  each
3546         alternative in which it appears if the pattern is ever  to  match  that         alternative  in  which  it appears if the pattern is ever to match that
3547         branch.  If all possible alternatives start with a circumflex, that is,         branch. If all possible alternatives start with a circumflex, that  is,
3548         if the pattern is constrained to match only at the start  of  the  sub-         if  the  pattern  is constrained to match only at the start of the sub-
3549         ject,  it  is  said  to be an "anchored" pattern. (There are also other         ject, it is said to be an "anchored" pattern.  (There  are  also  other
3550         constructs that can cause a pattern to be anchored.)         constructs that can cause a pattern to be anchored.)
3551    
3552         A dollar character is an assertion that is true  only  if  the  current         A  dollar  character  is  an assertion that is true only if the current
3553         matching  point  is  at  the  end of the subject string, or immediately         matching point is at the end of  the  subject  string,  or  immediately
3554         before a newline at the end of the string (by default). Dollar need not         before a newline at the end of the string (by default). Dollar need not
3555         be  the  last  character of the pattern if a number of alternatives are         be the last character of the pattern if a number  of  alternatives  are
3556         involved, but it should be the last item in  any  branch  in  which  it         involved,  but  it  should  be  the last item in any branch in which it
3557         appears. Dollar has no special meaning in a character class.         appears. Dollar has no special meaning in a character class.
3558    
3559         The  meaning  of  dollar  can be changed so that it matches only at the         The meaning of dollar can be changed so that it  matches  only  at  the
3560         very end of the string, by setting the  PCRE_DOLLAR_ENDONLY  option  at         very  end  of  the string, by setting the PCRE_DOLLAR_ENDONLY option at
3561         compile time. This does not affect the \Z assertion.         compile time. This does not affect the \Z assertion.
3562    
3563         The meanings of the circumflex and dollar characters are changed if the         The meanings of the circumflex and dollar characters are changed if the
3564         PCRE_MULTILINE option is set. When  this  is  the  case,  a  circumflex         PCRE_MULTILINE  option  is  set.  When  this  is the case, a circumflex
3565         matches  immediately after internal newlines as well as at the start of         matches immediately after internal newlines as well as at the start  of
3566         the subject string. It does not match after a  newline  that  ends  the         the  subject  string.  It  does not match after a newline that ends the
3567         string.  A dollar matches before any newlines in the string, as well as         string. A dollar matches before any newlines in the string, as well  as
3568         at the very end, when PCRE_MULTILINE is set. When newline is  specified         at  the very end, when PCRE_MULTILINE is set. When newline is specified
3569         as  the  two-character  sequence CRLF, isolated CR and LF characters do         as the two-character sequence CRLF, isolated CR and  LF  characters  do
3570         not indicate newlines.         not indicate newlines.
3571    
3572         For example, the pattern /^abc$/ matches the subject string  "def\nabc"         For  example, the pattern /^abc$/ matches the subject string "def\nabc"
3573         (where  \n  represents a newline) in multiline mode, but not otherwise.         (where \n represents a newline) in multiline mode, but  not  otherwise.
3574         Consequently, patterns that are anchored in single  line  mode  because         Consequently,  patterns  that  are anchored in single line mode because
3575         all  branches  start  with  ^ are not anchored in multiline mode, and a         all branches start with ^ are not anchored in  multiline  mode,  and  a
3576         match for circumflex is  possible  when  the  startoffset  argument  of         match  for  circumflex  is  possible  when  the startoffset argument of
3577         pcre_exec()  is  non-zero. The PCRE_DOLLAR_ENDONLY option is ignored if         pcre_exec() is non-zero. The PCRE_DOLLAR_ENDONLY option is  ignored  if
3578         PCRE_MULTILINE is set.         PCRE_MULTILINE is set.
3579    
3580         Note that the sequences \A, \Z, and \z can be used to match  the  start         Note  that  the sequences \A, \Z, and \z can be used to match the start
3581         and  end of the subject in both modes, and if all branches of a pattern         and end of the subject in both modes, and if all branches of a  pattern
3582         start with \A it is always anchored, whether or not  PCRE_MULTILINE  is         start  with  \A it is always anchored, whether or not PCRE_MULTILINE is
3583         set.         set.
3584    
3585    
3586  FULL STOP (PERIOD, DOT)  FULL STOP (PERIOD, DOT)
3587    
3588         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-
3589         ter in the subject string except (by default) a character  that  signi-         ter  in  the subject string except (by default) a character that signi-
3590         fies  the  end  of  a line. In UTF-8 mode, the matched character may be         fies the end of a line. In UTF-8 mode, the  matched  character  may  be
3591         more than one byte long.         more than one byte long.
3592    
3593         When a line ending is defined as a single character, dot never  matches         When  a line ending is defined as a single character, dot never matches
3594         that  character; when the two-character sequence CRLF is used, dot does         that character; when the two-character sequence CRLF is used, dot  does
3595         not match CR if it is immediately followed  by  LF,  but  otherwise  it         not  match  CR  if  it  is immediately followed by LF, but otherwise it
3596         matches  all characters (including isolated CRs and LFs). When any Uni-         matches all characters (including isolated CRs and LFs). When any  Uni-
3597         code line endings are being recognized, dot does not match CR or LF  or         code  line endings are being recognized, dot does not match CR or LF or
3598         any of the other line ending characters.         any of the other line ending characters.
3599    
3600         The  behaviour  of  dot  with regard to newlines can be changed. If the         The behaviour of dot with regard to newlines can  be  changed.  If  the
3601         PCRE_DOTALL option is set, a dot matches  any  one  character,  without         PCRE_DOTALL  option  is  set,  a dot matches any one character, without
3602         exception. If the two-character sequence CRLF is present in the subject         exception. If the two-character sequence CRLF is present in the subject
3603         string, it takes two dots to match it.         string, it takes two dots to match it.
3604    
3605         The handling of dot is entirely independent of the handling of  circum-         The  handling of dot is entirely independent of the handling of circum-
3606         flex  and  dollar,  the  only relationship being that they both involve         flex and dollar, the only relationship being  that  they  both  involve
3607         newlines. Dot has no special meaning in a character class.         newlines. Dot has no special meaning in a character class.
3608    
3609    
3610  MATCHING A SINGLE BYTE  MATCHING A SINGLE BYTE
3611    
3612         Outside a character class, the escape sequence \C matches any one byte,         Outside a character class, the escape sequence \C matches any one byte,
3613         both  in  and  out  of  UTF-8 mode. Unlike a dot, it always matches any         both in and out of UTF-8 mode. Unlike a  dot,  it  always  matches  any
3614         line-ending characters. The feature is provided in  Perl  in  order  to         line-ending  characters.  The  feature  is provided in Perl in order to
3615         match  individual bytes in UTF-8 mode. Because it breaks up UTF-8 char-         match individual bytes in UTF-8 mode. Because it breaks up UTF-8  char-
3616         acters into individual bytes, what remains in the string may be a  mal-         acters  into individual bytes, what remains in the string may be a mal-
3617         formed  UTF-8  string.  For this reason, the \C escape sequence is best         formed UTF-8 string. For this reason, the \C escape  sequence  is  best
3618         avoided.         avoided.
3619    
3620         PCRE does not allow \C to appear in  lookbehind  assertions  (described         PCRE  does  not  allow \C to appear in lookbehind assertions (described
3621         below),  because  in UTF-8 mode this would make it impossible to calcu-         below), because in UTF-8 mode this would make it impossible  to  calcu-
3622         late the length of the lookbehind.         late the length of the lookbehind.
3623    
3624    
# Line 3565  SQUARE BRACKETS AND CHARACTER CLASSES Line 3627  SQUARE BRACKETS AND CHARACTER CLASSES
3627         An opening square bracket introduces a character class, terminated by a         An opening square bracket introduces a character class, terminated by a
3628         closing square bracket. A closing square bracket on its own is not spe-         closing square bracket. A closing square bracket on its own is not spe-
3629         cial. If a closing square bracket is required as a member of the class,         cial. If a closing square bracket is required as a member of the class,
3630         it  should  be  the first data character in the class (after an initial         it should be the first data character in the class  (after  an  initial
3631         circumflex, if present) or escaped with a backslash.         circumflex, if present) or escaped with a backslash.
3632    
3633         A character class matches a single character in the subject.  In  UTF-8         A  character  class matches a single character in the subject. In UTF-8
3634         mode,  the character may occupy more than one byte. A matched character         mode, the character may occupy more than one byte. A matched  character
3635         must be in the set of characters defined by the class, unless the first         must be in the set of characters defined by the class, unless the first
3636         character  in  the  class definition is a circumflex, in which case the         character in the class definition is a circumflex, in  which  case  the
3637         subject character must not be in the set defined by  the  class.  If  a         subject  character  must  not  be in the set defined by the class. If a
3638         circumflex  is actually required as a member of the class, ensure it is         circumflex is actually required as a member of the class, ensure it  is
3639         not the first character, or escape it with a backslash.         not the first character, or escape it with a backslash.
3640    
3641         For example, the character class [aeiou] matches any lower case  vowel,         For  example, the character class [aeiou] matches any lower case vowel,
3642         while  [^aeiou]  matches  any character that is not a lower case vowel.         while [^aeiou] matches any character that is not a  lower  case  vowel.
3643         Note that a circumflex is just a convenient notation for specifying the         Note that a circumflex is just a convenient notation for specifying the
3644         characters  that  are in the class by enumerating those that are not. A         characters that are in the class by enumerating those that are  not.  A
3645         class that starts with a circumflex is not an assertion: it still  con-         class  that starts with a circumflex is not an assertion: it still con-
3646         sumes  a  character  from the subject string, and therefore it fails if         sumes a character from the subject string, and therefore  it  fails  if
3647         the current pointer is at the end of the string.         the current pointer is at the end of the string.
3648    
3649         In UTF-8 mode, characters with values greater than 255 can be  included         In  UTF-8 mode, characters with values greater than 255 can be included
3650         in  a  class as a literal string of bytes, or by using the \x{ escaping         in a class as a literal string of bytes, or by using the  \x{  escaping
3651         mechanism.         mechanism.
3652    
3653         When caseless matching is set, any letters in a  class  represent  both         When  caseless  matching  is set, any letters in a class represent both
3654         their  upper  case  and lower case versions, so for example, a caseless         their upper case and lower case versions, so for  example,  a  caseless
3655         [aeiou] matches "A" as well as "a", and a caseless  [^aeiou]  does  not         [aeiou]  matches  "A"  as well as "a", and a caseless [^aeiou] does not
3656         match  "A", whereas a caseful version would. In UTF-8 mode, PCRE always         match "A", whereas a caseful version would. In UTF-8 mode, PCRE  always
3657         understands the concept of case for characters whose  values  are  less         understands  the  concept  of case for characters whose values are less
3658         than  128, so caseless matching is always possible. For characters with         than 128, so caseless matching is always possible. For characters  with
3659         higher values, the concept of case is supported  if  PCRE  is  compiled         higher  values,  the  concept  of case is supported if PCRE is compiled
3660         with  Unicode  property support, but not otherwise.  If you want to use         with Unicode property support, but not otherwise.  If you want  to  use
3661         caseless matching for characters 128 and above, you  must  ensure  that         caseless  matching  for  characters 128 and above, you must ensure that
3662         PCRE  is  compiled  with Unicode property support as well as with UTF-8         PCRE is compiled with Unicode property support as well  as  with  UTF-8
3663         support.         support.
3664    
3665         Characters that might indicate line breaks are  never  treated  in  any         Characters  that  might  indicate  line breaks are never treated in any
3666         special  way  when  matching  character  classes,  whatever line-ending         special way  when  matching  character  classes,  whatever  line-ending
3667         sequence is in  use,  and  whatever  setting  of  the  PCRE_DOTALL  and         sequence  is  in  use,  and  whatever  setting  of  the PCRE_DOTALL and
3668         PCRE_MULTILINE options is used. A class such as [^a] always matches one         PCRE_MULTILINE options is used. A class such as [^a] always matches one
3669         of these characters.         of these characters.
3670    
3671         The minus (hyphen) character can be used to specify a range of  charac-         The  minus (hyphen) character can be used to specify a range of charac-
3672         ters  in  a  character  class.  For  example,  [d-m] matches any letter         ters in a character  class.  For  example,  [d-m]  matches  any  letter
3673         between d and m, inclusive. If a  minus  character  is  required  in  a         between  d  and  m,  inclusive.  If  a minus character is required in a
3674         class,  it  must  be  escaped  with a backslash or appear in a position         class, it must be escaped with a backslash  or  appear  in  a  position
3675         where it cannot be interpreted as indicating a range, typically as  the         where  it cannot be interpreted as indicating a range, typically as the
3676         first or last character in the class.         first or last character in the class.
3677    
3678         It is not possible to have the literal character "]" as the end charac-         It is not possible to have the literal character "]" as the end charac-
3679         ter of a range. A pattern such as [W-]46] is interpreted as a class  of         ter  of a range. A pattern such as [W-]46] is interpreted as a class of
3680         two  characters ("W" and "-") followed by a literal string "46]", so it         two characters ("W" and "-") followed by a literal string "46]", so  it
3681         would match "W46]" or "-46]". However, if the "]"  is  escaped  with  a         would  match  "W46]"  or  "-46]". However, if the "]" is escaped with a
3682         backslash  it is interpreted as the end of range, so [W-\]46] is inter-         backslash it is interpreted as the end of range, so [W-\]46] is  inter-
3683         preted as a class containing a range followed by two other  characters.         preted  as a class containing a range followed by two other characters.
3684         The  octal or hexadecimal representation of "]" can also be used to end         The octal or hexadecimal representation of "]" can also be used to  end
3685         a range.         a range.
3686    
3687         Ranges operate in the collating sequence of character values. They  can         Ranges  operate in the collating sequence of character values. They can
3688         also   be  used  for  characters  specified  numerically,  for  example         also  be  used  for  characters  specified  numerically,  for   example
3689         [\000-\037]. In UTF-8 mode, ranges can include characters whose  values         [\000-\037].  In UTF-8 mode, ranges can include characters whose values
3690         are greater than 255, for example [\x{100}-\x{2ff}].         are greater than 255, for example [\x{100}-\x{2ff}].
3691    
3692         If a range that includes letters is used when caseless matching is set,         If a range that includes letters is used when caseless matching is set,
3693         it matches the letters in either case. For example, [W-c] is equivalent         it matches the letters in either case. For example, [W-c] is equivalent
3694         to  [][\\^_`wxyzabc],  matched  caselessly,  and  in non-UTF-8 mode, if         to [][\\^_`wxyzabc], matched caselessly,  and  in  non-UTF-8  mode,  if
3695         character tables for a French locale are in  use,  [\xc8-\xcb]  matches         character  tables  for  a French locale are in use, [\xc8-\xcb] matches
3696         accented  E  characters in both cases. In UTF-8 mode, PCRE supports the         accented E characters in both cases. In UTF-8 mode, PCRE  supports  the
3697         concept of case for characters with values greater than 128  only  when         concept  of  case for characters with values greater than 128 only when
3698         it is compiled with Unicode property support.         it is compiled with Unicode property support.
3699    
3700         The  character types \d, \D, \p, \P, \s, \S, \w, and \W may also appear         The character types \d, \D, \p, \P, \s, \S, \w, and \W may also  appear
3701         in a character class, and add the characters that  they  match  to  the         in  a  character  class,  and add the characters that they match to the
3702         class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-         class. For example, [\dABCDEF] matches any hexadecimal digit. A circum-
3703         flex can conveniently be used with the upper case  character  types  to         flex  can  conveniently  be used with the upper case character types to
3704         specify  a  more  restricted  set of characters than the matching lower         specify a more restricted set of characters  than  the  matching  lower
3705         case type. For example, the class [^\W_] matches any letter  or  digit,         case  type.  For example, the class [^\W_] matches any letter or digit,
3706         but not underscore.         but not underscore.
3707    
3708         The  only  metacharacters  that are recognized in character classes are         The only metacharacters that are recognized in  character  classes  are
3709         backslash, hyphen (only where it can be  interpreted  as  specifying  a         backslash,  hyphen  (only  where  it can be interpreted as specifying a
3710         range),  circumflex  (only  at the start), opening square bracket (only         range), circumflex (only at the start), opening  square  bracket  (only
3711         when it can be interpreted as introducing a POSIX class name - see  the         when  it can be interpreted as introducing a POSIX class name - see the
3712         next  section),  and  the  terminating closing square bracket. However,         next section), and the terminating  closing  square  bracket.  However,
3713         escaping other non-alphanumeric characters does no harm.         escaping other non-alphanumeric characters does no harm.
3714    
3715    
3716  POSIX CHARACTER CLASSES  POSIX CHARACTER CLASSES
3717    
3718         Perl supports the POSIX notation for character classes. This uses names         Perl supports the POSIX notation for character classes. This uses names
3719         enclosed  by  [: and :] within the enclosing square brackets. PCRE also         enclosed by [: and :] within the enclosing square brackets.  PCRE  also
3720         supports this notation. For example,         supports this notation. For example,
3721    
3722           [01[:alpha:]%]           [01[:alpha:]%]
# Line 3677  POSIX CHARACTER CLASSES Line 3739  POSIX CHARACTER CLASSES
3739           word     "word" characters (same as \w)           word     "word" characters (same as \w)
3740           xdigit   hexadecimal digits           xdigit   hexadecimal digits
3741    
3742         The  "space" characters are HT (9), LF (10), VT (11), FF (12), CR (13),         The "space" characters are HT (9), LF (10), VT (11), FF (12), CR  (13),
3743         and space (32). Notice that this list includes the VT  character  (code         and  space  (32). Notice that this list includes the VT character (code
3744         11). This makes "space" different to \s, which does not include VT (for         11). This makes "space" different to \s, which does not include VT (for
3745         Perl compatibility).         Perl compatibility).
3746    
3747         The name "word" is a Perl extension, and "blank"  is  a  GNU  extension         The  name  "word"  is  a Perl extension, and "blank" is a GNU extension
3748         from  Perl  5.8. Another Perl extension is negation, which is indicated         from Perl 5.8. Another Perl extension is negation, which  is  indicated
3749         by a ^ character after the colon. For example,         by a ^ character after the colon. For example,
3750    
3751           [12[:^digit:]]           [12[:^digit:]]
3752    
3753         matches "1", "2", or any non-digit. PCRE (and Perl) also recognize  the         matches  "1", "2", or any non-digit. PCRE (and Perl) also recognize the
3754         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but         POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but
3755         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.
3756    
# Line 3698  POSIX CHARACTER CLASSES Line 3760  POSIX CHARACTER CLASSES
3760    
3761  VERTICAL BAR  VERTICAL BAR
3762    
3763         Vertical bar characters are used to separate alternative patterns.  For         Vertical  bar characters are used to separate alternative patterns. For
3764         example, the pattern         example, the pattern
3765    
3766           gilbert|sullivan           gilbert|sullivan
3767    
3768         matches  either "gilbert" or "sullivan". Any number of alternatives may         matches either "gilbert" or "sullivan". Any number of alternatives  may
3769         appear, and an empty  alternative  is  permitted  (matching  the  empty         appear,  and  an  empty  alternative  is  permitted (matching the empty
3770         string). The matching process tries each alternative in turn, from left         string). The matching process tries each alternative in turn, from left
3771         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
3772         are  within a subpattern (defined below), "succeeds" means matching the         are within a subpattern (defined below), "succeeds" means matching  the
3773         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.
3774    
3775    
3776  INTERNAL OPTION SETTING  INTERNAL OPTION SETTING
3777    
3778         The  settings  of  the  PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and         The settings of the  PCRE_CASELESS,  PCRE_MULTILINE,  PCRE_DOTALL,  and
3779         PCRE_EXTENDED options (which are Perl-compatible) can be  changed  from         PCRE_EXTENDED  options  (which are Perl-compatible) can be changed from
3780         within  the  pattern  by  a  sequence  of  Perl option letters enclosed         within the pattern by  a  sequence  of  Perl  option  letters  enclosed
3781         between "(?" and ")".  The option letters are         between "(?" and ")".  The option letters are
3782    
3783           i  for PCRE_CASELESS           i  for PCRE_CASELESS
# Line 3725  INTERNAL OPTION SETTING Line 3787  INTERNAL OPTION SETTING
3787    
3788         For example, (?im) sets caseless, multiline matching. It is also possi-         For example, (?im) sets caseless, multiline matching. It is also possi-
3789         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
3790         combined setting and unsetting such as (?im-sx), which sets  PCRE_CASE-         combined  setting and unsetting such as (?im-sx), which sets PCRE_CASE-
3791         LESS  and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED,         LESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and  PCRE_EXTENDED,
3792         is also permitted. If a  letter  appears  both  before  and  after  the         is  also  permitted.  If  a  letter  appears  both before and after the
3793         hyphen, the option is unset.         hyphen, the option is unset.
3794    
3795         The  PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA         The PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and  PCRE_EXTRA
3796         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
3797         the characters J, U and X respectively.         the characters J, U and X respectively.
3798    
3799         When  an option change occurs at top level (that is, not inside subpat-         When an option change occurs at top level (that is, not inside  subpat-
3800         tern parentheses), the change applies to the remainder of  the  pattern         tern  parentheses),  the change applies to the remainder of the pattern
3801         that follows.  If the change is placed right at the start of a pattern,         that follows.  If the change is placed right at the start of a pattern,
3802         PCRE extracts it into the global options (and it will therefore show up         PCRE extracts it into the global options (and it will therefore show up
3803         in data extracted by the pcre_fullinfo() function).         in data extracted by the pcre_fullinfo() function).
3804    
3805         An  option  change  within a subpattern (see below for a description of         An option change within a subpattern (see below for  a  description  of
3806         subpatterns) affects only that part of the current pattern that follows         subpatterns) affects only that part of the current pattern that follows
3807         it, so         it, so
3808    
3809           (a(?i)b)c           (a(?i)b)c
3810    
3811         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
3812         used).  By this means, options can be made to have  different  settings         used).   By  this means, options can be made to have different settings
3813         in  different parts of the pattern. Any changes made in one alternative         in different parts of the pattern. Any changes made in one  alternative
3814         do carry on into subsequent branches within the  same  subpattern.  For         do  carry  on  into subsequent branches within the same subpattern. For
3815         example,         example,
3816    
3817           (a(?i)b|c)           (a(?i)b|c)
3818    
3819         matches  "ab",  "aB",  "c",  and "C", even though when matching "C" the         matches "ab", "aB", "c", and "C", even though  when  matching  "C"  the
3820         first branch is abandoned before the option setting.  This  is  because         first  branch  is  abandoned before the option setting. This is because
3821         the  effects  of option settings happen at compile time. There would be         the effects of option settings happen at compile time. There  would  be
3822         some very weird behaviour otherwise.         some very weird behaviour otherwise.
3823    
3824         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
3825         application  when  the  compile  or match functions are called. In some         application when the compile or match functions  are  called.  In  some
3826         cases the pattern can contain special  leading  sequences  to  override         cases  the  pattern  can  contain special leading sequences to override
3827         what  the  application  has set or what has been defaulted. Details are         what the application has set or what has been  defaulted.  Details  are
3828         given in the section entitled "Newline sequences" above.         given in the section entitled "Newline sequences" above.
3829    
3830    
# Line 3775  SUBPATTERNS Line 3837  SUBPATTERNS
3837    
3838           cat(aract|erpillar|)           cat(aract|erpillar|)
3839    
3840         matches  one  of the words "cat", "cataract", or "caterpillar". Without         matches one of the words "cat", "cataract", or  "caterpillar".  Without
3841         the parentheses, it would match  "cataract",  "erpillar"  or  an  empty         the  parentheses,  it  would  match  "cataract", "erpillar" or an empty
3842         string.         string.
3843    
3844         2.  It  sets  up  the  subpattern as a capturing subpattern. This means         2. It sets up the subpattern as  a  capturing  subpattern.  This  means
3845         that, when the whole pattern  matches,  that  portion  of  the  subject         that,  when  the  whole  pattern  matches,  that portion of the subject
3846         string that matched the subpattern is passed back to the caller via the         string that matched the subpattern is passed back to the caller via the
3847         ovector argument of pcre_exec(). Opening parentheses are  counted  from         ovector  argument  of pcre_exec(). Opening parentheses are counted from
3848         left  to  right  (starting  from 1) to obtain numbers for the capturing         left to right (starting from 1) to obtain  numbers  for  the  capturing
3849         subpatterns.         subpatterns.
3850    
3851         For example, if the string "the red king" is matched against  the  pat-         For  example,  if the string "the red king" is matched against the pat-
3852         tern         tern
3853    
3854           the ((red|white) (king|queen))           the ((red|white) (king|queen))
# Line 3794  SUBPATTERNS Line 3856  SUBPATTERNS
3856         the captured substrings are "red king", "red", and "king", and are num-         the captured substrings are "red king", "red", and "king", and are num-
3857         bered 1, 2, and 3, respectively.         bered 1, 2, and 3, respectively.
3858    
3859         The fact that plain parentheses fulfil  two  functions  is  not  always         The  fact  that  plain  parentheses  fulfil two functions is not always
3860         helpful.   There are often times when a grouping subpattern is required         helpful.  There are often times when a grouping subpattern is  required
3861         without a capturing requirement. If an opening parenthesis is  followed         without  a capturing requirement. If an opening parenthesis is followed
3862         by  a question mark and a colon, the subpattern does not do any captur-         by a question mark and a colon, the subpattern does not do any  captur-
3863         ing, and is not counted when computing the  number  of  any  subsequent         ing,  and  is  not  counted when computing the number of any subsequent
3864         capturing  subpatterns. For example, if the string "the white queen" is         capturing subpatterns. For example, if the string "the white queen"  is
3865         matched against the pattern         matched against the pattern
3866    
3867           the ((?:red|white) (king|queen))           the ((?:red|white) (king|queen))
# Line 3807  SUBPATTERNS Line 3869  SUBPATTERNS
3869         the captured substrings are "white queen" and "queen", and are numbered         the captured substrings are "white queen" and "queen", and are numbered
3870         1 and 2. The maximum number of capturing subpatterns is 65535.         1 and 2. The maximum number of capturing subpatterns is 65535.
3871    
3872         As  a  convenient shorthand, if any option settings are required at the         As a convenient shorthand, if any option settings are required  at  the
3873         start of a non-capturing subpattern,  the  option  letters  may  appear         start  of  a  non-capturing  subpattern,  the option letters may appear
3874         between the "?" and the ":". Thus the two patterns         between the "?" and the ":". Thus the two patterns
3875    
3876           (?i:saturday|sunday)           (?i:saturday|sunday)
3877           (?:(?i)saturday|sunday)           (?:(?i)saturday|sunday)
3878    
3879         match exactly the same set of strings. Because alternative branches are         match exactly the same set of strings. Because alternative branches are
3880         tried from left to right, and options are not reset until  the  end  of         tried  from  left  to right, and options are not reset until the end of
3881         the  subpattern is reached, an option setting in one branch does affect         the subpattern is reached, an option setting in one branch does  affect
3882         subsequent branches, so the above patterns match "SUNDAY"  as  well  as         subsequent  branches,  so  the above patterns match "SUNDAY" as well as
3883         "Saturday".         "Saturday".
3884    
3885    
3886  DUPLICATE SUBPATTERN NUMBERS  DUPLICATE SUBPATTERN NUMBERS
3887    
3888         Perl 5.10 introduced a feature whereby each alternative in a subpattern         Perl 5.10 introduced a feature whereby each alternative in a subpattern
3889         uses the same numbers for its capturing parentheses. Such a  subpattern         uses  the same numbers for its capturing parentheses. Such a subpattern
3890         starts  with (?| and is itself a non-capturing subpattern. For example,         starts with (?| and is itself a non-capturing subpattern. For  example,
3891         consider this pattern:         consider this pattern:
3892    
3893           (?|(Sat)ur|(Sun))day           (?|(Sat)ur|(Sun))day
3894    
3895         Because the two alternatives are inside a (?| group, both sets of  cap-         Because  the two alternatives are inside a (?| group, both sets of cap-
3896         turing  parentheses  are  numbered one. Thus, when the pattern matches,         turing parentheses are numbered one. Thus, when  the  pattern  matches,
3897         you can look at captured substring number  one,  whichever  alternative         you  can  look  at captured substring number one, whichever alternative
3898         matched.  This  construct  is useful when you want to capture part, but         matched. This construct is useful when you want to  capture  part,  but
3899         not all, of one of a number of alternatives. Inside a (?| group, paren-         not all, of one of a number of alternatives. Inside a (?| group, paren-
3900         theses  are  numbered as usual, but the number is reset at the start of         theses are numbered as usual, but the number is reset at the  start  of
3901         each branch. The numbers of any capturing buffers that follow the  sub-         each  branch. The numbers of any capturing buffers that follow the sub-
3902         pattern  start after the highest number used in any branch. The follow-         pattern start after the highest number used in any branch. The  follow-
3903         ing example is taken from the Perl documentation.  The  numbers  under-         ing  example  is taken from the Perl documentation.  The numbers under-
3904         neath show in which buffer the captured content will be stored.         neath show in which buffer the captured content will be stored.
3905    
3906           # before  ---------------branch-reset----------- after           # before  ---------------branch-reset----------- after
3907           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x           / ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
3908           # 1            2         2  3        2     3     4           # 1            2         2  3        2     3     4
3909    
3910         A  backreference  or  a  recursive call to a numbered subpattern always         A backreference or a recursive call to  a  numbered  subpattern  always
3911         refers to the first one in the pattern with the given number.         refers to the first one in the pattern with the given number.
3912    
3913         An alternative approach to using this "branch reset" feature is to  use         An  alternative approach to using this "branch reset" feature is to use
3914         duplicate named subpatterns, as described in the next section.         duplicate named subpatterns, as described in the next section.
3915    
3916    
3917  NAMED SUBPATTERNS  NAMED SUBPATTERNS
3918    
3919         Identifying  capturing  parentheses  by number is simple, but it can be         Identifying capturing parentheses by number is simple, but  it  can  be
3920         very hard to keep track of the numbers in complicated  regular  expres-         very  hard  to keep track of the numbers in complicated regular expres-
3921         sions.  Furthermore,  if  an  expression  is  modified, the numbers may         sions. Furthermore, if an  expression  is  modified,  the  numbers  may
3922         change. To help with this difficulty, PCRE supports the naming of  sub-         change.  To help with this difficulty, PCRE supports the naming of sub-
3923         patterns. This feature was not added to Perl until release 5.10. Python         patterns. This feature was not added to Perl until release 5.10. Python
3924         had the feature earlier, and PCRE introduced it at release  4.0,  using         had  the  feature earlier, and PCRE introduced it at release 4.0, using
3925         the  Python syntax. PCRE now supports both the Perl and the Python syn-         the Python syntax. PCRE now supports both the Perl and the Python  syn-
3926         tax.         tax.
3927    
3928         In PCRE, a subpattern can be named in one of three  ways:  (?<name>...)         In  PCRE,  a subpattern can be named in one of three ways: (?<name>...)
3929         or  (?'name'...)  as in Perl, or (?P<name>...) as in Python. References         or (?'name'...) as in Perl, or (?P<name>...) as in  Python.  References
3930         to capturing parentheses from other parts of the pattern, such as back-         to capturing parentheses from other parts of the pattern, such as back-
3931         references,  recursion,  and conditions, can be made by name as well as         references, recursion, and conditions, can be made by name as  well  as
3932         by number.         by number.
3933    
3934         Names consist of up to  32  alphanumeric  characters  and  underscores.         Names  consist  of  up  to  32 alphanumeric characters and underscores.
3935         Named  capturing  parentheses  are  still  allocated numbers as well as         Named capturing parentheses are still  allocated  numbers  as  well  as
3936         names, exactly as if the names were not present. The PCRE API  provides         names,  exactly as if the names were not present. The PCRE API provides
3937         function calls for extracting the name-to-number translation table from         function calls for extracting the name-to-number translation table from
3938         a compiled pattern. There is also a convenience function for extracting         a compiled pattern. There is also a convenience function for extracting
3939         a captured substring by name.         a captured substring by name.
3940    
3941         By  default, a name must be unique within a pattern, but it is possible         By default, a name must be unique within a pattern, but it is  possible
3942         to relax this constraint by setting the PCRE_DUPNAMES option at compile         to relax this constraint by setting the PCRE_DUPNAMES option at compile
3943         time.  This  can  be useful for patterns where only one instance of the         time. This can be useful for patterns where only one  instance  of  the
3944         named parentheses can match. Suppose you want to match the  name  of  a         named  parentheses  can  match. Suppose you want to match the name of a
3945         weekday,  either as a 3-letter abbreviation or as the full name, and in         weekday, either as a 3-letter abbreviation or as the full name, and  in
3946         both cases you want to extract the abbreviation. This pattern (ignoring         both cases you want to extract the abbreviation. This pattern (ignoring
3947         the line breaks) does the job:         the line breaks) does the job:
3948    
# Line 3890  NAMED SUBPATTERNS Line 3952  NAMED SUBPATTERNS
3952           (?<DN>Thu)(?:rsday)?|           (?<DN>Thu)(?:rsday)?|
3953           (?<DN>Sat)(?:urday)?           (?<DN>Sat)(?:urday)?
3954    
3955         There  are  five capturing substrings, but only one is ever set after a         There are five capturing substrings, but only one is ever set  after  a
3956         match.  (An alternative way of solving this problem is to use a "branch         match.  (An alternative way of solving this problem is to use a "branch
3957         reset" subpattern, as described in the previous section.)         reset" subpattern, as described in the previous section.)
3958    
3959         The  convenience  function  for extracting the data by name returns the         The convenience function for extracting the data by  name  returns  the
3960         substring for the first (and in this example, the only)  subpattern  of         substring  for  the first (and in this example, the only) subpattern of
3961         that  name  that  matched.  This saves searching to find which numbered         that name that matched. This saves searching  to  find  which  numbered
3962         subpattern it was. If you make a reference to a non-unique  named  sub-         subpattern  it  was. If you make a reference to a non-unique named sub-
3963         pattern  from elsewhere in the pattern, the one that corresponds to the         pattern from elsewhere in the pattern, the one that corresponds to  the
3964         lowest number is used. For further details of the interfaces  for  han-         lowest  number  is used. For further details of the interfaces for han-
3965         dling named subpatterns, see the pcreapi documentation.         dling named subpatterns, see the pcreapi documentation.
3966    
3967    
3968  REPETITION  REPETITION
3969    
3970         Repetition  is  specified  by  quantifiers, which can follow any of the         Repetition is specified by quantifiers, which can  follow  any  of  the
3971         following items:         following items:
3972    
3973           a literal data character           a literal data character
# Line 3918  REPETITION Line 3980  REPETITION
3980           a back reference (see next section)           a back reference (see next section)
3981           a parenthesized subpattern (unless it is an assertion)           a parenthesized subpattern (unless it is an assertion)
3982    
3983         The general repetition quantifier specifies a minimum and maximum  num-         The  general repetition quantifier specifies a minimum and maximum num-
3984         ber  of  permitted matches, by giving the two numbers in curly brackets         ber of permitted matches, by giving the two numbers in  curly  brackets
3985         (braces), separated by a comma. The numbers must be  less  than  65536,         (braces),  separated  by  a comma. The numbers must be less than 65536,
3986         and the first must be less than or equal to the second. For example:         and the first must be less than or equal to the second. For example:
3987    
3988           z{2,4}           z{2,4}
3989    
3990         matches  "zz",  "zzz",  or  "zzzz". A closing brace on its own is not a         matches "zz", "zzz", or "zzzz". A closing brace on its  own  is  not  a
3991         special character. If the second number is omitted, but  the  comma  is         special  character.  If  the second number is omitted, but the comma is
3992         present,  there  is  no upper limit; if the second number and the comma         present, there is no upper limit; if the second number  and  the  comma
3993         are both omitted, the quantifier specifies an exact number of  required         are  both omitted, the quantifier specifies an exact number of required
3994         matches. Thus         matches. Thus
3995    
3996           [aeiou]{3,}           [aeiou]{3,}
# Line 3937  REPETITION Line 3999  REPETITION
3999    
4000           \d{8}           \d{8}
4001    
4002         matches  exactly  8  digits. An opening curly bracket that appears in a         matches exactly 8 digits. An opening curly bracket that  appears  in  a
4003         position where a quantifier is not allowed, or one that does not  match         position  where a quantifier is not allowed, or one that does not match
4004         the  syntax of a quantifier, is taken as a literal character. For exam-         the syntax of a quantifier, is taken as a literal character. For  exam-
4005         ple, {,6} is not a quantifier, but a literal string of four characters.         ple, {,6} is not a quantifier, but a literal string of four characters.
4006    
4007         In  UTF-8  mode,  quantifiers  apply to UTF-8 characters rather than to         In UTF-8 mode, quantifiers apply to UTF-8  characters  rather  than  to
4008         individual bytes. Thus, for example, \x{100}{2} matches two UTF-8 char-         individual bytes. Thus, for example, \x{100}{2} matches two UTF-8 char-
4009         acters, each of which is represented by a two-byte sequence. Similarly,         acters, each of which is represented by a two-byte sequence. Similarly,
4010         when Unicode property support is available, \X{3} matches three Unicode         when Unicode property support is available, \X{3} matches three Unicode
4011         extended  sequences,  each of which may be several bytes long (and they         extended sequences, each of which may be several bytes long  (and  they
4012         may be of different lengths).         may be of different lengths).
4013    
4014         The quantifier {0} is permitted, causing the expression to behave as if         The quantifier {0} is permitted, causing the expression to behave as if
4015         the previous item and the quantifier were not present.         the previous item and the quantifier were not present. This may be use-
4016           ful  for  subpatterns that are referenced as subroutines from elsewhere
4017           in the pattern. Items other than subpatterns that have a {0} quantifier
4018           are omitted from the compiled pattern.
4019    
4020         For  convenience, the three most common quantifiers have single-charac-         For  convenience, the three most common quantifiers have single-charac-
4021         ter abbreviations:         ter abbreviations:
# Line 4728  SUBPATTERNS AS SUBROUTINES Line 4793  SUBPATTERNS AS SUBROUTINES
4793         processing option does not affect the called subpattern.         processing option does not affect the called subpattern.
4794    
4795    
4796    ONIGURUMA SUBROUTINE SYNTAX
4797    
4798           For compatibility with Oniguruma, the non-Perl syntax \g followed by  a
4799           name or a number enclosed either in angle brackets or single quotes, is
4800           an alternative syntax for referencing a  subpattern  as  a  subroutine,
4801           possibly  recursively. Here are two of the examples used above, rewrit-
4802           ten using this syntax:
4803    
4804             (?<pn> \( ( (?>[^()]+) | \g<pn> )* \) )
4805             (sens|respons)e and \g'1'ibility
4806    
4807           PCRE supports an extension to Oniguruma: if a number is preceded  by  a
4808           plus or a minus sign it is taken as a relative reference. For example:
4809    
4810             (abc)(?i:\g<-1>)
4811    
4812           Note  that \g{...} (Perl syntax) and \g<...> (Oniguruma syntax) are not
4813           synonymous. The former is a back reference; the latter is a  subroutine
4814           call.
4815    
4816    
4817  CALLOUTS  CALLOUTS
4818    
4819         Perl has a feature whereby using the sequence (?{...}) causes arbitrary         Perl has a feature whereby using the sequence (?{...}) causes arbitrary
4820         Perl  code to be obeyed in the middle of matching a regular expression.         Perl code to be obeyed in the middle of matching a regular  expression.
4821         This makes it possible, amongst other things, to extract different sub-         This makes it possible, amongst other things, to extract different sub-
4822         strings that match the same pair of parentheses when there is a repeti-         strings that match the same pair of parentheses when there is a repeti-
4823         tion.         tion.
4824    
4825         PCRE provides a similar feature, but of course it cannot obey arbitrary         PCRE provides a similar feature, but of course it cannot obey arbitrary
4826         Perl code. The feature is called "callout". The caller of PCRE provides         Perl code. The feature is called "callout". The caller of PCRE provides
4827         an external function by putting its entry point in the global  variable         an  external function by putting its entry point in the global variable
4828         pcre_callout.   By default, this variable contains NULL, which disables         pcre_callout.  By default, this variable contains NULL, which  disables
4829         all calling out.         all calling out.
4830    
4831         Within a regular expression, (?C) indicates the  points  at  which  the         Within  a  regular  expression,  (?C) indicates the points at which the
4832         external  function  is  to be called. If you want to identify different         external function is to be called. If you want  to  identify  different
4833         callout points, you can put a number less than 256 after the letter  C.         callout  points, you can put a number less than 256 after the letter C.
4834         The  default  value is zero.  For example, this pattern has two callout         The default value is zero.  For example, this pattern has  two  callout
4835         points:         points:
4836    
4837           (?C1)abc(?C2)def           (?C1)abc(?C2)def
4838    
4839         If the PCRE_AUTO_CALLOUT flag is passed to pcre_compile(), callouts are         If the PCRE_AUTO_CALLOUT flag is passed to pcre_compile(), callouts are
4840         automatically  installed  before each item in the pattern. They are all         automatically installed before each item in the pattern. They  are  all
4841         numbered 255.         numbered 255.
4842    
4843         During matching, when PCRE reaches a callout point (and pcre_callout is         During matching, when PCRE reaches a callout point (and pcre_callout is
4844         set),  the  external function is called. It is provided with the number         set), the external function is called. It is provided with  the  number
4845         of the callout, the position in the pattern, and, optionally, one  item         of  the callout, the position in the pattern, and, optionally, one item
4846         of  data  originally supplied by the caller of pcre_exec(). The callout         of data originally supplied by the caller of pcre_exec().  The  callout
4847         function may cause matching to proceed, to backtrack, or to fail  alto-         function  may cause matching to proceed, to backtrack, or to fail alto-
4848         gether. A complete description of the interface to the callout function         gether. A complete description of the interface to the callout function
4849         is given in the pcrecallout documentation.         is given in the pcrecallout documentation.
4850    
4851    
4852  BACKTRACKING CONTROL  BACKTRACKING CONTROL
4853    
4854         Perl 5.10 introduced a number of "Special Backtracking Control  Verbs",         Perl  5.10 introduced a number of "Special Backtracking Control Verbs",
4855         which are described in the Perl documentation as "experimental and sub-         which are described in the Perl documentation as "experimental and sub-
4856         ject to change or removal in a future version of Perl". It goes  on  to         ject  to  change or removal in a future version of Perl". It goes on to
4857         say:  "Their usage in production code should be noted to avoid problems         say: "Their usage in production code should be noted to avoid  problems
4858         during upgrades." The same remarks apply to the PCRE features described         during upgrades." The same remarks apply to the PCRE features described
4859         in this section.         in this section.
4860    
4861         Since these verbs are specifically related to backtracking, they can be         Since these verbs are specifically related  to  backtracking,  most  of
4862         used only when the pattern is to be matched  using  pcre_exec(),  which         them  can  be  used  only  when  the  pattern  is  to  be matched using
4863         uses  a  backtracking  algorithm. They cause an error if encountered by         pcre_exec(), which uses a backtracking algorithm. With the exception of
4864         pcre_dfa_exec().         (*FAIL), which behaves like a failing negative assertion, they cause an
4865           error if encountered by pcre_dfa_exec().
4866    
4867         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-
4868         ing parenthesis followed by an asterisk. In Perl, they are generally of         ing parenthesis followed by an asterisk. In Perl, they are generally of
# Line 4894  AUTHOR Line 4981  AUTHOR
4981    
4982  REVISION  REVISION
4983    
4984         Last updated: 17 September 2007         Last updated: 19 April 2008
4985         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
4986  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
4987    
4988    
# Line 5153  SUBROUTINE REFERENCES (POSSIBLY RECURSIV Line 5240  SUBROUTINE REFERENCES (POSSIBLY RECURSIV
5240           (?-n)          call subpattern by relative number           (?-n)          call subpattern by relative number
5241           (?&name)       call subpattern by name (Perl)           (?&name)       call subpattern by name (Perl)
5242           (?P>name)      call subpattern by name (Python)           (?P>name)      call subpattern by name (Python)
5243             \g<name>       call subpattern by name (Oniguruma)
5244             \g'name'       call subpattern by name (Oniguruma)
5245             \g<n>          call subpattern by absolute number (Oniguruma)
5246             \g'n'          call subpattern by absolute number (Oniguruma)
5247             \g<+n>         call subpattern by relative number (PCRE extension)
5248             \g'+n'         call subpattern by relative number (PCRE extension)
5249             \g<-n>         call subpattern by relative number (PCRE extension)
5250             \g'-n'         call subpattern by relative number (PCRE extension)
5251    
5252    
5253  CONDITIONAL PATTERNS  CONDITIONAL PATTERNS
# Line 5232  AUTHOR Line 5327  AUTHOR
5327    
5328  REVISION  REVISION
5329    
5330         Last updated: 14 November 2007         Last updated: 09 April 2008
5331         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
5332  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
5333    
5334    
# Line 5888  MATCHING NEWLINE CHARACTERS Line 5983  MATCHING NEWLINE CHARACTERS
5983  MATCHING A PATTERN  MATCHING A PATTERN
5984    
5985         The  function  regexec()  is  called  to  match a compiled pattern preg         The  function  regexec()  is  called  to  match a compiled pattern preg
5986         against a given string, which is terminated by a zero byte, subject  to         against a given string, which is by default terminated by a  zero  byte
5987         the options in eflags. These can be:         (but  see  REG_STARTEND below), subject to the options in eflags. These
5988           can be:
5989    
5990           REG_NOTBOL           REG_NOTBOL
5991    
# Line 5901  MATCHING A PATTERN Line 5997  MATCHING A PATTERN
5997         The PCRE_NOTEOL option is set when calling the underlying PCRE matching         The PCRE_NOTEOL option is set when calling the underlying PCRE matching
5998         function.         function.
5999    
6000             REG_STARTEND
6001    
6002           The string is considered to start at string +  pmatch[0].rm_so  and  to
6003           have  a terminating NUL located at string + pmatch[0].rm_eo (there need
6004           not actually be a NUL at that location), regardless  of  the  value  of
6005           nmatch.  This  is a BSD extension, compatible with but not specified by
6006           IEEE Standard 1003.2 (POSIX.2), and should  be  used  with  caution  in
6007           software intended to be portable to other systems. Note that a non-zero
6008           rm_so does not imply REG_NOTBOL; REG_STARTEND affects only the location
6009           of the string, not how it is matched.
6010    
6011         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
6012         matched strings  is  returned.  The  nmatch  and  pmatch  arguments  of         matched strings  is  returned.  The  nmatch  and  pmatch  arguments  of
6013         regexec() are ignored.         regexec() are ignored.
# Line 5947  AUTHOR Line 6054  AUTHOR
6054    
6055  REVISION  REVISION
6056    
6057         Last updated: 06 March 2007         Last updated: 05 April 2008
6058         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
6059  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
6060    
6061    
# Line 6313  PCRE SAMPLE PROGRAM Line 6420  PCRE SAMPLE PROGRAM
6420         bility  of  matching an empty string. Comments in the code explain what         bility  of  matching an empty string. Comments in the code explain what
6421         is going on.         is going on.
6422    
6423         The demonstration program is automatically built if you use  "./config-         If PCRE is installed in the standard include  and  library  directories
6424         ure;make"  to  build PCRE. Otherwise, if PCRE is installed in the stan-         for  your  system, you should be able to compile the demonstration pro-
6425         dard include and library directories for your  system,  you  should  be         gram using this command:
        able to compile the demonstration program using this command:  
6426    
6427           gcc -o pcredemo pcredemo.c -lpcre           gcc -o pcredemo pcredemo.c -lpcre
6428    
6429         If  PCRE is installed elsewhere, you may need to add additional options         If PCRE is installed elsewhere, you may need to add additional  options
6430         to the command line. For example, on a Unix-like system that  has  PCRE         to  the  command line. For example, on a Unix-like system that has PCRE
6431         installed  in  /usr/local,  you  can  compile the demonstration program         installed in /usr/local, you  can  compile  the  demonstration  program
6432         using a command like this:         using a command like this:
6433    
6434           gcc -o pcredemo -I/usr/local/include pcredemo.c \           gcc -o pcredemo -I/usr/local/include pcredemo.c \
6435               -L/usr/local/lib -lpcre               -L/usr/local/lib -lpcre
6436    
6437         Once you have compiled the demonstration program, you  can  run  simple         Once  you  have  compiled the demonstration program, you can run simple
6438         tests like this:         tests like this:
6439    
6440           ./pcredemo 'cat|dog' 'the cat sat on the mat'           ./pcredemo 'cat|dog' 'the cat sat on the mat'
6441           ./pcredemo -g 'cat|dog' 'the dog sat on the cat'           ./pcredemo -g 'cat|dog' 'the dog sat on the cat'
6442    
6443         Note  that  there  is  a  much  more comprehensive test program, called         Note that there is a  much  more  comprehensive  test  program,  called
6444         pcretest, which supports  many  more  facilities  for  testing  regular         pcretest,  which  supports  many  more  facilities  for testing regular
6445         expressions and the PCRE library. The pcredemo program is provided as a         expressions and the PCRE library. The pcredemo program is provided as a
6446         simple coding example.         simple coding example.
6447    
# Line 6343  PCRE SAMPLE PROGRAM Line 6449  PCRE SAMPLE PROGRAM
6449         the standard library directory, you may get an error like this when you         the standard library directory, you may get an error like this when you
6450         try to run pcredemo:         try to run pcredemo:
6451    
6452           ld.so.1: a.out: fatal: libpcre.so.0: open failed:  No  such  file  or           ld.so.1:  a.out:  fatal:  libpcre.so.0:  open failed: No such file or
6453         directory         directory
6454    
6455         This  is  caused  by the way shared library support works on those sys-         This is caused by the way shared library support works  on  those  sys-
6456         tems. You need to add         tems. You need to add
6457    
6458           -R/usr/local/lib           -R/usr/local/lib
# Line 6363  AUTHOR Line 6469  AUTHOR
6469    
6470  REVISION  REVISION
6471    
6472         Last updated: 13 June 2007         Last updated: 23 January 2008
6473         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
6474  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
6475  PCRESTACK(3)                                                      PCRESTACK(3)  PCRESTACK(3)                                                      PCRESTACK(3)
6476    
# Line 6430  PCRE DISCUSSION OF STACK USAGE Line 6536  PCRE DISCUSSION OF STACK USAGE
6536         ing long subject strings is to write repeated parenthesized subpatterns         ing long subject strings is to write repeated parenthesized subpatterns
6537         to match more than one character whenever possible.         to match more than one character whenever possible.
6538    
6539       Compiling PCRE to use heap instead of stack
6540    
6541         In environments where stack memory is constrained, you  might  want  to         In environments where stack memory is constrained, you  might  want  to
6542         compile  PCRE to use heap memory instead of stack for remembering back-         compile  PCRE to use heap memory instead of stack for remembering back-
6543         up points. This makes it run a lot more slowly, however. Details of how         up points. This makes it run a lot more slowly, however. Details of how
# Line 6442  PCRE DISCUSSION OF STACK USAGE Line 6550  PCRE DISCUSSION OF STACK USAGE
6550         freed in reverse order, it may be possible to implement customized mem-         freed in reverse order, it may be possible to implement customized mem-
6551         ory handlers that are more efficient than the standard functions.         ory handlers that are more efficient than the standard functions.
6552    
6553       Limiting PCRE's stack usage
6554    
6555           PCRE has an internal counter that can be used to  limit  the  depth  of
6556           recursion,  and  thus cause pcre_exec() to give an error code before it
6557           runs out of stack. By default, the limit is very  large,  and  unlikely
6558           ever  to operate. It can be changed when PCRE is built, and it can also
6559           be set when pcre_exec() is called. For details of these interfaces, see
6560           the pcrebuild and pcreapi documentation.
6561    
6562           As a very rough rule of thumb, you should reckon on about 500 bytes per
6563           recursion. Thus, if you want to limit your  stack  usage  to  8Mb,  you
6564           should  set  the  limit at 16000 recursions. A 64Mb stack, on the other
6565           hand, can support around 128000 recursions. The pcretest  test  program
6566           has a command line option (-S) that can be used to increase the size of
6567           its stack.
6568    
6569       Changing stack size in Unix-like systems
6570    
6571         In Unix-like environments, there is not often a problem with the  stack         In Unix-like environments, there is not often a problem with the  stack
6572         unless  very  long  strings  are  involved, though the default limit on         unless  very  long  strings  are  involved, though the default limit on
6573         stack size varies from system to system. Values from 8Mb  to  64Mb  are         stack size varies from system to system. Values from 8Mb  to  64Mb  are
# Line 6462  PCRE DISCUSSION OF STACK USAGE Line 6588  PCRE DISCUSSION OF STACK USAGE
6588         attempts to increase the soft limit to  100Mb  using  setrlimit().  You         attempts to increase the soft limit to  100Mb  using  setrlimit().  You
6589         must do this before calling pcre_exec().         must do this before calling pcre_exec().
6590    
6591         PCRE  has  an  internal  counter that can be used to limit the depth of     Changing stack size in Mac OS X
        recursion, and thus cause pcre_exec() to give an error code  before  it  
        runs  out  of  stack. By default, the limit is very large, and unlikely  
        ever to operate. It can be changed when PCRE is built, and it can  also  
        be set when pcre_exec() is called. For details of these interfaces, see  
        the pcrebuild and pcreapi documentation.  
6592    
6593         As a very rough rule of thumb, you should reckon on about 500 bytes per         Using setrlimit(), as described above, should also work on Mac OS X. It
6594         recursion.  Thus,  if  you  want  to limit your stack usage to 8Mb, you         is also possible to set a stack size when linking a program. There is a
6595         should set the limit at 16000 recursions. A 64Mb stack,  on  the  other         discussion   about   stack  sizes  in  Mac  OS  X  at  this  web  site:
6596         hand,  can  support around 128000 recursions. The pcretest test program         http://developer.apple.com/qa/qa2005/qa1419.html.
        has a command line option (-S) that can be used to increase the size of  
        its stack.  
6597    
6598    
6599  AUTHOR  AUTHOR
# Line 6486  AUTHOR Line 6605  AUTHOR
6605    
6606  REVISION  REVISION
6607    
6608         Last updated: 05 June 2007         Last updated: 09 July 2008
6609         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.
6610  ------------------------------------------------------------------------------  ------------------------------------------------------------------------------
6611    
6612    

Legend:
Removed from v.289  
changed lines
  Added in v.358

  ViewVC Help
Powered by ViewVC 1.1.5