| 1 |
nigel |
41 |
.TH PCRE 3 |
| 2 |
|
|
.SH NAME |
| 3 |
nigel |
63 |
PCRE - Perl-compatible regular expressions |
| 4 |
nigel |
41 |
.SH DESCRIPTION |
| 5 |
nigel |
63 |
.rs |
| 6 |
|
|
.sp |
| 7 |
nigel |
41 |
The PCRE library is a set of functions that implement regular expression |
| 8 |
nigel |
63 |
pattern matching using the same syntax and semantics as Perl, with just a few |
| 9 |
|
|
differences. The current implementation of PCRE (release 4.x) corresponds |
| 10 |
|
|
approximately with Perl 5.8, including support for UTF-8 encoded strings. |
| 11 |
|
|
However, this support has to be explicitly enabled; it is not the default. |
| 12 |
nigel |
41 |
|
| 13 |
nigel |
63 |
PCRE is written in C and released as a C library. However, a number of people |
| 14 |
|
|
have written wrappers and interfaces of various kinds. A C++ class is included |
| 15 |
|
|
in these contributions, which can be found in the \fIContrib\fR directory at |
| 16 |
|
|
the primary FTP site, which is: |
| 17 |
nigel |
41 |
|
| 18 |
nigel |
63 |
.\" HTML <a href="ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre"> |
| 19 |
|
|
.\" </a> |
| 20 |
|
|
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre |
| 21 |
nigel |
41 |
|
| 22 |
nigel |
63 |
Details of exactly which Perl regular expression features are and are not |
| 23 |
|
|
supported by PCRE are given in separate documents. See the |
| 24 |
|
|
.\" HREF |
| 25 |
|
|
\fBpcrepattern\fR |
| 26 |
|
|
.\" |
| 27 |
|
|
and |
| 28 |
|
|
.\" HREF |
| 29 |
|
|
\fBpcrecompat\fR |
| 30 |
|
|
.\" |
| 31 |
|
|
pages. |
| 32 |
nigel |
49 |
|
| 33 |
nigel |
63 |
Some features of PCRE can be included, excluded, or changed when the library is |
| 34 |
|
|
built. The |
| 35 |
|
|
.\" HREF |
| 36 |
|
|
\fBpcre_config()\fR |
| 37 |
|
|
.\" |
| 38 |
|
|
function makes it possible for a client to discover which features are |
| 39 |
|
|
available. Documentation about building PCRE for various operating systems can |
| 40 |
|
|
be found in the \fBREADME\fR file in the source distribution. |
| 41 |
nigel |
41 |
|
| 42 |
nigel |
63 |
.SH USER DOCUMENTATION |
| 43 |
|
|
.rs |
| 44 |
|
|
.sp |
| 45 |
|
|
The user documentation for PCRE has been split up into a number of different |
| 46 |
|
|
sections. In the "man" format, each of these is a separate "man page". In the |
| 47 |
|
|
HTML format, each is a separate page, linked from the index page. In the plain |
| 48 |
|
|
text format, all the sections are concatenated, for ease of searching. The |
| 49 |
|
|
sections are as follows: |
| 50 |
nigel |
49 |
|
| 51 |
nigel |
63 |
pcre this document |
| 52 |
|
|
pcreapi details of PCRE's native API |
| 53 |
|
|
pcrebuild options for building PCRE |
| 54 |
|
|
pcrecallout details of the callout feature |
| 55 |
|
|
pcrecompat discussion of Perl compatibility |
| 56 |
|
|
pcregrep description of the \fBpcregrep\fR command |
| 57 |
|
|
pcrepattern syntax and semantics of supported |
| 58 |
|
|
regular expressions |
| 59 |
|
|
pcreperform discussion of performance issues |
| 60 |
|
|
pcreposix the POSIX-compatible API |
| 61 |
|
|
pcresample discussion of the sample program |
| 62 |
|
|
pcretest the \fBpcretest\fR testing command |
| 63 |
nigel |
41 |
|
| 64 |
nigel |
63 |
In addition, in the "man" and HTML formats, there is a short page for each |
| 65 |
|
|
library function, listing its arguments and results. |
| 66 |
nigel |
41 |
|
| 67 |
|
|
.SH LIMITATIONS |
| 68 |
nigel |
63 |
.rs |
| 69 |
|
|
.sp |
| 70 |
nigel |
41 |
There are some size limitations in PCRE but it is hoped that they will never in |
| 71 |
|
|
practice be relevant. |
| 72 |
nigel |
63 |
|
| 73 |
|
|
The maximum length of a compiled pattern is 65539 (sic) bytes if PCRE is |
| 74 |
|
|
compiled with the default internal linkage size of 2. If you want to process |
| 75 |
|
|
regular expressions that are truly enormous, you can compile PCRE with an |
| 76 |
|
|
internal linkage size of 3 or 4 (see the \fBREADME\fR file in the source |
| 77 |
|
|
distribution and the |
| 78 |
|
|
.\" HREF |
| 79 |
|
|
\fBpcrebuild\fR |
| 80 |
|
|
.\" |
| 81 |
|
|
documentation for details). If these cases the limit is substantially larger. |
| 82 |
|
|
However, the speed of execution will be slower. |
| 83 |
|
|
|
| 84 |
nigel |
41 |
All values in repeating quantifiers must be less than 65536. |
| 85 |
nigel |
63 |
The maximum number of capturing subpatterns is 65535. |
| 86 |
|
|
|
| 87 |
nigel |
53 |
There is no limit to the number of non-capturing subpatterns, but the maximum |
| 88 |
|
|
depth of nesting of all kinds of parenthesized subpattern, including capturing |
| 89 |
nigel |
41 |
subpatterns, assertions, and other types of subpattern, is 200. |
| 90 |
|
|
|
| 91 |
|
|
The maximum length of a subject string is the largest positive number that an |
| 92 |
|
|
integer variable can hold. However, PCRE uses recursion to handle subpatterns |
| 93 |
|
|
and indefinite repetition. This means that the available stack space may limit |
| 94 |
|
|
the size of a subject string that can be processed by certain patterns. |
| 95 |
|
|
|
| 96 |
nigel |
63 |
.\" HTML <a name="utf8support"></a> |
| 97 |
nigel |
49 |
.SH UTF-8 SUPPORT |
| 98 |
nigel |
63 |
.rs |
| 99 |
|
|
.sp |
| 100 |
|
|
Starting at release 3.3, PCRE has had some support for character strings |
| 101 |
|
|
encoded in the UTF-8 format. For release 4.0 this has been greatly extended to |
| 102 |
|
|
cover most common requirements. |
| 103 |
nigel |
49 |
|
| 104 |
nigel |
63 |
In order process UTF-8 strings, you must build PCRE to include UTF-8 support in |
| 105 |
|
|
the code, and, in addition, you must call |
| 106 |
|
|
.\" HREF |
| 107 |
|
|
\fBpcre_compile()\fR |
| 108 |
|
|
.\" |
| 109 |
|
|
with the PCRE_UTF8 option flag. When you do this, both the pattern and any |
| 110 |
|
|
subject strings that are matched against it are treated as UTF-8 strings |
| 111 |
|
|
instead of just strings of bytes. |
| 112 |
|
|
|
| 113 |
nigel |
49 |
If you compile PCRE with UTF-8 support, but do not use it at run time, the |
| 114 |
|
|
library will be a bit bigger, but the additional run time overhead is limited |
| 115 |
|
|
to testing the PCRE_UTF8 flag in several places, so should not be very large. |
| 116 |
|
|
|
| 117 |
nigel |
63 |
The following comments apply when PCRE is running in UTF-8 mode: |
| 118 |
|
|
|
| 119 |
nigel |
71 |
1. When you set the PCRE_UTF8 flag, the strings passed as patterns and subjects |
| 120 |
|
|
are checked for validity on entry to the relevant functions. If an invalid |
| 121 |
|
|
UTF-8 string is passed, an error return is given. In some situations, you may |
| 122 |
|
|
already know that your strings are valid, and therefore want to skip these |
| 123 |
|
|
checks in order to improve performance. If you set the PCRE_NO_UTF8_CHECK flag |
| 124 |
|
|
at compile time or at run time, PCRE assumes that the pattern or subject it |
| 125 |
|
|
is given (respectively) contains only valid UTF-8 codes. In this case, it does |
| 126 |
|
|
not diagnose an invalid UTF-8 string. If you pass an invalid UTF-8 string to |
| 127 |
|
|
PCRE when PCRE_NO_UTF8_CHECK is set, the results are undefined. Your program |
| 128 |
|
|
may crash. |
| 129 |
nigel |
49 |
|
| 130 |
nigel |
63 |
2. In a pattern, the escape sequence \\x{...}, where the contents of the braces |
| 131 |
nigel |
49 |
is a string of hexadecimal digits, is interpreted as a UTF-8 character whose |
| 132 |
nigel |
63 |
code number is the given hexadecimal number, for example: \\x{1234}. If a |
| 133 |
|
|
non-hexadecimal digit appears between the braces, the item is not recognized. |
| 134 |
|
|
This escape sequence can be used either as a literal, or within a character |
| 135 |
|
|
class. |
| 136 |
nigel |
49 |
|
| 137 |
nigel |
63 |
3. The original hexadecimal escape sequence, \\xhh, matches a two-byte UTF-8 |
| 138 |
|
|
character if the value is greater than 127. |
| 139 |
nigel |
49 |
|
| 140 |
nigel |
63 |
4. Repeat quantifiers apply to complete UTF-8 characters, not to individual |
| 141 |
|
|
bytes, for example: \\x{100}{3}. |
| 142 |
nigel |
49 |
|
| 143 |
nigel |
63 |
5. The dot metacharacter matches one UTF-8 character instead of a single byte. |
| 144 |
nigel |
49 |
|
| 145 |
nigel |
63 |
6. The escape sequence \\C can be used to match a single byte in UTF-8 mode, |
| 146 |
|
|
but its use can lead to some strange effects. |
| 147 |
nigel |
49 |
|
| 148 |
nigel |
63 |
7. The character escapes \\b, \\B, \\d, \\D, \\s, \\S, \\w, and \\W correctly |
| 149 |
|
|
test characters of any code value, but the characters that PCRE recognizes as |
| 150 |
|
|
digits, spaces, or word characters remain the same set as before, all with |
| 151 |
|
|
values less than 256. |
| 152 |
nigel |
49 |
|
| 153 |
nigel |
63 |
8. Case-insensitive matching applies only to characters whose values are less |
| 154 |
|
|
than 256. PCRE does not support the notion of "case" for higher-valued |
| 155 |
|
|
characters. |
| 156 |
nigel |
49 |
|
| 157 |
nigel |
63 |
9. PCRE does not support the use of Unicode tables and properties or the Perl |
| 158 |
|
|
escapes \\p, \\P, and \\X. |
| 159 |
nigel |
49 |
|
| 160 |
nigel |
41 |
.SH AUTHOR |
| 161 |
nigel |
63 |
.rs |
| 162 |
|
|
.sp |
| 163 |
nigel |
41 |
Philip Hazel <ph10@cam.ac.uk> |
| 164 |
|
|
.br |
| 165 |
|
|
University Computing Service, |
| 166 |
|
|
.br |
| 167 |
|
|
Cambridge CB2 3QG, England. |
| 168 |
|
|
.br |
| 169 |
|
|
Phone: +44 1223 334714 |
| 170 |
|
|
|
| 171 |
nigel |
63 |
.in 0 |
| 172 |
nigel |
71 |
Last updated: 20 August 2003 |
| 173 |
nigel |
41 |
.br |
| 174 |
nigel |
63 |
Copyright (c) 1997-2003 University of Cambridge. |