pcre2.3 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. .TH PCRE2 3 "28 April 2021" "PCRE2 10.37"
  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 strings of 8-bit, 16-bit,
  23. or 32-bit code units, which means that up to three separate libraries may be
  24. installed, one for each code unit size. The size of code unit is not related to
  25. the bit size of the underlying hardware. In a 64-bit environment that also
  26. supports 32-bit applications, versions of PCRE2 that are compiled in both
  27. 64-bit and 32-bit modes may be needed.
  28. .P
  29. The original work to extend PCRE to 16-bit and 32-bit code units was done by
  30. Zoltan Herczeg and Christian Persch, respectively. In all three cases, strings
  31. can be interpreted either as one character per code unit, or as UTF-encoded
  32. Unicode, with support for Unicode general category properties. Unicode support
  33. is optional at build time (but is the default). However, processing strings as
  34. UTF code units must be enabled explicitly at run time. The version of Unicode
  35. in use can be discovered by running
  36. .sp
  37. pcre2test -C
  38. .P
  39. The three libraries contain identical sets of functions, with names ending in
  40. _8, _16, or _32, respectively (for example, \fBpcre2_compile_8()\fP). However,
  41. by defining PCRE2_CODE_UNIT_WIDTH to be 8, 16, or 32, a program that uses just
  42. one code unit width can be written using generic names such as
  43. \fBpcre2_compile()\fP, and the documentation is written assuming that this is
  44. the case.
  45. .P
  46. In addition to the Perl-compatible matching function, PCRE2 contains an
  47. alternative function that matches the same compiled patterns in a different
  48. way. In certain circumstances, the alternative function has some advantages.
  49. For a discussion of the two matching algorithms, see the
  50. .\" HREF
  51. \fBpcre2matching\fP
  52. .\"
  53. page.
  54. .P
  55. Details of exactly which Perl regular expression features are and are not
  56. supported by PCRE2 are given in separate documents. See the
  57. .\" HREF
  58. \fBpcre2pattern\fP
  59. .\"
  60. and
  61. .\" HREF
  62. \fBpcre2compat\fP
  63. .\"
  64. pages. There is a syntax summary in the
  65. .\" HREF
  66. \fBpcre2syntax\fP
  67. .\"
  68. page.
  69. .P
  70. Some features of PCRE2 can be included, excluded, or changed when the library
  71. is built. The
  72. .\" HREF
  73. \fBpcre2_config()\fP
  74. .\"
  75. function makes it possible for a client to discover which features are
  76. available. The features themselves are described in the
  77. .\" HREF
  78. \fBpcre2build\fP
  79. .\"
  80. page. Documentation about building PCRE2 for various operating systems can be
  81. found in the
  82. .\" HTML <a href="README.txt">
  83. .\" </a>
  84. \fBREADME\fP
  85. .\"
  86. and
  87. .\" HTML <a href="NON-AUTOTOOLS-BUILD.txt">
  88. .\" </a>
  89. \fBNON-AUTOTOOLS_BUILD\fP
  90. .\"
  91. files in the source distribution.
  92. .P
  93. The libraries contains a number of undocumented internal functions and data
  94. tables that are used by more than one of the exported external functions, but
  95. which are not intended for use by external callers. Their names all begin with
  96. "_pcre2", which hopefully will not provoke any name clashes. In some
  97. environments, it is possible to control which external symbols are exported
  98. when a shared library is built, and in these cases the undocumented symbols are
  99. not exported.
  100. .
  101. .
  102. .SH "SECURITY CONSIDERATIONS"
  103. .rs
  104. .sp
  105. If you are using PCRE2 in a non-UTF application that permits users to supply
  106. arbitrary patterns for compilation, you should be aware of a feature that
  107. allows users to turn on UTF support from within a pattern. For example, an
  108. 8-bit pattern that begins with "(*UTF)" turns on UTF-8 mode, which interprets
  109. patterns and subjects as strings of UTF-8 code units instead of individual
  110. 8-bit characters. This causes both the pattern and any data against which it is
  111. matched to be checked for UTF-8 validity. If the data string is very long, such
  112. a check might use sufficiently many resources as to cause your application to
  113. lose performance.
  114. .P
  115. One way of guarding against this possibility is to use the
  116. \fBpcre2_pattern_info()\fP function to check the compiled pattern's options for
  117. PCRE2_UTF. Alternatively, you can set the PCRE2_NEVER_UTF option when calling
  118. \fBpcre2_compile()\fP. This causes a compile time error if the pattern contains
  119. a UTF-setting sequence.
  120. .P
  121. The use of Unicode properties for character types such as \ed can also be
  122. enabled from within the pattern, by specifying "(*UCP)". This feature can be
  123. disallowed by setting the PCRE2_NEVER_UCP option.
  124. .P
  125. If your application is one that supports UTF, be aware that validity checking
  126. can take time. If the same data string is to be matched many times, you can use
  127. the PCRE2_NO_UTF_CHECK option for the second and subsequent matches to avoid
  128. running redundant checks.
  129. .P
  130. The use of the \eC escape sequence in a UTF-8 or UTF-16 pattern can lead to
  131. problems, because it may leave the current matching point in the middle of a
  132. multi-code-unit character. The PCRE2_NEVER_BACKSLASH_C option can be used by an
  133. application to lock out the use of \eC, causing a compile-time error if it is
  134. encountered. It is also possible to build PCRE2 with the use of \eC permanently
  135. disabled.
  136. .P
  137. Another way that performance can be hit is by running a pattern that has a very
  138. large search tree against a string that will never match. Nested unlimited
  139. repeats in a pattern are a common example. PCRE2 provides some protection
  140. against this: see the \fBpcre2_set_match_limit()\fP function in the
  141. .\" HREF
  142. \fBpcre2api\fP
  143. .\"
  144. page. There is a similar function called \fBpcre2_set_depth_limit()\fP that can
  145. be used to restrict the amount of memory that is used.
  146. .
  147. .
  148. .SH "USER DOCUMENTATION"
  149. .rs
  150. .sp
  151. The user documentation for PCRE2 comprises a number of different sections. In
  152. the "man" format, each of these is a separate "man page". In the HTML format,
  153. each is a separate page, linked from the index page. In the plain text format,
  154. the descriptions of the \fBpcre2grep\fP and \fBpcre2test\fP programs are in
  155. files called \fBpcre2grep.txt\fP and \fBpcre2test.txt\fP, respectively. The
  156. remaining sections, except for the \fBpcre2demo\fP section (which is a program
  157. listing), and the short pages for individual functions, are concatenated in
  158. \fBpcre2.txt\fP, for ease of searching. The sections are as follows:
  159. .sp
  160. pcre2 this document
  161. pcre2-config show PCRE2 installation configuration information
  162. pcre2api details of PCRE2's native C API
  163. pcre2build building PCRE2
  164. pcre2callout details of the pattern callout feature
  165. pcre2compat discussion of Perl compatibility
  166. pcre2convert details of pattern conversion functions
  167. pcre2demo a demonstration C program that uses PCRE2
  168. pcre2grep description of the \fBpcre2grep\fP command (8-bit only)
  169. pcre2jit discussion of just-in-time optimization support
  170. pcre2limits details of size and other limits
  171. pcre2matching discussion of the two matching algorithms
  172. pcre2partial details of the partial matching facility
  173. .\" JOIN
  174. pcre2pattern syntax and semantics of supported regular
  175. expression patterns
  176. pcre2perform discussion of performance issues
  177. pcre2posix the POSIX-compatible C API for the 8-bit library
  178. pcre2sample discussion of the pcre2demo program
  179. pcre2serialize details of pattern serialization
  180. pcre2syntax quick syntax reference
  181. pcre2test description of the \fBpcre2test\fP command
  182. pcre2unicode discussion of Unicode and UTF support
  183. .sp
  184. In the "man" and HTML formats, there is also a short page for each C library
  185. function, listing its arguments and results.
  186. .
  187. .
  188. .SH AUTHOR
  189. .rs
  190. .sp
  191. .nf
  192. Philip Hazel
  193. University Computing Service
  194. Cambridge, England.
  195. .fi
  196. .P
  197. Putting an actual email address here is a spam magnet. If you want to email me,
  198. use my two initials, followed by the two digits 10, at the domain cam.ac.uk.
  199. .
  200. .
  201. .SH REVISION
  202. .rs
  203. .sp
  204. .nf
  205. Last updated: 28 April 2021
  206. Copyright (c) 1997-2021 University of Cambridge.
  207. .fi