1PCRE2(3)                   Library Functions Manual                   PCRE2(3)
2
3
4

NAME

6       PCRE2 - Perl-compatible regular expressions (revised API)
7

INTRODUCTION

9
10       PCRE2 is the name used for a revised API for the PCRE library, which is
11       a set of functions, written in C,  that  implement  regular  expression
12       pattern matching using the same syntax and semantics as Perl, with just
13       a few differences. After nearly two decades,  the  limitations  of  the
14       original  API  were  making development increasingly difficult. The new
15       API is more extensible, and it was simplified by abolishing  the  sepa‐
16       rate  "study" optimizing function; in PCRE2, patterns are automatically
17       optimized where possible. Since forking from PCRE1, the code  has  been
18       extensively  refactored and new features introduced. The old library is
19       now obsolete and is no longer maintained.
20
21       As well as Perl-style regular expression patterns, some  features  that
22       appeared  in  Python and the original PCRE before they appeared in Perl
23       are available using the Python syntax. There is also some  support  for
24       one  or  two .NET and Oniguruma syntax items, and there are options for
25       requesting some minor changes that give better  ECMAScript  (aka  Java‐
26       Script) compatibility.
27
28       The  source code for PCRE2 can be compiled to support strings of 8-bit,
29       16-bit, or 32-bit code units, which means that up to three separate li‐
30       braries may be installed, one for each code unit size. The size of code
31       unit is not related to the bit size of the underlying  hardware.  In  a
32       64-bit  environment that also supports 32-bit applications, versions of
33       PCRE2 that are compiled in both 64-bit and 32-bit modes may be needed.
34
35       The original work to extend PCRE to 16-bit and 32-bit  code  units  was
36       done by Zoltan Herczeg and Christian Persch, respectively. In all three
37       cases, strings can be interpreted either  as  one  character  per  code
38       unit, or as UTF-encoded Unicode, with support for Unicode general cate‐
39       gory properties. Unicode support is optional at build time (but is  the
40       default). However, processing strings as UTF code units must be enabled
41       explicitly at run time. The version of Unicode in use can be discovered
42       by running
43
44         pcre2test -C
45
46       The  three  libraries  contain  identical sets of functions, with names
47       ending in _8,  _16,  or  _32,  respectively  (for  example,  pcre2_com‐
48       pile_8()).  However,  by defining PCRE2_CODE_UNIT_WIDTH to be 8, 16, or
49       32, a program that uses just one code unit width can be  written  using
50       generic names such as pcre2_compile(), and the documentation is written
51       assuming that this is the case.
52
53       In addition to the Perl-compatible matching function, PCRE2 contains an
54       alternative  function that matches the same compiled patterns in a dif‐
55       ferent way. In certain circumstances, the alternative function has some
56       advantages.   For  a discussion of the two matching algorithms, see the
57       pcre2matching page.
58
59       Details of exactly which Perl regular expression features are  and  are
60       not  supported  by  PCRE2  are  given  in  separate  documents. See the
61       pcre2pattern and pcre2compat pages. There is a syntax  summary  in  the
62       pcre2syntax page.
63
64       Some  features  of PCRE2 can be included, excluded, or changed when the
65       library is built. The pcre2_config() function makes it possible  for  a
66       client  to  discover  which  features are available. The features them‐
67       selves are described in the pcre2build page. Documentation about build‐
68       ing  PCRE2 for various operating systems can be found in the README and
69       NON-AUTOTOOLS_BUILD files in the source distribution.
70
71       The libraries contains a number of undocumented internal functions  and
72       data  tables  that  are  used by more than one of the exported external
73       functions, but which are not intended  for  use  by  external  callers.
74       Their  names  all begin with "_pcre2", which hopefully will not provoke
75       any name clashes. In some environments, it is possible to control which
76       external  symbols  are  exported when a shared library is built, and in
77       these cases the undocumented symbols are not exported.
78

SECURITY CONSIDERATIONS

