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

NAME

6       PCRE - Perl-compatible regular expressions
7

INTRODUCTION

9
10       The  PCRE  library is a set of functions that implement regular expres‐
11       sion pattern matching using the same syntax and semantics as Perl, with
12       just  a few differences. Some features that appeared in Python and PCRE
13       before they appeared in Perl are also available using the  Python  syn‐
14       tax,  there  is  some  support for one or two .NET and Oniguruma syntax
15       items, and there is an option for requesting some  minor  changes  that
16       give better JavaScript compatibility.
17
18       Starting with release 8.30, it is possible to compile two separate PCRE
19       libraries:  the  original,  which  supports  8-bit  character   strings
20       (including  UTF-8  strings),  and a second library that supports 16-bit
21       character strings (including UTF-16 strings). The build process  allows
22       either  one  or both to be built. The majority of the work to make this
23       possible was done by Zoltan Herczeg.
24
25       Starting with release 8.32 it is possible to compile a  third  separate
26       PCRE library, which supports 32-bit character strings (including UTF-32
27       strings). The build process allows any set of the 8-,  16-  and  32-bit
28       libraries. The work to make this possible was done by Christian Persch.
29
30       The  three  libraries  contain identical sets of functions, except that
31       the names in the 16-bit library start with pcre16_  instead  of  pcre_,
32       and  the  names  in  the  32-bit  library start with pcre32_ instead of
33       pcre_. To avoid over-complication and reduce the documentation  mainte‐
34       nance load, most of the documentation describes the 8-bit library, with
35       the differences for the 16-bit and  32-bit  libraries  described  sepa‐
36       rately  in  the  pcre16  and  pcre32  pages. References to functions or
37       structures of the  form  pcre[16|32]_xxx  should  be  read  as  meaning
38       "pcre_xxx  when  using  the  8-bit  library,  pcre16_xxx when using the
39       16-bit library, or pcre32_xxx when using the 32-bit library".
40
41       The current implementation of PCRE corresponds approximately with  Perl
42       5.12,  including  support  for  UTF-8/16/32 encoded strings and Unicode
43       general category properties. However, UTF-8/16/32 and  Unicode  support
44       has to be explicitly enabled; it is not the default. The Unicode tables
45       correspond to Unicode release 6.2.0.
46
47       In addition to the Perl-compatible matching function, PCRE contains  an
48       alternative  function that matches the same compiled patterns in a dif‐
49       ferent way. In certain circumstances, the alternative function has some
50       advantages.   For  a discussion of the two matching algorithms, see the
51       pcrematching page.
52
53       PCRE is written in C and released as a C library. A  number  of  people
54       have  written  wrappers and interfaces of various kinds. In particular,
55       Google Inc.  have provided a comprehensive C++ wrapper  for  the  8-bit
56       library.  This  is  now  included as part of the PCRE distribution. The
57       pcrecpp page has details of this interface.  Other  people's  contribu‐
58       tions  can  be  found in the Contrib directory at the primary FTP site,
59       which is:
60
61       ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre
62
63       Details of exactly which Perl regular expression features are  and  are
64       not supported by PCRE are given in separate documents. See the pcrepat‐
65       tern and pcrecompat pages. There is a syntax summary in the  pcresyntax
66       page.
67
68       Some  features  of  PCRE can be included, excluded, or changed when the
69       library is built. The pcre_config() function makes it  possible  for  a
70       client  to  discover  which  features are available. The features them‐
71       selves are described in the pcrebuild page. Documentation about  build‐
72       ing  PCRE  for various operating systems can be found in the README and
73       NON-AUTOTOOLS_BUILD files in the source distribution.
74
75       The libraries contains a number of undocumented internal functions  and
76       data  tables  that  are  used by more than one of the exported external
77       functions, but which are not intended  for  use  by  external  callers.
78       Their  names all begin with "_pcre_" or "_pcre16_" or "_pcre32_", which
79       hopefully will not provoke any name clashes. In some  environments,  it
80       is  possible  to  control  which  external  symbols are exported when a
81       shared library is built, and in these cases  the  undocumented  symbols
82       are not exported.
83

