| 1 |
nigel |
63 |
<html> |
| 2 |
|
|
<head> |
| 3 |
|
|
<title>pcre specification</title> |
| 4 |
|
|
</head> |
| 5 |
|
|
<body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB"> |
| 6 |
nigel |
75 |
<h1>pcre man page</h1> |
| 7 |
|
|
<p> |
| 8 |
|
|
Return to the <a href="index.html">PCRE index page</a>. |
| 9 |
|
|
</p> |
| 10 |
ph10 |
111 |
<p> |
| 11 |
nigel |
75 |
This page is part of the PCRE HTML documentation. It was generated automatically |
| 12 |
|
|
from the original man page. If there is any nonsense in it, please consult the |
| 13 |
|
|
man page, in case the conversion went wrong. |
| 14 |
ph10 |
111 |
<br> |
| 15 |
nigel |
63 |
<ul> |
| 16 |
nigel |
75 |
<li><a name="TOC1" href="#SEC1">INTRODUCTION</a> |
| 17 |
ph10 |
1194 |
<li><a name="TOC2" href="#SEC2">SECURITY CONSIDERATIONS</a> |
| 18 |
|
|
<li><a name="TOC3" href="#SEC3">USER DOCUMENTATION</a> |
| 19 |
|
|
<li><a name="TOC4" href="#SEC4">AUTHOR</a> |
| 20 |
|
|
<li><a name="TOC5" href="#SEC5">REVISION</a> |
| 21 |
nigel |
63 |
</ul> |
| 22 |
nigel |
75 |
<br><a name="SEC1" href="#TOC1">INTRODUCTION</a><br> |
| 23 |
nigel |
63 |
<P> |
| 24 |
|
|
The PCRE library is a set of functions that implement regular expression |
| 25 |
|
|
pattern matching using the same syntax and semantics as Perl, with just a few |
| 26 |
ph10 |
461 |
differences. Some features that appeared in Python and PCRE before they |
| 27 |
|
|
appeared in Perl are also available using the Python syntax, there is some |
| 28 |
|
|
support for one or two .NET and Oniguruma syntax items, and there is an option |
| 29 |
|
|
for requesting some minor changes that give better JavaScript compatibility. |
| 30 |
nigel |
63 |
</P> |
| 31 |
|
|
<P> |
| 32 |
ph10 |
903 |
Starting with release 8.30, it is possible to compile two separate PCRE |
| 33 |
ph10 |
869 |
libraries: the original, which supports 8-bit character strings (including |
| 34 |
|
|
UTF-8 strings), and a second library that supports 16-bit character strings |
| 35 |
|
|
(including UTF-16 strings). The build process allows either one or both to be |
| 36 |
ph10 |
903 |
built. The majority of the work to make this possible was done by Zoltan |
| 37 |
ph10 |
869 |
Herczeg. |
| 38 |
|
|
</P> |
| 39 |
|
|
<P> |
| 40 |
ph10 |
1194 |
Starting with release 8.32 it is possible to compile a third separate PCRE |
| 41 |
ph10 |
1332 |
library that supports 32-bit character strings (including UTF-32 strings). The |
| 42 |
|
|
build process allows any combination of the 8-, 16- and 32-bit libraries. The |
| 43 |
|
|
work to make this possible was done by Christian Persch. |
| 44 |
ph10 |
1194 |
</P> |
| 45 |
|
|
<P> |
| 46 |
|
|
The three libraries contain identical sets of functions, except that the names |
| 47 |
|
|
in the 16-bit library start with <b>pcre16_</b> instead of <b>pcre_</b>, and the |
| 48 |
|
|
names in the 32-bit library start with <b>pcre32_</b> instead of <b>pcre_</b>. To |
| 49 |
|
|
avoid over-complication and reduce the documentation maintenance load, most of |
| 50 |
|
|
the documentation describes the 8-bit library, with the differences for the |
| 51 |
|
|
16-bit and 32-bit libraries described separately in the |
| 52 |
ph10 |
869 |
<a href="pcre16.html"><b>pcre16</b></a> |
| 53 |
ph10 |
1194 |
and |
| 54 |
|
|
<a href="pcre32.html"><b>pcre32</b></a> |
| 55 |
|
|
pages. References to functions or structures of the form <i>pcre[16|32]_xxx</i> |
| 56 |
|
|
should be read as meaning "<i>pcre_xxx</i> when using the 8-bit library, |
| 57 |
|
|
<i>pcre16_xxx</i> when using the 16-bit library, or <i>pcre32_xxx</i> when using |
| 58 |
|
|
the 32-bit library". |
| 59 |
ph10 |
869 |
</P> |
| 60 |
|
|
<P> |
| 61 |
ph10 |
572 |
The current implementation of PCRE corresponds approximately with Perl 5.12, |
| 62 |
ph10 |
1194 |
including support for UTF-8/16/32 encoded strings and Unicode general category |
| 63 |
|
|
properties. However, UTF-8/16/32 and Unicode support has to be explicitly |
| 64 |
|
|
enabled; it is not the default. The Unicode tables correspond to Unicode |
| 65 |
|
|
release 6.2.0. |
| 66 |
nigel |
93 |
</P> |
| 67 |
|
|
<P> |
| 68 |
|
|
In addition to the Perl-compatible matching function, PCRE contains an |
| 69 |
ph10 |
461 |
alternative function that matches the same compiled patterns in a different |
| 70 |
|
|
way. In certain circumstances, the alternative function has some advantages. |
| 71 |
|
|
For a discussion of the two matching algorithms, see the |
| 72 |
nigel |
77 |
<a href="pcrematching.html"><b>pcrematching</b></a> |
| 73 |
|
|
page. |
| 74 |
|
|
</P> |
| 75 |
|
|
<P> |
| 76 |
nigel |
75 |
PCRE is written in C and released as a C library. A number of people have |
| 77 |
nigel |
77 |
written wrappers and interfaces of various kinds. In particular, Google Inc. |
| 78 |
ph10 |
869 |
have provided a comprehensive C++ wrapper for the 8-bit library. This is now |
| 79 |
|
|
included as part of the PCRE distribution. The |
| 80 |
nigel |
77 |
<a href="pcrecpp.html"><b>pcrecpp</b></a> |
| 81 |
|
|
page has details of this interface. Other people's contributions can be found |
| 82 |
|
|
in the <i>Contrib</i> directory at the primary FTP site, which is: |
| 83 |
nigel |
75 |
<a href="ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre">ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre</a> |
| 84 |
nigel |
63 |
</P> |
| 85 |
|
|
<P> |
| 86 |
|
|
Details of exactly which Perl regular expression features are and are not |
| 87 |
|
|
supported by PCRE are given in separate documents. See the |
| 88 |
|
|
<a href="pcrepattern.html"><b>pcrepattern</b></a> |
| 89 |
|
|
and |
| 90 |
|
|
<a href="pcrecompat.html"><b>pcrecompat</b></a> |
| 91 |
ph10 |
208 |
pages. There is a syntax summary in the |
| 92 |
|
|
<a href="pcresyntax.html"><b>pcresyntax</b></a> |
| 93 |
|
|
page. |
| 94 |
nigel |
63 |
</P> |
| 95 |
|
|
<P> |
| 96 |
|
|
Some features of PCRE can be included, excluded, or changed when the library is |
| 97 |
|
|
built. The |
| 98 |
|
|
<a href="pcre_config.html"><b>pcre_config()</b></a> |
| 99 |
|
|
function makes it possible for a client to discover which features are |
| 100 |
nigel |
75 |
available. The features themselves are described in the |
| 101 |
|
|
<a href="pcrebuild.html"><b>pcrebuild</b></a> |
| 102 |
|
|
page. Documentation about building PCRE for various operating systems can be |
| 103 |
ph10 |
1332 |
found in the |
| 104 |
|
|
<a href="README.txt"><b>README</b></a> |
| 105 |
|
|
and |
| 106 |
|
|
<a href="NON-AUTOTOOLS-BUILD.txt"><b>NON-AUTOTOOLS_BUILD</b></a> |
| 107 |
|
|
files in the source distribution. |
| 108 |
nigel |
63 |
</P> |
| 109 |
nigel |
77 |
<P> |
| 110 |
ph10 |
869 |
The libraries contains a number of undocumented internal functions and data |
| 111 |
nigel |
77 |
tables that are used by more than one of the exported external functions, but |
| 112 |
|
|
which are not intended for use by external callers. Their names all begin with |
| 113 |
ph10 |
1194 |
"_pcre_" or "_pcre16_" or "_pcre32_", which hopefully will not provoke any name |
| 114 |
|
|
clashes. In some environments, it is possible to control which external symbols |
| 115 |
|
|
are exported when a shared library is built, and in these cases the |
| 116 |
|
|
undocumented symbols are not exported. |
| 117 |
nigel |
77 |
</P> |
| 118 |
ph10 |
1194 |
<br><a name="SEC2" href="#TOC1">SECURITY CONSIDERATIONS</a><br> |
| 119 |
nigel |
63 |
<P> |
| 120 |
ph10 |
1194 |
If you are using PCRE in a non-UTF application that permits users to supply |
| 121 |
|
|
arbitrary patterns for compilation, you should be aware of a feature that |
| 122 |
|
|
allows users to turn on UTF support from within a pattern, provided that PCRE |
| 123 |
|
|
was built with UTF support. For example, an 8-bit pattern that begins with |
| 124 |
ph10 |
1221 |
"(*UTF8)" or "(*UTF)" turns on UTF-8 mode, which interprets patterns and |
| 125 |
|
|
subjects as strings of UTF-8 characters instead of individual 8-bit characters. |
| 126 |
|
|
This causes both the pattern and any data against which it is matched to be |
| 127 |
|
|
checked for UTF-8 validity. If the data string is very long, such a check might |
| 128 |
|
|
use sufficiently many resources as to cause your application to lose |
| 129 |
|
|
performance. |
| 130 |
ph10 |
1194 |
</P> |
| 131 |
|
|
<P> |
| 132 |
ph10 |
1320 |
One way of guarding against this possibility is to use the |
| 133 |
ph10 |
1194 |
<b>pcre_fullinfo()</b> function to check the compiled pattern's options for UTF. |
| 134 |
ph10 |
1320 |
Alternatively, from release 8.33, you can set the PCRE_NEVER_UTF option at |
| 135 |
|
|
compile time. This causes an compile time error if a pattern contains a |
| 136 |
|
|
UTF-setting sequence. |
| 137 |
ph10 |
1194 |
</P> |
| 138 |
|
|
<P> |
| 139 |
|
|
If your application is one that supports UTF, be aware that validity checking |
| 140 |
|
|
can take time. If the same data string is to be matched many times, you can use |
| 141 |
ph10 |
1221 |
the PCRE_NO_UTF[8|16|32]_CHECK option for the second and subsequent matches to |
| 142 |
ph10 |
1194 |
save redundant checks. |
| 143 |
|
|
</P> |
| 144 |
|
|
<P> |
| 145 |
ph10 |
1221 |
Another way that performance can be hit is by running a pattern that has a very |
| 146 |
|
|
large search tree against a string that will never match. Nested unlimited |
| 147 |
|
|
repeats in a pattern are a common example. PCRE provides some protection |
| 148 |
ph10 |
1194 |
against this: see the PCRE_EXTRA_MATCH_LIMIT feature in the |
| 149 |
|
|
<a href="pcreapi.html"><b>pcreapi</b></a> |
| 150 |
|
|
page. |
| 151 |
|
|
</P> |
| 152 |
|
|
<br><a name="SEC3" href="#TOC1">USER DOCUMENTATION</a><br> |
| 153 |
|
|
<P> |
| 154 |
nigel |
75 |
The user documentation for PCRE comprises a number of different sections. In |
| 155 |
|
|
the "man" format, each of these is a separate "man page". In the HTML format, |
| 156 |
|
|
each is a separate page, linked from the index page. In the plain text format, |
| 157 |
ph10 |
429 |
all the sections, except the <b>pcredemo</b> section, are concatenated, for ease |
| 158 |
|
|
of searching. The sections are as follows: |
| 159 |
nigel |
63 |
<pre> |
| 160 |
|
|
pcre this document |
| 161 |
ph10 |
1332 |
pcre-config show PCRE installation configuration information |
| 162 |
ph10 |
903 |
pcre16 details of the 16-bit library |
| 163 |
ph10 |
1194 |
pcre32 details of the 32-bit library |
| 164 |
nigel |
77 |
pcreapi details of PCRE's native C API |
| 165 |
ph10 |
1332 |
pcrebuild building PCRE |
| 166 |
nigel |
63 |
pcrecallout details of the callout feature |
| 167 |
|
|
pcrecompat discussion of Perl compatibility |
| 168 |
ph10 |
869 |
pcrecpp details of the C++ wrapper for the 8-bit library |
| 169 |
ph10 |
429 |
pcredemo a demonstration C program that uses PCRE |
| 170 |
ph10 |
869 |
pcregrep description of the <b>pcregrep</b> command (8-bit only) |
| 171 |
ph10 |
691 |
pcrejit discussion of the just-in-time optimization support |
| 172 |
|
|
pcrelimits details of size and other limits |
| 173 |
nigel |
77 |
pcrematching discussion of the two matching algorithms |
| 174 |
nigel |
75 |
pcrepartial details of the partial matching facility |
| 175 |
|
|
pcrepattern syntax and semantics of supported regular expressions |
| 176 |
nigel |
63 |
pcreperform discussion of performance issues |
| 177 |
ph10 |
869 |
pcreposix the POSIX-compatible C API for the 8-bit library |
| 178 |
nigel |
75 |
pcreprecompile details of saving and re-using precompiled patterns |
| 179 |
ph10 |
429 |
pcresample discussion of the pcredemo program |
| 180 |
nigel |
91 |
pcrestack discussion of stack usage |
| 181 |
ph10 |
461 |
pcresyntax quick syntax reference |
| 182 |
nigel |
75 |
pcretest description of the <b>pcretest</b> testing command |
| 183 |
ph10 |
1194 |
pcreunicode discussion of Unicode and UTF-8/16/32 support |
| 184 |
nigel |
75 |
</pre> |
| 185 |
nigel |
63 |
In addition, in the "man" and HTML formats, there is a short page for each |
| 186 |
ph10 |
1194 |
C library function, listing its arguments and results. |
| 187 |
nigel |
63 |
</P> |
| 188 |
ph10 |
1194 |
<br><a name="SEC4" href="#TOC1">AUTHOR</a><br> |
| 189 |
nigel |
63 |
<P> |
| 190 |
nigel |
77 |
Philip Hazel |
| 191 |
nigel |
63 |
<br> |
| 192 |
ph10 |
99 |
University Computing Service |
| 193 |
nigel |
63 |
<br> |
| 194 |
nigel |
93 |
Cambridge CB2 3QH, England. |
| 195 |
ph10 |
99 |
<br> |
| 196 |
nigel |
77 |
</P> |
| 197 |
|
|
<P> |
| 198 |
|
|
Putting an actual email address here seems to have been a spam magnet, so I've |
| 199 |
ph10 |
153 |
taken it away. If you want to email me, use my two initials, followed by the |
| 200 |
|
|
two digits 10, at the domain cam.ac.uk. |
| 201 |
ph10 |
99 |
</P> |
| 202 |
ph10 |
1194 |
<br><a name="SEC5" href="#TOC1">REVISION</a><br> |
| 203 |
ph10 |
99 |
<P> |
| 204 |
ph10 |
1332 |
Last updated: 13 May 2013 |
| 205 |
nigel |
63 |
<br> |
| 206 |
ph10 |
1320 |
Copyright © 1997-2013 University of Cambridge. |
| 207 |
ph10 |
99 |
<br> |
| 208 |
nigel |
75 |
<p> |
| 209 |
|
|
Return to the <a href="index.html">PCRE index page</a>. |
| 210 |
|
|
</p> |