1482 |
50 [this code is not in use] |
50 [this code is not in use] |
1483 |
51 octal value is greater than \377 (not in UTF-8 mode) |
51 octal value is greater than \377 (not in UTF-8 mode) |
1484 |
52 internal error: overran compiling workspace |
52 internal error: overran compiling workspace |
1485 |
53 internal error: previously-checked referenced subpattern not |
53 internal error: previously-checked referenced subpattern |
1486 |
found |
not found |
1487 |
54 DEFINE group contains more than one branch |
54 DEFINE group contains more than one branch |
1488 |
55 repeating a DEFINE group is not allowed |
55 repeating a DEFINE group is not allowed |
1489 |
56 inconsistent NEWLINE options |
56 inconsistent NEWLINE options |
1496 |
62 subpattern name expected |
62 subpattern name expected |
1497 |
63 digit expected after (?+ |
63 digit expected after (?+ |
1498 |
64 ] is an invalid data character in JavaScript compatibility mode |
64 ] is an invalid data character in JavaScript compatibility mode |
1499 |
65 different names for subpatterns of the same number are not |
65 different names for subpatterns of the same number are |
1500 |
allowed |
not allowed |
1501 |
66 (*MARK) must have an argument |
66 (*MARK) must have an argument |
1502 |
67 this version of PCRE is not compiled with PCRE_UCP support |
67 this version of PCRE is not compiled with PCRE_UCP support |
1503 |
|
|
1559 |
bytes is created. This speeds up finding a position in the subject at |
bytes is created. This speeds up finding a position in the subject at |
1560 |
which to start matching. |
which to start matching. |
1561 |
|
|
1562 |
|
The two optimizations just described can be disabled by setting the |
1563 |
|
PCRE_NO_START_OPTIMIZE option when calling pcre_exec() or |
1564 |
|
pcre_dfa_exec(). You might want to do this if your pattern contains |
1565 |
|
callouts, or make use of (*MARK), and you make use of these in cases |
1566 |
|
where matching fails. See the discussion of PCRE_NO_START_OPTIMIZE |
1567 |
|
below. |
1568 |
|
|
1569 |
|
|
1570 |
LOCALE SUPPORT |
LOCALE SUPPORT |
1571 |
|
|
1572 |
PCRE handles caseless matching, and determines whether characters are |
PCRE handles caseless matching, and determines whether characters are |
1573 |
letters, digits, or whatever, by reference to a set of tables, indexed |
letters, digits, or whatever, by reference to a set of tables, indexed |
1574 |
by character value. When running in UTF-8 mode, this applies only to |
by character value. When running in UTF-8 mode, this applies only to |
1575 |
characters with codes less than 128. By default, higher-valued codes |
characters with codes less than 128. By default, higher-valued codes |
1576 |
never match escapes such as \w or \d, but they can be tested with \p if |
never match escapes such as \w or \d, but they can be tested with \p if |
1577 |
PCRE is built with Unicode character property support. Alternatively, |
PCRE is built with Unicode character property support. Alternatively, |
1578 |
the PCRE_UCP option can be set at compile time; this causes \w and |
the PCRE_UCP option can be set at compile time; this causes \w and |
1579 |
friends to use Unicode property support instead of built-in tables. The |
friends to use Unicode property support instead of built-in tables. The |
1580 |
use of locales with Unicode is discouraged. If you are handling charac- |
use of locales with Unicode is discouraged. If you are handling charac- |
1581 |
ters with codes greater than 128, you should either use UTF-8 and Uni- |
ters with codes greater than 128, you should either use UTF-8 and Uni- |
1582 |
code, or use locales, but not try to mix the two. |
code, or use locales, but not try to mix the two. |
1583 |
|
|
1584 |
PCRE contains an internal set of tables that are used when the final |
PCRE contains an internal set of tables that are used when the final |
1585 |
argument of pcre_compile() is NULL. These are sufficient for many |
argument of pcre_compile() is NULL. These are sufficient for many |
1586 |
applications. Normally, the internal tables recognize only ASCII char- |
applications. Normally, the internal tables recognize only ASCII char- |
1587 |
acters. However, when PCRE is built, it is possible to cause the inter- |
acters. However, when PCRE is built, it is possible to cause the inter- |
1588 |
nal tables to be rebuilt in the default "C" locale of the local system, |
nal tables to be rebuilt in the default "C" locale of the local system, |
1589 |
which may cause them to be different. |
which may cause them to be different. |
1590 |
|
|
1591 |
The internal tables can always be overridden by tables supplied by the |
The internal tables can always be overridden by tables supplied by the |
1592 |
application that calls PCRE. These may be created in a different locale |
application that calls PCRE. These may be created in a different locale |
1593 |
from the default. As more and more applications change to using Uni- |
from the default. As more and more applications change to using Uni- |
1594 |
code, the need for this locale support is expected to die away. |
code, the need for this locale support is expected to die away. |
1595 |
|
|
1596 |
External tables are built by calling the pcre_maketables() function, |
External tables are built by calling the pcre_maketables() function, |
1597 |
which has no arguments, in the relevant locale. The result can then be |
which has no arguments, in the relevant locale. The result can then be |
1598 |
passed to pcre_compile() or pcre_exec() as often as necessary. For |
passed to pcre_compile() or pcre_exec() as often as necessary. For |
1599 |
example, to build and use tables that are appropriate for the French |
example, to build and use tables that are appropriate for the French |
1600 |
locale (where accented characters with values greater than 128 are |
locale (where accented characters with values greater than 128 are |
1601 |
treated as letters), the following code could be used: |
treated as letters), the following code could be used: |
1602 |
|
|
1603 |
setlocale(LC_CTYPE, "fr_FR"); |
setlocale(LC_CTYPE, "fr_FR"); |
1604 |
tables = pcre_maketables(); |
tables = pcre_maketables(); |
1605 |
re = pcre_compile(..., tables); |
re = pcre_compile(..., tables); |
1606 |
|
|
1607 |
The locale name "fr_FR" is used on Linux and other Unix-like systems; |
The locale name "fr_FR" is used on Linux and other Unix-like systems; |
1608 |
if you are using Windows, the name for the French locale is "french". |
if you are using Windows, the name for the French locale is "french". |
1609 |
|
|
1610 |
When pcre_maketables() runs, the tables are built in memory that is |
When pcre_maketables() runs, the tables are built in memory that is |
1611 |
obtained via pcre_malloc. It is the caller's responsibility to ensure |
obtained via pcre_malloc. It is the caller's responsibility to ensure |
1612 |
that the memory containing the tables remains available for as long as |
that the memory containing the tables remains available for as long as |
1613 |
it is needed. |
it is needed. |
1614 |
|
|
1615 |
The pointer that is passed to pcre_compile() is saved with the compiled |
The pointer that is passed to pcre_compile() is saved with the compiled |
1616 |
pattern, and the same tables are used via this pointer by pcre_study() |
pattern, and the same tables are used via this pointer by pcre_study() |
1617 |
and normally also by pcre_exec(). Thus, by default, for any single pat- |
and normally also by pcre_exec(). Thus, by default, for any single pat- |
1618 |
tern, compilation, studying and matching all happen in the same locale, |
tern, compilation, studying and matching all happen in the same locale, |
1619 |
but different patterns can be compiled in different locales. |
but different patterns can be compiled in different locales. |
1620 |
|
|
1621 |
It is possible to pass a table pointer or NULL (indicating the use of |
It is possible to pass a table pointer or NULL (indicating the use of |
1622 |
the internal tables) to pcre_exec(). Although not intended for this |
the internal tables) to pcre_exec(). Although not intended for this |
1623 |
purpose, this facility could be used to match a pattern in a different |
purpose, this facility could be used to match a pattern in a different |
1624 |
locale from the one in which it was compiled. Passing table pointers at |
locale from the one in which it was compiled. Passing table pointers at |
1625 |
run time is discussed below in the section on matching a pattern. |
run time is discussed below in the section on matching a pattern. |
1626 |
|
|
1630 |
int pcre_fullinfo(const pcre *code, const pcre_extra *extra, |
int pcre_fullinfo(const pcre *code, const pcre_extra *extra, |
1631 |
int what, void *where); |
int what, void *where); |
1632 |
|
|
1633 |
The pcre_fullinfo() function returns information about a compiled pat- |
The pcre_fullinfo() function returns information about a compiled pat- |
1634 |
tern. It replaces the obsolete pcre_info() function, which is neverthe- |
tern. It replaces the obsolete pcre_info() function, which is neverthe- |
1635 |
less retained for backwards compability (and is documented below). |
less retained for backwards compability (and is documented below). |
1636 |
|
|
1637 |
The first argument for pcre_fullinfo() is a pointer to the compiled |
The first argument for pcre_fullinfo() is a pointer to the compiled |
1638 |
pattern. The second argument is the result of pcre_study(), or NULL if |
pattern. The second argument is the result of pcre_study(), or NULL if |
1639 |
the pattern was not studied. The third argument specifies which piece |
the pattern was not studied. The third argument specifies which piece |
1640 |
of information is required, and the fourth argument is a pointer to a |
of information is required, and the fourth argument is a pointer to a |
1641 |
variable to receive the data. The yield of the function is zero for |
variable to receive the data. The yield of the function is zero for |
1642 |
success, or one of the following negative numbers: |
success, or one of the following negative numbers: |
1643 |
|
|
1644 |
PCRE_ERROR_NULL the argument code was NULL |
PCRE_ERROR_NULL the argument code was NULL |
1646 |
PCRE_ERROR_BADMAGIC the "magic number" was not found |
PCRE_ERROR_BADMAGIC the "magic number" was not found |
1647 |
PCRE_ERROR_BADOPTION the value of what was invalid |
PCRE_ERROR_BADOPTION the value of what was invalid |
1648 |
|
|
1649 |
The "magic number" is placed at the start of each compiled pattern as |
The "magic number" is placed at the start of each compiled pattern as |
1650 |
an simple check against passing an arbitrary memory pointer. Here is a |
an simple check against passing an arbitrary memory pointer. Here is a |
1651 |
typical call of pcre_fullinfo(), to obtain the length of the compiled |
typical call of pcre_fullinfo(), to obtain the length of the compiled |
1652 |
pattern: |
pattern: |
1653 |
|
|
1654 |
int rc; |
int rc; |
1659 |
PCRE_INFO_SIZE, /* what is required */ |
PCRE_INFO_SIZE, /* what is required */ |
1660 |
&length); /* where to put the data */ |
&length); /* where to put the data */ |
1661 |
|
|
1662 |
The possible values for the third argument are defined in pcre.h, and |
The possible values for the third argument are defined in pcre.h, and |
1663 |
are as follows: |
are as follows: |
1664 |
|
|
1665 |
PCRE_INFO_BACKREFMAX |
PCRE_INFO_BACKREFMAX |
1666 |
|
|
1667 |
Return the number of the highest back reference in the pattern. The |
Return the number of the highest back reference in the pattern. The |
1668 |
fourth argument should point to an int variable. Zero is returned if |
fourth argument should point to an int variable. Zero is returned if |
1669 |
there are no back references. |
there are no back references. |
1670 |
|
|
1671 |
PCRE_INFO_CAPTURECOUNT |
PCRE_INFO_CAPTURECOUNT |
1672 |
|
|
1673 |
Return the number of capturing subpatterns in the pattern. The fourth |
Return the number of capturing subpatterns in the pattern. The fourth |
1674 |
argument should point to an int variable. |
argument should point to an int variable. |
1675 |
|
|
1676 |
PCRE_INFO_DEFAULT_TABLES |
PCRE_INFO_DEFAULT_TABLES |
1677 |
|
|
1678 |
Return a pointer to the internal default character tables within PCRE. |
Return a pointer to the internal default character tables within PCRE. |
1679 |
The fourth argument should point to an unsigned char * variable. This |
The fourth argument should point to an unsigned char * variable. This |
1680 |
information call is provided for internal use by the pcre_study() func- |
information call is provided for internal use by the pcre_study() func- |
1681 |
tion. External callers can cause PCRE to use its internal tables by |
tion. External callers can cause PCRE to use its internal tables by |
1682 |
passing a NULL table pointer. |
passing a NULL table pointer. |
1683 |
|
|
1684 |
PCRE_INFO_FIRSTBYTE |
PCRE_INFO_FIRSTBYTE |
1685 |
|
|
1686 |
Return information about the first byte of any matched string, for a |
Return information about the first byte of any matched string, for a |
1687 |
non-anchored pattern. The fourth argument should point to an int vari- |
non-anchored pattern. The fourth argument should point to an int vari- |
1688 |
able. (This option used to be called PCRE_INFO_FIRSTCHAR; the old name |
able. (This option used to be called PCRE_INFO_FIRSTCHAR; the old name |
1689 |
is still recognized for backwards compatibility.) |
is still recognized for backwards compatibility.) |
1690 |
|
|
1691 |
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 |
1692 |
(cat|cow|coyote), its value is returned. Otherwise, if either |
(cat|cow|coyote), its value is returned. Otherwise, if either |
1693 |
|
|
1694 |
(a) the pattern was compiled with the PCRE_MULTILINE option, and every |
(a) the pattern was compiled with the PCRE_MULTILINE option, and every |
1695 |
branch starts with "^", or |
branch starts with "^", or |
1696 |
|
|
1697 |
(b) every branch of the pattern starts with ".*" and PCRE_DOTALL is not |
(b) every branch of the pattern starts with ".*" and PCRE_DOTALL is not |
1698 |
set (if it were set, the pattern would be anchored), |
set (if it were set, the pattern would be anchored), |
1699 |
|
|
1700 |
-1 is returned, indicating that the pattern matches only at the start |
-1 is returned, indicating that the pattern matches only at the start |
1701 |
of a subject string or after any newline within the string. Otherwise |
of a subject string or after any newline within the string. Otherwise |
1702 |
-2 is returned. For anchored patterns, -2 is returned. |
-2 is returned. For anchored patterns, -2 is returned. |
1703 |
|
|
1704 |
PCRE_INFO_FIRSTTABLE |
PCRE_INFO_FIRSTTABLE |
1705 |
|
|
1706 |
If the pattern was studied, and this resulted in the construction of a |
If the pattern was studied, and this resulted in the construction of a |
1707 |
256-bit table indicating a fixed set of bytes for the first byte in any |
256-bit table indicating a fixed set of bytes for the first byte in any |
1708 |
matching string, a pointer to the table is returned. Otherwise NULL is |
matching string, a pointer to the table is returned. Otherwise NULL is |
1709 |
returned. The fourth argument should point to an unsigned char * vari- |
returned. The fourth argument should point to an unsigned char * vari- |
1710 |
able. |
able. |
1711 |
|
|
1712 |
PCRE_INFO_HASCRORLF |
PCRE_INFO_HASCRORLF |
1713 |
|
|
1714 |
Return 1 if the pattern contains any explicit matches for CR or LF |
Return 1 if the pattern contains any explicit matches for CR or LF |
1715 |
characters, otherwise 0. The fourth argument should point to an int |
characters, otherwise 0. The fourth argument should point to an int |
1716 |
variable. An explicit match is either a literal CR or LF character, or |
variable. An explicit match is either a literal CR or LF character, or |
1717 |
\r or \n. |
\r or \n. |
1718 |
|
|
1719 |
PCRE_INFO_JCHANGED |
PCRE_INFO_JCHANGED |
1720 |
|
|
1721 |
Return 1 if the (?J) or (?-J) option setting is used in the pattern, |
Return 1 if the (?J) or (?-J) option setting is used in the pattern, |
1722 |
otherwise 0. The fourth argument should point to an int variable. (?J) |
otherwise 0. The fourth argument should point to an int variable. (?J) |
1723 |
and (?-J) set and unset the local PCRE_DUPNAMES option, respectively. |
and (?-J) set and unset the local PCRE_DUPNAMES option, respectively. |
1724 |
|
|
1725 |
PCRE_INFO_LASTLITERAL |
PCRE_INFO_LASTLITERAL |
1726 |
|
|
1727 |
Return the value of the rightmost literal byte that must exist in any |
Return the value of the rightmost literal byte that must exist in any |
1728 |
matched string, other than at its start, if such a byte has been |
matched string, other than at its start, if such a byte has been |
1729 |
recorded. The fourth argument should point to an int variable. If there |
recorded. The fourth argument should point to an int variable. If there |
1730 |
is no such byte, -1 is returned. For anchored patterns, a last literal |
is no such byte, -1 is returned. For anchored patterns, a last literal |
1731 |
byte is recorded only if it follows something of variable length. For |
byte is recorded only if it follows something of variable length. For |
1732 |
example, for the pattern /^a\d+z\d+/ the returned value is "z", but for |
example, for the pattern /^a\d+z\d+/ the returned value is "z", but for |
1733 |
/^a\dz\d/ the returned value is -1. |
/^a\dz\d/ the returned value is -1. |
1734 |
|
|
1735 |
PCRE_INFO_MINLENGTH |
PCRE_INFO_MINLENGTH |
1736 |
|
|
1737 |
If the pattern was studied and a minimum length for matching subject |
If the pattern was studied and a minimum length for matching subject |
1738 |
strings was computed, its value is returned. Otherwise the returned |
strings was computed, its value is returned. Otherwise the returned |
1739 |
value is -1. The value is a number of characters, not bytes (this may |
value is -1. The value is a number of characters, not bytes (this may |
1740 |
be relevant in UTF-8 mode). The fourth argument should point to an int |
be relevant in UTF-8 mode). The fourth argument should point to an int |
1741 |
variable. A non-negative value is a lower bound to the length of any |
variable. A non-negative value is a lower bound to the length of any |
1742 |
matching string. There may not be any strings of that length that do |
matching string. There may not be any strings of that length that do |
1743 |
actually match, but every string that does match is at least that long. |
actually match, but every string that does match is at least that long. |
1744 |
|
|
1745 |
PCRE_INFO_NAMECOUNT |
PCRE_INFO_NAMECOUNT |
1746 |
PCRE_INFO_NAMEENTRYSIZE |
PCRE_INFO_NAMEENTRYSIZE |
1747 |
PCRE_INFO_NAMETABLE |
PCRE_INFO_NAMETABLE |
1748 |
|
|
1749 |
PCRE supports the use of named as well as numbered capturing parenthe- |
PCRE supports the use of named as well as numbered capturing parenthe- |
1750 |
ses. The names are just an additional way of identifying the parenthe- |
ses. The names are just an additional way of identifying the parenthe- |
1751 |
ses, which still acquire numbers. Several convenience functions such as |
ses, which still acquire numbers. Several convenience functions such as |
1752 |
pcre_get_named_substring() are provided for extracting captured sub- |
pcre_get_named_substring() are provided for extracting captured sub- |
1753 |
strings by name. It is also possible to extract the data directly, by |
strings by name. It is also possible to extract the data directly, by |
1754 |
first converting the name to a number in order to access the correct |
first converting the name to a number in order to access the correct |
1755 |
pointers in the output vector (described with pcre_exec() below). To do |
pointers in the output vector (described with pcre_exec() below). To do |
1756 |
the conversion, you need to use the name-to-number map, which is |
the conversion, you need to use the name-to-number map, which is |
1757 |
described by these three values. |
described by these three values. |
1758 |
|
|
1759 |
The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT |
The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT |
1760 |
gives the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size |
gives the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size |
1761 |
of each entry; both of these return an int value. The entry size |
of each entry; both of these return an int value. The entry size |
1762 |
depends on the length of the longest name. PCRE_INFO_NAMETABLE returns |
depends on the length of the longest name. PCRE_INFO_NAMETABLE returns |
1763 |
a pointer to the first entry of the table (a pointer to char). The |
a pointer to the first entry of the table (a pointer to char). The |
1764 |
first two bytes of each entry are the number of the capturing parenthe- |
first two bytes of each entry are the number of the capturing parenthe- |
1765 |
sis, most significant byte first. The rest of the entry is the corre- |
sis, most significant byte first. The rest of the entry is the corre- |
1766 |
sponding name, zero terminated. |
sponding name, zero terminated. |
1767 |
|
|
1768 |
The names are in alphabetical order. Duplicate names may appear if (?| |
The names are in alphabetical order. Duplicate names may appear if (?| |
1769 |
is used to create multiple groups with the same number, as described in |
is used to create multiple groups with the same number, as described in |
1770 |
the section on duplicate subpattern numbers in the pcrepattern page. |
the section on duplicate subpattern numbers in the pcrepattern page. |
1771 |
Duplicate names for subpatterns with different numbers are permitted |
Duplicate names for subpatterns with different numbers are permitted |
1772 |
only if PCRE_DUPNAMES is set. In all cases of duplicate names, they |
only if PCRE_DUPNAMES is set. In all cases of duplicate names, they |
1773 |
appear in the table in the order in which they were found in the pat- |
appear in the table in the order in which they were found in the pat- |
1774 |
tern. In the absence of (?| this is the order of increasing number; |
tern. In the absence of (?| this is the order of increasing number; |
1775 |
when (?| is used this is not necessarily the case because later subpat- |
when (?| is used this is not necessarily the case because later subpat- |
1776 |
terns may have lower numbers. |
terns may have lower numbers. |
1777 |
|
|
1778 |
As a simple example of the name/number table, consider the following |
As a simple example of the name/number table, consider the following |
1779 |
pattern (assume PCRE_EXTENDED is set, so white space - including new- |
pattern (assume PCRE_EXTENDED is set, so white space - including new- |
1780 |
lines - is ignored): |
lines - is ignored): |
1781 |
|
|
1782 |
(?<date> (?<year>(\d\d)?\d\d) - |
(?<date> (?<year>(\d\d)?\d\d) - |
1783 |
(?<month>\d\d) - (?<day>\d\d) ) |
(?<month>\d\d) - (?<day>\d\d) ) |
1784 |
|
|
1785 |
There are four named subpatterns, so the table has four entries, and |
There are four named subpatterns, so the table has four entries, and |
1786 |
each entry in the table is eight bytes long. The table is as follows, |
each entry in the table is eight bytes long. The table is as follows, |
1787 |
with non-printing bytes shows in hexadecimal, and undefined bytes shown |
with non-printing bytes shows in hexadecimal, and undefined bytes shown |
1788 |
as ??: |
as ??: |
1789 |
|
|
1792 |
00 04 m o n t h 00 |
00 04 m o n t h 00 |
1793 |
00 02 y e a r 00 ?? |
00 02 y e a r 00 ?? |
1794 |
|
|
1795 |
When writing code to extract data from named subpatterns using the |
When writing code to extract data from named subpatterns using the |
1796 |
name-to-number map, remember that the length of the entries is likely |
name-to-number map, remember that the length of the entries is likely |
1797 |
to be different for each compiled pattern. |
to be different for each compiled pattern. |
1798 |
|
|
1799 |
PCRE_INFO_OKPARTIAL |
PCRE_INFO_OKPARTIAL |
1800 |
|
|
1801 |
Return 1 if the pattern can be used for partial matching with |
Return 1 if the pattern can be used for partial matching with |
1802 |
pcre_exec(), otherwise 0. The fourth argument should point to an int |
pcre_exec(), otherwise 0. The fourth argument should point to an int |
1803 |
variable. From release 8.00, this always returns 1, because the |
variable. From release 8.00, this always returns 1, because the |
1804 |
restrictions that previously applied to partial matching have been |
restrictions that previously applied to partial matching have been |
1805 |
lifted. The pcrepartial documentation gives details of partial match- |
lifted. The pcrepartial documentation gives details of partial match- |
1806 |
ing. |
ing. |
1807 |
|
|
1808 |
PCRE_INFO_OPTIONS |
PCRE_INFO_OPTIONS |
1809 |
|
|
1810 |
Return a copy of the options with which the pattern was compiled. The |
Return a copy of the options with which the pattern was compiled. The |
1811 |
fourth argument should point to an unsigned long int variable. These |
fourth argument should point to an unsigned long int variable. These |
1812 |
option bits are those specified in the call to pcre_compile(), modified |
option bits are those specified in the call to pcre_compile(), modified |
1813 |
by any top-level option settings at the start of the pattern itself. In |
by any top-level option settings at the start of the pattern itself. In |
1814 |
other words, they are the options that will be in force when matching |
other words, they are the options that will be in force when matching |
1815 |
starts. For example, if the pattern /(?im)abc(?-i)d/ is compiled with |
starts. For example, if the pattern /(?im)abc(?-i)d/ is compiled with |
1816 |
the PCRE_EXTENDED option, the result is PCRE_CASELESS, PCRE_MULTILINE, |
the PCRE_EXTENDED option, the result is PCRE_CASELESS, PCRE_MULTILINE, |
1817 |
and PCRE_EXTENDED. |
and PCRE_EXTENDED. |
1818 |
|
|
1819 |
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 |
1820 |
alternatives begin with one of the following: |
alternatives begin with one of the following: |
1821 |
|
|
1822 |
^ unless PCRE_MULTILINE is set |
^ unless PCRE_MULTILINE is set |
1830 |
|
|
1831 |
PCRE_INFO_SIZE |
PCRE_INFO_SIZE |
1832 |
|
|
1833 |
Return the size of the compiled pattern, that is, the value that was |
Return the size of the compiled pattern, that is, the value that was |
1834 |
passed as the argument to pcre_malloc() when PCRE was getting memory in |
passed as the argument to pcre_malloc() when PCRE was getting memory in |
1835 |
which to place the compiled data. The fourth argument should point to a |
which to place the compiled data. The fourth argument should point to a |
1836 |
size_t variable. |
size_t variable. |
1838 |
PCRE_INFO_STUDYSIZE |
PCRE_INFO_STUDYSIZE |
1839 |
|
|
1840 |
Return the size of the data block pointed to by the study_data field in |
Return the size of the data block pointed to by the study_data field in |
1841 |
a pcre_extra block. That is, it is the value that was passed to |
a pcre_extra block. That is, it is the value that was passed to |
1842 |
pcre_malloc() when PCRE was getting memory into which to place the data |
pcre_malloc() when PCRE was getting memory into which to place the data |
1843 |
created by pcre_study(). If pcre_extra is NULL, or there is no study |
created by pcre_study(). If pcre_extra is NULL, or there is no study |
1844 |
data, zero is returned. The fourth argument should point to a size_t |
data, zero is returned. The fourth argument should point to a size_t |
1845 |
variable. |
variable. |
1846 |
|
|
1847 |
|
|
1849 |
|
|
1850 |
int pcre_info(const pcre *code, int *optptr, int *firstcharptr); |
int pcre_info(const pcre *code, int *optptr, int *firstcharptr); |
1851 |
|
|
1852 |
The pcre_info() function is now obsolete because its interface is too |
The pcre_info() function is now obsolete because its interface is too |
1853 |
restrictive to return all the available data about a compiled pattern. |
restrictive to return all the available data about a compiled pattern. |
1854 |
New programs should use pcre_fullinfo() instead. The yield of |
New programs should use pcre_fullinfo() instead. The yield of |
1855 |
pcre_info() is the number of capturing subpatterns, or one of the fol- |
pcre_info() is the number of capturing subpatterns, or one of the fol- |
1856 |
lowing negative numbers: |
lowing negative numbers: |
1857 |
|
|
1858 |
PCRE_ERROR_NULL the argument code was NULL |
PCRE_ERROR_NULL the argument code was NULL |
1859 |
PCRE_ERROR_BADMAGIC the "magic number" was not found |
PCRE_ERROR_BADMAGIC the "magic number" was not found |
1860 |
|
|
1861 |
If the optptr argument is not NULL, a copy of the options with which |
If the optptr argument is not NULL, a copy of the options with which |
1862 |
the pattern was compiled is placed in the integer it points to (see |
the pattern was compiled is placed in the integer it points to (see |
1863 |
PCRE_INFO_OPTIONS above). |
PCRE_INFO_OPTIONS above). |
1864 |
|
|
1865 |
If the pattern is not anchored and the firstcharptr argument is not |
If the pattern is not anchored and the firstcharptr argument is not |
1866 |
NULL, it is used to pass back information about the first character of |
NULL, it is used to pass back information about the first character of |
1867 |
any matched string (see PCRE_INFO_FIRSTBYTE above). |
any matched string (see PCRE_INFO_FIRSTBYTE above). |
1868 |
|
|
1869 |
|
|
1871 |
|
|
1872 |
int pcre_refcount(pcre *code, int adjust); |
int pcre_refcount(pcre *code, int adjust); |
1873 |
|
|
1874 |
The pcre_refcount() function is used to maintain a reference count in |
The pcre_refcount() function is used to maintain a reference count in |
1875 |
the data block that contains a compiled pattern. It is provided for the |
the data block that contains a compiled pattern. It is provided for the |
1876 |
benefit of applications that operate in an object-oriented manner, |
benefit of applications that operate in an object-oriented manner, |
1877 |
where different parts of the application may be using the same compiled |
where different parts of the application may be using the same compiled |
1878 |
pattern, but you want to free the block when they are all done. |
pattern, but you want to free the block when they are all done. |
1879 |
|
|
1880 |
When a pattern is compiled, the reference count field is initialized to |
When a pattern is compiled, the reference count field is initialized to |
1881 |
zero. It is changed only by calling this function, whose action is to |
zero. It is changed only by calling this function, whose action is to |
1882 |
add the adjust value (which may be positive or negative) to it. The |
add the adjust value (which may be positive or negative) to it. The |
1883 |
yield of the function is the new value. However, the value of the count |
yield of the function is the new value. However, the value of the count |
1884 |
is constrained to lie between 0 and 65535, inclusive. If the new value |
is constrained to lie between 0 and 65535, inclusive. If the new value |
1885 |
is outside these limits, it is forced to the appropriate limit value. |
is outside these limits, it is forced to the appropriate limit value. |
1886 |
|
|
1887 |
Except when it is zero, the reference count is not correctly preserved |
Except when it is zero, the reference count is not correctly preserved |
1888 |
if a pattern is compiled on one host and then transferred to a host |
if a pattern is compiled on one host and then transferred to a host |
1889 |
whose byte-order is different. (This seems a highly unlikely scenario.) |
whose byte-order is different. (This seems a highly unlikely scenario.) |
1890 |
|
|
1891 |
|
|
1895 |
const char *subject, int length, int startoffset, |
const char *subject, int length, int startoffset, |
1896 |
int options, int *ovector, int ovecsize); |
int options, int *ovector, int ovecsize); |
1897 |
|
|
1898 |
The function pcre_exec() is called to match a subject string against a |
The function pcre_exec() is called to match a subject string against a |
1899 |
compiled pattern, which is passed in the code argument. If the pattern |
compiled pattern, which is passed in the code argument. If the pattern |
1900 |
was studied, the result of the study should be passed in the extra |
was studied, the result of the study should be passed in the extra |
1901 |
argument. This function is the main matching facility of the library, |
argument. This function is the main matching facility of the library, |
1902 |
and it operates in a Perl-like manner. For specialist use there is also |
and it operates in a Perl-like manner. For specialist use there is also |
1903 |
an alternative matching function, which is described below in the sec- |
an alternative matching function, which is described below in the sec- |
1904 |
tion about the pcre_dfa_exec() function. |
tion about the pcre_dfa_exec() function. |
1905 |
|
|
1906 |
In most applications, the pattern will have been compiled (and option- |
In most applications, the pattern will have been compiled (and option- |
1907 |
ally studied) in the same process that calls pcre_exec(). However, it |
ally studied) in the same process that calls pcre_exec(). However, it |
1908 |
is possible to save compiled patterns and study data, and then use them |
is possible to save compiled patterns and study data, and then use them |
1909 |
later in different processes, possibly even on different hosts. For a |
later in different processes, possibly even on different hosts. For a |
1910 |
discussion about this, see the pcreprecompile documentation. |
discussion about this, see the pcreprecompile documentation. |
1911 |
|
|
1912 |
Here is an example of a simple call to pcre_exec(): |
Here is an example of a simple call to pcre_exec(): |
1925 |
|
|
1926 |
Extra data for pcre_exec() |
Extra data for pcre_exec() |
1927 |
|
|
1928 |
If the extra argument is not NULL, it must point to a pcre_extra data |
If the extra argument is not NULL, it must point to a pcre_extra data |
1929 |
block. The pcre_study() function returns such a block (when it doesn't |
block. The pcre_study() function returns such a block (when it doesn't |
1930 |
return NULL), but you can also create one for yourself, and pass addi- |
return NULL), but you can also create one for yourself, and pass addi- |
1931 |
tional information in it. The pcre_extra block contains the following |
tional information in it. The pcre_extra block contains the following |
1932 |
fields (not necessarily in this order): |
fields (not necessarily in this order): |
1933 |
|
|
1934 |
unsigned long int flags; |
unsigned long int flags; |
1939 |
const unsigned char *tables; |
const unsigned char *tables; |
1940 |
unsigned char **mark; |
unsigned char **mark; |
1941 |
|
|
1942 |
The flags field is a bitmap that specifies which of the other fields |
The flags field is a bitmap that specifies which of the other fields |
1943 |
are set. The flag bits are: |
are set. The flag bits are: |
1944 |
|
|
1945 |
PCRE_EXTRA_STUDY_DATA |
PCRE_EXTRA_STUDY_DATA |
1949 |
PCRE_EXTRA_TABLES |
PCRE_EXTRA_TABLES |
1950 |
PCRE_EXTRA_MARK |
PCRE_EXTRA_MARK |
1951 |
|
|
1952 |
Other flag bits should be set to zero. The study_data field is set in |
Other flag bits should be set to zero. The study_data field is set in |
1953 |
the pcre_extra block that is returned by pcre_study(), together with |
the pcre_extra block that is returned by pcre_study(), together with |
1954 |
the appropriate flag bit. You should not set this yourself, but you may |
the appropriate flag bit. You should not set this yourself, but you may |
1955 |
add to the block by setting the other fields and their corresponding |
add to the block by setting the other fields and their corresponding |
1956 |
flag bits. |
flag bits. |
1957 |
|
|
1958 |
The match_limit field provides a means of preventing PCRE from using up |
The match_limit field provides a means of preventing PCRE from using up |
1959 |
a vast amount of resources when running patterns that are not going to |
a vast amount of resources when running patterns that are not going to |
1960 |
match, but which have a very large number of possibilities in their |
match, but which have a very large number of possibilities in their |
1961 |
search trees. The classic example is a pattern that uses nested unlim- |
search trees. The classic example is a pattern that uses nested unlim- |
1962 |
ited repeats. |
ited repeats. |
1963 |
|
|
1964 |
Internally, PCRE uses a function called match() which it calls repeat- |
Internally, PCRE uses a function called match() which it calls repeat- |
1965 |
edly (sometimes recursively). The limit set by match_limit is imposed |
edly (sometimes recursively). The limit set by match_limit is imposed |
1966 |
on the number of times this function is called during a match, which |
on the number of times this function is called during a match, which |
1967 |
has the effect of limiting the amount of backtracking that can take |
has the effect of limiting the amount of backtracking that can take |
1968 |
place. For patterns that are not anchored, the count restarts from zero |
place. For patterns that are not anchored, the count restarts from zero |
1969 |
for each position in the subject string. |
for each position in the subject string. |
1970 |
|
|
1971 |
The default value for the limit can be set when PCRE is built; the |
The default value for the limit can be set when PCRE is built; the |
1972 |
default default is 10 million, which handles all but the most extreme |
default default is 10 million, which handles all but the most extreme |
1973 |
cases. You can override the default by suppling pcre_exec() with a |
cases. You can override the default by suppling pcre_exec() with a |
1974 |
pcre_extra block in which match_limit is set, and |
pcre_extra block in which match_limit is set, and |
1975 |
PCRE_EXTRA_MATCH_LIMIT is set in the flags field. If the limit is |
PCRE_EXTRA_MATCH_LIMIT is set in the flags field. If the limit is |
1976 |
exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT. |
exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT. |
1977 |
|
|
1978 |
The match_limit_recursion field is similar to match_limit, but instead |
The match_limit_recursion field is similar to match_limit, but instead |
1979 |
of limiting the total number of times that match() is called, it limits |
of limiting the total number of times that match() is called, it limits |
1980 |
the depth of recursion. The recursion depth is a smaller number than |
the depth of recursion. The recursion depth is a smaller number than |
1981 |
the total number of calls, because not all calls to match() are recur- |
the total number of calls, because not all calls to match() are recur- |
1982 |
sive. This limit is of use only if it is set smaller than match_limit. |
sive. This limit is of use only if it is set smaller than match_limit. |
1983 |
|
|
1984 |
Limiting the recursion depth limits the amount of stack that can be |
Limiting the recursion depth limits the amount of stack that can be |
1985 |
used, or, when PCRE has been compiled to use memory on the heap instead |
used, or, when PCRE has been compiled to use memory on the heap instead |
1986 |
of the stack, the amount of heap memory that can be used. |
of the stack, the amount of heap memory that can be used. |
1987 |
|
|
1988 |
The default value for match_limit_recursion can be set when PCRE is |
The default value for match_limit_recursion can be set when PCRE is |
1989 |
built; the default default is the same value as the default for |
built; the default default is the same value as the default for |
1990 |
match_limit. You can override the default by suppling pcre_exec() with |
match_limit. You can override the default by suppling pcre_exec() with |
1991 |
a pcre_extra block in which match_limit_recursion is set, and |
a pcre_extra block in which match_limit_recursion is set, and |
1992 |
PCRE_EXTRA_MATCH_LIMIT_RECURSION is set in the flags field. If the |
PCRE_EXTRA_MATCH_LIMIT_RECURSION is set in the flags field. If the |
1993 |
limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT. |
limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT. |
1994 |
|
|
1995 |
The callout_data field is used in conjunction with the "callout" fea- |
The callout_data field is used in conjunction with the "callout" fea- |
1996 |
ture, and is described in the pcrecallout documentation. |
ture, and is described in the pcrecallout documentation. |
1997 |
|
|
1998 |
The tables field is used to pass a character tables pointer to |
The tables field is used to pass a character tables pointer to |
1999 |
pcre_exec(); this overrides the value that is stored with the compiled |
pcre_exec(); this overrides the value that is stored with the compiled |
2000 |
pattern. A non-NULL value is stored with the compiled pattern only if |
pattern. A non-NULL value is stored with the compiled pattern only if |
2001 |
custom tables were supplied to pcre_compile() via its tableptr argu- |
custom tables were supplied to pcre_compile() via its tableptr argu- |
2002 |
ment. If NULL is passed to pcre_exec() using this mechanism, it forces |
ment. If NULL is passed to pcre_exec() using this mechanism, it forces |
2003 |
PCRE's internal tables to be used. This facility is helpful when re- |
PCRE's internal tables to be used. This facility is helpful when re- |
2004 |
using patterns that have been saved after compiling with an external |
using patterns that have been saved after compiling with an external |
2005 |
set of tables, because the external tables might be at a different |
set of tables, because the external tables might be at a different |
2006 |
address when pcre_exec() is called. See the pcreprecompile documenta- |
address when pcre_exec() is called. See the pcreprecompile documenta- |
2007 |
tion for a discussion of saving compiled patterns for later use. |
tion for a discussion of saving compiled patterns for later use. |
2008 |
|
|
2009 |
If PCRE_EXTRA_MARK is set in the flags field, the mark field must be |
If PCRE_EXTRA_MARK is set in the flags field, the mark field must be |
2010 |
set to point to a char * variable. If the pattern contains any back- |
set to point to a char * variable. If the pattern contains any back- |
2011 |
tracking control verbs such as (*MARK:NAME), and the execution ends up |
tracking control verbs such as (*MARK:NAME), and the execution ends up |
2012 |
with a name to pass back, a pointer to the name string (zero termi- |
with a name to pass back, a pointer to the name string (zero termi- |
2013 |
nated) is placed in the variable pointed to by the mark field. The |
nated) is placed in the variable pointed to by the mark field. The |
2014 |
names are within the compiled pattern; if you wish to retain such a |
names are within the compiled pattern; if you wish to retain such a |
2015 |
name you must copy it before freeing the memory of a compiled pattern. |
name you must copy it before freeing the memory of a compiled pattern. |
2016 |
If there is no name to pass back, the variable pointed to by the mark |
If there is no name to pass back, the variable pointed to by the mark |
2017 |
field set to NULL. For details of the backtracking control verbs, see |
field set to NULL. For details of the backtracking control verbs, see |
2018 |
the section entitled "Backtracking control" in the pcrepattern documen- |
the section entitled "Backtracking control" in the pcrepattern documen- |
2019 |
tation. |
tation. |
2020 |
|
|
2021 |
Option bits for pcre_exec() |
Option bits for pcre_exec() |
2022 |
|
|
2023 |
The unused bits of the options argument for pcre_exec() must be zero. |
The unused bits of the options argument for pcre_exec() must be zero. |
2024 |
The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_xxx, |
The only bits that may be set are PCRE_ANCHORED, PCRE_NEWLINE_xxx, |
2025 |
PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART, |
PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART, |
2026 |
PCRE_NO_START_OPTIMIZE, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_SOFT, and |
PCRE_NO_START_OPTIMIZE, PCRE_NO_UTF8_CHECK, PCRE_PARTIAL_SOFT, and |
2027 |
PCRE_PARTIAL_HARD. |
PCRE_PARTIAL_HARD. |
2028 |
|
|
2029 |
PCRE_ANCHORED |
PCRE_ANCHORED |
2030 |
|
|
2031 |
The PCRE_ANCHORED option limits pcre_exec() to matching at the first |
The PCRE_ANCHORED option limits pcre_exec() to matching at the first |
2032 |
matching position. If a pattern was compiled with PCRE_ANCHORED, or |
matching position. If a pattern was compiled with PCRE_ANCHORED, or |
2033 |
turned out to be anchored by virtue of its contents, it cannot be made |
turned out to be anchored by virtue of its contents, it cannot be made |
2034 |
unachored at matching time. |
unachored at matching time. |
2035 |
|
|
2036 |
PCRE_BSR_ANYCRLF |
PCRE_BSR_ANYCRLF |
2037 |
PCRE_BSR_UNICODE |
PCRE_BSR_UNICODE |
2038 |
|
|
2039 |
These options (which are mutually exclusive) control what the \R escape |
These options (which are mutually exclusive) control what the \R escape |
2040 |
sequence matches. The choice is either to match only CR, LF, or CRLF, |
sequence matches. The choice is either to match only CR, LF, or CRLF, |
2041 |
or to match any Unicode newline sequence. These options override the |
or to match any Unicode newline sequence. These options override the |
2042 |
choice that was made or defaulted when the pattern was compiled. |
choice that was made or defaulted when the pattern was compiled. |
2043 |
|
|
2044 |
PCRE_NEWLINE_CR |
PCRE_NEWLINE_CR |
2047 |
PCRE_NEWLINE_ANYCRLF |
PCRE_NEWLINE_ANYCRLF |
2048 |
PCRE_NEWLINE_ANY |
PCRE_NEWLINE_ANY |
2049 |
|
|
2050 |
These options override the newline definition that was chosen or |
These options override the newline definition that was chosen or |
2051 |
defaulted when the pattern was compiled. For details, see the descrip- |
defaulted when the pattern was compiled. For details, see the descrip- |
2052 |
tion of pcre_compile() above. During matching, the newline choice |
tion of pcre_compile() above. During matching, the newline choice |
2053 |
affects the behaviour of the dot, circumflex, and dollar metacharac- |
affects the behaviour of the dot, circumflex, and dollar metacharac- |
2054 |
ters. It may also alter the way the match position is advanced after a |
ters. It may also alter the way the match position is advanced after a |
2055 |
match failure for an unanchored pattern. |
match failure for an unanchored pattern. |
2056 |
|
|
2057 |
When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is |
When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is |
2058 |
set, and a match attempt for an unanchored pattern fails when the cur- |
set, and a match attempt for an unanchored pattern fails when the cur- |
2059 |
rent position is at a CRLF sequence, and the pattern contains no |
rent position is at a CRLF sequence, and the pattern contains no |
2060 |
explicit matches for CR or LF characters, the match position is |
explicit matches for CR or LF characters, the match position is |
2061 |
advanced by two characters instead of one, in other words, to after the |
advanced by two characters instead of one, in other words, to after the |
2062 |
CRLF. |
CRLF. |
2063 |
|
|
2064 |
The above rule is a compromise that makes the most common cases work as |
The above rule is a compromise that makes the most common cases work as |
2065 |
expected. For example, if the pattern is .+A (and the PCRE_DOTALL |
expected. For example, if the pattern is .+A (and the PCRE_DOTALL |
2066 |
option is not set), it does not match the string "\r\nA" because, after |
option is not set), it does not match the string "\r\nA" because, after |
2067 |
failing at the start, it skips both the CR and the LF before retrying. |
failing at the start, it skips both the CR and the LF before retrying. |
2068 |
However, the pattern [\r\n]A does match that string, because it con- |
However, the pattern [\r\n]A does match that string, because it con- |
2069 |
tains an explicit CR or LF reference, and so advances only by one char- |
tains an explicit CR or LF reference, and so advances only by one char- |
2070 |
acter after the first failure. |
acter after the first failure. |
2071 |
|
|
2072 |
An explicit match for CR of LF is either a literal appearance of one of |
An explicit match for CR of LF is either a literal appearance of one of |
2073 |
those characters, or one of the \r or \n escape sequences. Implicit |
those characters, or one of the \r or \n escape sequences. Implicit |
2074 |
matches such as [^X] do not count, nor does \s (which includes CR and |
matches such as [^X] do not count, nor does \s (which includes CR and |
2075 |
LF in the characters that it matches). |
LF in the characters that it matches). |
2076 |
|
|
2077 |
Notwithstanding the above, anomalous effects may still occur when CRLF |
Notwithstanding the above, anomalous effects may still occur when CRLF |
2078 |
is a valid newline sequence and explicit \r or \n escapes appear in the |
is a valid newline sequence and explicit \r or \n escapes appear in the |
2079 |
pattern. |
pattern. |
2080 |
|
|
2081 |
PCRE_NOTBOL |
PCRE_NOTBOL |
2082 |
|
|
2083 |
This option specifies that first character of the subject string is not |
This option specifies that first character of the subject string is not |
2084 |
the beginning of a line, so the circumflex metacharacter should not |
the beginning of a line, so the circumflex metacharacter should not |
2085 |
match before it. Setting this without PCRE_MULTILINE (at compile time) |
match before it. Setting this without PCRE_MULTILINE (at compile time) |
2086 |
causes circumflex never to match. This option affects only the behav- |
causes circumflex never to match. This option affects only the behav- |
2087 |
iour of the circumflex metacharacter. It does not affect \A. |
iour of the circumflex metacharacter. It does not affect \A. |
2088 |
|
|
2089 |
PCRE_NOTEOL |
PCRE_NOTEOL |
2090 |
|
|
2091 |
This option specifies that the end of the subject string is not the end |
This option specifies that the end of the subject string is not the end |
2092 |
of a line, so the dollar metacharacter should not match it nor (except |
of a line, so the dollar metacharacter should not match it nor (except |
2093 |
in multiline mode) a newline immediately before it. Setting this with- |
in multiline mode) a newline immediately before it. Setting this with- |
2094 |
out PCRE_MULTILINE (at compile time) causes dollar never to match. This |
out PCRE_MULTILINE (at compile time) causes dollar never to match. This |
2095 |
option affects only the behaviour of the dollar metacharacter. It does |
option affects only the behaviour of the dollar metacharacter. It does |
2096 |
not affect \Z or \z. |
not affect \Z or \z. |
2097 |
|
|
2098 |
PCRE_NOTEMPTY |
PCRE_NOTEMPTY |
2099 |
|
|
2100 |
An empty string is not considered to be a valid match if this option is |
An empty string is not considered to be a valid match if this option is |
2101 |
set. If there are alternatives in the pattern, they are tried. If all |
set. If there are alternatives in the pattern, they are tried. If all |
2102 |
the alternatives match the empty string, the entire match fails. For |
the alternatives match the empty string, the entire match fails. For |
2103 |
example, if the pattern |
example, if the pattern |
2104 |
|
|
2105 |
a?b? |
a?b? |
2106 |
|
|
2107 |
is applied to a string not beginning with "a" or "b", it matches an |
is applied to a string not beginning with "a" or "b", it matches an |
2108 |
empty string at the start of the subject. With PCRE_NOTEMPTY set, this |
empty string at the start of the subject. With PCRE_NOTEMPTY set, this |
2109 |
match is not valid, so PCRE searches further into the string for occur- |
match is not valid, so PCRE searches further into the string for occur- |
2110 |
rences of "a" or "b". |
rences of "a" or "b". |
2111 |
|
|
2112 |
PCRE_NOTEMPTY_ATSTART |
PCRE_NOTEMPTY_ATSTART |
2113 |
|
|
2114 |
This is like PCRE_NOTEMPTY, except that an empty string match that is |
This is like PCRE_NOTEMPTY, except that an empty string match that is |
2115 |
not at the start of the subject is permitted. If the pattern is |
not at the start of the subject is permitted. If the pattern is |
2116 |
anchored, such a match can occur only if the pattern contains \K. |
anchored, such a match can occur only if the pattern contains \K. |
2117 |
|
|
2118 |
Perl has no direct equivalent of PCRE_NOTEMPTY or |
Perl has no direct equivalent of PCRE_NOTEMPTY or |
2119 |
PCRE_NOTEMPTY_ATSTART, but it does make a special case of a pattern |
PCRE_NOTEMPTY_ATSTART, but it does make a special case of a pattern |
2120 |
match of the empty string within its split() function, and when using |
match of the empty string within its split() function, and when using |
2121 |
the /g modifier. It is possible to emulate Perl's behaviour after |
the /g modifier. It is possible to emulate Perl's behaviour after |
2122 |
matching a null string by first trying the match again at the same off- |
matching a null string by first trying the match again at the same off- |
2123 |
set with PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED, and then if that |
set with PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED, and then if that |
2124 |
fails, by advancing the starting offset (see below) and trying an ordi- |
fails, by advancing the starting offset (see below) and trying an ordi- |
2125 |
nary match again. There is some code that demonstrates how to do this |
nary match again. There is some code that demonstrates how to do this |
2126 |
in the pcredemo sample program. |
in the pcredemo sample program. |
2127 |
|
|
2128 |
PCRE_NO_START_OPTIMIZE |
PCRE_NO_START_OPTIMIZE |
2129 |
|
|
2130 |
There are a number of optimizations that pcre_exec() uses at the start |
There are a number of optimizations that pcre_exec() uses at the start |
2131 |
of a match, in order to speed up the process. For example, if it is |
of a match, in order to speed up the process. For example, if it is |
2132 |
known that an unanchored match must start with a specific character, it |
known that an unanchored match must start with a specific character, it |
2133 |
searches the subject for that character, and fails immediately if it |
searches the subject for that character, and fails immediately if it |
2134 |
cannot find it, without actually running the main matching function. |
cannot find it, without actually running the main matching function. |
2135 |
This means that a special item such as (*COMMIT) at the start of a pat- |
This means that a special item such as (*COMMIT) at the start of a pat- |
2136 |
tern is not considered until after a suitable starting point for the |
tern is not considered until after a suitable starting point for the |
2137 |
match has been found. When callouts are in use, these "start-up" opti- |
match has been found. When callouts or (*MARK) items are in use, these |
2138 |
mizations can cause them to be skipped if the pattern is never actually |
"start-up" optimizations can cause them to be skipped if the pattern is |
2139 |
used. The PCRE_NO_START_OPTIMIZE option disables the start-up optimiza- |
never actually used. The start-up optimizations are in effect a pre- |
2140 |
tions, causing performance to suffer, but ensuring that the callouts do |
scan of the subject that takes place before the pattern is run. |
2141 |
occur, and that items such as (*COMMIT) are considered at every possi- |
|
2142 |
ble starting position in the subject string. |
The PCRE_NO_START_OPTIMIZE option disables the start-up optimizations, |
2143 |
|
possibly causing performance to suffer, but ensuring that in cases |
2144 |
|
where the result is "no match", the callouts do occur, and that items |
2145 |
|
such as (*COMMIT) and (*MARK) are considered at every possible starting |
2146 |
|
position in the subject string. Setting PCRE_NO_START_OPTIMIZE can |
2147 |
|
change the outcome of a matching operation. Consider the pattern |
2148 |
|
|
2149 |
|
(*COMMIT)ABC |
2150 |
|
|
2151 |
|
When this is compiled, PCRE records the fact that a match must start |
2152 |
|
with the character "A". Suppose the subject string is "DEFABC". The |
2153 |
|
start-up optimization scans along the subject, finds "A" and runs the |
2154 |
|
first match attempt from there. The (*COMMIT) item means that the pat- |
2155 |
|
tern must match the current starting position, which in this case, it |
2156 |
|
does. However, if the same match is run with PCRE_NO_START_OPTIMIZE |
2157 |
|
set, the initial scan along the subject string does not happen. The |
2158 |
|
first match attempt is run starting from "D" and when this fails, |
2159 |
|
(*COMMIT) prevents any further matches being tried, so the overall |
2160 |
|
result is "no match". If the pattern is studied, more start-up opti- |
2161 |
|
mizations may be used. For example, a minimum length for the subject |
2162 |
|
may be recorded. Consider the pattern |
2163 |
|
|
2164 |
|
(*MARK:A)(X|Y) |
2165 |
|
|
2166 |
|
The minimum length for a match is one character. If the subject is |
2167 |
|
"ABC", there will be attempts to match "ABC", "BC", "C", and then |
2168 |
|
finally an empty string. If the pattern is studied, the final attempt |
2169 |
|
does not take place, because PCRE knows that the subject is too short, |
2170 |
|
and so the (*MARK) is never encountered. In this case, studying the |
2171 |
|
pattern does not affect the overall match result, which is still "no |
2172 |
|
match", but it does affect the auxiliary information that is returned. |
2173 |
|
|
2174 |
PCRE_NO_UTF8_CHECK |
PCRE_NO_UTF8_CHECK |
2175 |
|
|
2176 |
When PCRE_UTF8 is set at compile time, the validity of the subject as a |
When PCRE_UTF8 is set at compile time, the validity of the subject as a |
2177 |
UTF-8 string is automatically checked when pcre_exec() is subsequently |
UTF-8 string is automatically checked when pcre_exec() is subsequently |
2178 |
called. The value of startoffset is also checked to ensure that it |
called. The value of startoffset is also checked to ensure that it |
2179 |
points to the start of a UTF-8 character. There is a discussion about |
points to the start of a UTF-8 character. There is a discussion about |
2180 |
the validity of UTF-8 strings in the section on UTF-8 support in the |
the validity of UTF-8 strings in the section on UTF-8 support in the |
2181 |
main pcre page. If an invalid UTF-8 sequence of bytes is found, |
main pcre page. If an invalid UTF-8 sequence of bytes is found, |
2182 |
pcre_exec() returns the error PCRE_ERROR_BADUTF8. If startoffset con- |
pcre_exec() returns the error PCRE_ERROR_BADUTF8. If startoffset con- |
2183 |
tains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned. |
tains an invalid value, PCRE_ERROR_BADUTF8_OFFSET is returned. |
2184 |
|
|
2185 |
If you already know that your subject is valid, and you want to skip |
If you already know that your subject is valid, and you want to skip |
2186 |
these checks for performance reasons, you can set the |
these checks for performance reasons, you can set the |
2187 |
PCRE_NO_UTF8_CHECK option when calling pcre_exec(). You might want to |
PCRE_NO_UTF8_CHECK option when calling pcre_exec(). You might want to |
2188 |
do this for the second and subsequent calls to pcre_exec() if you are |
do this for the second and subsequent calls to pcre_exec() if you are |
2189 |
making repeated calls to find all the matches in a single subject |
making repeated calls to find all the matches in a single subject |
2190 |
string. However, you should be sure that the value of startoffset |
string. However, you should be sure that the value of startoffset |
2191 |
points to the start of a UTF-8 character. When PCRE_NO_UTF8_CHECK is |
points to the start of a UTF-8 character. When PCRE_NO_UTF8_CHECK is |
2192 |
set, the effect of passing an invalid UTF-8 string as a subject, or a |
set, the effect of passing an invalid UTF-8 string as a subject, or a |
2193 |
value of startoffset that does not point to the start of a UTF-8 char- |
value of startoffset that does not point to the start of a UTF-8 char- |
2194 |
acter, is undefined. Your program may crash. |
acter, is undefined. Your program may crash. |
2195 |
|
|
2196 |
PCRE_PARTIAL_HARD |
PCRE_PARTIAL_HARD |
2197 |
PCRE_PARTIAL_SOFT |
PCRE_PARTIAL_SOFT |
2198 |
|
|
2199 |
These options turn on the partial matching feature. For backwards com- |
These options turn on the partial matching feature. For backwards com- |
2200 |
patibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial |
patibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial |
2201 |
match occurs if the end of the subject string is reached successfully, |
match occurs if the end of the subject string is reached successfully, |
2202 |
but there are not enough subject characters to complete the match. If |
but there are not enough subject characters to complete the match. If |
2203 |
this happens when PCRE_PARTIAL_HARD is set, pcre_exec() immediately |
this happens when PCRE_PARTIAL_HARD is set, pcre_exec() immediately |
2204 |
returns PCRE_ERROR_PARTIAL. Otherwise, if PCRE_PARTIAL_SOFT is set, |
returns PCRE_ERROR_PARTIAL. Otherwise, if PCRE_PARTIAL_SOFT is set, |
2205 |
matching continues by testing any other alternatives. Only if they all |
matching continues by testing any other alternatives. Only if they all |
2206 |
fail is PCRE_ERROR_PARTIAL returned (instead of PCRE_ERROR_NOMATCH). |
fail is PCRE_ERROR_PARTIAL returned (instead of PCRE_ERROR_NOMATCH). |
2207 |
The portion of the string that was inspected when the partial match was |
The portion of the string that was inspected when the partial match was |
2208 |
found is set as the first matching string. There is a more detailed |
found is set as the first matching string. There is a more detailed |
2209 |
discussion in the pcrepartial documentation. |
discussion in the pcrepartial documentation. |
2210 |
|
|
2211 |
The string to be matched by pcre_exec() |
The string to be matched by pcre_exec() |
2212 |
|
|
2213 |
The subject string is passed to pcre_exec() as a pointer in subject, a |
The subject string is passed to pcre_exec() as a pointer in subject, a |
2214 |
length (in bytes) in length, and a starting byte offset in startoffset. |
length (in bytes) in length, and a starting byte offset in startoffset. |
2215 |
In UTF-8 mode, the byte offset must point to the start of a UTF-8 char- |
In UTF-8 mode, the byte offset must point to the start of a UTF-8 char- |
2216 |
acter. Unlike the pattern string, the subject may contain binary zero |
acter. Unlike the pattern string, the subject may contain binary zero |
2217 |
bytes. When the starting offset is zero, the search for a match starts |
bytes. When the starting offset is zero, the search for a match starts |
2218 |
at the beginning of the subject, and this is by far the most common |
at the beginning of the subject, and this is by far the most common |
2219 |
case. |
case. |
2220 |
|
|
2221 |
A non-zero starting offset is useful when searching for another match |
A non-zero starting offset is useful when searching for another match |
2222 |
in the same subject by calling pcre_exec() again after a previous suc- |
in the same subject by calling pcre_exec() again after a previous suc- |
2223 |
cess. Setting startoffset differs from just passing over a shortened |
cess. Setting startoffset differs from just passing over a shortened |
2224 |
string and setting PCRE_NOTBOL in the case of a pattern that begins |
string and setting PCRE_NOTBOL in the case of a pattern that begins |
2225 |
with any kind of lookbehind. For example, consider the pattern |
with any kind of lookbehind. For example, consider the pattern |
2226 |
|
|
2227 |
\Biss\B |
\Biss\B |
2228 |
|
|
2229 |
which finds occurrences of "iss" in the middle of words. (\B matches |
which finds occurrences of "iss" in the middle of words. (\B matches |
2230 |
only if the current position in the subject is not a word boundary.) |
only if the current position in the subject is not a word boundary.) |
2231 |
When applied to the string "Mississipi" the first call to pcre_exec() |
When applied to the string "Mississipi" the first call to pcre_exec() |
2232 |
finds the first occurrence. If pcre_exec() is called again with just |
finds the first occurrence. If pcre_exec() is called again with just |
2233 |
the remainder of the subject, namely "issipi", it does not match, |
the remainder of the subject, namely "issipi", it does not match, |
2234 |
because \B is always false at the start of the subject, which is deemed |
because \B is always false at the start of the subject, which is deemed |
2235 |
to be a word boundary. However, if pcre_exec() is passed the entire |
to be a word boundary. However, if pcre_exec() is passed the entire |
2236 |
string again, but with startoffset set to 4, it finds the second occur- |
string again, but with startoffset set to 4, it finds the second occur- |
2237 |
rence of "iss" because it is able to look behind the starting point to |
rence of "iss" because it is able to look behind the starting point to |
2238 |
discover that it is preceded by a letter. |
discover that it is preceded by a letter. |
2239 |
|
|
2240 |
If a non-zero starting offset is passed when the pattern is anchored, |
If a non-zero starting offset is passed when the pattern is anchored, |
2241 |
one attempt to match at the given offset is made. This can only succeed |
one attempt to match at the given offset is made. This can only succeed |
2242 |
if the pattern does not require the match to be at the start of the |
if the pattern does not require the match to be at the start of the |
2243 |
subject. |
subject. |
2244 |
|
|
2245 |
How pcre_exec() returns captured substrings |
How pcre_exec() returns captured substrings |
2246 |
|
|
2247 |
In general, a pattern matches a certain portion of the subject, and in |
In general, a pattern matches a certain portion of the subject, and in |
2248 |
addition, further substrings from the subject may be picked out by |
addition, further substrings from the subject may be picked out by |
2249 |
parts of the pattern. Following the usage in Jeffrey Friedl's book, |
parts of the pattern. Following the usage in Jeffrey Friedl's book, |
2250 |
this is called "capturing" in what follows, and the phrase "capturing |
this is called "capturing" in what follows, and the phrase "capturing |
2251 |
subpattern" is used for a fragment of a pattern that picks out a sub- |
subpattern" is used for a fragment of a pattern that picks out a sub- |
2252 |
string. PCRE supports several other kinds of parenthesized subpattern |
string. PCRE supports several other kinds of parenthesized subpattern |
2253 |
that do not cause substrings to be captured. |
that do not cause substrings to be captured. |
2254 |
|
|
2255 |
Captured substrings are returned to the caller via a vector of integers |
Captured substrings are returned to the caller via a vector of integers |
2256 |
whose address is passed in ovector. The number of elements in the vec- |
whose address is passed in ovector. The number of elements in the vec- |
2257 |
tor is passed in ovecsize, which must be a non-negative number. Note: |
tor is passed in ovecsize, which must be a non-negative number. Note: |
2258 |
this argument is NOT the size of ovector in bytes. |
this argument is NOT the size of ovector in bytes. |
2259 |
|
|
2260 |
The first two-thirds of the vector is used to pass back captured sub- |
The first two-thirds of the vector is used to pass back captured sub- |
2261 |
strings, each substring using a pair of integers. The remaining third |
strings, each substring using a pair of integers. The remaining third |
2262 |
of the vector is used as workspace by pcre_exec() while matching cap- |
of the vector is used as workspace by pcre_exec() while matching cap- |
2263 |
turing subpatterns, and is not available for passing back information. |
turing subpatterns, and is not available for passing back information. |
2264 |
The number passed in ovecsize should always be a multiple of three. If |
The number passed in ovecsize should always be a multiple of three. If |
2265 |
it is not, it is rounded down. |
it is not, it is rounded down. |
2266 |
|
|
2267 |
When a match is successful, information about captured substrings is |
When a match is successful, information about captured substrings is |
2268 |
returned in pairs of integers, starting at the beginning of ovector, |
returned in pairs of integers, starting at the beginning of ovector, |
2269 |
and continuing up to two-thirds of its length at the most. The first |
and continuing up to two-thirds of its length at the most. The first |
2270 |
element of each pair is set to the byte offset of the first character |
element of each pair is set to the byte offset of the first character |
2271 |
in a substring, and the second is set to the byte offset of the first |
in a substring, and the second is set to the byte offset of the first |
2272 |
character after the end of a substring. Note: these values are always |
character after the end of a substring. Note: these values are always |
2273 |
byte offsets, even in UTF-8 mode. They are not character counts. |
byte offsets, even in UTF-8 mode. They are not character counts. |
2274 |
|
|
2275 |
The first pair of integers, ovector[0] and ovector[1], identify the |
The first pair of integers, ovector[0] and ovector[1], identify the |
2276 |
portion of the subject string matched by the entire pattern. The next |
portion of the subject string matched by the entire pattern. The next |
2277 |
pair is used for the first capturing subpattern, and so on. The value |
pair is used for the first capturing subpattern, and so on. The value |
2278 |
returned by pcre_exec() is one more than the highest numbered pair that |
returned by pcre_exec() is one more than the highest numbered pair that |
2279 |
has been set. For example, if two substrings have been captured, the |
has been set. For example, if two substrings have been captured, the |
2280 |
returned value is 3. If there are no capturing subpatterns, the return |
returned value is 3. If there are no capturing subpatterns, the return |
2281 |
value from a successful match is 1, indicating that just the first pair |
value from a successful match is 1, indicating that just the first pair |
2282 |
of offsets has been set. |
of offsets has been set. |
2283 |
|
|
2284 |
If a capturing subpattern is matched repeatedly, it is the last portion |
If a capturing subpattern is matched repeatedly, it is the last portion |
2285 |
of the string that it matched that is returned. |
of the string that it matched that is returned. |
2286 |
|
|
2287 |
If the vector is too small to hold all the captured substring offsets, |
If the vector is too small to hold all the captured substring offsets, |
2288 |
it is used as far as possible (up to two-thirds of its length), and the |
it is used as far as possible (up to two-thirds of its length), and the |
2289 |
function returns a value of zero. If the substring offsets are not of |
function returns a value of zero. If the substring offsets are not of |
2290 |
interest, pcre_exec() may be called with ovector passed as NULL and |
interest, pcre_exec() may be called with ovector passed as NULL and |
2291 |
ovecsize as zero. However, if the pattern contains back references and |
ovecsize as zero. However, if the pattern contains back references and |
2292 |
the ovector is not big enough to remember the related substrings, PCRE |
the ovector is not big enough to remember the related substrings, PCRE |
2293 |
has to get additional memory for use during matching. Thus it is usu- |
has to get additional memory for use during matching. Thus it is usu- |
2294 |
ally advisable to supply an ovector. |
ally advisable to supply an ovector. |
2295 |
|
|
2296 |
The pcre_fullinfo() function can be used to find out how many capturing |
The pcre_fullinfo() function can be used to find out how many capturing |
2297 |
subpatterns there are in a compiled pattern. The smallest size for |
subpatterns there are in a compiled pattern. The smallest size for |
2298 |
ovector that will allow for n captured substrings, in addition to the |
ovector that will allow for n captured substrings, in addition to the |
2299 |
offsets of the substring matched by the whole pattern, is (n+1)*3. |
offsets of the substring matched by the whole pattern, is (n+1)*3. |
2300 |
|
|
2301 |
It is possible for capturing subpattern number n+1 to match some part |
It is possible for capturing subpattern number n+1 to match some part |
2302 |
of the subject when subpattern n has not been used at all. For example, |
of the subject when subpattern n has not been used at all. For example, |
2303 |
if the string "abc" is matched against the pattern (a|(z))(bc) the |
if the string "abc" is matched against the pattern (a|(z))(bc) the |
2304 |
return from the function is 4, and subpatterns 1 and 3 are matched, but |
return from the function is 4, and subpatterns 1 and 3 are matched, but |
2305 |
2 is not. When this happens, both values in the offset pairs corre- |
2 is not. When this happens, both values in the offset pairs corre- |
2306 |
sponding to unused subpatterns are set to -1. |
sponding to unused subpatterns are set to -1. |
2307 |
|
|
2308 |
Offset values that correspond to unused subpatterns at the end of the |
Offset values that correspond to unused subpatterns at the end of the |
2309 |
expression are also set to -1. For example, if the string "abc" is |
expression are also set to -1. For example, if the string "abc" is |
2310 |
matched against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not |
matched against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not |
2311 |
matched. The return from the function is 2, because the highest used |
matched. The return from the function is 2, because the highest used |
2312 |
capturing subpattern number is 1. However, you can refer to the offsets |
capturing subpattern number is 1. However, you can refer to the offsets |
2313 |
for the second and third capturing subpatterns if you wish (assuming |
for the second and third capturing subpatterns if you wish (assuming |
2314 |
the vector is large enough, of course). |
the vector is large enough, of course). |
2315 |
|
|
2316 |
Some convenience functions are provided for extracting the captured |
Some convenience functions are provided for extracting the captured |
2317 |
substrings as separate strings. These are described below. |
substrings as separate strings. These are described below. |
2318 |
|
|
2319 |
Error return values from pcre_exec() |
Error return values from pcre_exec() |
2320 |
|
|
2321 |
If pcre_exec() fails, it returns a negative number. The following are |
If pcre_exec() fails, it returns a negative number. The following are |
2322 |
defined in the header file: |
defined in the header file: |
2323 |
|
|
2324 |
PCRE_ERROR_NOMATCH (-1) |
PCRE_ERROR_NOMATCH (-1) |
2327 |
|
|
2328 |
PCRE_ERROR_NULL (-2) |
PCRE_ERROR_NULL (-2) |
2329 |
|
|
2330 |
Either code or subject was passed as NULL, or ovector was NULL and |
Either code or subject was passed as NULL, or ovector was NULL and |
2331 |
ovecsize was not zero. |
ovecsize was not zero. |
2332 |
|
|
2333 |
PCRE_ERROR_BADOPTION (-3) |
PCRE_ERROR_BADOPTION (-3) |
2336 |
|
|
2337 |
PCRE_ERROR_BADMAGIC (-4) |
PCRE_ERROR_BADMAGIC (-4) |
2338 |
|
|
2339 |
PCRE stores a 4-byte "magic number" at the start of the compiled code, |
PCRE stores a 4-byte "magic number" at the start of the compiled code, |
2340 |
to catch the case when it is passed a junk pointer and to detect when a |
to catch the case when it is passed a junk pointer and to detect when a |
2341 |
pattern that was compiled in an environment of one endianness is run in |
pattern that was compiled in an environment of one endianness is run in |
2342 |
an environment with the other endianness. This is the error that PCRE |
an environment with the other endianness. This is the error that PCRE |
2343 |
gives when the magic number is not present. |
gives when the magic number is not present. |
2344 |
|
|
2345 |
PCRE_ERROR_UNKNOWN_OPCODE (-5) |
PCRE_ERROR_UNKNOWN_OPCODE (-5) |
2346 |
|
|
2347 |
While running the pattern match, an unknown item was encountered in the |
While running the pattern match, an unknown item was encountered in the |
2348 |
compiled pattern. This error could be caused by a bug in PCRE or by |
compiled pattern. This error could be caused by a bug in PCRE or by |
2349 |
overwriting of the compiled pattern. |
overwriting of the compiled pattern. |
2350 |
|
|
2351 |
PCRE_ERROR_NOMEMORY (-6) |
PCRE_ERROR_NOMEMORY (-6) |
2352 |
|
|
2353 |
If a pattern contains back references, but the ovector that is passed |
If a pattern contains back references, but the ovector that is passed |
2354 |
to pcre_exec() is not big enough to remember the referenced substrings, |
to pcre_exec() is not big enough to remember the referenced substrings, |
2355 |
PCRE gets a block of memory at the start of matching to use for this |
PCRE gets a block of memory at the start of matching to use for this |
2356 |
purpose. If the call via pcre_malloc() fails, this error is given. The |
purpose. If the call via pcre_malloc() fails, this error is given. The |
2357 |
memory is automatically freed at the end of matching. |
memory is automatically freed at the end of matching. |
2358 |
|
|
2359 |
This error is also given if pcre_stack_malloc() fails in pcre_exec(). |
This error is also given if pcre_stack_malloc() fails in pcre_exec(). |
2360 |
This can happen only when PCRE has been compiled with --disable-stack- |
This can happen only when PCRE has been compiled with --disable-stack- |
2361 |
for-recursion. |
for-recursion. |
2362 |
|
|
2363 |
PCRE_ERROR_NOSUBSTRING (-7) |
PCRE_ERROR_NOSUBSTRING (-7) |
2364 |
|
|
2365 |
This error is used by the pcre_copy_substring(), pcre_get_substring(), |
This error is used by the pcre_copy_substring(), pcre_get_substring(), |
2366 |
and pcre_get_substring_list() functions (see below). It is never |
and pcre_get_substring_list() functions (see below). It is never |
2367 |
returned by pcre_exec(). |
returned by pcre_exec(). |
2368 |
|
|
2369 |
PCRE_ERROR_MATCHLIMIT (-8) |
PCRE_ERROR_MATCHLIMIT (-8) |
2370 |
|
|
2371 |
The backtracking limit, as specified by the match_limit field in a |
The backtracking limit, as specified by the match_limit field in a |
2372 |
pcre_extra structure (or defaulted) was reached. See the description |
pcre_extra structure (or defaulted) was reached. See the description |
2373 |
above. |
above. |
2374 |
|
|
2375 |
PCRE_ERROR_CALLOUT (-9) |
PCRE_ERROR_CALLOUT (-9) |
2376 |
|
|
2377 |
This error is never generated by pcre_exec() itself. It is provided for |
This error is never generated by pcre_exec() itself. It is provided for |
2378 |
use by callout functions that want to yield a distinctive error code. |
use by callout functions that want to yield a distinctive error code. |
2379 |
See the pcrecallout documentation for details. |
See the pcrecallout documentation for details. |
2380 |
|
|
2381 |
PCRE_ERROR_BADUTF8 (-10) |
PCRE_ERROR_BADUTF8 (-10) |
2382 |
|
|
2383 |
A string that contains an invalid UTF-8 byte sequence was passed as a |
A string that contains an invalid UTF-8 byte sequence was passed as a |
2384 |
subject. |
subject. |
2385 |
|
|
2386 |
PCRE_ERROR_BADUTF8_OFFSET (-11) |
PCRE_ERROR_BADUTF8_OFFSET (-11) |
2387 |
|
|
2388 |
The UTF-8 byte sequence that was passed as a subject was valid, but the |
The UTF-8 byte sequence that was passed as a subject was valid, but the |
2389 |
value of startoffset did not point to the beginning of a UTF-8 charac- |
value of startoffset did not point to the beginning of a UTF-8 charac- |
2390 |
ter. |
ter. |
2391 |
|
|
2392 |
PCRE_ERROR_PARTIAL (-12) |
PCRE_ERROR_PARTIAL (-12) |
2393 |
|
|
2394 |
The subject string did not match, but it did match partially. See the |
The subject string did not match, but it did match partially. See the |
2395 |
pcrepartial documentation for details of partial matching. |
pcrepartial documentation for details of partial matching. |
2396 |
|
|
2397 |
PCRE_ERROR_BADPARTIAL (-13) |
PCRE_ERROR_BADPARTIAL (-13) |
2398 |
|
|
2399 |
This code is no longer in use. It was formerly returned when the |
This code is no longer in use. It was formerly returned when the |
2400 |
PCRE_PARTIAL option was used with a compiled pattern containing items |
PCRE_PARTIAL option was used with a compiled pattern containing items |
2401 |
that were not supported for partial matching. From release 8.00 |
that were not supported for partial matching. From release 8.00 |
2402 |
onwards, there are no restrictions on partial matching. |
onwards, there are no restrictions on partial matching. |
2403 |
|
|
2404 |
PCRE_ERROR_INTERNAL (-14) |
PCRE_ERROR_INTERNAL (-14) |
2405 |
|
|
2406 |
An unexpected internal error has occurred. This error could be caused |
An unexpected internal error has occurred. This error could be caused |
2407 |
by a bug in PCRE or by overwriting of the compiled pattern. |
by a bug in PCRE or by overwriting of the compiled pattern. |
2408 |
|
|
2409 |
PCRE_ERROR_BADCOUNT (-15) |
PCRE_ERROR_BADCOUNT (-15) |
2413 |
PCRE_ERROR_RECURSIONLIMIT (-21) |
PCRE_ERROR_RECURSIONLIMIT (-21) |
2414 |
|
|
2415 |
The internal recursion limit, as specified by the match_limit_recursion |
The internal recursion limit, as specified by the match_limit_recursion |
2416 |
field in a pcre_extra structure (or defaulted) was reached. See the |
field in a pcre_extra structure (or defaulted) was reached. See the |
2417 |
description above. |
description above. |
2418 |
|
|
2419 |
PCRE_ERROR_BADNEWLINE (-23) |
PCRE_ERROR_BADNEWLINE (-23) |
2436 |
int pcre_get_substring_list(const char *subject, |
int pcre_get_substring_list(const char *subject, |
2437 |
int *ovector, int stringcount, const char ***listptr); |
int *ovector, int stringcount, const char ***listptr); |
2438 |
|
|
2439 |
Captured substrings can be accessed directly by using the offsets |
Captured substrings can be accessed directly by using the offsets |
2440 |
returned by pcre_exec() in ovector. For convenience, the functions |
returned by pcre_exec() in ovector. For convenience, the functions |
2441 |
pcre_copy_substring(), pcre_get_substring(), and pcre_get_sub- |
pcre_copy_substring(), pcre_get_substring(), and pcre_get_sub- |
2442 |
string_list() are provided for extracting captured substrings as new, |
string_list() are provided for extracting captured substrings as new, |
2443 |
separate, zero-terminated strings. These functions identify substrings |
separate, zero-terminated strings. These functions identify substrings |
2444 |
by number. The next section describes functions for extracting named |
by number. The next section describes functions for extracting named |
2445 |
substrings. |
substrings. |
2446 |
|
|
2447 |
A substring that contains a binary zero is correctly extracted and has |
A substring that contains a binary zero is correctly extracted and has |
2448 |
a further zero added on the end, but the result is not, of course, a C |
a further zero added on the end, but the result is not, of course, a C |
2449 |
string. However, you can process such a string by referring to the |
string. However, you can process such a string by referring to the |
2450 |
length that is returned by pcre_copy_substring() and pcre_get_sub- |
length that is returned by pcre_copy_substring() and pcre_get_sub- |
2451 |
string(). Unfortunately, the interface to pcre_get_substring_list() is |
string(). Unfortunately, the interface to pcre_get_substring_list() is |
2452 |
not adequate for handling strings containing binary zeros, because the |
not adequate for handling strings containing binary zeros, because the |
2453 |
end of the final string is not independently indicated. |
end of the final string is not independently indicated. |
2454 |
|
|
2455 |
The first three arguments are the same for all three of these func- |
The first three arguments are the same for all three of these func- |
2456 |
tions: subject is the subject string that has just been successfully |
tions: subject is the subject string that has just been successfully |
2457 |
matched, ovector is a pointer to the vector of integer offsets that was |
matched, ovector is a pointer to the vector of integer offsets that was |
2458 |
passed to pcre_exec(), and stringcount is the number of substrings that |
passed to pcre_exec(), and stringcount is the number of substrings that |
2459 |
were captured by the match, including the substring that matched the |
were captured by the match, including the substring that matched the |
2460 |
entire regular expression. This is the value returned by pcre_exec() if |
entire regular expression. This is the value returned by pcre_exec() if |
2461 |
it is greater than zero. If pcre_exec() returned zero, indicating that |
it is greater than zero. If pcre_exec() returned zero, indicating that |
2462 |
it ran out of space in ovector, the value passed as stringcount should |
it ran out of space in ovector, the value passed as stringcount should |
2463 |
be the number of elements in the vector divided by three. |
be the number of elements in the vector divided by three. |
2464 |
|
|
2465 |
The functions pcre_copy_substring() and pcre_get_substring() extract a |
The functions pcre_copy_substring() and pcre_get_substring() extract a |
2466 |
single substring, whose number is given as stringnumber. A value of |
single substring, whose number is given as stringnumber. A value of |
2467 |
zero extracts the substring that matched the entire pattern, whereas |
zero extracts the substring that matched the entire pattern, whereas |
2468 |
higher values extract the captured substrings. For pcre_copy_sub- |
higher values extract the captured substrings. For pcre_copy_sub- |
2469 |
string(), the string is placed in buffer, whose length is given by |
string(), the string is placed in buffer, whose length is given by |
2470 |
buffersize, while for pcre_get_substring() a new block of memory is |
buffersize, while for pcre_get_substring() a new block of memory is |
2471 |
obtained via pcre_malloc, and its address is returned via stringptr. |
obtained via pcre_malloc, and its address is returned via stringptr. |
2472 |
The yield of the function is the length of the string, not including |
The yield of the function is the length of the string, not including |
2473 |
the terminating zero, or one of these error codes: |
the terminating zero, or one of these error codes: |
2474 |
|
|
2475 |
PCRE_ERROR_NOMEMORY (-6) |
PCRE_ERROR_NOMEMORY (-6) |
2476 |
|
|
2477 |
The buffer was too small for pcre_copy_substring(), or the attempt to |
The buffer was too small for pcre_copy_substring(), or the attempt to |
2478 |
get memory failed for pcre_get_substring(). |
get memory failed for pcre_get_substring(). |
2479 |
|
|
2480 |
PCRE_ERROR_NOSUBSTRING (-7) |
PCRE_ERROR_NOSUBSTRING (-7) |
2481 |
|
|
2482 |
There is no substring whose number is stringnumber. |
There is no substring whose number is stringnumber. |
2483 |
|
|
2484 |
The pcre_get_substring_list() function extracts all available sub- |
The pcre_get_substring_list() function extracts all available sub- |
2485 |
strings and builds a list of pointers to them. All this is done in a |
strings and builds a list of pointers to them. All this is done in a |
2486 |
single block of memory that is obtained via pcre_malloc. The address of |
single block of memory that is obtained via pcre_malloc. The address of |
2487 |
the memory block is returned via listptr, which is also the start of |
the memory block is returned via listptr, which is also the start of |
2488 |
the list of string pointers. The end of the list is marked by a NULL |
the list of string pointers. The end of the list is marked by a NULL |
2489 |
pointer. The yield of the function is zero if all went well, or the |
pointer. The yield of the function is zero if all went well, or the |
2490 |
error code |
error code |
2491 |
|
|
2492 |
PCRE_ERROR_NOMEMORY (-6) |
PCRE_ERROR_NOMEMORY (-6) |
2493 |
|
|
2494 |
if the attempt to get the memory block failed. |
if the attempt to get the memory block failed. |
2495 |
|
|
2496 |
When any of these functions encounter a substring that is unset, which |
When any of these functions encounter a substring that is unset, which |
2497 |
can happen when capturing subpattern number n+1 matches some part of |
can happen when capturing subpattern number n+1 matches some part of |
2498 |
the subject, but subpattern n has not been used at all, they return an |
the subject, but subpattern n has not been used at all, they return an |
2499 |
empty string. This can be distinguished from a genuine zero-length sub- |
empty string. This can be distinguished from a genuine zero-length sub- |
2500 |
string by inspecting the appropriate offset in ovector, which is nega- |
string by inspecting the appropriate offset in ovector, which is nega- |
2501 |
tive for unset substrings. |
tive for unset substrings. |
2502 |
|
|
2503 |
The two convenience functions pcre_free_substring() and pcre_free_sub- |
The two convenience functions pcre_free_substring() and pcre_free_sub- |
2504 |
string_list() can be used to free the memory returned by a previous |
string_list() can be used to free the memory returned by a previous |
2505 |
call of pcre_get_substring() or pcre_get_substring_list(), respec- |
call of pcre_get_substring() or pcre_get_substring_list(), respec- |
2506 |
tively. They do nothing more than call the function pointed to by |
tively. They do nothing more than call the function pointed to by |
2507 |
pcre_free, which of course could be called directly from a C program. |
pcre_free, which of course could be called directly from a C program. |
2508 |
However, PCRE is used in some situations where it is linked via a spe- |
However, PCRE is used in some situations where it is linked via a spe- |
2509 |
cial interface to another programming language that cannot use |
cial interface to another programming language that cannot use |
2510 |
pcre_free directly; it is for these cases that the functions are pro- |
pcre_free directly; it is for these cases that the functions are pro- |
2511 |
vided. |
vided. |
2512 |
|
|
2513 |
|
|
2526 |
int stringcount, const char *stringname, |
int stringcount, const char *stringname, |
2527 |
const char **stringptr); |
const char **stringptr); |
2528 |
|
|
2529 |
To extract a substring by name, you first have to find associated num- |
To extract a substring by name, you first have to find associated num- |
2530 |
ber. For example, for this pattern |
ber. For example, for this pattern |
2531 |
|
|
2532 |
(a+)b(?<xxx>\d+)... |
(a+)b(?<xxx>\d+)... |
2535 |
be unique (PCRE_DUPNAMES was not set), you can find the number from the |
be unique (PCRE_DUPNAMES was not set), you can find the number from the |
2536 |
name by calling pcre_get_stringnumber(). The first argument is the com- |
name by calling pcre_get_stringnumber(). The first argument is the com- |
2537 |
piled pattern, and the second is the name. The yield of the function is |
piled pattern, and the second is the name. The yield of the function is |
2538 |
the subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if there is no |
the subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if there is no |
2539 |
subpattern of that name. |
subpattern of that name. |
2540 |
|
|
2541 |
Given the number, you can extract the substring directly, or use one of |
Given the number, you can extract the substring directly, or use one of |
2542 |
the functions described in the previous section. For convenience, there |
the functions described in the previous section. For convenience, there |
2543 |
are also two functions that do the whole job. |
are also two functions that do the whole job. |
2544 |
|
|
2545 |
Most of the arguments of pcre_copy_named_substring() and |
Most of the arguments of pcre_copy_named_substring() and |
2546 |
pcre_get_named_substring() are the same as those for the similarly |
pcre_get_named_substring() are the same as those for the similarly |
2547 |
named functions that extract by number. As these are described in the |
named functions that extract by number. As these are described in the |
2548 |
previous section, they are not re-described here. There are just two |
previous section, they are not re-described here. There are just two |
2549 |
differences: |
differences: |
2550 |
|
|
2551 |
First, instead of a substring number, a substring name is given. Sec- |
First, instead of a substring number, a substring name is given. Sec- |
2552 |
ond, there is an extra argument, given at the start, which is a pointer |
ond, there is an extra argument, given at the start, which is a pointer |
2553 |
to the compiled pattern. This is needed in order to gain access to the |
to the compiled pattern. This is needed in order to gain access to the |
2554 |
name-to-number translation table. |
name-to-number translation table. |
2555 |
|
|
2556 |
These functions call pcre_get_stringnumber(), and if it succeeds, they |
These functions call pcre_get_stringnumber(), and if it succeeds, they |
2557 |
then call pcre_copy_substring() or pcre_get_substring(), as appropri- |
then call pcre_copy_substring() or pcre_get_substring(), as appropri- |
2558 |
ate. NOTE: If PCRE_DUPNAMES is set and there are duplicate names, the |
ate. NOTE: If PCRE_DUPNAMES is set and there are duplicate names, the |
2559 |
behaviour may not be what you want (see the next section). |
behaviour may not be what you want (see the next section). |
2560 |
|
|
2561 |
Warning: If the pattern uses the (?| feature to set up multiple subpat- |
Warning: If the pattern uses the (?| feature to set up multiple subpat- |
2562 |
terns with the same number, as described in the section on duplicate |
terns with the same number, as described in the section on duplicate |
2563 |
subpattern numbers in the pcrepattern page, you cannot use names to |
subpattern numbers in the pcrepattern page, you cannot use names to |
2564 |
distinguish the different subpatterns, because names are not included |
distinguish the different subpatterns, because names are not included |
2565 |
in the compiled code. The matching process uses only numbers. For this |
in the compiled code. The matching process uses only numbers. For this |
2566 |
reason, the use of different names for subpatterns of the same number |
reason, the use of different names for subpatterns of the same number |
2567 |
causes an error at compile time. |
causes an error at compile time. |
2568 |
|
|
2569 |
|
|
2572 |
int pcre_get_stringtable_entries(const pcre *code, |
int pcre_get_stringtable_entries(const pcre *code, |
2573 |
const char *name, char **first, char **last); |
const char *name, char **first, char **last); |
2574 |
|
|
2575 |
When a pattern is compiled with the PCRE_DUPNAMES option, names for |
When a pattern is compiled with the PCRE_DUPNAMES option, names for |
2576 |
subpatterns are not required to be unique. (Duplicate names are always |
subpatterns are not required to be unique. (Duplicate names are always |
2577 |
allowed for subpatterns with the same number, created by using the (?| |
allowed for subpatterns with the same number, created by using the (?| |
2578 |
feature. Indeed, if such subpatterns are named, they are required to |
feature. Indeed, if such subpatterns are named, they are required to |
2579 |
use the same names.) |
use the same names.) |
2580 |
|
|
2581 |
Normally, patterns with duplicate names are such that in any one match, |
Normally, patterns with duplicate names are such that in any one match, |
2582 |
only one of the named subpatterns participates. An example is shown in |
only one of the named subpatterns participates. An example is shown in |
2583 |
the pcrepattern documentation. |
the pcrepattern documentation. |
2584 |
|
|
2585 |
When duplicates are present, pcre_copy_named_substring() and |
When duplicates are present, pcre_copy_named_substring() and |
2586 |
pcre_get_named_substring() return the first substring corresponding to |
pcre_get_named_substring() return the first substring corresponding to |
2587 |
the given name that is set. If none are set, PCRE_ERROR_NOSUBSTRING |
the given name that is set. If none are set, PCRE_ERROR_NOSUBSTRING |
2588 |
(-7) is returned; no data is returned. The pcre_get_stringnumber() |
(-7) is returned; no data is returned. The pcre_get_stringnumber() |
2589 |
function returns one of the numbers that are associated with the name, |
function returns one of the numbers that are associated with the name, |
2590 |
but it is not defined which it is. |
but it is not defined which it is. |
2591 |
|
|
2592 |
If you want to get full details of all captured substrings for a given |
If you want to get full details of all captured substrings for a given |
2593 |
name, you must use the pcre_get_stringtable_entries() function. The |
name, you must use the pcre_get_stringtable_entries() function. The |
2594 |
first argument is the compiled pattern, and the second is the name. The |
first argument is the compiled pattern, and the second is the name. The |
2595 |
third and fourth are pointers to variables which are updated by the |
third and fourth are pointers to variables which are updated by the |
2596 |
function. After it has run, they point to the first and last entries in |
function. After it has run, they point to the first and last entries in |
2597 |
the name-to-number table for the given name. The function itself |
the name-to-number table for the given name. The function itself |
2598 |
returns the length of each entry, or PCRE_ERROR_NOSUBSTRING (-7) if |
returns the length of each entry, or PCRE_ERROR_NOSUBSTRING (-7) if |
2599 |
there are none. The format of the table is described above in the sec- |
there are none. The format of the table is described above in the sec- |
2600 |
tion entitled Information about a pattern. Given all the relevant |
tion entitled Information about a pattern. Given all the relevant |
2601 |
entries for the name, you can extract each of their numbers, and hence |
entries for the name, you can extract each of their numbers, and hence |
2602 |
the captured data, if any. |
the captured data, if any. |
2603 |
|
|
2604 |
|
|
2605 |
FINDING ALL POSSIBLE MATCHES |
FINDING ALL POSSIBLE MATCHES |
2606 |
|
|
2607 |
The traditional matching function uses a similar algorithm to Perl, |
The traditional matching function uses a similar algorithm to Perl, |
2608 |
which stops when it finds the first match, starting at a given point in |
which stops when it finds the first match, starting at a given point in |
2609 |
the subject. If you want to find all possible matches, or the longest |
the subject. If you want to find all possible matches, or the longest |
2610 |
possible match, consider using the alternative matching function (see |
possible match, consider using the alternative matching function (see |
2611 |
below) instead. If you cannot use the alternative function, but still |
below) instead. If you cannot use the alternative function, but still |
2612 |
need to find all possible matches, you can kludge it up by making use |
need to find all possible matches, you can kludge it up by making use |
2613 |
of the callout facility, which is described in the pcrecallout documen- |
of the callout facility, which is described in the pcrecallout documen- |
2614 |
tation. |
tation. |
2615 |
|
|
2616 |
What you have to do is to insert a callout right at the end of the pat- |
What you have to do is to insert a callout right at the end of the pat- |
2617 |
tern. When your callout function is called, extract and save the cur- |
tern. When your callout function is called, extract and save the cur- |
2618 |
rent matched substring. Then return 1, which forces pcre_exec() to |
rent matched substring. Then return 1, which forces pcre_exec() to |
2619 |
backtrack and try other alternatives. Ultimately, when it runs out of |
backtrack and try other alternatives. Ultimately, when it runs out of |
2620 |
matches, pcre_exec() will yield PCRE_ERROR_NOMATCH. |
matches, pcre_exec() will yield PCRE_ERROR_NOMATCH. |
2621 |
|
|
2622 |
|
|
2627 |
int options, int *ovector, int ovecsize, |
int options, int *ovector, int ovecsize, |
2628 |
int *workspace, int wscount); |
int *workspace, int wscount); |
2629 |
|
|
2630 |
The function pcre_dfa_exec() is called to match a subject string |
The function pcre_dfa_exec() is called to match a subject string |
2631 |
against a compiled pattern, using a matching algorithm that scans the |
against a compiled pattern, using a matching algorithm that scans the |
2632 |
subject string just once, and does not backtrack. This has different |
subject string just once, and does not backtrack. This has different |
2633 |
characteristics to the normal algorithm, and is not compatible with |
characteristics to the normal algorithm, and is not compatible with |
2634 |
Perl. Some of the features of PCRE patterns are not supported. Never- |
Perl. Some of the features of PCRE patterns are not supported. Never- |
2635 |
theless, there are times when this kind of matching can be useful. For |
theless, there are times when this kind of matching can be useful. For |
2636 |
a discussion of the two matching algorithms, and a list of features |
a discussion of the two matching algorithms, and a list of features |
2637 |
that pcre_dfa_exec() does not support, see the pcrematching documenta- |
that pcre_dfa_exec() does not support, see the pcrematching documenta- |
2638 |
tion. |
tion. |
2639 |
|
|
2640 |
The arguments for the pcre_dfa_exec() function are the same as for |
The arguments for the pcre_dfa_exec() function are the same as for |
2641 |
pcre_exec(), plus two extras. The ovector argument is used in a differ- |
pcre_exec(), plus two extras. The ovector argument is used in a differ- |
2642 |
ent way, and this is described below. The other common arguments are |
ent way, and this is described below. The other common arguments are |
2643 |
used in the same way as for pcre_exec(), so their description is not |
used in the same way as for pcre_exec(), so their description is not |
2644 |
repeated here. |
repeated here. |
2645 |
|
|
2646 |
The two additional arguments provide workspace for the function. The |
The two additional arguments provide workspace for the function. The |
2647 |
workspace vector should contain at least 20 elements. It is used for |
workspace vector should contain at least 20 elements. It is used for |
2648 |
keeping track of multiple paths through the pattern tree. More |
keeping track of multiple paths through the pattern tree. More |
2649 |
workspace will be needed for patterns and subjects where there are a |
workspace will be needed for patterns and subjects where there are a |
2650 |
lot of potential matches. |
lot of potential matches. |
2651 |
|
|
2652 |
Here is an example of a simple call to pcre_dfa_exec(): |
Here is an example of a simple call to pcre_dfa_exec(): |
2668 |
|
|
2669 |
Option bits for pcre_dfa_exec() |
Option bits for pcre_dfa_exec() |
2670 |
|
|
2671 |
The unused bits of the options argument for pcre_dfa_exec() must be |
The unused bits of the options argument for pcre_dfa_exec() must be |
2672 |
zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEW- |
zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEW- |
2673 |
LINE_xxx, PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, |
LINE_xxx, PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, |
2674 |
PCRE_NOTEMPTY_ATSTART, PCRE_NO_UTF8_CHECK, PCRE_BSR_ANYCRLF, |
PCRE_NOTEMPTY_ATSTART, PCRE_NO_UTF8_CHECK, PCRE_BSR_ANYCRLF, |
2675 |
PCRE_BSR_UNICODE, PCRE_NO_START_OPTIMIZE, PCRE_PARTIAL_HARD, PCRE_PAR- |
PCRE_BSR_UNICODE, PCRE_NO_START_OPTIMIZE, PCRE_PARTIAL_HARD, PCRE_PAR- |
2676 |
TIAL_SOFT, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last |
TIAL_SOFT, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last |
2677 |
four of these are exactly the same as for pcre_exec(), so their |
four of these are exactly the same as for pcre_exec(), so their |
2678 |
description is not repeated here. |
description is not repeated here. |
2679 |
|
|
2680 |
PCRE_PARTIAL_HARD |
PCRE_PARTIAL_HARD |
2681 |
PCRE_PARTIAL_SOFT |
PCRE_PARTIAL_SOFT |
2682 |
|
|
2683 |
These have the same general effect as they do for pcre_exec(), but the |
These have the same general effect as they do for pcre_exec(), but the |
2684 |
details are slightly different. When PCRE_PARTIAL_HARD is set for |
details are slightly different. When PCRE_PARTIAL_HARD is set for |
2685 |
pcre_dfa_exec(), it returns PCRE_ERROR_PARTIAL if the end of the sub- |
pcre_dfa_exec(), it returns PCRE_ERROR_PARTIAL if the end of the sub- |
2686 |
ject is reached and there is still at least one matching possibility |
ject is reached and there is still at least one matching possibility |
2687 |
that requires additional characters. This happens even if some complete |
that requires additional characters. This happens even if some complete |
2688 |
matches have also been found. When PCRE_PARTIAL_SOFT is set, the return |
matches have also been found. When PCRE_PARTIAL_SOFT is set, the return |
2689 |
code PCRE_ERROR_NOMATCH is converted into PCRE_ERROR_PARTIAL if the end |
code PCRE_ERROR_NOMATCH is converted into PCRE_ERROR_PARTIAL if the end |
2690 |
of the subject is reached, there have been no complete matches, but |
of the subject is reached, there have been no complete matches, but |
2691 |
there is still at least one matching possibility. The portion of the |
there is still at least one matching possibility. The portion of the |
2692 |
string that was inspected when the longest partial match was found is |
string that was inspected when the longest partial match was found is |
2693 |
set as the first matching string in both cases. |
set as the first matching string in both cases. |
2694 |
|
|
2695 |
PCRE_DFA_SHORTEST |
PCRE_DFA_SHORTEST |
2696 |
|
|
2697 |
Setting the PCRE_DFA_SHORTEST option causes the matching algorithm to |
Setting the PCRE_DFA_SHORTEST option causes the matching algorithm to |
2698 |
stop as soon as it has found one match. Because of the way the alterna- |
stop as soon as it has found one match. Because of the way the alterna- |
2699 |
tive algorithm works, this is necessarily the shortest possible match |
tive algorithm works, this is necessarily the shortest possible match |
2700 |
at the first possible matching point in the subject string. |
at the first possible matching point in the subject string. |
2701 |
|
|
2702 |
PCRE_DFA_RESTART |
PCRE_DFA_RESTART |
2703 |
|
|
2704 |
When pcre_dfa_exec() returns a partial match, it is possible to call it |
When pcre_dfa_exec() returns a partial match, it is possible to call it |
2705 |
again, with additional subject characters, and have it continue with |
again, with additional subject characters, and have it continue with |
2706 |
the same match. The PCRE_DFA_RESTART option requests this action; when |
the same match. The PCRE_DFA_RESTART option requests this action; when |
2707 |
it is set, the workspace and wscount options must reference the same |
it is set, the workspace and wscount options must reference the same |
2708 |
vector as before because data about the match so far is left in them |
vector as before because data about the match so far is left in them |
2709 |
after a partial match. There is more discussion of this facility in the |
after a partial match. There is more discussion of this facility in the |
2710 |
pcrepartial documentation. |
pcrepartial documentation. |
2711 |
|
|
2712 |
Successful returns from pcre_dfa_exec() |
Successful returns from pcre_dfa_exec() |
2713 |
|
|
2714 |
When pcre_dfa_exec() succeeds, it may have matched more than one sub- |
When pcre_dfa_exec() succeeds, it may have matched more than one sub- |
2715 |
string in the subject. Note, however, that all the matches from one run |
string in the subject. Note, however, that all the matches from one run |
2716 |
of the function start at the same point in the subject. The shorter |
of the function start at the same point in the subject. The shorter |
2717 |
matches are all initial substrings of the longer matches. For example, |
matches are all initial substrings of the longer matches. For example, |
2718 |
if the pattern |
if the pattern |
2719 |
|
|
2720 |
<.*> |
<.*> |
2729 |
<something> <something else> |
<something> <something else> |
2730 |
<something> <something else> <something further> |
<something> <something else> <something further> |
2731 |
|
|
2732 |
On success, the yield of the function is a number greater than zero, |
On success, the yield of the function is a number greater than zero, |
2733 |
which is the number of matched substrings. The substrings themselves |
which is the number of matched substrings. The substrings themselves |
2734 |
are returned in ovector. Each string uses two elements; the first is |
are returned in ovector. Each string uses two elements; the first is |
2735 |
the offset to the start, and the second is the offset to the end. In |
the offset to the start, and the second is the offset to the end. In |
2736 |
fact, all the strings have the same start offset. (Space could have |
fact, all the strings have the same start offset. (Space could have |
2737 |
been saved by giving this only once, but it was decided to retain some |
been saved by giving this only once, but it was decided to retain some |
2738 |
compatibility with the way pcre_exec() returns data, even though the |
compatibility with the way pcre_exec() returns data, even though the |
2739 |
meaning of the strings is different.) |
meaning of the strings is different.) |
2740 |
|
|
2741 |
The strings are returned in reverse order of length; that is, the long- |
The strings are returned in reverse order of length; that is, the long- |
2742 |
est matching string is given first. If there were too many matches to |
est matching string is given first. If there were too many matches to |
2743 |
fit into ovector, the yield of the function is zero, and the vector is |
fit into ovector, the yield of the function is zero, and the vector is |
2744 |
filled with the longest matches. |
filled with the longest matches. |
2745 |
|
|
2746 |
Error returns from pcre_dfa_exec() |
Error returns from pcre_dfa_exec() |
2747 |
|
|
2748 |
The pcre_dfa_exec() function returns a negative number when it fails. |
The pcre_dfa_exec() function returns a negative number when it fails. |
2749 |
Many of the errors are the same as for pcre_exec(), and these are |
Many of the errors are the same as for pcre_exec(), and these are |
2750 |
described above. There are in addition the following errors that are |
described above. There are in addition the following errors that are |
2751 |
specific to pcre_dfa_exec(): |
specific to pcre_dfa_exec(): |
2752 |
|
|
2753 |
PCRE_ERROR_DFA_UITEM (-16) |
PCRE_ERROR_DFA_UITEM (-16) |
2754 |
|
|
2755 |
This return is given if pcre_dfa_exec() encounters an item in the pat- |
This return is given if pcre_dfa_exec() encounters an item in the pat- |
2756 |
tern that it does not support, for instance, the use of \C or a back |
tern that it does not support, for instance, the use of \C or a back |
2757 |
reference. |
reference. |
2758 |
|
|
2759 |
PCRE_ERROR_DFA_UCOND (-17) |
PCRE_ERROR_DFA_UCOND (-17) |
2760 |
|
|
2761 |
This return is given if pcre_dfa_exec() encounters a condition item |
This return is given if pcre_dfa_exec() encounters a condition item |
2762 |
that uses a back reference for the condition, or a test for recursion |
that uses a back reference for the condition, or a test for recursion |
2763 |
in a specific group. These are not supported. |
in a specific group. These are not supported. |
2764 |
|
|
2765 |
PCRE_ERROR_DFA_UMLIMIT (-18) |
PCRE_ERROR_DFA_UMLIMIT (-18) |
2766 |
|
|
2767 |
This return is given if pcre_dfa_exec() is called with an extra block |
This return is given if pcre_dfa_exec() is called with an extra block |
2768 |
that contains a setting of the match_limit field. This is not supported |
that contains a setting of the match_limit field. This is not supported |
2769 |
(it is meaningless). |
(it is meaningless). |
2770 |
|
|
2771 |
PCRE_ERROR_DFA_WSSIZE (-19) |
PCRE_ERROR_DFA_WSSIZE (-19) |
2772 |
|
|
2773 |
This return is given if pcre_dfa_exec() runs out of space in the |
This return is given if pcre_dfa_exec() runs out of space in the |
2774 |
workspace vector. |
workspace vector. |
2775 |
|
|
2776 |
PCRE_ERROR_DFA_RECURSE (-20) |
PCRE_ERROR_DFA_RECURSE (-20) |
2777 |
|
|
2778 |
When a recursive subpattern is processed, the matching function calls |
When a recursive subpattern is processed, the matching function calls |
2779 |
itself recursively, using private vectors for ovector and workspace. |
itself recursively, using private vectors for ovector and workspace. |
2780 |
This error is given if the output vector is not large enough. This |
This error is given if the output vector is not large enough. This |
2781 |
should be extremely rare, as a vector of size 1000 is used. |
should be extremely rare, as a vector of size 1000 is used. |
2782 |
|
|
2783 |
|
|
2784 |
SEE ALSO |
SEE ALSO |
2785 |
|
|
2786 |
pcrebuild(3), pcrecallout(3), pcrecpp(3)(3), pcrematching(3), pcrepar- |
pcrebuild(3), pcrecallout(3), pcrecpp(3)(3), pcrematching(3), pcrepar- |
2787 |
tial(3), pcreposix(3), pcreprecompile(3), pcresample(3), pcrestack(3). |
tial(3), pcreposix(3), pcreprecompile(3), pcresample(3), pcrestack(3). |
2788 |
|
|
2789 |
|
|
2796 |
|
|
2797 |
REVISION |
REVISION |
2798 |
|
|
2799 |
Last updated: 15 June 2010 |
Last updated: 21 June 2010 |
2800 |
Copyright (c) 1997-2010 University of Cambridge. |
Copyright (c) 1997-2010 University of Cambridge. |
2801 |
------------------------------------------------------------------------------ |
------------------------------------------------------------------------------ |
2802 |
|
|