SECURITY CONSIDERATIONS

85
86       If  you  are  using PCRE in a non-UTF application that permits users to
87       supply arbitrary patterns for compilation, you should  be  aware  of  a
88       feature that allows users to turn on UTF support from within a pattern,
89       provided that PCRE was built with UTF support. For  example,  an  8-bit
90       pattern  that  begins  with  "(*UTF8)" or "(*UTF)" turns on UTF-8 mode,
91       which interprets patterns and subjects as strings of  UTF-8  characters
92       instead  of  individual 8-bit characters.  This causes both the pattern
93       and any data against which it is matched to be checked for UTF-8 valid‐
94       ity.  If  the  data  string is very long, such a check might use suffi‐
95       ciently many resources as to cause your  application  to  lose  perfor‐
96       mance.
97
98       The  best  way  of  guarding  against  this  possibility  is to use the
99       pcre_fullinfo() function to check the compiled  pattern's  options  for
100       UTF.
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 PCRE_NO_UTF[8|16|32]_CHECK option for the second
105       and subsequent matches to save redundant checks.
106
107       Another way that performance can be hit is by running  a  pattern  that
108       has  a  very  large search tree against a string that will never match.
109       Nested unlimited repeats in a pattern are a common example.  PCRE  pro‐
110       vides some protection against this: see the PCRE_EXTRA_MATCH_LIMIT fea‐
111       ture in the pcreapi page.
112

USER DOCUMENTATION

114
115       The user documentation for PCRE comprises a number  of  different  sec‐
116       tions.  In the "man" format, each of these is a separate "man page". In
117       the HTML format, each is a separate page, linked from the  index  page.
118       In  the  plain  text format, all the sections, except the pcredemo sec‐
119       tion, are concatenated, for ease of searching. The sections are as fol‐
120       lows:
121
122         pcre              this document
123         pcre16            details of the 16-bit library
124         pcre32            details of the 32-bit library
125         pcre-config       show PCRE installation configuration information
126         pcreapi           details of PCRE's native C API
127         pcrebuild         options for building PCRE
128         pcrecallout       details of the callout feature
129         pcrecompat        discussion of Perl compatibility
130         pcrecpp           details of the C++ wrapper for the 8-bit library
131         pcredemo          a demonstration C program that uses PCRE
132         pcregrep          description of the pcregrep command (8-bit only)
133         pcrejit           discussion of the just-in-time optimization support
134         pcrelimits        details of size and other limits
135         pcrematching      discussion of the two matching algorithms
136         pcrepartial       details of the partial matching facility
137         pcrepattern       syntax and semantics of supported
138                             regular expressions
139         pcreperform       discussion of performance issues
140         pcreposix         the POSIX-compatible C API for the 8-bit library
141         pcreprecompile    details of saving and re-using precompiled patterns
142         pcresample        discussion of the pcredemo program
143         pcrestack         discussion of stack usage
144         pcresyntax        quick syntax reference
145         pcretest          description of the pcretest testing command
146         pcreunicode       discussion of Unicode and UTF-8/16/32 support
147
148       In  addition,  in the "man" and HTML formats, there is a short page for
149       each C library function, listing its arguments and results.
150

AUTHOR

152
153       Philip Hazel
154       University Computing Service
155       Cambridge CB2 3QH, England.
156
157       Putting an actual email address here seems to have been a spam  magnet,
158       so  I've  taken  it away. If you want to email me, use my two initials,
159       followed by the two digits 10, at the domain cam.ac.uk.
160

REVISION

162
163       Last updated: 11 November 2012
164       Copyright (c) 1997-2012 University of Cambridge.
165
166
167
168PCRE 8.32                      11 November 2012                        PCRE(3)
Impressum