/[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 345 by ph10, Mon Apr 28 15:10:02 2008 UTC revision 545 by ph10, Wed Jun 16 10:51:15 2010 UTC
# Line 161  and PCRE_MINOR to contain the major and Line 161  and PCRE_MINOR to contain the major and
161  Applications can use these to include support for different releases of PCRE.  Applications can use these to include support for different releases of PCRE.
162  </P>  </P>
163  <P>  <P>
164    In a Windows environment, if you want to statically link an application program
165    against a non-dll <b>pcre.a</b> file, you must define PCRE_STATIC before
166    including <b>pcre.h</b> or <b>pcrecpp.h</b>, because otherwise the
167    <b>pcre_malloc()</b> and <b>pcre_free()</b> exported functions will be declared
168    <b>__declspec(dllimport)</b>, with unwanted results.
169    </P>
170    <P>
171  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>,
172  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
173  in a Perl-compatible manner. A sample program that demonstrates the simplest  in a Perl-compatible manner. A sample program that demonstrates the simplest
174  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
175  distribution. The  source distribution. A listing of this program is given in the
176    <a href="pcredemo.html"><b>pcredemo</b></a>
177    documentation, and the
178  <a href="pcresample.html"><b>pcresample</b></a>  <a href="pcresample.html"><b>pcresample</b></a>
179  documentation describes how to compile and run it.  documentation describes how to compile and run it.
180  </P>  </P>
# Line 173  documentation describes how to compile a Line 182  documentation describes how to compile a
182  A second matching function, <b>pcre_dfa_exec()</b>, which is not  A second matching function, <b>pcre_dfa_exec()</b>, which is not
183  Perl-compatible, is also provided. This uses a different algorithm for the  Perl-compatible, is also provided. This uses a different algorithm for the
184  matching. The alternative algorithm finds all possible matches (at a given  matching. The alternative algorithm finds all possible matches (at a given
185  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
186  does not return captured substrings. A description of the two matching  lookbehind assertions). However, this algorithm does not return captured
187  algorithms and their advantages and disadvantages is given in the  substrings. A description of the two matching algorithms and their advantages
188    and disadvantages is given in the
189  <a href="pcrematching.html"><b>pcrematching</b></a>  <a href="pcrematching.html"><b>pcrematching</b></a>
190  documentation.  documentation.
191  </P>  </P>
# Line 333  properties is available; otherwise it is Line 343  properties is available; otherwise it is
343  </pre>  </pre>
344  The output is an integer whose value specifies the default character sequence  The output is an integer whose value specifies the default character sequence
345  that is recognized as meaning "newline". The four values that are supported  that is recognized as meaning "newline". The four values that are supported
346  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.
347  default should normally be the standard sequence for your operating system.  Though they are derived from ASCII, the same values are returned in EBCDIC
348    environments. The default should normally correspond to the standard sequence
349    for your operating system.
350  <pre>  <pre>
351    PCRE_CONFIG_BSR    PCRE_CONFIG_BSR
352  </pre>  </pre>
# Line 361  documentation. Line 373  documentation.
373  <pre>  <pre>
374    PCRE_CONFIG_MATCH_LIMIT    PCRE_CONFIG_MATCH_LIMIT
375  </pre>  </pre>
376  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
377  internal matching function calls in a <b>pcre_exec()</b> execution. Further  internal matching function calls in a <b>pcre_exec()</b> execution. Further
378  details are given with <b>pcre_exec()</b> below.  details are given with <b>pcre_exec()</b> below.
379  <pre>  <pre>
380    PCRE_CONFIG_MATCH_LIMIT_RECURSION    PCRE_CONFIG_MATCH_LIMIT_RECURSION
381  </pre>  </pre>
382  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
383  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>
384  execution. Further details are given with <b>pcre_exec()</b> below.  execution. Further details are given with <b>pcre_exec()</b> below.
385  <pre>  <pre>
# Line 395  avoiding the use of the stack. Line 407  avoiding the use of the stack.
407  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
408  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
409  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,
410  <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
411    too much repetition, we refer just to <b>pcre_compile()</b> below, but the
412    information applies equally to <b>pcre_compile2()</b>.
413  </P>  </P>
414  <P>  <P>
415  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 414  argument, which is an address (see below Line 428  argument, which is an address (see below
428  <P>  <P>
429  The <i>options</i> argument contains various bit settings that affect the  The <i>options</i> argument contains various bit settings that affect the
430  compilation. It should be zero if no options are required. The available  compilation. It should be zero if no options are required. The available
431  options are described below. Some of them, in particular, those that are  options are described below. Some of them (in particular, those that are
432  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
433  the detailed description in the  within the pattern (see the detailed description in the
434  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
435  documentation). For these options, the contents of the <i>options</i> argument  documentation). For those options that can be different in different parts of
436  specifies their initial settings at the start of compilation and execution. The  the pattern, the contents of the <i>options</i> argument specifies their
437  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,
438  matching as well as at compile time.  PCRE_BSR_<i>xxx</i>, and PCRE_NEWLINE_<i>xxx</i> options can be set at the time
439    of matching as well as at compile time.
440  </P>  </P>
441  <P>  <P>
442  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.
443  Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns  Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns
444  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
445  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
446  not try to free it. The offset from the start of the pattern to the character  not try to free it. The byte offset from the start of the pattern to the
447  where the error was discovered is placed in the variable pointed to by  character that was being processed when the error was discovered is placed in
448  <i>erroffset</i>, which must not be NULL. If it is, an immediate error is given.  the variable pointed to by <i>erroffset</i>, which must not be NULL. If it is,
449    an immediate error is given. Some errors are not detected until checks are
450    carried out when the whole pattern has been scanned; in this case the offset is
451    set to the end of the pattern.
452  </P>  </P>
453  <P>  <P>
454  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 549  set, any backslash in a pattern that is Line 567  set, any backslash in a pattern that is
567  special meaning causes an error, thus reserving these combinations for future  special meaning causes an error, thus reserving these combinations for future
568  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
569  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
570  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
571  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)
572    option setting within a pattern.
573  <pre>  <pre>
574    PCRE_FIRSTLINE    PCRE_FIRSTLINE
575  </pre>  </pre>
# Line 637  were followed by ?: but named parenthese Line 656  were followed by ?: but named parenthese
656  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
657  in Perl.  in Perl.
658  <pre>  <pre>
659      PCRE_UCP
660    </pre>
661    This option changes the way PCRE processes \b, \d, \s, \w, and some of the
662    POSIX character classes. By default, only ASCII characters are recognized, but
663    if PCRE_UCP is set, Unicode properties are used instead to classify characters.
664    More details are given in the section on
665    <a href="pcre.html#genericchartypes">generic character types</a>
666    in the
667    <a href="pcrepattern.html"><b>pcrepattern</b></a>
668    page. If you set PCRE_UCP, matching one of the items it affects takes much
669    longer. The option is available only if PCRE has been compiled with Unicode
670    property support.
671    <pre>
672    PCRE_UNGREEDY    PCRE_UNGREEDY
673  </pre>  </pre>
674  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 737  out of use. To avoid confusion, they hav Line 769  out of use. To avoid confusion, they hav
769    57  \g is not followed by a braced, angle-bracketed, or quoted    57  \g is not followed by a braced, angle-bracketed, or quoted
770          name/number or by a plain number          name/number or by a plain number
771    58  a numbered reference must not be zero    58  a numbered reference must not be zero
772    59  (*VERB) with an argument is not supported    59  an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)
773    60  (*VERB) not recognized    60  (*VERB) not recognized
774    61  number is too big    61  number is too big
775    62  subpattern name expected    62  subpattern name expected
776    63  digit expected after (?+    63  digit expected after (?+
777    64  ] is an invalid data character in JavaScript compatibility mode    64  ] is an invalid data character in JavaScript compatibility mode
778      65  different names for subpatterns of the same number are not allowed
779      66  (*MARK) must have an argument
780      67  this version of PCRE is not compiled with PCRE_UCP support
781  </pre>  </pre>
782  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
783  be used if the limits were changed when PCRE was built.  be used if the limits were changed when PCRE was built.
# Line 763  results of the study. Line 798  results of the study.
798  </P>  </P>
799  <P>  <P>
800  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
801  <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
802  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
803  described  passed; these are described
804  <a href="#extradata">below</a>  <a href="#extradata">below</a>
805  in the section on matching a pattern.  in the section on matching a pattern.
806  </P>  </P>
807  <P>  <P>
808  If studying the pattern does not produce any additional information  If studying the pattern does not produce any useful information,
809  <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
810  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
811  own <b>pcre_extra</b> block.  <b>pcre_dfa_exec()</b>, it must set up its own <b>pcre_extra</b> block.
812  </P>  </P>
813  <P>  <P>
814  The second argument of <b>pcre_study()</b> contains option bits. At present, no  The second argument of <b>pcre_study()</b> contains option bits. At present, no
# Line 796  This is a typical call to <b>pcre_study< Line 831  This is a typical call to <b>pcre_study<
831      0,              /* no options exist */      0,              /* no options exist */
832      &error);        /* set to NULL or points to a message */      &error);        /* set to NULL or points to a message */
833  </pre>  </pre>
834  At present, studying a pattern is useful only for non-anchored patterns that do  Studying a pattern does two things: first, a lower bound for the length of
835  not have a single fixed starting character. A bitmap of possible starting  subject string that is needed to match the pattern is computed. This does not
836  bytes is created.  mean that there are any strings of that length that match, but it does
837    guarantee that no shorter strings match. The value is used by
838    <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b> to avoid wasting time by trying to
839    match strings that are shorter than the lower bound. You can find out the value
840    in a calling program via the <b>pcre_fullinfo()</b> function.
841    </P>
842    <P>
843    Studying a pattern is also useful for non-anchored patterns that do not have a
844    single fixed starting character. A bitmap of possible starting bytes is
845    created. This speeds up finding a position in the subject at which to start
846    matching.
847  <a name="localesupport"></a></P>  <a name="localesupport"></a></P>
848  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>
849  <P>  <P>
850  PCRE handles caseless matching, and determines whether characters are letters,  PCRE handles caseless matching, and determines whether characters are letters,
851  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
852  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
853  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
854  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
855  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
856  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
857  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
858    handling characters with codes greater than 128, you should either use UTF-8
859    and Unicode, or use locales, but not try to mix the two.
860  </P>  </P>
861  <P>  <P>
862  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 969  follows something of variable length. Fo Line 1016  follows something of variable length. Fo
1016  /^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
1017  is -1.  is -1.
1018  <pre>  <pre>
1019      PCRE_INFO_MINLENGTH
1020    </pre>
1021    If the pattern was studied and a minimum length for matching subject strings
1022    was computed, its value is returned. Otherwise the returned value is -1. The
1023    value is a number of characters, not bytes (this may be relevant in UTF-8
1024    mode). The fourth argument should point to an <b>int</b> variable. A
1025    non-negative value is a lower bound to the length of any matching string. There
1026    may not be any strings of that length that do actually match, but every string
1027    that does match is at least that long.
1028    <pre>
1029    PCRE_INFO_NAMECOUNT    PCRE_INFO_NAMECOUNT
1030    PCRE_INFO_NAMEENTRYSIZE    PCRE_INFO_NAMEENTRYSIZE
1031    PCRE_INFO_NAMETABLE    PCRE_INFO_NAMETABLE
# Line 990  entry; both of these return an <b>int</b Line 1047  entry; both of these return an <b>int</b
1047  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
1048  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
1049  are the number of the capturing parenthesis, most significant byte first. The  are the number of the capturing parenthesis, most significant byte first. The
1050  rest of the entry is the corresponding name, zero terminated. The names are in  rest of the entry is the corresponding name, zero terminated.
1051  alphabetical order. When PCRE_DUPNAMES is set, duplicate names are in order of  </P>
1052  their parentheses numbers. For example, consider the following pattern (assume  <P>
1053  PCRE_EXTENDED is set, so white space - including newlines - is ignored):  The names are in alphabetical order. Duplicate names may appear if (?| is used
1054    to create multiple groups with the same number, as described in the
1055    <a href="pcrepattern.html#dupsubpatternnumber">section on duplicate subpattern numbers</a>
1056    in the
1057    <a href="pcrepattern.html"><b>pcrepattern</b></a>
1058    page. Duplicate names for subpatterns with different numbers are permitted only
1059    if PCRE_DUPNAMES is set. In all cases of duplicate names, they appear in the
1060    table in the order in which they were found in the pattern. In the absence of
1061    (?| this is the order of increasing number; when (?| is used this is not
1062    necessarily the case because later subpatterns may have lower numbers.
1063    </P>
1064    <P>
1065    As a simple example of the name/number table, consider the following pattern
1066    (assume PCRE_EXTENDED is set, so white space - including newlines - is
1067    ignored):
1068  <pre>  <pre>
1069    (?&#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) )
1070  </pre>  </pre>
# Line 1012  different for each compiled pattern. Line 1083  different for each compiled pattern.
1083  <pre>  <pre>
1084    PCRE_INFO_OKPARTIAL    PCRE_INFO_OKPARTIAL
1085  </pre>  </pre>
1086  Return 1 if the pattern can be used for partial matching, otherwise 0. The  Return 1 if the pattern can be used for partial matching with
1087  fourth argument should point to an <b>int</b> variable. The  <b>pcre_exec()</b>, otherwise 0. The fourth argument should point to an
1088    <b>int</b> variable. From release 8.00, this always returns 1, because the
1089    restrictions that previously applied to partial matching have been lifted. The
1090  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
1091  documentation lists the restrictions that apply to patterns when partial  documentation gives details of partial matching.
 matching is used.  
1092  <pre>  <pre>
1093    PCRE_INFO_OPTIONS    PCRE_INFO_OPTIONS
1094  </pre>  </pre>
# Line 1052  variable. Line 1124  variable.
1124  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
1125  a <b>pcre_extra</b> block. That is, it is the value that was passed to  a <b>pcre_extra</b> block. That is, it is the value that was passed to
1126  <b>pcre_malloc()</b> when PCRE was getting memory into which to place the data  <b>pcre_malloc()</b> when PCRE was getting memory into which to place the data
1127  created by <b>pcre_study()</b>. The fourth argument should point to a  created by <b>pcre_study()</b>. If <b>pcre_extra</b> is NULL, or there is no
1128    study data, zero is returned. The fourth argument should point to a
1129  <b>size_t</b> variable.  <b>size_t</b> variable.
1130  </P>  </P>
1131  <br><a name="SEC12" href="#TOC1">OBSOLETE INFO FUNCTION</a><br>  <br><a name="SEC12" href="#TOC1">OBSOLETE INFO FUNCTION</a><br>
# Line 1112  is different. (This seems a highly unlik Line 1185  is different. (This seems a highly unlik
1185  <P>  <P>
1186  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
1187  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
1188  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
1189  <i>extra</i> argument. This function is the main matching facility of the  <i>extra</i> argument. This function is the main matching facility of the
1190  library, and it operates in a Perl-like manner. For specialist use there is  library, and it operates in a Perl-like manner. For specialist use there is
1191  also an alternative matching function, which is described  also an alternative matching function, which is described
# Line 1160  fields (not necessarily in this order): Line 1233  fields (not necessarily in this order):
1233    unsigned long int <i>match_limit_recursion</i>;    unsigned long int <i>match_limit_recursion</i>;
1234    void *<i>callout_data</i>;    void *<i>callout_data</i>;
1235    const unsigned char *<i>tables</i>;    const unsigned char *<i>tables</i>;
1236      unsigned char **<i>mark</i>;
1237  </pre>  </pre>
1238  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
1239  are set. The flag bits are:  are set. The flag bits are:
# Line 1169  are set. The flag bits are: Line 1243  are set. The flag bits are:
1243    PCRE_EXTRA_MATCH_LIMIT_RECURSION    PCRE_EXTRA_MATCH_LIMIT_RECURSION
1244    PCRE_EXTRA_CALLOUT_DATA    PCRE_EXTRA_CALLOUT_DATA
1245    PCRE_EXTRA_TABLES    PCRE_EXTRA_TABLES
1246      PCRE_EXTRA_MARK
1247  </pre>  </pre>
1248  Other flag bits should be set to zero. The <i>study_data</i> field is set in the  Other flag bits should be set to zero. The <i>study_data</i> field is set in the
1249  <b>pcre_extra</b> block that is returned by <b>pcre_study()</b>, together with  <b>pcre_extra</b> block that is returned by <b>pcre_study()</b>, together with
# Line 1179  the block by setting the other fields an Line 1254  the block by setting the other fields an
1254  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
1255  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,
1256  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
1257  classic example is the use of nested unlimited repeats.  classic example is a pattern that uses nested unlimited repeats.
1258  </P>  </P>
1259  <P>  <P>
1260  Internally, PCRE uses a function called <b>match()</b> which it calls repeatedly  Internally, PCRE uses a function called <b>match()</b> which it calls repeatedly
# Line 1218  PCRE_EXTRA_MATCH_LIMIT_RECURSION is set Line 1293  PCRE_EXTRA_MATCH_LIMIT_RECURSION is set
1293  is exceeded, <b>pcre_exec()</b> returns PCRE_ERROR_RECURSIONLIMIT.  is exceeded, <b>pcre_exec()</b> returns PCRE_ERROR_RECURSIONLIMIT.
1294  </P>  </P>
1295  <P>  <P>
1296  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,
1297  which is described in the  and is described in the
1298  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
1299  documentation.  documentation.
1300  </P>  </P>
# Line 1235  the external tables might be at a differ Line 1310  the external tables might be at a differ
1310  called. See the  called. See the
1311  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
1312  documentation for a discussion of saving compiled patterns for later use.  documentation for a discussion of saving compiled patterns for later use.
1313    </P>
1314    <P>
1315    If PCRE_EXTRA_MARK is set in the <i>flags</i> field, the <i>mark</i> field must
1316    be set to point to a <b>char *</b> variable. If the pattern contains any
1317    backtracking control verbs such as (*MARK:NAME), and the execution ends up with
1318    a name to pass back, a pointer to the name string (zero terminated) is placed
1319    in the variable pointed to by the <i>mark</i> field. The names are within the
1320    compiled pattern; if you wish to retain such a name you must copy it before
1321    freeing the memory of a compiled pattern. If there is no name to pass back, the
1322    variable pointed to by the <i>mark</i> field set to NULL. For details of the
1323    backtracking control verbs, see the section entitled
1324    <a href="pcrepattern#backtrackcontrol">"Backtracking control"</a>
1325    in the
1326    <a href="pcrepattern.html"><b>pcrepattern</b></a>
1327    documentation.
1328  <a name="execoptions"></a></P>  <a name="execoptions"></a></P>
1329  <br><b>  <br><b>
1330  Option bits for <b>pcre_exec()</b>  Option bits for <b>pcre_exec()</b>
# Line 1242  Option bits for <b>pcre_exec()</b> Line 1332  Option bits for <b>pcre_exec()</b>
1332  <P>  <P>
1333  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
1334  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>,
1335  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK and PCRE_PARTIAL.  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART,
1336    PCRE_NO_START_OPTIMIZE, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_SOFT, and
1337    PCRE_PARTIAL_HARD.
1338  <pre>  <pre>
1339    PCRE_ANCHORED    PCRE_ANCHORED
1340  </pre>  </pre>
# Line 1321  match the empty string, the entire match Line 1413  match the empty string, the entire match
1413  <pre>  <pre>
1414    a?b?    a?b?
1415  </pre>  </pre>
1416  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
1417  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
1418  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".
1419    <pre>
1420      PCRE_NOTEMPTY_ATSTART
1421    </pre>
1422    This is like PCRE_NOTEMPTY, except that an empty string match that is not at
1423    the start of the subject is permitted. If the pattern is anchored, such a match
1424    can occur only if the pattern contains \K.
1425  </P>  </P>
1426  <P>  <P>
1427  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
1428  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
1429  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
1430  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
1431  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
1432  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
1433  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
1434    the
1435    <a href="pcredemo.html"><b>pcredemo</b></a>
1436    sample program.
1437    <pre>
1438      PCRE_NO_START_OPTIMIZE
1439    </pre>
1440    There are a number of optimizations that <b>pcre_exec()</b> uses at the start of
1441    a match, in order to speed up the process. For example, if it is known that an
1442    unanchored match must start with a specific character, it searches the subject
1443    for that character, and fails immediately if it cannot find it, without
1444    actually running the main matching function. This means that a special item
1445    such as (*COMMIT) at the start of a pattern is not considered until after a
1446    suitable starting point for the match has been found. When callouts are in use,
1447    these "start-up" optimizations can cause them to be skipped if the pattern is
1448    never actually used. The PCRE_NO_START_OPTIMIZE option disables the start-up
1449    optimizations, causing performance to suffer, but ensuring that the callouts do
1450    occur, and that items such as (*COMMIT) are considered at every possible
1451    starting position in the subject string.
1452  <pre>  <pre>
1453    PCRE_NO_UTF8_CHECK    PCRE_NO_UTF8_CHECK
1454  </pre>  </pre>
# Line 1359  PCRE_NO_UTF8_CHECK is set, the effect of Line 1475  PCRE_NO_UTF8_CHECK is set, the effect of
1475  subject, or a value of <i>startoffset</i> that does not point to the start of a  subject, or a value of <i>startoffset</i> that does not point to the start of a
1476  UTF-8 character, is undefined. Your program may crash.  UTF-8 character, is undefined. Your program may crash.
1477  <pre>  <pre>
1478    PCRE_PARTIAL    PCRE_PARTIAL_HARD
1479      PCRE_PARTIAL_SOFT
1480  </pre>  </pre>
1481  This option turns on the partial matching feature. If the subject string fails  These options turn on the partial matching feature. For backwards
1482  to match the pattern, but at some point during the matching process the end of  compatibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial match
1483  the subject was reached (that is, the subject partially matches the pattern and  occurs if the end of the subject string is reached successfully, but there are
1484  the failure to match occurred only because there were not enough subject  not enough subject characters to complete the match. If this happens when
1485  characters), <b>pcre_exec()</b> returns PCRE_ERROR_PARTIAL instead of  PCRE_PARTIAL_HARD is set, <b>pcre_exec()</b> immediately returns
1486  PCRE_ERROR_NOMATCH. When PCRE_PARTIAL is used, there are restrictions on what  PCRE_ERROR_PARTIAL. Otherwise, if PCRE_PARTIAL_SOFT is set, matching continues
1487  may appear in the pattern. These are discussed in the  by testing any other alternatives. Only if they all fail is PCRE_ERROR_PARTIAL
1488    returned (instead of PCRE_ERROR_NOMATCH). The portion of the string that
1489    was inspected when the partial match was found is set as the first matching
1490    string. There is a more detailed discussion in the
1491  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
1492  documentation.  documentation.
1493  </P>  </P>
# Line 1376  The string to be matched by <b>pcre_exec Line 1496  The string to be matched by <b>pcre_exec
1496  </b><br>  </b><br>
1497  <P>  <P>
1498  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
1499  <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
1500  <i>startoffset</i>. In UTF-8 mode, the byte offset must point to the start of a  in <i>startoffset</i>. In UTF-8 mode, the byte offset must point to the start of
1501  UTF-8 character. Unlike the pattern string, the subject may contain binary zero  a UTF-8 character. Unlike the pattern string, the subject may contain binary
1502  bytes. When the starting offset is zero, the search for a match starts at the  zero bytes. When the starting offset is zero, the search for a match starts at
1503  beginning of the subject, and this is by far the most common case.  the beginning of the subject, and this is by far the most common case.
1504  </P>  </P>
1505  <P>  <P>
1506  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 1418  a fragment of a pattern that picks out a Line 1538  a fragment of a pattern that picks out a
1538  kinds of parenthesized subpattern that do not cause substrings to be captured.  kinds of parenthesized subpattern that do not cause substrings to be captured.
1539  </P>  </P>
1540  <P>  <P>
1541  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
1542  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
1543  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
1544  this argument is NOT the size of <i>ovector</i> in bytes.  argument is NOT the size of <i>ovector</i> in bytes.
1545  </P>  </P>
1546  <P>  <P>
1547  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,
1548  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
1549  used as workspace by <b>pcre_exec()</b> while matching capturing subpatterns,  used as workspace by <b>pcre_exec()</b> while matching capturing subpatterns,
1550  and is not available for passing back information. The length passed in  and is not available for passing back information. The number passed in
1551  <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
1552  rounded down.  rounded down.
1553  </P>  </P>
1554  <P>  <P>
1555  When a match is successful, information about captured substrings is returned  When a match is successful, information about captured substrings is returned
1556  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
1557  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
1558  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
1559  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
1560  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
1561  subject string matched by the entire pattern. The next pair is used for the  mode. They are not character counts.
1562  first capturing subpattern, and so on. The value returned by <b>pcre_exec()</b>  </P>
1563  is one more than the highest numbered pair that has been set. For example, if  <P>
1564  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
1565  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
1566  indicating that just the first pair of offsets has been set.  used for the first capturing subpattern, and so on. The value returned by
1567    <b>pcre_exec()</b> is one more than the highest numbered pair that has been set.
1568    For example, if two substrings have been captured, the returned value is 3. If
1569    there are no capturing subpatterns, the return value from a successful match is
1570    1, indicating that just the first pair of offsets has been set.
1571  </P>  </P>
1572  <P>  <P>
1573  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 1452  string that it matched that is returned. Line 1576  string that it matched that is returned.
1576  <P>  <P>
1577  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
1578  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
1579  returns a value of zero. In particular, if the substring offsets are not of  returns a value of zero. If the substring offsets are not of interest,
1580  interest, <b>pcre_exec()</b> may be called with <i>ovector</i> passed as NULL and  <b>pcre_exec()</b> may be called with <i>ovector</i> passed as NULL and
1581  <i>ovecsize</i> as zero. However, if the pattern contains back references and  <i>ovecsize</i> as zero. However, if the pattern contains back references and
1582  the <i>ovector</i> is not big enough to remember the related substrings, PCRE  the <i>ovector</i> is not big enough to remember the related substrings, PCRE
1583  has to get additional memory for use during matching. Thus it is usually  has to get additional memory for use during matching. Thus it is usually
1584  advisable to supply an <i>ovector</i>.  advisable to supply an <i>ovector</i>.
1585  </P>  </P>
1586  <P>  <P>
1587  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
1588  subpatterns there are in a compiled pattern. The smallest size for  subpatterns there are in a compiled pattern. The smallest size for
1589  <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
1590  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 1527  If a pattern contains back references, b Line 1651  If a pattern contains back references, b
1651  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
1652  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
1653  automatically freed at the end of matching.  automatically freed at the end of matching.
1654    </P>
1655    <P>
1656    This error is also given if <b>pcre_stack_malloc()</b> fails in
1657    <b>pcre_exec()</b>. This can happen only when PCRE has been compiled with
1658    <b>--disable-stack-for-recursion</b>.
1659  <pre>  <pre>
1660    PCRE_ERROR_NOSUBSTRING    (-7)    PCRE_ERROR_NOSUBSTRING    (-7)
1661  </pre>  </pre>
# Line 1564  documentation for details of partial mat Line 1693  documentation for details of partial mat
1693  <pre>  <pre>
1694    PCRE_ERROR_BADPARTIAL     (-13)    PCRE_ERROR_BADPARTIAL     (-13)
1695  </pre>  </pre>
1696  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
1697  are not supported for partial matching. See the  option was used with a compiled pattern containing items that were not
1698  <a href="pcrepartial.html"><b>pcrepartial</b></a>  supported for partial matching. From release 8.00 onwards, there are no
1699  documentation for details of partial matching.  restrictions on partial matching.
1700  <pre>  <pre>
1701    PCRE_ERROR_INTERNAL       (-14)    PCRE_ERROR_INTERNAL       (-14)
1702  </pre>  </pre>
# Line 1739  then call <b>pcre_copy_substring()</b> o Line 1868  then call <b>pcre_copy_substring()</b> o
1868  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,
1869  the behaviour may not be what you want (see the next section).  the behaviour may not be what you want (see the next section).
1870  </P>  </P>
1871    <P>
1872    <b>Warning:</b> If the pattern uses the (?| feature to set up multiple
1873    subpatterns with the same number, as described in the
1874    <a href="pcrepattern.html#dupsubpatternnumber">section on duplicate subpattern numbers</a>
1875    in the
1876    <a href="pcrepattern.html"><b>pcrepattern</b></a>
1877    page, you cannot use names to distinguish the different subpatterns, because
1878    names are not included in the compiled code. The matching process uses only
1879    numbers. For this reason, the use of different names for subpatterns of the
1880    same number causes an error at compile time.
1881    </P>
1882  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>
1883  <P>  <P>
1884  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>
# Line 1746  the behaviour may not be what you want ( Line 1886  the behaviour may not be what you want (
1886  </P>  </P>
1887  <P>  <P>
1888  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
1889  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
1890  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
1891  example is shown in the  such subpatterns are named, they are required to use the same names.)
1892    </P>
1893    <P>
1894    Normally, patterns with duplicate names are such that in any one match, only
1895    one of the named subpatterns participates. An example is shown in the
1896  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
1897  documentation.  documentation.
1898  </P>  </P>
# Line 1804  a compiled pattern, using a matching alg Line 1948  a compiled pattern, using a matching alg
1948  just once, and does not backtrack. This has different characteristics to the  just once, and does not backtrack. This has different characteristics to the
1949  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
1950  patterns are not supported. Nevertheless, there are times when this kind of  patterns are not supported. Nevertheless, there are times when this kind of
1951  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
1952  the  list of features that <b>pcre_dfa_exec()</b> does not support, see the
1953  <a href="pcrematching.html"><b>pcrematching</b></a>  <a href="pcrematching.html"><b>pcrematching</b></a>
1954  documentation.  documentation.
1955  </P>  </P>
# Line 1847  Option bits for <b>pcre_dfa_exec()</b> Line 1991  Option bits for <b>pcre_dfa_exec()</b>
1991  <P>  <P>
1992  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
1993  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>,
1994  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL,  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART,
1995  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,
1996  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.
1997  <pre>  All but the last four of these are exactly the same as for <b>pcre_exec()</b>,
1998    PCRE_PARTIAL  so their description is not repeated here.
1999  </pre>  <pre>
2000  This has the same general effect as it does for <b>pcre_exec()</b>, but the    PCRE_PARTIAL_HARD
2001  details are slightly different. When PCRE_PARTIAL is set for    PCRE_PARTIAL_SOFT
2002  <b>pcre_dfa_exec()</b>, the return code PCRE_ERROR_NOMATCH is converted into  </pre>
2003  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
2004  complete matches, but there is still at least one matching possibility. The  details are slightly different. When PCRE_PARTIAL_HARD is set for
2005  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
2006  matching string.  is reached and there is still at least one matching possibility that requires
2007    additional characters. This happens even if some complete matches have also
2008    been found. When PCRE_PARTIAL_SOFT is set, the return code PCRE_ERROR_NOMATCH
2009    is converted into PCRE_ERROR_PARTIAL if the end of the subject is reached,
2010    there have been no complete matches, but there is still at least one matching
2011    possibility. The portion of the string that was inspected when the longest
2012    partial match was found is set as the first matching string in both cases.
2013  <pre>  <pre>
2014    PCRE_DFA_SHORTEST    PCRE_DFA_SHORTEST
2015  </pre>  </pre>
# Line 1870  matching point in the subject string. Line 2020  matching point in the subject string.
2020  <pre>  <pre>
2021    PCRE_DFA_RESTART    PCRE_DFA_RESTART
2022  </pre>  </pre>
2023  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
2024  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
2025  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
2026  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
2027  <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
2028  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  
2029  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
2030  documentation.  documentation.
2031  </P>  </P>
# Line 1972  Cambridge CB2 3QH, England. Line 2121  Cambridge CB2 3QH, England.
2121  </P>  </P>
2122  <br><a name="SEC22" href="#TOC1">REVISION</a><br>  <br><a name="SEC22" href="#TOC1">REVISION</a><br>
2123  <P>  <P>
2124  Last updated: 12 April 2008  Last updated: 15 June 2010
2125  <br>  <br>
2126  Copyright &copy; 1997-2008 University of Cambridge.  Copyright &copy; 1997-2010 University of Cambridge.
2127  <br>  <br>
2128  <p>  <p>
2129  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.345  
changed lines
  Added in v.545

  ViewVC Help
Powered by ViewVC 1.1.5