| 18 |
<li><a name="TOC3" href="#SEC3">LIMITATIONS</a> |
<li><a name="TOC3" href="#SEC3">LIMITATIONS</a> |
| 19 |
<li><a name="TOC4" href="#SEC4">UTF-8 AND UNICODE PROPERTY SUPPORT</a> |
<li><a name="TOC4" href="#SEC4">UTF-8 AND UNICODE PROPERTY SUPPORT</a> |
| 20 |
<li><a name="TOC5" href="#SEC5">AUTHOR</a> |
<li><a name="TOC5" href="#SEC5">AUTHOR</a> |
| 21 |
|
<li><a name="TOC6" href="#SEC6">REVISION</a> |
| 22 |
</ul> |
</ul> |
| 23 |
<br><a name="SEC1" href="#TOC1">INTRODUCTION</a><br> |
<br><a name="SEC1" href="#TOC1">INTRODUCTION</a><br> |
| 24 |
<P> |
<P> |
| 25 |
The PCRE library is a set of functions that implement regular expression |
The PCRE library is a set of functions that implement regular expression |
| 26 |
pattern matching using the same syntax and semantics as Perl, with just a few |
pattern matching using the same syntax and semantics as Perl, with just a few |
| 27 |
differences. The current implementation of PCRE (release 6.x) corresponds |
differences. (Certain features that appeared in Python and PCRE before they |
| 28 |
approximately with Perl 5.8, including support for UTF-8 encoded strings and |
appeared in Perl are also available using the Python syntax.) |
|
Unicode general category properties. However, this support has to be explicitly |
|
|
enabled; it is not the default. |
|
| 29 |
</P> |
</P> |
| 30 |
<P> |
<P> |
| 31 |
In addition to the Perl-compatible matching function, PCRE also contains an |
The current implementation of PCRE (release 7.x) corresponds approximately with |
| 32 |
|
Perl 5.10, including support for UTF-8 encoded strings and Unicode general |
| 33 |
|
category properties. However, UTF-8 and Unicode support has to be explicitly |
| 34 |
|
enabled; it is not the default. The Unicode tables correspond to Unicode |
| 35 |
|
release 5.0.0. |
| 36 |
|
</P> |
| 37 |
|
<P> |
| 38 |
|
In addition to the Perl-compatible matching function, PCRE contains an |
| 39 |
alternative matching function that matches the same compiled patterns in a |
alternative matching function that matches the same compiled patterns in a |
| 40 |
different way. In certain circumstances, the alternative function has some |
different way. In certain circumstances, the alternative function has some |
| 41 |
advantages. For a discussion of the two matching algorithms, see the |
advantages. For a discussion of the two matching algorithms, see the |
| 58 |
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
| 59 |
and |
and |
| 60 |
<a href="pcrecompat.html"><b>pcrecompat</b></a> |
<a href="pcrecompat.html"><b>pcrecompat</b></a> |
| 61 |
pages. |
pages. There is a syntax summary in the |
| 62 |
|
<a href="pcresyntax.html"><b>pcresyntax</b></a> |
| 63 |
|
page. |
| 64 |
</P> |
</P> |
| 65 |
<P> |
<P> |
| 66 |
Some features of PCRE can be included, excluded, or changed when the library is |
Some features of PCRE can be included, excluded, or changed when the library is |
| 90 |
follows: |
follows: |
| 91 |
<pre> |
<pre> |
| 92 |
pcre this document |
pcre this document |
| 93 |
|
pcre-config show PCRE installation configuration information |
| 94 |
pcreapi details of PCRE's native C API |
pcreapi details of PCRE's native C API |
| 95 |
pcrebuild options for building PCRE |
pcrebuild options for building PCRE |
| 96 |
pcrecallout details of the callout feature |
pcrecallout details of the callout feature |
| 100 |
pcrematching discussion of the two matching algorithms |
pcrematching discussion of the two matching algorithms |
| 101 |
pcrepartial details of the partial matching facility |
pcrepartial details of the partial matching facility |
| 102 |
pcrepattern syntax and semantics of supported regular expressions |
pcrepattern syntax and semantics of supported regular expressions |
| 103 |
|
pcresyntax quick syntax reference |
| 104 |
pcreperform discussion of performance issues |
pcreperform discussion of performance issues |
| 105 |
pcreposix the POSIX-compatible C API |
pcreposix the POSIX-compatible C API |
| 106 |
pcreprecompile details of saving and re-using precompiled patterns |
pcreprecompile details of saving and re-using precompiled patterns |
| 107 |
pcresample discussion of the sample program |
pcresample discussion of the sample program |
| 108 |
|
pcrestack discussion of stack usage |
| 109 |
pcretest description of the <b>pcretest</b> testing command |
pcretest description of the <b>pcretest</b> testing command |
| 110 |
</pre> |
</pre> |
| 111 |
In addition, in the "man" and HTML formats, there is a short page for each |
In addition, in the "man" and HTML formats, there is a short page for each |
| 124 |
distribution and the |
distribution and the |
| 125 |
<a href="pcrebuild.html"><b>pcrebuild</b></a> |
<a href="pcrebuild.html"><b>pcrebuild</b></a> |
| 126 |
documentation for details). In these cases the limit is substantially larger. |
documentation for details). In these cases the limit is substantially larger. |
| 127 |
However, the speed of execution will be slower. |
However, the speed of execution is slower. |
| 128 |
</P> |
</P> |
| 129 |
<P> |
<P> |
| 130 |
All values in repeating quantifiers must be less than 65536. |
All values in repeating quantifiers must be less than 65536. |
|
The maximum number of capturing subpatterns is 65535. |
|
| 131 |
</P> |
</P> |
| 132 |
<P> |
<P> |
| 133 |
There is no limit to the number of non-capturing subpatterns, but the maximum |
There is no limit to the number of parenthesized subpatterns, but there can be |
| 134 |
depth of nesting of all kinds of parenthesized subpattern, including capturing |
no more than 65535 capturing subpatterns. |
| 135 |
subpatterns, assertions, and other types of subpattern, is 200. |
</P> |
| 136 |
|
<P> |
| 137 |
|
The maximum length of name for a named subpattern is 32 characters, and the |
| 138 |
|
maximum number of named subpatterns is 10000. |
| 139 |
</P> |
</P> |
| 140 |
<P> |
<P> |
| 141 |
The maximum length of a subject string is the largest positive number that an |
The maximum length of a subject string is the largest positive number that an |
| 142 |
integer variable can hold. However, when using the traditional matching |
integer variable can hold. However, when using the traditional matching |
| 143 |
function, PCRE uses recursion to handle subpatterns and indefinite repetition. |
function, PCRE uses recursion to handle subpatterns and indefinite repetition. |
| 144 |
This means that the available stack space may limit the size of a subject |
This means that the available stack space may limit the size of a subject |
| 145 |
string that can be processed by certain patterns. |
string that can be processed by certain patterns. For a discussion of stack |
| 146 |
|
issues, see the |
| 147 |
|
<a href="pcrestack.html"><b>pcrestack</b></a> |
| 148 |
|
documentation. |
| 149 |
<a name="utf8support"></a></P> |
<a name="utf8support"></a></P> |
| 150 |
<br><a name="SEC4" href="#TOC1">UTF-8 AND UNICODE PROPERTY SUPPORT</a><br> |
<br><a name="SEC4" href="#TOC1">UTF-8 AND UNICODE PROPERTY SUPPORT</a><br> |
| 151 |
<P> |
<P> |
| 165 |
<P> |
<P> |
| 166 |
If you compile PCRE with UTF-8 support, but do not use it at run time, the |
If you compile PCRE with UTF-8 support, but do not use it at run time, the |
| 167 |
library will be a bit bigger, but the additional run time overhead is limited |
library will be a bit bigger, but the additional run time overhead is limited |
| 168 |
to testing the PCRE_UTF8 flag in several places, so should not be very large. |
to testing the PCRE_UTF8 flag occasionally, so should not be very big. |
| 169 |
</P> |
</P> |
| 170 |
<P> |
<P> |
| 171 |
If PCRE is built with Unicode character property support (which implies UTF-8 |
If PCRE is built with Unicode character property support (which implies UTF-8 |
| 179 |
\p{L} matches a letter. Its Perl synonym, \p{Letter}, is not supported. |
\p{L} matches a letter. Its Perl synonym, \p{Letter}, is not supported. |
| 180 |
Furthermore, in Perl, many properties may optionally be prefixed by "Is", for |
Furthermore, in Perl, many properties may optionally be prefixed by "Is", for |
| 181 |
compatibility with Perl 5.6. PCRE does not support this. |
compatibility with Perl 5.6. PCRE does not support this. |
| 182 |
</P> |
<a name="utf8strings"></a></P> |
| 183 |
<P> |
<br><b> |
| 184 |
The following comments apply when PCRE is running in UTF-8 mode: |
Validity of UTF-8 strings |
| 185 |
</P> |
</b><br> |
| 186 |
|
<P> |
| 187 |
|
When you set the PCRE_UTF8 flag, the strings passed as patterns and subjects |
| 188 |
|
are (by default) checked for validity on entry to the relevant functions. From |
| 189 |
|
release 7.3 of PCRE, the check is according the rules of RFC 3629, which are |
| 190 |
|
themselves derived from the Unicode specification. Earlier releases of PCRE |
| 191 |
|
followed the rules of RFC 2279, which allows the full range of 31-bit values (0 |
| 192 |
|
to 0x7FFFFFFF). The current check allows only values in the range U+0 to |
| 193 |
|
U+10FFFF, excluding U+D800 to U+DFFF. |
| 194 |
|
</P> |
| 195 |
|
<P> |
| 196 |
|
The excluded code points are the "Low Surrogate Area" of Unicode, of which the |
| 197 |
|
Unicode Standard says this: "The Low Surrogate Area does not contain any |
| 198 |
|
character assignments, consequently no character code charts or namelists are |
| 199 |
|
provided for this area. Surrogates are reserved for use with UTF-16 and then |
| 200 |
|
must be used in pairs." The code points that are encoded by UTF-16 pairs are |
| 201 |
|
available as independent code points in the UTF-8 encoding. (In other words, |
| 202 |
|
the whole surrogate thing is a fudge for UTF-16 which unfortunately messes up |
| 203 |
|
UTF-8.) |
| 204 |
|
</P> |
| 205 |
|
<P> |
| 206 |
|
If an invalid UTF-8 string is passed to PCRE, an error return |
| 207 |
|
(PCRE_ERROR_BADUTF8) is given. In some situations, you may already know that |
| 208 |
|
your strings are valid, and therefore want to skip these checks in order to |
| 209 |
|
improve performance. If you set the PCRE_NO_UTF8_CHECK flag at compile time or |
| 210 |
|
at run time, PCRE assumes that the pattern or subject it is given |
| 211 |
|
(respectively) contains only valid UTF-8 codes. In this case, it does not |
| 212 |
|
diagnose an invalid UTF-8 string. |
| 213 |
|
</P> |
| 214 |
|
<P> |
| 215 |
|
If you pass an invalid UTF-8 string when PCRE_NO_UTF8_CHECK is set, what |
| 216 |
|
happens depends on why the string is invalid. If the string conforms to the |
| 217 |
|
"old" definition of UTF-8 (RFC 2279), it is processed as a string of characters |
| 218 |
|
in the range 0 to 0x7FFFFFFF. In other words, apart from the initial validity |
| 219 |
|
test, PCRE (when in UTF-8 mode) handles strings according to the more liberal |
| 220 |
|
rules of RFC 2279. However, if the string does not even conform to RFC 2279, |
| 221 |
|
the result is undefined. Your program may crash. |
| 222 |
|
</P> |
| 223 |
|
<P> |
| 224 |
|
If you want to process strings of values in the full range 0 to 0x7FFFFFFF, |
| 225 |
|
encoded in a UTF-8-like manner as per the old RFC, you can set |
| 226 |
|
PCRE_NO_UTF8_CHECK to bypass the more restrictive test. However, in this |
| 227 |
|
situation, you will have to apply your own validity check. |
| 228 |
|
</P> |
| 229 |
|
<br><b> |
| 230 |
|
General comments about UTF-8 mode |
| 231 |
|
</b><br> |
| 232 |
<P> |
<P> |
| 233 |
1. When you set the PCRE_UTF8 flag, the strings passed as patterns and subjects |
1. An unbraced hexadecimal escape sequence (such as \xb3) matches a two-byte |
| 234 |
are checked for validity on entry to the relevant functions. If an invalid |
UTF-8 character if the value is greater than 127. |
|
UTF-8 string is passed, an error return is given. In some situations, you may |
|
|
already know that your strings are valid, and therefore want to skip these |
|
|
checks in order to improve performance. If you set the PCRE_NO_UTF8_CHECK flag |
|
|
at compile time or at run time, PCRE assumes that the pattern or subject it |
|
|
is given (respectively) contains only valid UTF-8 codes. In this case, it does |
|
|
not diagnose an invalid UTF-8 string. If you pass an invalid UTF-8 string to |
|
|
PCRE when PCRE_NO_UTF8_CHECK is set, the results are undefined. Your program |
|
|
may crash. |
|
| 235 |
</P> |
</P> |
| 236 |
<P> |
<P> |
| 237 |
2. An unbraced hexadecimal escape sequence (such as \xb3) matches a two-byte |
2. Octal numbers up to \777 are recognized, and match two-byte UTF-8 |
| 238 |
UTF-8 character if the value is greater than 127. |
characters for values greater than \177. |
| 239 |
</P> |
</P> |
| 240 |
<P> |
<P> |
| 241 |
3. Repeat quantifiers apply to complete UTF-8 characters, not to individual |
3. Repeat quantifiers apply to complete UTF-8 characters, not to individual |
| 263 |
low-valued characters. |
low-valued characters. |
| 264 |
</P> |
</P> |
| 265 |
<P> |
<P> |
| 266 |
8. Case-insensitive matching applies only to characters whose values are less |
8. However, the Perl 5.10 horizontal and vertical whitespace matching escapes |
| 267 |
|
(\h, \H, \v, and \V) do match all the appropriate Unicode characters. |
| 268 |
|
</P> |
| 269 |
|
<P> |
| 270 |
|
9. Case-insensitive matching applies only to characters whose values are less |
| 271 |
than 128, unless PCRE is built with Unicode property support. Even when Unicode |
than 128, unless PCRE is built with Unicode property support. Even when Unicode |
| 272 |
property support is available, PCRE still uses its own character tables when |
property support is available, PCRE still uses its own character tables when |
| 273 |
checking the case of low-valued characters, so as not to degrade performance. |
checking the case of low-valued characters, so as not to degrade performance. |
| 281 |
<P> |
<P> |
| 282 |
Philip Hazel |
Philip Hazel |
| 283 |
<br> |
<br> |
| 284 |
University Computing Service, |
University Computing Service |
| 285 |
|
<br> |
| 286 |
|
Cambridge CB2 3QH, England. |
| 287 |
<br> |
<br> |
|
Cambridge CB2 3QG, England. |
|
| 288 |
</P> |
</P> |
| 289 |
<P> |
<P> |
| 290 |
Putting an actual email address here seems to have been a spam magnet, so I've |
Putting an actual email address here seems to have been a spam magnet, so I've |
| 291 |
taken it away. If you want to email me, use my initial and surname, separated |
taken it away. If you want to email me, use my two initials, followed by the |
| 292 |
by a dot, at the domain ucs.cam.ac.uk. |
two digits 10, at the domain cam.ac.uk. |
| 293 |
Last updated: 24 January 2006 |
</P> |
| 294 |
|
<br><a name="SEC6" href="#TOC1">REVISION</a><br> |
| 295 |
|
<P> |
| 296 |
|
Last updated: 09 August 2007 |
| 297 |
|
<br> |
| 298 |
|
Copyright © 1997-2007 University of Cambridge. |
| 299 |
<br> |
<br> |
|
Copyright © 1997-2006 University of Cambridge. |
|
| 300 |
<p> |
<p> |
| 301 |
Return to the <a href="index.html">PCRE index page</a>. |
Return to the <a href="index.html">PCRE index page</a>. |
| 302 |
</p> |
</p> |