/[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 155 by ph10, Tue Apr 24 13:36:11 2007 UTC revision 784 by ph10, Mon Dec 5 12:33:44 2011 UTC
# Line 13  from the original man page. If there is Line 13  from the original man page. If there is
13  man page, in case the conversion went wrong.  man page, in case the conversion went wrong.
14  <br>  <br>
15  <ul>  <ul>
16  <li><a name="TOC1" href="#SEC1">PCRE NATIVE API</a>  <li><a name="TOC1" href="#SEC1">PCRE NATIVE API BASIC FUNCTIONS</a>
17  <li><a name="TOC2" href="#SEC2">PCRE API OVERVIEW</a>  <li><a name="TOC2" href="#SEC2">PCRE NATIVE API AUXILIARY FUNCTIONS</a>
18  <li><a name="TOC3" href="#SEC3">NEWLINES</a>  <li><a name="TOC3" href="#SEC3">PCRE NATIVE API INDIRECTED FUNCTIONS</a>
19  <li><a name="TOC4" href="#SEC4">MULTITHREADING</a>  <li><a name="TOC4" href="#SEC4">PCRE API OVERVIEW</a>
20  <li><a name="TOC5" href="#SEC5">SAVING PRECOMPILED PATTERNS FOR LATER USE</a>  <li><a name="TOC5" href="#SEC5">NEWLINES</a>
21  <li><a name="TOC6" href="#SEC6">CHECKING BUILD-TIME OPTIONS</a>  <li><a name="TOC6" href="#SEC6">MULTITHREADING</a>
22  <li><a name="TOC7" href="#SEC7">COMPILING A PATTERN</a>  <li><a name="TOC7" href="#SEC7">SAVING PRECOMPILED PATTERNS FOR LATER USE</a>
23  <li><a name="TOC8" href="#SEC8">COMPILATION ERROR CODES</a>  <li><a name="TOC8" href="#SEC8">CHECKING BUILD-TIME OPTIONS</a>
24  <li><a name="TOC9" href="#SEC9">STUDYING A PATTERN</a>  <li><a name="TOC9" href="#SEC9">COMPILING A PATTERN</a>
25  <li><a name="TOC10" href="#SEC10">LOCALE SUPPORT</a>  <li><a name="TOC10" href="#SEC10">COMPILATION ERROR CODES</a>
26  <li><a name="TOC11" href="#SEC11">INFORMATION ABOUT A PATTERN</a>  <li><a name="TOC11" href="#SEC11">STUDYING A PATTERN</a>
27  <li><a name="TOC12" href="#SEC12">OBSOLETE INFO FUNCTION</a>  <li><a name="TOC12" href="#SEC12">LOCALE SUPPORT</a>
28  <li><a name="TOC13" href="#SEC13">REFERENCE COUNTS</a>  <li><a name="TOC13" href="#SEC13">INFORMATION ABOUT A PATTERN</a>
29  <li><a name="TOC14" href="#SEC14">MATCHING A PATTERN: THE TRADITIONAL FUNCTION</a>  <li><a name="TOC14" href="#SEC14">OBSOLETE INFO FUNCTION</a>
30  <li><a name="TOC15" href="#SEC15">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a>  <li><a name="TOC15" href="#SEC15">REFERENCE COUNTS</a>
31  <li><a name="TOC16" href="#SEC16">EXTRACTING CAPTURED SUBSTRINGS BY NAME</a>  <li><a name="TOC16" href="#SEC16">MATCHING A PATTERN: THE TRADITIONAL FUNCTION</a>
32  <li><a name="TOC17" href="#SEC17">DUPLICATE SUBPATTERN NAMES</a>  <li><a name="TOC17" href="#SEC17">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a>
33  <li><a name="TOC18" href="#SEC18">FINDING ALL POSSIBLE MATCHES</a>  <li><a name="TOC18" href="#SEC18">EXTRACTING CAPTURED SUBSTRINGS BY NAME</a>
34  <li><a name="TOC19" href="#SEC19">MATCHING A PATTERN: THE ALTERNATIVE FUNCTION</a>  <li><a name="TOC19" href="#SEC19">DUPLICATE SUBPATTERN NAMES</a>
35  <li><a name="TOC20" href="#SEC20">SEE ALSO</a>  <li><a name="TOC20" href="#SEC20">FINDING ALL POSSIBLE MATCHES</a>
36  <li><a name="TOC21" href="#SEC21">AUTHOR</a>  <li><a name="TOC21" href="#SEC21">MATCHING A PATTERN: THE ALTERNATIVE FUNCTION</a>
37  <li><a name="TOC22" href="#SEC22">REVISION</a>  <li><a name="TOC22" href="#SEC22">SEE ALSO</a>
38    <li><a name="TOC23" href="#SEC23">AUTHOR</a>
39    <li><a name="TOC24" href="#SEC24">REVISION</a>
40  </ul>  </ul>
41  <br><a name="SEC1" href="#TOC1">PCRE NATIVE API</a><br>  <br><a name="SEC1" href="#TOC1">PCRE NATIVE API BASIC FUNCTIONS</a><br>
42  <P>  <P>
43  <b>#include &#60;pcre.h&#62;</b>  <b>#include &#60;pcre.h&#62;</b>
44  </P>  </P>
# Line 56  man page, in case the conversion went wr Line 58  man page, in case the conversion went wr
58  <b>const char **<i>errptr</i>);</b>  <b>const char **<i>errptr</i>);</b>
59  </P>  </P>
60  <P>  <P>
61    <b>void pcre_free_study(pcre_extra *<i>extra</i>);</b>
62    </P>
63    <P>
64  <b>int pcre_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>  <b>int pcre_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>
65  <b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b>  <b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b>
66  <b>int <i>options</i>, int *<i>ovector</i>, int <i>ovecsize</i>);</b>  <b>int <i>options</i>, int *<i>ovector</i>, int <i>ovecsize</i>);</b>
67  </P>  </P>
68    <br><a name="SEC2" href="#TOC1">PCRE NATIVE API AUXILIARY FUNCTIONS</a><br>
69    <P>
70    <b>pcre_jit_stack *pcre_jit_stack_alloc(int <i>startsize</i>, int <i>maxsize</i>);</b>
71    </P>
72    <P>
73    <b>void pcre_jit_stack_free(pcre_jit_stack *<i>stack</i>);</b>
74    </P>
75    <P>
76    <b>void pcre_assign_jit_stack(pcre_extra *<i>extra</i>,</b>
77    <b>pcre_jit_callback <i>callback</i>, void *<i>data</i>);</b>
78    </P>
79  <P>  <P>
80  <b>int pcre_dfa_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>  <b>int pcre_dfa_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>
81  <b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b>  <b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b>
# Line 126  man page, in case the conversion went wr Line 142  man page, in case the conversion went wr
142  <P>  <P>
143  <b>char *pcre_version(void);</b>  <b>char *pcre_version(void);</b>
144  </P>  </P>
145    <br><a name="SEC3" href="#TOC1">PCRE NATIVE API INDIRECTED FUNCTIONS</a><br>
146  <P>  <P>
147  <b>void *(*pcre_malloc)(size_t);</b>  <b>void *(*pcre_malloc)(size_t);</b>
148  </P>  </P>
# Line 141  man page, in case the conversion went wr Line 158  man page, in case the conversion went wr
158  <P>  <P>
159  <b>int (*pcre_callout)(pcre_callout_block *);</b>  <b>int (*pcre_callout)(pcre_callout_block *);</b>
160  </P>  </P>
161  <br><a name="SEC2" href="#TOC1">PCRE API OVERVIEW</a><br>  <br><a name="SEC4" href="#TOC1">PCRE API OVERVIEW</a><br>
162  <P>  <P>
163  PCRE has its own native API, which is described in this document. There are  PCRE has its own native API, which is described in this document. There are
164  also some wrapper functions that correspond to the POSIX regular expression  also some wrapper functions that correspond to the POSIX regular expression
165  API. These are described in the  API, but they do not give access to all the functionality. They are described
166    in the
167  <a href="pcreposix.html"><b>pcreposix</b></a>  <a href="pcreposix.html"><b>pcreposix</b></a>
168  documentation. Both of these APIs define a set of C function calls. A C++  documentation. Both of these APIs define a set of C function calls. A C++
169  wrapper is distributed with PCRE. It is documented in the  wrapper is also distributed with PCRE. It is documented in the
170  <a href="pcrecpp.html"><b>pcrecpp</b></a>  <a href="pcrecpp.html"><b>pcrecpp</b></a>
171  page.  page.
172  </P>  </P>
# Line 161  and PCRE_MINOR to contain the major and Line 179  and PCRE_MINOR to contain the major and
179  Applications can use these to include support for different releases of PCRE.  Applications can use these to include support for different releases of PCRE.
180  </P>  </P>
181  <P>  <P>
182    In a Windows environment, if you want to statically link an application program
183    against a non-dll <b>pcre.a</b> file, you must define PCRE_STATIC before
184    including <b>pcre.h</b> or <b>pcrecpp.h</b>, because otherwise the
185    <b>pcre_malloc()</b> and <b>pcre_free()</b> exported functions will be declared
186    <b>__declspec(dllimport)</b>, with unwanted results.
187    </P>
188    <P>
189  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>,
190  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
191  in a Perl-compatible manner. A sample program that demonstrates the simplest  in a Perl-compatible manner. A sample program that demonstrates the simplest
192  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
193  distribution. The  source distribution. A listing of this program is given in the
194    <a href="pcredemo.html"><b>pcredemo</b></a>
195    documentation, and the
196  <a href="pcresample.html"><b>pcresample</b></a>  <a href="pcresample.html"><b>pcresample</b></a>
197  documentation describes how to run it.  documentation describes how to compile and run it.
198    </P>
199    <P>
200    Just-in-time compiler support is an optional feature of PCRE that can be built
201    in appropriate hardware environments. It greatly speeds up the matching
202    performance of many patterns. Simple programs can easily request that it be
203    used if available, by setting an option that is ignored when it is not
204    relevant. More complicated programs might need to make use of the functions
205    <b>pcre_jit_stack_alloc()</b>, <b>pcre_jit_stack_free()</b>, and
206    <b>pcre_assign_jit_stack()</b> in order to control the JIT code's memory usage.
207    These functions are discussed in the
208    <a href="pcrejit.html"><b>pcrejit</b></a>
209    documentation.
210  </P>  </P>
211  <P>  <P>
212  A second matching function, <b>pcre_dfa_exec()</b>, which is not  A second matching function, <b>pcre_dfa_exec()</b>, which is not
213  Perl-compatible, is also provided. This uses a different algorithm for the  Perl-compatible, is also provided. This uses a different algorithm for the
214  matching. The alternative algorithm finds all possible matches (at a given  matching. The alternative algorithm finds all possible matches (at a given
215  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
216  does not return captured substrings. A description of the two matching  lookbehind assertions). However, this algorithm does not return captured
217  algorithms and their advantages and disadvantages is given in the  substrings. A description of the two matching algorithms and their advantages
218    and disadvantages is given in the
219  <a href="pcrematching.html"><b>pcrematching</b></a>  <a href="pcrematching.html"><b>pcrematching</b></a>
220  documentation.  documentation.
221  </P>  </P>
# Line 243  by the caller to a "callout" function, w Line 283  by the caller to a "callout" function, w
283  points during a matching operation. Details are given in the  points during a matching operation. Details are given in the
284  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
285  documentation.  documentation.
286  </P>  <a name="newlines"></a></P>
287  <br><a name="SEC3" href="#TOC1">NEWLINES</a><br>  <br><a name="SEC5" href="#TOC1">NEWLINES</a><br>
288  <P>  <P>
289  PCRE supports five different conventions for indicating line breaks in  PCRE supports five different conventions for indicating line breaks in
290  strings: a single CR (carriage return) character, a single LF (linefeed)  strings: a single CR (carriage return) character, a single LF (linefeed)
# Line 262  default can be overridden, either when a Line 302  default can be overridden, either when a
302  matched.  matched.
303  </P>  </P>
304  <P>  <P>
305    At compile time, the newline convention can be specified by the <i>options</i>
306    argument of <b>pcre_compile()</b>, or it can be specified by special text at the
307    start of the pattern itself; this overrides any other settings. See the
308    <a href="pcrepattern.html"><b>pcrepattern</b></a>
309    page for details of the special character sequences.
310    </P>
311    <P>
312  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
313  pair of characters that indicate a line break". The choice of newline  pair of characters that indicate a line break". The choice of newline
314  convention affects the handling of the dot, circumflex, and dollar  convention affects the handling of the dot, circumflex, and dollar
315  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
316  recognized line ending sequence, the match position advancement for a  recognized line ending sequence, the match position advancement for a
317  non-anchored pattern. The choice of newline convention does not affect the  non-anchored pattern. There is more detail about this in the
318  interpretation of the \n or \r escape sequences.  <a href="#execoptions">section on <b>pcre_exec()</b> options</a>
319    below.
320  </P>  </P>
321  <br><a name="SEC4" href="#TOC1">MULTITHREADING</a><br>  <P>
322    The choice of newline convention does not affect the interpretation of
323    the \n or \r escape sequences, nor does it affect what \R matches, which is
324    controlled in a similar way, but by separate options.
325    </P>
326    <br><a name="SEC6" href="#TOC1">MULTITHREADING</a><br>
327  <P>  <P>
328  The PCRE functions can be used in multi-threading applications, with the  The PCRE functions can be used in multi-threading applications, with the
329  proviso that the memory management functions pointed to by <b>pcre_malloc</b>,  proviso that the memory management functions pointed to by <b>pcre_malloc</b>,
# Line 281  callout function pointed to by pcre_c Line 334  callout function pointed to by pcre_c
334  The compiled form of a regular expression is not altered during matching, so  The compiled form of a regular expression is not altered during matching, so
335  the same compiled pattern can safely be used by several threads at once.  the same compiled pattern can safely be used by several threads at once.
336  </P>  </P>
337  <br><a name="SEC5" href="#TOC1">SAVING PRECOMPILED PATTERNS FOR LATER USE</a><br>  <P>
338    If the just-in-time optimization feature is being used, it needs separate
339    memory stack areas for each thread. See the
340    <a href="pcrejit.html"><b>pcrejit</b></a>
341    documentation for more details.
342    </P>
343    <br><a name="SEC7" href="#TOC1">SAVING PRECOMPILED PATTERNS FOR LATER USE</a><br>
344  <P>  <P>
345  The compiled form of a regular expression can be saved and re-used at a later  The compiled form of a regular expression can be saved and re-used at a later
346  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
# Line 291  documentation. However, compiling a regu Line 350  documentation. However, compiling a regu
350  for use with a different version is not guaranteed to work and may cause  for use with a different version is not guaranteed to work and may cause
351  crashes.  crashes.
352  </P>  </P>
353  <br><a name="SEC6" href="#TOC1">CHECKING BUILD-TIME OPTIONS</a><br>  <br><a name="SEC8" href="#TOC1">CHECKING BUILD-TIME OPTIONS</a><br>
354  <P>  <P>
355  <b>int pcre_config(int <i>what</i>, void *<i>where</i>);</b>  <b>int pcre_config(int <i>what</i>, void *<i>where</i>);</b>
356  </P>  </P>
# Line 316  otherwise it is set to zero. Line 375  otherwise it is set to zero.
375  The output is an integer that is set to one if support for Unicode character  The output is an integer that is set to one if support for Unicode character
376  properties is available; otherwise it is set to zero.  properties is available; otherwise it is set to zero.
377  <pre>  <pre>
378      PCRE_CONFIG_JIT
379    </pre>
380    The output is an integer that is set to one if support for just-in-time
381    compiling is available; otherwise it is set to zero.
382    <pre>
383    PCRE_CONFIG_NEWLINE    PCRE_CONFIG_NEWLINE
384  </pre>  </pre>
385  The output is an integer whose value specifies the default character sequence  The output is an integer whose value specifies the default character sequence
386  that is recognized as meaning "newline". The four values that are supported  that is recognized as meaning "newline". The four values that are supported
387  are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF, and -1 for ANY. The  are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF, and -1 for ANY.
388  default should normally be the standard sequence for your operating system.  Though they are derived from ASCII, the same values are returned in EBCDIC
389    environments. The default should normally correspond to the standard sequence
390    for your operating system.
391    <pre>
392      PCRE_CONFIG_BSR
393    </pre>
394    The output is an integer whose value indicates what character sequences the \R
395    escape sequence matches by default. A value of 0 means that \R matches any
396    Unicode line ending sequence; a value of 1 means that \R matches only CR, LF,
397    or CRLF. The default can be overridden when a pattern is compiled or matched.
398  <pre>  <pre>
399    PCRE_CONFIG_LINK_SIZE    PCRE_CONFIG_LINK_SIZE
400  </pre>  </pre>
# Line 341  documentation. Line 414  documentation.
414  <pre>  <pre>
415    PCRE_CONFIG_MATCH_LIMIT    PCRE_CONFIG_MATCH_LIMIT
416  </pre>  </pre>
417  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
418  internal matching function calls in a <b>pcre_exec()</b> execution. Further  internal matching function calls in a <b>pcre_exec()</b> execution. Further
419  details are given with <b>pcre_exec()</b> below.  details are given with <b>pcre_exec()</b> below.
420  <pre>  <pre>
421    PCRE_CONFIG_MATCH_LIMIT_RECURSION    PCRE_CONFIG_MATCH_LIMIT_RECURSION
422  </pre>  </pre>
423  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
424  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>
425  execution. Further details are given with <b>pcre_exec()</b> below.  execution. Further details are given with <b>pcre_exec()</b> below.
426  <pre>  <pre>
# Line 361  of recursive function calls. In this cas Line 434  of recursive function calls. In this cas
434  <b>pcre_stack_free</b> are called to manage memory blocks on the heap, thus  <b>pcre_stack_free</b> are called to manage memory blocks on the heap, thus
435  avoiding the use of the stack.  avoiding the use of the stack.
436  </P>  </P>
437  <br><a name="SEC7" href="#TOC1">COMPILING A PATTERN</a><br>  <br><a name="SEC9" href="#TOC1">COMPILING A PATTERN</a><br>
438  <P>  <P>
439  <b>pcre *pcre_compile(const char *<i>pattern</i>, int <i>options</i>,</b>  <b>pcre *pcre_compile(const char *<i>pattern</i>, int <i>options</i>,</b>
440  <b>const char **<i>errptr</i>, int *<i>erroffset</i>,</b>  <b>const char **<i>errptr</i>, int *<i>erroffset</i>,</b>
# Line 375  avoiding the use of the stack. Line 448  avoiding the use of the stack.
448  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
449  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
450  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,
451  <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
452    too much repetition, we refer just to <b>pcre_compile()</b> below, but the
453    information applies equally to <b>pcre_compile2()</b>.
454  </P>  </P>
455  <P>  <P>
456  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 394  argument, which is an address (see below Line 469  argument, which is an address (see below
469  <P>  <P>
470  The <i>options</i> argument contains various bit settings that affect the  The <i>options</i> argument contains various bit settings that affect the
471  compilation. It should be zero if no options are required. The available  compilation. It should be zero if no options are required. The available
472  options are described below. Some of them, in particular, those that are  options are described below. Some of them (in particular, those that are
473  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
474  the detailed description in the  within the pattern (see the detailed description in the
475  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
476  documentation). For these options, the contents of the <i>options</i> argument  documentation). For those options that can be different in different parts of
477  specifies their initial settings at the start of compilation and execution. The  the pattern, the contents of the <i>options</i> argument specifies their
478  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,
479  matching as well as at compile time.  PCRE_BSR_<i>xxx</i>, PCRE_NEWLINE_<i>xxx</i>, PCRE_NO_UTF8_CHECK, and
480    PCRE_NO_START_OPT options can be set at the time of matching as well as at
481    compile time.
482  </P>  </P>
483  <P>  <P>
484  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.
485  Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns  Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns
486  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
487  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
488  not try to free it. The offset from the start of the pattern to the character  not try to free it. Normally, the offset from the start of the pattern to the
489  where the error was discovered is placed in the variable pointed to by  byte that was being processed when the error was discovered is placed in the
490  <i>erroffset</i>, which must not be NULL. If it is, an immediate error is given.  variable pointed to by <i>erroffset</i>, which must not be NULL (if it is, an
491    immediate error is given). However, for an invalid UTF-8 string, the offset is
492    that of the first byte of the failing character. Also, some errors are not
493    detected until checks are carried out when the whole pattern has been scanned;
494    in these cases the offset passed back is the length of the pattern.
495    </P>
496    <P>
497    Note that the offset is in bytes, not characters, even in UTF-8 mode. It may
498    sometimes point into the middle of a UTF-8 character.
499  </P>  </P>
500  <P>  <P>
501  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 458  facility, see the Line 543  facility, see the
543  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
544  documentation.  documentation.
545  <pre>  <pre>
546      PCRE_BSR_ANYCRLF
547      PCRE_BSR_UNICODE
548    </pre>
549    These options (which are mutually exclusive) control what the \R escape
550    sequence matches. The choice is either to match only CR, LF, or CRLF, or to
551    match any Unicode newline sequence. The default is specified when PCRE is
552    built. It can be overridden from within the pattern, or by setting an option
553    when a compiled pattern is matched.
554    <pre>
555    PCRE_CASELESS    PCRE_CASELESS
556  </pre>  </pre>
557  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 481  pattern. Line 575  pattern.
575  <pre>  <pre>
576    PCRE_DOTALL    PCRE_DOTALL
577  </pre>  </pre>
578  If this bit is set, a dot metacharater in the pattern matches all characters,  If this bit is set, a dot metacharacter in the pattern matches a character of
579  including those that indicate newline. Without it, a dot does not match when  any value, including one that indicates a newline. However, it only ever
580  the current position is at a newline. This option is equivalent to Perl's /s  matches one character, even if newlines are coded as CRLF. Without this option,
581  option, and it can be changed within a pattern by a (?s) option setting. A  a dot does not match when the current position is at a newline. This option is
582  negative class such as [^a] always matches newline characters, independent of  equivalent to Perl's /s option, and it can be changed within a pattern by a
583  the setting of this option.  (?s) option setting. A negative class such as [^a] always matches newline
584    characters, independent of the setting of this option.
585  <pre>  <pre>
586    PCRE_DUPNAMES    PCRE_DUPNAMES
587  </pre>  </pre>
# Line 507  ignored. This is equivalent to Perl's /x Line 602  ignored. This is equivalent to Perl's /x
602  pattern by a (?x) option setting.  pattern by a (?x) option setting.
603  </P>  </P>
604  <P>  <P>
605    Which characters are interpreted as newlines is controlled by the options
606    passed to <b>pcre_compile()</b> or by a special sequence at the start of the
607    pattern, as described in the section entitled
608    <a href="pcrepattern.html#newlines">"Newline conventions"</a>
609    in the <b>pcrepattern</b> documentation. Note that the end of this type of
610    comment is a literal newline sequence in the pattern; escape sequences that
611    happen to represent a newline do not count.
612    </P>
613    <P>
614  This option makes it possible to include comments inside complicated patterns.  This option makes it possible to include comments inside complicated patterns.
615  Note, however, that this applies only to data characters. Whitespace characters  Note, however, that this applies only to data characters. Whitespace characters
616  may never appear within special character sequences in a pattern, for example  may never appear within special character sequences in a pattern, for example
617  within the sequence (?( which introduces a conditional subpattern.  within the sequence (?( that introduces a conditional subpattern.
618  <pre>  <pre>
619    PCRE_EXTRA    PCRE_EXTRA
620  </pre>  </pre>
# Line 520  set, any backslash in a pattern that is Line 624  set, any backslash in a pattern that is
624  special meaning causes an error, thus reserving these combinations for future  special meaning causes an error, thus reserving these combinations for future
625  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
626  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
627  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
628  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)
629    option setting within a pattern.
630  <pre>  <pre>
631    PCRE_FIRSTLINE    PCRE_FIRSTLINE
632  </pre>  </pre>
# Line 529  If this option is set, an unanchored pat Line 634  If this option is set, an unanchored pat
634  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
635  over the newline.  over the newline.
636  <pre>  <pre>
637      PCRE_JAVASCRIPT_COMPAT
638    </pre>
639    If this option is set, PCRE's behaviour is changed in some ways so that it is
640    compatible with JavaScript rather than Perl. The changes are as follows:
641    </P>
642    <P>
643    (1) A lone closing square bracket in a pattern causes a compile-time error,
644    because this is illegal in JavaScript (by default it is treated as a data
645    character). Thus, the pattern AB]CD becomes illegal when this option is set.
646    </P>
647    <P>
648    (2) At run time, a back reference to an unset subpattern group matches an empty
649    string (by default this causes the current matching alternative to fail). A
650    pattern such as (\1)(a) succeeds when this option is set (assuming it can find
651    an "a" in the subject), whereas it fails by default, for Perl compatibility.
652    </P>
653    <P>
654    (3) \U matches an upper case "U" character; by default \U causes a compile
655    time error (Perl uses \U to upper case subsequent characters).
656    </P>
657    <P>
658    (4) \u matches a lower case "u" character unless it is followed by four
659    hexadecimal digits, in which case the hexadecimal number defines the code point
660    to match. By default, \u causes a compile time error (Perl uses it to upper
661    case the following character).
662    </P>
663    <P>
664    (5) \x matches a lower case "x" character unless it is followed by two
665    hexadecimal digits, in which case the hexadecimal number defines the code point
666    to match. By default, as in Perl, a hexadecimal number is always expected after
667    \x, but it may have zero, one, or two digits (so, for example, \xz matches a
668    binary zero character followed by z).
669    <pre>
670    PCRE_MULTILINE    PCRE_MULTILINE
671  </pre>  </pre>
672  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 573  PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is Line 711  PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is
711  other combinations may yield unused numbers and cause an error.  other combinations may yield unused numbers and cause an error.
712  </P>  </P>
713  <P>  <P>
714  The only time that a line break is specially recognized when compiling a  The only time that a line break in a pattern is specially recognized when
715  pattern is if PCRE_EXTENDED is set, and an unescaped # outside a character  compiling is when PCRE_EXTENDED is set. CR and LF are whitespace characters,
716  class is encountered. This indicates a comment that lasts until after the next  and so are ignored in this mode. Also, an unescaped # outside a character class
717  line break sequence. In other circumstances, line break sequences are treated  indicates a comment that lasts until after the next line break sequence. In
718  as literal data, except that in PCRE_EXTENDED mode, both CR and LF are treated  other circumstances, line break sequences in patterns are treated as literal
719  as whitespace characters and are therefore ignored.  data.
720  </P>  </P>
721  <P>  <P>
722  The newline option that is set at compile time becomes the default that is used  The newline option that is set at compile time becomes the default that is used
# Line 592  were followed by ?: but named parenthese Line 730  were followed by ?: but named parenthese
730  they acquire numbers in the usual way). There is no equivalent of this option  they acquire numbers in the usual way). There is no equivalent of this option
731  in Perl.  in Perl.
732  <pre>  <pre>
733      NO_START_OPTIMIZE
734    </pre>
735    This is an option that acts at matching time; that is, it is really an option
736    for <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>. If it is set at compile time,
737    it is remembered with the compiled pattern and assumed at matching time. For
738    details see the discussion of PCRE_NO_START_OPTIMIZE
739    <a href="#execoptions">below.</a>
740    <pre>
741      PCRE_UCP
742    </pre>
743    This option changes the way PCRE processes \B, \b, \D, \d, \S, \s, \W,
744    \w, and some of the POSIX character classes. By default, only ASCII characters
745    are recognized, but if PCRE_UCP is set, Unicode properties are used instead to
746    classify characters. More details are given in the section on
747    <a href="pcre.html#genericchartypes">generic character types</a>
748    in the
749    <a href="pcrepattern.html"><b>pcrepattern</b></a>
750    page. If you set PCRE_UCP, matching one of the items it affects takes much
751    longer. The option is available only if PCRE has been compiled with Unicode
752    property support.
753    <pre>
754    PCRE_UNGREEDY    PCRE_UNGREEDY
755  </pre>  </pre>
756  This option inverts the "greediness" of the quantifiers so that they are not  This option inverts the "greediness" of the quantifiers so that they are not
# Line 605  of UTF-8 characters instead of single-by Line 764  of UTF-8 characters instead of single-by
764  available only when PCRE is built to include UTF-8 support. If not, the use  available only when PCRE is built to include UTF-8 support. If not, the use
765  of this option provokes an error. Details of how this option changes the  of this option provokes an error. Details of how this option changes the
766  behaviour of PCRE are given in the  behaviour of PCRE are given in the
767  <a href="pcre.html#utf8support">section on UTF-8 support</a>  <a href="pcreunicode.html"><b>pcreunicode</b></a>
 in the main  
 <a href="pcre.html"><b>pcre</b></a>  
768  page.  page.
769  <pre>  <pre>
770    PCRE_NO_UTF8_CHECK    PCRE_NO_UTF8_CHECK
771  </pre>  </pre>
772  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
773  automatically checked. If an invalid UTF-8 sequence of bytes is found,  automatically checked. There is a discussion about the
774  <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>
775  valid, and you want to skip this check for performance reasons, you can set the  in the main
776  PCRE_NO_UTF8_CHECK option. When it is set, the effect of passing an invalid  <a href="pcre.html"><b>pcre</b></a>
777  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>
778  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
779  <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
780  strings.  option. When it is set, the effect of passing an invalid UTF-8 string as a
781    pattern is undefined. It may cause your program to crash. Note that this option
782    can also be passed to <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b>, to suppress
783    the UTF-8 validity checking of subject strings.
784  </P>  </P>
785  <br><a name="SEC8" href="#TOC1">COMPILATION ERROR CODES</a><br>  <br><a name="SEC10" href="#TOC1">COMPILATION ERROR CODES</a><br>
786  <P>  <P>
787  The following table lists the error codes than may be returned by  The following table lists the error codes than may be returned by
788  <b>pcre_compile2()</b>, along with the error messages that may be returned by  <b>pcre_compile2()</b>, along with the error messages that may be returned by
# Line 641  out of use. To avoid confusion, they hav Line 801  out of use. To avoid confusion, they hav
801     9  nothing to repeat     9  nothing to repeat
802    10  [this code is not in use]    10  [this code is not in use]
803    11  internal error: unexpected repeat    11  internal error: unexpected repeat
804    12  unrecognized character after (?    12  unrecognized character after (? or (?-
805    13  POSIX named classes are supported only within a class    13  POSIX named classes are supported only within a class
806    14  missing )    14  missing )
807    15  reference to non-existent subpattern    15  reference to non-existent subpattern
# Line 649  out of use. To avoid confusion, they hav Line 809  out of use. To avoid confusion, they hav
809    17  unknown option bit(s) set    17  unknown option bit(s) set
810    18  missing ) after comment    18  missing ) after comment
811    19  [this code is not in use]    19  [this code is not in use]
812    20  regular expression too large    20  regular expression is too large
813    21  failed to get memory    21  failed to get memory
814    22  unmatched parentheses    22  unmatched parentheses
815    23  internal error: code overflow    23  internal error: code overflow
# Line 658  out of use. To avoid confusion, they hav Line 818  out of use. To avoid confusion, they hav
818    26  malformed number or name after (?(    26  malformed number or name after (?(
819    27  conditional group contains more than two branches    27  conditional group contains more than two branches
820    28  assertion expected after (?(    28  assertion expected after (?(
821    29  (?R or (?digits must be followed by )    29  (?R or (?[+-]digits must be followed by )
822    30  unknown POSIX class name    30  unknown POSIX class name
823    31  POSIX collating elements are not supported    31  POSIX collating elements are not supported
824    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 666  out of use. To avoid confusion, they hav Line 826  out of use. To avoid confusion, they hav
826    34  character value in \x{...} sequence is too large    34  character value in \x{...} sequence is too large
827    35  invalid condition (?(0)    35  invalid condition (?(0)
828    36  \C not allowed in lookbehind assertion    36  \C not allowed in lookbehind assertion
829    37  PCRE does not support \L, \l, \N, \U, or \u    37  PCRE does not support \L, \l, \N{name}, \U, or \u
830    38  number after (?C is &#62; 255    38  number after (?C is &#62; 255
831    39  closing ) for (?C expected    39  closing ) for (?C expected
832    40  recursive call could loop indefinitely    40  recursive call could loop indefinitely
# Line 678  out of use. To avoid confusion, they hav Line 838  out of use. To avoid confusion, they hav
838    46  malformed \P or \p sequence    46  malformed \P or \p sequence
839    47  unknown property name after \P or \p    47  unknown property name after \P or \p
840    48  subpattern name is too long (maximum 32 characters)    48  subpattern name is too long (maximum 32 characters)
841    49  too many named subpatterns (maximum 10,000)    49  too many named subpatterns (maximum 10000)
842    50  repeated subpattern is too long    50  [this code is not in use]
843    51  octal value is greater than \377 (not in UTF-8 mode)    51  octal value is greater than \377 (not in UTF-8 mode)
844    52  internal error: overran compiling workspace    52  internal error: overran compiling workspace
845    53  internal error: previously-checked referenced subpattern not found    53  internal error: previously-checked referenced subpattern
846            not found
847    54  DEFINE group contains more than one branch    54  DEFINE group contains more than one branch
848    55  repeating a DEFINE group is not allowed    55  repeating a DEFINE group is not allowed
849    56  inconsistent NEWLINE options"    56  inconsistent NEWLINE options
850  </PRE>    57  \g is not followed by a braced, angle-bracketed, or quoted
851  </P>          name/number or by a plain number
852  <br><a name="SEC9" href="#TOC1">STUDYING A PATTERN</a><br>    58  a numbered reference must not be zero
853      59  an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)
854      60  (*VERB) not recognized
855      61  number is too big
856      62  subpattern name expected
857      63  digit expected after (?+
858      64  ] is an invalid data character in JavaScript compatibility mode
859      65  different names for subpatterns of the same number are
860            not allowed
861      66  (*MARK) must have an argument
862      67  this version of PCRE is not compiled with PCRE_UCP support
863      68  \c must be followed by an ASCII character
864      69  \k is not followed by a braced, angle-bracketed, or quoted name
865    </pre>
866    The numbers 32 and 10000 in errors 48 and 49 are defaults; different values may
867    be used if the limits were changed when PCRE was built.
868    <a name="studyingapattern"></a></P>
869    <br><a name="SEC11" href="#TOC1">STUDYING A PATTERN</a><br>
870  <P>  <P>
871  <b>pcre_extra *pcre_study(const pcre *<i>code</i>, int <i>options</i></b>  <b>pcre_extra *pcre_study(const pcre *<i>code</i>, int <i>options</i></b>
872  <b>const char **<i>errptr</i>);</b>  <b>const char **<i>errptr</i>);</b>
# Line 704  results of the study. Line 882  results of the study.
882  </P>  </P>
883  <P>  <P>
884  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
885  <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
886  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
887  described  passed; these are described
888  <a href="#extradata">below</a>  <a href="#extradata">below</a>
889  in the section on matching a pattern.  in the section on matching a pattern.
890  </P>  </P>
891  <P>  <P>
892  If studying the pattern does not produce any additional information  If studying the pattern does not produce any useful information,
893  <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
894  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
895  own <b>pcre_extra</b> block.  <b>pcre_dfa_exec()</b>, it must set up its own <b>pcre_extra</b> block.
896  </P>  </P>
897  <P>  <P>
898  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. There is only
899  options are defined, and this argument should always be zero.  one option: PCRE_STUDY_JIT_COMPILE. If this is set, and the just-in-time
900    compiler is available, the pattern is further compiled into machine code that
901    executes much faster than the <b>pcre_exec()</b> matching function. If
902    the just-in-time compiler is not available, this option is ignored. All other
903    bits in the <i>options</i> argument must be zero.
904    </P>
905    <P>
906    JIT compilation is a heavyweight optimization. It can take some time for
907    patterns to be analyzed, and for one-off matches and simple patterns the
908    benefit of faster execution might be offset by a much slower study time.
909    Not all patterns can be optimized by the JIT compiler. For those that cannot be
910    handled, matching automatically falls back to the <b>pcre_exec()</b>
911    interpreter. For more details, see the
912    <a href="pcrejit.html"><b>pcrejit</b></a>
913    documentation.
914  </P>  </P>
915  <P>  <P>
916  The third argument for <b>pcre_study()</b> is a pointer for an error message. If  The third argument for <b>pcre_study()</b> is a pointer for an error message. If
# Line 729  should test the error pointer for NULL a Line 921  should test the error pointer for NULL a
921  sure that it has run successfully.  sure that it has run successfully.
922  </P>  </P>
923  <P>  <P>
924  This is a typical call to <b>pcre_study</b>():  When you are finished with a pattern, you can free the memory used for the
925    study data by calling <b>pcre_free_study()</b>. This function was added to the
926    API for release 8.20. For earlier versions, the memory could be freed with
927    <b>pcre_free()</b>, just like the pattern itself. This will still work in cases
928    where PCRE_STUDY_JIT_COMPILE is not used, but it is advisable to change to the
929    new function when convenient.
930    </P>
931    <P>
932    This is a typical way in which <b>pcre_study</b>() is used (except that in a
933    real application there should be tests for errors):
934  <pre>  <pre>
935    pcre_extra *pe;    int rc;
936    pe = pcre_study(    pcre *re;
937      pcre_extra *sd;
938      re = pcre_compile("pattern", 0, &error, &erroroffset, NULL);
939      sd = pcre_study(
940      re,             /* result of pcre_compile() */      re,             /* result of pcre_compile() */
941      0,              /* no options exist */      0,              /* no options */
942      &error);        /* set to NULL or points to a message */      &error);        /* set to NULL or points to a message */
943  </pre>    rc = pcre_exec(   /* see below for details of pcre_exec() options */
944  At present, studying a pattern is useful only for non-anchored patterns that do      re, sd, "subject", 7, 0, 0, ovector, 30);
945  not have a single fixed starting character. A bitmap of possible starting    ...
946  bytes is created.    pcre_free_study(sd);
947      pcre_free(re);
948    </pre>
949    Studying a pattern does two things: first, a lower bound for the length of
950    subject string that is needed to match the pattern is computed. This does not
951    mean that there are any strings of that length that match, but it does
952    guarantee that no shorter strings match. The value is used by
953    <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b> to avoid wasting time by trying to
954    match strings that are shorter than the lower bound. You can find out the value
955    in a calling program via the <b>pcre_fullinfo()</b> function.
956    </P>
957    <P>
958    Studying a pattern is also useful for non-anchored patterns that do not have a
959    single fixed starting character. A bitmap of possible starting bytes is
960    created. This speeds up finding a position in the subject at which to start
961    matching.
962    </P>
963    <P>
964    These two optimizations apply to both <b>pcre_exec()</b> and
965    <b>pcre_dfa_exec()</b>. However, they are not used by <b>pcre_exec()</b> if
966    <b>pcre_study()</b> is called with the PCRE_STUDY_JIT_COMPILE option, and
967    just-in-time compiling is successful. The optimizations can be disabled by
968    setting the PCRE_NO_START_OPTIMIZE option when calling <b>pcre_exec()</b> or
969    <b>pcre_dfa_exec()</b>. You might want to do this if your pattern contains
970    callouts or (*MARK) (which cannot be handled by the JIT compiler), and you want
971    to make use of these facilities in cases where matching fails. See the
972    discussion of PCRE_NO_START_OPTIMIZE
973    <a href="#execoptions">below.</a>
974  <a name="localesupport"></a></P>  <a name="localesupport"></a></P>
975  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>  <br><a name="SEC12" href="#TOC1">LOCALE SUPPORT</a><br>
976  <P>  <P>
977  PCRE handles caseless matching, and determines whether characters are letters,  PCRE handles caseless matching, and determines whether characters are letters,
978  digits, or whatever, by reference to a set of tables, indexed by character  digits, or whatever, by reference to a set of tables, indexed by character
979  value. When running in UTF-8 mode, this applies only to characters with codes  value. When running in UTF-8 mode, this applies only to characters with codes
980  less than 128. Higher-valued codes never match escapes such as \w or \d, but  less than 128. By default, higher-valued codes never match escapes such as \w
981  can be tested with \p if PCRE is built with Unicode character property  or \d, but they can be tested with \p if PCRE is built with Unicode character
982  support. The use of locales with Unicode is discouraged. If you are handling  property support. Alternatively, the PCRE_UCP option can be set at compile
983  characters with codes greater than 128, you should either use UTF-8 and  time; this causes \w and friends to use Unicode property support instead of
984  Unicode, or use locales, but not try to mix the two.  built-in tables. The use of locales with Unicode is discouraged. If you are
985    handling characters with codes greater than 128, you should either use UTF-8
986    and Unicode, or use locales, but not try to mix the two.
987  </P>  </P>
988  <P>  <P>
989  PCRE contains an internal set of tables that are used when the final argument  PCRE contains an internal set of tables that are used when the final argument
# Line 799  internal tables) to pcre_exec(). Line 1032  internal tables) to pcre_exec().
1032  this facility could be used to match a pattern in a different locale from the  this facility could be used to match a pattern in a different locale from the
1033  one in which it was compiled. Passing table pointers at run time is discussed  one in which it was compiled. Passing table pointers at run time is discussed
1034  below in the section on matching a pattern.  below in the section on matching a pattern.
1035  </P>  <a name="infoaboutpattern"></a></P>
1036  <br><a name="SEC11" href="#TOC1">INFORMATION ABOUT A PATTERN</a><br>  <br><a name="SEC13" href="#TOC1">INFORMATION ABOUT A PATTERN</a><br>
1037  <P>  <P>
1038  <b>int pcre_fullinfo(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>  <b>int pcre_fullinfo(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>
1039  <b>int <i>what</i>, void *<i>where</i>);</b>  <b>int <i>what</i>, void *<i>where</i>);</b>
# Line 831  check against passing an arbitrary memor Line 1064  check against passing an arbitrary memor
1064    size_t length;    size_t length;
1065    rc = pcre_fullinfo(    rc = pcre_fullinfo(
1066      re,               /* result of pcre_compile() */      re,               /* result of pcre_compile() */
1067      pe,               /* result of pcre_study(), or NULL */      sd,               /* result of pcre_study(), or NULL */
1068      PCRE_INFO_SIZE,   /* what is required */      PCRE_INFO_SIZE,   /* what is required */
1069      &length);         /* where to put the data */      &length);         /* where to put the data */
1070  </pre>  </pre>
# Line 888  table indicating a fixed set of bytes fo Line 1121  table indicating a fixed set of bytes fo
1121  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
1122  fourth argument should point to an <b>unsigned char *</b> variable.  fourth argument should point to an <b>unsigned char *</b> variable.
1123  <pre>  <pre>
1124      PCRE_INFO_HASCRORLF
1125    </pre>
1126    Return 1 if the pattern contains any explicit matches for CR or LF characters,
1127    otherwise 0. The fourth argument should point to an <b>int</b> variable. An
1128    explicit match is either a literal CR or LF character, or \r or \n.
1129    <pre>
1130      PCRE_INFO_JCHANGED
1131    </pre>
1132    Return 1 if the (?J) or (?-J) option setting is used in the pattern, otherwise
1133    0. The fourth argument should point to an <b>int</b> variable. (?J) and
1134    (?-J) set and unset the local PCRE_DUPNAMES option, respectively.
1135    <pre>
1136      PCRE_INFO_JIT
1137    </pre>
1138    Return 1 if the pattern was studied with the PCRE_STUDY_JIT_COMPILE option, and
1139    just-in-time compiling was successful. The fourth argument should point to an
1140    <b>int</b> variable. A return value of 0 means that JIT support is not available
1141    in this version of PCRE, or that the pattern was not studied with the
1142    PCRE_STUDY_JIT_COMPILE option, or that the JIT compiler could not handle this
1143    particular pattern. See the
1144    <a href="pcrejit.html"><b>pcrejit</b></a>
1145    documentation for details of what can and cannot be handled.
1146    <pre>
1147      PCRE_INFO_JITSIZE
1148    </pre>
1149    If the pattern was successfully studied with the PCRE_STUDY_JIT_COMPILE option,
1150    return the size of the JIT compiled code, otherwise return zero. The fourth
1151    argument should point to a <b>size_t</b> variable.
1152    <pre>
1153    PCRE_INFO_LASTLITERAL    PCRE_INFO_LASTLITERAL
1154  </pre>  </pre>
1155  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 898  follows something of variable length. Fo Line 1160  follows something of variable length. Fo
1160  /^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
1161  is -1.  is -1.
1162  <pre>  <pre>
1163      PCRE_INFO_MINLENGTH
1164    </pre>
1165    If the pattern was studied and a minimum length for matching subject strings
1166    was computed, its value is returned. Otherwise the returned value is -1. The
1167    value is a number of characters, not bytes (this may be relevant in UTF-8
1168    mode). The fourth argument should point to an <b>int</b> variable. A
1169    non-negative value is a lower bound to the length of any matching string. There
1170    may not be any strings of that length that do actually match, but every string
1171    that does match is at least that long.
1172    <pre>
1173    PCRE_INFO_NAMECOUNT    PCRE_INFO_NAMECOUNT
1174    PCRE_INFO_NAMEENTRYSIZE    PCRE_INFO_NAMEENTRYSIZE
1175    PCRE_INFO_NAMETABLE    PCRE_INFO_NAMETABLE
# Line 919  entry; both of these return an int Line 1191  entry; both of these return an int
1191  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
1192  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
1193  are the number of the capturing parenthesis, most significant byte first. The  are the number of the capturing parenthesis, most significant byte first. The
1194  rest of the entry is the corresponding name, zero terminated. The names are in  rest of the entry is the corresponding name, zero terminated.
1195  alphabetical order. When PCRE_DUPNAMES is set, duplicate names are in order of  </P>
1196  their parentheses numbers. For example, consider the following pattern (assume  <P>
1197  PCRE_EXTENDED is set, so white space - including newlines - is ignored):  The names are in alphabetical order. Duplicate names may appear if (?| is used
1198    to create multiple groups with the same number, as described in the
1199    <a href="pcrepattern.html#dupsubpatternnumber">section on duplicate subpattern numbers</a>
1200    in the
1201    <a href="pcrepattern.html"><b>pcrepattern</b></a>
1202    page. Duplicate names for subpatterns with different numbers are permitted only
1203    if PCRE_DUPNAMES is set. In all cases of duplicate names, they appear in the
1204    table in the order in which they were found in the pattern. In the absence of
1205    (?| this is the order of increasing number; when (?| is used this is not
1206    necessarily the case because later subpatterns may have lower numbers.
1207    </P>
1208    <P>
1209    As a simple example of the name/number table, consider the following pattern
1210    (assume PCRE_EXTENDED is set, so white space - including newlines - is
1211    ignored):
1212  <pre>  <pre>
1213    (?&#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) )
1214  </pre>  </pre>
# Line 939  When writing code to extract data from n Line 1225  When writing code to extract data from n
1225  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
1226  different for each compiled pattern.  different for each compiled pattern.
1227  <pre>  <pre>
1228      PCRE_INFO_OKPARTIAL
1229    </pre>
1230    Return 1 if the pattern can be used for partial matching with
1231    <b>pcre_exec()</b>, otherwise 0. The fourth argument should point to an
1232    <b>int</b> variable. From release 8.00, this always returns 1, because the
1233    restrictions that previously applied to partial matching have been lifted. The
1234    <a href="pcrepartial.html"><b>pcrepartial</b></a>
1235    documentation gives details of partial matching.
1236    <pre>
1237    PCRE_INFO_OPTIONS    PCRE_INFO_OPTIONS
1238  </pre>  </pre>
1239  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
1240  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
1241  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
1242  top-level option settings within the pattern itself.  top-level option settings at the start of the pattern itself. In other words,
1243    they are the options that will be in force when matching starts. For example,
1244    if the pattern /(?im)abc(?-i)d/ is compiled with the PCRE_EXTENDED option, the
1245    result is PCRE_CASELESS, PCRE_MULTILINE, and PCRE_EXTENDED.
1246  </P>  </P>
1247  <P>  <P>
1248  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 960  For such patterns, the PCRE_ANCHORED bit Line 1258  For such patterns, the PCRE_ANCHORED bit
1258  <pre>  <pre>
1259    PCRE_INFO_SIZE    PCRE_INFO_SIZE
1260  </pre>  </pre>
1261  Return the size of the compiled pattern, that is, the value that was passed as  Return the size of the compiled pattern. The fourth argument should point to a
1262  the argument to <b>pcre_malloc()</b> when PCRE was getting memory in which to  <b>size_t</b> variable. This value does not include the size of the <b>pcre</b>
1263  place the compiled data. The fourth argument should point to a <b>size_t</b>  structure that is returned by <b>pcre_compile()</b>. The value that is passed as
1264  variable.  the argument to <b>pcre_malloc()</b> when <b>pcre_compile()</b> is getting memory
1265    in which to place the compiled data is the value returned by this option plus
1266    the size of the <b>pcre</b> structure. Studying a compiled pattern, with or
1267    without JIT, does not alter the value returned by this option.
1268  <pre>  <pre>
1269    PCRE_INFO_STUDYSIZE    PCRE_INFO_STUDYSIZE
1270  </pre>  </pre>
1271  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 a
1272  a <b>pcre_extra</b> block. That is, it is the value that was passed to  <b>pcre_extra</b> block. If <b>pcre_extra</b> is NULL, or there is no study data,
1273  <b>pcre_malloc()</b> when PCRE was getting memory into which to place the data  zero is returned. The fourth argument should point to a <b>size_t</b> variable.
1274  created by <b>pcre_study()</b>. The fourth argument should point to a  The <i>study_data</i> field is set by <b>pcre_study()</b> to record information
1275  <b>size_t</b> variable.  that will speed up matching (see the section entitled
1276    <a href="#studyingapattern">"Studying a pattern"</a>
1277    above). The format of the <i>study_data</i> block is private, but its length
1278    is made available via this option so that it can be saved and restored (see the
1279    <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
1280    documentation for details).
1281  </P>  </P>
1282  <br><a name="SEC12" href="#TOC1">OBSOLETE INFO FUNCTION</a><br>  <br><a name="SEC14" href="#TOC1">OBSOLETE INFO FUNCTION</a><br>
1283  <P>  <P>
1284  <b>int pcre_info(const pcre *<i>code</i>, int *<i>optptr</i>, int</b>  <b>int pcre_info(const pcre *<i>code</i>, int *<i>optptr</i>, int</b>
1285  <b>*<i>firstcharptr</i>);</b>  <b>*<i>firstcharptr</i>);</b>
# Line 997  If the pattern is not anchored and the < Line 1303  If the pattern is not anchored and the <
1303  it is used to pass back information about the first character of any matched  it is used to pass back information about the first character of any matched
1304  string (see PCRE_INFO_FIRSTBYTE above).  string (see PCRE_INFO_FIRSTBYTE above).
1305  </P>  </P>
1306  <br><a name="SEC13" href="#TOC1">REFERENCE COUNTS</a><br>  <br><a name="SEC15" href="#TOC1">REFERENCE COUNTS</a><br>
1307  <P>  <P>
1308  <b>int pcre_refcount(pcre *<i>code</i>, int <i>adjust</i>);</b>  <b>int pcre_refcount(pcre *<i>code</i>, int <i>adjust</i>);</b>
1309  </P>  </P>
# Line 1021  Except when it is zero, the reference co Line 1327  Except when it is zero, the reference co
1327  pattern is compiled on one host and then transferred to a host whose byte-order  pattern is compiled on one host and then transferred to a host whose byte-order
1328  is different. (This seems a highly unlikely scenario.)  is different. (This seems a highly unlikely scenario.)
1329  </P>  </P>
1330  <br><a name="SEC14" href="#TOC1">MATCHING A PATTERN: THE TRADITIONAL FUNCTION</a><br>  <br><a name="SEC16" href="#TOC1">MATCHING A PATTERN: THE TRADITIONAL FUNCTION</a><br>
1331  <P>  <P>
1332  <b>int pcre_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>  <b>int pcre_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>
1333  <b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b>  <b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b>
# Line 1030  is different. (This seems a highly unlik Line 1336  is different. (This seems a highly unlik
1336  <P>  <P>
1337  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
1338  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
1339  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
1340  <i>extra</i> argument. This function is the main matching facility of the  <i>extra</i> argument. You can call <b>pcre_exec()</b> with the same <i>code</i>
1341  library, and it operates in a Perl-like manner. For specialist use there is  and <i>extra</i> arguments as many times as you like, in order to match
1342  also an alternative matching function, which is described  different subject strings with the same pattern.
1343    </P>
1344    <P>
1345    This function is the main matching facility of the library, and it operates in
1346    a Perl-like manner. For specialist use there is also an alternative matching
1347    function, which is described
1348  <a href="#dfamatch">below</a>  <a href="#dfamatch">below</a>
1349  in the section about the <b>pcre_dfa_exec()</b> function.  in the section about the <b>pcre_dfa_exec()</b> function.
1350  </P>  </P>
# Line 1074  fields (not necessarily in this order): Line 1385  fields (not necessarily in this order):
1385  <pre>  <pre>
1386    unsigned long int <i>flags</i>;    unsigned long int <i>flags</i>;
1387    void *<i>study_data</i>;    void *<i>study_data</i>;
1388      void *<i>executable_jit</i>;
1389    unsigned long int <i>match_limit</i>;    unsigned long int <i>match_limit</i>;
1390    unsigned long int <i>match_limit_recursion</i>;    unsigned long int <i>match_limit_recursion</i>;
1391    void *<i>callout_data</i>;    void *<i>callout_data</i>;
1392    const unsigned char *<i>tables</i>;    const unsigned char *<i>tables</i>;
1393      unsigned char **<i>mark</i>;
1394  </pre>  </pre>
1395  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
1396  are set. The flag bits are:  are set. The flag bits are:
1397  <pre>  <pre>
1398    PCRE_EXTRA_STUDY_DATA    PCRE_EXTRA_STUDY_DATA
1399      PCRE_EXTRA_EXECUTABLE_JIT
1400    PCRE_EXTRA_MATCH_LIMIT    PCRE_EXTRA_MATCH_LIMIT
1401    PCRE_EXTRA_MATCH_LIMIT_RECURSION    PCRE_EXTRA_MATCH_LIMIT_RECURSION
1402    PCRE_EXTRA_CALLOUT_DATA    PCRE_EXTRA_CALLOUT_DATA
1403    PCRE_EXTRA_TABLES    PCRE_EXTRA_TABLES
1404      PCRE_EXTRA_MARK
1405  </pre>  </pre>
1406  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 and sometimes
1407  <b>pcre_extra</b> block that is returned by <b>pcre_study()</b>, together with  the <i>executable_jit</i> field are set in the <b>pcre_extra</b> block that is
1408  the appropriate flag bit. You should not set this yourself, but you may add to  returned by <b>pcre_study()</b>, together with the appropriate flag bits. You
1409  the block by setting the other fields and their corresponding flag bits.  should not set these yourself, but you may add to the block by setting the
1410    other fields and their corresponding flag bits.
1411  </P>  </P>
1412  <P>  <P>
1413  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
1414  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,
1415  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
1416  classic example is the use of nested unlimited repeats.  classic example is a pattern that uses nested unlimited repeats.
1417  </P>  </P>
1418  <P>  <P>
1419  Internally, PCRE uses a function called <b>match()</b> which it calls repeatedly  Internally, <b>pcre_exec()</b> uses a function called <b>match()</b>, which it
1420  (sometimes recursively). The limit set by <i>match_limit</i> is imposed on the  calls repeatedly (sometimes recursively). The limit set by <i>match_limit</i> is
1421  number of times this function is called during a match, which has the effect of  imposed on the number of times this function is called during a match, which
1422  limiting the amount of backtracking that can take place. For patterns that are  has the effect of limiting the amount of backtracking that can take place. For
1423  not anchored, the count restarts from zero for each position in the subject  patterns that are not anchored, the count restarts from zero for each position
1424  string.  in the subject string.
1425    </P>
1426    <P>
1427    When <b>pcre_exec()</b> is called with a pattern that was successfully studied
1428    with the PCRE_STUDY_JIT_COMPILE option, the way that the matching is executed
1429    is entirely different. However, there is still the possibility of runaway
1430    matching that goes on for a very long time, and so the <i>match_limit</i> value
1431    is also used in this case (but in a different way) to limit how long the
1432    matching can continue.
1433  </P>  </P>
1434  <P>  <P>
1435  The default value for the limit can be set when PCRE is built; the default  The default value for the limit can be set when PCRE is built; the default
# Line 1123  total number of calls, because not all c Line 1447  total number of calls, because not all c
1447  This limit is of use only if it is set smaller than <i>match_limit</i>.  This limit is of use only if it is set smaller than <i>match_limit</i>.
1448  </P>  </P>
1449  <P>  <P>
1450  Limiting the recursion depth limits the amount of stack that can be used, or,  Limiting the recursion depth limits the amount of machine stack that can be
1451  when PCRE has been compiled to use memory on the heap instead of the stack, the  used, or, when PCRE has been compiled to use memory on the heap instead of the
1452  amount of heap memory that can be used.  stack, the amount of heap memory that can be used. This limit is not relevant,
1453    and is ignored, if the pattern was successfully studied with
1454    PCRE_STUDY_JIT_COMPILE.
1455  </P>  </P>
1456  <P>  <P>
1457  The default value for <i>match_limit_recursion</i> can be set when PCRE is  The default value for <i>match_limit_recursion</i> can be set when PCRE is
# Line 1136  PCRE_EXTRA_MATCH_LIMIT_RECURSION is set Line 1462  PCRE_EXTRA_MATCH_LIMIT_RECURSION is set
1462  is exceeded, <b>pcre_exec()</b> returns PCRE_ERROR_RECURSIONLIMIT.  is exceeded, <b>pcre_exec()</b> returns PCRE_ERROR_RECURSIONLIMIT.
1463  </P>  </P>
1464  <P>  <P>
1465  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,
1466  which is described in the  and is described in the
1467  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
1468  documentation.  documentation.
1469  </P>  </P>
# Line 1154  called. See the Line 1480  called. See the
1480  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
1481  documentation for a discussion of saving compiled patterns for later use.  documentation for a discussion of saving compiled patterns for later use.
1482  </P>  </P>
1483    <P>
1484    If PCRE_EXTRA_MARK is set in the <i>flags</i> field, the <i>mark</i> field must
1485    be set to point to a <b>char *</b> variable. If the pattern contains any
1486    backtracking control verbs such as (*MARK:NAME), and the execution ends up with
1487    a name to pass back, a pointer to the name string (zero terminated) is placed
1488    in the variable pointed to by the <i>mark</i> field. The names are within the
1489    compiled pattern; if you wish to retain such a name you must copy it before
1490    freeing the memory of a compiled pattern. If there is no name to pass back, the
1491    variable pointed to by the <i>mark</i> field set to NULL. For details of the
1492    backtracking control verbs, see the section entitled
1493    <a href="pcrepattern#backtrackcontrol">"Backtracking control"</a>
1494    in the
1495    <a href="pcrepattern.html"><b>pcrepattern</b></a>
1496    documentation.
1497    <a name="execoptions"></a></P>
1498  <br><b>  <br><b>
1499  Option bits for <b>pcre_exec()</b>  Option bits for <b>pcre_exec()</b>
1500  </b><br>  </b><br>
1501  <P>  <P>
1502  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
1503  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>,
1504  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK and PCRE_PARTIAL.  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART,
1505    PCRE_NO_START_OPTIMIZE, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_SOFT, and
1506    PCRE_PARTIAL_HARD.
1507    </P>
1508    <P>
1509    If the pattern was successfully studied with the PCRE_STUDY_JIT_COMPILE option,
1510    the only supported options for JIT execution are PCRE_NO_UTF8_CHECK,
1511    PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, and PCRE_NOTEMPTY_ATSTART. Note in
1512    particular that partial matching is not supported. If an unsupported option is
1513    used, JIT execution is disabled and the normal interpretive code in
1514    <b>pcre_exec()</b> is run.
1515  <pre>  <pre>
1516    PCRE_ANCHORED    PCRE_ANCHORED
1517  </pre>  </pre>
# Line 1169  matching position. If a pattern was comp Line 1520  matching position. If a pattern was comp
1520  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
1521  matching time.  matching time.
1522  <pre>  <pre>
1523      PCRE_BSR_ANYCRLF
1524      PCRE_BSR_UNICODE
1525    </pre>
1526    These options (which are mutually exclusive) control what the \R escape
1527    sequence matches. The choice is either to match only CR, LF, or CRLF, or to
1528    match any Unicode newline sequence. These options override the choice that was
1529    made or defaulted when the pattern was compiled.
1530    <pre>
1531    PCRE_NEWLINE_CR    PCRE_NEWLINE_CR
1532    PCRE_NEWLINE_LF    PCRE_NEWLINE_LF
1533    PCRE_NEWLINE_CRLF    PCRE_NEWLINE_CRLF
# Line 1180  the pattern was compiled. For details, s Line 1539  the pattern was compiled. For details, s
1539  <b>pcre_compile()</b> above. During matching, the newline choice affects the  <b>pcre_compile()</b> above. During matching, the newline choice affects the
1540  behaviour of the dot, circumflex, and dollar metacharacters. It may also alter  behaviour of the dot, circumflex, and dollar metacharacters. It may also alter
1541  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
1542  pattern. When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is  pattern.
1543  set, and a match attempt fails when the current position is at a CRLF sequence,  </P>
1544  the match position is advanced by two characters instead of one, in other  <P>
1545  words, to after the CRLF.  When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is set, and a
1546    match attempt for an unanchored pattern fails when the current position is at a
1547    CRLF sequence, and the pattern contains no explicit matches for CR or LF
1548    characters, the match position is advanced by two characters instead of one, in
1549    other words, to after the CRLF.
1550    </P>
1551    <P>
1552    The above rule is a compromise that makes the most common cases work as
1553    expected. For example, if the pattern is .+A (and the PCRE_DOTALL option is not
1554    set), it does not match the string "\r\nA" because, after failing at the
1555    start, it skips both the CR and the LF before retrying. However, the pattern
1556    [\r\n]A does match that string, because it contains an explicit CR or LF
1557    reference, and so advances only by one character after the first failure.
1558    </P>
1559    <P>
1560    An explicit match for CR of LF is either a literal appearance of one of those
1561    characters, or one of the \r or \n escape sequences. Implicit matches such as
1562    [^X] do not count, nor does \s (which includes CR and LF in the characters
1563    that it matches).
1564    </P>
1565    <P>
1566    Notwithstanding the above, anomalous effects may still occur when CRLF is a
1567    valid newline sequence and explicit \r or \n escapes appear in the pattern.
1568  <pre>  <pre>
1569    PCRE_NOTBOL    PCRE_NOTBOL
1570  </pre>  </pre>
# Line 1209  match the empty string, the entire match Line 1590  match the empty string, the entire match
1590  <pre>  <pre>
1591    a?b?    a?b?
1592  </pre>  </pre>
1593  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
1594  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
1595  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".
1596    <pre>
1597      PCRE_NOTEMPTY_ATSTART
1598    </pre>
1599    This is like PCRE_NOTEMPTY, except that an empty string match that is not at
1600    the start of the subject is permitted. If the pattern is anchored, such a match
1601    can occur only if the pattern contains \K.
1602  </P>  </P>
1603  <P>  <P>
1604  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
1605  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
1606  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
1607  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
1608  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
1609  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
1610  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
1611    the
1612    <a href="pcredemo.html"><b>pcredemo</b></a>
1613    sample program. In the most general case, you have to check to see if the
1614    newline convention recognizes CRLF as a newline, and if so, and the current
1615    character is CR followed by LF, advance the starting offset by two characters
1616    instead of one.
1617    <pre>
1618      PCRE_NO_START_OPTIMIZE
1619    </pre>
1620    There are a number of optimizations that <b>pcre_exec()</b> uses at the start of
1621    a match, in order to speed up the process. For example, if it is known that an
1622    unanchored match must start with a specific character, it searches the subject
1623    for that character, and fails immediately if it cannot find it, without
1624    actually running the main matching function. This means that a special item
1625    such as (*COMMIT) at the start of a pattern is not considered until after a
1626    suitable starting point for the match has been found. When callouts or (*MARK)
1627    items are in use, these "start-up" optimizations can cause them to be skipped
1628    if the pattern is never actually used. The start-up optimizations are in effect
1629    a pre-scan of the subject that takes place before the pattern is run.
1630    </P>
1631    <P>
1632    The PCRE_NO_START_OPTIMIZE option disables the start-up optimizations, possibly
1633    causing performance to suffer, but ensuring that in cases where the result is
1634    "no match", the callouts do occur, and that items such as (*COMMIT) and (*MARK)
1635    are considered at every possible starting position in the subject string. If
1636    PCRE_NO_START_OPTIMIZE is set at compile time, it cannot be unset at matching
1637    time.
1638    </P>
1639    <P>
1640    Setting PCRE_NO_START_OPTIMIZE can change the outcome of a matching operation.
1641    Consider the pattern
1642    <pre>
1643      (*COMMIT)ABC
1644    </pre>
1645    When this is compiled, PCRE records the fact that a match must start with the
1646    character "A". Suppose the subject string is "DEFABC". The start-up
1647    optimization scans along the subject, finds "A" and runs the first match
1648    attempt from there. The (*COMMIT) item means that the pattern must match the
1649    current starting position, which in this case, it does. However, if the same
1650    match is run with PCRE_NO_START_OPTIMIZE set, the initial scan along the
1651    subject string does not happen. The first match attempt is run starting from
1652    "D" and when this fails, (*COMMIT) prevents any further matches being tried, so
1653    the overall result is "no match". If the pattern is studied, more start-up
1654    optimizations may be used. For example, a minimum length for the subject may be
1655    recorded. Consider the pattern
1656    <pre>
1657      (*MARK:A)(X|Y)
1658    </pre>
1659    The minimum length for a match is one character. If the subject is "ABC", there
1660    will be attempts to match "ABC", "BC", "C", and then finally an empty string.
1661    If the pattern is studied, the final attempt does not take place, because PCRE
1662    knows that the subject is too short, and so the (*MARK) is never encountered.
1663    In this case, studying the pattern does not affect the overall match result,
1664    which is still "no match", but it does affect the auxiliary information that is
1665    returned.
1666  <pre>  <pre>
1667    PCRE_NO_UTF8_CHECK    PCRE_NO_UTF8_CHECK
1668  </pre>  </pre>
1669  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
1670  string is automatically checked when <b>pcre_exec()</b> is subsequently called.  string is automatically checked when <b>pcre_exec()</b> is subsequently called.
1671  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
1672  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
1673  <b>pcre_exec()</b> returns the error PCRE_ERROR_BADUTF8. If <i>startoffset</i>  strings in the
1674  contains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned.  <a href="pcre.html#utf8strings">section on UTF-8 support</a>
1675    in the main
1676    <a href="pcre.html"><b>pcre</b></a>
1677    page. If an invalid UTF-8 sequence of bytes is found, <b>pcre_exec()</b> returns
1678    the error PCRE_ERROR_BADUTF8 or, if PCRE_PARTIAL_HARD is set and the problem is
1679    a truncated UTF-8 character at the end of the subject, PCRE_ERROR_SHORTUTF8. In
1680    both cases, information about the precise nature of the error may also be
1681    returned (see the descriptions of these errors in the section entitled \fIError
1682    return values from\fP <b>pcre_exec()</b>
1683    <a href="#errorlist">below).</a>
1684    If <i>startoffset</i> contains a value that does not point to the start of a
1685    UTF-8 character (or to the end of the subject), PCRE_ERROR_BADUTF8_OFFSET is
1686    returned.
1687  </P>  </P>
1688  <P>  <P>
1689  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 1237  checks for performance reasons, you can Line 1691  checks for performance reasons, you can
1691  calling <b>pcre_exec()</b>. You might want to do this for the second and  calling <b>pcre_exec()</b>. You might want to do this for the second and
1692  subsequent calls to <b>pcre_exec()</b> if you are making repeated calls to find  subsequent calls to <b>pcre_exec()</b> if you are making repeated calls to find
1693  all the matches in a single subject string. However, you should be sure that  all the matches in a single subject string. However, you should be sure that
1694  the value of <i>startoffset</i> points to the start of a UTF-8 character. When  the value of <i>startoffset</i> points to the start of a UTF-8 character (or the
1695  PCRE_NO_UTF8_CHECK is set, the effect of passing an invalid UTF-8 string as a  end of the subject). When PCRE_NO_UTF8_CHECK is set, the effect of passing an
1696  subject, or a value of <i>startoffset</i> that does not point to the start of a  invalid UTF-8 string as a subject or an invalid value of <i>startoffset</i> is
1697  UTF-8 character, is undefined. Your program may crash.  undefined. Your program may crash.
1698  <pre>  <pre>
1699    PCRE_PARTIAL    PCRE_PARTIAL_HARD
1700  </pre>    PCRE_PARTIAL_SOFT
1701  This option turns on the partial matching feature. If the subject string fails  </pre>
1702  to match the pattern, but at some point during the matching process the end of  These options turn on the partial matching feature. For backwards
1703  the subject was reached (that is, the subject partially matches the pattern and  compatibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial match
1704  the failure to match occurred only because there were not enough subject  occurs if the end of the subject string is reached successfully, but there are
1705  characters), <b>pcre_exec()</b> returns PCRE_ERROR_PARTIAL instead of  not enough subject characters to complete the match. If this happens when
1706  PCRE_ERROR_NOMATCH. When PCRE_PARTIAL is used, there are restrictions on what  PCRE_PARTIAL_SOFT (but not PCRE_PARTIAL_HARD) is set, matching continues by
1707  may appear in the pattern. These are discussed in the  testing any remaining alternatives. Only if no complete match can be found is
1708    PCRE_ERROR_PARTIAL returned instead of PCRE_ERROR_NOMATCH. In other words,
1709    PCRE_PARTIAL_SOFT says that the caller is prepared to handle a partial match,
1710    but only if no complete match can be found.
1711    </P>
1712    <P>
1713    If PCRE_PARTIAL_HARD is set, it overrides PCRE_PARTIAL_SOFT. In this case, if a
1714    partial match is found, <b>pcre_exec()</b> immediately returns
1715    PCRE_ERROR_PARTIAL, without considering any other alternatives. In other words,
1716    when PCRE_PARTIAL_HARD is set, a partial match is considered to be more
1717    important that an alternative complete match.
1718    </P>
1719    <P>
1720    In both cases, the portion of the string that was inspected when the partial
1721    match was found is set as the first matching string. There is a more detailed
1722    discussion of partial and multi-segment matching, with examples, in the
1723  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
1724  documentation.  documentation.
1725  </P>  </P>
# Line 1259  The string to be matched by pcre_exec Line 1728  The string to be matched by pcre_exec
1728  </b><br>  </b><br>
1729  <P>  <P>
1730  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
1731  <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
1732  <i>startoffset</i>. In UTF-8 mode, the byte offset must point to the start of a  in <i>startoffset</i>. If this is negative or greater than the length of the
1733  UTF-8 character. Unlike the pattern string, the subject may contain binary zero  subject, <b>pcre_exec()</b> returns PCRE_ERROR_BADOFFSET. When the starting
1734  bytes. When the starting offset is zero, the search for a match starts at the  offset is zero, the search for a match starts at the beginning of the subject,
1735  beginning of the subject, and this is by far the most common case.  and this is by far the most common case. In UTF-8 mode, the byte offset must
1736    point to the start of a UTF-8 character (or the end of the subject). Unlike the
1737    pattern string, the subject may contain binary zero bytes.
1738  </P>  </P>
1739  <P>  <P>
1740  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 1285  set to 4, it finds the second occurrence Line 1756  set to 4, it finds the second occurrence
1756  behind the starting point to discover that it is preceded by a letter.  behind the starting point to discover that it is preceded by a letter.
1757  </P>  </P>
1758  <P>  <P>
1759    Finding all the matches in a subject is tricky when the pattern can match an
1760    empty string. It is possible to emulate Perl's /g behaviour by first trying the
1761    match again at the same offset, with the PCRE_NOTEMPTY_ATSTART and
1762    PCRE_ANCHORED options, and then if that fails, advancing the starting offset
1763    and trying an ordinary match again. There is some code that demonstrates how to
1764    do this in the
1765    <a href="pcredemo.html"><b>pcredemo</b></a>
1766    sample program. In the most general case, you have to check to see if the
1767    newline convention recognizes CRLF as a newline, and if so, and the current
1768    character is CR followed by LF, advance the starting offset by two characters
1769    instead of one.
1770    </P>
1771    <P>
1772  If a non-zero starting offset is passed when the pattern is anchored, one  If a non-zero starting offset is passed when the pattern is anchored, one
1773  attempt to match at the given offset is made. This can only succeed if the  attempt to match at the given offset is made. This can only succeed if the
1774  pattern does not require the match to be at the start of the subject.  pattern does not require the match to be at the start of the subject.
# Line 1301  a fragment of a pattern that picks out a Line 1785  a fragment of a pattern that picks out a
1785  kinds of parenthesized subpattern that do not cause substrings to be captured.  kinds of parenthesized subpattern that do not cause substrings to be captured.
1786  </P>  </P>
1787  <P>  <P>
1788  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
1789  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
1790  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
1791  this argument is NOT the size of <i>ovector</i> in bytes.  argument is NOT the size of <i>ovector</i> in bytes.
1792  </P>  </P>
1793  <P>  <P>
1794  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,
1795  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
1796  used as workspace by <b>pcre_exec()</b> while matching capturing subpatterns,  used as workspace by <b>pcre_exec()</b> while matching capturing subpatterns,
1797  and is not available for passing back information. The length passed in  and is not available for passing back information. The number passed in
1798  <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
1799  rounded down.  rounded down.
1800  </P>  </P>
1801  <P>  <P>
1802  When a match is successful, information about captured substrings is returned  When a match is successful, information about captured substrings is returned
1803  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
1804  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
1805  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
1806  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
1807  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
1808  subject string matched by the entire pattern. The next pair is used for the  mode. They are not character counts.
1809  first capturing subpattern, and so on. The value returned by <b>pcre_exec()</b>  </P>
1810  is one more than the highest numbered pair that has been set. For example, if  <P>
1811  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
1812  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
1813  indicating that just the first pair of offsets has been set.  used for the first capturing subpattern, and so on. The value returned by
1814    <b>pcre_exec()</b> is one more than the highest numbered pair that has been set.
1815    For example, if two substrings have been captured, the returned value is 3. If
1816    there are no capturing subpatterns, the return value from a successful match is
1817    1, indicating that just the first pair of offsets has been set.
1818  </P>  </P>
1819  <P>  <P>
1820  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 1335  string that it matched that is returned. Line 1823  string that it matched that is returned.
1823  <P>  <P>
1824  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
1825  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
1826  returns a value of zero. In particular, if the substring offsets are not of  returns a value of zero. If neither the actual string matched not any captured
1827  interest, <b>pcre_exec()</b> may be called with <i>ovector</i> passed as NULL and  substrings are of interest, <b>pcre_exec()</b> may be called with <i>ovector</i>
1828  <i>ovecsize</i> as zero. However, if the pattern contains back references and  passed as NULL and <i>ovecsize</i> as zero. However, if the pattern contains
1829  the <i>ovector</i> is not big enough to remember the related substrings, PCRE  back references and the <i>ovector</i> is not big enough to remember the related
1830  has to get additional memory for use during matching. Thus it is usually  substrings, PCRE has to get additional memory for use during matching. Thus it
1831  advisable to supply an <i>ovector</i>.  is usually advisable to supply an <i>ovector</i> of reasonable size.
1832    </P>
1833    <P>
1834    There are some cases where zero is returned (indicating vector overflow) when
1835    in fact the vector is exactly the right size for the final match. For example,
1836    consider the pattern
1837    <pre>
1838      (a)(?:(b)c|bd)
1839    </pre>
1840    If a vector of 6 elements (allowing for only 1 captured substring) is given
1841    with subject string "abd", <b>pcre_exec()</b> will try to set the second
1842    captured string, thereby recording a vector overflow, before failing to match
1843    "c" and backing up to try the second alternative. The zero return, however,
1844    does correctly indicate that the maximum number of slots (namely 2) have been
1845    filled. In similar cases where there is temporary overflow, but the final
1846    number of used slots is actually less than the maximum, a non-zero value is
1847    returned.
1848  </P>  </P>
1849  <P>  <P>
1850  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
1851  subpatterns there are in a compiled pattern. The smallest size for  subpatterns there are in a compiled pattern. The smallest size for
1852  <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
1853  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 1361  Offset values that correspond to unused Line 1865  Offset values that correspond to unused
1865  expression are also set to -1. For example, if the string "abc" is matched  expression are also set to -1. For example, if the string "abc" is matched
1866  against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not matched. The  against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not matched. The
1867  return from the function is 2, because the highest used capturing subpattern  return from the function is 2, because the highest used capturing subpattern
1868  number is 1. However, you can refer to the offsets for the second and third  number is 1, and the offsets for for the second and third capturing subpatterns
1869  capturing subpatterns if you wish (assuming the vector is large enough, of  (assuming the vector is large enough, of course) are set to -1.
1870  course).  </P>
1871    <P>
1872    <b>Note</b>: Elements in the first two-thirds of <i>ovector</i> that do not
1873    correspond to capturing parentheses in the pattern are never changed. That is,
1874    if a pattern contains <i>n</i> capturing parentheses, no more than
1875    <i>ovector[0]</i> to <i>ovector[2n+1]</i> are set by <b>pcre_exec()</b>. The other
1876    elements (in the first two-thirds) retain whatever values they previously had.
1877  </P>  </P>
1878  <P>  <P>
1879  Some convenience functions are provided for extracting the captured substrings  Some convenience functions are provided for extracting the captured substrings
# Line 1410  If a pattern contains back references, b Line 1920  If a pattern contains back references, b
1920  gets a block of memory at the start of matching to use for this purpose. If the  gets a block of memory at the start of matching to use for this purpose. If the
1921  call via <b>pcre_malloc()</b> fails, this error is given. The memory is  call via <b>pcre_malloc()</b> fails, this error is given. The memory is
1922  automatically freed at the end of matching.  automatically freed at the end of matching.
1923    </P>
1924    <P>
1925    This error is also given if <b>pcre_stack_malloc()</b> fails in
1926    <b>pcre_exec()</b>. This can happen only when PCRE has been compiled with
1927    <b>--disable-stack-for-recursion</b>.
1928  <pre>  <pre>
1929    PCRE_ERROR_NOSUBSTRING    (-7)    PCRE_ERROR_NOSUBSTRING    (-7)
1930  </pre>  </pre>
# Line 1432  documentation for details. Line 1947  documentation for details.
1947  <pre>  <pre>
1948    PCRE_ERROR_BADUTF8        (-10)    PCRE_ERROR_BADUTF8        (-10)
1949  </pre>  </pre>
1950  A string that contains an invalid UTF-8 byte sequence was passed as a subject.  A string that contains an invalid UTF-8 byte sequence was passed as a subject,
1951    and the PCRE_NO_UTF8_CHECK option was not set. If the size of the output vector
1952    (<i>ovecsize</i>) is at least 2, the byte offset to the start of the the invalid
1953    UTF-8 character is placed in the first element, and a reason code is placed in
1954    the second element. The reason codes are listed in the
1955    <a href="#badutf8reasons">following section.</a>
1956    For backward compatibility, if PCRE_PARTIAL_HARD is set and the problem is a
1957    truncated UTF-8 character at the end of the subject (reason codes 1 to 5),
1958    PCRE_ERROR_SHORTUTF8 is returned instead of PCRE_ERROR_BADUTF8.
1959  <pre>  <pre>
1960    PCRE_ERROR_BADUTF8_OFFSET (-11)    PCRE_ERROR_BADUTF8_OFFSET (-11)
1961  </pre>  </pre>
1962  The UTF-8 byte sequence that was passed as a subject was valid, but the value  The UTF-8 byte sequence that was passed as a subject was checked and found to
1963  of <i>startoffset</i> did not point to the beginning of a UTF-8 character.  be valid (the PCRE_NO_UTF8_CHECK option was not set), but the value of
1964    <i>startoffset</i> did not point to the beginning of a UTF-8 character or the
1965    end of the subject.
1966  <pre>  <pre>
1967    PCRE_ERROR_PARTIAL        (-12)    PCRE_ERROR_PARTIAL        (-12)
1968  </pre>  </pre>
# Line 1447  documentation for details of partial mat Line 1972  documentation for details of partial mat
1972  <pre>  <pre>
1973    PCRE_ERROR_BADPARTIAL     (-13)    PCRE_ERROR_BADPARTIAL     (-13)
1974  </pre>  </pre>
1975  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
1976  are not supported for partial matching. See the  option was used with a compiled pattern containing items that were not
1977  <a href="pcrepartial.html"><b>pcrepartial</b></a>  supported for partial matching. From release 8.00 onwards, there are no
1978  documentation for details of partial matching.  restrictions on partial matching.
1979  <pre>  <pre>
1980    PCRE_ERROR_INTERNAL       (-14)    PCRE_ERROR_INTERNAL       (-14)
1981  </pre>  </pre>
# Line 1467  The internal recursion limit, as specifi Line 1992  The internal recursion limit, as specifi
1992  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
1993  description above.  description above.
1994  <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>  
1995    PCRE_ERROR_BADNEWLINE     (-23)    PCRE_ERROR_BADNEWLINE     (-23)
1996  </pre>  </pre>
1997  An invalid combination of PCRE_NEWLINE_<i>xxx</i> options was given.  An invalid combination of PCRE_NEWLINE_<i>xxx</i> options was given.
1998    <pre>
1999      PCRE_ERROR_BADOFFSET      (-24)
2000    </pre>
2001    The value of <i>startoffset</i> was negative or greater than the length of the
2002    subject, that is, the value in <i>length</i>.
2003    <pre>
2004      PCRE_ERROR_SHORTUTF8      (-25)
2005    </pre>
2006    This error is returned instead of PCRE_ERROR_BADUTF8 when the subject string
2007    ends with a truncated UTF-8 character and the PCRE_PARTIAL_HARD option is set.
2008    Information about the failure is returned as for PCRE_ERROR_BADUTF8. It is in
2009    fact sufficient to detect this case, but this special error code for
2010    PCRE_PARTIAL_HARD precedes the implementation of returned information; it is
2011    retained for backwards compatibility.
2012    <pre>
2013      PCRE_ERROR_RECURSELOOP    (-26)
2014    </pre>
2015    This error is returned when <b>pcre_exec()</b> detects a recursion loop within
2016    the pattern. Specifically, it means that either the whole pattern or a
2017    subpattern has been called recursively for the second time at the same position
2018    in the subject string. Some simple patterns that might do this are detected and
2019    faulted at compile time, but more complicated cases, in particular mutual
2020    recursions between two different subpatterns, cannot be detected until run
2021    time.
2022    <pre>
2023      PCRE_ERROR_JIT_STACKLIMIT (-27)
2024    </pre>
2025    This error is returned when a pattern that was successfully studied using the
2026    PCRE_STUDY_JIT_COMPILE option is being matched, but the memory available for
2027    the just-in-time processing stack is not large enough. See the
2028    <a href="pcrejit.html"><b>pcrejit</b></a>
2029    documentation for more details.
2030  </P>  </P>
2031  <P>  <P>
2032  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>.
2033    <a name="badutf8reasons"></a></P>
2034    <br><b>
2035    Reason codes for invalid UTF-8 strings
2036    </b><br>
2037    <P>
2038    When <b>pcre_exec()</b> returns either PCRE_ERROR_BADUTF8 or
2039    PCRE_ERROR_SHORTUTF8, and the size of the output vector (<i>ovecsize</i>) is at
2040    least 2, the offset of the start of the invalid UTF-8 character is placed in
2041    the first output vector element (<i>ovector[0]</i>) and a reason code is placed
2042    in the second element (<i>ovector[1]</i>). The reason codes are given names in
2043    the <b>pcre.h</b> header file:
2044    <pre>
2045      PCRE_UTF8_ERR1
2046      PCRE_UTF8_ERR2
2047      PCRE_UTF8_ERR3
2048      PCRE_UTF8_ERR4
2049      PCRE_UTF8_ERR5
2050    </pre>
2051    The string ends with a truncated UTF-8 character; the code specifies how many
2052    bytes are missing (1 to 5). Although RFC 3629 restricts UTF-8 characters to be
2053    no longer than 4 bytes, the encoding scheme (originally defined by RFC 2279)
2054    allows for up to 6 bytes, and this is checked first; hence the possibility of
2055    4 or 5 missing bytes.
2056    <pre>
2057      PCRE_UTF8_ERR6
2058      PCRE_UTF8_ERR7
2059      PCRE_UTF8_ERR8
2060      PCRE_UTF8_ERR9
2061      PCRE_UTF8_ERR10
2062    </pre>
2063    The two most significant bits of the 2nd, 3rd, 4th, 5th, or 6th byte of the
2064    character do not have the binary value 0b10 (that is, either the most
2065    significant bit is 0, or the next bit is 1).
2066    <pre>
2067      PCRE_UTF8_ERR11
2068      PCRE_UTF8_ERR12
2069    </pre>
2070    A character that is valid by the RFC 2279 rules is either 5 or 6 bytes long;
2071    these code points are excluded by RFC 3629.
2072    <pre>
2073      PCRE_UTF8_ERR13
2074    </pre>
2075    A 4-byte character has a value greater than 0x10fff; these code points are
2076    excluded by RFC 3629.
2077    <pre>
2078      PCRE_UTF8_ERR14
2079    </pre>
2080    A 3-byte character has a value in the range 0xd800 to 0xdfff; this range of
2081    code points are reserved by RFC 3629 for use with UTF-16, and so are excluded
2082    from UTF-8.
2083    <pre>
2084      PCRE_UTF8_ERR15
2085      PCRE_UTF8_ERR16
2086      PCRE_UTF8_ERR17
2087      PCRE_UTF8_ERR18
2088      PCRE_UTF8_ERR19
2089    </pre>
2090    A 2-, 3-, 4-, 5-, or 6-byte character is "overlong", that is, it codes for a
2091    value that can be represented by fewer bytes, which is invalid. For example,
2092    the two bytes 0xc0, 0xae give the value 0x2e, whose correct coding uses just
2093    one byte.
2094    <pre>
2095      PCRE_UTF8_ERR20
2096    </pre>
2097    The two most significant bits of the first byte of a character have the binary
2098    value 0b10 (that is, the most significant bit is 1 and the second is 0). Such a
2099    byte can only validly occur as the second or subsequent byte of a multi-byte
2100    character.
2101    <pre>
2102      PCRE_UTF8_ERR21
2103    </pre>
2104    The first byte of a character has the value 0xfe or 0xff. These values can
2105    never occur in a valid UTF-8 string.
2106  </P>  </P>
2107  <br><a name="SEC15" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a><br>  <br><a name="SEC17" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a><br>
2108  <P>  <P>
2109  <b>int pcre_copy_substring(const char *<i>subject</i>, int *<i>ovector</i>,</b>  <b>int pcre_copy_substring(const char *<i>subject</i>, int *<i>ovector</i>,</b>
2110  <b>int <i>stringcount</i>, int <i>stringnumber</i>, char *<i>buffer</i>,</b>  <b>int <i>stringcount</i>, int <i>stringnumber</i>, char *<i>buffer</i>,</b>
# Line 1577  linked via a special interface to anothe Line 2199  linked via a special interface to anothe
2199  <b>pcre_free</b> directly; it is for these cases that the functions are  <b>pcre_free</b> directly; it is for these cases that the functions are
2200  provided.  provided.
2201  </P>  </P>
2202  <br><a name="SEC16" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NAME</a><br>  <br><a name="SEC18" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NAME</a><br>
2203  <P>  <P>
2204  <b>int pcre_get_stringnumber(const pcre *<i>code</i>,</b>  <b>int pcre_get_stringnumber(const pcre *<i>code</i>,</b>
2205  <b>const char *<i>name</i>);</b>  <b>const char *<i>name</i>);</b>
# Line 1630  then call pcre_copy_substring() o Line 2252  then call pcre_copy_substring() o
2252  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,
2253  the behaviour may not be what you want (see the next section).  the behaviour may not be what you want (see the next section).
2254  </P>  </P>
2255  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>  <P>
2256    <b>Warning:</b> If the pattern uses the (?| feature to set up multiple
2257    subpatterns with the same number, as described in the
2258    <a href="pcrepattern.html#dupsubpatternnumber">section on duplicate subpattern numbers</a>
2259    in the
2260    <a href="pcrepattern.html"><b>pcrepattern</b></a>
2261    page, you cannot use names to distinguish the different subpatterns, because
2262    names are not included in the compiled code. The matching process uses only
2263    numbers. For this reason, the use of different names for subpatterns of the
2264    same number causes an error at compile time.
2265    </P>
2266    <br><a name="SEC19" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>
2267  <P>  <P>
2268  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>
2269  <b>const char *<i>name</i>, char **<i>first</i>, char **<i>last</i>);</b>  <b>const char *<i>name</i>, char **<i>first</i>, char **<i>last</i>);</b>
2270  </P>  </P>
2271  <P>  <P>
2272  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
2273  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
2274  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
2275  example is shown in the  such subpatterns are named, they are required to use the same names.)
2276    </P>
2277    <P>
2278    Normally, patterns with duplicate names are such that in any one match, only
2279    one of the named subpatterns participates. An example is shown in the
2280  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
2281  documentation. When duplicates are present, <b>pcre_copy_named_substring()</b>  documentation.
2282  and <b>pcre_get_named_substring()</b> return the first substring corresponding  </P>
2283  to the given name that is set. If none are set, an empty string is returned.  <P>
2284  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
2285  associated with the name, but it is not defined which it is.  <b>pcre_get_named_substring()</b> return the first substring corresponding to
2286  <br>  the given name that is set. If none are set, PCRE_ERROR_NOSUBSTRING (-7) is
2287  <br>  returned; no data is returned. The <b>pcre_get_stringnumber()</b> function
2288    returns one of the numbers that are associated with the name, but it is not
2289    defined which it is.
2290    </P>
2291    <P>
2292  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,
2293  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
2294  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 1655  fourth are pointers to variables which a Line 2296  fourth are pointers to variables which a
2296  has run, they point to the first and last entries in the name-to-number table  has run, they point to the first and last entries in the name-to-number table
2297  for the given name. The function itself returns the length of each entry, or  for the given name. The function itself returns the length of each entry, or
2298  PCRE_ERROR_NOSUBSTRING (-7) if there are none. The format of the table is  PCRE_ERROR_NOSUBSTRING (-7) if there are none. The format of the table is
2299  described above in the section entitled <i>Information about a pattern</i>.  described above in the section entitled <i>Information about a pattern</i>
2300    <a href="#infoaboutpattern">above.</a>
2301  Given all the relevant entries for the name, you can extract each of their  Given all the relevant entries for the name, you can extract each of their
2302  numbers, and hence the captured data, if any.  numbers, and hence the captured data, if any.
2303  </P>  </P>
2304  <br><a name="SEC18" href="#TOC1">FINDING ALL POSSIBLE MATCHES</a><br>  <br><a name="SEC20" href="#TOC1">FINDING ALL POSSIBLE MATCHES</a><br>
2305  <P>  <P>
2306  The traditional matching function uses a similar algorithm to Perl, which stops  The traditional matching function uses a similar algorithm to Perl, which stops
2307  when it finds the first match, starting at a given point in the subject. If you  when it finds the first match, starting at a given point in the subject. If you
# Line 1678  substring. Then return 1, which forces < Line 2320  substring. Then return 1, which forces <
2320  other alternatives. Ultimately, when it runs out of matches, <b>pcre_exec()</b>  other alternatives. Ultimately, when it runs out of matches, <b>pcre_exec()</b>
2321  will yield PCRE_ERROR_NOMATCH.  will yield PCRE_ERROR_NOMATCH.
2322  <a name="dfamatch"></a></P>  <a name="dfamatch"></a></P>
2323  <br><a name="SEC19" href="#TOC1">MATCHING A PATTERN: THE ALTERNATIVE FUNCTION</a><br>  <br><a name="SEC21" href="#TOC1">MATCHING A PATTERN: THE ALTERNATIVE FUNCTION</a><br>
2324  <P>  <P>
2325  <b>int pcre_dfa_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>  <b>int pcre_dfa_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b>
2326  <b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b>  <b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b>
# Line 1691  a compiled pattern, using a matching alg Line 2333  a compiled pattern, using a matching alg
2333  just once, and does not backtrack. This has different characteristics to the  just once, and does not backtrack. This has different characteristics to the
2334  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
2335  patterns are not supported. Nevertheless, there are times when this kind of  patterns are not supported. Nevertheless, there are times when this kind of
2336  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
2337  the  list of features that <b>pcre_dfa_exec()</b> does not support, see the
2338  <a href="pcrematching.html"><b>pcrematching</b></a>  <a href="pcrematching.html"><b>pcrematching</b></a>
2339  documentation.  documentation.
2340  </P>  </P>
# Line 1734  Option bits for pcre_dfa_exec() Line 2376  Option bits for pcre_dfa_exec()
2376  <P>  <P>
2377  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
2378  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>,
2379  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL,  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART,
2380  PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last three of these are  PCRE_NO_UTF8_CHECK, PCRE_BSR_ANYCRLF, PCRE_BSR_UNICODE, PCRE_NO_START_OPTIMIZE,
2381  the same as for <b>pcre_exec()</b>, so their description is not repeated here.  PCRE_PARTIAL_HARD, PCRE_PARTIAL_SOFT, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART.
2382  <pre>  All but the last four of these are exactly the same as for <b>pcre_exec()</b>,
2383    PCRE_PARTIAL  so their description is not repeated here.
2384  </pre>  <pre>
2385  This has the same general effect as it does for <b>pcre_exec()</b>, but the    PCRE_PARTIAL_HARD
2386  details are slightly different. When PCRE_PARTIAL is set for    PCRE_PARTIAL_SOFT
2387  <b>pcre_dfa_exec()</b>, the return code PCRE_ERROR_NOMATCH is converted into  </pre>
2388  PCRE_ERROR_PARTIAL if the end of the subject is reached, there have been no  These have the same general effect as they do for <b>pcre_exec()</b>, but the
2389  complete matches, but there is still at least one matching possibility. The  details are slightly different. When PCRE_PARTIAL_HARD is set for
2390  portion of the string that provided the partial match is set as the first  <b>pcre_dfa_exec()</b>, it returns PCRE_ERROR_PARTIAL if the end of the subject
2391  matching string.  is reached and there is still at least one matching possibility that requires
2392    additional characters. This happens even if some complete matches have also
2393    been found. When PCRE_PARTIAL_SOFT is set, the return code PCRE_ERROR_NOMATCH
2394    is converted into PCRE_ERROR_PARTIAL if the end of the subject is reached,
2395    there have been no complete matches, but there is still at least one matching
2396    possibility. The portion of the string that was inspected when the longest
2397    partial match was found is set as the first matching string in both cases.
2398    There is a more detailed discussion of partial and multi-segment matching, with
2399    examples, in the
2400    <a href="pcrepartial.html"><b>pcrepartial</b></a>
2401    documentation.
2402  <pre>  <pre>
2403    PCRE_DFA_SHORTEST    PCRE_DFA_SHORTEST
2404  </pre>  </pre>
# Line 1757  matching point in the subject string. Line 2409  matching point in the subject string.
2409  <pre>  <pre>
2410    PCRE_DFA_RESTART    PCRE_DFA_RESTART
2411  </pre>  </pre>
2412  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
2413  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
2414  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
2415  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
2416  <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
2417  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  
2418  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
2419  documentation.  documentation.
2420  </P>  </P>
# Line 1800  returns data, even though the meaning of Line 2451  returns data, even though the meaning of
2451  The strings are returned in reverse order of length; that is, the longest  The strings are returned in reverse order of length; that is, the longest
2452  matching string is given first. If there were too many matches to fit into  matching string is given first. If there were too many matches to fit into
2453  <i>ovector</i>, the yield of the function is zero, and the vector is filled with  <i>ovector</i>, the yield of the function is zero, and the vector is filled with
2454  the longest matches.  the longest matches. Unlike <b>pcre_exec()</b>, <b>pcre_dfa_exec()</b> can use
2455    the entire <i>ovector</i> for returning matched strings.
2456  </P>  </P>
2457  <br><b>  <br><b>
2458  Error returns from <b>pcre_dfa_exec()</b>  Error returns from <b>pcre_dfa_exec()</b>
# Line 1827  group. These are not supported. Line 2479  group. These are not supported.
2479    PCRE_ERROR_DFA_UMLIMIT    (-18)    PCRE_ERROR_DFA_UMLIMIT    (-18)
2480  </pre>  </pre>
2481  This return is given if <b>pcre_dfa_exec()</b> is called with an <i>extra</i>  This return is given if <b>pcre_dfa_exec()</b> is called with an <i>extra</i>
2482  block that contains a setting of the <i>match_limit</i> field. This is not  block that contains a setting of the <i>match_limit</i> or
2483  supported (it is meaningless).  <i>match_limit_recursion</i> fields. This is not supported (these fields are
2484    meaningless for DFA matching).
2485  <pre>  <pre>
2486    PCRE_ERROR_DFA_WSSIZE     (-19)    PCRE_ERROR_DFA_WSSIZE     (-19)
2487  </pre>  </pre>
# Line 1842  recursively, using private vectors for < Line 2495  recursively, using private vectors for <
2495  error is given if the output vector is not large enough. This should be  error is given if the output vector is not large enough. This should be
2496  extremely rare, as a vector of size 1000 is used.  extremely rare, as a vector of size 1000 is used.
2497  </P>  </P>
2498  <br><a name="SEC20" href="#TOC1">SEE ALSO</a><br>  <br><a name="SEC22" href="#TOC1">SEE ALSO</a><br>
2499  <P>  <P>
2500  <b>pcrebuild</b>(3), <b>pcrecallout</b>(3), <b>pcrecpp(3)</b>(3),  <b>pcrebuild</b>(3), <b>pcrecallout</b>(3), <b>pcrecpp(3)</b>(3),
2501  <b>pcrematching</b>(3), <b>pcrepartial</b>(3), <b>pcreposix</b>(3),  <b>pcrematching</b>(3), <b>pcrepartial</b>(3), <b>pcreposix</b>(3),
2502  <b>pcreprecompile</b>(3), <b>pcresample</b>(3), <b>pcrestack</b>(3).  <b>pcreprecompile</b>(3), <b>pcresample</b>(3), <b>pcrestack</b>(3).
2503  </P>  </P>
2504  <br><a name="SEC21" href="#TOC1">AUTHOR</a><br>  <br><a name="SEC23" href="#TOC1">AUTHOR</a><br>
2505  <P>  <P>
2506  Philip Hazel  Philip Hazel
2507  <br>  <br>
# Line 1857  University Computing Service Line 2510  University Computing Service
2510  Cambridge CB2 3QH, England.  Cambridge CB2 3QH, England.
2511  <br>  <br>
2512  </P>  </P>
2513  <br><a name="SEC22" href="#TOC1">REVISION</a><br>  <br><a name="SEC24" href="#TOC1">REVISION</a><br>
2514  <P>  <P>
2515  Last updated: 24 April 2007  Last updated: 02 December 2011
2516  <br>  <br>
2517  Copyright &copy; 1997-2007 University of Cambridge.  Copyright &copy; 1997-2011 University of Cambridge.
2518  <br>  <br>
2519  <p>  <p>
2520  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.155  
changed lines
  Added in v.784

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12