/[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 345 by ph10, Mon Apr 28 15:10:02 2008 UTC revision 429 by ph10, Tue Sep 1 16:10:16 2009 UTC
# Line 164  Applications can use these to include su Line 164  Applications can use these to include su
164  The functions <b>pcre_compile()</b>, <b>pcre_compile2()</b>, <b>pcre_study()</b>,  The functions <b>pcre_compile()</b>, <b>pcre_compile2()</b>, <b>pcre_study()</b>,
165  and <b>pcre_exec()</b> are used for compiling and matching regular expressions  and <b>pcre_exec()</b> are used for compiling and matching regular expressions
166  in a Perl-compatible manner. A sample program that demonstrates the simplest  in a Perl-compatible manner. A sample program that demonstrates the simplest
167  way of using them is provided in the file called <i>pcredemo.c</i> in the source  way of using them is provided in the file called <i>pcredemo.c</i> in the PCRE
168  distribution. The  source distribution. A listing of this program is given in the
169    <a href="pcredemo.html"><b>pcredemo</b></a>
170    documentation, and the
171  <a href="pcresample.html"><b>pcresample</b></a>  <a href="pcresample.html"><b>pcresample</b></a>
172  documentation describes how to compile and run it.  documentation describes how to compile and run it.
173  </P>  </P>
# Line 333  properties is available; otherwise it is Line 335  properties is available; otherwise it is
335  </pre>  </pre>
336  The output is an integer whose value specifies the default character sequence  The output is an integer whose value specifies the default character sequence
337  that is recognized as meaning "newline". The four values that are supported  that is recognized as meaning "newline". The four values that are supported
338  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.
339  default should normally be the standard sequence for your operating system.  Though they are derived from ASCII, the same values are returned in EBCDIC
340    environments. The default should normally correspond to the standard sequence
341    for your operating system.
342  <pre>  <pre>
343    PCRE_CONFIG_BSR    PCRE_CONFIG_BSR
344  </pre>  </pre>
# Line 361  documentation. Line 365  documentation.
365  <pre>  <pre>
366    PCRE_CONFIG_MATCH_LIMIT    PCRE_CONFIG_MATCH_LIMIT
367  </pre>  </pre>
368  The output is an integer that gives the default limit for the number of  The output is a long integer that gives the default limit for the number of
369  internal matching function calls in a <b>pcre_exec()</b> execution. Further  internal matching function calls in a <b>pcre_exec()</b> execution. Further
370  details are given with <b>pcre_exec()</b> below.  details are given with <b>pcre_exec()</b> below.
371  <pre>  <pre>
372    PCRE_CONFIG_MATCH_LIMIT_RECURSION    PCRE_CONFIG_MATCH_LIMIT_RECURSION
373  </pre>  </pre>
374  The output is an integer that gives the default limit for the depth of  The output is a long integer that gives the default limit for the depth of
375  recursion when calling the internal matching function in a <b>pcre_exec()</b>  recursion when calling the internal matching function in a <b>pcre_exec()</b>
376  execution. Further details are given with <b>pcre_exec()</b> below.  execution. Further details are given with <b>pcre_exec()</b> below.
377  <pre>  <pre>
# Line 414  argument, which is an address (see below Line 418  argument, which is an address (see below
418  <P>  <P>
419  The <i>options</i> argument contains various bit settings that affect the  The <i>options</i> argument contains various bit settings that affect the
420  compilation. It should be zero if no options are required. The available  compilation. It should be zero if no options are required. The available
421  options are described below. Some of them, in particular, those that are  options are described below. Some of them (in particular, those that are
422  compatible with Perl, can also be set and unset from within the pattern (see  compatible with Perl, but also some others) can also be set and unset from
423  the detailed description in the  within the pattern (see the detailed description in the
424  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
425  documentation). For these options, the contents of the <i>options</i> argument  documentation). For those options that can be different in different parts of
426  specifies their initial settings at the start of compilation and execution. The  the pattern, the contents of the <i>options</i> argument specifies their initial
427  PCRE_ANCHORED and PCRE_NEWLINE_<i>xxx</i> options can be set at the time of  settings at the start of compilation and execution. The PCRE_ANCHORED and
428  matching as well as at compile time.  PCRE_NEWLINE_<i>xxx</i> options can be set at the time of matching as well as at
429    compile time.
430  </P>  </P>
431  <P>  <P>
432  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.
# Line 1013  different for each compiled pattern. Line 1018  different for each compiled pattern.
1018    PCRE_INFO_OKPARTIAL    PCRE_INFO_OKPARTIAL
1019  </pre>  </pre>
1020  Return 1 if the pattern can be used for partial matching, otherwise 0. The  Return 1 if the pattern can be used for partial matching, otherwise 0. The
1021  fourth argument should point to an <b>int</b> variable. The  fourth argument should point to an <b>int</b> variable. From release 8.00, this
1022    always returns 1, because the restrictions that previously applied to partial
1023    matching have been lifted. The
1024  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
1025  documentation lists the restrictions that apply to patterns when partial  documentation gives details of partial matching.
 matching is used.  
1026  <pre>  <pre>
1027    PCRE_INFO_OPTIONS    PCRE_INFO_OPTIONS
1028  </pre>  </pre>
# Line 1242  Option bits for <b>pcre_exec()</b> Line 1248  Option bits for <b>pcre_exec()</b>
1248  <P>  <P>
1249  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
1250  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,
1251  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK and PCRE_PARTIAL.  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_START_OPTIMIZE,
1252    PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_SOFT, and PCRE_PARTIAL_HARD.
1253  <pre>  <pre>
1254    PCRE_ANCHORED    PCRE_ANCHORED
1255  </pre>  </pre>
# Line 1332  when using the /g modifier. It is possib Line 1339  when using the /g modifier. It is possib
1339  matching a null string by first trying the match again at the same offset with  matching a null string by first trying the match again at the same offset with
1340  PCRE_NOTEMPTY and PCRE_ANCHORED, and then if that fails by advancing the  PCRE_NOTEMPTY and PCRE_ANCHORED, and then if that fails by advancing the
1341  starting offset (see below) and trying an ordinary match again. There is some  starting offset (see below) and trying an ordinary match again. There is some
1342  code that demonstrates how to do this in the <i>pcredemo.c</i> sample program.  code that demonstrates how to do this in the
1343    <a href="pcredemo.html"><b>pcredemo</b></a>
1344    sample program.
1345    <pre>
1346      PCRE_NO_START_OPTIMIZE
1347    </pre>
1348    There are a number of optimizations that <b>pcre_exec()</b> uses at the start of
1349    a match, in order to speed up the process. For example, if it is known that a
1350    match must start with a specific character, it searches the subject for that
1351    character, and fails immediately if it cannot find it, without actually running
1352    the main matching function. When callouts are in use, these optimizations can
1353    cause them to be skipped. This option disables the "start-up" optimizations,
1354    causing performance to suffer, but ensuring that the callouts do occur.
1355  <pre>  <pre>
1356    PCRE_NO_UTF8_CHECK    PCRE_NO_UTF8_CHECK
1357  </pre>  </pre>
# Line 1359  PCRE_NO_UTF8_CHECK is set, the effect of Line 1378  PCRE_NO_UTF8_CHECK is set, the effect of
1378  subject, or a value of <i>startoffset</i> that does not point to the start of a  subject, or a value of <i>startoffset</i> that does not point to the start of a
1379  UTF-8 character, is undefined. Your program may crash.  UTF-8 character, is undefined. Your program may crash.
1380  <pre>  <pre>
1381    PCRE_PARTIAL    PCRE_PARTIAL_HARD
1382      PCRE_PARTIAL_SOFT
1383  </pre>  </pre>
1384  This option turns on the partial matching feature. If the subject string fails  These options turn on the partial matching feature. For backwards
1385  to match the pattern, but at some point during the matching process the end of  compatibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial match
1386  the subject was reached (that is, the subject partially matches the pattern and  occurs if the end of the subject string is reached successfully, but there are
1387  the failure to match occurred only because there were not enough subject  not enough subject characters to complete the match. If this happens when
1388  characters), <b>pcre_exec()</b> returns PCRE_ERROR_PARTIAL instead of  PCRE_PARTIAL_HARD is set, <b>pcre_exec()</b> immediately returns
1389  PCRE_ERROR_NOMATCH. When PCRE_PARTIAL is used, there are restrictions on what  PCRE_ERROR_PARTIAL. Otherwise, if PCRE_PARTIAL_SOFT is set, matching continues
1390  may appear in the pattern. These are discussed in the  by testing any other alternatives. Only if they all fail is PCRE_ERROR_PARTIAL
1391    returned (instead of PCRE_ERROR_NOMATCH). The portion of the string that
1392    provided the partial match is set as the first matching string. There is a more
1393    detailed discussion in the
1394  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
1395  documentation.  documentation.
1396  </P>  </P>
# Line 1376  The string to be matched by <b>pcre_exec Line 1399  The string to be matched by <b>pcre_exec
1399  </b><br>  </b><br>
1400  <P>  <P>
1401  The subject string is passed to <b>pcre_exec()</b> as a pointer in  The subject string is passed to <b>pcre_exec()</b> as a pointer in
1402  <i>subject</i>, a length in <i>length</i>, and a starting byte offset in  <i>subject</i>, a length (in bytes) in <i>length</i>, and a starting byte offset
1403  <i>startoffset</i>. In UTF-8 mode, the byte offset must point to the start of a  in <i>startoffset</i>. In UTF-8 mode, the byte offset must point to the start of
1404  UTF-8 character. Unlike the pattern string, the subject may contain binary zero  a UTF-8 character. Unlike the pattern string, the subject may contain binary
1405  bytes. When the starting offset is zero, the search for a match starts at the  zero bytes. When the starting offset is zero, the search for a match starts at
1406  beginning of the subject, and this is by far the most common case.  the beginning of the subject, and this is by far the most common case.
1407  </P>  </P>
1408  <P>  <P>
1409  A non-zero starting offset is useful when searching for another match in the  A non-zero starting offset is useful when searching for another match in the
# Line 1418  a fragment of a pattern that picks out a Line 1441  a fragment of a pattern that picks out a
1441  kinds of parenthesized subpattern that do not cause substrings to be captured.  kinds of parenthesized subpattern that do not cause substrings to be captured.
1442  </P>  </P>
1443  <P>  <P>
1444  Captured substrings are returned to the caller via a vector of integer offsets  Captured substrings are returned to the caller via a vector of integers whose
1445  whose address is passed in <i>ovector</i>. The number of elements in the vector  address is passed in <i>ovector</i>. The number of elements in the vector is
1446  is passed in <i>ovecsize</i>, which must be a non-negative number. <b>Note</b>:  passed in <i>ovecsize</i>, which must be a non-negative number. <b>Note</b>: this
1447  this argument is NOT the size of <i>ovector</i> in bytes.  argument is NOT the size of <i>ovector</i> in bytes.
1448  </P>  </P>
1449  <P>  <P>
1450  The first two-thirds of the vector is used to pass back captured substrings,  The first two-thirds of the vector is used to pass back captured substrings,
1451  each substring using a pair of integers. The remaining third of the vector is  each substring using a pair of integers. The remaining third of the vector is
1452  used as workspace by <b>pcre_exec()</b> while matching capturing subpatterns,  used as workspace by <b>pcre_exec()</b> while matching capturing subpatterns,
1453  and is not available for passing back information. The length passed in  and is not available for passing back information. The number passed in
1454  <i>ovecsize</i> should always be a multiple of three. If it is not, it is  <i>ovecsize</i> should always be a multiple of three. If it is not, it is
1455  rounded down.  rounded down.
1456  </P>  </P>
1457  <P>  <P>
1458  When a match is successful, information about captured substrings is returned  When a match is successful, information about captured substrings is returned
1459  in pairs of integers, starting at the beginning of <i>ovector</i>, and  in pairs of integers, starting at the beginning of <i>ovector</i>, and
1460  continuing up to two-thirds of its length at the most. The first element of a  continuing up to two-thirds of its length at the most. The first element of
1461  pair is set to the offset of the first character in a substring, and the second  each pair is set to the byte offset of the first character in a substring, and
1462  is set to the offset of the first character after the end of a substring. The  the second is set to the byte offset of the first character after the end of a
1463  first pair, <i>ovector[0]</i> and <i>ovector[1]</i>, identify the portion of the  substring. <b>Note</b>: these values are always byte offsets, even in UTF-8
1464  subject string matched by the entire pattern. The next pair is used for the  mode. They are not character counts.
1465  first capturing subpattern, and so on. The value returned by <b>pcre_exec()</b>  </P>
1466  is one more than the highest numbered pair that has been set. For example, if  <P>
1467  two substrings have been captured, the returned value is 3. If there are no  The first pair of integers, <i>ovector[0]</i> and <i>ovector[1]</i>, identify the
1468  capturing subpatterns, the return value from a successful match is 1,  portion of the subject string matched by the entire pattern. The next pair is
1469  indicating that just the first pair of offsets has been set.  used for the first capturing subpattern, and so on. The value returned by
1470    <b>pcre_exec()</b> is one more than the highest numbered pair that has been set.
1471    For example, if two substrings have been captured, the returned value is 3. If
1472    there are no capturing subpatterns, the return value from a successful match is
1473    1, indicating that just the first pair of offsets has been set.
1474  </P>  </P>
1475  <P>  <P>
1476  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
# Line 1452  string that it matched that is returned. Line 1479  string that it matched that is returned.
1479  <P>  <P>
1480  If the vector is too small to hold all the captured substring offsets, it is  If the vector is too small to hold all the captured substring offsets, it is
1481  used as far as possible (up to two-thirds of its length), and the function  used as far as possible (up to two-thirds of its length), and the function
1482  returns a value of zero. In particular, if the substring offsets are not of  returns a value of zero. If the substring offsets are not of interest,
1483  interest, <b>pcre_exec()</b> may be called with <i>ovector</i> passed as NULL and  <b>pcre_exec()</b> may be called with <i>ovector</i> passed as NULL and
1484  <i>ovecsize</i> as zero. However, if the pattern contains back references and  <i>ovecsize</i> as zero. However, if the pattern contains back references and
1485  the <i>ovector</i> is not big enough to remember the related substrings, PCRE  the <i>ovector</i> is not big enough to remember the related substrings, PCRE
1486  has to get additional memory for use during matching. Thus it is usually  has to get additional memory for use during matching. Thus it is usually
# Line 1564  documentation for details of partial mat Line 1591  documentation for details of partial mat
1591  <pre>  <pre>
1592    PCRE_ERROR_BADPARTIAL     (-13)    PCRE_ERROR_BADPARTIAL     (-13)
1593  </pre>  </pre>
1594  The PCRE_PARTIAL option was used with a compiled pattern containing items that  This code is no longer in use. It was formerly returned when the PCRE_PARTIAL
1595  are not supported for partial matching. See the  option was used with a compiled pattern containing items that were not
1596  <a href="pcrepartial.html"><b>pcrepartial</b></a>  supported for partial matching. From release 8.00 onwards, there are no
1597  documentation for details of partial matching.  restrictions on partial matching.
1598  <pre>  <pre>
1599    PCRE_ERROR_INTERNAL       (-14)    PCRE_ERROR_INTERNAL       (-14)
1600  </pre>  </pre>
# Line 1739  then call <b>pcre_copy_substring()</b> o Line 1766  then call <b>pcre_copy_substring()</b> o
1766  appropriate. <b>NOTE:</b> If PCRE_DUPNAMES is set and there are duplicate names,  appropriate. <b>NOTE:</b> If PCRE_DUPNAMES is set and there are duplicate names,
1767  the behaviour may not be what you want (see the next section).  the behaviour may not be what you want (see the next section).
1768  </P>  </P>
1769    <P>
1770    <b>Warning:</b> If the pattern uses the "(?|" feature to set up multiple
1771    subpatterns with the same number, you cannot use names to distinguish them,
1772    because names are not included in the compiled code. The matching process uses
1773    only numbers.
1774    </P>
1775  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>  <br><a name="SEC17" href="#TOC1">DUPLICATE SUBPATTERN NAMES</a><br>
1776  <P>  <P>
1777  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>  <b>int pcre_get_stringtable_entries(const pcre *<i>code</i>,</b>
# Line 1847  Option bits for <b>pcre_dfa_exec()</b> Line 1880  Option bits for <b>pcre_dfa_exec()</b>
1880  <P>  <P>
1881  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
1882  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,  zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_<i>xxx</i>,
1883  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL,  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_HARD,
1884  PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last three of these are  PCRE_PARTIAL_SOFT, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last
1885  the same as for <b>pcre_exec()</b>, so their description is not repeated here.  four of these are exactly the same as for <b>pcre_exec()</b>, so their
1886  <pre>  description is not repeated here.
1887    PCRE_PARTIAL  <pre>
1888  </pre>    PCRE_PARTIAL_HARD
1889  This has the same general effect as it does for <b>pcre_exec()</b>, but the    PCRE_PARTIAL_SOFT
1890  details are slightly different. When PCRE_PARTIAL is set for  </pre>
1891  <b>pcre_dfa_exec()</b>, the return code PCRE_ERROR_NOMATCH is converted into  These have the same general effect as they do for <b>pcre_exec()</b>, but the
1892  PCRE_ERROR_PARTIAL if the end of the subject is reached, there have been no  details are slightly different. When PCRE_PARTIAL_HARD is set for
1893  complete matches, but there is still at least one matching possibility. The  <b>pcre_dfa_exec()</b>, it returns PCRE_ERROR_PARTIAL if the end of the subject
1894  portion of the string that provided the partial match is set as the first  is reached and there is still at least one matching possibility that requires
1895  matching string.  additional characters. This happens even if some complete matches have also
1896    been found. When PCRE_PARTIAL_SOFT is set, the return code PCRE_ERROR_NOMATCH
1897    is converted into PCRE_ERROR_PARTIAL if the end of the subject is reached,
1898    there have been no complete matches, but there is still at least one matching
1899    possibility. The portion of the string that provided the longest partial match
1900    is set as the first matching string in both cases.
1901  <pre>  <pre>
1902    PCRE_DFA_SHORTEST    PCRE_DFA_SHORTEST
1903  </pre>  </pre>
# Line 1870  matching point in the subject string. Line 1908  matching point in the subject string.
1908  <pre>  <pre>
1909    PCRE_DFA_RESTART    PCRE_DFA_RESTART
1910  </pre>  </pre>
1911  When <b>pcre_dfa_exec()</b> is called with the PCRE_PARTIAL option, and returns  When <b>pcre_dfa_exec()</b> returns a partial match, it is possible to call it
1912  a partial match, it is possible to call it again, with additional subject  again, with additional subject characters, and have it continue with the same
1913  characters, and have it continue with the same match. The PCRE_DFA_RESTART  match. The PCRE_DFA_RESTART option requests this action; when it is set, the
1914  option requests this action; when it is set, the <i>workspace</i> and  <i>workspace</i> and <i>wscount</i> options must reference the same vector as
1915  <i>wscount</i> options must reference the same vector as before because data  before because data about the match so far is left in them after a partial
1916  about the match so far is left in them after a partial match. There is more  match. There is more discussion of this facility in the
 discussion of this facility in the  
1917  <a href="pcrepartial.html"><b>pcrepartial</b></a>  <a href="pcrepartial.html"><b>pcrepartial</b></a>
1918  documentation.  documentation.
1919  </P>  </P>
# Line 1972  Cambridge CB2 3QH, England. Line 2009  Cambridge CB2 3QH, England.
2009  </P>  </P>
2010  <br><a name="SEC22" href="#TOC1">REVISION</a><br>  <br><a name="SEC22" href="#TOC1">REVISION</a><br>
2011  <P>  <P>
2012  Last updated: 12 April 2008  Last updated: 01 September 2009
2013  <br>  <br>
2014  Copyright &copy; 1997-2008 University of Cambridge.  Copyright &copy; 1997-2009 University of Cambridge.
2015  <br>  <br>
2016  <p>  <p>
2017  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.

Legend:
Removed from v.345  
changed lines
  Added in v.429

  ViewVC Help
Powered by ViewVC 1.1.5