/usr/share/doc/pcre2-devel/html
NameSizeModeActions
index.html136960644editdlrm
NON-AUTOTOOLS-BUILD.txt177620644editdlrm
pcre2-config.html34980644editdlrm
pcre2.html95750644editdlrm
pcre2api.html1719170644editdlrm
pcre2build.html247930644editdlrm
pcre2callout.html200580644editdlrm
pcre2compat.html102970644editdlrm
pcre2convert.html78840644editdlrm
pcre2demo.html201640644editdlrm
pcre2grep.html481110644editdlrm
pcre2jit.html200360644editdlrm
pcre2limits.html32570644editdlrm
pcre2matching.html108630644editdlrm
pcre2partial.html208260644editdlrm
pcre2pattern.html1558790644editdlrm
pcre2perform.html118520644editdlrm
pcre2posix.html145020644editdlrm
pcre2sample.html39050644editdlrm
pcre2serialize.html100820644editdlrm
pcre2syntax.html204780644editdlrm
pcre2test.html870530644editdlrm
pcre2unicode.html121500644editdlrm
pcre2_callout_enumerate.html24310644editdlrm
pcre2_code_copy.html13700644editdlrm
pcre2_code_copy_with_tables.html14910644editdlrm
pcre2_code_free.html12430644editdlrm
pcre2_compile.html43180644editdlrm
pcre2_compile_context_copy.html11760644editdlrm
pcre2_compile_context_create.html12710644editdlrm
pcre2_compile_context_free.html12330644editdlrm
pcre2_config.html35750644editdlrm
pcre2_converted_pattern_free.html12490644editdlrm
pcre2_convert_context_copy.html11570644editdlrm
pcre2_convert_context_create.html12510644editdlrm
pcre2_convert_context_free.html12140644editdlrm
pcre2_dfa_match.html34990644editdlrm
pcre2_general_context_copy.html12250644editdlrm
pcre2_general_context_create.html14860644editdlrm
pcre2_general_context_free.html11720644editdlrm
pcre2_get_error_message.html17450644editdlrm
pcre2_get_mark.html15050644editdlrm
pcre2_get_ovector_count.html10720644editdlrm
pcre2_get_ovector_pointer.html11480644editdlrm
pcre2_get_startchar.html14300644editdlrm
pcre2_jit_compile.html18430644editdlrm
pcre2_jit_free_unused_memory.html13270644editdlrm
pcre2_jit_match.html20390644editdlrm
pcre2_jit_stack_assign.html25620644editdlrm
pcre2_jit_stack_create.html17250644editdlrm
pcre2_jit_stack_free.html12230644editdlrm
pcre2_maketables.html16530644editdlrm
pcre2_match.html35770644editdlrm
pcre2_match_context_copy.html11640644editdlrm
pcre2_match_context_create.html12610644editdlrm
pcre2_match_context_free.html12230644editdlrm
pcre2_match_data_create.html16230644editdlrm
pcre2_match_data_create_from_pattern.html17400644editdlrm
pcre2_match_data_free.html12390644editdlrm
pcre2_pattern_convert.html26630644editdlrm
pcre2_pattern_info.html48010644editdlrm
pcre2_serialize_decode.html25470644editdlrm
pcre2_serialize_encode.html27210644editdlrm
pcre2_serialize_free.html11870644editdlrm
pcre2_serialize_get_number_of_codes.html16340644editdlrm
pcre2_set_bsr.html11990644editdlrm
pcre2_set_callout.html12760644editdlrm
pcre2_set_character_tables.html12350644editdlrm
pcre2_set_compile_extra_options.html15130644editdlrm
pcre2_set_compile_recursion_guard.html16640644editdlrm
pcre2_set_depth_limit.html10800644editdlrm
pcre2_set_glob_escape.html13650644editdlrm
pcre2_set_glob_separator.html13360644editdlrm
pcre2_set_heap_limit.html10760644editdlrm
pcre2_set_match_limit.html10670644editdlrm
pcre2_set_max_pattern_length.html13360644editdlrm
pcre2_set_newline.html15660644editdlrm
pcre2_set_offset_limit.html10730644editdlrm
pcre2_set_parens_nest_limit.html11220644editdlrm
pcre2_set_recursion_limit.html10970644editdlrm
pcre2_set_recursion_memory_management.html12450644editdlrm
pcre2_substitute.html40840644editdlrm
pcre2_substring_copy_byname.html20590644editdlrm
pcre2_substring_copy_bynumber.html18600644editdlrm
pcre2_substring_free.html11960644editdlrm
pcre2_substring_get_byname.html21870644editdlrm
pcre2_substring_get_bynumber.html20230644editdlrm
pcre2_substring_length_byname.html13640644editdlrm
pcre2_substring_length_bynumber.html15180644editdlrm
pcre2_substring_list_free.html12110644editdlrm
pcre2_substring_list_get.html21360644editdlrm
pcre2_substring_nametable_scan.html18450644editdlrm
pcre2_substring_number_from_name.html16450644editdlrm
README.txt419750644editdlrm
Edit: /usr/share/doc/pcre2-devel/html/pcre2.html (9575B)
pcre2 specification

