/[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 690 by ph10, Sun Aug 28 15:23:03 2011 UTC revision 691 by ph10, Sun Sep 11 14:31:21 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 179  documentation, and the Line 197  documentation, and the
197  documentation describes how to compile and run it.  documentation describes how to compile and run it.
198  </P>  </P>
199  <P>  <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>
211    <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
# Line 254  points during a matching operation. Deta Line 284  points during a matching operation. Deta
284  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
285  documentation.  documentation.
286  <a name="newlines"></a></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 293  The choice of newline convention does no Line 323  The choice of newline convention does no
323  the \n or \r escape sequences, nor does it affect what \R matches, which is  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.  controlled in a similar way, but by separate options.
325  </P>  </P>
326  <br><a name="SEC4" href="#TOC1">MULTITHREADING</a><br>  <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 304  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 314  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 339  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
# Line 393  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 724  pattern is undefined. It may cause your Line 765  pattern is undefined. It may cause your
765  can also be passed to <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b>, to suppress  can also be passed to <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b>, to suppress
766  the UTF-8 validity checking of subject strings.  the UTF-8 validity checking of subject strings.
767  </P>  </P>
768  <br><a name="SEC8" href="#TOC1">COMPILATION ERROR CODES</a><br>  <br><a name="SEC10" href="#TOC1">COMPILATION ERROR CODES</a><br>
769  <P>  <P>
770  The following table lists the error codes than may be returned by  The following table lists the error codes than may be returned by
771  <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 808  out of use. To avoid confusion, they hav Line 849  out of use. To avoid confusion, they hav
849  The numbers 32 and 10000 in errors 48 and 49 are defaults; different values may  The numbers 32 and 10000 in errors 48 and 49 are defaults; different values may
850  be used if the limits were changed when PCRE was built.  be used if the limits were changed when PCRE was built.
851  <a name="studyingapattern"></a></P>  <a name="studyingapattern"></a></P>
852  <br><a name="SEC9" href="#TOC1">STUDYING A PATTERN</a><br>  <br><a name="SEC11" href="#TOC1">STUDYING A PATTERN</a><br>
853  <P>  <P>
854  <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>
855  <b>const char **<i>errptr</i>);</b>  <b>const char **<i>errptr</i>);</b>
# Line 837  wants to pass any of the other fields to Line 878  wants to pass any of the other fields to
878  <b>pcre_dfa_exec()</b>, it must set up its own <b>pcre_extra</b> block.  <b>pcre_dfa_exec()</b>, it must set up its own <b>pcre_extra</b> block.
879  </P>  </P>
880  <P>  <P>
881  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
882  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
883    compiler is available, the pattern is further compiled into machine code that
884    executes much faster than the <b>pcre_exec()</b> matching function. If
885    the just-in-time compiler is not available, this option is ignored. All other
886    bits in the <i>options</i> argument must be zero.
887    </P>
888    <P>
889    JIT compilation is a heavyweight optimization. It can take some time for
890    patterns to be analyzed, and for one-off matches and simple patterns the
891    benefit of faster execution might be offset by a much slower study time.
892    Not all patterns can be optimized by the JIT compiler. For those that cannot be
893    handled, matching automatically falls back to the <b>pcre_exec()</b>
894    interpreter. For more details, see the
895    <a href="pcrejit.html"><b>pcrejit</b></a>
896    documentation.
897  </P>  </P>
898  <P>  <P>
899  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 849  should test the error pointer for NULL a Line 904  should test the error pointer for NULL a
904  sure that it has run successfully.  sure that it has run successfully.
905  </P>  </P>
906  <P>  <P>
907  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
908    study data by calling <b>pcre_free_study()</b>. This function was added to the
909    API for release 8.20. For earlier versions, the memory could be freed with
910    <b>pcre_free()</b>, just like the pattern itself. This will still work in cases
911    where PCRE_STUDY_JIT_COMPILE is not used, but it is advisable to change to the
912    new function when convenient.
913    </P>
914    <P>
915    This is a typical way in which <b>pcre_study</b>() is used (except that in a
916    real application there should be tests for errors):
917  <pre>  <pre>
918    pcre_extra *pe;    int rc;
919    pe = pcre_study(    pcre *re;
920      pcre_extra *sd;
921      re = pcre_compile("pattern", 0, &error, &erroroffset, NULL);
922      sd = pcre_study(
923      re,             /* result of pcre_compile() */      re,             /* result of pcre_compile() */
924      0,              /* no options exist */      0,              /* no options */
925      &error);        /* set to NULL or points to a message */      &error);        /* set to NULL or points to a message */
926      rc = pcre_exec(   /* see below for details of pcre_exec() options */
927        re, sd, "subject", 7, 0, 0, ovector, 30);
928      ...
929      pcre_free_study(sd);
930      pcre_free(re);
931  </pre>  </pre>
932  Studying a pattern does two things: first, a lower bound for the length of  Studying a pattern does two things: first, a lower bound for the length of
933  subject string that is needed to match the pattern is computed. This does not  subject string that is needed to match the pattern is computed. This does not
# Line 872  created. This speeds up finding a positi Line 944  created. This speeds up finding a positi
944  matching.  matching.
945  </P>  </P>
946  <P>  <P>
947  The two optimizations just described can be disabled by setting the  These two optimizations apply to both <b>pcre_exec()</b> and
948  PCRE_NO_START_OPTIMIZE option when calling <b>pcre_exec()</b> or  <b>pcre_dfa_exec()</b>. However, they are not used by <b>pcre_exec()</b> if
949    <b>pcre_study()</b> is called with the PCRE_STUDY_JIT_COMPILE option, and
950    just-in-time compiling is successful. The optimizations can be disabled by
951    setting the PCRE_NO_START_OPTIMIZE option when calling <b>pcre_exec()</b> or
952  <b>pcre_dfa_exec()</b>. You might want to do this if your pattern contains  <b>pcre_dfa_exec()</b>. You might want to do this if your pattern contains
953  callouts or (*MARK), and you want to make use of these facilities in cases  callouts or (*MARK) (which cannot be handled by the JIT compiler), and you want
954  where matching fails. See the discussion of PCRE_NO_START_OPTIMIZE  to make use of these facilities in cases where matching fails. See the
955    discussion of PCRE_NO_START_OPTIMIZE
956  <a href="#execoptions">below.</a>  <a href="#execoptions">below.</a>
957  <a name="localesupport"></a></P>  <a name="localesupport"></a></P>
958  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>  <br><a name="SEC12" href="#TOC1">LOCALE SUPPORT</a><br>
959  <P>  <P>
960  PCRE handles caseless matching, and determines whether characters are letters,  PCRE handles caseless matching, and determines whether characters are letters,
961  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
# Line 940  this facility could be used to match a p Line 1016  this facility could be used to match a p
1016  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
1017  below in the section on matching a pattern.  below in the section on matching a pattern.
1018  <a name="infoaboutpattern"></a></P>  <a name="infoaboutpattern"></a></P>
1019  <br><a name="SEC11" href="#TOC1">INFORMATION ABOUT A PATTERN</a><br>  <br><a name="SEC13" href="#TOC1">INFORMATION ABOUT A PATTERN</a><br>
1020  <P>  <P>
1021  <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>
1022  <b>int <i>what</i>, void *<i>where</i>);</b>  <b>int <i>what</i>, void *<i>where</i>);</b>
# Line 971  check against passing an arbitrary memor Line 1047  check against passing an arbitrary memor
1047    size_t length;    size_t length;
1048    rc = pcre_fullinfo(    rc = pcre_fullinfo(
1049      re,               /* result of pcre_compile() */      re,               /* result of pcre_compile() */
1050      pe,               /* result of pcre_study(), or NULL */      sd,               /* result of pcre_study(), or NULL */
1051      PCRE_INFO_SIZE,   /* what is required */      PCRE_INFO_SIZE,   /* what is required */
1052      &length);         /* where to put the data */      &length);         /* where to put the data */
1053  </pre>  </pre>
# Line 1040  Return 1 if the (?J) or (?-J) option set Line 1116  Return 1 if the (?J) or (?-J) option set
1116  0. The fourth argument should point to an <b>int</b> variable. (?J) and  0. The fourth argument should point to an <b>int</b> variable. (?J) and
1117  (?-J) set and unset the local PCRE_DUPNAMES option, respectively.  (?-J) set and unset the local PCRE_DUPNAMES option, respectively.
1118  <pre>  <pre>
1119      PCRE_INFO_JIT
1120    </pre>
1121    Return 1 if the pattern was studied with the PCRE_STUDY_JIT_COMPILE option, and
1122    just-in-time compiling was successful. The fourth argument should point to an
1123    <b>int</b> variable. A return value of 0 means that JIT support is not available
1124    in this version of PCRE, or that the pattern was not studied with the
1125    PCRE_STUDY_JIT_COMPILE option, or that the JIT compiler could not handle this
1126    particular pattern. See the
1127    <a href="pcrejit.html"><b>pcrejit</b></a>
1128    documentation for details of what can and cannot be handled.
1129    <pre>
1130    PCRE_INFO_LASTLITERAL    PCRE_INFO_LASTLITERAL
1131  </pre>  </pre>
1132  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 1166  is made available via this option so tha Line 1253  is made available via this option so tha
1253  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
1254  documentation for details).  documentation for details).
1255  </P>  </P>
1256  <br><a name="SEC12" href="#TOC1">OBSOLETE INFO FUNCTION</a><br>  <br><a name="SEC14" href="#TOC1">OBSOLETE INFO FUNCTION</a><br>
1257  <P>  <P>
1258  <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>
1259  <b>*<i>firstcharptr</i>);</b>  <b>*<i>firstcharptr</i>);</b>
# Line 1190  If the pattern is not anchored and the < Line 1277  If the pattern is not anchored and the <
1277  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
1278  string (see PCRE_INFO_FIRSTBYTE above).  string (see PCRE_INFO_FIRSTBYTE above).
1279  </P>  </P>
1280  <br><a name="SEC13" href="#TOC1">REFERENCE COUNTS</a><br>  <br><a name="SEC15" href="#TOC1">REFERENCE COUNTS</a><br>
1281  <P>  <P>
1282  <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>
1283  </P>  </P>
# Line 1214  Except when it is zero, the reference co Line 1301  Except when it is zero, the reference co
1301  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
1302  is different. (This seems a highly unlikely scenario.)  is different. (This seems a highly unlikely scenario.)
1303  </P>  </P>
1304  <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>
1305  <P>  <P>
1306  <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>
1307  <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 1267  fields (not necessarily in this order): Line 1354  fields (not necessarily in this order):
1354  <pre>  <pre>
1355    unsigned long int <i>flags</i>;    unsigned long int <i>flags</i>;
1356    void *<i>study_data</i>;    void *<i>study_data</i>;
1357      void *<i>executable_jit</i>;
1358    unsigned long int <i>match_limit</i>;    unsigned long int <i>match_limit</i>;
1359    unsigned long int <i>match_limit_recursion</i>;    unsigned long int <i>match_limit_recursion</i>;
1360    void *<i>callout_data</i>;    void *<i>callout_data</i>;
# Line 1277  The flags field is a bitmap that Line 1365  The flags field is a bitmap that
1365  are set. The flag bits are:  are set. The flag bits are:
1366  <pre>  <pre>
1367    PCRE_EXTRA_STUDY_DATA    PCRE_EXTRA_STUDY_DATA
1368      PCRE_EXTRA_EXECUTABLE_JIT
1369    PCRE_EXTRA_MATCH_LIMIT    PCRE_EXTRA_MATCH_LIMIT
1370    PCRE_EXTRA_MATCH_LIMIT_RECURSION    PCRE_EXTRA_MATCH_LIMIT_RECURSION
1371    PCRE_EXTRA_CALLOUT_DATA    PCRE_EXTRA_CALLOUT_DATA
1372    PCRE_EXTRA_TABLES    PCRE_EXTRA_TABLES
1373    PCRE_EXTRA_MARK    PCRE_EXTRA_MARK
1374  </pre>  </pre>
1375  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
1376  <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
1377  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
1378  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
1379    other fields and their corresponding flag bits.
1380  </P>  </P>
1381  <P>  <P>
1382  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
# Line 1295  but which have a very large number of po Line 1385  but which have a very large number of po
1385  classic example is a pattern that uses nested unlimited repeats.  classic example is a pattern that uses nested unlimited repeats.
1386  </P>  </P>
1387  <P>  <P>
1388  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
1389  (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
1390  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
1391  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
1392  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
1393  string.  in the subject string.
1394    </P>
1395    <P>
1396    When <b>pcre_exec()</b> is called with a pattern that was successfully studied
1397    with the PCRE_STUDY_JIT_COMPILE option, the way that the matching is executed
1398    is entirely different. However, there is still the possibility of runaway
1399    matching that goes on for a very long time, and so the <i>match_limit</i> value
1400    is also used in this case (but in a different way) to limit how long the
1401    matching can continue.
1402  </P>  </P>
1403  <P>  <P>
1404  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 1318  total number of calls, because not all c Line 1416  total number of calls, because not all c
1416  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>.
1417  </P>  </P>
1418  <P>  <P>
1419  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
1420  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
1421  amount of heap memory that can be used.  stack, the amount of heap memory that can be used. This limit is not relevant,
1422    and is ignored, if the pattern was successfully studied with
1423    PCRE_STUDY_JIT_COMPILE.
1424  </P>  </P>
1425  <P>  <P>
1426  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 1373  zero. The only bits that may be set are Line 1473  zero. The only bits that may be set are
1473  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART,  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART,
1474  PCRE_NO_START_OPTIMIZE, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_SOFT, and  PCRE_NO_START_OPTIMIZE, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_SOFT, and
1475  PCRE_PARTIAL_HARD.  PCRE_PARTIAL_HARD.
1476    </P>
1477    <P>
1478    If the pattern was successfully studied with the PCRE_STUDY_JIT_COMPILE option,
1479    the only supported options for JIT execution are PCRE_NO_UTF8_CHECK,
1480    PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, and PCRE_NOTEMPTY_ATSTART. Note in
1481    particular that partial matching is not supported. If an unsupported option is
1482    used, JIT execution is disabled and the normal interpretive code in
1483    <b>pcre_exec()</b> is run.
1484  <pre>  <pre>
1485    PCRE_ANCHORED    PCRE_ANCHORED
1486  </pre>  </pre>
# Line 1684  string that it matched that is returned. Line 1792  string that it matched that is returned.
1792  <P>  <P>
1793  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
1794  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
1795  returns a value of zero. If the substring offsets are not of interest,  returns a value of zero. If neither the actual string matched not any captured
1796  <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>
1797  <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
1798  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
1799  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
1800  advisable to supply an <i>ovector</i>.  is usually advisable to supply an <i>ovector</i> of reasonable size.
1801    </P>
1802    <P>
1803    There are some cases where zero is returned (indicating vector overflow) when
1804    in fact the vector is exactly the right size for the final match. For example,
1805    consider the pattern
1806    <pre>
1807      (a)(?:(b)c|bd)
1808    </pre>
1809    If a vector of 6 elements (allowing for only 1 captured substring) is given
1810    with subject string "abd", <b>pcre_exec()</b> will try to set the second
1811    captured string, thereby recording a vector overflow, before failing to match
1812    "c" and backing up to try the second alternative. The zero return, however,
1813    does correctly indicate that the maximum number of slots (namely 2) have been
1814    filled. In similar cases where there is temporary overflow, but the final
1815    number of used slots is actually less than the maximum, a non-zero value is
1816    returned.
1817  </P>  </P>
1818  <P>  <P>
1819  The <b>pcre_fullinfo()</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
# Line 1714  number is 1, and the offsets for for the Line 1838  number is 1, and the offsets for for the
1838  (assuming the vector is large enough, of course) are set to -1.  (assuming the vector is large enough, of course) are set to -1.
1839  </P>  </P>
1840  <P>  <P>
1841  <b>Note</b>: Elements of <i>ovector</i> that do not correspond to capturing  <b>Note</b>: Elements in the first two-thirds of <i>ovector</i> that do not
1842  parentheses in the pattern are never changed. That is, if a pattern contains  correspond to capturing parentheses in the pattern are never changed. That is,
1843  <i>n</i> capturing parentheses, no more than <i>ovector[0]</i> to  if a pattern contains <i>n</i> capturing parentheses, no more than
1844  <i>ovector[2n+1]</i> are set by <b>pcre_exec()</b>. The other elements retain  <i>ovector[0]</i> to <i>ovector[2n+1]</i> are set by <b>pcre_exec()</b>. The other
1845  whatever values they previously had.  elements (in the first two-thirds) retain whatever values they previously had.
1846  </P>  </P>
1847  <P>  <P>
1848  Some convenience functions are provided for extracting the captured substrings  Some convenience functions are provided for extracting the captured substrings
# Line 1864  in the subject string. Some simple patte Line 1988  in the subject string. Some simple patte
1988  faulted at compile time, but more complicated cases, in particular mutual  faulted at compile time, but more complicated cases, in particular mutual
1989  recursions between two different subpatterns, cannot be detected until run  recursions between two different subpatterns, cannot be detected until run
1990  time.  time.
1991    <pre>
1992      PCRE_ERROR_JIT_STACKLIMIT (-27)
1993    </pre>
1994    This error is returned when a pattern that was successfully studied using the
1995    PCRE_STUDY_JIT_COMPILE option is being matched, but the memory available for
1996    the just-in-time processing stack is not large enough. See the
1997    <a href="pcrejit.html"><b>pcrejit</b></a>
1998    documentation for more details.
1999  </P>  </P>
2000  <P>  <P>
2001  Error numbers -16 to -20 and -22 are not used by <b>pcre_exec()</b>.  Error numbers -16 to -20 and -22 are not used by <b>pcre_exec()</b>.
# Line 1941  character. Line 2073  character.
2073  The first byte of a character has the value 0xfe or 0xff. These values can  The first byte of a character has the value 0xfe or 0xff. These values can
2074  never occur in a valid UTF-8 string.  never occur in a valid UTF-8 string.
2075  </P>  </P>
2076  <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>
2077  <P>  <P>
2078  <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>
2079  <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 2036  linked via a special interface to anothe Line 2168  linked via a special interface to anothe
2168  <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
2169  provided.  provided.
2170  </P>  </P>
2171  <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>
2172  <P>  <P>
2173  <b>int pcre_get_stringnumber(const pcre *<i>code</i>,</b>  <b>int pcre_get_stringnumber(const pcre *<i>code</i>,</b>
2174  <b>const char *<i>name</i>);</b>  <b>const char *<i>name</i>);</b>
# Line 2100  names are not included in the compiled c Line 2232  names are not included in the compiled c
2232  numbers. For this reason, the use of different names for subpatterns of the  numbers. For this reason, the use of different names for subpatterns of the
2233  same number causes an error at compile time.  same number causes an error at compile time.
2234  </P>  </P>
2235  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>  <br><a name="SEC19" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>
2236  <P>  <P>
2237  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>
2238  <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>
# Line 2138  described above in the section entitled Line 2270  described above in the section entitled
2270  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
2271  numbers, and hence the captured data, if any.  numbers, and hence the captured data, if any.
2272  </P>  </P>
2273  <br><a name="SEC18" href="#TOC1">FINDING ALL POSSIBLE MATCHES</a><br>  <br><a name="SEC20" href="#TOC1">FINDING ALL POSSIBLE MATCHES</a><br>
2274  <P>  <P>
2275  The traditional matching function uses a similar algorithm to Perl, which stops  The traditional matching function uses a similar algorithm to Perl, which stops
2276  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 2157  substring. Then return 1, which forces < Line 2289  substring. Then return 1, which forces <
2289  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>
2290  will yield PCRE_ERROR_NOMATCH.  will yield PCRE_ERROR_NOMATCH.
2291  <a name="dfamatch"></a></P>  <a name="dfamatch"></a></P>
2292  <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>
2293  <P>  <P>
2294  <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>
2295  <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 2288  returns data, even though the meaning of Line 2420  returns data, even though the meaning of
2420  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
2421  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
2422  <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
2423  the longest matches.  the longest matches. Unlike <b>pcre_exec()</b>, <b>pcre_dfa_exec()</b> can use
2424    the entire <i>ovector</i> for returning matched strings.
2425  </P>  </P>
2426  <br><b>  <br><b>
2427  Error returns from <b>pcre_dfa_exec()</b>  Error returns from <b>pcre_dfa_exec()</b>
# Line 2315  group. These are not supported. Line 2448  group. These are not supported.
2448    PCRE_ERROR_DFA_UMLIMIT    (-18)    PCRE_ERROR_DFA_UMLIMIT    (-18)
2449  </pre>  </pre>
2450  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>
2451  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
2452  supported (it is meaningless).  <i>match_limit_recursion</i> fields. This is not supported (these fields are
2453    meaningless for DFA matching).
2454  <pre>  <pre>
2455    PCRE_ERROR_DFA_WSSIZE     (-19)    PCRE_ERROR_DFA_WSSIZE     (-19)
2456  </pre>  </pre>
# Line 2330  recursively, using private vectors for < Line 2464  recursively, using private vectors for <
2464  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
2465  extremely rare, as a vector of size 1000 is used.  extremely rare, as a vector of size 1000 is used.
2466  </P>  </P>
2467  <br><a name="SEC20" href="#TOC1">SEE ALSO</a><br>  <br><a name="SEC22" href="#TOC1">SEE ALSO</a><br>
2468  <P>  <P>
2469  <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),
2470  <b>pcrematching</b>(3), <b>pcrepartial</b>(3), <b>pcreposix</b>(3),  <b>pcrematching</b>(3), <b>pcrepartial</b>(3), <b>pcreposix</b>(3),
2471  <b>pcreprecompile</b>(3), <b>pcresample</b>(3), <b>pcrestack</b>(3).  <b>pcreprecompile</b>(3), <b>pcresample</b>(3), <b>pcrestack</b>(3).
2472  </P>  </P>
2473  <br><a name="SEC21" href="#TOC1">AUTHOR</a><br>  <br><a name="SEC23" href="#TOC1">AUTHOR</a><br>
2474  <P>  <P>
2475  Philip Hazel  Philip Hazel
2476  <br>  <br>
# Line 2345  University Computing Service Line 2479  University Computing Service
2479  Cambridge CB2 3QH, England.  Cambridge CB2 3QH, England.
2480  <br>  <br>
2481  </P>  </P>
2482  <br><a name="SEC22" href="#TOC1">REVISION</a><br>  <br><a name="SEC24" href="#TOC1">REVISION</a><br>
2483  <P>  <P>
2484  Last updated: 13 August 2011  Last updated: 06 September 2011
2485  <br>  <br>
2486  Copyright &copy; 1997-2011 University of Cambridge.  Copyright &copy; 1997-2011 University of Cambridge.
2487  <br>  <br>

Legend:
Removed from v.690  
changed lines
  Added in v.691

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12