/[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 202 by ph10, Fri Aug 3 09:44:26 2007 UTC revision 286 by ph10, Mon Dec 17 14:46:11 2007 UTC
# Line 243  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 five different conventions for indicating line breaks in  PCRE supports five different conventions for indicating line breaks in
# Line 262  default can be overridden, either when a Line 262  default can be overridden, either when a
262  matched.  matched.
263  </P>  </P>
264  <P>  <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". The choice of newline  pair of characters that indicate a line break". The choice of newline
274  convention affects the handling of the dot, circumflex, and dollar  convention affects the handling of the dot, circumflex, and dollar
275  metacharacters, the handling of #-comments in /x mode, and, when CRLF is a  metacharacters, the handling of #-comments in /x mode, and, when CRLF is a
276  recognized line ending sequence, the match position advancement for a  recognized line ending sequence, the match position advancement for a
277  non-anchored pattern. The choice of newline convention does not affect the  non-anchored pattern. There is more detail about this in the
278  interpretation of the \n or \r escape sequences.  <a href="#execoptions">section on <b>pcre_exec()</b> options</a>
279    below.
280    </P>
281    <P>
282    The choice of newline convention does not affect the interpretation of
283    the \n or \r escape sequences, nor does it affect what \R matches, which is
284    controlled in a similar way, but by separate options.
285  </P>  </P>
286  <br><a name="SEC4" href="#TOC1">MULTITHREADING</a><br>  <br><a name="SEC4" href="#TOC1">MULTITHREADING</a><br>
287  <P>  <P>
# Line 323  that is recognized as meaning "newline". Line 336  that is recognized as meaning "newline".
336  are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF, and -1 for ANY. The  are: 10 for LF, 13 for CR, 3338 for CRLF, -2 for ANYCRLF, and -1 for ANY. The
337  default should normally be the standard sequence for your operating system.  default should normally be the standard sequence for your operating system.
338  <pre>  <pre>
339      PCRE_CONFIG_BSR
340    </pre>
341    The output is an integer whose value indicates what character sequences the \R
342    escape sequence matches by default. A value of 0 means that \R matches any
343    Unicode line ending sequence; a value of 1 means that \R matches only CR, LF,
344    or CRLF. The default can be overridden when a pattern is compiled or matched.
345    <pre>
346    PCRE_CONFIG_LINK_SIZE    PCRE_CONFIG_LINK_SIZE
347  </pre>  </pre>
348  The output is an integer that contains the number of bytes used for internal  The output is an integer that contains the number of bytes used for internal
# Line 458  facility, see the Line 478  facility, see the
478  <a href="pcrecallout.html"><b>pcrecallout</b></a>  <a href="pcrecallout.html"><b>pcrecallout</b></a>
479  documentation.  documentation.
480  <pre>  <pre>
481      PCRE_BSR_ANYCRLF
482      PCRE_BSR_UNICODE
483    </pre>
484    These options (which are mutually exclusive) control what the \R escape
485    sequence matches. The choice is either to match only CR, LF, or CRLF, or to
486    match any Unicode newline sequence. The default is specified when PCRE is
487    built. It can be overridden from within the pattern, or by setting an option
488    when a compiled pattern is matched.
489    <pre>
490    PCRE_CASELESS    PCRE_CASELESS
491  </pre>  </pre>
492  If this bit is set, letters in the pattern match both upper and lower case  If this bit is set, letters in the pattern match both upper and lower case
# Line 613  page. Line 642  page.
642    PCRE_NO_UTF8_CHECK    PCRE_NO_UTF8_CHECK
643  </pre>  </pre>
644  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
645  automatically checked. If an invalid UTF-8 sequence of bytes is found,  automatically checked. There is a discussion about the
646  <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>
647  valid, and you want to skip this check for performance reasons, you can set the  in the main
648  PCRE_NO_UTF8_CHECK option. When it is set, the effect of passing an invalid  <a href="pcre.html"><b>pcre</b></a>
649  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>
650  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
651  <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
652  strings.  option. When it is set, the effect of passing an invalid UTF-8 string as a
653    pattern is undefined. It may cause your program to crash. Note that this option
654    can also be passed to <b>pcre_exec()</b> and <b>pcre_dfa_exec()</b>, to suppress
655    the UTF-8 validity checking of subject strings.
656  </P>  </P>
657  <br><a name="SEC8" href="#TOC1">COMPILATION ERROR CODES</a><br>  <br><a name="SEC8" href="#TOC1">COMPILATION ERROR CODES</a><br>
658  <P>  <P>
# Line 685  out of use. To avoid confusion, they hav Line 717  out of use. To avoid confusion, they hav
717    53  internal error: previously-checked referenced subpattern not found    53  internal error: previously-checked referenced subpattern not found
718    54  DEFINE group contains more than one branch    54  DEFINE group contains more than one branch
719    55  repeating a DEFINE group is not allowed    55  repeating a DEFINE group is not allowed
720    56  inconsistent NEWLINE options"    56  inconsistent NEWLINE options
721    57  \g is not followed by a braced name or an optionally braced    57  \g is not followed by a braced name or an optionally braced
722          non-zero number          non-zero number
723    58  (?+ or (?- or (?(+ or (?(- must be followed by a non-zero number    58  (?+ or (?- or (?(+ or (?(- must be followed by a non-zero number
# Line 891  table indicating a fixed set of bytes fo Line 923  table indicating a fixed set of bytes fo
923  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
924  fourth argument should point to an <b>unsigned char *</b> variable.  fourth argument should point to an <b>unsigned char *</b> variable.
925  <pre>  <pre>
926      PCRE_INFO_HASCRORLF
927    </pre>
928    Return 1 if the pattern contains any explicit matches for CR or LF characters,
929    otherwise 0. The fourth argument should point to an <b>int</b> variable. An
930    explicit match is either a literal CR or LF character, or \r or \n.
931    <pre>
932    PCRE_INFO_JCHANGED    PCRE_INFO_JCHANGED
933  </pre>  </pre>
934  Return 1 if the (?J) option setting is used in the pattern, otherwise 0. The  Return 1 if the (?J) or (?-J) option setting is used in the pattern, otherwise
935  fourth argument should point to an <b>int</b> variable. The (?J) internal option  0. The fourth argument should point to an <b>int</b> variable. (?J) and
936  setting changes the local PCRE_DUPNAMES option.  (?-J) set and unset the local PCRE_DUPNAMES option, respectively.
937  <pre>  <pre>
938    PCRE_INFO_LASTLITERAL    PCRE_INFO_LASTLITERAL
939  </pre>  </pre>
# Line 1173  the external tables might be at a differ Line 1211  the external tables might be at a differ
1211  called. See the  called. See the
1212  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>  <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
1213  documentation for a discussion of saving compiled patterns for later use.  documentation for a discussion of saving compiled patterns for later use.
1214  </P>  <a name="execoptions"></a></P>
1215  <br><b>  <br><b>
1216  Option bits for <b>pcre_exec()</b>  Option bits for <b>pcre_exec()</b>
1217  </b><br>  </b><br>
# Line 1189  matching position. If a pattern was comp Line 1227  matching position. If a pattern was comp
1227  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
1228  matching time.  matching time.
1229  <pre>  <pre>
1230      PCRE_BSR_ANYCRLF
1231      PCRE_BSR_UNICODE
1232    </pre>
1233    These options (which are mutually exclusive) control what the \R escape
1234    sequence matches. The choice is either to match only CR, LF, or CRLF, or to
1235    match any Unicode newline sequence. These options override the choice that was
1236    made or defaulted when the pattern was compiled.
1237    <pre>
1238    PCRE_NEWLINE_CR    PCRE_NEWLINE_CR
1239    PCRE_NEWLINE_LF    PCRE_NEWLINE_LF
1240    PCRE_NEWLINE_CRLF    PCRE_NEWLINE_CRLF
# Line 1200  the pattern was compiled. For details, s Line 1246  the pattern was compiled. For details, s
1246  <b>pcre_compile()</b> above. During matching, the newline choice affects the  <b>pcre_compile()</b> above. During matching, the newline choice affects the
1247  behaviour of the dot, circumflex, and dollar metacharacters. It may also alter  behaviour of the dot, circumflex, and dollar metacharacters. It may also alter
1248  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
1249  pattern. When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is  pattern.
1250  set, and a match attempt fails when the current position is at a CRLF sequence,  </P>
1251  the match position is advanced by two characters instead of one, in other  <P>
1252  words, to after the CRLF.  When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is set, and a
1253    match attempt for an unanchored pattern fails when the current position is at a
1254    CRLF sequence, and the pattern contains no explicit matches for CR or LF
1255    characters, the match position is advanced by two characters instead of one, in
1256    other words, to after the CRLF.
1257    </P>
1258    <P>
1259    The above rule is a compromise that makes the most common cases work as
1260    expected. For example, if the pattern is .+A (and the PCRE_DOTALL option is not
1261    set), it does not match the string "\r\nA" because, after failing at the
1262    start, it skips both the CR and the LF before retrying. However, the pattern
1263    [\r\n]A does match that string, because it contains an explicit CR or LF
1264    reference, and so advances only by one character after the first failure.
1265    </P>
1266    <P>
1267    An explicit match for CR of LF is either a literal appearance of one of those
1268    characters, or one of the \r or \n escape sequences. Implicit matches such as
1269    [^X] do not count, nor does \s (which includes CR and LF in the characters
1270    that it matches).
1271    </P>
1272    <P>
1273    Notwithstanding the above, anomalous effects may still occur when CRLF is a
1274    valid newline sequence and explicit \r or \n escapes appear in the pattern.
1275  <pre>  <pre>
1276    PCRE_NOTBOL    PCRE_NOTBOL
1277  </pre>  </pre>
# Line 1247  code that demonstrates how to do this in Line 1315  code that demonstrates how to do this in
1315  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
1316  string is automatically checked when <b>pcre_exec()</b> is subsequently called.  string is automatically checked when <b>pcre_exec()</b> is subsequently called.
1317  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
1318  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
1319  <b>pcre_exec()</b> returns the error PCRE_ERROR_BADUTF8. If <i>startoffset</i>  strings in the
1320  contains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned.  <a href="pcre.html#utf8strings">section on UTF-8 support</a>
1321    in the main
1322    <a href="pcre.html"><b>pcre</b></a>
1323    page. If an invalid UTF-8 sequence of bytes is found, <b>pcre_exec()</b> returns
1324    the error PCRE_ERROR_BADUTF8. If <i>startoffset</i> contains an invalid value,
1325    PCRE_ERROR_BADUTF8_OFFSET is returned.
1326  </P>  </P>
1327  <P>  <P>
1328  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 1653  are not required to be unique. Normally, Line 1726  are not required to be unique. Normally,
1726  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
1727  example is shown in the  example is shown in the
1728  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
1729  documentation. When duplicates are present, <b>pcre_copy_named_substring()</b>  documentation.
1730  and <b>pcre_get_named_substring()</b> return the first substring corresponding  </P>
1731  to the given name that is set. If none are set, an empty string is returned.  <P>
1732  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
1733  associated with the name, but it is not defined which it is.  <b>pcre_get_named_substring()</b> return the first substring corresponding to
1734  <br>  the given name that is set. If none are set, PCRE_ERROR_NOSUBSTRING (-7) is
1735  <br>  returned; no data is returned. The <b>pcre_get_stringnumber()</b> function
1736    returns one of the numbers that are associated with the name, but it is not
1737    defined which it is.
1738    </P>
1739    <P>
1740  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,
1741  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
1742  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 1871  Cambridge CB2 3QH, England. Line 1948  Cambridge CB2 3QH, England.
1948  </P>  </P>
1949  <br><a name="SEC22" href="#TOC1">REVISION</a><br>  <br><a name="SEC22" href="#TOC1">REVISION</a><br>
1950  <P>  <P>
1951  Last updated: 30 July 2007  Last updated: 27 November 2007
1952  <br>  <br>
1953  Copyright &copy; 1997-2007 University of Cambridge.  Copyright &copy; 1997-2007 University of Cambridge.
1954  <br>  <br>

Legend:
Removed from v.202  
changed lines
  Added in v.286

  ViewVC Help
Powered by ViewVC 1.1.5