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