1 .TH PCRE2 3 "11 July 2018" "PCRE2 10.32"
3 PCRE2 - Perl-compatible regular expressions (revised API)
7 PCRE2 is the name used for a revised API for the PCRE library, which is a set
8 of functions, written in C, that implement regular expression pattern matching
9 using the same syntax and semantics as Perl, with just a few differences. After
10 nearly two decades, the limitations of the original API were making development
11 increasingly difficult. The new API is more extensible, and it was simplified
12 by abolishing the separate "study" optimizing function; in PCRE2, patterns are
13 automatically optimized where possible. Since forking from PCRE1, the code has
14 been extensively refactored and new features introduced.
16 As well as Perl-style regular expression patterns, some features that appeared
17 in Python and the original PCRE before they appeared in Perl are available
18 using the Python syntax. There is also some support for one or two .NET and
19 Oniguruma syntax items, and there are options for requesting some minor changes
20 that give better ECMAScript (aka JavaScript) compatibility.
22 The source code for PCRE2 can be compiled to support 8-bit, 16-bit, or 32-bit
23 code units, which means that up to three separate libraries may be installed.
24 The original work to extend PCRE to 16-bit and 32-bit code units was done by
25 Zoltan Herczeg and Christian Persch, respectively. In all three cases, strings
26 can be interpreted either as one character per code unit, or as UTF-encoded
27 Unicode, with support for Unicode general category properties. Unicode support
28 is optional at build time (but is the default). However, processing strings as
29 UTF code units must be enabled explicitly at run time. The version of Unicode
30 in use can be discovered by running
34 The three libraries contain identical sets of functions, with names ending in
35 _8, _16, or _32, respectively (for example, \fBpcre2_compile_8()\fP). However,
36 by defining PCRE2_CODE_UNIT_WIDTH to be 8, 16, or 32, a program that uses just
37 one code unit width can be written using generic names such as
38 \fBpcre2_compile()\fP, and the documentation is written assuming that this is
41 In addition to the Perl-compatible matching function, PCRE2 contains an
42 alternative function that matches the same compiled patterns in a different
43 way. In certain circumstances, the alternative function has some advantages.
44 For a discussion of the two matching algorithms, see the
50 Details of exactly which Perl regular expression features are and are not
51 supported by PCRE2 are given in separate documents. See the
59 pages. There is a syntax summary in the
65 Some features of PCRE2 can be included, excluded, or changed when the library
70 function makes it possible for a client to discover which features are
71 available. The features themselves are described in the
75 page. Documentation about building PCRE2 for various operating systems can be
77 .\" HTML <a href="README.txt">
82 .\" HTML <a href="NON-AUTOTOOLS-BUILD.txt">
84 \fBNON-AUTOTOOLS_BUILD\fP
86 files in the source distribution.
88 The libraries contains a number of undocumented internal functions and data
89 tables that are used by more than one of the exported external functions, but
90 which are not intended for use by external callers. Their names all begin with
91 "_pcre2", which hopefully will not provoke any name clashes. In some
92 environments, it is possible to control which external symbols are exported
93 when a shared library is built, and in these cases the undocumented symbols are
97 .SH "SECURITY CONSIDERATIONS"
100 If you are using PCRE2 in a non-UTF application that permits users to supply
101 arbitrary patterns for compilation, you should be aware of a feature that
102 allows users to turn on UTF support from within a pattern. For example, an
103 8-bit pattern that begins with "(*UTF)" turns on UTF-8 mode, which interprets
104 patterns and subjects as strings of UTF-8 code units instead of individual
105 8-bit characters. This causes both the pattern and any data against which it is
106 matched to be checked for UTF-8 validity. If the data string is very long, such
107 a check might use sufficiently many resources as to cause your application to
110 One way of guarding against this possibility is to use the
111 \fBpcre2_pattern_info()\fP function to check the compiled pattern's options for
112 PCRE2_UTF. Alternatively, you can set the PCRE2_NEVER_UTF option when calling
113 \fBpcre2_compile()\fP. This causes a compile time error if the pattern contains
114 a UTF-setting sequence.
116 The use of Unicode properties for character types such as \ed can also be
117 enabled from within the pattern, by specifying "(*UCP)". This feature can be
118 disallowed by setting the PCRE2_NEVER_UCP option.
120 If your application is one that supports UTF, be aware that validity checking
121 can take time. If the same data string is to be matched many times, you can use
122 the PCRE2_NO_UTF_CHECK option for the second and subsequent matches to avoid
123 running redundant checks.
125 The use of the \eC escape sequence in a UTF-8 or UTF-16 pattern can lead to
126 problems, because it may leave the current matching point in the middle of a
127 multi-code-unit character. The PCRE2_NEVER_BACKSLASH_C option can be used by an
128 application to lock out the use of \eC, causing a compile-time error if it is
129 encountered. It is also possible to build PCRE2 with the use of \eC permanently
132 Another way that performance can be hit is by running a pattern that has a very
133 large search tree against a string that will never match. Nested unlimited
134 repeats in a pattern are a common example. PCRE2 provides some protection
135 against this: see the \fBpcre2_set_match_limit()\fP function in the
139 page. There is a similar function called \fBpcre2_set_depth_limit()\fP that can
140 be used to restrict the amount of memory that is used.
143 .SH "USER DOCUMENTATION"
146 The user documentation for PCRE2 comprises a number of different sections. In
147 the "man" format, each of these is a separate "man page". In the HTML format,
148 each is a separate page, linked from the index page. In the plain text format,
149 the descriptions of the \fBpcre2grep\fP and \fBpcre2test\fP programs are in
150 files called \fBpcre2grep.txt\fP and \fBpcre2test.txt\fP, respectively. The
151 remaining sections, except for the \fBpcre2demo\fP section (which is a program
152 listing), and the short pages for individual functions, are concatenated in
153 \fBpcre2.txt\fP, for ease of searching. The sections are as follows:
156 pcre2-config show PCRE2 installation configuration information
157 pcre2api details of PCRE2's native C API
158 pcre2build building PCRE2
159 pcre2callout details of the callout feature
160 pcre2compat discussion of Perl compatibility
161 pcre2convert details of pattern conversion functions
162 pcre2demo a demonstration C program that uses PCRE2
163 pcre2grep description of the \fBpcre2grep\fP command (8-bit only)
164 pcre2jit discussion of just-in-time optimization support
165 pcre2limits details of size and other limits
166 pcre2matching discussion of the two matching algorithms
167 pcre2partial details of the partial matching facility
169 pcre2pattern syntax and semantics of supported regular
171 pcre2perform discussion of performance issues
172 pcre2posix the POSIX-compatible C API for the 8-bit library
173 pcre2sample discussion of the pcre2demo program
174 pcre2serialize details of pattern serialization
175 pcre2syntax quick syntax reference
176 pcre2test description of the \fBpcre2test\fP command
177 pcre2unicode discussion of Unicode and UTF support
179 In the "man" and HTML formats, there is also a short page for each C library
180 function, listing its arguments and results.
188 University Computing Service
192 Putting an actual email address here is a spam magnet. If you want to email me,
193 use my two initials, followed by the two digits 10, at the domain cam.ac.uk.
200 Last updated: 11 July 2018
201 Copyright (c) 1997-2018 University of Cambridge.