github的一些开源项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
8.7 KiB

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