/[pcre]/code/trunk/doc/html/pcreapi.html
ViewVC logotype

Diff of /code/trunk/doc/html/pcreapi.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 142 by ph10, Fri Mar 30 15:55:18 2007 UTC revision 518 by ph10, Tue May 18 15:47:01 2010 UTC
# Line 164  Applications can use these to include su Line 164  Applications can use these to include su
164  The functions <b>pcre_compile()</b>, <b>pcre_compile2()</b>, <b>pcre_study()</b>,  The functions <b>pcre_compile()</b>, <b>pcre_compile2()</b>, <b>pcre_study()</b>,
165  and <b>pcre_exec()</b> are used for compiling and matching regular expressions  and <b>pcre_exec()</b> are used for compiling and matching regular expressions
166  in a Perl-compatible manner. A sample program that demonstrates the simplest  in a Perl-compatible manner. A sample program that demonstrates the simplest
167  way of using them is provided in the file called <i>pcredemo.c</i> in the source  way of using them is provided in the file called <i>pcredemo.c</i> in the PCRE
168  distribution. The  source distribution. A listing of this program is given in the
169    <a href="pcredemo.html"><b>pcredemo</b></a>
170    documentation, and the
171  <a href="pcresample.html"><b>pcresample</b></a>  <a href="pcresample.html"><b>pcresample</b></a>
172  documentation describes how to run it.  documentation describes how to compile and run it.
173  </P>  </P>
174  <P>  <P>
175  A second matching function, <b>pcre_dfa_exec()</b>, which is not  A second matching function, <b>pcre_dfa_exec()</b>, which is not
176  Perl-compatible, is also provided. This uses a different algorithm for the  Perl-compatible, is also provided. This uses a different algorithm for the
177  matching. The alternative algorithm finds all possible matches (at a given  matching. The alternative algorithm finds all possible matches (at a given
178  point in the subject), and scans the subject just once. However, this algorithm  point in the subject), and scans the subject just once (unless there are
179  does not return captured substrings. A description of the two matching  lookbehind assertions). However, this algorithm does not return captured
180  algorithms and their advantages and disadvantages is given in the  substrings. A description of the two matching algorithms and their advantages
181    and disadvantages is given in the
182  <a href="pcrematching.html"><b>pcrematching</b></a>  <a href="pcrematching.html"><b>pcrematching</b></a>
183  documentation.  documentation.
184  </P>  </P>
# Line 243  by the caller to a "callout" function, w Line 246  by the caller to a "callout" function, w
246  points during a matching operation. Details are given in the  points during a matching operation. Details are given in the
247  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
248  documentation.  documentation.
249  </P>  <a name="newlines"></a></P>
250  <br><a name="SEC3" href="#TOC1">NEWLINES</a><br>  <br><a name="SEC3" href="#TOC1">NEWLINES</a><br>
251  <P>  <P>
252  PCRE supports four different conventions for indicating line breaks in  PCRE supports five different conventions for indicating line breaks in
253  strings: a single CR (carriage return) character, a single LF (linefeed)  strings: a single CR (carriage return) character, a single LF (linefeed)
254  character, the two-character sequence CRLF, or any Unicode newline sequence.  character, the two-character sequence CRLF, any of the three preceding, or any
255  The Unicode newline sequences are the three just mentioned, plus the single  Unicode newline sequence. The Unicode newline sequences are the three just
256  characters VT (vertical tab, U+000B), FF (formfeed, U+000C), NEL (next line,  mentioned, plus the single characters VT (vertical tab, U+000B), FF (formfeed,
257  U+0085), LS (line separator, U+2028), and PS (paragraph separator, U+2029).  U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS
258    (paragraph separator, U+2029).
259  </P>  </P>
260  <P>  <P>
261  Each of the first three conventions is used by at least one operating system as  Each of the first three conventions is used by at least one operating system as
# Line 261  default can be overridden, either when a Line 265  default can be overridden, either when a
265  matched.  matched.
266  </P>  </P>
267  <P>  <P>
268    At compile time, the newline convention can be specified by the <i>options</i>
269    argument of <b>pcre_compile()</b>, or it can be specified by special text at the
270    start of the pattern itself; this overrides any other settings. See the
271    <a href="pcrepattern.html"><b>pcrepattern</b></a>
272    page for details of the special character sequences.
273    </P>
274    <P>
275  In the PCRE documentation the word "newline" is used to mean "the character or  In the PCRE documentation the word "newline" is used to mean "the character or
276  pair of characters that indicate a line break". The choice of newline  pair of characters that indicate a line break". The choice of newline
277  convention affects the handling of the dot, circumflex, and dollar  convention affects the handling of the dot, circumflex, and dollar
278  metacharacters, the handling of #-comments in /x mode, and, when CRLF is a  metacharacters, the handling of #-comments in /x mode, and, when CRLF is a
279  recognized line ending sequence, the match position advancement for a  recognized line ending sequence, the match position advancement for a
280  non-anchored pattern. The choice of newline convention does not affect the  non-anchored pattern. There is more detail about this in the
281  interpretation of the \n or \r escape sequences.  <a href="#execoptions">section on <b>pcre_exec()</b> options</a>
282    below.
283    </P>
284    <P>
285    The choice of newline convention does not affect the interpretation of
286    the \n or \r escape sequences, nor does it affect what \R matches, which is
287    controlled in a similar way, but by separate options.
288  </P>  </P>
289  <br><a name="SEC4" href="#TOC1">MULTITHREADING</a><br>  <br><a name="SEC4" href="#TOC1">MULTITHREADING</a><br>
290  <P>  <P>
# Line 286  The compiled form of a regular expressio Line 303  The compiled form of a regular expressio
303  time, possibly by a different program, and even on a host other than the one on  time, possibly by a different program, and even on a host other than the one on
304  which it was compiled. Details are given in the  which it was compiled. Details are given in the
305  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
306  documentation.  documentation. However, compiling a regular expression with one version of PCRE
307    for use with a different version is not guaranteed to work and may cause
308    crashes.
309  </P>  </P>
310  <br><a name="SEC6" href="#TOC1">CHECKING BUILD-TIME OPTIONS</a><br>  <br><a name="SEC6" href="#TOC1">CHECKING BUILD-TIME OPTIONS</a><br>
311  <P>  <P>
# Line 317  properties is available; otherwise it is Line 336  properties is available; otherwise it is
336  </pre>  </pre>
337  The output is an integer whose value specifies the default character sequence  The output is an integer whose value specifies the default character sequence
338  that is recognized as meaning "newline". The four values that are supported  that is recognized as meaning "newline". The four values that are supported
339  are: 10 for LF, 13 for CR, 3338 for CRLF, and -1 for ANY. The default should  are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF, and -1 for ANY.
340  normally be the standard sequence for your operating system.  Though they are derived from ASCII, the same values are returned in EBCDIC
341    environments. The default should normally correspond to the standard sequence
342    for your operating system.
343    <pre>
344      PCRE_CONFIG_BSR
345    </pre>
346    The output is an integer whose value indicates what character sequences the \R
347    escape sequence matches by default. A value of 0 means that \R matches any
348    Unicode line ending sequence; a value of 1 means that \R matches only CR, LF,
349    or CRLF. The default can be overridden when a pattern is compiled or matched.
350  <pre>  <pre>
351    PCRE_CONFIG_LINK_SIZE    PCRE_CONFIG_LINK_SIZE
352  </pre>  </pre>
# Line 338  documentation. Line 366  documentation.
366  <pre>  <pre>
367    PCRE_CONFIG_MATCH_LIMIT    PCRE_CONFIG_MATCH_LIMIT
368  </pre>  </pre>
369  The output is an integer that gives the default limit for the number of  The output is a long integer that gives the default limit for the number of
370  internal matching function calls in a <b>pcre_exec()</b> execution. Further  internal matching function calls in a <b>pcre_exec()</b> execution. Further
371  details are given with <b>pcre_exec()</b> below.  details are given with <b>pcre_exec()</b> below.
372  <pre>  <pre>
373    PCRE_CONFIG_MATCH_LIMIT_RECURSION    PCRE_CONFIG_MATCH_LIMIT_RECURSION
374  </pre>  </pre>
375  The output is an integer that gives the default limit for the depth of  The output is a long integer that gives the default limit for the depth of
376  recursion when calling the internal matching function in a <b>pcre_exec()</b>  recursion when calling the internal matching function in a <b>pcre_exec()</b>
377  execution. Further details are given with <b>pcre_exec()</b> below.  execution. Further details are given with <b>pcre_exec()</b> below.
378  <pre>  <pre>
# Line 372  avoiding the use of the stack. Line 400  avoiding the use of the stack.
400  Either of the functions <b>pcre_compile()</b> or <b>pcre_compile2()</b> can be  Either of the functions <b>pcre_compile()</b> or <b>pcre_compile2()</b> can be
401  called to compile a pattern into an internal form. The only difference between  called to compile a pattern into an internal form. The only difference between
402  the two interfaces is that <b>pcre_compile2()</b> has an additional argument,  the two interfaces is that <b>pcre_compile2()</b> has an additional argument,
403  <i>errorcodeptr</i>, via which a numerical error code can be returned.  <i>errorcodeptr</i>, via which a numerical error code can be returned. To avoid
404    too much repetition, we refer just to <b>pcre_compile()</b> below, but the
405    information applies equally to <b>pcre_compile2()</b>.
406  </P>  </P>
407  <P>  <P>
408  The pattern is a C string terminated by a binary zero, and is passed in the  The pattern is a C string terminated by a binary zero, and is passed in the
# Line 391  argument, which is an address (see below Line 421  argument, which is an address (see below
421  <P>  <P>
422  The <i>options</i> argument contains various bit settings that affect the  The <i>options</i> argument contains various bit settings that affect the
423  compilation. It should be zero if no options are required. The available  compilation. It should be zero if no options are required. The available
424  options are described below. Some of them, in particular, those that are  options are described below. Some of them (in particular, those that are
425  compatible with Perl, can also be set and unset from within the pattern (see  compatible with Perl, but some others as well) can also be set and unset from
426  the detailed description in the  within the pattern (see the detailed description in the
427  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
428  documentation). For these options, the contents of the <i>options</i> argument  documentation). For those options that can be different in different parts of
429  specifies their initial settings at the start of compilation and execution. The  the pattern, the contents of the <i>options</i> argument specifies their
430  PCRE_ANCHORED and PCRE_NEWLINE_<i>xxx</i> options can be set at the time of  settings at the start of compilation and execution. The PCRE_ANCHORED,
431  matching as well as at compile time.  PCRE_BSR_<i>xxx</i>, and PCRE_NEWLINE_<i>xxx</i> options can be set at the time
432    of matching as well as at compile time.
433  </P>  </P>
434  <P>  <P>
435  If <i>errptr</i> is NULL, <b>pcre_compile()</b> returns NULL immediately.  If <i>errptr</i> is NULL, <b>pcre_compile()</b> returns NULL immediately.
436  Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns  Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns
437  NULL, and sets the variable pointed to by <i>errptr</i> to point to a textual  NULL, and sets the variable pointed to by <i>errptr</i> to point to a textual
438  error message. This is a static string that is part of the library. You must  error message. This is a static string that is part of the library. You must
439  not try to free it. The offset from the start of the pattern to the character  not try to free it. The byte offset from the start of the pattern to the
440  where the error was discovered is placed in the variable pointed to by  character that was being processed when the error was discovered is placed in
441  <i>erroffset</i>, which must not be NULL. If it is, an immediate error is given.  the variable pointed to by <i>erroffset</i>, which must not be NULL. If it is,
442    an immediate error is given. Some errors are not detected until checks are
443    carried out when the whole pattern has been scanned; in this case the offset is
444    set to the end of the pattern.
445  </P>  </P>
446  <P>  <P>
447  If <b>pcre_compile2()</b> is used instead of <b>pcre_compile()</b>, and the  If <b>pcre_compile2()</b> is used instead of <b>pcre_compile()</b>, and the
# Line 455  facility, see the Line 489  facility, see the
489  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
490  documentation.  documentation.
491  <pre>  <pre>
492      PCRE_BSR_ANYCRLF
493      PCRE_BSR_UNICODE
494    </pre>
495    These options (which are mutually exclusive) control what the \R escape
496    sequence matches. The choice is either to match only CR, LF, or CRLF, or to
497    match any Unicode newline sequence. The default is specified when PCRE is
498    built. It can be overridden from within the pattern, or by setting an option
499    when a compiled pattern is matched.
500    <pre>
501    PCRE_CASELESS    PCRE_CASELESS
502  </pre>  </pre>
503  If this bit is set, letters in the pattern match both upper and lower case  If this bit is set, letters in the pattern match both upper and lower case
# Line 517  set, any backslash in a pattern that is Line 560  set, any backslash in a pattern that is
560  special meaning causes an error, thus reserving these combinations for future  special meaning causes an error, thus reserving these combinations for future
561  expansion. By default, as in Perl, a backslash followed by a letter with no  expansion. By default, as in Perl, a backslash followed by a letter with no
562  special meaning is treated as a literal. (Perl can, however, be persuaded to  special meaning is treated as a literal. (Perl can, however, be persuaded to
563  give a warning for this.) There are at present no other features controlled by  give an error for this, by running it with the -w option.) There are at present
564  this option. It can also be set by a (?X) option setting within a pattern.  no other features controlled by this option. It can also be set by a (?X)
565    option setting within a pattern.
566  <pre>  <pre>
567    PCRE_FIRSTLINE    PCRE_FIRSTLINE
568  </pre>  </pre>
# Line 526  If this option is set, an unanchored pat Line 570  If this option is set, an unanchored pat
570  the first newline in the subject string, though the matched text may continue  the first newline in the subject string, though the matched text may continue
571  over the newline.  over the newline.
572  <pre>  <pre>
573      PCRE_JAVASCRIPT_COMPAT
574    </pre>
575    If this option is set, PCRE's behaviour is changed in some ways so that it is
576    compatible with JavaScript rather than Perl. The changes are as follows:
577    </P>
578    <P>
579    (1) A lone closing square bracket in a pattern causes a compile-time error,
580    because this is illegal in JavaScript (by default it is treated as a data
581    character). Thus, the pattern AB]CD becomes illegal when this option is set.
582    </P>
583    <P>
584    (2) At run time, a back reference to an unset subpattern group matches an empty
585    string (by default this causes the current matching alternative to fail). A
586    pattern such as (\1)(a) succeeds when this option is set (assuming it can find
587    an "a" in the subject), whereas it fails by default, for Perl compatibility.
588    <pre>
589    PCRE_MULTILINE    PCRE_MULTILINE
590  </pre>  </pre>
591  By default, PCRE treats the subject string as consisting of a single line of  By default, PCRE treats the subject string as consisting of a single line of
# Line 546  occurrences of ^ or $ in a pattern, sett Line 606  occurrences of ^ or $ in a pattern, sett
606    PCRE_NEWLINE_CR    PCRE_NEWLINE_CR
607    PCRE_NEWLINE_LF    PCRE_NEWLINE_LF
608    PCRE_NEWLINE_CRLF    PCRE_NEWLINE_CRLF
609      PCRE_NEWLINE_ANYCRLF
610    PCRE_NEWLINE_ANY    PCRE_NEWLINE_ANY
611  </pre>  </pre>
612  These options override the default newline definition that was chosen when PCRE  These options override the default newline definition that was chosen when PCRE
613  was built. Setting the first or the second specifies that a newline is  was built. Setting the first or the second specifies that a newline is
614  indicated by a single character (CR or LF, respectively). Setting  indicated by a single character (CR or LF, respectively). Setting
615  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the two-character  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the two-character
616  CRLF sequence. Setting PCRE_NEWLINE_ANY specifies that any Unicode newline  CRLF sequence. Setting PCRE_NEWLINE_ANYCRLF specifies that any of the three
617  sequence should be recognized. The Unicode newline sequences are the three just  preceding sequences should be recognized. Setting PCRE_NEWLINE_ANY specifies
618  mentioned, plus the single characters VT (vertical tab, U+000B), FF (formfeed,  that any Unicode newline sequence should be recognized. The Unicode newline
619  U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS  sequences are the three just mentioned, plus the single characters VT (vertical
620  (paragraph separator, U+2029). The last two are recognized only in UTF-8 mode.  tab, U+000B), FF (formfeed, U+000C), NEL (next line, U+0085), LS (line
621    separator, U+2028), and PS (paragraph separator, U+2029). The last two are
622    recognized only in UTF-8 mode.
623  </P>  </P>
624  <P>  <P>
625  The newline setting in the options word uses three bits that are treated  The newline setting in the options word uses three bits that are treated
626  as a number, giving eight possibilities. Currently only five are used (default  as a number, giving eight possibilities. Currently only six are used (default
627  plus the four values above). This means that if you set more than one newline  plus the five values above). This means that if you set more than one newline
628  option, the combination may or may not be sensible. For example,  option, the combination may or may not be sensible. For example,
629  PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is equivalent to PCRE_NEWLINE_CRLF, but  PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is equivalent to PCRE_NEWLINE_CRLF, but
630  other combinations yield unused numbers and cause an error.  other combinations may yield unused numbers and cause an error.
631  </P>  </P>
632  <P>  <P>
633  The only time that a line break is specially recognized when compiling a  The only time that a line break is specially recognized when compiling a
# Line 607  page. Line 670  page.
670    PCRE_NO_UTF8_CHECK    PCRE_NO_UTF8_CHECK
671  </pre>  </pre>
672  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
673  automatically checked. If an invalid UTF-8 sequence of bytes is found,  automatically checked. There is a discussion about the
674  <b>pcre_compile()</b> returns an error. If you already know that your pattern is  <a href="pcre.html#utf8strings">validity of UTF-8 strings</a>
675  valid, and you want to skip this check for performance reasons, you can set the  in the main
676  PCRE_NO_UTF8_CHECK option. When it is set, the effect of passing an invalid  <a href="pcre.html"><b>pcre</b></a>
677  UTF-8 string as a pattern is undefined. It may cause your program to crash.  page. If an invalid UTF-8 sequence of bytes is found, <b>pcre_compile()</b>
678  Note that this option can also be passed to <b>pcre_exec()</b> and  returns an error. If you already know that your pattern is valid, and you want
679  <b>pcre_dfa_exec()</b>, to suppress the UTF-8 validity checking of subject  to skip this check for performance reasons, you can set the PCRE_NO_UTF8_CHECK
680  strings.  option. When it is set, the effect of passing an invalid UTF-8 string as a
681    pattern is undefined. It may cause your program to crash. Note that this option
682    can also be passed to <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b>, to suppress
683    the UTF-8 validity checking of subject strings.
684  </P>  </P>
685  <br><a name="SEC8" href="#TOC1">COMPILATION ERROR CODES</a><br>  <br><a name="SEC8" href="#TOC1">COMPILATION ERROR CODES</a><br>
686  <P>  <P>
# Line 635  out of use. To avoid confusion, they hav Line 701  out of use. To avoid confusion, they hav
701     9  nothing to repeat     9  nothing to repeat
702    10  [this code is not in use]    10  [this code is not in use]
703    11  internal error: unexpected repeat    11  internal error: unexpected repeat
704    12  unrecognized character after (?    12  unrecognized character after (? or (?-
705    13  POSIX named classes are supported only within a class    13  POSIX named classes are supported only within a class
706    14  missing )    14  missing )
707    15  reference to non-existent subpattern    15  reference to non-existent subpattern
# Line 643  out of use. To avoid confusion, they hav Line 709  out of use. To avoid confusion, they hav
709    17  unknown option bit(s) set    17  unknown option bit(s) set
710    18  missing ) after comment    18  missing ) after comment
711    19  [this code is not in use]    19  [this code is not in use]
712    20  regular expression too large    20  regular expression is too large
713    21  failed to get memory    21  failed to get memory
714    22  unmatched parentheses    22  unmatched parentheses
715    23  internal error: code overflow    23  internal error: code overflow
# Line 652  out of use. To avoid confusion, they hav Line 718  out of use. To avoid confusion, they hav
718    26  malformed number or name after (?(    26  malformed number or name after (?(
719    27  conditional group contains more than two branches    27  conditional group contains more than two branches
720    28  assertion expected after (?(    28  assertion expected after (?(
721    29  (?R or (?digits must be followed by )    29  (?R or (?[+-]digits must be followed by )
722    30  unknown POSIX class name    30  unknown POSIX class name
723    31  POSIX collating elements are not supported    31  POSIX collating elements are not supported
724    32  this version of PCRE is not compiled with PCRE_UTF8 support    32  this version of PCRE is not compiled with PCRE_UTF8 support
# Line 672  out of use. To avoid confusion, they hav Line 738  out of use. To avoid confusion, they hav
738    46  malformed \P or \p sequence    46  malformed \P or \p sequence
739    47  unknown property name after \P or \p    47  unknown property name after \P or \p
740    48  subpattern name is too long (maximum 32 characters)    48  subpattern name is too long (maximum 32 characters)
741    49  too many named subpatterns (maximum 10,000)    49  too many named subpatterns (maximum 10000)
742    50  repeated subpattern is too long    50  [this code is not in use]
743    51  octal value is greater than \377 (not in UTF-8 mode)    51  octal value is greater than \377 (not in UTF-8 mode)
744    52  internal error: overran compiling workspace    52  internal error: overran compiling workspace
745    53  internal error: previously-checked referenced subpattern not found    53  internal error: previously-checked referenced subpattern not found
746    54  DEFINE group contains more than one branch    54  DEFINE group contains more than one branch
747    55  repeating a DEFINE group is not allowed    55  repeating a DEFINE group is not allowed
748    56  inconsistent NEWLINE options"    56  inconsistent NEWLINE options
749  </PRE>    57  \g is not followed by a braced, angle-bracketed, or quoted
750            name/number or by a plain number
751      58  a numbered reference must not be zero
752      59  an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)
753      60  (*VERB) not recognized
754      61  number is too big
755      62  subpattern name expected
756      63  digit expected after (?+
757      64  ] is an invalid data character in JavaScript compatibility mode
758      65  different names for subpatterns of the same number are not allowed
759      66  (*MARK) must have an argument
760    </pre>
761    The numbers 32 and 10000 in errors 48 and 49 are defaults; different values may
762    be used if the limits were changed when PCRE was built.
763  </P>  </P>
764  <br><a name="SEC9" href="#TOC1">STUDYING A PATTERN</a><br>  <br><a name="SEC9" href="#TOC1">STUDYING A PATTERN</a><br>
765  <P>  <P>
# Line 698  results of the study. Line 777  results of the study.
777  </P>  </P>
778  <P>  <P>
779  The returned value from <b>pcre_study()</b> can be passed directly to  The returned value from <b>pcre_study()</b> can be passed directly to
780  <b>pcre_exec()</b>. However, a <b>pcre_extra</b> block also contains other  <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>. However, a <b>pcre_extra</b> block
781  fields that can be set by the caller before the block is passed; these are  also contains other fields that can be set by the caller before the block is
782  described  passed; these are described
783  <a href="#extradata">below</a>  <a href="#extradata">below</a>
784  in the section on matching a pattern.  in the section on matching a pattern.
785  </P>  </P>
786  <P>  <P>
787  If studying the pattern does not produce any additional information  If studying the pattern does not produce any useful information,
788  <b>pcre_study()</b> returns NULL. In that circumstance, if the calling program  <b>pcre_study()</b> returns NULL. In that circumstance, if the calling program
789  wants to pass any of the other fields to <b>pcre_exec()</b>, it must set up its  wants to pass any of the other fields to <b>pcre_exec()</b> or
790  own <b>pcre_extra</b> block.  <b>pcre_dfa_exec()</b>, it must set up its own <b>pcre_extra</b> block.
791  </P>  </P>
792  <P>  <P>
793  The second argument of <b>pcre_study()</b> contains option bits. At present, no  The second argument of <b>pcre_study()</b> contains option bits. At present, no
# Line 731  This is a typical call to pcre_study< Line 810  This is a typical call to pcre_study<
810      0,              /* no options exist */      0,              /* no options exist */
811      &error);        /* set to NULL or points to a message */      &error);        /* set to NULL or points to a message */
812  </pre>  </pre>
813  At present, studying a pattern is useful only for non-anchored patterns that do  Studying a pattern does two things: first, a lower bound for the length of
814  not have a single fixed starting character. A bitmap of possible starting  subject string that is needed to match the pattern is computed. This does not
815  bytes is created.  mean that there are any strings of that length that match, but it does
816    guarantee that no shorter strings match. The value is used by
817    <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b> to avoid wasting time by trying to
818    match strings that are shorter than the lower bound. You can find out the value
819    in a calling program via the <b>pcre_fullinfo()</b> function.
820    </P>
821    <P>
822    Studying a pattern is also useful for non-anchored patterns that do not have a
823    single fixed starting character. A bitmap of possible starting bytes is
824    created. This speeds up finding a position in the subject at which to start
825    matching.
826  <a name="localesupport"></a></P>  <a name="localesupport"></a></P>
827  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>
828  <P>  <P>
# Line 882  table indicating a fixed set of bytes fo Line 971  table indicating a fixed set of bytes fo
971  string, a pointer to the table is returned. Otherwise NULL is returned. The  string, a pointer to the table is returned. Otherwise NULL is returned. The
972  fourth argument should point to an <b>unsigned char *</b> variable.  fourth argument should point to an <b>unsigned char *</b> variable.
973  <pre>  <pre>
974      PCRE_INFO_HASCRORLF
975    </pre>
976    Return 1 if the pattern contains any explicit matches for CR or LF characters,
977    otherwise 0. The fourth argument should point to an <b>int</b> variable. An
978    explicit match is either a literal CR or LF character, or \r or \n.
979    <pre>
980      PCRE_INFO_JCHANGED
981    </pre>
982    Return 1 if the (?J) or (?-J) option setting is used in the pattern, otherwise
983    0. The fourth argument should point to an <b>int</b> variable. (?J) and
984    (?-J) set and unset the local PCRE_DUPNAMES option, respectively.
985    <pre>
986    PCRE_INFO_LASTLITERAL    PCRE_INFO_LASTLITERAL
987  </pre>  </pre>
988  Return the value of the rightmost literal byte that must exist in any matched  Return the value of the rightmost literal byte that must exist in any matched
# Line 892  follows something of variable length. Fo Line 993  follows something of variable length. Fo
993  /^a\d+z\d+/ the returned value is "z", but for /^a\dz\d/ the returned value  /^a\d+z\d+/ the returned value is "z", but for /^a\dz\d/ the returned value
994  is -1.  is -1.
995  <pre>  <pre>
996      PCRE_INFO_MINLENGTH
997    </pre>
998    If the pattern was studied and a minimum length for matching subject strings
999    was computed, its value is returned. Otherwise the returned value is -1. The
1000    value is a number of characters, not bytes (this may be relevant in UTF-8
1001    mode). The fourth argument should point to an <b>int</b> variable. A
1002    non-negative value is a lower bound to the length of any matching string. There
1003    may not be any strings of that length that do actually match, but every string
1004    that does match is at least that long.
1005    <pre>
1006    PCRE_INFO_NAMECOUNT    PCRE_INFO_NAMECOUNT
1007    PCRE_INFO_NAMEENTRYSIZE    PCRE_INFO_NAMEENTRYSIZE
1008    PCRE_INFO_NAMETABLE    PCRE_INFO_NAMETABLE
# Line 913  entry; both of these return an int Line 1024  entry; both of these return an int
1024  length of the longest name. PCRE_INFO_NAMETABLE returns a pointer to the first  length of the longest name. PCRE_INFO_NAMETABLE returns a pointer to the first
1025  entry of the table (a pointer to <b>char</b>). The first two bytes of each entry  entry of the table (a pointer to <b>char</b>). The first two bytes of each entry
1026  are the number of the capturing parenthesis, most significant byte first. The  are the number of the capturing parenthesis, most significant byte first. The
1027  rest of the entry is the corresponding name, zero terminated. The names are in  rest of the entry is the corresponding name, zero terminated.
1028  alphabetical order. When PCRE_DUPNAMES is set, duplicate names are in order of  </P>
1029  their parentheses numbers. For example, consider the following pattern (assume  <P>
1030  PCRE_EXTENDED is set, so white space - including newlines - is ignored):  The names are in alphabetical order. Duplicate names may appear if (?| is used
1031    to create multiple groups with the same number, as described in the
1032    <a href="pcrepattern.html#dupsubpatternnumber">section on duplicate subpattern numbers</a>
1033    in the
1034    <a href="pcrepattern.html"><b>pcrepattern</b></a>
1035    page. Duplicate names for subpatterns with different numbers are permitted only
1036    if PCRE_DUPNAMES is set. In all cases of duplicate names, they appear in the
1037    table in the order in which they were found in the pattern. In the absence of
1038    (?| this is the order of increasing number; when (?| is used this is not
1039    necessarily the case because later subpatterns may have lower numbers.
1040    </P>
1041    <P>
1042    As a simple example of the name/number table, consider the following pattern
1043    (assume PCRE_EXTENDED is set, so white space - including newlines - is
1044    ignored):
1045  <pre>  <pre>
1046    (?&#60;date&#62; (?&#60;year&#62;(\d\d)?\d\d) - (?&#60;month&#62;\d\d) - (?&#60;day&#62;\d\d) )    (?&#60;date&#62; (?&#60;year&#62;(\d\d)?\d\d) - (?&#60;month&#62;\d\d) - (?&#60;day&#62;\d\d) )
1047  </pre>  </pre>
# Line 933  When writing code to extract data from n Line 1058  When writing code to extract data from n
1058  name-to-number map, remember that the length of the entries is likely to be  name-to-number map, remember that the length of the entries is likely to be
1059  different for each compiled pattern.  different for each compiled pattern.
1060  <pre>  <pre>
1061      PCRE_INFO_OKPARTIAL
1062    </pre>
1063    Return 1 if the pattern can be used for partial matching with
1064    <b>pcre_exec()</b>, otherwise 0. The fourth argument should point to an
1065    <b>int</b> variable. From release 8.00, this always returns 1, because the
1066    restrictions that previously applied to partial matching have been lifted. The
1067    <a href="pcrepartial.html"><b>pcrepartial</b></a>
1068    documentation gives details of partial matching.
1069    <pre>
1070    PCRE_INFO_OPTIONS    PCRE_INFO_OPTIONS
1071  </pre>  </pre>
1072  Return a copy of the options with which the pattern was compiled. The fourth  Return a copy of the options with which the pattern was compiled. The fourth
1073  argument should point to an <b>unsigned long int</b> variable. These option bits  argument should point to an <b>unsigned long int</b> variable. These option bits
1074  are those specified in the call to <b>pcre_compile()</b>, modified by any  are those specified in the call to <b>pcre_compile()</b>, modified by any
1075  top-level option settings within the pattern itself.  top-level option settings at the start of the pattern itself. In other words,
1076    they are the options that will be in force when matching starts. For example,
1077    if the pattern /(?im)abc(?-i)d/ is compiled with the PCRE_EXTENDED option, the
1078    result is PCRE_CASELESS, PCRE_MULTILINE, and PCRE_EXTENDED.
1079  </P>  </P>
1080  <P>  <P>
1081  A pattern is automatically anchored by PCRE if all of its top-level  A pattern is automatically anchored by PCRE if all of its top-level
# Line 964  variable. Line 1101  variable.
1101  Return the size of the data block pointed to by the <i>study_data</i> field in  Return the size of the data block pointed to by the <i>study_data</i> field in
1102  a <b>pcre_extra</b> block. That is, it is the value that was passed to  a <b>pcre_extra</b> block. That is, it is the value that was passed to
1103  <b>pcre_malloc()</b> when PCRE was getting memory into which to place the data  <b>pcre_malloc()</b> when PCRE was getting memory into which to place the data
1104  created by <b>pcre_study()</b>. The fourth argument should point to a  created by <b>pcre_study()</b>. If <b>pcre_extra</b> is NULL, or there is no
1105    study data, zero is returned. The fourth argument should point to a
1106  <b>size_t</b> variable.  <b>size_t</b> variable.
1107  </P>  </P>
1108  <br><a name="SEC12" href="#TOC1">OBSOLETE INFO FUNCTION</a><br>  <br><a name="SEC12" href="#TOC1">OBSOLETE INFO FUNCTION</a><br>
# Line 1024  is different. (This seems a highly unlik Line 1162  is different. (This seems a highly unlik
1162  <P>  <P>
1163  The function <b>pcre_exec()</b> is called to match a subject string against a  The function <b>pcre_exec()</b> is called to match a subject string against a
1164  compiled pattern, which is passed in the <i>code</i> argument. If the  compiled pattern, which is passed in the <i>code</i> argument. If the
1165  pattern has been studied, the result of the study should be passed in the  pattern was studied, the result of the study should be passed in the
1166  <i>extra</i> argument. This function is the main matching facility of the  <i>extra</i> argument. This function is the main matching facility of the
1167  library, and it operates in a Perl-like manner. For specialist use there is  library, and it operates in a Perl-like manner. For specialist use there is
1168  also an alternative matching function, which is described  also an alternative matching function, which is described
# Line 1072  fields (not necessarily in this order): Line 1210  fields (not necessarily in this order):
1210    unsigned long int <i>match_limit_recursion</i>;    unsigned long int <i>match_limit_recursion</i>;
1211    void *<i>callout_data</i>;    void *<i>callout_data</i>;
1212    const unsigned char *<i>tables</i>;    const unsigned char *<i>tables</i>;
1213      unsigned char **<i>mark</i>;
1214  </pre>  </pre>
1215  The <i>flags</i> field is a bitmap that specifies which of the other fields  The <i>flags</i> field is a bitmap that specifies which of the other fields
1216  are set. The flag bits are:  are set. The flag bits are:
# Line 1081  are set. The flag bits are: Line 1220  are set. The flag bits are:
1220    PCRE_EXTRA_MATCH_LIMIT_RECURSION    PCRE_EXTRA_MATCH_LIMIT_RECURSION
1221    PCRE_EXTRA_CALLOUT_DATA    PCRE_EXTRA_CALLOUT_DATA
1222    PCRE_EXTRA_TABLES    PCRE_EXTRA_TABLES
1223      PCRE_EXTRA_MARK
1224  </pre>  </pre>
1225  Other flag bits should be set to zero. The <i>study_data</i> field is set in the  Other flag bits should be set to zero. The <i>study_data</i> field is set in the
1226  <b>pcre_extra</b> block that is returned by <b>pcre_study()</b>, together with  <b>pcre_extra</b> block that is returned by <b>pcre_study()</b>, together with
# Line 1091  the block by setting the other fields an Line 1231  the block by setting the other fields an
1231  The <i>match_limit</i> field provides a means of preventing PCRE from using up a  The <i>match_limit</i> field provides a means of preventing PCRE from using up a
1232  vast amount of resources when running patterns that are not going to match,  vast amount of resources when running patterns that are not going to match,
1233  but which have a very large number of possibilities in their search trees. The  but which have a very large number of possibilities in their search trees. The
1234  classic example is the use of nested unlimited repeats.  classic example is a pattern that uses nested unlimited repeats.
1235  </P>  </P>
1236  <P>  <P>
1237  Internally, PCRE uses a function called <b>match()</b> which it calls repeatedly  Internally, PCRE uses a function called <b>match()</b> which it calls repeatedly
# Line 1130  PCRE_EXTRA_MATCH_LIMIT_RECURSION is set Line 1270  PCRE_EXTRA_MATCH_LIMIT_RECURSION is set
1270  is exceeded, <b>pcre_exec()</b> returns PCRE_ERROR_RECURSIONLIMIT.  is exceeded, <b>pcre_exec()</b> returns PCRE_ERROR_RECURSIONLIMIT.
1271  </P>  </P>
1272  <P>  <P>
1273  The <i>pcre_callout</i> field is used in conjunction with the "callout" feature,  The <i>callout_data</i> field is used in conjunction with the "callout" feature,
1274  which is described in the  and is described in the
1275  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
1276  documentation.  documentation.
1277  </P>  </P>
# Line 1148  called. See the Line 1288  called. See the
1288  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
1289  documentation for a discussion of saving compiled patterns for later use.  documentation for a discussion of saving compiled patterns for later use.
1290  </P>  </P>
1291    <P>
1292    If PCRE_EXTRA_MARK is set in the <i>flags</i> field, the <i>mark</i> field must
1293    be set to point to a <b>char *</b> variable. If the pattern contains any
1294    backtracking control verbs such as (*MARK:NAME), and the execution ends up with
1295    a name to pass back, a pointer to the name string (zero terminated) is placed
1296    in the variable pointed to by the <i>mark</i> field. The names are within the
1297    compiled pattern; if you wish to retain such a name you must copy it before
1298    freeing the memory of a compiled pattern. If there is no name to pass back, the
1299    variable pointed to by the <i>mark</i> field set to NULL. For details of the
1300    backtracking control verbs, see the section entitled
1301    <a href="pcrepattern#backtrackcontrol">"Backtracking control"</a>
1302    in the
1303    <a href="pcrepattern.html"><b>pcrepattern</b></a>
1304    documentation.
1305    <a name="execoptions"></a></P>
1306  <br><b>  <br><b>
1307  Option bits for <b>pcre_exec()</b>  Option bits for <b>pcre_exec()</b>
1308  </b><br>  </b><br>
1309  <P>  <P>
1310  The unused bits of the <i>options</i> argument for <b>pcre_exec()</b> must be  The unused bits of the <i>options</i> argument for <b>pcre_exec()</b> must be
1311  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,
1312  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK and PCRE_PARTIAL.  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART,
1313    PCRE_NO_START_OPTIMIZE, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_SOFT, and
1314    PCRE_PARTIAL_HARD.
1315  <pre>  <pre>
1316    PCRE_ANCHORED    PCRE_ANCHORED
1317  </pre>  </pre>
# Line 1163  matching position. If a pattern was comp Line 1320  matching position. If a pattern was comp
1320  to be anchored by virtue of its contents, it cannot be made unachored at  to be anchored by virtue of its contents, it cannot be made unachored at
1321  matching time.  matching time.
1322  <pre>  <pre>
1323      PCRE_BSR_ANYCRLF
1324      PCRE_BSR_UNICODE
1325    </pre>
1326    These options (which are mutually exclusive) control what the \R escape
1327    sequence matches. The choice is either to match only CR, LF, or CRLF, or to
1328    match any Unicode newline sequence. These options override the choice that was
1329    made or defaulted when the pattern was compiled.
1330    <pre>
1331    PCRE_NEWLINE_CR    PCRE_NEWLINE_CR
1332    PCRE_NEWLINE_LF    PCRE_NEWLINE_LF
1333    PCRE_NEWLINE_CRLF    PCRE_NEWLINE_CRLF
1334      PCRE_NEWLINE_ANYCRLF
1335    PCRE_NEWLINE_ANY    PCRE_NEWLINE_ANY
1336  </pre>  </pre>
1337  These options override the newline definition that was chosen or defaulted when  These options override the newline definition that was chosen or defaulted when
# Line 1173  the pattern was compiled. For details, s Line 1339  the pattern was compiled. For details, s
1339  <b>pcre_compile()</b> above. During matching, the newline choice affects the  <b>pcre_compile()</b> above. During matching, the newline choice affects the
1340  behaviour of the dot, circumflex, and dollar metacharacters. It may also alter  behaviour of the dot, circumflex, and dollar metacharacters. It may also alter
1341  the way the match position is advanced after a match failure for an unanchored  the way the match position is advanced after a match failure for an unanchored
1342  pattern. When PCRE_NEWLINE_CRLF or PCRE_NEWLINE_ANY is set, and a match attempt  pattern.
1343  fails when the current position is at a CRLF sequence, the match position is  </P>
1344  advanced by two characters instead of one, in other words, to after the CRLF.  <P>
1345    When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is set, and a
1346    match attempt for an unanchored pattern fails when the current position is at a
1347    CRLF sequence, and the pattern contains no explicit matches for CR or LF
1348    characters, the match position is advanced by two characters instead of one, in
1349    other words, to after the CRLF.
1350    </P>
1351    <P>
1352    The above rule is a compromise that makes the most common cases work as
1353    expected. For example, if the pattern is .+A (and the PCRE_DOTALL option is not
1354    set), it does not match the string "\r\nA" because, after failing at the
1355    start, it skips both the CR and the LF before retrying. However, the pattern
1356    [\r\n]A does match that string, because it contains an explicit CR or LF
1357    reference, and so advances only by one character after the first failure.
1358    </P>
1359    <P>
1360    An explicit match for CR of LF is either a literal appearance of one of those
1361    characters, or one of the \r or \n escape sequences. Implicit matches such as
1362    [^X] do not count, nor does \s (which includes CR and LF in the characters
1363    that it matches).
1364    </P>
1365    <P>
1366    Notwithstanding the above, anomalous effects may still occur when CRLF is a
1367    valid newline sequence and explicit \r or \n escapes appear in the pattern.
1368  <pre>  <pre>
1369    PCRE_NOTBOL    PCRE_NOTBOL
1370  </pre>  </pre>
# Line 1201  match the empty string, the entire match Line 1390  match the empty string, the entire match
1390  <pre>  <pre>
1391    a?b?    a?b?
1392  </pre>  </pre>
1393  is applied to a string not beginning with "a" or "b", it matches the empty  is applied to a string not beginning with "a" or "b", it matches an empty
1394  string at the start of the subject. With PCRE_NOTEMPTY set, this match is not  string at the start of the subject. With PCRE_NOTEMPTY set, this match is not
1395  valid, so PCRE searches further into the string for occurrences of "a" or "b".  valid, so PCRE searches further into the string for occurrences of "a" or "b".
1396    <pre>
1397      PCRE_NOTEMPTY_ATSTART
1398    </pre>
1399    This is like PCRE_NOTEMPTY, except that an empty string match that is not at
1400    the start of the subject is permitted. If the pattern is anchored, such a match
1401    can occur only if the pattern contains \K.
1402  </P>  </P>
1403  <P>  <P>
1404  Perl has no direct equivalent of PCRE_NOTEMPTY, but it does make a special case  Perl has no direct equivalent of PCRE_NOTEMPTY or PCRE_NOTEMPTY_ATSTART, but it
1405  of a pattern match of the empty string within its <b>split()</b> function, and  does make a special case of a pattern match of the empty string within its
1406  when using the /g modifier. It is possible to emulate Perl's behaviour after  <b>split()</b> function, and when using the /g modifier. It is possible to
1407  matching a null string by first trying the match again at the same offset with  emulate Perl's behaviour after matching a null string by first trying the match
1408  PCRE_NOTEMPTY and PCRE_ANCHORED, and then if that fails by advancing the  again at the same offset with PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED, and then
1409  starting offset (see below) and trying an ordinary match again. There is some  if that fails, by advancing the starting offset (see below) and trying an
1410  code that demonstrates how to do this in the <i>pcredemo.c</i> sample program.  ordinary match again. There is some code that demonstrates how to do this in
1411    the
1412    <a href="pcredemo.html"><b>pcredemo</b></a>
1413    sample program.
1414    <pre>
1415      PCRE_NO_START_OPTIMIZE
1416    </pre>
1417    There are a number of optimizations that <b>pcre_exec()</b> uses at the start of
1418    a match, in order to speed up the process. For example, if it is known that a
1419    match must start with a specific character, it searches the subject for that
1420    character, and fails immediately if it cannot find it, without actually running
1421    the main matching function. When callouts are in use, these optimizations can
1422    cause them to be skipped. This option disables the "start-up" optimizations,
1423    causing performance to suffer, but ensuring that the callouts do occur.
1424  <pre>  <pre>
1425    PCRE_NO_UTF8_CHECK    PCRE_NO_UTF8_CHECK
1426  </pre>  </pre>
1427  When PCRE_UTF8 is set at compile time, the validity of the subject as a UTF-8  When PCRE_UTF8 is set at compile time, the validity of the subject as a UTF-8
1428  string is automatically checked when <b>pcre_exec()</b> is subsequently called.  string is automatically checked when <b>pcre_exec()</b> is subsequently called.
1429  The value of <i>startoffset</i> is also checked to ensure that it points to the  The value of <i>startoffset</i> is also checked to ensure that it points to the
1430  start of a UTF-8 character. If an invalid UTF-8 sequence of bytes is found,  start of a UTF-8 character. There is a discussion about the validity of UTF-8
1431  <b>pcre_exec()</b> returns the error PCRE_ERROR_BADUTF8. If <i>startoffset</i>  strings in the
1432  contains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned.  <a href="pcre.html#utf8strings">section on UTF-8 support</a>
1433    in the main
1434    <a href="pcre.html"><b>pcre</b></a>
1435    page. If an invalid UTF-8 sequence of bytes is found, <b>pcre_exec()</b> returns
1436    the error PCRE_ERROR_BADUTF8. If <i>startoffset</i> contains an invalid value,
1437    PCRE_ERROR_BADUTF8_OFFSET is returned.
1438  </P>  </P>
1439  <P>  <P>
1440  If you already know that your subject is valid, and you want to skip these  If you already know that your subject is valid, and you want to skip these
# Line 1234  PCRE_NO_UTF8_CHECK is set, the effect of Line 1447  PCRE_NO_UTF8_CHECK is set, the effect of
1447  subject, or a value of <i>startoffset</i> that does not point to the start of a  subject, or a value of <i>startoffset</i> that does not point to the start of a
1448  UTF-8 character, is undefined. Your program may crash.  UTF-8 character, is undefined. Your program may crash.
1449  <pre>  <pre>
1450    PCRE_PARTIAL    PCRE_PARTIAL_HARD
1451      PCRE_PARTIAL_SOFT
1452  </pre>  </pre>
1453  This option turns on the partial matching feature. If the subject string fails  These options turn on the partial matching feature. For backwards
1454  to match the pattern, but at some point during the matching process the end of  compatibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial match
1455  the subject was reached (that is, the subject partially matches the pattern and  occurs if the end of the subject string is reached successfully, but there are
1456  the failure to match occurred only because there were not enough subject  not enough subject characters to complete the match. If this happens when
1457  characters), <b>pcre_exec()</b> returns PCRE_ERROR_PARTIAL instead of  PCRE_PARTIAL_HARD is set, <b>pcre_exec()</b> immediately returns
1458  PCRE_ERROR_NOMATCH. When PCRE_PARTIAL is used, there are restrictions on what  PCRE_ERROR_PARTIAL. Otherwise, if PCRE_PARTIAL_SOFT is set, matching continues
1459  may appear in the pattern. These are discussed in the  by testing any other alternatives. Only if they all fail is PCRE_ERROR_PARTIAL
1460    returned (instead of PCRE_ERROR_NOMATCH). The portion of the string that
1461    was inspected when the partial match was found is set as the first matching
1462    string. There is a more detailed discussion in the
1463  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
1464  documentation.  documentation.
1465  </P>  </P>
# Line 1251  The string to be matched by pcre_exec Line 1468  The string to be matched by pcre_exec
1468  </b><br>  </b><br>
1469  <P>  <P>
1470  The subject string is passed to <b>pcre_exec()</b> as a pointer in  The subject string is passed to <b>pcre_exec()</b> as a pointer in
1471  <i>subject</i>, a length in <i>length</i>, and a starting byte offset in  <i>subject</i>, a length (in bytes) in <i>length</i>, and a starting byte offset
1472  <i>startoffset</i>. In UTF-8 mode, the byte offset must point to the start of a  in <i>startoffset</i>. In UTF-8 mode, the byte offset must point to the start of
1473  UTF-8 character. Unlike the pattern string, the subject may contain binary zero  a UTF-8 character. Unlike the pattern string, the subject may contain binary
1474  bytes. When the starting offset is zero, the search for a match starts at the  zero bytes. When the starting offset is zero, the search for a match starts at
1475  beginning of the subject, and this is by far the most common case.  the beginning of the subject, and this is by far the most common case.
1476  </P>  </P>
1477  <P>  <P>
1478  A non-zero starting offset is useful when searching for another match in the  A non-zero starting offset is useful when searching for another match in the
# Line 1293  a fragment of a pattern that picks out a Line 1510  a fragment of a pattern that picks out a
1510  kinds of parenthesized subpattern that do not cause substrings to be captured.  kinds of parenthesized subpattern that do not cause substrings to be captured.
1511  </P>  </P>
1512  <P>  <P>
1513  Captured substrings are returned to the caller via a vector of integer offsets  Captured substrings are returned to the caller via a vector of integers whose
1514  whose address is passed in <i>ovector</i>. The number of elements in the vector  address is passed in <i>ovector</i>. The number of elements in the vector is
1515  is passed in <i>ovecsize</i>, which must be a non-negative number. <b>Note</b>:  passed in <i>ovecsize</i>, which must be a non-negative number. <b>Note</b>: this
1516  this argument is NOT the size of <i>ovector</i> in bytes.  argument is NOT the size of <i>ovector</i> in bytes.
1517  </P>  </P>
1518  <P>  <P>
1519  The first two-thirds of the vector is used to pass back captured substrings,  The first two-thirds of the vector is used to pass back captured substrings,
1520  each substring using a pair of integers. The remaining third of the vector is  each substring using a pair of integers. The remaining third of the vector is
1521  used as workspace by <b>pcre_exec()</b> while matching capturing subpatterns,  used as workspace by <b>pcre_exec()</b> while matching capturing subpatterns,
1522  and is not available for passing back information. The length passed in  and is not available for passing back information. The number passed in
1523  <i>ovecsize</i> should always be a multiple of three. If it is not, it is  <i>ovecsize</i> should always be a multiple of three. If it is not, it is
1524  rounded down.  rounded down.
1525  </P>  </P>
1526  <P>  <P>
1527  When a match is successful, information about captured substrings is returned  When a match is successful, information about captured substrings is returned
1528  in pairs of integers, starting at the beginning of <i>ovector</i>, and  in pairs of integers, starting at the beginning of <i>ovector</i>, and
1529  continuing up to two-thirds of its length at the most. The first element of a  continuing up to two-thirds of its length at the most. The first element of
1530  pair is set to the offset of the first character in a substring, and the second  each pair is set to the byte offset of the first character in a substring, and
1531  is set to the offset of the first character after the end of a substring. The  the second is set to the byte offset of the first character after the end of a
1532  first pair, <i>ovector[0]</i> and <i>ovector[1]</i>, identify the portion of the  substring. <b>Note</b>: these values are always byte offsets, even in UTF-8
1533  subject string matched by the entire pattern. The next pair is used for the  mode. They are not character counts.
1534  first capturing subpattern, and so on. The value returned by <b>pcre_exec()</b>  </P>
1535  is one more than the highest numbered pair that has been set. For example, if  <P>
1536  two substrings have been captured, the returned value is 3. If there are no  The first pair of integers, <i>ovector[0]</i> and <i>ovector[1]</i>, identify the
1537  capturing subpatterns, the return value from a successful match is 1,  portion of the subject string matched by the entire pattern. The next pair is
1538  indicating that just the first pair of offsets has been set.  used for the first capturing subpattern, and so on. The value returned by
1539    <b>pcre_exec()</b> is one more than the highest numbered pair that has been set.
1540    For example, if two substrings have been captured, the returned value is 3. If
1541    there are no capturing subpatterns, the return value from a successful match is
1542    1, indicating that just the first pair of offsets has been set.
1543  </P>  </P>
1544  <P>  <P>
1545  If a capturing subpattern is matched repeatedly, it is the last portion of the  If a capturing subpattern is matched repeatedly, it is the last portion of the
# Line 1327  string that it matched that is returned. Line 1548  string that it matched that is returned.
1548  <P>  <P>
1549  If the vector is too small to hold all the captured substring offsets, it is  If the vector is too small to hold all the captured substring offsets, it is
1550  used as far as possible (up to two-thirds of its length), and the function  used as far as possible (up to two-thirds of its length), and the function
1551  returns a value of zero. In particular, if the substring offsets are not of  returns a value of zero. If the substring offsets are not of interest,
1552  interest, <b>pcre_exec()</b> may be called with <i>ovector</i> passed as NULL and  <b>pcre_exec()</b> may be called with <i>ovector</i> passed as NULL and
1553  <i>ovecsize</i> as zero. However, if the pattern contains back references and  <i>ovecsize</i> as zero. However, if the pattern contains back references and
1554  the <i>ovector</i> is not big enough to remember the related substrings, PCRE  the <i>ovector</i> is not big enough to remember the related substrings, PCRE
1555  has to get additional memory for use during matching. Thus it is usually  has to get additional memory for use during matching. Thus it is usually
1556  advisable to supply an <i>ovector</i>.  advisable to supply an <i>ovector</i>.
1557  </P>  </P>
1558  <P>  <P>
1559  The <b>pcre_info()</b> function can be used to find out how many capturing  The <b>pcre_fullinfo()</b> function can be used to find out how many capturing
1560  subpatterns there are in a compiled pattern. The smallest size for  subpatterns there are in a compiled pattern. The smallest size for
1561  <i>ovector</i> that will allow for <i>n</i> captured substrings, in addition to  <i>ovector</i> that will allow for <i>n</i> captured substrings, in addition to
1562  the offsets of the substring matched by the whole pattern, is (<i>n</i>+1)*3.  the offsets of the substring matched by the whole pattern, is (<i>n</i>+1)*3.
# Line 1439  documentation for details of partial mat Line 1660  documentation for details of partial mat
1660  <pre>  <pre>
1661    PCRE_ERROR_BADPARTIAL     (-13)    PCRE_ERROR_BADPARTIAL     (-13)
1662  </pre>  </pre>
1663  The PCRE_PARTIAL option was used with a compiled pattern containing items that  This code is no longer in use. It was formerly returned when the PCRE_PARTIAL
1664  are not supported for partial matching. See the  option was used with a compiled pattern containing items that were not
1665  <a href="pcrepartial.html"><b>pcrepartial</b></a>  supported for partial matching. From release 8.00 onwards, there are no
1666  documentation for details of partial matching.  restrictions on partial matching.
1667  <pre>  <pre>
1668    PCRE_ERROR_INTERNAL       (-14)    PCRE_ERROR_INTERNAL       (-14)
1669  </pre>  </pre>
# Line 1459  The internal recursion limit, as specifi Line 1680  The internal recursion limit, as specifi
1680  field in a <b>pcre_extra</b> structure (or defaulted) was reached. See the  field in a <b>pcre_extra</b> structure (or defaulted) was reached. See the
1681  description above.  description above.
1682  <pre>  <pre>
   PCRE_ERROR_NULLWSLIMIT    (-22)  
 </pre>  
 When a group that can match an empty substring is repeated with an unbounded  
 upper limit, the subject position at the start of the group must be remembered,  
 so that a test for an empty string can be made when the end of the group is  
 reached. Some workspace is required for this; if it runs out, this error is  
 given.  
 <pre>  
1683    PCRE_ERROR_BADNEWLINE     (-23)    PCRE_ERROR_BADNEWLINE     (-23)
1684  </pre>  </pre>
1685  An invalid combination of PCRE_NEWLINE_<i>xxx</i> options was given.  An invalid combination of PCRE_NEWLINE_<i>xxx</i> options was given.
1686  </P>  </P>
1687  <P>  <P>
1688  Error numbers -16 to -20 are not used by <b>pcre_exec()</b>.  Error numbers -16 to -20 and -22 are not used by <b>pcre_exec()</b>.
1689  </P>  </P>
1690  <br><a name="SEC15" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a><br>  <br><a name="SEC15" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a><br>
1691  <P>  <P>
# Line 1622  then call pcre_copy_substring() o Line 1835  then call pcre_copy_substring() o
1835  appropriate. <b>NOTE:</b> If PCRE_DUPNAMES is set and there are duplicate names,  appropriate. <b>NOTE:</b> If PCRE_DUPNAMES is set and there are duplicate names,
1836  the behaviour may not be what you want (see the next section).  the behaviour may not be what you want (see the next section).
1837  </P>  </P>
1838    <P>
1839    <b>Warning:</b> If the pattern uses the (?| feature to set up multiple
1840    subpatterns with the same number, as described in the
1841    <a href="pcrepattern.html#dupsubpatternnumber">section on duplicate subpattern numbers</a>
1842    in the
1843    <a href="pcrepattern.html"><b>pcrepattern</b></a>
1844    page, you cannot use names to distinguish the different subpatterns, because
1845    names are not included in the compiled code. The matching process uses only
1846    numbers. For this reason, the use of different names for subpatterns of the
1847    same number causes an error at compile time.
1848    </P>
1849  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>
1850  <P>  <P>
1851  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>
# Line 1629  the behaviour may not be what you want ( Line 1853  the behaviour may not be what you want (
1853  </P>  </P>
1854  <P>  <P>
1855  When a pattern is compiled with the PCRE_DUPNAMES option, names for subpatterns  When a pattern is compiled with the PCRE_DUPNAMES option, names for subpatterns
1856  are not required to be unique. Normally, patterns with duplicate names are such  are not required to be unique. (Duplicate names are always allowed for
1857  that in any one match, only one of the named subpatterns participates. An  subpatterns with the same number, created by using the (?| feature. Indeed, if
1858  example is shown in the  such subpatterns are named, they are required to use the same names.)
1859    </P>
1860    <P>
1861    Normally, patterns with duplicate names are such that in any one match, only
1862    one of the named subpatterns participates. An example is shown in the
1863  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
1864  documentation. When duplicates are present, <b>pcre_copy_named_substring()</b>  documentation.
1865  and <b>pcre_get_named_substring()</b> return the first substring corresponding  </P>
1866  to the given name that is set. If none are set, an empty string is returned.  <P>
1867  The <b>pcre_get_stringnumber()</b> function returns one of the numbers that are  When duplicates are present, <b>pcre_copy_named_substring()</b> and
1868  associated with the name, but it is not defined which it is.  <b>pcre_get_named_substring()</b> return the first substring corresponding to
1869  <br>  the given name that is set. If none are set, PCRE_ERROR_NOSUBSTRING (-7) is
1870  <br>  returned; no data is returned. The <b>pcre_get_stringnumber()</b> function
1871    returns one of the numbers that are associated with the name, but it is not
1872    defined which it is.
1873    </P>
1874    <P>
1875  If you want to get full details of all captured substrings for a given name,  If you want to get full details of all captured substrings for a given name,
1876  you must use the <b>pcre_get_stringtable_entries()</b> function. The first  you must use the <b>pcre_get_stringtable_entries()</b> function. The first
1877  argument is the compiled pattern, and the second is the name. The third and  argument is the compiled pattern, and the second is the name. The third and
# Line 1683  a compiled pattern, using a matching alg Line 1915  a compiled pattern, using a matching alg
1915  just once, and does not backtrack. This has different characteristics to the  just once, and does not backtrack. This has different characteristics to the
1916  normal algorithm, and is not compatible with Perl. Some of the features of PCRE  normal algorithm, and is not compatible with Perl. Some of the features of PCRE
1917  patterns are not supported. Nevertheless, there are times when this kind of  patterns are not supported. Nevertheless, there are times when this kind of
1918  matching can be useful. For a discussion of the two matching algorithms, see  matching can be useful. For a discussion of the two matching algorithms, and a
1919  the  list of features that <b>pcre_dfa_exec()</b> does not support, see the
1920  <a href="pcrematching.html"><b>pcrematching</b></a>  <a href="pcrematching.html"><b>pcrematching</b></a>
1921  documentation.  documentation.
1922  </P>  </P>
# Line 1726  Option bits for pcre_dfa_exec() Line 1958  Option bits for pcre_dfa_exec()
1958  <P>  <P>
1959  The unused bits of the <i>options</i> argument for <b>pcre_dfa_exec()</b> must be  The unused bits of the <i>options</i> argument for <b>pcre_dfa_exec()</b> must be
1960  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,
1961  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL,  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART,
1962  PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last three of these are  PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_HARD, PCRE_PARTIAL_SOFT, PCRE_DFA_SHORTEST,
1963  the same as for <b>pcre_exec()</b>, so their description is not repeated here.  and PCRE_DFA_RESTART. All but the last four of these are exactly the same as
1964  <pre>  for <b>pcre_exec()</b>, so their description is not repeated here.
1965    PCRE_PARTIAL  <pre>
1966  </pre>    PCRE_PARTIAL_HARD
1967  This has the same general effect as it does for <b>pcre_exec()</b>, but the    PCRE_PARTIAL_SOFT
1968  details are slightly different. When PCRE_PARTIAL is set for  </pre>
1969  <b>pcre_dfa_exec()</b>, the return code PCRE_ERROR_NOMATCH is converted into  These have the same general effect as they do for <b>pcre_exec()</b>, but the
1970  PCRE_ERROR_PARTIAL if the end of the subject is reached, there have been no  details are slightly different. When PCRE_PARTIAL_HARD is set for
1971  complete matches, but there is still at least one matching possibility. The  <b>pcre_dfa_exec()</b>, it returns PCRE_ERROR_PARTIAL if the end of the subject
1972  portion of the string that provided the partial match is set as the first  is reached and there is still at least one matching possibility that requires
1973  matching string.  additional characters. This happens even if some complete matches have also
1974    been found. When PCRE_PARTIAL_SOFT is set, the return code PCRE_ERROR_NOMATCH
1975    is converted into PCRE_ERROR_PARTIAL if the end of the subject is reached,
1976    there have been no complete matches, but there is still at least one matching
1977    possibility. The portion of the string that was inspected when the longest
1978    partial match was found is set as the first matching string in both cases.
1979  <pre>  <pre>
1980    PCRE_DFA_SHORTEST    PCRE_DFA_SHORTEST
1981  </pre>  </pre>
# Line 1749  matching point in the subject string. Line 1986  matching point in the subject string.
1986  <pre>  <pre>
1987    PCRE_DFA_RESTART    PCRE_DFA_RESTART
1988  </pre>  </pre>
1989  When <b>pcre_dfa_exec()</b> is called with the PCRE_PARTIAL option, and returns  When <b>pcre_dfa_exec()</b> returns a partial match, it is possible to call it
1990  a partial match, it is possible to call it again, with additional subject  again, with additional subject characters, and have it continue with the same
1991  characters, and have it continue with the same match. The PCRE_DFA_RESTART  match. The PCRE_DFA_RESTART option requests this action; when it is set, the
1992  option requests this action; when it is set, the <i>workspace</i> and  <i>workspace</i> and <i>wscount</i> options must reference the same vector as
1993  <i>wscount</i> options must reference the same vector as before because data  before because data about the match so far is left in them after a partial
1994  about the match so far is left in them after a partial match. There is more  match. There is more discussion of this facility in the
 discussion of this facility in the  
1995  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
1996  documentation.  documentation.
1997  </P>  </P>
# Line 1851  Cambridge CB2 3QH, England. Line 2087  Cambridge CB2 3QH, England.
2087  </P>  </P>
2088  <br><a name="SEC22" href="#TOC1">REVISION</a><br>  <br><a name="SEC22" href="#TOC1">REVISION</a><br>
2089  <P>  <P>
2090  Last updated: 06 March 2007  Last updated: 03 May 2010
2091  <br>  <br>
2092  Copyright &copy; 1997-2007 University of Cambridge.  Copyright &copy; 1997-2010 University of Cambridge.
2093  <br>  <br>
2094  <p>  <p>
2095  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.

Legend:
Removed from v.142  
changed lines
  Added in v.518

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12