new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / external / pcre2-10.32 / doc / pcre2.3
1 .TH PCRE2 3 "11 July 2018" "PCRE2 10.32"
2 .SH NAME
3 PCRE2 - Perl-compatible regular expressions (revised API)
4 .SH INTRODUCTION
5 .rs
6 .sp
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.
15 .P
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.
21 .P
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
31 .sp
32   pcre2test -C
33 .P
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
39 the case.
40 .P
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
45 .\" HREF
46 \fBpcre2matching\fP
47 .\"
48 page.
49 .P
50 Details of exactly which Perl regular expression features are and are not
51 supported by PCRE2 are given in separate documents. See the
52 .\" HREF
53 \fBpcre2pattern\fP
54 .\"
55 and
56 .\" HREF
57 \fBpcre2compat\fP
58 .\"
59 pages. There is a syntax summary in the
60 .\" HREF
61 \fBpcre2syntax\fP
62 .\"
63 page.
64 .P
65 Some features of PCRE2 can be included, excluded, or changed when the library
66 is built. The
67 .\" HREF
68 \fBpcre2_config()\fP
69 .\"
70 function makes it possible for a client to discover which features are
71 available. The features themselves are described in the
72 .\" HREF
73 \fBpcre2build\fP
74 .\"
75 page. Documentation about building PCRE2 for various operating systems can be
76 found in the
77 .\" HTML <a href="README.txt">
78 .\" </a>
79 \fBREADME\fP
80 .\"
81 and
82 .\" HTML <a href="NON-AUTOTOOLS-BUILD.txt">
83 .\" </a>
84 \fBNON-AUTOTOOLS_BUILD\fP
85 .\"
86 files in the source distribution.
87 .P
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
94 not exported.
95 .
96 .
97 .SH "SECURITY CONSIDERATIONS"
98 .rs
99 .sp
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
108 lose performance.
109 .P
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.
115 .P
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.
119 .P
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.
124 .P
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
130 disabled.
131 .P
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
136 .\" HREF
137 \fBpcre2api\fP
138 .\"
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.
141 .
142 .
143 .SH "USER DOCUMENTATION"
144 .rs
145 .sp
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:
154 .sp
155   pcre2              this document
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
168 .\" JOIN
169   pcre2pattern       syntax and semantics of supported regular
170                        expression patterns
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
178 .sp
179 In the "man" and HTML formats, there is also a short page for each C library
180 function, listing its arguments and results.
181 .
182 .
183 .SH AUTHOR
184 .rs
185 .sp
186 .nf
187 Philip Hazel
188 University Computing Service
189 Cambridge, England.
190 .fi
191 .P
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.
194 .
195 .
196 .SH REVISION
197 .rs
198 .sp
199 .nf
200 Last updated: 11 July 2018
201 Copyright (c) 1997-2018 University of Cambridge.
202 .fi