As well as Perl-style regular expression patterns, some features that appeared in Python and the original PCRE before they appeared in Perl are available using the Python syntax. There is also some support for one or two .NET and Oniguruma syntax items, and there are options for requesting some minor changes that give better ECMAScript (aka JavaScript) compatibility.
The source code for PCRE2 can be compiled to support 8-bit, 16-bit, or 32-bit code units, which means that up to three separate libraries may be installed. The original work to extend PCRE to 16-bit and 32-bit code units was done by Zoltan Herczeg and Christian Persch, respectively. In all three cases, strings can be interpreted either as one character per code unit, or as UTF-encoded Unicode, with support for Unicode general category properties. Unicode support is optional at build time (but is the default). However, processing strings as UTF code units must be enabled explicitly at run time. The version of Unicode in use can be discovered by running pcre2test -C
The three libraries contain identical sets of functions, with names ending in _8, _16, or _32, respectively (for example, pcre2_compile_8()). However, by defining PCRE2_CODE_UNIT_WIDTH to be 8, 16, or 32, a program that uses just one code unit width can be written using generic names such as pcre2_compile(), and the documentation is written assuming that this is the case.
In addition to the Perl-compatible matching function, PCRE2 contains an
alternative function that matches the same compiled patterns in a different
way. In certain circumstances, the alternative function has some advantages.
For a discussion of the two matching algorithms, see the
HREF
pcre2matching
page.
Details of exactly which Perl regular expression features are and are not
supported by PCRE2 are given in separate documents. See the
HREF
pcre2pattern
and
HREF
pcre2compat
pages. There is a syntax summary in the
HREF
pcre2syntax
page.
Some features of PCRE2 can be included, excluded, or changed when the library
is built. The
HREF
pcre2_config()
function makes it possible for a client to discover which features are
available. The features themselves are described in the
HREF
pcre2build
page. Documentation about building PCRE2 for various operating systems can be
found in the
HTML <a href="README.txt">
</a>
README
and
HTML <a href="NON-AUTOTOOLS-BUILD.txt">
</a>
NON-AUTOTOOLS_BUILD
files in the source distribution.
The libraries contains a number of undocumented internal functions and data tables that are used by more than one of the exported external functions, but which are not intended for use by external callers. Their names all begin with "_pcre2", which hopefully will not provoke any name clashes. In some environments, it is possible to control which external symbols are exported when a shared library is built, and in these cases the undocumented symbols are not exported. . .
One way of guarding against this possibility is to use the pcre2_pattern_info() function to check the compiled pattern's options for PCRE2_UTF. Alternatively, you can set the PCRE2_NEVER_UTF option when calling pcre2_compile(). This causes a compile time error if the pattern contains a UTF-setting sequence.
The use of Unicode properties for character types such as \ed can also be enabled from within the pattern, by specifying "(*UCP)". This feature can be disallowed by setting the PCRE2_NEVER_UCP option.
If your application is one that supports UTF, be aware that validity checking can take time. If the same data string is to be matched many times, you can use the PCRE2_NO_UTF_CHECK option for the second and subsequent matches to avoid running redundant checks.
The use of the \eC escape sequence in a UTF-8 or UTF-16 pattern can lead to problems, because it may leave the current matching point in the middle of a multi-code-unit character. The PCRE2_NEVER_BACKSLASH_C option can be used by an application to lock out the use of \eC, causing a compile-time error if it is encountered. It is also possible to build PCRE2 with the use of \eC permanently disabled.
Another way that performance can be hit is by running a pattern that has a very
large search tree against a string that will never match. Nested unlimited
repeats in a pattern are a common example. PCRE2 provides some protection
against this: see the pcre2_set_match_limit() function in the
HREF
pcre2api
page. There is a similar function called pcre2_set_depth_limit() that can
be used to restrict the amount of memory that is used.
.
.
pcre2pattern syntax and semantics of supported regular expression patterns pcre2perform discussion of performance issues pcre2posix the POSIX-compatible C API for the 8-bit library pcre2sample discussion of the pcre2demo program pcre2serialize details of pattern serialization pcre2syntax quick syntax reference pcre2test description of the pcre2test command pcre2unicode discussion of Unicode and UTF support In the "man" and HTML formats, there is also a short page for each C library function, listing its arguments and results. . .
Philip Hazel University Computing Service Cambridge, England.
Putting an actual email address here is a spam magnet. If you want to email me, use my two initials, followed by the two digits 10, at the domain cam.ac.uk. . .
Last updated: 11 July 2018 Copyright (c) 1997-2018 University of Cambridge.