80
81       If you are using PCRE2 in a non-UTF application that permits  users  to
82       supply  arbitrary  patterns  for  compilation, you should be aware of a
83       feature that allows users to turn on UTF support from within a pattern.
84       For  example, an 8-bit pattern that begins with "(*UTF)" turns on UTF-8
85       mode, which interprets patterns and subjects as strings of  UTF-8  code
86       units instead of individual 8-bit characters. This causes both the pat‐
87       tern and any data against which it is matched to be checked  for  UTF-8
88       validity.  If the data string is very long, such a check might use suf‐
89       ficiently many resources as to cause your application to  lose  perfor‐
90       mance.
91
92       One  way  of guarding against this possibility is to use the pcre2_pat‐
93       tern_info() function  to  check  the  compiled  pattern's  options  for
94       PCRE2_UTF.  Alternatively,  you can set the PCRE2_NEVER_UTF option when
95       calling pcre2_compile(). This causes a compile time error if  the  pat‐
96       tern contains a UTF-setting sequence.
97
98       The  use  of Unicode properties for character types such as \d can also
99       be enabled from within the pattern, by specifying "(*UCP)".  This  fea‐
100       ture can be disallowed by setting the PCRE2_NEVER_UCP option.
101
102       If  your  application  is one that supports UTF, be aware that validity
103       checking can take time. If the same data string is to be  matched  many
104       times,  you  can  use  the PCRE2_NO_UTF_CHECK option for the second and
105       subsequent matches to avoid running redundant checks.
106
107       The use of the \C escape sequence in a UTF-8 or UTF-16 pattern can lead
108       to  problems,  because  it  may leave the current matching point in the
109       middle of a multi-code-unit character. The PCRE2_NEVER_BACKSLASH_C  op‐
110       tion can be used by an application to lock out the use of \C, causing a
111       compile-time error if it is encountered. It is also possible  to  build
112       PCRE2 with the use of \C permanently disabled.
113
114       Another  way  that  performance can be hit is by running a pattern that
115       has a very large search tree against a string that  will  never  match.
116       Nested  unlimited repeats in a pattern are a common example. PCRE2 pro‐
117       vides some protection against  this:  see  the  pcre2_set_match_limit()
118       function  in  the  pcre2api  page.  There  is a similar function called
119       pcre2_set_depth_limit() that can be used to restrict the amount of mem‐
120       ory that is used.
121

USER DOCUMENTATION

123
124       The  user  documentation for PCRE2 comprises a number of different sec‐
125       tions. In the "man" format, each of these is a separate "man page".  In
126       the  HTML  format, each is a separate page, linked from the index page.
127       In the plain  text  format,  the  descriptions  of  the  pcre2grep  and
128       pcre2test programs are in files called pcre2grep.txt and pcre2test.txt,
129       respectively. The remaining sections, except for the pcre2demo  section
130       (which  is a program listing), and the short pages for individual func‐
131       tions, are concatenated in pcre2.txt, for ease of searching.  The  sec‐
132       tions are as follows:
133
134         pcre2              this document
135         pcre2-config       show PCRE2 installation configuration information
136         pcre2api           details of PCRE2's native C API
137         pcre2build         building PCRE2
138         pcre2callout       details of the pattern callout feature
139         pcre2compat        discussion of Perl compatibility
140         pcre2convert       details of pattern conversion functions
141         pcre2demo          a demonstration C program that uses PCRE2
142         pcre2grep          description of the pcre2grep command (8-bit only)
143         pcre2jit           discussion of just-in-time optimization support
144         pcre2limits        details of size and other limits
145         pcre2matching      discussion of the two matching algorithms
146         pcre2partial       details of the partial matching facility
147         pcre2pattern       syntax and semantics of supported regular
148                              expression patterns
149         pcre2perform       discussion of performance issues
150         pcre2posix         the POSIX-compatible C API for the 8-bit library
151         pcre2sample        discussion of the pcre2demo program
152         pcre2serialize     details of pattern serialization
153         pcre2syntax        quick syntax reference
154         pcre2test          description of the pcre2test command
155         pcre2unicode       discussion of Unicode and UTF support
156
157       In  the  "man"  and HTML formats, there is also a short page for each C
158       library function, listing its arguments and results.
159

AUTHOR

161
162       Philip Hazel
163       Retired from University Computing Service
164       Cambridge, England.
165
166       Putting an actual email address here is a spam magnet. If you  want  to
167       email me, use my two names separated by a dot at gmail.com.
168

REVISION

170
171       Last updated: 27 August 2021
172       Copyright (c) 1997-2021 University of Cambridge.
173
174
175
176PCRE2 10.38                     27 August 2021                        PCRE2(3)
Impressum