/[pcre]/code/trunk/doc/html/pcreapi.html
ViewVC logotype

Diff of /code/trunk/doc/html/pcreapi.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 91 by nigel, Sat Feb 24 21:41:34 2007 UTC revision 227 by ph10, Tue Aug 21 15:00:15 2007 UTC
# Line 32  man page, in case the conversion went wr Line 32  man page, in case the conversion went wr
32  <li><a name="TOC17" href="#SEC17">DUPLICATE SUBPATTERN NAMES</a>  <li><a name="TOC17" href="#SEC17">DUPLICATE SUBPATTERN NAMES</a>
33  <li><a name="TOC18" href="#SEC18">FINDING ALL POSSIBLE MATCHES</a>  <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>  <li><a name="TOC19" href="#SEC19">MATCHING A PATTERN: THE ALTERNATIVE FUNCTION</a>
35    <li><a name="TOC20" href="#SEC20">SEE ALSO</a>
36    <li><a name="TOC21" href="#SEC21">AUTHOR</a>
37    <li><a name="TOC22" href="#SEC22">REVISION</a>
38  </ul>  </ul>
39  <br><a name="SEC1" href="#TOC1">PCRE NATIVE API</a><br>  <br><a name="SEC1" href="#TOC1">PCRE NATIVE API</a><br>
40  <P>  <P>
# Line 140  man page, in case the conversion went wr Line 143  man page, in case the conversion went wr
143  </P>  </P>
144  <br><a name="SEC2" href="#TOC1">PCRE API OVERVIEW</a><br>  <br><a name="SEC2" href="#TOC1">PCRE API OVERVIEW</a><br>
145  <P>  <P>
146  PCRE has its own native API, which is described in this document. There is  PCRE has its own native API, which is described in this document. There are
147  also a set of wrapper functions that correspond to the POSIX regular expression  also some wrapper functions that correspond to the POSIX regular expression
148  API. These are described in the  API. These are described in the
149  <a href="pcreposix.html"><b>pcreposix</b></a>  <a href="pcreposix.html"><b>pcreposix</b></a>
150  documentation. Both of these APIs define a set of C function calls. A C++  documentation. Both of these APIs define a set of C function calls. A C++
# Line 170  documentation describes how to run it. Line 173  documentation describes how to run it.
173  A second matching function, <b>pcre_dfa_exec()</b>, which is not  A second matching function, <b>pcre_dfa_exec()</b>, which is not
174  Perl-compatible, is also provided. This uses a different algorithm for the  Perl-compatible, is also provided. This uses a different algorithm for the
175  matching. The alternative algorithm finds all possible matches (at a given  matching. The alternative algorithm finds all possible matches (at a given
176  point in the subject). However, this algorithm does not return captured  point in the subject), and scans the subject just once. However, this algorithm
177  substrings. A description of the two matching algorithms and their advantages  does not return captured substrings. A description of the two matching
178  and disadvantages is given in the  algorithms and their advantages and disadvantages is given in the
179  <a href="pcrematching.html"><b>pcrematching</b></a>  <a href="pcrematching.html"><b>pcrematching</b></a>
180  documentation.  documentation.
181  </P>  </P>
# Line 240  by the caller to a "callout" function, w Line 243  by the caller to a "callout" function, w
243  points during a matching operation. Details are given in the  points during a matching operation. Details are given in the
244  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
245  documentation.  documentation.
246  </P>  <a name="newlines"></a></P>
247  <br><a name="SEC3" href="#TOC1">NEWLINES</a><br>  <br><a name="SEC3" href="#TOC1">NEWLINES</a><br>
248  <P>  <P>
249  PCRE supports three different conventions for indicating line breaks in  PCRE supports five different conventions for indicating line breaks in
250  strings: a single CR character, a single LF character, or the two-character  strings: a single CR (carriage return) character, a single LF (linefeed)
251  sequence CRLF. All three are used as "standard" by different operating systems.  character, the two-character sequence CRLF, any of the three preceding, or any
252  When PCRE is built, a default can be specified. The default default is LF,  Unicode newline sequence. The Unicode newline sequences are the three just
253  which is the Unix standard. When PCRE is run, the default can be overridden,  mentioned, plus the single characters VT (vertical tab, U+000B), FF (formfeed,
254  either when a pattern is compiled, or when it is matched.  U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS
255  <br>  (paragraph separator, U+2029).
256  <br>  </P>
257    <P>
258    Each of the first three conventions is used by at least one operating system as
259    its standard newline sequence. When PCRE is built, a default can be specified.
260    The default default is LF, which is the Unix standard. When PCRE is run, the
261    default can be overridden, either when a pattern is compiled, or when it is
262    matched.
263    </P>
264    <P>
265    At compile time, the newline convention can be specified by the <i>options</i>
266    argument of <b>pcre_compile()</b>, or it can be specified by special text at the
267    start of the pattern itself; this overrides any other settings. See the
268    <a href="pcrepattern.html"><b>pcrepattern</b></a>
269    page for details of the special character sequences.
270    </P>
271    <P>
272  In the PCRE documentation the word "newline" is used to mean "the character or  In the PCRE documentation the word "newline" is used to mean "the character or
273  pair of characters that indicate a line break".  pair of characters that indicate a line break". The choice of newline
274    convention affects the handling of the dot, circumflex, and dollar
275    metacharacters, the handling of #-comments in /x mode, and, when CRLF is a
276    recognized line ending sequence, the match position advancement for a
277    non-anchored pattern. There is more detail about this in the
278    <a href="#execoptions">section on <b>pcre_exec()</b> options</a>
279    below. The choice of newline convention does not affect the interpretation of
280    the \n or \r escape sequences.
281  </P>  </P>
282  <br><a name="SEC4" href="#TOC1">MULTITHREADING</a><br>  <br><a name="SEC4" href="#TOC1">MULTITHREADING</a><br>
283  <P>  <P>
# Line 271  The compiled form of a regular expressio Line 296  The compiled form of a regular expressio
296  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
297  which it was compiled. Details are given in the  which it was compiled. Details are given in the
298  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
299  documentation.  documentation. However, compiling a regular expression with one version of PCRE
300    for use with a different version is not guaranteed to work and may cause
301    crashes.
302  </P>  </P>
303  <br><a name="SEC6" href="#TOC1">CHECKING BUILD-TIME OPTIONS</a><br>  <br><a name="SEC6" href="#TOC1">CHECKING BUILD-TIME OPTIONS</a><br>
304  <P>  <P>
# Line 301  properties is available; otherwise it is Line 328  properties is available; otherwise it is
328    PCRE_CONFIG_NEWLINE    PCRE_CONFIG_NEWLINE
329  </pre>  </pre>
330  The output is an integer whose value specifies the default character sequence  The output is an integer whose value specifies the default character sequence
331  that is recognized as meaning "newline". The three values that are supported  that is recognized as meaning "newline". The four values that are supported
332  are: 10 for LF, 13 for CR, and 3338 for CRLF. The default should normally be  are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF, and -1 for ANY. The
333  the standard sequence for your operating system.  default should normally be the standard sequence for your operating system.
334  <pre>  <pre>
335    PCRE_CONFIG_LINK_SIZE    PCRE_CONFIG_LINK_SIZE
336  </pre>  </pre>
# Line 374  fully relocatable, because it may contai Line 401  fully relocatable, because it may contai
401  argument, which is an address (see below).  argument, which is an address (see below).
402  </P>  </P>
403  <P>  <P>
404  The <i>options</i> argument contains independent bits that affect the  The <i>options</i> argument contains various bit settings that affect the
405  compilation. It should be zero if no options are required. The available  compilation. It should be zero if no options are required. The available
406  options are described below. Some of them, in particular, those that are  options are described below. Some of them, in particular, those that are
407  compatible with Perl, can also be set and unset from within the pattern (see  compatible with Perl, can also be set and unset from within the pattern (see
# Line 467  If this bit is set, a dot metacharater i Line 494  If this bit is set, a dot metacharater i
494  including those that indicate newline. Without it, a dot does not match when  including those that indicate newline. Without it, a dot does not match when
495  the current position is at a newline. This option is equivalent to Perl's /s  the current position is at a newline. This option is equivalent to Perl's /s
496  option, and it can be changed within a pattern by a (?s) option setting. A  option, and it can be changed within a pattern by a (?s) option setting. A
497  negative class such as [^a] always matches newlines, independent of the setting  negative class such as [^a] always matches newline characters, independent of
498  of this option.  the setting of this option.
499  <pre>  <pre>
500    PCRE_DUPNAMES    PCRE_DUPNAMES
501  </pre>  </pre>
# Line 531  occurrences of ^ or $ in a pattern, sett Line 558  occurrences of ^ or $ in a pattern, sett
558    PCRE_NEWLINE_CR    PCRE_NEWLINE_CR
559    PCRE_NEWLINE_LF    PCRE_NEWLINE_LF
560    PCRE_NEWLINE_CRLF    PCRE_NEWLINE_CRLF
561      PCRE_NEWLINE_ANYCRLF
562      PCRE_NEWLINE_ANY
563  </pre>  </pre>
564  These options override the default newline definition that was chosen when PCRE  These options override the default newline definition that was chosen when PCRE
565  was built. Setting the first or the second specifies that a newline is  was built. Setting the first or the second specifies that a newline is
566  indicated by a single character (CR or LF, respectively). Setting both of them  indicated by a single character (CR or LF, respectively). Setting
567  specifies that a newline is indicated by the two-character CRLF sequence. For  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the two-character
568  convenience, PCRE_NEWLINE_CRLF is defined to contain both bits. The only time  CRLF sequence. Setting PCRE_NEWLINE_ANYCRLF specifies that any of the three
569  that a line break is relevant when compiling a pattern is if PCRE_EXTENDED is  preceding sequences should be recognized. Setting PCRE_NEWLINE_ANY specifies
570  set, and an unescaped # outside a character class is encountered. This  that any Unicode newline sequence should be recognized. The Unicode newline
571  indicates a comment that lasts until after the next newline.  sequences are the three just mentioned, plus the single characters VT (vertical
572    tab, U+000B), FF (formfeed, U+000C), NEL (next line, U+0085), LS (line
573    separator, U+2028), and PS (paragraph separator, U+2029). The last two are
574    recognized only in UTF-8 mode.
575    </P>
576    <P>
577    The newline setting in the options word uses three bits that are treated
578    as a number, giving eight possibilities. Currently only six are used (default
579    plus the five values above). This means that if you set more than one newline
580    option, the combination may or may not be sensible. For example,
581    PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is equivalent to PCRE_NEWLINE_CRLF, but
582    other combinations may yield unused numbers and cause an error.
583    </P>
584    <P>
585    The only time that a line break is specially recognized when compiling a
586    pattern is if PCRE_EXTENDED is set, and an unescaped # outside a character
587    class is encountered. This indicates a comment that lasts until after the next
588    line break sequence. In other circumstances, line break sequences are treated
589    as literal data, except that in PCRE_EXTENDED mode, both CR and LF are treated
590    as whitespace characters and are therefore ignored.
591  </P>  </P>
592  <P>  <P>
593  The newline option set at compile time becomes the default that is used for  The newline option that is set at compile time becomes the default that is used
594  <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b>, but it can be overridden.  for <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b>, but it can be overridden.
595  <pre>  <pre>
596    PCRE_NO_AUTO_CAPTURE    PCRE_NO_AUTO_CAPTURE
597  </pre>  </pre>
# Line 574  page. Line 622  page.
622    PCRE_NO_UTF8_CHECK    PCRE_NO_UTF8_CHECK
623  </pre>  </pre>
624  When PCRE_UTF8 is set, the validity of the pattern as a UTF-8 string is  When PCRE_UTF8 is set, the validity of the pattern as a UTF-8 string is
625  automatically checked. If an invalid UTF-8 sequence of bytes is found,  automatically checked. There is a discussion about the
626  <b>pcre_compile()</b> returns an error. If you already know that your pattern is  <a href="pcre.html#utf8strings">validity of UTF-8 strings</a>
627  valid, and you want to skip this check for performance reasons, you can set the  in the main
628  PCRE_NO_UTF8_CHECK option. When it is set, the effect of passing an invalid  <a href="pcre.html"><b>pcre</b></a>
629  UTF-8 string as a pattern is undefined. It may cause your program to crash.  page. If an invalid UTF-8 sequence of bytes is found, <b>pcre_compile()</b>
630  Note that this option can also be passed to <b>pcre_exec()</b> and  returns an error. If you already know that your pattern is valid, and you want
631  <b>pcre_dfa_exec()</b>, to suppress the UTF-8 validity checking of subject  to skip this check for performance reasons, you can set the PCRE_NO_UTF8_CHECK
632  strings.  option. When it is set, the effect of passing an invalid UTF-8 string as a
633    pattern is undefined. It may cause your program to crash. Note that this option
634    can also be passed to <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b>, to suppress
635    the UTF-8 validity checking of subject strings.
636  </P>  </P>
637  <br><a name="SEC8" href="#TOC1">COMPILATION ERROR CODES</a><br>  <br><a name="SEC8" href="#TOC1">COMPILATION ERROR CODES</a><br>
638  <P>  <P>
639  The following table lists the error codes than may be returned by  The following table lists the error codes than may be returned by
640  <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
641  both compiling functions.  both compiling functions. As PCRE has developed, some error codes have fallen
642    out of use. To avoid confusion, they have not been re-used.
643  <pre>  <pre>
644     0  no error     0  no error
645     1  \ at end of pattern     1  \ at end of pattern
# Line 599  both compiling functions. Line 651  both compiling functions.
651     7  invalid escape sequence in character class     7  invalid escape sequence in character class
652     8  range out of order in character class     8  range out of order in character class
653     9  nothing to repeat     9  nothing to repeat
654    10  operand of unlimited repeat could match the empty string    10  [this code is not in use]
655    11  internal error: unexpected repeat    11  internal error: unexpected repeat
656    12  unrecognized character after (?    12  unrecognized character after (?
657    13  POSIX named classes are supported only within a class    13  POSIX named classes are supported only within a class
# Line 608  both compiling functions. Line 660  both compiling functions.
660    16  erroffset passed as NULL    16  erroffset passed as NULL
661    17  unknown option bit(s) set    17  unknown option bit(s) set
662    18  missing ) after comment    18  missing ) after comment
663    19  parentheses nested too deeply    19  [this code is not in use]
664    20  regular expression too large    20  regular expression too large
665    21  failed to get memory    21  failed to get memory
666    22  unmatched parentheses    22  unmatched parentheses
# Line 618  both compiling functions. Line 670  both compiling functions.
670    26  malformed number or name after (?(    26  malformed number or name after (?(
671    27  conditional group contains more than two branches    27  conditional group contains more than two branches
672    28  assertion expected after (?(    28  assertion expected after (?(
673    29  (?R or (?digits must be followed by )    29  (?R or (?[+-]digits must be followed by )
674    30  unknown POSIX class name    30  unknown POSIX class name
675    31  POSIX collating elements are not supported    31  POSIX collating elements are not supported
676    32  this version of PCRE is not compiled with PCRE_UTF8 support    32  this version of PCRE is not compiled with PCRE_UTF8 support
677    33  spare error    33  [this code is not in use]
678    34  character value in \x{...} sequence is too large    34  character value in \x{...} sequence is too large
679    35  invalid condition (?(0)    35  invalid condition (?(0)
680    36  \C not allowed in lookbehind assertion    36  \C not allowed in lookbehind assertion
# Line 631  both compiling functions. Line 683  both compiling functions.
683    39  closing ) for (?C expected    39  closing ) for (?C expected
684    40  recursive call could loop indefinitely    40  recursive call could loop indefinitely
685    41  unrecognized character after (?P    41  unrecognized character after (?P
686    42  syntax error after (?P    42  syntax error in subpattern name (missing terminator)
687    43  two named subpatterns have the same name    43  two named subpatterns have the same name
688    44  invalid UTF-8 string    44  invalid UTF-8 string
689    45  support for \P, \p, and \X has not been compiled    45  support for \P, \p, and \X has not been compiled
# Line 639  both compiling functions. Line 691  both compiling functions.
691    47  unknown property name after \P or \p    47  unknown property name after \P or \p
692    48  subpattern name is too long (maximum 32 characters)    48  subpattern name is too long (maximum 32 characters)
693    49  too many named subpatterns (maximum 10,000)    49  too many named subpatterns (maximum 10,000)
694    50  repeated subpattern is too long    50  [this code is not in use]
695    51  octal value is greater than \377 (not in UTF-8 mode)    51  octal value is greater than \377 (not in UTF-8 mode)
696      52  internal error: overran compiling workspace
697      53  internal error: previously-checked referenced subpattern not found
698      54  DEFINE group contains more than one branch
699      55  repeating a DEFINE group is not allowed
700      56  inconsistent NEWLINE options"
701      57  \g is not followed by a braced name or an optionally braced
702            non-zero number
703      58  (?+ or (?- or (?(+ or (?(- must be followed by a non-zero number
704  </PRE>  </PRE>
705  </P>  </P>
706  <br><a name="SEC9" href="#TOC1">STUDYING A PATTERN</a><br>  <br><a name="SEC9" href="#TOC1">STUDYING A PATTERN</a><br>
# Line 698  bytes is created. Line 758  bytes is created.
758  <a name="localesupport"></a></P>  <a name="localesupport"></a></P>
759  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>
760  <P>  <P>
761  PCRE handles caseless matching, and determines whether characters are letters  PCRE handles caseless matching, and determines whether characters are letters,
762  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
763  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
764  less than 128. Higher-valued codes never match escapes such as \w or \d, but  less than 128. Higher-valued codes never match escapes such as \w or \d, but
765  can be tested with \p if PCRE is built with Unicode character property  can be tested with \p if PCRE is built with Unicode character property
766  support. The use of locales with Unicode is discouraged.  support. The use of locales with Unicode is discouraged. If you are handling
767  </P>  characters with codes greater than 128, you should either use UTF-8 and
768  <P>  Unicode, or use locales, but not try to mix the two.
769  An internal set of tables is created in the default C locale when PCRE is  </P>
770  built. This is used when the final argument of <b>pcre_compile()</b> is NULL,  <P>
771  and is sufficient for many applications. An alternative set of tables can,  PCRE contains an internal set of tables that are used when the final argument
772  however, be supplied. These may be created in a different locale from the  of <b>pcre_compile()</b> is NULL. These are sufficient for many applications.
773  default. As more and more applications change to using Unicode, the need for  Normally, the internal tables recognize only ASCII characters. However, when
774  this locale support is expected to die away.  PCRE is built, it is possible to cause the internal tables to be rebuilt in the
775    default "C" locale of the local system, which may cause them to be different.
776    </P>
777    <P>
778    The internal tables can always be overridden by tables supplied by the
779    application that calls PCRE. These may be created in a different locale from
780    the default. As more and more applications change to using Unicode, the need
781    for this locale support is expected to die away.
782  </P>  </P>
783  <P>  <P>
784  External tables are built by calling the <b>pcre_maketables()</b> function,  External tables are built by calling the <b>pcre_maketables()</b> function,
# Line 725  the following code could be used: Line 792  the following code could be used:
792    tables = pcre_maketables();    tables = pcre_maketables();
793    re = pcre_compile(..., tables);    re = pcre_compile(..., tables);
794  </pre>  </pre>
795    The locale name "fr_FR" is used on Linux and other Unix-like systems; if you
796    are using Windows, the name for the French locale is "french".
797    </P>
798    <P>
799  When <b>pcre_maketables()</b> runs, the tables are built in memory that is  When <b>pcre_maketables()</b> runs, the tables are built in memory that is
800  obtained via <b>pcre_malloc</b>. It is the caller's responsibility to ensure  obtained via <b>pcre_malloc</b>. It is the caller's responsibility to ensure
801  that the memory containing the tables remains available for as long as it is  that the memory containing the tables remains available for as long as it is
# Line 810  still recognized for backwards compatibi Line 881  still recognized for backwards compatibi
881  </P>  </P>
882  <P>  <P>
883  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
884  (cat|cow|coyote). Otherwise, if either  (cat|cow|coyote), its value is returned. Otherwise, if either
885  <br>  <br>
886  <br>  <br>
887  (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
# Line 832  table indicating a fixed set of bytes fo Line 903  table indicating a fixed set of bytes fo
903  string, a pointer to the table is returned. Otherwise NULL is returned. The  string, a pointer to the table is returned. Otherwise NULL is returned. The
904  fourth argument should point to an <b>unsigned char *</b> variable.  fourth argument should point to an <b>unsigned char *</b> variable.
905  <pre>  <pre>
906      PCRE_INFO_HASCRORLF
907    </pre>
908    Return 1 if the pattern contains any explicit matches for CR or LF characters,
909    otherwise 0. The fourth argument should point to an <b>int</b> variable.
910    <pre>
911      PCRE_INFO_JCHANGED
912    </pre>
913    Return 1 if the (?J) option setting is used in the pattern, otherwise 0. The
914    fourth argument should point to an <b>int</b> variable. The (?J) internal option
915    setting changes the local PCRE_DUPNAMES option.
916    <pre>
917    PCRE_INFO_LASTLITERAL    PCRE_INFO_LASTLITERAL
918  </pre>  </pre>
919  Return the value of the rightmost literal byte that must exist in any matched  Return the value of the rightmost literal byte that must exist in any matched
# Line 868  alphabetical order. When PCRE_DUPNAMES i Line 950  alphabetical order. When PCRE_DUPNAMES i
950  their parentheses numbers. For example, consider the following pattern (assume  their parentheses numbers. For example, consider the following pattern (assume
951  PCRE_EXTENDED is set, so white space - including newlines - is ignored):  PCRE_EXTENDED is set, so white space - including newlines - is ignored):
952  <pre>  <pre>
953    (?P&#60;date&#62; (?P&#60;year&#62;(\d\d)?\d\d) - (?P&#60;month&#62;\d\d) - (?P&#60;day&#62;\d\d) )    (?&#60;date&#62; (?&#60;year&#62;(\d\d)?\d\d) - (?&#60;month&#62;\d\d) - (?&#60;day&#62;\d\d) )
954  </pre>  </pre>
955  There are four named subpatterns, so the table has four entries, and each entry  There are four named subpatterns, so the table has four entries, and each entry
956  in the table is eight bytes long. The table is as follows, with non-printing  in the table is eight bytes long. The table is as follows, with non-printing
# Line 883  When writing code to extract data from n Line 965  When writing code to extract data from n
965  name-to-number map, remember that the length of the entries is likely to be  name-to-number map, remember that the length of the entries is likely to be
966  different for each compiled pattern.  different for each compiled pattern.
967  <pre>  <pre>
968      PCRE_INFO_OKPARTIAL
969    </pre>
970    Return 1 if the pattern can be used for partial matching, otherwise 0. The
971    fourth argument should point to an <b>int</b> variable. The
972    <a href="pcrepartial.html"><b>pcrepartial</b></a>
973    documentation lists the restrictions that apply to patterns when partial
974    matching is used.
975    <pre>
976    PCRE_INFO_OPTIONS    PCRE_INFO_OPTIONS
977  </pre>  </pre>
978  Return a copy of the options with which the pattern was compiled. The fourth  Return a copy of the options with which the pattern was compiled. The fourth
979  argument should point to an <b>unsigned long int</b> variable. These option bits  argument should point to an <b>unsigned long int</b> variable. These option bits
980  are those specified in the call to <b>pcre_compile()</b>, modified by any  are those specified in the call to <b>pcre_compile()</b>, modified by any
981  top-level option settings within the pattern itself.  top-level option settings at the start of the pattern itself. In other words,
982    they are the options that will be in force when matching starts. For example,
983    if the pattern /(?im)abc(?-i)d/ is compiled with the PCRE_EXTENDED option, the
984    result is PCRE_CASELESS, PCRE_MULTILINE, and PCRE_EXTENDED.
985  </P>  </P>
986  <P>  <P>
987  A pattern is automatically anchored by PCRE if all of its top-level  A pattern is automatically anchored by PCRE if all of its top-level
# Line 1097  the external tables might be at a differ Line 1190  the external tables might be at a differ
1190  called. See the  called. See the
1191  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
1192  documentation for a discussion of saving compiled patterns for later use.  documentation for a discussion of saving compiled patterns for later use.
1193  </P>  <a name="execoptions"></a></P>
1194  <br><b>  <br><b>
1195  Option bits for <b>pcre_exec()</b>  Option bits for <b>pcre_exec()</b>
1196  </b><br>  </b><br>
# Line 1116  matching time. Line 1209  matching time.
1209    PCRE_NEWLINE_CR    PCRE_NEWLINE_CR
1210    PCRE_NEWLINE_LF    PCRE_NEWLINE_LF
1211    PCRE_NEWLINE_CRLF    PCRE_NEWLINE_CRLF
1212      PCRE_NEWLINE_ANYCRLF
1213      PCRE_NEWLINE_ANY
1214  </pre>  </pre>
1215  These options override the newline definition that was chosen or defaulted when  These options override the newline definition that was chosen or defaulted when
1216  the pattern was compiled. For details, see the description <b>pcre_compile()</b>  the pattern was compiled. For details, see the description of
1217  above. During matching, the newline choice affects the behaviour of the dot,  <b>pcre_compile()</b> above. During matching, the newline choice affects the
1218  circumflex, and dollar metacharacters.  behaviour of the dot, circumflex, and dollar metacharacters. It may also alter
1219    the way the match position is advanced after a match failure for an unanchored
1220    pattern.
1221    </P>
1222    <P>
1223    When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is set, and a
1224    match attempt for an unanchored pattern fails when the current position is at a
1225    CRLF sequence, and the pattern contains no explicit matches for CR or NL
1226    characters, the match position is advanced by two characters instead of one, in
1227    other words, to after the CRLF.
1228    </P>
1229    <P>
1230    The above rule is a compromise that makes the most common cases work as
1231    expected. For example, if the pattern is .+A (and the PCRE_DOTALL option is not
1232    set), it does not match the string "\r\nA" because, after failing at the
1233    start, it skips both the CR and the LF before retrying. However, the pattern
1234    [\r\n]A does match that string, because it contains an explicit CR or LF
1235    reference, and so advances only by one character after the first failure.
1236    Note than an explicit CR or LF reference occurs for negated character classes
1237    such as [^X] because they can match CR or LF characters.
1238    </P>
1239    <P>
1240    Notwithstanding the above, anomalous effects may still occur when CRLF is a
1241    valid newline sequence and explicit \r or \n escapes appear in the pattern.
1242  <pre>  <pre>
1243    PCRE_NOTBOL    PCRE_NOTBOL
1244  </pre>  </pre>
# Line 1164  code that demonstrates how to do this in Line 1282  code that demonstrates how to do this in
1282  When PCRE_UTF8 is set at compile time, the validity of the subject as a UTF-8  When PCRE_UTF8 is set at compile time, the validity of the subject as a UTF-8
1283  string is automatically checked when <b>pcre_exec()</b> is subsequently called.  string is automatically checked when <b>pcre_exec()</b> is subsequently called.
1284  The value of <i>startoffset</i> is also checked to ensure that it points to the  The value of <i>startoffset</i> is also checked to ensure that it points to the
1285  start of a UTF-8 character. If an invalid UTF-8 sequence of bytes is found,  start of a UTF-8 character. There is a discussion about the validity of UTF-8
1286  <b>pcre_exec()</b> returns the error PCRE_ERROR_BADUTF8. If <i>startoffset</i>  strings in the
1287  contains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned.  <a href="pcre.html#utf8strings">section on UTF-8 support</a>
1288    in the main
1289    <a href="pcre.html"><b>pcre</b></a>
1290    page. If an invalid UTF-8 sequence of bytes is found, <b>pcre_exec()</b> returns
1291    the error PCRE_ERROR_BADUTF8. If <i>startoffset</i> contains an invalid value,
1292    PCRE_ERROR_BADUTF8_OFFSET is returned.
1293  </P>  </P>
1294  <P>  <P>
1295  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
# Line 1334  compiled in an environment of one endian Line 1457  compiled in an environment of one endian
1457  other endianness. This is the error that PCRE gives when the magic number is  other endianness. This is the error that PCRE gives when the magic number is
1458  not present.  not present.
1459  <pre>  <pre>
1460    PCRE_ERROR_UNKNOWN_NODE   (-5)    PCRE_ERROR_UNKNOWN_OPCODE (-5)
1461  </pre>  </pre>
1462  While running the pattern match, an unknown item was encountered in the  While running the pattern match, an unknown item was encountered in the
1463  compiled pattern. This error could be caused by a bug in PCRE or by overwriting  compiled pattern. This error could be caused by a bug in PCRE or by overwriting
# Line 1360  The backtracking limit, as specified by Line 1483  The backtracking limit, as specified by
1483  <b>pcre_extra</b> structure (or defaulted) was reached. See the description  <b>pcre_extra</b> structure (or defaulted) was reached. See the description
1484  above.  above.
1485  <pre>  <pre>
   PCRE_ERROR_RECURSIONLIMIT (-21)  
 </pre>  
 The internal recursion limit, as specified by the <i>match_limit_recursion</i>  
 field in a <b>pcre_extra</b> structure (or defaulted) was reached. See the  
 description above.  
 <pre>  
1486    PCRE_ERROR_CALLOUT        (-9)    PCRE_ERROR_CALLOUT        (-9)
1487  </pre>  </pre>
1488  This error is never generated by <b>pcre_exec()</b> itself. It is provided for  This error is never generated by <b>pcre_exec()</b> itself. It is provided for
# Line 1403  in PCRE or by overwriting of the compile Line 1520  in PCRE or by overwriting of the compile
1520    PCRE_ERROR_BADCOUNT       (-15)    PCRE_ERROR_BADCOUNT       (-15)
1521  </pre>  </pre>
1522  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.
1523    <pre>
1524      PCRE_ERROR_RECURSIONLIMIT (-21)
1525    </pre>
1526    The internal recursion limit, as specified by the <i>match_limit_recursion</i>
1527    field in a <b>pcre_extra</b> structure (or defaulted) was reached. See the
1528    description above.
1529    <pre>
1530      PCRE_ERROR_BADNEWLINE     (-23)
1531    </pre>
1532    An invalid combination of PCRE_NEWLINE_<i>xxx</i> options was given.
1533    </P>
1534    <P>
1535    Error numbers -16 to -20 and -22 are not used by <b>pcre_exec()</b>.
1536  </P>  </P>
1537  <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>
1538  <P>  <P>
# Line 1457  the string is placed in <i>buffer</i>, w Line 1587  the string is placed in <i>buffer</i>, w
1587  <i>buffersize</i>, while for <b>pcre_get_substring()</b> a new block of memory is  <i>buffersize</i>, while for <b>pcre_get_substring()</b> a new block of memory is
1588  obtained via <b>pcre_malloc</b>, and its address is returned via  obtained via <b>pcre_malloc</b>, and its address is returned via
1589  <i>stringptr</i>. The yield of the function is the length of the string, not  <i>stringptr</i>. The yield of the function is the length of the string, not
1590  including the terminating zero, or one of  including the terminating zero, or one of these error codes:
1591  <pre>  <pre>
1592    PCRE_ERROR_NOMEMORY       (-6)    PCRE_ERROR_NOMEMORY       (-6)
1593  </pre>  </pre>
# Line 1474  and builds a list of pointers to them. A Line 1604  and builds a list of pointers to them. A
1604  memory that is obtained via <b>pcre_malloc</b>. The address of the memory block  memory that is obtained via <b>pcre_malloc</b>. The address of the memory block
1605  is returned via <i>listptr</i>, which is also the start of the list of string  is returned via <i>listptr</i>, which is also the start of the list of string
1606  pointers. The end of the list is marked by a NULL pointer. The yield of the  pointers. The end of the list is marked by a NULL pointer. The yield of the
1607  function is zero if all went well, or  function is zero if all went well, or the error code
1608  <pre>  <pre>
1609    PCRE_ERROR_NOMEMORY       (-6)    PCRE_ERROR_NOMEMORY       (-6)
1610  </pre>  </pre>
# Line 1520  provided. Line 1650  provided.
1650  To extract a substring by name, you first have to find associated number.  To extract a substring by name, you first have to find associated number.
1651  For example, for this pattern  For example, for this pattern
1652  <pre>  <pre>
1653    (a+)b(?P&#60;xxx&#62;\d+)...    (a+)b(?&#60;xxx&#62;\d+)...
1654  </pre>  </pre>
1655  the number of the subpattern called "xxx" is 2. If the name is known to be  the number of the subpattern called "xxx" is 2. If the name is known to be
1656  unique (PCRE_DUPNAMES was not set), you can find the number from the name by  unique (PCRE_DUPNAMES was not set), you can find the number from the name by
# Line 1548  translation table. Line 1678  translation table.
1678  </P>  </P>
1679  <P>  <P>
1680  These functions call <b>pcre_get_stringnumber()</b>, and if it succeeds, they  These functions call <b>pcre_get_stringnumber()</b>, and if it succeeds, they
1681  then call <i>pcre_copy_substring()</i> or <i>pcre_get_substring()</i>, as  then call <b>pcre_copy_substring()</b> or <b>pcre_get_substring()</b>, as
1682  appropriate.  appropriate. <b>NOTE:</b> If PCRE_DUPNAMES is set and there are duplicate names,
1683    the behaviour may not be what you want (see the next section).
1684  </P>  </P>
1685  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>
1686  <P>  <P>
# Line 1562  are not required to be unique. Normally, Line 1693  are not required to be unique. Normally,
1693  that in any one match, only one of the named subpatterns participates. An  that in any one match, only one of the named subpatterns participates. An
1694  example is shown in the  example is shown in the
1695  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
1696  documentation. When duplicates are present, <b>pcre_copy_named_substring()</b>  documentation.
1697  and <b>pcre_get_named_substring()</b> return the first substring corresponding  </P>
1698  to the given name that is set. If none are set, an empty string is returned.  <P>
1699  The <b>pcre_get_stringnumber()</b> function returns one of the numbers that are  When duplicates are present, <b>pcre_copy_named_substring()</b> and
1700  associated with the name, but it is not defined which it is.  <b>pcre_get_named_substring()</b> return the first substring corresponding to
1701  <br>  the given name that is set. If none are set, PCRE_ERROR_NOSUBSTRING (-7) is
1702  <br>  returned; no data is returned. The <b>pcre_get_stringnumber()</b> function
1703    returns one of the numbers that are associated with the name, but it is not
1704    defined which it is.
1705    </P>
1706    <P>
1707  If you want to get full details of all captured substrings for a given name,  If you want to get full details of all captured substrings for a given name,
1708  you must use the <b>pcre_get_stringtable_entries()</b> function. The first  you must use the <b>pcre_get_stringtable_entries()</b> function. The first
1709  argument is the compiled pattern, and the second is the name. The third and  argument is the compiled pattern, and the second is the name. The third and
1710  fourth are pointers to variables which are updated by the function. After it  fourth are pointers to variables which are updated by the function. After it
1711  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
1712  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
1713  PCRE_ERROR_NOSUBSTRING if there are none. The format of the table is described  PCRE_ERROR_NOSUBSTRING (-7) if there are none. The format of the table is
1714  above in the section entitled <i>Information about a pattern</i>. Given all the  described above in the section entitled <i>Information about a pattern</i>.
1715  relevant entries for the name, you can extract each of their numbers, and hence  Given all the relevant entries for the name, you can extract each of their
1716  the captured data, if any.  numbers, and hence the captured data, if any.
1717  </P>  </P>
1718  <br><a name="SEC18" href="#TOC1">FINDING ALL POSSIBLE MATCHES</a><br>  <br><a name="SEC18" href="#TOC1">FINDING ALL POSSIBLE MATCHES</a><br>
1719  <P>  <P>
# Line 1608  will yield PCRE_ERROR_NOMATCH. Line 1743  will yield PCRE_ERROR_NOMATCH.
1743  </P>  </P>
1744  <P>  <P>
1745  The function <b>pcre_dfa_exec()</b> is called to match a subject string against  The function <b>pcre_dfa_exec()</b> is called to match a subject string against
1746  a compiled pattern, using a "DFA" matching algorithm. This has different  a compiled pattern, using a matching algorithm that scans the subject string
1747  characteristics to the normal algorithm, and is not compatible with Perl. Some  just once, and does not backtrack. This has different characteristics to the
1748  of the features of PCRE patterns are not supported. Nevertheless, there are  normal algorithm, and is not compatible with Perl. Some of the features of PCRE
1749  times when this kind of matching can be useful. For a discussion of the two  patterns are not supported. Nevertheless, there are times when this kind of
1750  matching algorithms, see the  matching can be useful. For a discussion of the two matching algorithms, see
1751    the
1752  <a href="pcrematching.html"><b>pcrematching</b></a>  <a href="pcrematching.html"><b>pcrematching</b></a>
1753  documentation.  documentation.
1754  </P>  </P>
# Line 1671  matching string. Line 1807  matching string.
1807    PCRE_DFA_SHORTEST    PCRE_DFA_SHORTEST
1808  </pre>  </pre>
1809  Setting the PCRE_DFA_SHORTEST option causes the matching algorithm to stop as  Setting the PCRE_DFA_SHORTEST option causes the matching algorithm to stop as
1810  soon as it has found one match. Because of the way the DFA algorithm works,  soon as it has found one match. Because of the way the alternative algorithm
1811  this is necessarily the shortest possible match at the first possible matching  works, this is necessarily the shortest possible match at the first possible
1812  point in the subject string.  matching point in the subject string.
1813  <pre>  <pre>
1814    PCRE_DFA_RESTART    PCRE_DFA_RESTART
1815  </pre>  </pre>
# Line 1711  the three matched strings are Line 1847  the three matched strings are
1847  On success, the yield of the function is a number greater than zero, which is  On success, the yield of the function is a number greater than zero, which is
1848  the number of matched substrings. The substrings themselves are returned in  the number of matched substrings. The substrings themselves are returned in
1849  <i>ovector</i>. Each string uses two elements; the first is the offset to the  <i>ovector</i>. Each string uses two elements; the first is the offset to the
1850  start, and the second is the offset to the end. All the strings have the same  start, and the second is the offset to the end. In fact, all the strings have
1851  start offset. (Space could have been saved by giving this only once, but it was  the same start offset. (Space could have been saved by giving this only once,
1852  decided to retain some compatibility with the way <b>pcre_exec()</b> returns  but it was decided to retain some compatibility with the way <b>pcre_exec()</b>
1853  data, even though the meaning of the strings is different.)  returns data, even though the meaning of the strings is different.)
1854  </P>  </P>
1855  <P>  <P>
1856  The strings are returned in reverse order of length; that is, the longest  The strings are returned in reverse order of length; that is, the longest
# Line 1740  that it does not support, for instance, Line 1876  that it does not support, for instance,
1876  <pre>  <pre>
1877    PCRE_ERROR_DFA_UCOND      (-17)    PCRE_ERROR_DFA_UCOND      (-17)
1878  </pre>  </pre>
1879  This return is given if <b>pcre_dfa_exec()</b> encounters a condition item in a  This return is given if <b>pcre_dfa_exec()</b> encounters a condition item that
1880  pattern that uses a back reference for the condition. This is not supported.  uses a back reference for the condition, or a test for recursion in a specific
1881    group. These are not supported.
1882  <pre>  <pre>
1883    PCRE_ERROR_DFA_UMLIMIT    (-18)    PCRE_ERROR_DFA_UMLIMIT    (-18)
1884  </pre>  </pre>
# Line 1761  recursively, using private vectors for < Line 1898  recursively, using private vectors for <
1898  error is given if the output vector is not large enough. This should be  error is given if the output vector is not large enough. This should be
1899  extremely rare, as a vector of size 1000 is used.  extremely rare, as a vector of size 1000 is used.
1900  </P>  </P>
1901    <br><a name="SEC20" href="#TOC1">SEE ALSO</a><br>
1902  <P>  <P>
1903  Last updated: 08 June 2006  <b>pcrebuild</b>(3), <b>pcrecallout</b>(3), <b>pcrecpp(3)</b>(3),
1904    <b>pcrematching</b>(3), <b>pcrepartial</b>(3), <b>pcreposix</b>(3),
1905    <b>pcreprecompile</b>(3), <b>pcresample</b>(3), <b>pcrestack</b>(3).
1906    </P>
1907    <br><a name="SEC21" href="#TOC1">AUTHOR</a><br>
1908    <P>
1909    Philip Hazel
1910    <br>
1911    University Computing Service
1912    <br>
1913    Cambridge CB2 3QH, England.
1914    <br>
1915    </P>
1916    <br><a name="SEC22" href="#TOC1">REVISION</a><br>
1917    <P>
1918    Last updated: 21 August 2007
1919    <br>
1920    Copyright &copy; 1997-2007 University of Cambridge.
1921  <br>  <br>
 Copyright &copy; 1997-2006 University of Cambridge.  
1922  <p>  <p>
1923  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.
1924  </p>  </p>

Legend:
Removed from v.91  
changed lines
  Added in v.227

  ViewVC Help
Powered by ViewVC 1.1.5