| 15 |
<ul> |
<ul> |
| 16 |
<li><a name="TOC1" href="#SEC1">PCRE NATIVE API</a> |
<li><a name="TOC1" href="#SEC1">PCRE NATIVE API</a> |
| 17 |
<li><a name="TOC2" href="#SEC2">PCRE API OVERVIEW</a> |
<li><a name="TOC2" href="#SEC2">PCRE API OVERVIEW</a> |
| 18 |
<li><a name="TOC3" href="#SEC3">MULTITHREADING</a> |
<li><a name="TOC3" href="#SEC3">NEWLINES</a> |
| 19 |
<li><a name="TOC4" href="#SEC4">SAVING PRECOMPILED PATTERNS FOR LATER USE</a> |
<li><a name="TOC4" href="#SEC4">MULTITHREADING</a> |
| 20 |
<li><a name="TOC5" href="#SEC5">CHECKING BUILD-TIME OPTIONS</a> |
<li><a name="TOC5" href="#SEC5">SAVING PRECOMPILED PATTERNS FOR LATER USE</a> |
| 21 |
<li><a name="TOC6" href="#SEC6">COMPILING A PATTERN</a> |
<li><a name="TOC6" href="#SEC6">CHECKING BUILD-TIME OPTIONS</a> |
| 22 |
<li><a name="TOC7" href="#SEC7">COMPILATION ERROR CODES</a> |
<li><a name="TOC7" href="#SEC7">COMPILING A PATTERN</a> |
| 23 |
<li><a name="TOC8" href="#SEC8">STUDYING A PATTERN</a> |
<li><a name="TOC8" href="#SEC8">COMPILATION ERROR CODES</a> |
| 24 |
<li><a name="TOC9" href="#SEC9">LOCALE SUPPORT</a> |
<li><a name="TOC9" href="#SEC9">STUDYING A PATTERN</a> |
| 25 |
<li><a name="TOC10" href="#SEC10">INFORMATION ABOUT A PATTERN</a> |
<li><a name="TOC10" href="#SEC10">LOCALE SUPPORT</a> |
| 26 |
<li><a name="TOC11" href="#SEC11">OBSOLETE INFO FUNCTION</a> |
<li><a name="TOC11" href="#SEC11">INFORMATION ABOUT A PATTERN</a> |
| 27 |
<li><a name="TOC12" href="#SEC12">REFERENCE COUNTS</a> |
<li><a name="TOC12" href="#SEC12">OBSOLETE INFO FUNCTION</a> |
| 28 |
<li><a name="TOC13" href="#SEC13">MATCHING A PATTERN: THE TRADITIONAL FUNCTION</a> |
<li><a name="TOC13" href="#SEC13">REFERENCE COUNTS</a> |
| 29 |
<li><a name="TOC14" href="#SEC14">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a> |
<li><a name="TOC14" href="#SEC14">MATCHING A PATTERN: THE TRADITIONAL FUNCTION</a> |
| 30 |
<li><a name="TOC15" href="#SEC15">EXTRACTING CAPTURED SUBSTRINGS BY NAME</a> |
<li><a name="TOC15" href="#SEC15">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a> |
| 31 |
<li><a name="TOC16" href="#SEC16">FINDING ALL POSSIBLE MATCHES</a> |
<li><a name="TOC16" href="#SEC16">EXTRACTING CAPTURED SUBSTRINGS BY NAME</a> |
| 32 |
<li><a name="TOC17" href="#SEC17">MATCHING A PATTERN: THE ALTERNATIVE FUNCTION</a> |
<li><a name="TOC17" href="#SEC17">DUPLICATE SUBPATTERN NAMES</a> |
| 33 |
|
<li><a name="TOC18" href="#SEC18">FINDING ALL POSSIBLE MATCHES</a> |
| 34 |
|
<li><a name="TOC19" href="#SEC19">MATCHING A PATTERN: THE ALTERNATIVE FUNCTION</a> |
| 35 |
</ul> |
</ul> |
| 36 |
<br><a name="SEC1" href="#TOC1">PCRE NATIVE API</a><br> |
<br><a name="SEC1" href="#TOC1">PCRE NATIVE API</a><br> |
| 37 |
<P> |
<P> |
| 85 |
<b>const char *<i>name</i>);</b> |
<b>const char *<i>name</i>);</b> |
| 86 |
</P> |
</P> |
| 87 |
<P> |
<P> |
| 88 |
|
<b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b> |
| 89 |
|
<b>const char *<i>name</i>, char **<i>first</i>, char **<i>last</i>);</b> |
| 90 |
|
</P> |
| 91 |
|
<P> |
| 92 |
<b>int pcre_get_substring(const char *<i>subject</i>, int *<i>ovector</i>,</b> |
<b>int pcre_get_substring(const char *<i>subject</i>, int *<i>ovector</i>,</b> |
| 93 |
<b>int <i>stringcount</i>, int <i>stringnumber</i>,</b> |
<b>int <i>stringcount</i>, int <i>stringnumber</i>,</b> |
| 94 |
<b>const char **<i>stringptr</i>);</b> |
<b>const char **<i>stringptr</i>);</b> |
| 169 |
<P> |
<P> |
| 170 |
A second matching function, <b>pcre_dfa_exec()</b>, which is not |
A second matching function, <b>pcre_dfa_exec()</b>, which is not |
| 171 |
Perl-compatible, is also provided. This uses a different algorithm for the |
Perl-compatible, is also provided. This uses a different algorithm for the |
| 172 |
matching. This allows it to find all possible matches (at a given point in the |
matching. The alternative algorithm finds all possible matches (at a given |
| 173 |
subject), not just one. However, this algorithm does not return captured |
point in the subject). However, this algorithm does not return captured |
| 174 |
substrings. A description of the two matching algorithms and their advantages |
substrings. A description of the two matching algorithms and their advantages |
| 175 |
and disadvantages is given in the |
and disadvantages is given in the |
| 176 |
<a href="pcrematching.html"><b>pcrematching</b></a> |
<a href="pcrematching.html"><b>pcrematching</b></a> |
| 187 |
<b>pcre_get_named_substring()</b> |
<b>pcre_get_named_substring()</b> |
| 188 |
<b>pcre_get_substring_list()</b> |
<b>pcre_get_substring_list()</b> |
| 189 |
<b>pcre_get_stringnumber()</b> |
<b>pcre_get_stringnumber()</b> |
| 190 |
|
<b>pcre_get_stringtable_entries()</b> |
| 191 |
</pre> |
</pre> |
| 192 |
<b>pcre_free_substring()</b> and <b>pcre_free_substring_list()</b> are also |
<b>pcre_free_substring()</b> and <b>pcre_free_substring_list()</b> are also |
| 193 |
provided, to free the memory used for extracted strings. |
provided, to free the memory used for extracted strings. |
| 222 |
The global variables <b>pcre_stack_malloc</b> and <b>pcre_stack_free</b> are also |
The global variables <b>pcre_stack_malloc</b> and <b>pcre_stack_free</b> are also |
| 223 |
indirections to memory management functions. These special functions are used |
indirections to memory management functions. These special functions are used |
| 224 |
only when PCRE is compiled to use the heap for remembering data, instead of |
only when PCRE is compiled to use the heap for remembering data, instead of |
| 225 |
recursive function calls, when running the <b>pcre_exec()</b> function. This is |
recursive function calls, when running the <b>pcre_exec()</b> function. See the |
| 226 |
a non-standard way of building PCRE, for use in environments that have limited |
<a href="pcrebuild.html"><b>pcrebuild</b></a> |
| 227 |
stacks. Because of the greater use of memory management, it runs more slowly. |
documentation for details of how to do this. It is a non-standard way of |
| 228 |
Separate functions are provided so that special-purpose external code can be |
building PCRE, for use in environments that have limited stacks. Because of the |
| 229 |
used for this case. When used, these functions are always called in a |
greater use of memory management, it runs more slowly. Separate functions are |
| 230 |
stack-like manner (last obtained, first freed), and always for memory blocks of |
provided so that special-purpose external code can be used for this case. When |
| 231 |
the same size. |
used, these functions are always called in a stack-like manner (last obtained, |
| 232 |
|
first freed), and always for memory blocks of the same size. There is a |
| 233 |
|
discussion about PCRE's stack usage in the |
| 234 |
|
<a href="pcrestack.html"><b>pcrestack</b></a> |
| 235 |
|
documentation. |
| 236 |
</P> |
</P> |
| 237 |
<P> |
<P> |
| 238 |
The global variable <b>pcre_callout</b> initially contains NULL. It can be set |
The global variable <b>pcre_callout</b> initially contains NULL. It can be set |
| 241 |
<a href="pcrecallout.html"><b>pcrecallout</b></a> |
<a href="pcrecallout.html"><b>pcrecallout</b></a> |
| 242 |
documentation. |
documentation. |
| 243 |
</P> |
</P> |
| 244 |
<br><a name="SEC3" href="#TOC1">MULTITHREADING</a><br> |
<br><a name="SEC3" href="#TOC1">NEWLINES</a><br> |
| 245 |
|
<P> |
| 246 |
|
PCRE supports three different conventions for indicating line breaks in |
| 247 |
|
strings: a single CR character, a single LF character, or the two-character |
| 248 |
|
sequence CRLF. All three are used as "standard" by different operating systems. |
| 249 |
|
When PCRE is built, a default can be specified. The default default is LF, |
| 250 |
|
which is the Unix standard. When PCRE is run, the default can be overridden, |
| 251 |
|
either when a pattern is compiled, or when it is matched. |
| 252 |
|
<br> |
| 253 |
|
<br> |
| 254 |
|
In the PCRE documentation the word "newline" is used to mean "the character or |
| 255 |
|
pair of characters that indicate a line break". |
| 256 |
|
</P> |
| 257 |
|
<br><a name="SEC4" href="#TOC1">MULTITHREADING</a><br> |
| 258 |
<P> |
<P> |
| 259 |
The PCRE functions can be used in multi-threading applications, with the |
The PCRE functions can be used in multi-threading applications, with the |
| 260 |
proviso that the memory management functions pointed to by <b>pcre_malloc</b>, |
proviso that the memory management functions pointed to by <b>pcre_malloc</b>, |
| 265 |
The compiled form of a regular expression is not altered during matching, so |
The compiled form of a regular expression is not altered during matching, so |
| 266 |
the same compiled pattern can safely be used by several threads at once. |
the same compiled pattern can safely be used by several threads at once. |
| 267 |
</P> |
</P> |
| 268 |
<br><a name="SEC4" href="#TOC1">SAVING PRECOMPILED PATTERNS FOR LATER USE</a><br> |
<br><a name="SEC5" href="#TOC1">SAVING PRECOMPILED PATTERNS FOR LATER USE</a><br> |
| 269 |
<P> |
<P> |
| 270 |
The compiled form of a regular expression can be saved and re-used at a later |
The compiled form of a regular expression can be saved and re-used at a later |
| 271 |
time, possibly by a different program, and even on a host other than the one on |
time, possibly by a different program, and even on a host other than the one on |
| 273 |
<a href="pcreprecompile.html"><b>pcreprecompile</b></a> |
<a href="pcreprecompile.html"><b>pcreprecompile</b></a> |
| 274 |
documentation. |
documentation. |
| 275 |
</P> |
</P> |
| 276 |
<br><a name="SEC5" href="#TOC1">CHECKING BUILD-TIME OPTIONS</a><br> |
<br><a name="SEC6" href="#TOC1">CHECKING BUILD-TIME OPTIONS</a><br> |
| 277 |
<P> |
<P> |
| 278 |
<b>int pcre_config(int <i>what</i>, void *<i>where</i>);</b> |
<b>int pcre_config(int <i>what</i>, void *<i>where</i>);</b> |
| 279 |
</P> |
</P> |
| 300 |
<pre> |
<pre> |
| 301 |
PCRE_CONFIG_NEWLINE |
PCRE_CONFIG_NEWLINE |
| 302 |
</pre> |
</pre> |
| 303 |
The output is an integer that is set to the value of the code that is used for |
The output is an integer whose value specifies the default character sequence |
| 304 |
the newline character. It is either linefeed (10) or carriage return (13), and |
that is recognized as meaning "newline". The three values that are supported |
| 305 |
should normally be the standard character for your operating system. |
are: 10 for LF, 13 for CR, and 3338 for CRLF. The default should normally be |
| 306 |
|
the standard sequence for your operating system. |
| 307 |
<pre> |
<pre> |
| 308 |
PCRE_CONFIG_LINK_SIZE |
PCRE_CONFIG_LINK_SIZE |
| 309 |
</pre> |
</pre> |
| 343 |
<b>pcre_stack_free</b> are called to manage memory blocks on the heap, thus |
<b>pcre_stack_free</b> are called to manage memory blocks on the heap, thus |
| 344 |
avoiding the use of the stack. |
avoiding the use of the stack. |
| 345 |
</P> |
</P> |
| 346 |
<br><a name="SEC6" href="#TOC1">COMPILING A PATTERN</a><br> |
<br><a name="SEC7" href="#TOC1">COMPILING A PATTERN</a><br> |
| 347 |
<P> |
<P> |
| 348 |
<b>pcre *pcre_compile(const char *<i>pattern</i>, int <i>options</i>,</b> |
<b>pcre *pcre_compile(const char *<i>pattern</i>, int <i>options</i>,</b> |
| 349 |
<b>const char **<i>errptr</i>, int *<i>erroffset</i>,</b> |
<b>const char **<i>errptr</i>, int *<i>erroffset</i>,</b> |
| 365 |
via <b>pcre_malloc</b> is returned. This contains the compiled code and related |
via <b>pcre_malloc</b> is returned. This contains the compiled code and related |
| 366 |
data. The <b>pcre</b> type is defined for the returned block; this is a typedef |
data. The <b>pcre</b> type is defined for the returned block; this is a typedef |
| 367 |
for a structure whose contents are not externally defined. It is up to the |
for a structure whose contents are not externally defined. It is up to the |
| 368 |
caller to free the memory when it is no longer required. |
caller to free the memory (via <b>pcre_free</b>) when it is no longer required. |
| 369 |
</P> |
</P> |
| 370 |
<P> |
<P> |
| 371 |
Although the compiled code of a PCRE regex is relocatable, that is, it does not |
Although the compiled code of a PCRE regex is relocatable, that is, it does not |
| 382 |
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
| 383 |
documentation). For these options, the contents of the <i>options</i> argument |
documentation). For these options, the contents of the <i>options</i> argument |
| 384 |
specifies their initial settings at the start of compilation and execution. The |
specifies their initial settings at the start of compilation and execution. The |
| 385 |
PCRE_ANCHORED option can be set at the time of matching as well as at compile |
PCRE_ANCHORED and PCRE_NEWLINE_<i>xxx</i> options can be set at the time of |
| 386 |
time. |
matching as well as at compile time. |
| 387 |
</P> |
</P> |
| 388 |
<P> |
<P> |
| 389 |
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. |
| 456 |
</pre> |
</pre> |
| 457 |
If this bit is set, a dollar metacharacter in the pattern matches only at the |
If this bit is set, a dollar metacharacter in the pattern matches only at the |
| 458 |
end of the subject string. Without this option, a dollar also matches |
end of the subject string. Without this option, a dollar also matches |
| 459 |
immediately before the final character if it is a newline (but not before any |
immediately before a newline at the end of the string (but not before any other |
| 460 |
other newlines). The PCRE_DOLLAR_ENDONLY option is ignored if PCRE_MULTILINE is |
newlines). The PCRE_DOLLAR_ENDONLY option is ignored if PCRE_MULTILINE is set. |
| 461 |
set. There is no equivalent to this option in Perl, and no way to set it within |
There is no equivalent to this option in Perl, and no way to set it within a |
| 462 |
a pattern. |
pattern. |
| 463 |
<pre> |
<pre> |
| 464 |
PCRE_DOTALL |
PCRE_DOTALL |
| 465 |
</pre> |
</pre> |
| 466 |
If this bit is set, a dot metacharater in the pattern matches all characters, |
If this bit is set, a dot metacharater in the pattern matches all characters, |
| 467 |
including newlines. Without it, newlines are excluded. This option is |
including those that indicate newline. Without it, a dot does not match when |
| 468 |
equivalent to Perl's /s option, and it can be changed within a pattern by a |
the current position is at a newline. This option is equivalent to Perl's /s |
| 469 |
(?s) option setting. A negative class such as [^a] always matches a newline |
option, and it can be changed within a pattern by a (?s) option setting. A |
| 470 |
character, independent of the setting of this option. |
negative class such as [^a] always matches newlines, independent of the setting |
| 471 |
|
of this option. |
| 472 |
|
<pre> |
| 473 |
|
PCRE_DUPNAMES |
| 474 |
|
</pre> |
| 475 |
|
If this bit is set, names used to identify capturing subpatterns need not be |
| 476 |
|
unique. This can be helpful for certain types of pattern when it is known that |
| 477 |
|
only one instance of the named subpattern can ever be matched. There are more |
| 478 |
|
details of named subpatterns below; see also the |
| 479 |
|
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
| 480 |
|
documentation. |
| 481 |
<pre> |
<pre> |
| 482 |
PCRE_EXTENDED |
PCRE_EXTENDED |
| 483 |
</pre> |
</pre> |
| 484 |
If this bit is set, whitespace data characters in the pattern are totally |
If this bit is set, whitespace data characters in the pattern are totally |
| 485 |
ignored except when escaped or inside a character class. Whitespace does not |
ignored except when escaped or inside a character class. Whitespace does not |
| 486 |
include the VT character (code 11). In addition, characters between an |
include the VT character (code 11). In addition, characters between an |
| 487 |
unescaped # outside a character class and the next newline character, |
unescaped # outside a character class and the next newline, inclusive, are also |
| 488 |
inclusive, are also ignored. This is equivalent to Perl's /x option, and it can |
ignored. This is equivalent to Perl's /x option, and it can be changed within a |
| 489 |
be changed within a pattern by a (?x) option setting. |
pattern by a (?x) option setting. |
| 490 |
</P> |
</P> |
| 491 |
<P> |
<P> |
| 492 |
This option makes it possible to include comments inside complicated patterns. |
This option makes it possible to include comments inside complicated patterns. |
| 501 |
set, any backslash in a pattern that is followed by a letter that has no |
set, any backslash in a pattern that is followed by a letter that has no |
| 502 |
special meaning causes an error, thus reserving these combinations for future |
special meaning causes an error, thus reserving these combinations for future |
| 503 |
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 |
| 504 |
special meaning is treated as a literal. There are at present no other features |
special meaning is treated as a literal. (Perl can, however, be persuaded to |
| 505 |
controlled by this option. It can also be set by a (?X) option setting within a |
give a warning for this.) There are at present no other features controlled by |
| 506 |
pattern. |
this option. It can also be set by a (?X) option setting within a pattern. |
| 507 |
<pre> |
<pre> |
| 508 |
PCRE_FIRSTLINE |
PCRE_FIRSTLINE |
| 509 |
</pre> |
</pre> |
| 510 |
If this option is set, an unanchored pattern is required to match before or at |
If this option is set, an unanchored pattern is required to match before or at |
| 511 |
the first newline character in the subject string, though the matched text may |
the first newline in the subject string, though the matched text may continue |
| 512 |
continue over the newline. |
over the newline. |
| 513 |
<pre> |
<pre> |
| 514 |
PCRE_MULTILINE |
PCRE_MULTILINE |
| 515 |
</pre> |
</pre> |
| 522 |
</P> |
</P> |
| 523 |
<P> |
<P> |
| 524 |
When PCRE_MULTILINE it is set, the "start of line" and "end of line" constructs |
When PCRE_MULTILINE it is set, the "start of line" and "end of line" constructs |
| 525 |
match immediately following or immediately before any newline in the subject |
match immediately following or immediately before internal newlines in the |
| 526 |
string, respectively, as well as at the very start and end. This is equivalent |
subject string, respectively, as well as at the very start and end. This is |
| 527 |
to Perl's /m option, and it can be changed within a pattern by a (?m) option |
equivalent to Perl's /m option, and it can be changed within a pattern by a |
| 528 |
setting. If there are no "\n" characters in a subject string, or no |
(?m) option setting. If there are no newlines in a subject string, or no |
| 529 |
occurrences of ^ or $ in a pattern, setting PCRE_MULTILINE has no effect. |
occurrences of ^ or $ in a pattern, setting PCRE_MULTILINE has no effect. |
| 530 |
<pre> |
<pre> |
| 531 |
|
PCRE_NEWLINE_CR |
| 532 |
|
PCRE_NEWLINE_LF |
| 533 |
|
PCRE_NEWLINE_CRLF |
| 534 |
|
</pre> |
| 535 |
|
These options override the default newline definition that was chosen when PCRE |
| 536 |
|
was built. Setting the first or the second specifies that a newline is |
| 537 |
|
indicated by a single character (CR or LF, respectively). Setting both of them |
| 538 |
|
specifies that a newline is indicated by the two-character CRLF sequence. For |
| 539 |
|
convenience, PCRE_NEWLINE_CRLF is defined to contain both bits. The only time |
| 540 |
|
that a line break is relevant when compiling a pattern is if PCRE_EXTENDED is |
| 541 |
|
set, and an unescaped # outside a character class is encountered. This |
| 542 |
|
indicates a comment that lasts until after the next newline. |
| 543 |
|
</P> |
| 544 |
|
<P> |
| 545 |
|
The newline option set at compile time becomes the default that is used for |
| 546 |
|
<b>pcre_exec()</b> and <b>pcre_dfa_exec()</b>, but it can be overridden. |
| 547 |
|
<pre> |
| 548 |
PCRE_NO_AUTO_CAPTURE |
PCRE_NO_AUTO_CAPTURE |
| 549 |
</pre> |
</pre> |
| 550 |
If this option is set, it disables the use of numbered capturing parentheses in |
If this option is set, it disables the use of numbered capturing parentheses in |
| 583 |
<b>pcre_dfa_exec()</b>, to suppress the UTF-8 validity checking of subject |
<b>pcre_dfa_exec()</b>, to suppress the UTF-8 validity checking of subject |
| 584 |
strings. |
strings. |
| 585 |
</P> |
</P> |
| 586 |
<br><a name="SEC7" href="#TOC1">COMPILATION ERROR CODES</a><br> |
<br><a name="SEC8" href="#TOC1">COMPILATION ERROR CODES</a><br> |
| 587 |
<P> |
<P> |
| 588 |
The following table lists the error codes than may be returned by |
The following table lists the error codes than may be returned by |
| 589 |
<b>pcre_compile2()</b>, along with the error messages that may be returned by |
<b>pcre_compile2()</b>, along with the error messages that may be returned by |
| 615 |
23 internal error: code overflow |
23 internal error: code overflow |
| 616 |
24 unrecognized character after (?< |
24 unrecognized character after (?< |
| 617 |
25 lookbehind assertion is not fixed length |
25 lookbehind assertion is not fixed length |
| 618 |
26 malformed number after (?( |
26 malformed number or name after (?( |
| 619 |
27 conditional group contains more than two branches |
27 conditional group contains more than two branches |
| 620 |
28 assertion expected after (?( |
28 assertion expected after (?( |
| 621 |
29 (?R or (?digits must be followed by ) |
29 (?R or (?digits must be followed by ) |
| 632 |
40 recursive call could loop indefinitely |
40 recursive call could loop indefinitely |
| 633 |
41 unrecognized character after (?P |
41 unrecognized character after (?P |
| 634 |
42 syntax error after (?P |
42 syntax error after (?P |
| 635 |
43 two named groups have the same name |
43 two named subpatterns have the same name |
| 636 |
44 invalid UTF-8 string |
44 invalid UTF-8 string |
| 637 |
45 support for \P, \p, and \X has not been compiled |
45 support for \P, \p, and \X has not been compiled |
| 638 |
46 malformed \P or \p sequence |
46 malformed \P or \p sequence |
| 639 |
47 unknown property name after \P or \p |
47 unknown property name after \P or \p |
| 640 |
|
48 subpattern name is too long (maximum 32 characters) |
| 641 |
|
49 too many named subpatterns (maximum 10,000) |
| 642 |
|
50 repeated subpattern is too long |
| 643 |
|
51 octal value is greater than \377 (not in UTF-8 mode) |
| 644 |
</PRE> |
</PRE> |
| 645 |
</P> |
</P> |
| 646 |
<br><a name="SEC8" href="#TOC1">STUDYING A PATTERN</a><br> |
<br><a name="SEC9" href="#TOC1">STUDYING A PATTERN</a><br> |
| 647 |
<P> |
<P> |
| 648 |
<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> |
| 649 |
<b>const char **<i>errptr</i>);</b> |
<b>const char **<i>errptr</i>);</b> |
| 696 |
not have a single fixed starting character. A bitmap of possible starting |
not have a single fixed starting character. A bitmap of possible starting |
| 697 |
bytes is created. |
bytes is created. |
| 698 |
<a name="localesupport"></a></P> |
<a name="localesupport"></a></P> |
| 699 |
<br><a name="SEC9" href="#TOC1">LOCALE SUPPORT</a><br> |
<br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br> |
| 700 |
<P> |
<P> |
| 701 |
PCRE handles caseless matching, and determines whether characters are letters |
PCRE handles caseless matching, and determines whether characters are letters |
| 702 |
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 |
| 744 |
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 |
| 745 |
below in the section on matching a pattern. |
below in the section on matching a pattern. |
| 746 |
</P> |
</P> |
| 747 |
<br><a name="SEC10" href="#TOC1">INFORMATION ABOUT A PATTERN</a><br> |
<br><a name="SEC11" href="#TOC1">INFORMATION ABOUT A PATTERN</a><br> |
| 748 |
<P> |
<P> |
| 749 |
<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> |
| 750 |
<b>int <i>what</i>, void *<i>where</i>);</b> |
<b>int <i>what</i>, void *<i>where</i>);</b> |
| 772 |
<b>pcre_fullinfo()</b>, to obtain the length of the compiled pattern: |
<b>pcre_fullinfo()</b>, to obtain the length of the compiled pattern: |
| 773 |
<pre> |
<pre> |
| 774 |
int rc; |
int rc; |
| 775 |
unsigned long int length; |
size_t length; |
| 776 |
rc = pcre_fullinfo( |
rc = pcre_fullinfo( |
| 777 |
re, /* result of pcre_compile() */ |
re, /* result of pcre_compile() */ |
| 778 |
pe, /* result of pcre_study(), or NULL */ |
pe, /* result of pcre_study(), or NULL */ |
| 804 |
PCRE_INFO_FIRSTBYTE |
PCRE_INFO_FIRSTBYTE |
| 805 |
</pre> |
</pre> |
| 806 |
Return information about the first byte of any matched string, for a |
Return information about the first byte of any matched string, for a |
| 807 |
non-anchored pattern. (This option used to be called PCRE_INFO_FIRSTCHAR; the |
non-anchored pattern. The fourth argument should point to an <b>int</b> |
| 808 |
old name is still recognized for backwards compatibility.) |
variable. (This option used to be called PCRE_INFO_FIRSTCHAR; the old name is |
| 809 |
|
still recognized for backwards compatibility.) |
| 810 |
</P> |
</P> |
| 811 |
<P> |
<P> |
| 812 |
If there is a fixed first byte, for example, from a pattern such as |
If there is a fixed first byte, for example, from a pattern such as |
| 813 |
(cat|cow|coyote), it is returned in the integer pointed to by <i>where</i>. |
(cat|cow|coyote). Otherwise, if either |
|
Otherwise, if either |
|
| 814 |
<br> |
<br> |
| 815 |
<br> |
<br> |
| 816 |
(a) the pattern was compiled with the PCRE_MULTILINE option, and every branch |
(a) the pattern was compiled with the PCRE_MULTILINE option, and every branch |
| 848 |
</pre> |
</pre> |
| 849 |
PCRE supports the use of named as well as numbered capturing parentheses. The |
PCRE supports the use of named as well as numbered capturing parentheses. The |
| 850 |
names are just an additional way of identifying the parentheses, which still |
names are just an additional way of identifying the parentheses, which still |
| 851 |
acquire numbers. A convenience function called <b>pcre_get_named_substring()</b> |
acquire numbers. Several convenience functions such as |
| 852 |
is provided for extracting an individual captured substring by name. It is also |
<b>pcre_get_named_substring()</b> are provided for extracting captured |
| 853 |
possible to extract the data directly, by first converting the name to a number |
substrings by name. It is also possible to extract the data directly, by first |
| 854 |
in order to access the correct pointers in the output vector (described with |
converting the name to a number in order to access the correct pointers in the |
| 855 |
<b>pcre_exec()</b> below). To do the conversion, you need to use the |
output vector (described with <b>pcre_exec()</b> below). To do the conversion, |
| 856 |
name-to-number map, which is described by these three values. |
you need to use the name-to-number map, which is described by these three |
| 857 |
|
values. |
| 858 |
</P> |
</P> |
| 859 |
<P> |
<P> |
| 860 |
The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT gives |
The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT gives |
| 864 |
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 |
| 865 |
are the number of the capturing parenthesis, most significant byte first. The |
are the number of the capturing parenthesis, most significant byte first. The |
| 866 |
rest of the entry is the corresponding name, zero terminated. The names are in |
rest of the entry is the corresponding name, zero terminated. The names are in |
| 867 |
alphabetical order. For example, consider the following pattern (assume |
alphabetical order. When PCRE_DUPNAMES is set, duplicate names are in order of |
| 868 |
|
their parentheses numbers. For example, consider the following pattern (assume |
| 869 |
PCRE_EXTENDED is set, so white space - including newlines - is ignored): |
PCRE_EXTENDED is set, so white space - including newlines - is ignored): |
| 870 |
<pre> |
<pre> |
| 871 |
(?P<date> (?P<year>(\d\d)?\d\d) - (?P<month>\d\d) - (?P<day>\d\d) ) |
(?P<date> (?P<year>(\d\d)?\d\d) - (?P<month>\d\d) - (?P<day>\d\d) ) |
| 880 |
00 02 y e a r 00 ?? |
00 02 y e a r 00 ?? |
| 881 |
</pre> |
</pre> |
| 882 |
When writing code to extract data from named subpatterns using the |
When writing code to extract data from named subpatterns using the |
| 883 |
name-to-number map, remember that the length of each entry is likely to be |
name-to-number map, remember that the length of the entries is likely to be |
| 884 |
different for each compiled pattern. |
different for each compiled pattern. |
| 885 |
<pre> |
<pre> |
| 886 |
PCRE_INFO_OPTIONS |
PCRE_INFO_OPTIONS |
| 917 |
created by <b>pcre_study()</b>. The fourth argument should point to a |
created by <b>pcre_study()</b>. The fourth argument should point to a |
| 918 |
<b>size_t</b> variable. |
<b>size_t</b> variable. |
| 919 |
</P> |
</P> |
| 920 |
<br><a name="SEC11" href="#TOC1">OBSOLETE INFO FUNCTION</a><br> |
<br><a name="SEC12" href="#TOC1">OBSOLETE INFO FUNCTION</a><br> |
| 921 |
<P> |
<P> |
| 922 |
<b>int pcre_info(const pcre *<i>code</i>, int *<i>optptr</i>, int</b> |
<b>int pcre_info(const pcre *<i>code</i>, int *<i>optptr</i>, int</b> |
| 923 |
<b>*<i>firstcharptr</i>);</b> |
<b>*<i>firstcharptr</i>);</b> |
| 941 |
it is used to pass back information about the first character of any matched |
it is used to pass back information about the first character of any matched |
| 942 |
string (see PCRE_INFO_FIRSTBYTE above). |
string (see PCRE_INFO_FIRSTBYTE above). |
| 943 |
</P> |
</P> |
| 944 |
<br><a name="SEC12" href="#TOC1">REFERENCE COUNTS</a><br> |
<br><a name="SEC13" href="#TOC1">REFERENCE COUNTS</a><br> |
| 945 |
<P> |
<P> |
| 946 |
<b>int pcre_refcount(pcre *<i>code</i>, int <i>adjust</i>);</b> |
<b>int pcre_refcount(pcre *<i>code</i>, int <i>adjust</i>);</b> |
| 947 |
</P> |
</P> |
| 965 |
pattern is compiled on one host and then transferred to a host whose byte-order |
pattern is compiled on one host and then transferred to a host whose byte-order |
| 966 |
is different. (This seems a highly unlikely scenario.) |
is different. (This seems a highly unlikely scenario.) |
| 967 |
</P> |
</P> |
| 968 |
<br><a name="SEC13" href="#TOC1">MATCHING A PATTERN: THE TRADITIONAL FUNCTION</a><br> |
<br><a name="SEC14" href="#TOC1">MATCHING A PATTERN: THE TRADITIONAL FUNCTION</a><br> |
| 969 |
<P> |
<P> |
| 970 |
<b>int pcre_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b> |
<b>int pcre_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b> |
| 971 |
<b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b> |
<b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b> |
| 1103 |
</b><br> |
</b><br> |
| 1104 |
<P> |
<P> |
| 1105 |
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 |
| 1106 |
zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NOTBOL, |
zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>, |
| 1107 |
PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK and PCRE_PARTIAL. |
PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK and PCRE_PARTIAL. |
| 1108 |
<pre> |
<pre> |
| 1109 |
PCRE_ANCHORED |
PCRE_ANCHORED |
| 1110 |
</pre> |
</pre> |
| 1113 |
to be anchored by virtue of its contents, it cannot be made unachored at |
to be anchored by virtue of its contents, it cannot be made unachored at |
| 1114 |
matching time. |
matching time. |
| 1115 |
<pre> |
<pre> |
| 1116 |
|
PCRE_NEWLINE_CR |
| 1117 |
|
PCRE_NEWLINE_LF |
| 1118 |
|
PCRE_NEWLINE_CRLF |
| 1119 |
|
</pre> |
| 1120 |
|
These options override the newline definition that was chosen or defaulted when |
| 1121 |
|
the pattern was compiled. For details, see the description <b>pcre_compile()</b> |
| 1122 |
|
above. During matching, the newline choice affects the behaviour of the dot, |
| 1123 |
|
circumflex, and dollar metacharacters. |
| 1124 |
|
<pre> |
| 1125 |
PCRE_NOTBOL |
PCRE_NOTBOL |
| 1126 |
</pre> |
</pre> |
| 1127 |
This option specifies that first character of the subject string is not the |
This option specifies that first character of the subject string is not the |
| 1260 |
first pair, <i>ovector[0]</i> and <i>ovector[1]</i>, identify the portion of the |
first pair, <i>ovector[0]</i> and <i>ovector[1]</i>, identify the portion of the |
| 1261 |
subject string matched by the entire pattern. The next pair is used for the |
subject string matched by the entire pattern. The next pair is used for the |
| 1262 |
first capturing subpattern, and so on. The value returned by <b>pcre_exec()</b> |
first capturing subpattern, and so on. The value returned by <b>pcre_exec()</b> |
| 1263 |
is the number of pairs that have been set. If there are no capturing |
is one more than the highest numbered pair that has been set. For example, if |
| 1264 |
subpatterns, the return value from a successful match is 1, indicating that |
two substrings have been captured, the returned value is 3. If there are no |
| 1265 |
just the first pair of offsets has been set. |
capturing subpatterns, the return value from a successful match is 1, |
| 1266 |
</P> |
indicating that just the first pair of offsets has been set. |
|
<P> |
|
|
Some convenience functions are provided for extracting the captured substrings |
|
|
as separate strings. These are described in the following section. |
|
|
</P> |
|
|
<P> |
|
|
It is possible for an capturing subpattern number <i>n+1</i> to match some |
|
|
part of the subject when subpattern <i>n</i> has not been used at all. For |
|
|
example, if the string "abc" is matched against the pattern (a|(z))(bc) |
|
|
subpatterns 1 and 3 are matched, but 2 is not. When this happens, both offset |
|
|
values corresponding to the unused subpattern are set to -1. |
|
| 1267 |
</P> |
</P> |
| 1268 |
<P> |
<P> |
| 1269 |
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 |
| 1280 |
advisable to supply an <i>ovector</i>. |
advisable to supply an <i>ovector</i>. |
| 1281 |
</P> |
</P> |
| 1282 |
<P> |
<P> |
| 1283 |
Note that <b>pcre_info()</b> can be used to find out how many capturing |
The <b>pcre_info()</b> function can be used to find out how many capturing |
| 1284 |
subpatterns there are in a compiled pattern. The smallest size for |
subpatterns there are in a compiled pattern. The smallest size for |
| 1285 |
<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 |
| 1286 |
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. |
| 1287 |
|
</P> |
| 1288 |
|
<P> |
| 1289 |
|
It is possible for capturing subpattern number <i>n+1</i> to match some part of |
| 1290 |
|
the subject when subpattern <i>n</i> has not been used at all. For example, if |
| 1291 |
|
the string "abc" is matched against the pattern (a|(z))(bc) the return from the |
| 1292 |
|
function is 4, and subpatterns 1 and 3 are matched, but 2 is not. When this |
| 1293 |
|
happens, both values in the offset pairs corresponding to unused subpatterns |
| 1294 |
|
are set to -1. |
| 1295 |
|
</P> |
| 1296 |
|
<P> |
| 1297 |
|
Offset values that correspond to unused subpatterns at the end of the |
| 1298 |
|
expression are also set to -1. For example, if the string "abc" is matched |
| 1299 |
|
against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not matched. The |
| 1300 |
|
return from the function is 2, because the highest used capturing subpattern |
| 1301 |
|
number is 1. However, you can refer to the offsets for the second and third |
| 1302 |
|
capturing subpatterns if you wish (assuming the vector is large enough, of |
| 1303 |
|
course). |
| 1304 |
|
</P> |
| 1305 |
|
<P> |
| 1306 |
|
Some convenience functions are provided for extracting the captured substrings |
| 1307 |
|
as separate strings. These are described below. |
| 1308 |
<a name="errorlist"></a></P> |
<a name="errorlist"></a></P> |
| 1309 |
<br><b> |
<br><b> |
| 1310 |
Return values from <b>pcre_exec()</b> |
Error return values from <b>pcre_exec()</b> |
| 1311 |
</b><br> |
</b><br> |
| 1312 |
<P> |
<P> |
| 1313 |
If <b>pcre_exec()</b> fails, it returns a negative number. The following are |
If <b>pcre_exec()</b> fails, it returns a negative number. The following are |
| 1404 |
</pre> |
</pre> |
| 1405 |
This error is given if the value of the <i>ovecsize</i> argument is negative. |
This error is given if the value of the <i>ovecsize</i> argument is negative. |
| 1406 |
</P> |
</P> |
| 1407 |
<br><a name="SEC14" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a><br> |
<br><a name="SEC15" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NUMBER</a><br> |
| 1408 |
<P> |
<P> |
| 1409 |
<b>int pcre_copy_substring(const char *<i>subject</i>, int *<i>ovector</i>,</b> |
<b>int pcre_copy_substring(const char *<i>subject</i>, int *<i>ovector</i>,</b> |
| 1410 |
<b>int <i>stringcount</i>, int <i>stringnumber</i>, char *<i>buffer</i>,</b> |
<b>int <i>stringcount</i>, int <i>stringnumber</i>, char *<i>buffer</i>,</b> |
| 1426 |
<b>pcre_get_substring_list()</b> are provided for extracting captured substrings |
<b>pcre_get_substring_list()</b> are provided for extracting captured substrings |
| 1427 |
as new, separate, zero-terminated strings. These functions identify substrings |
as new, separate, zero-terminated strings. These functions identify substrings |
| 1428 |
by number. The next section describes functions for extracting named |
by number. The next section describes functions for extracting named |
| 1429 |
substrings. A substring that contains a binary zero is correctly extracted and |
substrings. |
| 1430 |
has a further zero added on the end, but the result is not, of course, |
</P> |
| 1431 |
a C string. |
<P> |
| 1432 |
|
A substring that contains a binary zero is correctly extracted and has a |
| 1433 |
|
further zero added on the end, but the result is not, of course, a C string. |
| 1434 |
|
However, you can process such a string by referring to the length that is |
| 1435 |
|
returned by <b>pcre_copy_substring()</b> and <b>pcre_get_substring()</b>. |
| 1436 |
|
Unfortunately, the interface to <b>pcre_get_substring_list()</b> is not adequate |
| 1437 |
|
for handling strings containing binary zeros, because the end of the final |
| 1438 |
|
string is not independently indicated. |
| 1439 |
</P> |
</P> |
| 1440 |
<P> |
<P> |
| 1441 |
The first three arguments are the same for all three of these functions: |
The first three arguments are the same for all three of these functions: |
| 1495 |
<b>pcre_get_substring_list()</b>, respectively. They do nothing more than call |
<b>pcre_get_substring_list()</b>, respectively. They do nothing more than call |
| 1496 |
the function pointed to by <b>pcre_free</b>, which of course could be called |
the function pointed to by <b>pcre_free</b>, which of course could be called |
| 1497 |
directly from a C program. However, PCRE is used in some situations where it is |
directly from a C program. However, PCRE is used in some situations where it is |
| 1498 |
linked via a special interface to another programming language which cannot use |
linked via a special interface to another programming language that cannot use |
| 1499 |
<b>pcre_free</b> directly; it is for these cases that the functions are |
<b>pcre_free</b> directly; it is for these cases that the functions are |
| 1500 |
provided. |
provided. |
| 1501 |
</P> |
</P> |
| 1502 |
<br><a name="SEC15" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NAME</a><br> |
<br><a name="SEC16" href="#TOC1">EXTRACTING CAPTURED SUBSTRINGS BY NAME</a><br> |
| 1503 |
<P> |
<P> |
| 1504 |
<b>int pcre_get_stringnumber(const pcre *<i>code</i>,</b> |
<b>int pcre_get_stringnumber(const pcre *<i>code</i>,</b> |
| 1505 |
<b>const char *<i>name</i>);</b> |
<b>const char *<i>name</i>);</b> |
| 1522 |
<pre> |
<pre> |
| 1523 |
(a+)b(?P<xxx>\d+)... |
(a+)b(?P<xxx>\d+)... |
| 1524 |
</pre> |
</pre> |
| 1525 |
the number of the subpattern called "xxx" is 2. You can find the number from |
the number of the subpattern called "xxx" is 2. If the name is known to be |
| 1526 |
the name by calling <b>pcre_get_stringnumber()</b>. The first argument is the |
unique (PCRE_DUPNAMES was not set), you can find the number from the name by |
| 1527 |
compiled pattern, and the second is the name. The yield of the function is the |
calling <b>pcre_get_stringnumber()</b>. The first argument is the compiled |
| 1528 |
|
pattern, and the second is the name. The yield of the function is the |
| 1529 |
subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if there is no subpattern of |
subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if there is no subpattern of |
| 1530 |
that name. |
that name. |
| 1531 |
</P> |
</P> |
| 1535 |
two functions that do the whole job. |
two functions that do the whole job. |
| 1536 |
</P> |
</P> |
| 1537 |
<P> |
<P> |
| 1538 |
Most of the arguments of <i>pcre_copy_named_substring()</i> and |
Most of the arguments of <b>pcre_copy_named_substring()</b> and |
| 1539 |
<i>pcre_get_named_substring()</i> are the same as those for the similarly named |
<b>pcre_get_named_substring()</b> are the same as those for the similarly named |
| 1540 |
functions that extract by number. As these are described in the previous |
functions that extract by number. As these are described in the previous |
| 1541 |
section, they are not re-described here. There are just two differences: |
section, they are not re-described here. There are just two differences: |
| 1542 |
</P> |
</P> |
| 1551 |
then call <i>pcre_copy_substring()</i> or <i>pcre_get_substring()</i>, as |
then call <i>pcre_copy_substring()</i> or <i>pcre_get_substring()</i>, as |
| 1552 |
appropriate. |
appropriate. |
| 1553 |
</P> |
</P> |
| 1554 |
<br><a name="SEC16" href="#TOC1">FINDING ALL POSSIBLE MATCHES</a><br> |
<br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br> |
| 1555 |
|
<P> |
| 1556 |
|
<b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b> |
| 1557 |
|
<b>const char *<i>name</i>, char **<i>first</i>, char **<i>last</i>);</b> |
| 1558 |
|
</P> |
| 1559 |
|
<P> |
| 1560 |
|
When a pattern is compiled with the PCRE_DUPNAMES option, names for subpatterns |
| 1561 |
|
are not required to be unique. Normally, patterns with duplicate names are such |
| 1562 |
|
that in any one match, only one of the named subpatterns participates. An |
| 1563 |
|
example is shown in the |
| 1564 |
|
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
| 1565 |
|
documentation. When duplicates are present, <b>pcre_copy_named_substring()</b> |
| 1566 |
|
and <b>pcre_get_named_substring()</b> return the first substring corresponding |
| 1567 |
|
to the given name that is set. If none are set, an empty string is returned. |
| 1568 |
|
The <b>pcre_get_stringnumber()</b> function returns one of the numbers that are |
| 1569 |
|
associated with the name, but it is not defined which it is. |
| 1570 |
|
<br> |
| 1571 |
|
<br> |
| 1572 |
|
If you want to get full details of all captured substrings for a given name, |
| 1573 |
|
you must use the <b>pcre_get_stringtable_entries()</b> function. The first |
| 1574 |
|
argument is the compiled pattern, and the second is the name. The third and |
| 1575 |
|
fourth are pointers to variables which are updated by the function. After it |
| 1576 |
|
has run, they point to the first and last entries in the name-to-number table |
| 1577 |
|
for the given name. The function itself returns the length of each entry, or |
| 1578 |
|
PCRE_ERROR_NOSUBSTRING if there are none. The format of the table is described |
| 1579 |
|
above in the section entitled <i>Information about a pattern</i>. Given all the |
| 1580 |
|
relevant entries for the name, you can extract each of their numbers, and hence |
| 1581 |
|
the captured data, if any. |
| 1582 |
|
</P> |
| 1583 |
|
<br><a name="SEC18" href="#TOC1">FINDING ALL POSSIBLE MATCHES</a><br> |
| 1584 |
<P> |
<P> |
| 1585 |
The traditional matching function uses a similar algorithm to Perl, which stops |
The traditional matching function uses a similar algorithm to Perl, which stops |
| 1586 |
when it finds the first match, starting at a given point in the subject. If you |
when it finds the first match, starting at a given point in the subject. If you |
| 1599 |
other alternatives. Ultimately, when it runs out of matches, <b>pcre_exec()</b> |
other alternatives. Ultimately, when it runs out of matches, <b>pcre_exec()</b> |
| 1600 |
will yield PCRE_ERROR_NOMATCH. |
will yield PCRE_ERROR_NOMATCH. |
| 1601 |
<a name="dfamatch"></a></P> |
<a name="dfamatch"></a></P> |
| 1602 |
<br><a name="SEC17" href="#TOC1">MATCHING A PATTERN: THE ALTERNATIVE FUNCTION</a><br> |
<br><a name="SEC19" href="#TOC1">MATCHING A PATTERN: THE ALTERNATIVE FUNCTION</a><br> |
| 1603 |
<P> |
<P> |
| 1604 |
<b>int pcre_dfa_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b> |
<b>int pcre_dfa_exec(const pcre *<i>code</i>, const pcre_extra *<i>extra</i>,</b> |
| 1605 |
<b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b> |
<b>const char *<i>subject</i>, int <i>length</i>, int <i>startoffset</i>,</b> |
| 1627 |
The two additional arguments provide workspace for the function. The workspace |
The two additional arguments provide workspace for the function. The workspace |
| 1628 |
vector should contain at least 20 elements. It is used for keeping track of |
vector should contain at least 20 elements. It is used for keeping track of |
| 1629 |
multiple paths through the pattern tree. More workspace will be needed for |
multiple paths through the pattern tree. More workspace will be needed for |
| 1630 |
patterns and subjects where there are a lot of possible matches. |
patterns and subjects where there are a lot of potential matches. |
| 1631 |
</P> |
</P> |
| 1632 |
<P> |
<P> |
| 1633 |
Here is an example of a simple call to <b>pcre_dfa_exec()</b>: |
Here is an example of a simple call to <b>pcre_dfa_exec()</b>: |
| 1653 |
</b><br> |
</b><br> |
| 1654 |
<P> |
<P> |
| 1655 |
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 |
| 1656 |
zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NOTBOL, |
zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>, |
| 1657 |
PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL, |
PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL, |
| 1658 |
PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last three of these are |
PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last three of these are |
| 1659 |
the same as for <b>pcre_exec()</b>, so their description is not repeated here. |
the same as for <b>pcre_exec()</b>, so their description is not repeated here. |
| 1660 |
<pre> |
<pre> |
| 1762 |
extremely rare, as a vector of size 1000 is used. |
extremely rare, as a vector of size 1000 is used. |
| 1763 |
</P> |
</P> |
| 1764 |
<P> |
<P> |
| 1765 |
Last updated: 18 January 2006 |
Last updated: 08 June 2006 |
| 1766 |
<br> |
<br> |
| 1767 |
Copyright © 1997-2006 University of Cambridge. |
Copyright © 1997-2006 University of Cambridge. |
| 1768 |
<p> |
<p> |