pcre2 man page

Return to the PCRE2 index page.

This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.


INTRODUCTION

PCRE2 is the name used for a revised API for the PCRE library, which is a set of functions, written in C, that implement regular expression pattern matching using the same syntax and semantics as Perl, with just a few differences. After nearly two decades, the limitations of the original API were making development increasingly difficult. The new API is more extensible, and it was simplified by abolishing the separate "study" optimizing function; in PCRE2, patterns are automatically optimized where possible. Since forking from PCRE1, the code has been extensively refactored and new features introduced.

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 pcre2matching page.

Details of exactly which Perl regular expression features are and are not supported by PCRE2 are given in separate documents. See the pcre2pattern and pcre2compat pages. There is a syntax summary in the pcre2syntax page.

Some features of PCRE2 can be included, excluded, or changed when the library is built. The pcre2_config() function makes it possible for a client to discover which features are available. The features themselves are described in the pcre2build page. Documentation about building PCRE2 for various operating systems can be found in the README and 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.


SECURITY CONSIDERATIONS

If you are using PCRE2 in a non-UTF application that permits users to supply arbitrary patterns for compilation, you should be aware of a feature that allows users to turn on UTF support from within a pattern. For example, an 8-bit pattern that begins with "(*UTF)" turns on UTF-8 mode, which interprets patterns and subjects as strings of UTF-8 code units instead of individual 8-bit characters. This causes both the pattern and any data against which it is matched to be checked for UTF-8 validity. If the data string is very long, such a check might use sufficiently many resources as to cause your application to lose performance.

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 \d 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 \C 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 \C, causing a compile-time error if it is encountered. It is also possible to build PCRE2 with the use of \C 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 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.


USER DOCUMENTATION

The user documentation for PCRE2 comprises a number of different sections. In the "man" format, each of these is a separate "man page". In the HTML format, each is a separate page, linked from the index page. In the plain text format, the descriptions of the pcre2grep and pcre2test programs are in files called pcre2grep.txt and pcre2test.txt, respectively. The remaining sections, except for the pcre2demo section (which is a program listing), and the short pages for individual functions, are concatenated in pcre2.txt, for ease of searching. The sections are as follows:

  pcre2              this document
  pcre2-config       show PCRE2 installation configuration information
  pcre2api           details of PCRE2's native C API
  pcre2build         building PCRE2
  pcre2callout       details of the callout feature
  pcre2compat        discussion of Perl compatibility
  pcre2convert       details of pattern conversion functions
  pcre2demo          a demonstration C program that uses PCRE2
  pcre2grep          description of the pcre2grep command (8-bit only)
  pcre2jit           discussion of just-in-time optimization support
  pcre2limits        details of size and other limits
  pcre2matching      discussion of the two matching algorithms
  pcre2partial       details of the partial matching facility
  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.


AUTHOR

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.


REVISION

Last updated: 11 July 2018
Copyright © 1997-2018 University of Cambridge.

Return to the PCRE2 index page.