/[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 518 by ph10, Tue May 18 15:47:01 2010 UTC
# Line 164  Applications can use these to include su Line 164  Applications can use these to include su
164  The functions <b>pcre_compile()</b>, <b>pcre_compile2()</b>, <b>pcre_study()</b>,  The functions <b>pcre_compile()</b>, <b>pcre_compile2()</b>, <b>pcre_study()</b>,
165  and <b>pcre_exec()</b> are used for compiling and matching regular expressions  and <b>pcre_exec()</b> are used for compiling and matching regular expressions
166  in a Perl-compatible manner. A sample program that demonstrates the simplest  in a Perl-compatible manner. A sample program that demonstrates the simplest
167  way of using them is provided in the file called <i>pcredemo.c</i> in the source  way of using them is provided in the file called <i>pcredemo.c</i> in the PCRE
168  distribution. The  source distribution. A listing of this program is given in the
169    <a href="pcredemo.html"><b>pcredemo</b></a>
170    documentation, and the
171  <a href="pcresample.html"><b>pcresample</b></a>  <a href="pcresample.html"><b>pcresample</b></a>
172  documentation describes how to compile and run it.  documentation describes how to compile and run it.
173  </P>  </P>
# Line 173  documentation describes how to compile a Line 175  documentation describes how to compile a
175  A second matching function, <b>pcre_dfa_exec()</b>, which is not  A second matching function, <b>pcre_dfa_exec()</b>, which is not
176  Perl-compatible, is also provided. This uses a different algorithm for the  Perl-compatible, is also provided. This uses a different algorithm for the
177  matching. The alternative algorithm finds all possible matches (at a given  matching. The alternative algorithm finds all possible matches (at a given
178  point in the subject), and scans the subject just once. However, this algorithm  point in the subject), and scans the subject just once (unless there are
179  does not return captured substrings. A description of the two matching  lookbehind assertions). However, this algorithm does not return captured
180  algorithms and their advantages and disadvantages is given in the  substrings. A description of the two matching algorithms and their advantages
181    and disadvantages is given in the
182  <a href="pcrematching.html"><b>pcrematching</b></a>  <a href="pcrematching.html"><b>pcrematching</b></a>
183  documentation.  documentation.
184  </P>  </P>
# Line 333  properties is available; otherwise it is Line 336  properties is available; otherwise it is
336  </pre>  </pre>
337  The output is an integer whose value specifies the default character sequence  The output is an integer whose value specifies the default character sequence
338  that is recognized as meaning "newline". The four values that are supported  that is recognized as meaning "newline". The four values that are supported
339  are: 10 for LF, 13 for CR, 3338 for CRLF, -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.
340  default should normally be the standard sequence for your operating system.  Though they are derived from ASCII, the same values are returned in EBCDIC
341    environments. The default should normally correspond to the standard sequence
342    for your operating system.
343  <pre>  <pre>
344    PCRE_CONFIG_BSR    PCRE_CONFIG_BSR
345  </pre>  </pre>
# Line 361  documentation. Line 366  documentation.
366  <pre>  <pre>
367    PCRE_CONFIG_MATCH_LIMIT    PCRE_CONFIG_MATCH_LIMIT
368  </pre>  </pre>
369  The output is an integer that gives the default limit for the number of  The output is a long integer that gives the default limit for the number of
370  internal matching function calls in a <b>pcre_exec()</b> execution. Further  internal matching function calls in a <b>pcre_exec()</b> execution. Further
371  details are given with <b>pcre_exec()</b> below.  details are given with <b>pcre_exec()</b> below.
372  <pre>  <pre>
373    PCRE_CONFIG_MATCH_LIMIT_RECURSION    PCRE_CONFIG_MATCH_LIMIT_RECURSION
374  </pre>  </pre>
375  The output is an integer that gives the default limit for the depth of  The output is a long integer that gives the default limit for the depth of
376  recursion when calling the internal matching function in a <b>pcre_exec()</b>  recursion when calling the internal matching function in a <b>pcre_exec()</b>
377  execution. Further details are given with <b>pcre_exec()</b> below.  execution. Further details are given with <b>pcre_exec()</b> below.
378  <pre>  <pre>
# Line 395  avoiding the use of the stack. Line 400  avoiding the use of the stack.
400  Either of the functions <b>pcre_compile()</b> or <b>pcre_compile2()</b> can be  Either of the functions <b>pcre_compile()</b> or <b>pcre_compile2()</b> can be
401  called to compile a pattern into an internal form. The only difference between  called to compile a pattern into an internal form. The only difference between
402  the two interfaces is that <b>pcre_compile2()</b> has an additional argument,  the two interfaces is that <b>pcre_compile2()</b> has an additional argument,
403  <i>errorcodeptr</i>, via which a numerical error code can be returned.  <i>errorcodeptr</i>, via which a numerical error code can be returned. To avoid
404    too much repetition, we refer just to <b>pcre_compile()</b> below, but the
405    information applies equally to <b>pcre_compile2()</b>.
406  </P>  </P>
407  <P>  <P>
408  The pattern is a C string terminated by a binary zero, and is passed in the  The pattern is a C string terminated by a binary zero, and is passed in the
# Line 414  argument, which is an address (see below Line 421  argument, which is an address (see below
421  <P>  <P>
422  The <i>options</i> argument contains various bit settings that affect the  The <i>options</i> argument contains various bit settings that affect the
423  compilation. It should be zero if no options are required. The available  compilation. It should be zero if no options are required. The available
424  options are described below. Some of them, in particular, those that are  options are described below. Some of them (in particular, those that are
425  compatible with Perl, can also be set and unset from within the pattern (see  compatible with Perl, but some others as well) can also be set and unset from
426  the detailed description in the  within the pattern (see the detailed description in the
427  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
428  documentation). For these options, the contents of the <i>options</i> argument  documentation). For those options that can be different in different parts of
429  specifies their initial settings at the start of compilation and execution. The  the pattern, the contents of the <i>options</i> argument specifies their
430  PCRE_ANCHORED and PCRE_NEWLINE_<i>xxx</i> options can be set at the time of  settings at the start of compilation and execution. The PCRE_ANCHORED,
431  matching as well as at compile time.  PCRE_BSR_<i>xxx</i>, and PCRE_NEWLINE_<i>xxx</i> options can be set at the time
432    of matching as well as at compile time.
433  </P>  </P>
434  <P>  <P>
435  If <i>errptr</i> is NULL, <b>pcre_compile()</b> returns NULL immediately.  If <i>errptr</i> is NULL, <b>pcre_compile()</b> returns NULL immediately.
436  Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns  Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns
437  NULL, and sets the variable pointed to by <i>errptr</i> to point to a textual  NULL, and sets the variable pointed to by <i>errptr</i> to point to a textual
438  error message. This is a static string that is part of the library. You must  error message. This is a static string that is part of the library. You must
439  not try to free it. The offset from the start of the pattern to the character  not try to free it. The byte offset from the start of the pattern to the
440  where the error was discovered is placed in the variable pointed to by  character that was being processed when the error was discovered is placed in
441  <i>erroffset</i>, which must not be NULL. If it is, an immediate error is given.  the variable pointed to by <i>erroffset</i>, which must not be NULL. If it is,
442    an immediate error is given. Some errors are not detected until checks are
443    carried out when the whole pattern has been scanned; in this case the offset is
444    set to the end of the pattern.
445  </P>  </P>
446  <P>  <P>
447  If <b>pcre_compile2()</b> is used instead of <b>pcre_compile()</b>, and the  If <b>pcre_compile2()</b> is used instead of <b>pcre_compile()</b>, and the
# Line 549  set, any backslash in a pattern that is Line 560  set, any backslash in a pattern that is
560  special meaning causes an error, thus reserving these combinations for future  special meaning causes an error, thus reserving these combinations for future
561  expansion. By default, as in Perl, a backslash followed by a letter with no  expansion. By default, as in Perl, a backslash followed by a letter with no
562  special meaning is treated as a literal. (Perl can, however, be persuaded to  special meaning is treated as a literal. (Perl can, however, be persuaded to
563  give a warning for this.) There are at present no other features controlled by  give an error for this, by running it with the -w option.) There are at present
564  this option. It can also be set by a (?X) option setting within a pattern.  no other features controlled by this option. It can also be set by a (?X)
565    option setting within a pattern.
566  <pre>  <pre>
567    PCRE_FIRSTLINE    PCRE_FIRSTLINE
568  </pre>  </pre>
# Line 737  out of use. To avoid confusion, they hav Line 749  out of use. To avoid confusion, they hav
749    57  \g is not followed by a braced, angle-bracketed, or quoted    57  \g is not followed by a braced, angle-bracketed, or quoted
750          name/number or by a plain number          name/number or by a plain number
751    58  a numbered reference must not be zero    58  a numbered reference must not be zero
752    59  (*VERB) with an argument is not supported    59  an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)
753    60  (*VERB) not recognized    60  (*VERB) not recognized
754    61  number is too big    61  number is too big
755    62  subpattern name expected    62  subpattern name expected
756    63  digit expected after (?+    63  digit expected after (?+
757    64  ] is an invalid data character in JavaScript compatibility mode    64  ] is an invalid data character in JavaScript compatibility mode
758      65  different names for subpatterns of the same number are not allowed
759      66  (*MARK) must have an argument
760  </pre>  </pre>
761  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
762  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 777  results of the study.
777  </P>  </P>
778  <P>  <P>
779  The returned value from <b>pcre_study()</b> can be passed directly to  The returned value from <b>pcre_study()</b> can be passed directly to
780  <b>pcre_exec()</b>. However, a <b>pcre_extra</b> block also contains other  <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>. However, a <b>pcre_extra</b> block
781  fields that can be set by the caller before the block is passed; these are  also contains other fields that can be set by the caller before the block is
782  described  passed; these are described
783  <a href="#extradata">below</a>  <a href="#extradata">below</a>
784  in the section on matching a pattern.  in the section on matching a pattern.
785  </P>  </P>
786  <P>  <P>
787  If studying the pattern does not produce any additional information  If studying the pattern does not produce any useful information,
788  <b>pcre_study()</b> returns NULL. In that circumstance, if the calling program  <b>pcre_study()</b> returns NULL. In that circumstance, if the calling program
789  wants to pass any of the other fields to <b>pcre_exec()</b>, it must set up its  wants to pass any of the other fields to <b>pcre_exec()</b> or
790  own <b>pcre_extra</b> block.  <b>pcre_dfa_exec()</b>, it must set up its own <b>pcre_extra</b> block.
791  </P>  </P>
792  <P>  <P>
793  The second argument of <b>pcre_study()</b> contains option bits. At present, no  The second argument of <b>pcre_study()</b> contains option bits. At present, no
# Line 796  This is a typical call to <b>pcre_study< Line 810  This is a typical call to <b>pcre_study<
810      0,              /* no options exist */      0,              /* no options exist */
811      &error);        /* set to NULL or points to a message */      &error);        /* set to NULL or points to a message */
812  </pre>  </pre>
813  At present, studying a pattern is useful only for non-anchored patterns that do  Studying a pattern does two things: first, a lower bound for the length of
814  not have a single fixed starting character. A bitmap of possible starting  subject string that is needed to match the pattern is computed. This does not
815  bytes is created.  mean that there are any strings of that length that match, but it does
816    guarantee that no shorter strings match. The value is used by
817    <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b> to avoid wasting time by trying to
818    match strings that are shorter than the lower bound. You can find out the value
819    in a calling program via the <b>pcre_fullinfo()</b> function.
820    </P>
821    <P>
822    Studying a pattern is also useful for non-anchored patterns that do not have a
823    single fixed starting character. A bitmap of possible starting bytes is
824    created. This speeds up finding a position in the subject at which to start
825    matching.
826  <a name="localesupport"></a></P>  <a name="localesupport"></a></P>
827  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>
828  <P>  <P>
# Line 969  follows something of variable length. Fo Line 993  follows something of variable length. Fo
993  /^a\d+z\d+/ the returned value is "z", but for /^a\dz\d/ the returned value  /^a\d+z\d+/ the returned value is "z", but for /^a\dz\d/ the returned value
994  is -1.  is -1.
995  <pre>  <pre>
996      PCRE_INFO_MINLENGTH
997    </pre>
998    If the pattern was studied and a minimum length for matching subject strings
999    was computed, its value is returned. Otherwise the returned value is -1. The
1000    value is a number of characters, not bytes (this may be relevant in UTF-8
1001    mode). The fourth argument should point to an <b>int</b> variable. A
1002    non-negative value is a lower bound to the length of any matching string. There
1003    may not be any strings of that length that do actually match, but every string
1004    that does match is at least that long.
1005    <pre>
1006    PCRE_INFO_NAMECOUNT    PCRE_INFO_NAMECOUNT
1007    PCRE_INFO_NAMEENTRYSIZE    PCRE_INFO_NAMEENTRYSIZE
1008    PCRE_INFO_NAMETABLE    PCRE_INFO_NAMETABLE
# Line 990  entry; both of these return an <b>int</b Line 1024  entry; both of these return an <b>int</b
1024  length of the longest name. PCRE_INFO_NAMETABLE returns a pointer to the first  length of the longest name. PCRE_INFO_NAMETABLE returns a pointer to the first
1025  entry of the table (a pointer to <b>char</b>). The first two bytes of each entry  entry of the table (a pointer to <b>char</b>). The first two bytes of each entry
1026  are the number of the capturing parenthesis, most significant byte first. The  are the number of the capturing parenthesis, most significant byte first. The
1027  rest of the entry is the corresponding name, zero terminated. The names are in  rest of the entry is the corresponding name, zero terminated.
1028  alphabetical order. When PCRE_DUPNAMES is set, duplicate names are in order of  </P>
1029  their parentheses numbers. For example, consider the following pattern (assume  <P>
1030  PCRE_EXTENDED is set, so white space - including newlines - is ignored):  The names are in alphabetical order. Duplicate names may appear if (?| is used
1031    to create multiple groups with the same number, as described in the
1032    <a href="pcrepattern.html#dupsubpatternnumber">section on duplicate subpattern numbers</a>
1033    in the
1034    <a href="pcrepattern.html"><b>pcrepattern</b></a>
1035    page. Duplicate names for subpatterns with different numbers are permitted only
1036    if PCRE_DUPNAMES is set. In all cases of duplicate names, they appear in the
1037    table in the order in which they were found in the pattern. In the absence of
1038    (?| this is the order of increasing number; when (?| is used this is not
1039    necessarily the case because later subpatterns may have lower numbers.
1040    </P>
1041    <P>
1042    As a simple example of the name/number table, consider the following pattern
1043    (assume PCRE_EXTENDED is set, so white space - including newlines - is
1044    ignored):
1045  <pre>  <pre>
1046    (?&#60;date&#62; (?&#60;year&#62;(\d\d)?\d\d) - (?&#60;month&#62;\d\d) - (?&#60;day&#62;\d\d) )    (?&#60;date&#62; (?&#60;year&#62;(\d\d)?\d\d) - (?&#60;month&#62;\d\d) - (?&#60;day&#62;\d\d) )
1047  </pre>  </pre>
# Line 1012  different for each compiled pattern. Line 1060  different for each compiled pattern.
1060  <pre>  <pre>
1061    PCRE_INFO_OKPARTIAL    PCRE_INFO_OKPARTIAL
1062  </pre>  </pre>
1063  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
1064  fourth argument should point to an <b>int</b> variable. The  <b>pcre_exec()</b>, otherwise 0. The fourth argument should point to an
1065    <b>int</b> variable. From release 8.00, this always returns 1, because the
1066    restrictions that previously applied to partial matching have been lifted. The
1067  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
1068  documentation lists the restrictions that apply to patterns when partial  documentation gives details of partial matching.
 matching is used.  
1069  <pre>  <pre>
1070    PCRE_INFO_OPTIONS    PCRE_INFO_OPTIONS
1071  </pre>  </pre>
# Line 1052  variable. Line 1101  variable.
1101  Return the size of the data block pointed to by the <i>study_data</i> field in  Return the size of the data block pointed to by the <i>study_data</i> field in
1102  a <b>pcre_extra</b> block. That is, it is the value that was passed to  a <b>pcre_extra</b> block. That is, it is the value that was passed to
1103  <b>pcre_malloc()</b> when PCRE was getting memory into which to place the data  <b>pcre_malloc()</b> when PCRE was getting memory into which to place the data
1104  created by <b>pcre_study()</b>. The fourth argument should point to a  created by <b>pcre_study()</b>. If <b>pcre_extra</b> is NULL, or there is no
1105    study data, zero is returned. The fourth argument should point to a
1106  <b>size_t</b> variable.  <b>size_t</b> variable.
1107  </P>  </P>
1108  <br><a name="SEC12" href="#TOC1">OBSOLETE INFO FUNCTION</a><br>  <br><a name="SEC12" href="#TOC1">OBSOLETE INFO FUNCTION</a><br>
# Line 1112  is different. (This seems a highly unlik Line 1162  is different. (This seems a highly unlik
1162  <P>  <P>
1163  The function <b>pcre_exec()</b> is called to match a subject string against a  The function <b>pcre_exec()</b> is called to match a subject string against a
1164  compiled pattern, which is passed in the <i>code</i> argument. If the  compiled pattern, which is passed in the <i>code</i> argument. If the
1165  pattern has been studied, the result of the study should be passed in the  pattern was studied, the result of the study should be passed in the
1166  <i>extra</i> argument. This function is the main matching facility of the  <i>extra</i> argument. This function is the main matching facility of the
1167  library, and it operates in a Perl-like manner. For specialist use there is  library, and it operates in a Perl-like manner. For specialist use there is
1168  also an alternative matching function, which is described  also an alternative matching function, which is described
# Line 1160  fields (not necessarily in this order): Line 1210  fields (not necessarily in this order):
1210    unsigned long int <i>match_limit_recursion</i>;    unsigned long int <i>match_limit_recursion</i>;
1211    void *<i>callout_data</i>;    void *<i>callout_data</i>;
1212    const unsigned char *<i>tables</i>;    const unsigned char *<i>tables</i>;
1213      unsigned char **<i>mark</i>;
1214  </pre>  </pre>
1215  The <i>flags</i> field is a bitmap that specifies which of the other fields  The <i>flags</i> field is a bitmap that specifies which of the other fields
1216  are set. The flag bits are:  are set. The flag bits are:
# Line 1169  are set. The flag bits are: Line 1220  are set. The flag bits are:
1220    PCRE_EXTRA_MATCH_LIMIT_RECURSION    PCRE_EXTRA_MATCH_LIMIT_RECURSION
1221    PCRE_EXTRA_CALLOUT_DATA    PCRE_EXTRA_CALLOUT_DATA
1222    PCRE_EXTRA_TABLES    PCRE_EXTRA_TABLES
1223      PCRE_EXTRA_MARK
1224  </pre>  </pre>
1225  Other flag bits should be set to zero. The <i>study_data</i> field is set in the  Other flag bits should be set to zero. The <i>study_data</i> field is set in the
1226  <b>pcre_extra</b> block that is returned by <b>pcre_study()</b>, together with  <b>pcre_extra</b> block that is returned by <b>pcre_study()</b>, together with
# Line 1179  the block by setting the other fields an Line 1231  the block by setting the other fields an
1231  The <i>match_limit</i> field provides a means of preventing PCRE from using up a  The <i>match_limit</i> field provides a means of preventing PCRE from using up a
1232  vast amount of resources when running patterns that are not going to match,  vast amount of resources when running patterns that are not going to match,
1233  but which have a very large number of possibilities in their search trees. The  but which have a very large number of possibilities in their search trees. The
1234  classic example is the use of nested unlimited repeats.  classic example is a pattern that uses nested unlimited repeats.
1235  </P>  </P>
1236  <P>  <P>
1237  Internally, PCRE uses a function called <b>match()</b> which it calls repeatedly  Internally, PCRE uses a function called <b>match()</b> which it calls repeatedly
# Line 1218  PCRE_EXTRA_MATCH_LIMIT_RECURSION is set Line 1270  PCRE_EXTRA_MATCH_LIMIT_RECURSION is set
1270  is exceeded, <b>pcre_exec()</b> returns PCRE_ERROR_RECURSIONLIMIT.  is exceeded, <b>pcre_exec()</b> returns PCRE_ERROR_RECURSIONLIMIT.
1271  </P>  </P>
1272  <P>  <P>
1273  The <i>pcre_callout</i> field is used in conjunction with the "callout" feature,  The <i>callout_data</i> field is used in conjunction with the "callout" feature,
1274  which is described in the  and is described in the
1275  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
1276  documentation.  documentation.
1277  </P>  </P>
# Line 1235  the external tables might be at a differ Line 1287  the external tables might be at a differ
1287  called. See the  called. See the
1288  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
1289  documentation for a discussion of saving compiled patterns for later use.  documentation for a discussion of saving compiled patterns for later use.
1290    </P>
1291    <P>
1292    If PCRE_EXTRA_MARK is set in the <i>flags</i> field, the <i>mark</i> field must
1293    be set to point to a <b>char *</b> variable. If the pattern contains any
1294    backtracking control verbs such as (*MARK:NAME), and the execution ends up with
1295    a name to pass back, a pointer to the name string (zero terminated) is placed
1296    in the variable pointed to by the <i>mark</i> field. The names are within the
1297    compiled pattern; if you wish to retain such a name you must copy it before
1298    freeing the memory of a compiled pattern. If there is no name to pass back, the
1299    variable pointed to by the <i>mark</i> field set to NULL. For details of the
1300    backtracking control verbs, see the section entitled
1301    <a href="pcrepattern#backtrackcontrol">"Backtracking control"</a>
1302    in the
1303    <a href="pcrepattern.html"><b>pcrepattern</b></a>
1304    documentation.
1305  <a name="execoptions"></a></P>  <a name="execoptions"></a></P>
1306  <br><b>  <br><b>
1307  Option bits for <b>pcre_exec()</b>  Option bits for <b>pcre_exec()</b>
# Line 1242  Option bits for <b>pcre_exec()</b> Line 1309  Option bits for <b>pcre_exec()</b>
1309  <P>  <P>
1310  The unused bits of the <i>options</i> argument for <b>pcre_exec()</b> must be  The unused bits of the <i>options</i> argument for <b>pcre_exec()</b> must be
1311  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,
1312  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK and PCRE_PARTIAL.  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART,
1313    PCRE_NO_START_OPTIMIZE, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_SOFT, and
1314    PCRE_PARTIAL_HARD.
1315  <pre>  <pre>
1316    PCRE_ANCHORED    PCRE_ANCHORED
1317  </pre>  </pre>
# Line 1321  match the empty string, the entire match Line 1390  match the empty string, the entire match
1390  <pre>  <pre>
1391    a?b?    a?b?
1392  </pre>  </pre>
1393  is applied to a string not beginning with "a" or "b", it matches the empty  is applied to a string not beginning with "a" or "b", it matches an empty
1394  string at the start of the subject. With PCRE_NOTEMPTY set, this match is not  string at the start of the subject. With PCRE_NOTEMPTY set, this match is not
1395  valid, so PCRE searches further into the string for occurrences of "a" or "b".  valid, so PCRE searches further into the string for occurrences of "a" or "b".
1396    <pre>
1397      PCRE_NOTEMPTY_ATSTART
1398    </pre>
1399    This is like PCRE_NOTEMPTY, except that an empty string match that is not at
1400    the start of the subject is permitted. If the pattern is anchored, such a match
1401    can occur only if the pattern contains \K.
1402  </P>  </P>
1403  <P>  <P>
1404  Perl has no direct equivalent of PCRE_NOTEMPTY, but it does make a special case  Perl has no direct equivalent of PCRE_NOTEMPTY or PCRE_NOTEMPTY_ATSTART, but it
1405  of a pattern match of the empty string within its <b>split()</b> function, and  does make a special case of a pattern match of the empty string within its
1406  when using the /g modifier. It is possible to emulate Perl's behaviour after  <b>split()</b> function, and when using the /g modifier. It is possible to
1407  matching a null string by first trying the match again at the same offset with  emulate Perl's behaviour after matching a null string by first trying the match
1408  PCRE_NOTEMPTY and PCRE_ANCHORED, and then if that fails by advancing the  again at the same offset with PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED, and then
1409  starting offset (see below) and trying an ordinary match again. There is some  if that fails, by advancing the starting offset (see below) and trying an
1410  code that demonstrates how to do this in the <i>pcredemo.c</i> sample program.  ordinary match again. There is some code that demonstrates how to do this in
1411    the
1412    <a href="pcredemo.html"><b>pcredemo</b></a>
1413    sample program.
1414    <pre>
1415      PCRE_NO_START_OPTIMIZE
1416    </pre>
1417    There are a number of optimizations that <b>pcre_exec()</b> uses at the start of
1418    a match, in order to speed up the process. For example, if it is known that a
1419    match must start with a specific character, it searches the subject for that
1420    character, and fails immediately if it cannot find it, without actually running
1421    the main matching function. When callouts are in use, these optimizations can
1422    cause them to be skipped. This option disables the "start-up" optimizations,
1423    causing performance to suffer, but ensuring that the callouts do occur.
1424  <pre>  <pre>
1425    PCRE_NO_UTF8_CHECK    PCRE_NO_UTF8_CHECK
1426  </pre>  </pre>
# Line 1359  PCRE_NO_UTF8_CHECK is set, the effect of Line 1447  PCRE_NO_UTF8_CHECK is set, the effect of
1447  subject, or a value of <i>startoffset</i> that does not point to the start of a  subject, or a value of <i>startoffset</i> that does not point to the start of a
1448  UTF-8 character, is undefined. Your program may crash.  UTF-8 character, is undefined. Your program may crash.
1449  <pre>  <pre>
1450    PCRE_PARTIAL    PCRE_PARTIAL_HARD
1451      PCRE_PARTIAL_SOFT
1452  </pre>  </pre>
1453  This option turns on the partial matching feature. If the subject string fails  These options turn on the partial matching feature. For backwards
1454  to match the pattern, but at some point during the matching process the end of  compatibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial match
1455  the subject was reached (that is, the subject partially matches the pattern and  occurs if the end of the subject string is reached successfully, but there are
1456  the failure to match occurred only because there were not enough subject  not enough subject characters to complete the match. If this happens when
1457  characters), <b>pcre_exec()</b> returns PCRE_ERROR_PARTIAL instead of  PCRE_PARTIAL_HARD is set, <b>pcre_exec()</b> immediately returns
1458  PCRE_ERROR_NOMATCH. When PCRE_PARTIAL is used, there are restrictions on what  PCRE_ERROR_PARTIAL. Otherwise, if PCRE_PARTIAL_SOFT is set, matching continues
1459  may appear in the pattern. These are discussed in the  by testing any other alternatives. Only if they all fail is PCRE_ERROR_PARTIAL
1460    returned (instead of PCRE_ERROR_NOMATCH). The portion of the string that
1461    was inspected when the partial match was found is set as the first matching
1462    string. There is a more detailed discussion in the
1463  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
1464  documentation.  documentation.
1465  </P>  </P>
# Line 1376  The string to be matched by <b>pcre_exec Line 1468  The string to be matched by <b>pcre_exec
1468  </b><br>  </b><br>
1469  <P>  <P>
1470  The subject string is passed to <b>pcre_exec()</b> as a pointer in  The subject string is passed to <b>pcre_exec()</b> as a pointer in
1471  <i>subject</i>, a length in <i>length</i>, and a starting byte offset in  <i>subject</i>, a length (in bytes) in <i>length</i>, and a starting byte offset
1472  <i>startoffset</i>. In UTF-8 mode, the byte offset must point to the start of a  in <i>startoffset</i>. In UTF-8 mode, the byte offset must point to the start of
1473  UTF-8 character. Unlike the pattern string, the subject may contain binary zero  a UTF-8 character. Unlike the pattern string, the subject may contain binary
1474  bytes. When the starting offset is zero, the search for a match starts at the  zero bytes. When the starting offset is zero, the search for a match starts at
1475  beginning of the subject, and this is by far the most common case.  the beginning of the subject, and this is by far the most common case.
1476  </P>  </P>
1477  <P>  <P>
1478  A non-zero starting offset is useful when searching for another match in the  A non-zero starting offset is useful when searching for another match in the
# Line 1418  a fragment of a pattern that picks out a Line 1510  a fragment of a pattern that picks out a
1510  kinds of parenthesized subpattern that do not cause substrings to be captured.  kinds of parenthesized subpattern that do not cause substrings to be captured.
1511  </P>  </P>
1512  <P>  <P>
1513  Captured substrings are returned to the caller via a vector of integer offsets  Captured substrings are returned to the caller via a vector of integers whose
1514  whose address is passed in <i>ovector</i>. The number of elements in the vector  address is passed in <i>ovector</i>. The number of elements in the vector is
1515  is passed in <i>ovecsize</i>, which must be a non-negative number. <b>Note</b>:  passed in <i>ovecsize</i>, which must be a non-negative number. <b>Note</b>: this
1516  this argument is NOT the size of <i>ovector</i> in bytes.  argument is NOT the size of <i>ovector</i> in bytes.
1517  </P>  </P>
1518  <P>  <P>
1519  The first two-thirds of the vector is used to pass back captured substrings,  The first two-thirds of the vector is used to pass back captured substrings,
1520  each substring using a pair of integers. The remaining third of the vector is  each substring using a pair of integers. The remaining third of the vector is
1521  used as workspace by <b>pcre_exec()</b> while matching capturing subpatterns,  used as workspace by <b>pcre_exec()</b> while matching capturing subpatterns,
1522  and is not available for passing back information. The length passed in  and is not available for passing back information. The number passed in
1523  <i>ovecsize</i> should always be a multiple of three. If it is not, it is  <i>ovecsize</i> should always be a multiple of three. If it is not, it is
1524  rounded down.  rounded down.
1525  </P>  </P>
1526  <P>  <P>
1527  When a match is successful, information about captured substrings is returned  When a match is successful, information about captured substrings is returned
1528  in pairs of integers, starting at the beginning of <i>ovector</i>, and  in pairs of integers, starting at the beginning of <i>ovector</i>, and
1529  continuing up to two-thirds of its length at the most. The first element of a  continuing up to two-thirds of its length at the most. The first element of
1530  pair is set to the offset of the first character in a substring, and the second  each pair is set to the byte offset of the first character in a substring, and
1531  is set to the offset of the first character after the end of a substring. The  the second is set to the byte offset of the first character after the end of a
1532  first pair, <i>ovector[0]</i> and <i>ovector[1]</i>, identify the portion of the  substring. <b>Note</b>: these values are always byte offsets, even in UTF-8
1533  subject string matched by the entire pattern. The next pair is used for the  mode. They are not character counts.
1534  first capturing subpattern, and so on. The value returned by <b>pcre_exec()</b>  </P>
1535  is one more than the highest numbered pair that has been set. For example, if  <P>
1536  two substrings have been captured, the returned value is 3. If there are no  The first pair of integers, <i>ovector[0]</i> and <i>ovector[1]</i>, identify the
1537  capturing subpatterns, the return value from a successful match is 1,  portion of the subject string matched by the entire pattern. The next pair is
1538  indicating that just the first pair of offsets has been set.  used for the first capturing subpattern, and so on. The value returned by
1539    <b>pcre_exec()</b> is one more than the highest numbered pair that has been set.
1540    For example, if two substrings have been captured, the returned value is 3. If
1541    there are no capturing subpatterns, the return value from a successful match is
1542    1, indicating that just the first pair of offsets has been set.
1543  </P>  </P>
1544  <P>  <P>
1545  If a capturing subpattern is matched repeatedly, it is the last portion of the  If a capturing subpattern is matched repeatedly, it is the last portion of the
# Line 1452  string that it matched that is returned. Line 1548  string that it matched that is returned.
1548  <P>  <P>
1549  If the vector is too small to hold all the captured substring offsets, it is  If the vector is too small to hold all the captured substring offsets, it is
1550  used as far as possible (up to two-thirds of its length), and the function  used as far as possible (up to two-thirds of its length), and the function
1551  returns a value of zero. In particular, if the substring offsets are not of  returns a value of zero. If the substring offsets are not of interest,
1552  interest, <b>pcre_exec()</b> may be called with <i>ovector</i> passed as NULL and  <b>pcre_exec()</b> may be called with <i>ovector</i> passed as NULL and
1553  <i>ovecsize</i> as zero. However, if the pattern contains back references and  <i>ovecsize</i> as zero. However, if the pattern contains back references and
1554  the <i>ovector</i> is not big enough to remember the related substrings, PCRE  the <i>ovector</i> is not big enough to remember the related substrings, PCRE
1555  has to get additional memory for use during matching. Thus it is usually  has to get additional memory for use during matching. Thus it is usually
1556  advisable to supply an <i>ovector</i>.  advisable to supply an <i>ovector</i>.
1557  </P>  </P>
1558  <P>  <P>
1559  The <b>pcre_info()</b> function can be used to find out how many capturing  The <b>pcre_fullinfo()</b> function can be used to find out how many capturing
1560  subpatterns there are in a compiled pattern. The smallest size for  subpatterns there are in a compiled pattern. The smallest size for
1561  <i>ovector</i> that will allow for <i>n</i> captured substrings, in addition to  <i>ovector</i> that will allow for <i>n</i> captured substrings, in addition to
1562  the offsets of the substring matched by the whole pattern, is (<i>n</i>+1)*3.  the offsets of the substring matched by the whole pattern, is (<i>n</i>+1)*3.
# Line 1564  documentation for details of partial mat Line 1660  documentation for details of partial mat
1660  <pre>  <pre>
1661    PCRE_ERROR_BADPARTIAL     (-13)    PCRE_ERROR_BADPARTIAL     (-13)
1662  </pre>  </pre>
1663  The PCRE_PARTIAL option was used with a compiled pattern containing items that  This code is no longer in use. It was formerly returned when the PCRE_PARTIAL
1664  are not supported for partial matching. See the  option was used with a compiled pattern containing items that were not
1665  <a href="pcrepartial.html"><b>pcrepartial</b></a>  supported for partial matching. From release 8.00 onwards, there are no
1666  documentation for details of partial matching.  restrictions on partial matching.
1667  <pre>  <pre>
1668    PCRE_ERROR_INTERNAL       (-14)    PCRE_ERROR_INTERNAL       (-14)
1669  </pre>  </pre>
# Line 1739  then call <b>pcre_copy_substring()</b> o Line 1835  then call <b>pcre_copy_substring()</b> o
1835  appropriate. <b>NOTE:</b> If PCRE_DUPNAMES is set and there are duplicate names,  appropriate. <b>NOTE:</b> If PCRE_DUPNAMES is set and there are duplicate names,
1836  the behaviour may not be what you want (see the next section).  the behaviour may not be what you want (see the next section).
1837  </P>  </P>
1838    <P>
1839    <b>Warning:</b> If the pattern uses the (?| feature to set up multiple
1840    subpatterns with the same number, as described in the
1841    <a href="pcrepattern.html#dupsubpatternnumber">section on duplicate subpattern numbers</a>
1842    in the
1843    <a href="pcrepattern.html"><b>pcrepattern</b></a>
1844    page, you cannot use names to distinguish the different subpatterns, because
1845    names are not included in the compiled code. The matching process uses only
1846    numbers. For this reason, the use of different names for subpatterns of the
1847    same number causes an error at compile time.
1848    </P>
1849  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>
1850  <P>  <P>
1851  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>
# Line 1746  the behaviour may not be what you want ( Line 1853  the behaviour may not be what you want (
1853  </P>  </P>
1854  <P>  <P>
1855  When a pattern is compiled with the PCRE_DUPNAMES option, names for subpatterns  When a pattern is compiled with the PCRE_DUPNAMES option, names for subpatterns
1856  are not required to be unique. Normally, patterns with duplicate names are such  are not required to be unique. (Duplicate names are always allowed for
1857  that in any one match, only one of the named subpatterns participates. An  subpatterns with the same number, created by using the (?| feature. Indeed, if
1858  example is shown in the  such subpatterns are named, they are required to use the same names.)
1859    </P>
1860    <P>
1861    Normally, patterns with duplicate names are such that in any one match, only
1862    one of the named subpatterns participates. An example is shown in the
1863  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
1864  documentation.  documentation.
1865  </P>  </P>
# Line 1804  a compiled pattern, using a matching alg Line 1915  a compiled pattern, using a matching alg
1915  just once, and does not backtrack. This has different characteristics to the  just once, and does not backtrack. This has different characteristics to the
1916  normal algorithm, and is not compatible with Perl. Some of the features of PCRE  normal algorithm, and is not compatible with Perl. Some of the features of PCRE
1917  patterns are not supported. Nevertheless, there are times when this kind of  patterns are not supported. Nevertheless, there are times when this kind of
1918  matching can be useful. For a discussion of the two matching algorithms, see  matching can be useful. For a discussion of the two matching algorithms, and a
1919  the  list of features that <b>pcre_dfa_exec()</b> does not support, see the
1920  <a href="pcrematching.html"><b>pcrematching</b></a>  <a href="pcrematching.html"><b>pcrematching</b></a>
1921  documentation.  documentation.
1922  </P>  </P>
# Line 1847  Option bits for <b>pcre_dfa_exec()</b> Line 1958  Option bits for <b>pcre_dfa_exec()</b>
1958  <P>  <P>
1959  The unused bits of the <i>options</i> argument for <b>pcre_dfa_exec()</b> must be  The unused bits of the <i>options</i> argument for <b>pcre_dfa_exec()</b> must be
1960  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,
1961  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL,  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART,
1962  PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last three of these are  PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_HARD, PCRE_PARTIAL_SOFT, PCRE_DFA_SHORTEST,
1963  the same as for <b>pcre_exec()</b>, so their description is not repeated here.  and PCRE_DFA_RESTART. All but the last four of these are exactly the same as
1964  <pre>  for <b>pcre_exec()</b>, so their description is not repeated here.
1965    PCRE_PARTIAL  <pre>
1966  </pre>    PCRE_PARTIAL_HARD
1967  This has the same general effect as it does for <b>pcre_exec()</b>, but the    PCRE_PARTIAL_SOFT
1968  details are slightly different. When PCRE_PARTIAL is set for  </pre>
1969  <b>pcre_dfa_exec()</b>, the return code PCRE_ERROR_NOMATCH is converted into  These have the same general effect as they do for <b>pcre_exec()</b>, but the
1970  PCRE_ERROR_PARTIAL if the end of the subject is reached, there have been no  details are slightly different. When PCRE_PARTIAL_HARD is set for
1971  complete matches, but there is still at least one matching possibility. The  <b>pcre_dfa_exec()</b>, it returns PCRE_ERROR_PARTIAL if the end of the subject
1972  portion of the string that provided the partial match is set as the first  is reached and there is still at least one matching possibility that requires
1973  matching string.  additional characters. This happens even if some complete matches have also
1974    been found. When PCRE_PARTIAL_SOFT is set, the return code PCRE_ERROR_NOMATCH
1975    is converted into PCRE_ERROR_PARTIAL if the end of the subject is reached,
1976    there have been no complete matches, but there is still at least one matching
1977    possibility. The portion of the string that was inspected when the longest
1978    partial match was found is set as the first matching string in both cases.
1979  <pre>  <pre>
1980    PCRE_DFA_SHORTEST    PCRE_DFA_SHORTEST
1981  </pre>  </pre>
# Line 1870  matching point in the subject string. Line 1986  matching point in the subject string.
1986  <pre>  <pre>
1987    PCRE_DFA_RESTART    PCRE_DFA_RESTART
1988  </pre>  </pre>
1989  When <b>pcre_dfa_exec()</b> is called with the PCRE_PARTIAL option, and returns  When <b>pcre_dfa_exec()</b> returns a partial match, it is possible to call it
1990  a partial match, it is possible to call it again, with additional subject  again, with additional subject characters, and have it continue with the same
1991  characters, and have it continue with the same match. The PCRE_DFA_RESTART  match. The PCRE_DFA_RESTART option requests this action; when it is set, the
1992  option requests this action; when it is set, the <i>workspace</i> and  <i>workspace</i> and <i>wscount</i> options must reference the same vector as
1993  <i>wscount</i> options must reference the same vector as before because data  before because data about the match so far is left in them after a partial
1994  about the match so far is left in them after a partial match. There is more  match. There is more discussion of this facility in the
 discussion of this facility in the  
1995  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
1996  documentation.  documentation.
1997  </P>  </P>
# Line 1972  Cambridge CB2 3QH, England. Line 2087  Cambridge CB2 3QH, England.
2087  </P>  </P>
2088  <br><a name="SEC22" href="#TOC1">REVISION</a><br>  <br><a name="SEC22" href="#TOC1">REVISION</a><br>
2089  <P>  <P>
2090  Last updated: 12 April 2008  Last updated: 03 May 2010
2091  <br>  <br>
2092  Copyright &copy; 1997-2008 University of Cambridge.  Copyright &copy; 1997-2010 University of Cambridge.
2093  <br>  <br>
2094  <p>  <p>
2095  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.

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

  ViewVC Help
Powered by ViewVC 1.1.5