/[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 111 by ph10, Thu Mar 8 16:53:09 2007 UTC revision 211 by ph10, Thu Aug 9 09:52:43 2007 UTC
# Line 246  documentation. Line 246  documentation.
246  </P>  </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 four different conventions for indicating line breaks in  PCRE supports five different conventions for indicating line breaks in
250  strings: a single CR (carriage return) character, a single LF (linefeed)  strings: a single CR (carriage return) character, a single LF (linefeed)
251  character, the two-character sequence CRLF, or any Unicode newline sequence.  character, the two-character sequence CRLF, any of the three preceding, or any
252  The Unicode newline sequences are the three just mentioned, plus the single  Unicode newline sequence. The Unicode newline sequences are the three just
253  characters VT (vertical tab, U+000B), FF (formfeed, U+000C), NEL (next line,  mentioned, plus the single characters VT (vertical tab, U+000B), FF (formfeed,
254  U+0085), LS (line separator, U+2028), and PS (paragraph separator, U+2029).  U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS
255    (paragraph separator, U+2029).
256  </P>  </P>
257  <P>  <P>
258  Each of the first three conventions is used by at least one operating system as  Each of the first three conventions is used by at least one operating system as
# Line 286  The compiled form of a regular expressio Line 287  The compiled form of a regular expressio
287  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
288  which it was compiled. Details are given in the  which it was compiled. Details are given in the
289  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
290  documentation.  documentation. However, compiling a regular expression with one version of PCRE
291    for use with a different version is not guaranteed to work and may cause
292    crashes.
293  </P>  </P>
294  <br><a name="SEC6" href="#TOC1">CHECKING BUILD-TIME OPTIONS</a><br>  <br><a name="SEC6" href="#TOC1">CHECKING BUILD-TIME OPTIONS</a><br>
295  <P>  <P>
# Line 317  properties is available; otherwise it is Line 320  properties is available; otherwise it is
320  </pre>  </pre>
321  The output is an integer whose value specifies the default character sequence  The output is an integer whose value specifies the default character sequence
322  that is recognized as meaning "newline". The four values that are supported  that is recognized as meaning "newline". The four values that are supported
323  are: 10 for LF, 13 for CR, 3338 for CRLF, and -1 for ANY. The default should  are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF, and -1 for ANY. The
324  normally be the standard sequence for your operating system.  default should normally be the standard sequence for your operating system.
325  <pre>  <pre>
326    PCRE_CONFIG_LINK_SIZE    PCRE_CONFIG_LINK_SIZE
327  </pre>  </pre>
# Line 546  occurrences of ^ or $ in a pattern, sett Line 549  occurrences of ^ or $ in a pattern, sett
549    PCRE_NEWLINE_CR    PCRE_NEWLINE_CR
550    PCRE_NEWLINE_LF    PCRE_NEWLINE_LF
551    PCRE_NEWLINE_CRLF    PCRE_NEWLINE_CRLF
552      PCRE_NEWLINE_ANYCRLF
553    PCRE_NEWLINE_ANY    PCRE_NEWLINE_ANY
554  </pre>  </pre>
555  These options override the default newline definition that was chosen when PCRE  These options override the default newline definition that was chosen when PCRE
556  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
557  indicated by a single character (CR or LF, respectively). Setting  indicated by a single character (CR or LF, respectively). Setting
558  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the two-character  PCRE_NEWLINE_CRLF specifies that a newline is indicated by the two-character
559  CRLF sequence. Setting PCRE_NEWLINE_ANY specifies that any Unicode newline  CRLF sequence. Setting PCRE_NEWLINE_ANYCRLF specifies that any of the three
560  sequence should be recognized. The Unicode newline sequences are the three just  preceding sequences should be recognized. Setting PCRE_NEWLINE_ANY specifies
561  mentioned, plus the single characters VT (vertical tab, U+000B), FF (formfeed,  that any Unicode newline sequence should be recognized. The Unicode newline
562  U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS  sequences are the three just mentioned, plus the single characters VT (vertical
563  (paragraph separator, U+2029). The last two are recognized only in UTF-8 mode.  tab, U+000B), FF (formfeed, U+000C), NEL (next line, U+0085), LS (line
564    separator, U+2028), and PS (paragraph separator, U+2029). The last two are
565    recognized only in UTF-8 mode.
566  </P>  </P>
567  <P>  <P>
568  The newline setting in the options word uses three bits that are treated  The newline setting in the options word uses three bits that are treated
569  as a number, giving eight possibilities. Currently only five are used (default  as a number, giving eight possibilities. Currently only six are used (default
570  plus the four values above). This means that if you set more than one newline  plus the five values above). This means that if you set more than one newline
571  option, the combination may or may not be sensible. For example,  option, the combination may or may not be sensible. For example,
572  PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is equivalent to PCRE_NEWLINE_CRLF, but  PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is equivalent to PCRE_NEWLINE_CRLF, but
573  other combinations yield unused numbers and cause an error.  other combinations may yield unused numbers and cause an error.
574  </P>  </P>
575  <P>  <P>
576  The only time that a line break is specially recognized when compiling a  The only time that a line break is specially recognized when compiling a
# Line 607  page. Line 613  page.
613    PCRE_NO_UTF8_CHECK    PCRE_NO_UTF8_CHECK
614  </pre>  </pre>
615  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
616  automatically checked. If an invalid UTF-8 sequence of bytes is found,  automatically checked. There is a discussion about the
617  <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>
618  valid, and you want to skip this check for performance reasons, you can set the  in the main
619  PCRE_NO_UTF8_CHECK option. When it is set, the effect of passing an invalid  <a href="pcre.html"><b>pcre</b></a>
620  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>
621  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
622  <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
623  strings.  option. When it is set, the effect of passing an invalid UTF-8 string as a
624    pattern is undefined. It may cause your program to crash. Note that this option
625    can also be passed to <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b>, to suppress
626    the UTF-8 validity checking of subject strings.
627  </P>  </P>
628  <br><a name="SEC8" href="#TOC1">COMPILATION ERROR CODES</a><br>  <br><a name="SEC8" href="#TOC1">COMPILATION ERROR CODES</a><br>
629  <P>  <P>
# Line 652  out of use. To avoid confusion, they hav Line 661  out of use. To avoid confusion, they hav
661    26  malformed number or name after (?(    26  malformed number or name after (?(
662    27  conditional group contains more than two branches    27  conditional group contains more than two branches
663    28  assertion expected after (?(    28  assertion expected after (?(
664    29  (?R or (?digits must be followed by )    29  (?R or (?[+-]digits must be followed by )
665    30  unknown POSIX class name    30  unknown POSIX class name
666    31  POSIX collating elements are not supported    31  POSIX collating elements are not supported
667    32  this version of PCRE is not compiled with PCRE_UTF8 support    32  this version of PCRE is not compiled with PCRE_UTF8 support
# Line 673  out of use. To avoid confusion, they hav Line 682  out of use. To avoid confusion, they hav
682    47  unknown property name after \P or \p    47  unknown property name after \P or \p
683    48  subpattern name is too long (maximum 32 characters)    48  subpattern name is too long (maximum 32 characters)
684    49  too many named subpatterns (maximum 10,000)    49  too many named subpatterns (maximum 10,000)
685    50  repeated subpattern is too long    50  [this code is not in use]
686    51  octal value is greater than \377 (not in UTF-8 mode)    51  octal value is greater than \377 (not in UTF-8 mode)
687    52  internal error: overran compiling workspace    52  internal error: overran compiling workspace
688    53  internal error: previously-checked referenced subpattern not found    53  internal error: previously-checked referenced subpattern not found
689    54  DEFINE group contains more than one branch    54  DEFINE group contains more than one branch
690    55  repeating a DEFINE group is not allowed    55  repeating a DEFINE group is not allowed
691    56  inconsistent NEWLINE options"    56  inconsistent NEWLINE options"
692      57  \g is not followed by a braced name or an optionally braced
693            non-zero number
694      58  (?+ or (?- or (?(+ or (?(- must be followed by a non-zero number
695  </PRE>  </PRE>
696  </P>  </P>
697  <br><a name="SEC9" href="#TOC1">STUDYING A PATTERN</a><br>  <br><a name="SEC9" href="#TOC1">STUDYING A PATTERN</a><br>
# Line 737  bytes is created. Line 749  bytes is created.
749  <a name="localesupport"></a></P>  <a name="localesupport"></a></P>
750  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>  <br><a name="SEC10" href="#TOC1">LOCALE SUPPORT</a><br>
751  <P>  <P>
752  PCRE handles caseless matching, and determines whether characters are letters  PCRE handles caseless matching, and determines whether characters are letters,
753  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
754  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
755  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
756  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
757  support. The use of locales with Unicode is discouraged.  support. The use of locales with Unicode is discouraged. If you are handling
758  </P>  characters with codes greater than 128, you should either use UTF-8 and
759  <P>  Unicode, or use locales, but not try to mix the two.
760  An internal set of tables is created in the default C locale when PCRE is  </P>
761  built. This is used when the final argument of <b>pcre_compile()</b> is NULL,  <P>
762  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
763  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.
764  default. As more and more applications change to using Unicode, the need for  Normally, the internal tables recognize only ASCII characters. However, when
765  this locale support is expected to die away.  PCRE is built, it is possible to cause the internal tables to be rebuilt in the
766    default "C" locale of the local system, which may cause them to be different.
767    </P>
768    <P>
769    The internal tables can always be overridden by tables supplied by the
770    application that calls PCRE. These may be created in a different locale from
771    the default. As more and more applications change to using Unicode, the need
772    for this locale support is expected to die away.
773  </P>  </P>
774  <P>  <P>
775  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 764  the following code could be used: Line 783  the following code could be used:
783    tables = pcre_maketables();    tables = pcre_maketables();
784    re = pcre_compile(..., tables);    re = pcre_compile(..., tables);
785  </pre>  </pre>
786    The locale name "fr_FR" is used on Linux and other Unix-like systems; if you
787    are using Windows, the name for the French locale is "french".
788    </P>
789    <P>
790  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
791  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
792  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 871  table indicating a fixed set of bytes fo Line 894  table indicating a fixed set of bytes fo
894  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
895  fourth argument should point to an <b>unsigned char *</b> variable.  fourth argument should point to an <b>unsigned char *</b> variable.
896  <pre>  <pre>
897      PCRE_INFO_JCHANGED
898    </pre>
899    Return 1 if the (?J) option setting is used in the pattern, otherwise 0. The
900    fourth argument should point to an <b>int</b> variable. The (?J) internal option
901    setting changes the local PCRE_DUPNAMES option.
902    <pre>
903    PCRE_INFO_LASTLITERAL    PCRE_INFO_LASTLITERAL
904  </pre>  </pre>
905  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 922  When writing code to extract data from n Line 951  When writing code to extract data from n
951  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
952  different for each compiled pattern.  different for each compiled pattern.
953  <pre>  <pre>
954      PCRE_INFO_OKPARTIAL
955    </pre>
956    Return 1 if the pattern can be used for partial matching, otherwise 0. The
957    fourth argument should point to an <b>int</b> variable. The
958    <a href="pcrepartial.html"><b>pcrepartial</b></a>
959    documentation lists the restrictions that apply to patterns when partial
960    matching is used.
961    <pre>
962    PCRE_INFO_OPTIONS    PCRE_INFO_OPTIONS
963  </pre>  </pre>
964  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
965  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
966  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
967  top-level option settings within the pattern itself.  top-level option settings at the start of the pattern itself. In other words,
968    they are the options that will be in force when matching starts. For example,
969    if the pattern /(?im)abc(?-i)d/ is compiled with the PCRE_EXTENDED option, the
970    result is PCRE_CASELESS, PCRE_MULTILINE, and PCRE_EXTENDED.
971  </P>  </P>
972  <P>  <P>
973  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 1155  matching time. Line 1195  matching time.
1195    PCRE_NEWLINE_CR    PCRE_NEWLINE_CR
1196    PCRE_NEWLINE_LF    PCRE_NEWLINE_LF
1197    PCRE_NEWLINE_CRLF    PCRE_NEWLINE_CRLF
1198      PCRE_NEWLINE_ANYCRLF
1199    PCRE_NEWLINE_ANY    PCRE_NEWLINE_ANY
1200  </pre>  </pre>
1201  These options override the newline definition that was chosen or defaulted when  These options override the newline definition that was chosen or defaulted when
# Line 1162  the pattern was compiled. For details, s Line 1203  the pattern was compiled. For details, s
1203  <b>pcre_compile()</b> above. During matching, the newline choice affects the  <b>pcre_compile()</b> above. During matching, the newline choice affects the
1204  behaviour of the dot, circumflex, and dollar metacharacters. It may also alter  behaviour of the dot, circumflex, and dollar metacharacters. It may also alter
1205  the way the match position is advanced after a match failure for an unanchored  the way the match position is advanced after a match failure for an unanchored
1206  pattern. When PCRE_NEWLINE_CRLF or PCRE_NEWLINE_ANY is set, and a match attempt  pattern. When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is
1207  fails when the current position is at a CRLF sequence, the match position is  set, and a match attempt fails when the current position is at a CRLF sequence,
1208  advanced by two characters instead of one, in other words, to after the CRLF.  the match position is advanced by two characters instead of one, in other
1209    words, to after the CRLF.
1210  <pre>  <pre>
1211    PCRE_NOTBOL    PCRE_NOTBOL
1212  </pre>  </pre>
# Line 1208  code that demonstrates how to do this in Line 1250  code that demonstrates how to do this in
1250  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
1251  string is automatically checked when <b>pcre_exec()</b> is subsequently called.  string is automatically checked when <b>pcre_exec()</b> is subsequently called.
1252  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
1253  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
1254  <b>pcre_exec()</b> returns the error PCRE_ERROR_BADUTF8. If <i>startoffset</i>  strings in the
1255  contains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned.  <a href="pcre.html#utf8strings">section on UTF-8 support</a>
1256    in the main
1257    <a href="pcre.html"><b>pcre</b></a>
1258    page. If an invalid UTF-8 sequence of bytes is found, <b>pcre_exec()</b> returns
1259    the error PCRE_ERROR_BADUTF8. If <i>startoffset</i> contains an invalid value,
1260    PCRE_ERROR_BADUTF8_OFFSET is returned.
1261  </P>  </P>
1262  <P>  <P>
1263  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 1448  The internal recursion limit, as specifi Line 1495  The internal recursion limit, as specifi
1495  field in a <b>pcre_extra</b> structure (or defaulted) was reached. See the  field in a <b>pcre_extra</b> structure (or defaulted) was reached. See the
1496  description above.  description above.
1497  <pre>  <pre>
   PCRE_ERROR_NULLWSLIMIT    (-22)  
 </pre>  
 When a group that can match an empty substring is repeated with an unbounded  
 upper limit, the subject position at the start of the group must be remembered,  
 so that a test for an empty string can be made when the end of the group is  
 reached. Some workspace is required for this; if it runs out, this error is  
 given.  
 <pre>  
1498    PCRE_ERROR_BADNEWLINE     (-23)    PCRE_ERROR_BADNEWLINE     (-23)
1499  </pre>  </pre>
1500  An invalid combination of PCRE_NEWLINE_<i>xxx</i> options was given.  An invalid combination of PCRE_NEWLINE_<i>xxx</i> options was given.
1501  </P>  </P>
1502  <P>  <P>
1503  Error numbers -16 to -20 are not used by <b>pcre_exec()</b>.  Error numbers -16 to -20 and -22 are not used by <b>pcre_exec()</b>.
1504  </P>  </P>
1505  <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>
1506  <P>  <P>
# Line 1607  translation table. Line 1646  translation table.
1646  </P>  </P>
1647  <P>  <P>
1648  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
1649  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
1650  appropriate.  appropriate. <b>NOTE:</b> If PCRE_DUPNAMES is set and there are duplicate names,
1651    the behaviour may not be what you want (see the next section).
1652  </P>  </P>
1653  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>
1654  <P>  <P>
# Line 1621  are not required to be unique. Normally, Line 1661  are not required to be unique. Normally,
1661  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
1662  example is shown in the  example is shown in the
1663  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
1664  documentation. When duplicates are present, <b>pcre_copy_named_substring()</b>  documentation.
1665  and <b>pcre_get_named_substring()</b> return the first substring corresponding  </P>
1666  to the given name that is set. If none are set, an empty string is returned.  <P>
1667  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
1668  associated with the name, but it is not defined which it is.  <b>pcre_get_named_substring()</b> return the first substring corresponding to
1669  <br>  the given name that is set. If none are set, PCRE_ERROR_NOSUBSTRING (-7) is
1670  <br>  returned; no data is returned. The <b>pcre_get_stringnumber()</b> function
1671    returns one of the numbers that are associated with the name, but it is not
1672    defined which it is.
1673    </P>
1674    <P>
1675  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,
1676  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
1677  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
# Line 1839  Cambridge CB2 3QH, England. Line 1883  Cambridge CB2 3QH, England.
1883  </P>  </P>
1884  <br><a name="SEC22" href="#TOC1">REVISION</a><br>  <br><a name="SEC22" href="#TOC1">REVISION</a><br>
1885  <P>  <P>
1886  Last updated: 06 March 2007  Last updated: 09 August 2007
1887  <br>  <br>
1888  Copyright &copy; 1997-2007 University of Cambridge.  Copyright &copy; 1997-2007 University of Cambridge.
1889  <br>  <br>

Legend:
Removed from v.111  
changed lines
  Added in v.211

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12