| 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> |
| 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> |
| 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> |
| 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> |
| 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 |
| 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>, PCRE_NEWLINE_<i>xxx</i>, PCRE_NO_UTF8_CHECK, and |
| 439 |
|
PCRE_NO_START_OPT options can be set at the time of matching as well as at |
| 440 |
|
compile time. |
| 441 |
</P> |
</P> |
| 442 |
<P> |
<P> |
| 443 |
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. |
| 444 |
Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns |
Otherwise, if compilation of a pattern fails, <b>pcre_compile()</b> returns |
| 445 |
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 |
| 446 |
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 |
| 447 |
not try to free it. The offset from the start of the pattern to the character |
not try to free it. Normally, the offset from the start of the pattern to the |
| 448 |
where the error was discovered is placed in the variable pointed to by |
byte that was being processed when the error was discovered is placed in the |
| 449 |
<i>erroffset</i>, which must not be NULL. If it is, an immediate error is given. |
variable pointed to by <i>erroffset</i>, which must not be NULL (if it is, an |
| 450 |
|
immediate error is given). However, for an invalid UTF-8 string, the offset is |
| 451 |
|
that of the first byte of the failing character. Also, some errors are not |
| 452 |
|
detected until checks are carried out when the whole pattern has been scanned; |
| 453 |
|
in these cases the offset passed back is the length of the pattern. |
| 454 |
|
</P> |
| 455 |
|
<P> |
| 456 |
|
Note that the offset is in bytes, not characters, even in UTF-8 mode. It may |
| 457 |
|
sometimes point into the middle of a UTF-8 character. |
| 458 |
</P> |
</P> |
| 459 |
<P> |
<P> |
| 460 |
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 |
| 534 |
<pre> |
<pre> |
| 535 |
PCRE_DOTALL |
PCRE_DOTALL |
| 536 |
</pre> |
</pre> |
| 537 |
If this bit is set, a dot metacharater in the pattern matches all characters, |
If this bit is set, a dot metacharacter in the pattern matches a character of |
| 538 |
including those that indicate newline. Without it, a dot does not match when |
any value, including one that indicates a newline. However, it only ever |
| 539 |
the current position is at a newline. This option is equivalent to Perl's /s |
matches one character, even if newlines are coded as CRLF. Without this option, |
| 540 |
option, and it can be changed within a pattern by a (?s) option setting. A |
a dot does not match when the current position is at a newline. This option is |
| 541 |
negative class such as [^a] always matches newline characters, independent of |
equivalent to Perl's /s option, and it can be changed within a pattern by a |
| 542 |
the setting of this option. |
(?s) option setting. A negative class such as [^a] always matches newline |
| 543 |
|
characters, independent of the setting of this option. |
| 544 |
<pre> |
<pre> |
| 545 |
PCRE_DUPNAMES |
PCRE_DUPNAMES |
| 546 |
</pre> |
</pre> |
| 561 |
pattern by a (?x) option setting. |
pattern by a (?x) option setting. |
| 562 |
</P> |
</P> |
| 563 |
<P> |
<P> |
| 564 |
|
Which characters are interpreted as newlines is controlled by the options |
| 565 |
|
passed to <b>pcre_compile()</b> or by a special sequence at the start of the |
| 566 |
|
pattern, as described in the section entitled |
| 567 |
|
<a href="pcrepattern.html#newlines">"Newline conventions"</a> |
| 568 |
|
in the <b>pcrepattern</b> documentation. Note that the end of this type of |
| 569 |
|
comment is a literal newline sequence in the pattern; escape sequences that |
| 570 |
|
happen to represent a newline do not count. |
| 571 |
|
</P> |
| 572 |
|
<P> |
| 573 |
This option makes it possible to include comments inside complicated patterns. |
This option makes it possible to include comments inside complicated patterns. |
| 574 |
Note, however, that this applies only to data characters. Whitespace characters |
Note, however, that this applies only to data characters. Whitespace characters |
| 575 |
may never appear within special character sequences in a pattern, for example |
may never appear within special character sequences in a pattern, for example |
| 576 |
within the sequence (?( which introduces a conditional subpattern. |
within the sequence (?( that introduces a conditional subpattern. |
| 577 |
<pre> |
<pre> |
| 578 |
PCRE_EXTRA |
PCRE_EXTRA |
| 579 |
</pre> |
</pre> |
| 583 |
special meaning causes an error, thus reserving these combinations for future |
special meaning causes an error, thus reserving these combinations for future |
| 584 |
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 |
| 585 |
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 |
| 586 |
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 |
| 587 |
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) |
| 588 |
|
option setting within a pattern. |
| 589 |
<pre> |
<pre> |
| 590 |
PCRE_FIRSTLINE |
PCRE_FIRSTLINE |
| 591 |
</pre> |
</pre> |
| 653 |
other combinations may yield unused numbers and cause an error. |
other combinations may yield unused numbers and cause an error. |
| 654 |
</P> |
</P> |
| 655 |
<P> |
<P> |
| 656 |
The only time that a line break is specially recognized when compiling a |
The only time that a line break in a pattern is specially recognized when |
| 657 |
pattern is if PCRE_EXTENDED is set, and an unescaped # outside a character |
compiling is when PCRE_EXTENDED is set. CR and LF are whitespace characters, |
| 658 |
class is encountered. This indicates a comment that lasts until after the next |
and so are ignored in this mode. Also, an unescaped # outside a character class |
| 659 |
line break sequence. In other circumstances, line break sequences are treated |
indicates a comment that lasts until after the next line break sequence. In |
| 660 |
as literal data, except that in PCRE_EXTENDED mode, both CR and LF are treated |
other circumstances, line break sequences in patterns are treated as literal |
| 661 |
as whitespace characters and are therefore ignored. |
data. |
| 662 |
</P> |
</P> |
| 663 |
<P> |
<P> |
| 664 |
The newline option that is set at compile time becomes the default that is used |
The newline option that is set at compile time becomes the default that is used |
| 672 |
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 |
| 673 |
in Perl. |
in Perl. |
| 674 |
<pre> |
<pre> |
| 675 |
|
NO_START_OPTIMIZE |
| 676 |
|
</pre> |
| 677 |
|
This is an option that acts at matching time; that is, it is really an option |
| 678 |
|
for <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>. If it is set at compile time, |
| 679 |
|
it is remembered with the compiled pattern and assumed at matching time. For |
| 680 |
|
details see the discussion of PCRE_NO_START_OPTIMIZE |
| 681 |
|
<a href="#execoptions">below.</a> |
| 682 |
|
<pre> |
| 683 |
|
PCRE_UCP |
| 684 |
|
</pre> |
| 685 |
|
This option changes the way PCRE processes \B, \b, \D, \d, \S, \s, \W, |
| 686 |
|
\w, and some of the POSIX character classes. By default, only ASCII characters |
| 687 |
|
are recognized, but if PCRE_UCP is set, Unicode properties are used instead to |
| 688 |
|
classify characters. More details are given in the section on |
| 689 |
|
<a href="pcre.html#genericchartypes">generic character types</a> |
| 690 |
|
in the |
| 691 |
|
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
| 692 |
|
page. If you set PCRE_UCP, matching one of the items it affects takes much |
| 693 |
|
longer. The option is available only if PCRE has been compiled with Unicode |
| 694 |
|
property support. |
| 695 |
|
<pre> |
| 696 |
PCRE_UNGREEDY |
PCRE_UNGREEDY |
| 697 |
</pre> |
</pre> |
| 698 |
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 |
| 770 |
34 character value in \x{...} sequence is too large |
34 character value in \x{...} sequence is too large |
| 771 |
35 invalid condition (?(0) |
35 invalid condition (?(0) |
| 772 |
36 \C not allowed in lookbehind assertion |
36 \C not allowed in lookbehind assertion |
| 773 |
37 PCRE does not support \L, \l, \N, \U, or \u |
37 PCRE does not support \L, \l, \N{name}, \U, or \u |
| 774 |
38 number after (?C is > 255 |
38 number after (?C is > 255 |
| 775 |
39 closing ) for (?C expected |
39 closing ) for (?C expected |
| 776 |
40 recursive call could loop indefinitely |
40 recursive call could loop indefinitely |
| 786 |
50 [this code is not in use] |
50 [this code is not in use] |
| 787 |
51 octal value is greater than \377 (not in UTF-8 mode) |
51 octal value is greater than \377 (not in UTF-8 mode) |
| 788 |
52 internal error: overran compiling workspace |
52 internal error: overran compiling workspace |
| 789 |
53 internal error: previously-checked referenced subpattern not found |
53 internal error: previously-checked referenced subpattern |
| 790 |
|
not found |
| 791 |
54 DEFINE group contains more than one branch |
54 DEFINE group contains more than one branch |
| 792 |
55 repeating a DEFINE group is not allowed |
55 repeating a DEFINE group is not allowed |
| 793 |
56 inconsistent NEWLINE options |
56 inconsistent NEWLINE options |
| 794 |
57 \g is not followed by a braced, angle-bracketed, or quoted |
57 \g is not followed by a braced, angle-bracketed, or quoted |
| 795 |
name/number or by a plain number |
name/number or by a plain number |
| 796 |
58 a numbered reference must not be zero |
58 a numbered reference must not be zero |
| 797 |
59 (*VERB) with an argument is not supported |
59 an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT) |
| 798 |
60 (*VERB) not recognized |
60 (*VERB) not recognized |
| 799 |
61 number is too big |
61 number is too big |
| 800 |
62 subpattern name expected |
62 subpattern name expected |
| 801 |
63 digit expected after (?+ |
63 digit expected after (?+ |
| 802 |
64 ] is an invalid data character in JavaScript compatibility mode |
64 ] is an invalid data character in JavaScript compatibility mode |
| 803 |
|
65 different names for subpatterns of the same number are |
| 804 |
|
not allowed |
| 805 |
|
66 (*MARK) must have an argument |
| 806 |
|
67 this version of PCRE is not compiled with PCRE_UCP support |
| 807 |
|
68 \c must be followed by an ASCII character |
| 808 |
|
69 \k is not followed by a braced, angle-bracketed, or quoted name |
| 809 |
</pre> |
</pre> |
| 810 |
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 |
| 811 |
be used if the limits were changed when PCRE was built. |
be used if the limits were changed when PCRE was built. |
| 812 |
</P> |
<a name="studyingapattern"></a></P> |
| 813 |
<br><a name="SEC9" href="#TOC1">STUDYING A PATTERN</a><br> |
<br><a name="SEC9" href="#TOC1">STUDYING A PATTERN</a><br> |
| 814 |
<P> |
<P> |
| 815 |
<b>pcre_extra *pcre_study(const pcre *<i>code</i>, int <i>options</i></b> |
<b>pcre_extra *pcre_study(const pcre *<i>code</i>, int <i>options</i></b> |
| 826 |
</P> |
</P> |
| 827 |
<P> |
<P> |
| 828 |
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 |
| 829 |
<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 |
| 830 |
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 |
| 831 |
described |
passed; these are described |
| 832 |
<a href="#extradata">below</a> |
<a href="#extradata">below</a> |
| 833 |
in the section on matching a pattern. |
in the section on matching a pattern. |
| 834 |
</P> |
</P> |
| 835 |
<P> |
<P> |
| 836 |
If studying the pattern does not produce any additional information |
If studying the pattern does not produce any useful information, |
| 837 |
<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 |
| 838 |
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 |
| 839 |
own <b>pcre_extra</b> block. |
<b>pcre_dfa_exec()</b>, it must set up its own <b>pcre_extra</b> block. |
| 840 |
</P> |
</P> |
| 841 |
<P> |
<P> |
| 842 |
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 |
| 859 |
0, /* no options exist */ |
0, /* no options exist */ |
| 860 |
&error); /* set to NULL or points to a message */ |
&error); /* set to NULL or points to a message */ |
| 861 |
</pre> |
</pre> |
| 862 |
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 |
| 863 |
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 |
| 864 |
bytes is created. |
mean that there are any strings of that length that match, but it does |
| 865 |
|
guarantee that no shorter strings match. The value is used by |
| 866 |
|
<b>pcre_exec()</b> and <b>pcre_dfa_exec()</b> to avoid wasting time by trying to |
| 867 |
|
match strings that are shorter than the lower bound. You can find out the value |
| 868 |
|
in a calling program via the <b>pcre_fullinfo()</b> function. |
| 869 |
|
</P> |
| 870 |
|
<P> |
| 871 |
|
Studying a pattern is also useful for non-anchored patterns that do not have a |
| 872 |
|
single fixed starting character. A bitmap of possible starting bytes is |
| 873 |
|
created. This speeds up finding a position in the subject at which to start |
| 874 |
|
matching. |
| 875 |
|
</P> |
| 876 |
|
<P> |
| 877 |
|
The two optimizations just described can be disabled by setting the |
| 878 |
|
PCRE_NO_START_OPTIMIZE option when calling <b>pcre_exec()</b> or |
| 879 |
|
<b>pcre_dfa_exec()</b>. You might want to do this if your pattern contains |
| 880 |
|
callouts or (*MARK), and you want to make use of these facilities in cases |
| 881 |
|
where matching fails. See the discussion of PCRE_NO_START_OPTIMIZE |
| 882 |
|
<a href="#execoptions">below.</a> |
| 883 |
<a name="localesupport"></a></P> |
<a name="localesupport"></a></P> |
| 884 |
<br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br> |
<br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br> |
| 885 |
<P> |
<P> |
| 886 |
PCRE handles caseless matching, and determines whether characters are letters, |
PCRE handles caseless matching, and determines whether characters are letters, |
| 887 |
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 |
| 888 |
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 |
| 889 |
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 |
| 890 |
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 |
| 891 |
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 |
| 892 |
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 |
| 893 |
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 |
| 894 |
|
handling characters with codes greater than 128, you should either use UTF-8 |
| 895 |
|
and Unicode, or use locales, but not try to mix the two. |
| 896 |
</P> |
</P> |
| 897 |
<P> |
<P> |
| 898 |
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 |
| 941 |
this facility could be used to match a pattern in a different locale from the |
this facility could be used to match a pattern in a different locale from the |
| 942 |
one in which it was compiled. Passing table pointers at run time is discussed |
one in which it was compiled. Passing table pointers at run time is discussed |
| 943 |
below in the section on matching a pattern. |
below in the section on matching a pattern. |
| 944 |
</P> |
<a name="infoaboutpattern"></a></P> |
| 945 |
<br><a name="SEC11" href="#TOC1">INFORMATION ABOUT A PATTERN</a><br> |
<br><a name="SEC11" href="#TOC1">INFORMATION ABOUT A PATTERN</a><br> |
| 946 |
<P> |
<P> |
| 947 |
<b>int pcre_fullinfo(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b> |
<b>int pcre_fullinfo(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b> |
| 1052 |
/^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 |
| 1053 |
is -1. |
is -1. |
| 1054 |
<pre> |
<pre> |
| 1055 |
|
PCRE_INFO_MINLENGTH |
| 1056 |
|
</pre> |
| 1057 |
|
If the pattern was studied and a minimum length for matching subject strings |
| 1058 |
|
was computed, its value is returned. Otherwise the returned value is -1. The |
| 1059 |
|
value is a number of characters, not bytes (this may be relevant in UTF-8 |
| 1060 |
|
mode). The fourth argument should point to an <b>int</b> variable. A |
| 1061 |
|
non-negative value is a lower bound to the length of any matching string. There |
| 1062 |
|
may not be any strings of that length that do actually match, but every string |
| 1063 |
|
that does match is at least that long. |
| 1064 |
|
<pre> |
| 1065 |
PCRE_INFO_NAMECOUNT |
PCRE_INFO_NAMECOUNT |
| 1066 |
PCRE_INFO_NAMEENTRYSIZE |
PCRE_INFO_NAMEENTRYSIZE |
| 1067 |
PCRE_INFO_NAMETABLE |
PCRE_INFO_NAMETABLE |
| 1083 |
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 |
| 1084 |
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 |
| 1085 |
are the number of the capturing parenthesis, most significant byte first. The |
are the number of the capturing parenthesis, most significant byte first. The |
| 1086 |
rest of the entry is the corresponding name, zero terminated. The names are in |
rest of the entry is the corresponding name, zero terminated. |
| 1087 |
alphabetical order. When PCRE_DUPNAMES is set, duplicate names are in order of |
</P> |
| 1088 |
their parentheses numbers. For example, consider the following pattern (assume |
<P> |
| 1089 |
PCRE_EXTENDED is set, so white space - including newlines - is ignored): |
The names are in alphabetical order. Duplicate names may appear if (?| is used |
| 1090 |
|
to create multiple groups with the same number, as described in the |
| 1091 |
|
<a href="pcrepattern.html#dupsubpatternnumber">section on duplicate subpattern numbers</a> |
| 1092 |
|
in the |
| 1093 |
|
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
| 1094 |
|
page. Duplicate names for subpatterns with different numbers are permitted only |
| 1095 |
|
if PCRE_DUPNAMES is set. In all cases of duplicate names, they appear in the |
| 1096 |
|
table in the order in which they were found in the pattern. In the absence of |
| 1097 |
|
(?| this is the order of increasing number; when (?| is used this is not |
| 1098 |
|
necessarily the case because later subpatterns may have lower numbers. |
| 1099 |
|
</P> |
| 1100 |
|
<P> |
| 1101 |
|
As a simple example of the name/number table, consider the following pattern |
| 1102 |
|
(assume PCRE_EXTENDED is set, so white space - including newlines - is |
| 1103 |
|
ignored): |
| 1104 |
<pre> |
<pre> |
| 1105 |
(?<date> (?<year>(\d\d)?\d\d) - (?<month>\d\d) - (?<day>\d\d) ) |
(?<date> (?<year>(\d\d)?\d\d) - (?<month>\d\d) - (?<day>\d\d) ) |
| 1106 |
</pre> |
</pre> |
| 1119 |
<pre> |
<pre> |
| 1120 |
PCRE_INFO_OKPARTIAL |
PCRE_INFO_OKPARTIAL |
| 1121 |
</pre> |
</pre> |
| 1122 |
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 |
| 1123 |
fourth argument should point to an <b>int</b> variable. The |
<b>pcre_exec()</b>, otherwise 0. The fourth argument should point to an |
| 1124 |
|
<b>int</b> variable. From release 8.00, this always returns 1, because the |
| 1125 |
|
restrictions that previously applied to partial matching have been lifted. The |
| 1126 |
<a href="pcrepartial.html"><b>pcrepartial</b></a> |
<a href="pcrepartial.html"><b>pcrepartial</b></a> |
| 1127 |
documentation lists the restrictions that apply to patterns when partial |
documentation gives details of partial matching. |
|
matching is used. |
|
| 1128 |
<pre> |
<pre> |
| 1129 |
PCRE_INFO_OPTIONS |
PCRE_INFO_OPTIONS |
| 1130 |
</pre> |
</pre> |
| 1157 |
<pre> |
<pre> |
| 1158 |
PCRE_INFO_STUDYSIZE |
PCRE_INFO_STUDYSIZE |
| 1159 |
</pre> |
</pre> |
| 1160 |
Return the size of the data block pointed to by the <i>study_data</i> field in |
Return the size of the data block pointed to by the <i>study_data</i> field in a |
| 1161 |
a <b>pcre_extra</b> block. That is, it is the value that was passed to |
<b>pcre_extra</b> block. If <b>pcre_extra</b> is NULL, or there is no study data, |
| 1162 |
<b>pcre_malloc()</b> when PCRE was getting memory into which to place the data |
zero is returned. The fourth argument should point to a <b>size_t</b> variable. |
| 1163 |
created by <b>pcre_study()</b>. The fourth argument should point to a |
The <i>study_data</i> field is set by <b>pcre_study()</b> to record information |
| 1164 |
<b>size_t</b> variable. |
that will speed up matching (see the section entitled |
| 1165 |
|
<a href="#studyingapattern">"Studying a pattern"</a> |
| 1166 |
|
above). The format of the <i>study_data</i> block is private, but its length |
| 1167 |
|
is made available via this option so that it can be saved and restored (see the |
| 1168 |
|
<a href="pcreprecompile.html"><b>pcreprecompile</b></a> |
| 1169 |
|
documentation for details). |
| 1170 |
</P> |
</P> |
| 1171 |
<br><a name="SEC12" href="#TOC1">OBSOLETE INFO FUNCTION</a><br> |
<br><a name="SEC12" href="#TOC1">OBSOLETE INFO FUNCTION</a><br> |
| 1172 |
<P> |
<P> |
| 1225 |
<P> |
<P> |
| 1226 |
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 |
| 1227 |
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 |
| 1228 |
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 |
| 1229 |
<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 |
| 1230 |
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 |
| 1231 |
also an alternative matching function, which is described |
also an alternative matching function, which is described |
| 1273 |
unsigned long int <i>match_limit_recursion</i>; |
unsigned long int <i>match_limit_recursion</i>; |
| 1274 |
void *<i>callout_data</i>; |
void *<i>callout_data</i>; |
| 1275 |
const unsigned char *<i>tables</i>; |
const unsigned char *<i>tables</i>; |
| 1276 |
|
unsigned char **<i>mark</i>; |
| 1277 |
</pre> |
</pre> |
| 1278 |
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 |
| 1279 |
are set. The flag bits are: |
are set. The flag bits are: |
| 1283 |
PCRE_EXTRA_MATCH_LIMIT_RECURSION |
PCRE_EXTRA_MATCH_LIMIT_RECURSION |
| 1284 |
PCRE_EXTRA_CALLOUT_DATA |
PCRE_EXTRA_CALLOUT_DATA |
| 1285 |
PCRE_EXTRA_TABLES |
PCRE_EXTRA_TABLES |
| 1286 |
|
PCRE_EXTRA_MARK |
| 1287 |
</pre> |
</pre> |
| 1288 |
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 |
| 1289 |
<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 |
| 1294 |
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 |
| 1295 |
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, |
| 1296 |
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 |
| 1297 |
classic example is the use of nested unlimited repeats. |
classic example is a pattern that uses nested unlimited repeats. |
| 1298 |
</P> |
</P> |
| 1299 |
<P> |
<P> |
| 1300 |
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 |
| 1333 |
is exceeded, <b>pcre_exec()</b> returns PCRE_ERROR_RECURSIONLIMIT. |
is exceeded, <b>pcre_exec()</b> returns PCRE_ERROR_RECURSIONLIMIT. |
| 1334 |
</P> |
</P> |
| 1335 |
<P> |
<P> |
| 1336 |
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, |
| 1337 |
which is described in the |
and is described in the |
| 1338 |
<a href="pcrecallout.html"><b>pcrecallout</b></a> |
<a href="pcrecallout.html"><b>pcrecallout</b></a> |
| 1339 |
documentation. |
documentation. |
| 1340 |
</P> |
</P> |
| 1350 |
called. See the |
called. See the |
| 1351 |
<a href="pcreprecompile.html"><b>pcreprecompile</b></a> |
<a href="pcreprecompile.html"><b>pcreprecompile</b></a> |
| 1352 |
documentation for a discussion of saving compiled patterns for later use. |
documentation for a discussion of saving compiled patterns for later use. |
| 1353 |
|
</P> |
| 1354 |
|
<P> |
| 1355 |
|
If PCRE_EXTRA_MARK is set in the <i>flags</i> field, the <i>mark</i> field must |
| 1356 |
|
be set to point to a <b>char *</b> variable. If the pattern contains any |
| 1357 |
|
backtracking control verbs such as (*MARK:NAME), and the execution ends up with |
| 1358 |
|
a name to pass back, a pointer to the name string (zero terminated) is placed |
| 1359 |
|
in the variable pointed to by the <i>mark</i> field. The names are within the |
| 1360 |
|
compiled pattern; if you wish to retain such a name you must copy it before |
| 1361 |
|
freeing the memory of a compiled pattern. If there is no name to pass back, the |
| 1362 |
|
variable pointed to by the <i>mark</i> field set to NULL. For details of the |
| 1363 |
|
backtracking control verbs, see the section entitled |
| 1364 |
|
<a href="pcrepattern#backtrackcontrol">"Backtracking control"</a> |
| 1365 |
|
in the |
| 1366 |
|
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
| 1367 |
|
documentation. |
| 1368 |
<a name="execoptions"></a></P> |
<a name="execoptions"></a></P> |
| 1369 |
<br><b> |
<br><b> |
| 1370 |
Option bits for <b>pcre_exec()</b> |
Option bits for <b>pcre_exec()</b> |
| 1372 |
<P> |
<P> |
| 1373 |
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 |
| 1374 |
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>, |
| 1375 |
PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK and PCRE_PARTIAL. |
PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART, |
| 1376 |
|
PCRE_NO_START_OPTIMIZE, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_SOFT, and |
| 1377 |
|
PCRE_PARTIAL_HARD. |
| 1378 |
<pre> |
<pre> |
| 1379 |
PCRE_ANCHORED |
PCRE_ANCHORED |
| 1380 |
</pre> |
</pre> |
| 1453 |
<pre> |
<pre> |
| 1454 |
a?b? |
a?b? |
| 1455 |
</pre> |
</pre> |
| 1456 |
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 |
| 1457 |
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 |
| 1458 |
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". |
| 1459 |
|
<pre> |
| 1460 |
|
PCRE_NOTEMPTY_ATSTART |
| 1461 |
|
</pre> |
| 1462 |
|
This is like PCRE_NOTEMPTY, except that an empty string match that is not at |
| 1463 |
|
the start of the subject is permitted. If the pattern is anchored, such a match |
| 1464 |
|
can occur only if the pattern contains \K. |
| 1465 |
</P> |
</P> |
| 1466 |
<P> |
<P> |
| 1467 |
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 |
| 1468 |
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 |
| 1469 |
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 |
| 1470 |
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 |
| 1471 |
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 |
| 1472 |
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 |
| 1473 |
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 |
| 1474 |
|
the |
| 1475 |
|
<a href="pcredemo.html"><b>pcredemo</b></a> |
| 1476 |
|
sample program. In the most general case, you have to check to see if the |
| 1477 |
|
newline convention recognizes CRLF as a newline, and if so, and the current |
| 1478 |
|
character is CR followed by LF, advance the starting offset by two characters |
| 1479 |
|
instead of one. |
| 1480 |
|
<pre> |
| 1481 |
|
PCRE_NO_START_OPTIMIZE |
| 1482 |
|
</pre> |
| 1483 |
|
There are a number of optimizations that <b>pcre_exec()</b> uses at the start of |
| 1484 |
|
a match, in order to speed up the process. For example, if it is known that an |
| 1485 |
|
unanchored match must start with a specific character, it searches the subject |
| 1486 |
|
for that character, and fails immediately if it cannot find it, without |
| 1487 |
|
actually running the main matching function. This means that a special item |
| 1488 |
|
such as (*COMMIT) at the start of a pattern is not considered until after a |
| 1489 |
|
suitable starting point for the match has been found. When callouts or (*MARK) |
| 1490 |
|
items are in use, these "start-up" optimizations can cause them to be skipped |
| 1491 |
|
if the pattern is never actually used. The start-up optimizations are in effect |
| 1492 |
|
a pre-scan of the subject that takes place before the pattern is run. |
| 1493 |
|
</P> |
| 1494 |
|
<P> |
| 1495 |
|
The PCRE_NO_START_OPTIMIZE option disables the start-up optimizations, possibly |
| 1496 |
|
causing performance to suffer, but ensuring that in cases where the result is |
| 1497 |
|
"no match", the callouts do occur, and that items such as (*COMMIT) and (*MARK) |
| 1498 |
|
are considered at every possible starting position in the subject string. If |
| 1499 |
|
PCRE_NO_START_OPTIMIZE is set at compile time, it cannot be unset at matching |
| 1500 |
|
time. |
| 1501 |
|
</P> |
| 1502 |
|
<P> |
| 1503 |
|
Setting PCRE_NO_START_OPTIMIZE can change the outcome of a matching operation. |
| 1504 |
|
Consider the pattern |
| 1505 |
|
<pre> |
| 1506 |
|
(*COMMIT)ABC |
| 1507 |
|
</pre> |
| 1508 |
|
When this is compiled, PCRE records the fact that a match must start with the |
| 1509 |
|
character "A". Suppose the subject string is "DEFABC". The start-up |
| 1510 |
|
optimization scans along the subject, finds "A" and runs the first match |
| 1511 |
|
attempt from there. The (*COMMIT) item means that the pattern must match the |
| 1512 |
|
current starting position, which in this case, it does. However, if the same |
| 1513 |
|
match is run with PCRE_NO_START_OPTIMIZE set, the initial scan along the |
| 1514 |
|
subject string does not happen. The first match attempt is run starting from |
| 1515 |
|
"D" and when this fails, (*COMMIT) prevents any further matches being tried, so |
| 1516 |
|
the overall result is "no match". If the pattern is studied, more start-up |
| 1517 |
|
optimizations may be used. For example, a minimum length for the subject may be |
| 1518 |
|
recorded. Consider the pattern |
| 1519 |
|
<pre> |
| 1520 |
|
(*MARK:A)(X|Y) |
| 1521 |
|
</pre> |
| 1522 |
|
The minimum length for a match is one character. If the subject is "ABC", there |
| 1523 |
|
will be attempts to match "ABC", "BC", "C", and then finally an empty string. |
| 1524 |
|
If the pattern is studied, the final attempt does not take place, because PCRE |
| 1525 |
|
knows that the subject is too short, and so the (*MARK) is never encountered. |
| 1526 |
|
In this case, studying the pattern does not affect the overall match result, |
| 1527 |
|
which is still "no match", but it does affect the auxiliary information that is |
| 1528 |
|
returned. |
| 1529 |
<pre> |
<pre> |
| 1530 |
PCRE_NO_UTF8_CHECK |
PCRE_NO_UTF8_CHECK |
| 1531 |
</pre> |
</pre> |
| 1538 |
in the main |
in the main |
| 1539 |
<a href="pcre.html"><b>pcre</b></a> |
<a href="pcre.html"><b>pcre</b></a> |
| 1540 |
page. If an invalid UTF-8 sequence of bytes is found, <b>pcre_exec()</b> returns |
page. If an invalid UTF-8 sequence of bytes is found, <b>pcre_exec()</b> returns |
| 1541 |
the error PCRE_ERROR_BADUTF8. If <i>startoffset</i> contains an invalid value, |
the error PCRE_ERROR_BADUTF8 or, if PCRE_PARTIAL_HARD is set and the problem is |
| 1542 |
PCRE_ERROR_BADUTF8_OFFSET is returned. |
a truncated UTF-8 character at the end of the subject, PCRE_ERROR_SHORTUTF8. In |
| 1543 |
|
both cases, information about the precise nature of the error may also be |
| 1544 |
|
returned (see the descriptions of these errors in the section entitled \fIError |
| 1545 |
|
return values from\fP <b>pcre_exec()</b> |
| 1546 |
|
<a href="#errorlist">below).</a> |
| 1547 |
|
If <i>startoffset</i> contains a value that does not point to the start of a |
| 1548 |
|
UTF-8 character (or to the end of the subject), PCRE_ERROR_BADUTF8_OFFSET is |
| 1549 |
|
returned. |
| 1550 |
</P> |
</P> |
| 1551 |
<P> |
<P> |
| 1552 |
If you already know that your subject is valid, and you want to skip these |
If you already know that your subject is valid, and you want to skip these |
| 1554 |
calling <b>pcre_exec()</b>. You might want to do this for the second and |
calling <b>pcre_exec()</b>. You might want to do this for the second and |
| 1555 |
subsequent calls to <b>pcre_exec()</b> if you are making repeated calls to find |
subsequent calls to <b>pcre_exec()</b> if you are making repeated calls to find |
| 1556 |
all the matches in a single subject string. However, you should be sure that |
all the matches in a single subject string. However, you should be sure that |
| 1557 |
the value of <i>startoffset</i> points to the start of a UTF-8 character. When |
the value of <i>startoffset</i> points to the start of a UTF-8 character (or the |
| 1558 |
PCRE_NO_UTF8_CHECK is set, the effect of passing an invalid UTF-8 string as a |
end of the subject). When PCRE_NO_UTF8_CHECK is set, the effect of passing an |
| 1559 |
subject, or a value of <i>startoffset</i> that does not point to the start of a |
invalid UTF-8 string as a subject or an invalid value of <i>startoffset</i> is |
| 1560 |
UTF-8 character, is undefined. Your program may crash. |
undefined. Your program may crash. |
| 1561 |
<pre> |
<pre> |
| 1562 |
PCRE_PARTIAL |
PCRE_PARTIAL_HARD |
| 1563 |
</pre> |
PCRE_PARTIAL_SOFT |
| 1564 |
This option turns on the partial matching feature. If the subject string fails |
</pre> |
| 1565 |
to match the pattern, but at some point during the matching process the end of |
These options turn on the partial matching feature. For backwards |
| 1566 |
the subject was reached (that is, the subject partially matches the pattern and |
compatibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial match |
| 1567 |
the failure to match occurred only because there were not enough subject |
occurs if the end of the subject string is reached successfully, but there are |
| 1568 |
characters), <b>pcre_exec()</b> returns PCRE_ERROR_PARTIAL instead of |
not enough subject characters to complete the match. If this happens when |
| 1569 |
PCRE_ERROR_NOMATCH. When PCRE_PARTIAL is used, there are restrictions on what |
PCRE_PARTIAL_SOFT (but not PCRE_PARTIAL_HARD) is set, matching continues by |
| 1570 |
may appear in the pattern. These are discussed in the |
testing any remaining alternatives. Only if no complete match can be found is |
| 1571 |
|
PCRE_ERROR_PARTIAL returned instead of PCRE_ERROR_NOMATCH. In other words, |
| 1572 |
|
PCRE_PARTIAL_SOFT says that the caller is prepared to handle a partial match, |
| 1573 |
|
but only if no complete match can be found. |
| 1574 |
|
</P> |
| 1575 |
|
<P> |
| 1576 |
|
If PCRE_PARTIAL_HARD is set, it overrides PCRE_PARTIAL_SOFT. In this case, if a |
| 1577 |
|
partial match is found, <b>pcre_exec()</b> immediately returns |
| 1578 |
|
PCRE_ERROR_PARTIAL, without considering any other alternatives. In other words, |
| 1579 |
|
when PCRE_PARTIAL_HARD is set, a partial match is considered to be more |
| 1580 |
|
important that an alternative complete match. |
| 1581 |
|
</P> |
| 1582 |
|
<P> |
| 1583 |
|
In both cases, the portion of the string that was inspected when the partial |
| 1584 |
|
match was found is set as the first matching string. There is a more detailed |
| 1585 |
|
discussion of partial and multi-segment matching, with examples, in the |
| 1586 |
<a href="pcrepartial.html"><b>pcrepartial</b></a> |
<a href="pcrepartial.html"><b>pcrepartial</b></a> |
| 1587 |
documentation. |
documentation. |
| 1588 |
</P> |
</P> |
| 1592 |
<P> |
<P> |
| 1593 |
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 |
| 1594 |
<i>subject</i>, a length (in bytes) in <i>length</i>, and a starting byte offset |
<i>subject</i>, a length (in bytes) in <i>length</i>, and a starting byte offset |
| 1595 |
in <i>startoffset</i>. In UTF-8 mode, the byte offset must point to the start of |
in <i>startoffset</i>. If this is negative or greater than the length of the |
| 1596 |
a UTF-8 character. Unlike the pattern string, the subject may contain binary |
subject, <b>pcre_exec()</b> returns PCRE_ERROR_BADOFFSET. When the starting |
| 1597 |
zero bytes. When the starting offset is zero, the search for a match starts at |
offset is zero, the search for a match starts at the beginning of the subject, |
| 1598 |
the beginning of the subject, and this is by far the most common case. |
and this is by far the most common case. In UTF-8 mode, the byte offset must |
| 1599 |
|
point to the start of a UTF-8 character (or the end of the subject). Unlike the |
| 1600 |
|
pattern string, the subject may contain binary zero bytes. |
| 1601 |
</P> |
</P> |
| 1602 |
<P> |
<P> |
| 1603 |
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 |
| 1619 |
behind the starting point to discover that it is preceded by a letter. |
behind the starting point to discover that it is preceded by a letter. |
| 1620 |
</P> |
</P> |
| 1621 |
<P> |
<P> |
| 1622 |
|
Finding all the matches in a subject is tricky when the pattern can match an |
| 1623 |
|
empty string. It is possible to emulate Perl's /g behaviour by first trying the |
| 1624 |
|
match again at the same offset, with the PCRE_NOTEMPTY_ATSTART and |
| 1625 |
|
PCRE_ANCHORED options, and then if that fails, advancing the starting offset |
| 1626 |
|
and trying an ordinary match again. There is some code that demonstrates how to |
| 1627 |
|
do this in the |
| 1628 |
|
<a href="pcredemo.html"><b>pcredemo</b></a> |
| 1629 |
|
sample program. In the most general case, you have to check to see if the |
| 1630 |
|
newline convention recognizes CRLF as a newline, and if so, and the current |
| 1631 |
|
character is CR followed by LF, advance the starting offset by two characters |
| 1632 |
|
instead of one. |
| 1633 |
|
</P> |
| 1634 |
|
<P> |
| 1635 |
If a non-zero starting offset is passed when the pattern is anchored, one |
If a non-zero starting offset is passed when the pattern is anchored, one |
| 1636 |
attempt to match at the given offset is made. This can only succeed if the |
attempt to match at the given offset is made. This can only succeed if the |
| 1637 |
pattern does not require the match to be at the start of the subject. |
pattern does not require the match to be at the start of the subject. |
| 1694 |
advisable to supply an <i>ovector</i>. |
advisable to supply an <i>ovector</i>. |
| 1695 |
</P> |
</P> |
| 1696 |
<P> |
<P> |
| 1697 |
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 |
| 1698 |
subpatterns there are in a compiled pattern. The smallest size for |
subpatterns there are in a compiled pattern. The smallest size for |
| 1699 |
<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 |
| 1700 |
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. |
| 1712 |
expression are also set to -1. For example, if the string "abc" is matched |
expression are also set to -1. For example, if the string "abc" is matched |
| 1713 |
against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not matched. The |
against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not matched. The |
| 1714 |
return from the function is 2, because the highest used capturing subpattern |
return from the function is 2, because the highest used capturing subpattern |
| 1715 |
number is 1. However, you can refer to the offsets for the second and third |
number is 1, and the offsets for for the second and third capturing subpatterns |
| 1716 |
capturing subpatterns if you wish (assuming the vector is large enough, of |
(assuming the vector is large enough, of course) are set to -1. |
| 1717 |
course). |
</P> |
| 1718 |
|
<P> |
| 1719 |
|
<b>Note</b>: Elements of <i>ovector</i> that do not correspond to capturing |
| 1720 |
|
parentheses in the pattern are never changed. That is, if a pattern contains |
| 1721 |
|
<i>n</i> capturing parentheses, no more than <i>ovector[0]</i> to |
| 1722 |
|
<i>ovector[2n+1]</i> are set by <b>pcre_exec()</b>. The other elements retain |
| 1723 |
|
whatever values they previously had. |
| 1724 |
</P> |
</P> |
| 1725 |
<P> |
<P> |
| 1726 |
Some convenience functions are provided for extracting the captured substrings |
Some convenience functions are provided for extracting the captured substrings |
| 1767 |
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 |
| 1768 |
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 |
| 1769 |
automatically freed at the end of matching. |
automatically freed at the end of matching. |
| 1770 |
|
</P> |
| 1771 |
|
<P> |
| 1772 |
|
This error is also given if <b>pcre_stack_malloc()</b> fails in |
| 1773 |
|
<b>pcre_exec()</b>. This can happen only when PCRE has been compiled with |
| 1774 |
|
<b>--disable-stack-for-recursion</b>. |
| 1775 |
<pre> |
<pre> |
| 1776 |
PCRE_ERROR_NOSUBSTRING (-7) |
PCRE_ERROR_NOSUBSTRING (-7) |
| 1777 |
</pre> |
</pre> |
| 1794 |
<pre> |
<pre> |
| 1795 |
PCRE_ERROR_BADUTF8 (-10) |
PCRE_ERROR_BADUTF8 (-10) |
| 1796 |
</pre> |
</pre> |
| 1797 |
A string that contains an invalid UTF-8 byte sequence was passed as a subject. |
A string that contains an invalid UTF-8 byte sequence was passed as a subject, |
| 1798 |
|
and the PCRE_NO_UTF8_CHECK option was not set. If the size of the output vector |
| 1799 |
|
(<i>ovecsize</i>) is at least 2, the byte offset to the start of the the invalid |
| 1800 |
|
UTF-8 character is placed in the first element, and a reason code is placed in |
| 1801 |
|
the second element. The reason codes are listed in the |
| 1802 |
|
<a href="#badutf8reasons">following section.</a> |
| 1803 |
|
For backward compatibility, if PCRE_PARTIAL_HARD is set and the problem is a |
| 1804 |
|
truncated UTF-8 character at the end of the subject (reason codes 1 to 5), |
| 1805 |
|
PCRE_ERROR_SHORTUTF8 is returned instead of PCRE_ERROR_BADUTF8. |
| 1806 |
<pre> |
<pre> |
| 1807 |
PCRE_ERROR_BADUTF8_OFFSET (-11) |
PCRE_ERROR_BADUTF8_OFFSET (-11) |
| 1808 |
</pre> |
</pre> |
| 1809 |
The UTF-8 byte sequence that was passed as a subject was valid, but the value |
The UTF-8 byte sequence that was passed as a subject was checked and found to |
| 1810 |
of <i>startoffset</i> did not point to the beginning of a UTF-8 character. |
be valid (the PCRE_NO_UTF8_CHECK option was not set), but the value of |
| 1811 |
|
<i>startoffset</i> did not point to the beginning of a UTF-8 character or the |
| 1812 |
|
end of the subject. |
| 1813 |
<pre> |
<pre> |
| 1814 |
PCRE_ERROR_PARTIAL (-12) |
PCRE_ERROR_PARTIAL (-12) |
| 1815 |
</pre> |
</pre> |
| 1819 |
<pre> |
<pre> |
| 1820 |
PCRE_ERROR_BADPARTIAL (-13) |
PCRE_ERROR_BADPARTIAL (-13) |
| 1821 |
</pre> |
</pre> |
| 1822 |
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 |
| 1823 |
are not supported for partial matching. See the |
option was used with a compiled pattern containing items that were not |
| 1824 |
<a href="pcrepartial.html"><b>pcrepartial</b></a> |
supported for partial matching. From release 8.00 onwards, there are no |
| 1825 |
documentation for details of partial matching. |
restrictions on partial matching. |
| 1826 |
<pre> |
<pre> |
| 1827 |
PCRE_ERROR_INTERNAL (-14) |
PCRE_ERROR_INTERNAL (-14) |
| 1828 |
</pre> |
</pre> |
| 1842 |
PCRE_ERROR_BADNEWLINE (-23) |
PCRE_ERROR_BADNEWLINE (-23) |
| 1843 |
</pre> |
</pre> |
| 1844 |
An invalid combination of PCRE_NEWLINE_<i>xxx</i> options was given. |
An invalid combination of PCRE_NEWLINE_<i>xxx</i> options was given. |
| 1845 |
|
<pre> |
| 1846 |
|
PCRE_ERROR_BADOFFSET (-24) |
| 1847 |
|
</pre> |
| 1848 |
|
The value of <i>startoffset</i> was negative or greater than the length of the |
| 1849 |
|
subject, that is, the value in <i>length</i>. |
| 1850 |
|
<pre> |
| 1851 |
|
PCRE_ERROR_SHORTUTF8 (-25) |
| 1852 |
|
</pre> |
| 1853 |
|
This error is returned instead of PCRE_ERROR_BADUTF8 when the subject string |
| 1854 |
|
ends with a truncated UTF-8 character and the PCRE_PARTIAL_HARD option is set. |
| 1855 |
|
Information about the failure is returned as for PCRE_ERROR_BADUTF8. It is in |
| 1856 |
|
fact sufficient to detect this case, but this special error code for |
| 1857 |
|
PCRE_PARTIAL_HARD precedes the implementation of returned information; it is |
| 1858 |
|
retained for backwards compatibility. |
| 1859 |
|
<pre> |
| 1860 |
|
PCRE_ERROR_RECURSELOOP (-26) |
| 1861 |
|
</pre> |
| 1862 |
|
This error is returned when <b>pcre_exec()</b> detects a recursion loop within |
| 1863 |
|
the pattern. Specifically, it means that either the whole pattern or a |
| 1864 |
|
subpattern has been called recursively for the second time at the same position |
| 1865 |
|
in the subject string. Some simple patterns that might do this are detected and |
| 1866 |
|
faulted at compile time, but more complicated cases, in particular mutual |
| 1867 |
|
recursions between two different subpatterns, cannot be detected until run |
| 1868 |
|
time. |
| 1869 |
</P> |
</P> |
| 1870 |
<P> |
<P> |
| 1871 |
Error numbers -16 to -20 and -22 are not used by <b>pcre_exec()</b>. |
Error numbers -16 to -20 and -22 are not used by <b>pcre_exec()</b>. |
| 1872 |
|
<a name="badutf8reasons"></a></P> |
| 1873 |
|
<br><b> |
| 1874 |
|
Reason codes for invalid UTF-8 strings |
| 1875 |
|
</b><br> |
| 1876 |
|
<P> |
| 1877 |
|
When <b>pcre_exec()</b> returns either PCRE_ERROR_BADUTF8 or |
| 1878 |
|
PCRE_ERROR_SHORTUTF8, and the size of the output vector (<i>ovecsize</i>) is at |
| 1879 |
|
least 2, the offset of the start of the invalid UTF-8 character is placed in |
| 1880 |
|
the first output vector element (<i>ovector[0]</i>) and a reason code is placed |
| 1881 |
|
in the second element (<i>ovector[1]</i>). The reason codes are given names in |
| 1882 |
|
the <b>pcre.h</b> header file: |
| 1883 |
|
<pre> |
| 1884 |
|
PCRE_UTF8_ERR1 |
| 1885 |
|
PCRE_UTF8_ERR2 |
| 1886 |
|
PCRE_UTF8_ERR3 |
| 1887 |
|
PCRE_UTF8_ERR4 |
| 1888 |
|
PCRE_UTF8_ERR5 |
| 1889 |
|
</pre> |
| 1890 |
|
The string ends with a truncated UTF-8 character; the code specifies how many |
| 1891 |
|
bytes are missing (1 to 5). Although RFC 3629 restricts UTF-8 characters to be |
| 1892 |
|
no longer than 4 bytes, the encoding scheme (originally defined by RFC 2279) |
| 1893 |
|
allows for up to 6 bytes, and this is checked first; hence the possibility of |
| 1894 |
|
4 or 5 missing bytes. |
| 1895 |
|
<pre> |
| 1896 |
|
PCRE_UTF8_ERR6 |
| 1897 |
|
PCRE_UTF8_ERR7 |
| 1898 |
|
PCRE_UTF8_ERR8 |
| 1899 |
|
PCRE_UTF8_ERR9 |
| 1900 |
|
PCRE_UTF8_ERR10 |
| 1901 |
|
</pre> |
| 1902 |
|
The two most significant bits of the 2nd, 3rd, 4th, 5th, or 6th byte of the |
| 1903 |
|
character do not have the binary value 0b10 (that is, either the most |
| 1904 |
|
significant bit is 0, or the next bit is 1). |
| 1905 |
|
<pre> |
| 1906 |
|
PCRE_UTF8_ERR11 |
| 1907 |
|
PCRE_UTF8_ERR12 |
| 1908 |
|
</pre> |
| 1909 |
|
A character that is valid by the RFC 2279 rules is either 5 or 6 bytes long; |
| 1910 |
|
these code points are excluded by RFC 3629. |
| 1911 |
|
<pre> |
| 1912 |
|
PCRE_UTF8_ERR13 |
| 1913 |
|
</pre> |
| 1914 |
|
A 4-byte character has a value greater than 0x10fff; these code points are |
| 1915 |
|
excluded by RFC 3629. |
| 1916 |
|
<pre> |
| 1917 |
|
PCRE_UTF8_ERR14 |
| 1918 |
|
</pre> |
| 1919 |
|
A 3-byte character has a value in the range 0xd800 to 0xdfff; this range of |
| 1920 |
|
code points are reserved by RFC 3629 for use with UTF-16, and so are excluded |
| 1921 |
|
from UTF-8. |
| 1922 |
|
<pre> |
| 1923 |
|
PCRE_UTF8_ERR15 |
| 1924 |
|
PCRE_UTF8_ERR16 |
| 1925 |
|
PCRE_UTF8_ERR17 |
| 1926 |
|
PCRE_UTF8_ERR18 |
| 1927 |
|
PCRE_UTF8_ERR19 |
| 1928 |
|
</pre> |
| 1929 |
|
A 2-, 3-, 4-, 5-, or 6-byte character is "overlong", that is, it codes for a |
| 1930 |
|
value that can be represented by fewer bytes, which is invalid. For example, |
| 1931 |
|
the two bytes 0xc0, 0xae give the value 0x2e, whose correct coding uses just |
| 1932 |
|
one byte. |
| 1933 |
|
<pre> |
| 1934 |
|
PCRE_UTF8_ERR20 |
| 1935 |
|
</pre> |
| 1936 |
|
The two most significant bits of the first byte of a character have the binary |
| 1937 |
|
value 0b10 (that is, the most significant bit is 1 and the second is 0). Such a |
| 1938 |
|
byte can only validly occur as the second or subsequent byte of a multi-byte |
| 1939 |
|
character. |
| 1940 |
|
<pre> |
| 1941 |
|
PCRE_UTF8_ERR21 |
| 1942 |
|
</pre> |
| 1943 |
|
The first byte of a character has the value 0xfe or 0xff. These values can |
| 1944 |
|
never occur in a valid UTF-8 string. |
| 1945 |
</P> |
</P> |
| 1946 |
<br><a name="SEC15" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a><br> |
<br><a name="SEC15" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a><br> |
| 1947 |
<P> |
<P> |
| 2091 |
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, |
| 2092 |
the behaviour may not be what you want (see the next section). |
the behaviour may not be what you want (see the next section). |
| 2093 |
</P> |
</P> |
| 2094 |
|
<P> |
| 2095 |
|
<b>Warning:</b> If the pattern uses the (?| feature to set up multiple |
| 2096 |
|
subpatterns with the same number, as described in the |
| 2097 |
|
<a href="pcrepattern.html#dupsubpatternnumber">section on duplicate subpattern numbers</a> |
| 2098 |
|
in the |
| 2099 |
|
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
| 2100 |
|
page, you cannot use names to distinguish the different subpatterns, because |
| 2101 |
|
names are not included in the compiled code. The matching process uses only |
| 2102 |
|
numbers. For this reason, the use of different names for subpatterns of the |
| 2103 |
|
same number causes an error at compile time. |
| 2104 |
|
</P> |
| 2105 |
<br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br> |
<br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br> |
| 2106 |
<P> |
<P> |
| 2107 |
<b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b> |
<b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b> |
| 2109 |
</P> |
</P> |
| 2110 |
<P> |
<P> |
| 2111 |
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 |
| 2112 |
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 |
| 2113 |
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 |
| 2114 |
example is shown in the |
such subpatterns are named, they are required to use the same names.) |
| 2115 |
|
</P> |
| 2116 |
|
<P> |
| 2117 |
|
Normally, patterns with duplicate names are such that in any one match, only |
| 2118 |
|
one of the named subpatterns participates. An example is shown in the |
| 2119 |
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
| 2120 |
documentation. |
documentation. |
| 2121 |
</P> |
</P> |
| 2135 |
has run, they point to the first and last entries in the name-to-number table |
has run, they point to the first and last entries in the name-to-number table |
| 2136 |
for the given name. The function itself returns the length of each entry, or |
for the given name. The function itself returns the length of each entry, or |
| 2137 |
PCRE_ERROR_NOSUBSTRING (-7) if there are none. The format of the table is |
PCRE_ERROR_NOSUBSTRING (-7) if there are none. The format of the table is |
| 2138 |
described above in the section entitled <i>Information about a pattern</i>. |
described above in the section entitled <i>Information about a pattern</i> |
| 2139 |
|
<a href="#infoaboutpattern">above.</a> |
| 2140 |
Given all the relevant entries for the name, you can extract each of their |
Given all the relevant entries for the name, you can extract each of their |
| 2141 |
numbers, and hence the captured data, if any. |
numbers, and hence the captured data, if any. |
| 2142 |
</P> |
</P> |
| 2172 |
just once, and does not backtrack. This has different characteristics to the |
just once, and does not backtrack. This has different characteristics to the |
| 2173 |
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 |
| 2174 |
patterns are not supported. Nevertheless, there are times when this kind of |
patterns are not supported. Nevertheless, there are times when this kind of |
| 2175 |
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 |
| 2176 |
the |
list of features that <b>pcre_dfa_exec()</b> does not support, see the |
| 2177 |
<a href="pcrematching.html"><b>pcrematching</b></a> |
<a href="pcrematching.html"><b>pcrematching</b></a> |
| 2178 |
documentation. |
documentation. |
| 2179 |
</P> |
</P> |
| 2215 |
<P> |
<P> |
| 2216 |
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 |
| 2217 |
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>, |
| 2218 |
PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL, |
PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART, |
| 2219 |
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, |
| 2220 |
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. |
| 2221 |
<pre> |
All but the last four of these are exactly the same as for <b>pcre_exec()</b>, |
| 2222 |
PCRE_PARTIAL |
so their description is not repeated here. |
| 2223 |
</pre> |
<pre> |
| 2224 |
This has the same general effect as it does for <b>pcre_exec()</b>, but the |
PCRE_PARTIAL_HARD |
| 2225 |
details are slightly different. When PCRE_PARTIAL is set for |
PCRE_PARTIAL_SOFT |
| 2226 |
<b>pcre_dfa_exec()</b>, the return code PCRE_ERROR_NOMATCH is converted into |
</pre> |
| 2227 |
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 |
| 2228 |
complete matches, but there is still at least one matching possibility. The |
details are slightly different. When PCRE_PARTIAL_HARD is set for |
| 2229 |
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 |
| 2230 |
matching string. |
is reached and there is still at least one matching possibility that requires |
| 2231 |
|
additional characters. This happens even if some complete matches have also |
| 2232 |
|
been found. When PCRE_PARTIAL_SOFT is set, the return code PCRE_ERROR_NOMATCH |
| 2233 |
|
is converted into PCRE_ERROR_PARTIAL if the end of the subject is reached, |
| 2234 |
|
there have been no complete matches, but there is still at least one matching |
| 2235 |
|
possibility. The portion of the string that was inspected when the longest |
| 2236 |
|
partial match was found is set as the first matching string in both cases. |
| 2237 |
|
There is a more detailed discussion of partial and multi-segment matching, with |
| 2238 |
|
examples, in the |
| 2239 |
|
<a href="pcrepartial.html"><b>pcrepartial</b></a> |
| 2240 |
|
documentation. |
| 2241 |
<pre> |
<pre> |
| 2242 |
PCRE_DFA_SHORTEST |
PCRE_DFA_SHORTEST |
| 2243 |
</pre> |
</pre> |
| 2248 |
<pre> |
<pre> |
| 2249 |
PCRE_DFA_RESTART |
PCRE_DFA_RESTART |
| 2250 |
</pre> |
</pre> |
| 2251 |
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 |
| 2252 |
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 |
| 2253 |
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 |
| 2254 |
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 |
| 2255 |
<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 |
| 2256 |
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 |
|
| 2257 |
<a href="pcrepartial.html"><b>pcrepartial</b></a> |
<a href="pcrepartial.html"><b>pcrepartial</b></a> |
| 2258 |
documentation. |
documentation. |
| 2259 |
</P> |
</P> |
| 2349 |
</P> |
</P> |
| 2350 |
<br><a name="SEC22" href="#TOC1">REVISION</a><br> |
<br><a name="SEC22" href="#TOC1">REVISION</a><br> |
| 2351 |
<P> |
<P> |
| 2352 |
Last updated: 24 August 2008 |
Last updated: 13 August 2011 |
| 2353 |
<br> |
<br> |
| 2354 |
Copyright © 1997-2008 University of Cambridge. |
Copyright © 1997-2011 University of Cambridge. |
| 2355 |
<br> |
<br> |
| 2356 |
<p> |
<p> |
| 2357 |
Return to the <a href="index.html">PCRE index page</a>. |
Return to the <a href="index.html">PCRE index page</a>. |