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.

2186 lines
90 KiB

  1. .TH PCRE2TEST 1 "24 April 2024" "PCRE 10.44"
  2. .SH NAME
  3. pcre2test - a program for testing Perl-compatible regular expressions.
  4. .SH SYNOPSIS
  5. .rs
  6. .sp
  7. .B pcre2test "[options] [input file [output file]]"
  8. .sp
  9. \fBpcre2test\fP is a test program for the PCRE2 regular expression libraries,
  10. but it can also be used for experimenting with regular expressions. This
  11. document describes the features of the test program; for details of the regular
  12. expressions themselves, see the
  13. .\" HREF
  14. \fBpcre2pattern\fP
  15. .\"
  16. documentation. For details of the PCRE2 library function calls and their
  17. options, see the
  18. .\" HREF
  19. \fBpcre2api\fP
  20. .\"
  21. documentation.
  22. .P
  23. The input for \fBpcre2test\fP is a sequence of regular expression patterns and
  24. subject strings to be matched. There are also command lines for setting
  25. defaults and controlling some special actions. The output shows the result of
  26. each match attempt. Modifiers on external or internal command lines, the
  27. patterns, and the subject lines specify PCRE2 function options, control how the
  28. subject is processed, and what output is produced.
  29. .P
  30. There are many obscure modifiers, some of which are specifically designed for
  31. use in conjunction with the test script and data files that are distributed as
  32. part of PCRE2. All the modifiers are documented here, some without much
  33. justification, but many of them are unlikely to be of use except when testing
  34. the libraries.
  35. .
  36. .
  37. .SH "PCRE2's 8-BIT, 16-BIT AND 32-BIT LIBRARIES"
  38. .rs
  39. .sp
  40. Different versions of the PCRE2 library can be built to support character
  41. strings that are encoded in 8-bit, 16-bit, or 32-bit code units. One, two, or
  42. all three of these libraries may be simultaneously installed. The
  43. \fBpcre2test\fP program can be used to test all the libraries. However, its own
  44. input and output are always in 8-bit format. When testing the 16-bit or 32-bit
  45. libraries, patterns and subject strings are converted to 16-bit or 32-bit
  46. format before being passed to the library functions. Results are converted back
  47. to 8-bit code units for output.
  48. .P
  49. In the rest of this document, the names of library functions and structures
  50. are given in generic form, for example, \fBpcre2_compile()\fP. The actual
  51. names used in the libraries have a suffix _8, _16, or _32, as appropriate.
  52. .
  53. .
  54. .\" HTML <a name="inputencoding"></a>
  55. .SH "INPUT ENCODING"
  56. .rs
  57. .sp
  58. Input to \fBpcre2test\fP is processed line by line, either by calling the C
  59. library's \fBfgets()\fP function, or via the \fBlibreadline\fP or \fBlibedit\fP
  60. library. In some Windows environments character 26 (hex 1A) causes an immediate
  61. end of file, and no further data is read, so this character should be avoided
  62. unless you really want that action.
  63. .P
  64. The input is processed using C's string functions, so must not contain binary
  65. zeros, even though in Unix-like environments, \fBfgets()\fP treats any bytes
  66. other than newline as data characters. An error is generated if a binary zero
  67. is encountered. By default subject lines are processed for backslash escapes,
  68. which makes it possible to include any data value in strings that are passed to
  69. the library for matching. For patterns, there is a facility for specifying some
  70. or all of the 8-bit input characters as hexadecimal pairs, which makes it
  71. possible to include binary zeros.
  72. .
  73. .
  74. .SS "Input for the 16-bit and 32-bit libraries"
  75. .rs
  76. .sp
  77. When testing the 16-bit or 32-bit libraries, there is a need to be able to
  78. generate character code points greater than 255 in the strings that are passed
  79. to the library. For subject lines, backslash escapes can be used. In addition,
  80. when the \fButf\fP modifier (see
  81. .\" HTML <a href="#optionmodifiers">
  82. .\" </a>
  83. "Setting compilation options"
  84. .\"
  85. below) is set, the pattern and any following subject lines are interpreted as
  86. UTF-8 strings and translated to UTF-16 or UTF-32 as appropriate.
  87. .P
  88. For non-UTF testing of wide characters, the \fButf8_input\fP modifier can be
  89. used. This is mutually exclusive with \fButf\fP, and is allowed only in 16-bit
  90. or 32-bit mode. It causes the pattern and following subject lines to be treated
  91. as UTF-8 according to the original definition (RFC 2279), which allows for
  92. character values up to 0x7fffffff. Each character is placed in one 16-bit or
  93. 32-bit code unit (in the 16-bit case, values greater than 0xffff cause an error
  94. to occur).
  95. .P
  96. UTF-8 (in its original definition) is not capable of encoding values greater
  97. than 0x7fffffff, but such values can be handled by the 32-bit library. When
  98. testing this library in non-UTF mode with \fButf8_input\fP set, if any
  99. character is preceded by the byte 0xff (which is an invalid byte in UTF-8)
  100. 0x80000000 is added to the character's value. This is the only way of passing
  101. such code points in a pattern string. For subject strings, using an escape
  102. sequence is preferable.
  103. .
  104. .
  105. .SH "COMMAND LINE OPTIONS"
  106. .rs
  107. .TP 10
  108. \fB-8\fP
  109. If the 8-bit library has been built, this option causes it to be used (this is
  110. the default). If the 8-bit library has not been built, this option causes an
  111. error.
  112. .TP 10
  113. \fB-16\fP
  114. If the 16-bit library has been built, this option causes it to be used. If the
  115. 8-bit library has not been built, this is the default. If the 16-bit library
  116. has not been built, this option causes an error.
  117. .TP 10
  118. \fB-32\fP
  119. If the 32-bit library has been built, this option causes it to be used. If no
  120. other library has been built, this is the default. If the 32-bit library has
  121. not been built, this option causes an error.
  122. .TP 10
  123. \fB-ac\fP
  124. Behave as if each pattern has the \fBauto_callout\fP modifier, that is, insert
  125. automatic callouts into every pattern that is compiled.
  126. .TP 10
  127. \fB-AC\fP
  128. As for \fB-ac\fP, but in addition behave as if each subject line has the
  129. \fBcallout_extra\fP modifier, that is, show additional information from
  130. callouts.
  131. .TP 10
  132. \fB-b\fP
  133. Behave as if each pattern has the \fBfullbincode\fP modifier; the full
  134. internal binary form of the pattern is output after compilation.
  135. .TP 10
  136. \fB-C\fP
  137. Output the version number of the PCRE2 library, and all available information
  138. about the optional features that are included, and then exit with zero exit
  139. code. All other options are ignored. If both -C and -LM are present, whichever
  140. is first is recognized.
  141. .TP 10
  142. \fB-C\fP \fIoption\fP
  143. Output information about a specific build-time option, then exit. This
  144. functionality is intended for use in scripts such as \fBRunTest\fP. The
  145. following options output the value and set the exit code as indicated:
  146. .sp
  147. ebcdic-nl the code for LF (= NL) in an EBCDIC environment:
  148. 0x15 or 0x25
  149. 0 if used in an ASCII environment
  150. exit code is always 0
  151. linksize the configured internal link size (2, 3, or 4)
  152. exit code is set to the link size
  153. newline the default newline setting:
  154. CR, LF, CRLF, ANYCRLF, ANY, or NUL
  155. exit code is always 0
  156. bsr the default setting for what \eR matches:
  157. ANYCRLF or ANY
  158. exit code is always 0
  159. .sp
  160. The following options output 1 for true or 0 for false, and set the exit code
  161. to the same value:
  162. .sp
  163. backslash-C \eC is supported (not locked out)
  164. ebcdic compiled for an EBCDIC environment
  165. jit just-in-time support is available
  166. pcre2-16 the 16-bit library was built
  167. pcre2-32 the 32-bit library was built
  168. pcre2-8 the 8-bit library was built
  169. unicode Unicode support is available
  170. .sp
  171. If an unknown option is given, an error message is output; the exit code is 0.
  172. .TP 10
  173. \fB-d\fP
  174. Behave as if each pattern has the \fBdebug\fP modifier; the internal
  175. form and information about the compiled pattern is output after compilation;
  176. \fB-d\fP is equivalent to \fB-b -i\fP.
  177. .TP 10
  178. \fB-dfa\fP
  179. Behave as if each subject line has the \fBdfa\fP modifier; matching is done
  180. using the \fBpcre2_dfa_match()\fP function instead of the default
  181. \fBpcre2_match()\fP.
  182. .TP 10
  183. \fB-error\fP \fInumber[,number,...]\fP
  184. Call \fBpcre2_get_error_message()\fP for each of the error numbers in the
  185. comma-separated list, display the resulting messages on the standard output,
  186. then exit with zero exit code. The numbers may be positive or negative. This is
  187. a convenience facility for PCRE2 maintainers.
  188. .TP 10
  189. \fB-help\fP
  190. Output a brief summary these options and then exit.
  191. .TP 10
  192. \fB-i\fP
  193. Behave as if each pattern has the \fBinfo\fP modifier; information about the
  194. compiled pattern is given after compilation.
  195. .TP 10
  196. \fB-jit\fP
  197. Behave as if each pattern line has the \fBjit\fP modifier; after successful
  198. compilation, each pattern is passed to the just-in-time compiler, if available.
  199. .TP 10
  200. \fB-jitfast\fP
  201. Behave as if each pattern line has the \fBjitfast\fP modifier; after
  202. successful compilation, each pattern is passed to the just-in-time compiler, if
  203. available, and each subject line is passed directly to the JIT matcher via its
  204. "fast path".
  205. .TP 10
  206. \fB-jitverify\fP
  207. Behave as if each pattern line has the \fBjitverify\fP modifier; after
  208. successful compilation, each pattern is passed to the just-in-time compiler, if
  209. available, and the use of JIT for matching is verified.
  210. .TP 10
  211. \fB-LM\fP
  212. List modifiers: write a list of available pattern and subject modifiers to the
  213. standard output, then exit with zero exit code. All other options are ignored.
  214. If both -C and any -Lx options are present, whichever is first is recognized.
  215. .TP 10
  216. \fB-LP\fP
  217. List properties: write a list of recognized Unicode properties to the standard
  218. output, then exit with zero exit code. All other options are ignored. If both
  219. -C and any -Lx options are present, whichever is first is recognized.
  220. .TP 10
  221. \fB-LS\fP
  222. List scripts: write a list of recognized Unicode script names to the standard
  223. output, then exit with zero exit code. All other options are ignored. If both
  224. -C and any -Lx options are present, whichever is first is recognized.
  225. .TP 10
  226. \fB-pattern\fP \fImodifier-list\fP
  227. Behave as if each pattern line contains the given modifiers.
  228. .TP 10
  229. \fB-q\fP
  230. Do not output the version number of \fBpcre2test\fP at the start of execution.
  231. .TP 10
  232. \fB-S\fP \fIsize\fP
  233. On Unix-like systems, set the size of the run-time stack to \fIsize\fP
  234. mebibytes (units of 1024*1024 bytes).
  235. .TP 10
  236. \fB-subject\fP \fImodifier-list\fP
  237. Behave as if each subject line contains the given modifiers.
  238. .TP 10
  239. \fB-t\fP
  240. Run each compile and match many times with a timer, and output the resulting
  241. times per compile or match. When JIT is used, separate times are given for the
  242. initial compile and the JIT compile. You can control the number of iterations
  243. that are used for timing by following \fB-t\fP with a number (as a separate
  244. item on the command line). For example, "-t 1000" iterates 1000 times. The
  245. default is to iterate 500,000 times.
  246. .TP 10
  247. \fB-tm\fP
  248. This is like \fB-t\fP except that it times only the matching phase, not the
  249. compile phase.
  250. .TP 10
  251. \fB-T\fP \fB-TM\fP
  252. These behave like \fB-t\fP and \fB-tm\fP, but in addition, at the end of a run,
  253. the total times for all compiles and matches are output.
  254. .TP 10
  255. \fB-version\fP
  256. Output the PCRE2 version number and then exit.
  257. .
  258. .
  259. .SH "DESCRIPTION"
  260. .rs
  261. .sp
  262. If \fBpcre2test\fP is given two filename arguments, it reads from the first and
  263. writes to the second. If the first name is "-", input is taken from the
  264. standard input. If \fBpcre2test\fP is given only one argument, it reads from
  265. that file and writes to stdout. Otherwise, it reads from stdin and writes to
  266. stdout.
  267. .P
  268. When \fBpcre2test\fP is built, a configuration option can specify that it
  269. should be linked with the \fBlibreadline\fP or \fBlibedit\fP library. When this
  270. is done, if the input is from a terminal, it is read using the \fBreadline()\fP
  271. function. This provides line-editing and history facilities. The output from
  272. the \fB-help\fP option states whether or not \fBreadline()\fP will be used.
  273. .P
  274. The program handles any number of tests, each of which consists of a set of
  275. input lines. Each set starts with a regular expression pattern, followed by any
  276. number of subject lines to be matched against that pattern. In between sets of
  277. test data, command lines that begin with # may appear. This file format, with
  278. some restrictions, can also be processed by the \fBperltest.sh\fP script that
  279. is distributed with PCRE2 as a means of checking that the behaviour of PCRE2
  280. and Perl is the same. For a specification of \fBperltest.sh\fP, see the
  281. comments near its beginning. See also the #perltest command below.
  282. .P
  283. When the input is a terminal, \fBpcre2test\fP prompts for each line of input,
  284. using "re>" to prompt for regular expression patterns, and "data>" to prompt
  285. for subject lines. Command lines starting with # can be entered only in
  286. response to the "re>" prompt.
  287. .P
  288. Each subject line is matched separately and independently. If you want to do
  289. multi-line matches, you have to use the \en escape sequence (or \er or \er\en,
  290. etc., depending on the newline setting) in a single line of input to encode the
  291. newline sequences. There is no limit on the length of subject lines; the input
  292. buffer is automatically extended if it is too small. There are replication
  293. features that makes it possible to generate long repetitive pattern or subject
  294. lines without having to supply them explicitly.
  295. .P
  296. An empty line or the end of the file signals the end of the subject lines for a
  297. test, at which point a new pattern or command line is expected if there is
  298. still input to be read.
  299. .
  300. .
  301. .SH "COMMAND LINES"
  302. .rs
  303. .sp
  304. In between sets of test data, a line that begins with # is interpreted as a
  305. command line. If the first character is followed by white space or an
  306. exclamation mark, the line is treated as a comment, and ignored. Otherwise, the
  307. following commands are recognized:
  308. .sp
  309. #forbid_utf
  310. .sp
  311. Subsequent patterns automatically have the PCRE2_NEVER_UTF and PCRE2_NEVER_UCP
  312. options set, which locks out the use of the PCRE2_UTF and PCRE2_UCP options and
  313. the use of (*UTF) and (*UCP) at the start of patterns. This command also forces
  314. an error if a subsequent pattern contains any occurrences of \eP, \ep, or \eX,
  315. which are still supported when PCRE2_UTF is not set, but which require Unicode
  316. property support to be included in the library.
  317. .P
  318. This is a trigger guard that is used in test files to ensure that UTF or
  319. Unicode property tests are not accidentally added to files that are used when
  320. Unicode support is not included in the library. Setting PCRE2_NEVER_UTF and
  321. PCRE2_NEVER_UCP as a default can also be obtained by the use of \fB#pattern\fP;
  322. the difference is that \fB#forbid_utf\fP cannot be unset, and the automatic
  323. options are not displayed in pattern information, to avoid cluttering up test
  324. output.
  325. .sp
  326. #load <filename>
  327. .sp
  328. This command is used to load a set of precompiled patterns from a file, as
  329. described in the section entitled "Saving and restoring compiled patterns"
  330. .\" HTML <a href="#saverestore">
  331. .\" </a>
  332. below.
  333. .\"
  334. .sp
  335. #loadtables <filename>
  336. .sp
  337. This command is used to load a set of binary character tables that can be
  338. accessed by the tables=3 qualifier. Such tables can be created by the
  339. \fBpcre2_dftables\fP program with the -b option.
  340. .sp
  341. #newline_default [<newline-list>]
  342. .sp
  343. When PCRE2 is built, a default newline convention can be specified. This
  344. determines which characters and/or character pairs are recognized as indicating
  345. a newline in a pattern or subject string. The default can be overridden when a
  346. pattern is compiled. The standard test files contain tests of various newline
  347. conventions, but the majority of the tests expect a single linefeed to be
  348. recognized as a newline by default. Without special action the tests would fail
  349. when PCRE2 is compiled with either CR or CRLF as the default newline.
  350. .P
  351. The #newline_default command specifies a list of newline types that are
  352. acceptable as the default. The types must be one of CR, LF, CRLF, ANYCRLF,
  353. ANY, or NUL (in upper or lower case), for example:
  354. .sp
  355. #newline_default LF Any anyCRLF
  356. .sp
  357. If the default newline is in the list, this command has no effect. Otherwise,
  358. except when testing the POSIX API, a \fBnewline\fP modifier that specifies the
  359. first newline convention in the list (LF in the above example) is added to any
  360. pattern that does not already have a \fBnewline\fP modifier. If the newline
  361. list is empty, the feature is turned off. This command is present in a number
  362. of the standard test input files.
  363. .P
  364. When the POSIX API is being tested there is no way to override the default
  365. newline convention, though it is possible to set the newline convention from
  366. within the pattern. A warning is given if the \fBposix\fP or \fBposix_nosub\fP
  367. modifier is used when \fB#newline_default\fP would set a default for the
  368. non-POSIX API.
  369. .sp
  370. #pattern <modifier-list>
  371. .sp
  372. This command sets a default modifier list that applies to all subsequent
  373. patterns. Modifiers on a pattern can change these settings.
  374. .sp
  375. #perltest
  376. .sp
  377. This line is used in test files that can also be processed by \fBperltest.sh\fP
  378. to confirm that Perl gives the same results as PCRE2. Subsequent tests are
  379. checked for the use of \fBpcre2test\fP features that are incompatible with the
  380. \fBperltest.sh\fP script.
  381. .P
  382. Patterns must use '/' as their delimiter, and only certain modifiers are
  383. supported. Comment lines, #pattern commands, and #subject commands that set or
  384. unset "mark" are recognized and acted on. The #perltest, #forbid_utf, and
  385. #newline_default commands, which are needed in the relevant pcre2test files,
  386. are silently ignored. All other command lines are ignored, but give a warning
  387. message. The \fB#perltest\fP command helps detect tests that are accidentally
  388. put in the wrong file or use the wrong delimiter. For more details of the
  389. \fBperltest.sh\fP script see the comments it contains.
  390. .sp
  391. #pop [<modifiers>]
  392. #popcopy [<modifiers>]
  393. .sp
  394. These commands are used to manipulate the stack of compiled patterns, as
  395. described in the section entitled "Saving and restoring compiled patterns"
  396. .\" HTML <a href="#saverestore">
  397. .\" </a>
  398. below.
  399. .\"
  400. .sp
  401. #save <filename>
  402. .sp
  403. This command is used to save a set of compiled patterns to a file, as described
  404. in the section entitled "Saving and restoring compiled patterns"
  405. .\" HTML <a href="#saverestore">
  406. .\" </a>
  407. below.
  408. .\"
  409. .sp
  410. #subject <modifier-list>
  411. .sp
  412. This command sets a default modifier list that applies to all subsequent
  413. subject lines. Modifiers on a subject line can change these settings.
  414. .
  415. .
  416. .SH "MODIFIER SYNTAX"
  417. .rs
  418. .sp
  419. Modifier lists are used with both pattern and subject lines. Items in a list
  420. are separated by commas followed by optional white space. Trailing whitespace
  421. in a modifier list is ignored. Some modifiers may be given for both patterns
  422. and subject lines, whereas others are valid only for one or the other. Each
  423. modifier has a long name, for example "anchored", and some of them must be
  424. followed by an equals sign and a value, for example, "offset=12". Values cannot
  425. contain comma characters, but may contain spaces. Modifiers that do not take
  426. values may be preceded by a minus sign to turn off a previous setting.
  427. .P
  428. A few of the more common modifiers can also be specified as single letters, for
  429. example "i" for "caseless". In documentation, following the Perl convention,
  430. these are written with a slash ("the /i modifier") for clarity. Abbreviated
  431. modifiers must all be concatenated in the first item of a modifier list. If the
  432. first item is not recognized as a long modifier name, it is interpreted as a
  433. sequence of these abbreviations. For example:
  434. .sp
  435. /abc/ig,newline=cr,jit=3
  436. .sp
  437. This is a pattern line whose modifier list starts with two one-letter modifiers
  438. (/i and /g). The lower-case abbreviated modifiers are the same as used in Perl.
  439. .
  440. .
  441. .SH "PATTERN SYNTAX"
  442. .rs
  443. .sp
  444. A pattern line must start with one of the following characters (common symbols,
  445. excluding pattern meta-characters):
  446. .sp
  447. / ! " ' ` - = _ : ; , % & @ ~
  448. .sp
  449. This is interpreted as the pattern's delimiter. A regular expression may be
  450. continued over several input lines, in which case the newline characters are
  451. included within it. It is possible to include the delimiter as a literal within
  452. the pattern by escaping it with a backslash, for example
  453. .sp
  454. /abc\e/def/
  455. .sp
  456. If you do this, the escape and the delimiter form part of the pattern, but
  457. since the delimiters are all non-alphanumeric, the inclusion of the backslash
  458. does not affect the pattern's interpretation. Note, however, that this trick
  459. does not work within \eQ...\eE literal bracketing because the backslash will
  460. itself be interpreted as a literal. If the terminating delimiter is immediately
  461. followed by a backslash, for example,
  462. .sp
  463. /abc/\e
  464. .sp
  465. a backslash is added to the end of the pattern. This is done to provide a way
  466. of testing the error condition that arises if a pattern finishes with a
  467. backslash, because
  468. .sp
  469. /abc\e/
  470. .sp
  471. is interpreted as the first line of a pattern that starts with "abc/", causing
  472. pcre2test to read the next line as a continuation of the regular expression.
  473. .P
  474. A pattern can be followed by a modifier list (details below).
  475. .
  476. .
  477. .SH "SUBJECT LINE SYNTAX"
  478. .rs
  479. .sp
  480. Before each subject line is passed to \fBpcre2_match()\fP,
  481. \fBpcre2_dfa_match()\fP, or \fBpcre2_jit_match()\fP, leading and trailing white
  482. space is removed, and the line is scanned for backslash escapes, unless the
  483. \fBsubject_literal\fP modifier was set for the pattern. The following provide a
  484. means of encoding non-printing characters in a visible way:
  485. .sp
  486. \ea alarm (BEL, \ex07)
  487. \eb backspace (\ex08)
  488. \ee escape (\ex27)
  489. \ef form feed (\ex0c)
  490. \en newline (\ex0a)
  491. \er carriage return (\ex0d)
  492. \et tab (\ex09)
  493. \ev vertical tab (\ex0b)
  494. \ennn octal character (up to 3 octal digits); always
  495. a byte unless > 255 in UTF-8 or 16-bit or 32-bit mode
  496. \eo{dd...} octal character (any number of octal digits}
  497. \exhh hexadecimal byte (up to 2 hex digits)
  498. \ex{hh...} hexadecimal character (any number of hex digits)
  499. .sp
  500. The use of \ex{hh...} is not dependent on the use of the \fButf\fP modifier on
  501. the pattern. It is recognized always. There may be any number of hexadecimal
  502. digits inside the braces; invalid values provoke error messages.
  503. .P
  504. Note that \exhh specifies one byte rather than one character in UTF-8 mode;
  505. this makes it possible to construct invalid UTF-8 sequences for testing
  506. purposes. On the other hand, \ex{hh} is interpreted as a UTF-8 character in
  507. UTF-8 mode, generating more than one byte if the value is greater than 127.
  508. When testing the 8-bit library not in UTF-8 mode, \ex{hh} generates one byte
  509. for values less than 256, and causes an error for greater values.
  510. .P
  511. In UTF-16 mode, all 4-digit \ex{hhhh} values are accepted. This makes it
  512. possible to construct invalid UTF-16 sequences for testing purposes.
  513. .P
  514. In UTF-32 mode, all 4- to 8-digit \ex{...} values are accepted. This makes it
  515. possible to construct invalid UTF-32 sequences for testing purposes.
  516. .P
  517. There is a special backslash sequence that specifies replication of one or more
  518. characters:
  519. .sp
  520. \e[<characters>]{<count>}
  521. .sp
  522. This makes it possible to test long strings without having to provide them as
  523. part of the file. For example:
  524. .sp
  525. \e[abc]{4}
  526. .sp
  527. is converted to "abcabcabcabc". This feature does not support nesting. To
  528. include a closing square bracket in the characters, code it as \ex5D.
  529. .P
  530. A backslash followed by an equals sign marks the end of the subject string and
  531. the start of a modifier list. For example:
  532. .sp
  533. abc\e=notbol,notempty
  534. .sp
  535. If the subject string is empty and \e= is followed by whitespace, the line is
  536. treated as a comment line, and is not used for matching. For example:
  537. .sp
  538. \e= This is a comment.
  539. abc\e= This is an invalid modifier list.
  540. .sp
  541. A backslash followed by any other non-alphanumeric character just escapes that
  542. character. A backslash followed by anything else causes an error. However, if
  543. the very last character in the line is a backslash (and there is no modifier
  544. list), it is ignored. This gives a way of passing an empty line as data, since
  545. a real empty line terminates the data input.
  546. .P
  547. If the \fBsubject_literal\fP modifier is set for a pattern, all subject lines
  548. that follow are treated as literals, with no special treatment of backslashes.
  549. No replication is possible, and any subject modifiers must be set as defaults
  550. by a \fB#subject\fP command.
  551. .
  552. .
  553. .SH "PATTERN MODIFIERS"
  554. .rs
  555. .sp
  556. There are several types of modifier that can appear in pattern lines. Except
  557. where noted below, they may also be used in \fB#pattern\fP commands. A
  558. pattern's modifier list can add to or override default modifiers that were set
  559. by a previous \fB#pattern\fP command.
  560. .
  561. .
  562. .\" HTML <a name="optionmodifiers"></a>
  563. .SS "Setting compilation options"
  564. .rs
  565. .sp
  566. The following modifiers set options for \fBpcre2_compile()\fP. Most of them set
  567. bits in the options argument of that function, but those whose names start with
  568. PCRE2_EXTRA are additional options that are set in the compile context.
  569. Some of these options have single-letter abbreviations. There is special
  570. handling for /x: if a second x is present, PCRE2_EXTENDED is converted into
  571. PCRE2_EXTENDED_MORE as in Perl. A third appearance adds PCRE2_EXTENDED as well,
  572. though this makes no difference to the way \fBpcre2_compile()\fP behaves. See
  573. .\" HREF
  574. \fBpcre2api\fP
  575. .\"
  576. for a description of the effects of these options.
  577. .sp
  578. allow_empty_class set PCRE2_ALLOW_EMPTY_CLASS
  579. allow_lookaround_bsk set PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK
  580. allow_surrogate_escapes set PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES
  581. alt_bsux set PCRE2_ALT_BSUX
  582. alt_circumflex set PCRE2_ALT_CIRCUMFLEX
  583. alt_verbnames set PCRE2_ALT_VERBNAMES
  584. anchored set PCRE2_ANCHORED
  585. /a ascii_all set all ASCII options
  586. ascii_bsd set PCRE2_EXTRA_ASCII_BSD
  587. ascii_bss set PCRE2_EXTRA_ASCII_BSS
  588. ascii_bsw set PCRE2_EXTRA_ASCII_BSW
  589. ascii_digit set PCRE2_EXTRA_ASCII_DIGIT
  590. ascii_posix set PCRE2_EXTRA_ASCII_POSIX
  591. auto_callout set PCRE2_AUTO_CALLOUT
  592. bad_escape_is_literal set PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL
  593. /i caseless set PCRE2_CASELESS
  594. /r caseless_restrict set PCRE2_EXTRA_CASELESS_RESTRICT
  595. dollar_endonly set PCRE2_DOLLAR_ENDONLY
  596. /s dotall set PCRE2_DOTALL
  597. dupnames set PCRE2_DUPNAMES
  598. endanchored set PCRE2_ENDANCHORED
  599. escaped_cr_is_lf set PCRE2_EXTRA_ESCAPED_CR_IS_LF
  600. /x extended set PCRE2_EXTENDED
  601. /xx extended_more set PCRE2_EXTENDED_MORE
  602. extra_alt_bsux set PCRE2_EXTRA_ALT_BSUX
  603. firstline set PCRE2_FIRSTLINE
  604. literal set PCRE2_LITERAL
  605. match_line set PCRE2_EXTRA_MATCH_LINE
  606. match_invalid_utf set PCRE2_MATCH_INVALID_UTF
  607. match_unset_backref set PCRE2_MATCH_UNSET_BACKREF
  608. match_word set PCRE2_EXTRA_MATCH_WORD
  609. /m multiline set PCRE2_MULTILINE
  610. never_backslash_c set PCRE2_NEVER_BACKSLASH_C
  611. never_ucp set PCRE2_NEVER_UCP
  612. never_utf set PCRE2_NEVER_UTF
  613. /n no_auto_capture set PCRE2_NO_AUTO_CAPTURE
  614. no_auto_possess set PCRE2_NO_AUTO_POSSESS
  615. no_dotstar_anchor set PCRE2_NO_DOTSTAR_ANCHOR
  616. no_start_optimize set PCRE2_NO_START_OPTIMIZE
  617. no_utf_check set PCRE2_NO_UTF_CHECK
  618. ucp set PCRE2_UCP
  619. ungreedy set PCRE2_UNGREEDY
  620. use_offset_limit set PCRE2_USE_OFFSET_LIMIT
  621. utf set PCRE2_UTF
  622. .sp
  623. As well as turning on the PCRE2_UTF option, the \fButf\fP modifier causes all
  624. non-printing characters in output strings to be printed using the \ex{hh...}
  625. notation. Otherwise, those less than 0x100 are output in hex without the curly
  626. brackets. Setting \fButf\fP in 16-bit or 32-bit mode also causes pattern and
  627. subject strings to be translated to UTF-16 or UTF-32, respectively, before
  628. being passed to library functions.
  629. .
  630. .
  631. .\" HTML <a name="controlmodifiers"></a>
  632. .SS "Setting compilation controls"
  633. .rs
  634. .sp
  635. The following modifiers affect the compilation process or request information
  636. about the pattern. There are single-letter abbreviations for some that are
  637. heavily used in the test files.
  638. .sp
  639. bsr=[anycrlf|unicode] specify \eR handling
  640. /B bincode show binary code without lengths
  641. callout_info show callout information
  642. convert=<options> request foreign pattern conversion
  643. convert_glob_escape=c set glob escape character
  644. convert_glob_separator=c set glob separator character
  645. convert_length set convert buffer length
  646. debug same as info,fullbincode
  647. framesize show matching frame size
  648. fullbincode show binary code with lengths
  649. /I info show info about compiled pattern
  650. hex unquoted characters are hexadecimal
  651. jit[=<number>] use JIT
  652. jitfast use JIT fast path
  653. jitverify verify JIT use
  654. locale=<name> use this locale
  655. max_pattern_compiled ) set maximum compiled pattern
  656. _length=<n> ) length (bytes)
  657. max_pattern_length=<n> set maximum pattern length (code units)
  658. max_varlookbehind=<n> set maximum variable lookbehind length
  659. memory show memory used
  660. newline=<type> set newline type
  661. null_context compile with a NULL context
  662. null_pattern pass pattern as NULL
  663. parens_nest_limit=<n> set maximum parentheses depth
  664. posix use the POSIX API
  665. posix_nosub use the POSIX API with REG_NOSUB
  666. push push compiled pattern onto the stack
  667. pushcopy push a copy onto the stack
  668. stackguard=<number> test the stackguard feature
  669. subject_literal treat all subject lines as literal
  670. tables=[0|1|2|3] select internal tables
  671. use_length do not zero-terminate the pattern
  672. utf8_input treat input as UTF-8
  673. .sp
  674. The effects of these modifiers are described in the following sections.
  675. .
  676. .
  677. .SS "Newline and \eR handling"
  678. .rs
  679. .sp
  680. The \fBbsr\fP modifier specifies what \eR in a pattern should match. If it is
  681. set to "anycrlf", \eR matches CR, LF, or CRLF only. If it is set to "unicode",
  682. \eR matches any Unicode newline sequence. The default can be specified when
  683. PCRE2 is built; if it is not, the default is set to Unicode.
  684. .P
  685. The \fBnewline\fP modifier specifies which characters are to be interpreted as
  686. newlines, both in the pattern and in subject lines. The type must be one of CR,
  687. LF, CRLF, ANYCRLF, ANY, or NUL (in upper or lower case).
  688. .
  689. .
  690. .SS "Information about a pattern"
  691. .rs
  692. .sp
  693. The \fBdebug\fP modifier is a shorthand for \fBinfo,fullbincode\fP, requesting
  694. all available information.
  695. .P
  696. The \fBbincode\fP modifier causes a representation of the compiled code to be
  697. output after compilation. This information does not contain length and offset
  698. values, which ensures that the same output is generated for different internal
  699. link sizes and different code unit widths. By using \fBbincode\fP, the same
  700. regression tests can be used in different environments.
  701. .P
  702. The \fBfullbincode\fP modifier, by contrast, \fIdoes\fP include length and
  703. offset values. This is used in a few special tests that run only for specific
  704. code unit widths and link sizes, and is also useful for one-off tests.
  705. .P
  706. The \fBinfo\fP modifier requests information about the compiled pattern
  707. (whether it is anchored, has a fixed first character, and so on). The
  708. information is obtained from the \fBpcre2_pattern_info()\fP function. Here are
  709. some typical examples:
  710. .sp
  711. re> /(?i)(^a|^b)/m,info
  712. Capture group count = 1
  713. Compile options: multiline
  714. Overall options: caseless multiline
  715. First code unit at start or follows newline
  716. Subject length lower bound = 1
  717. .sp
  718. re> /(?i)abc/info
  719. Capture group count = 0
  720. Compile options: <none>
  721. Overall options: caseless
  722. First code unit = 'a' (caseless)
  723. Last code unit = 'c' (caseless)
  724. Subject length lower bound = 3
  725. .sp
  726. "Compile options" are those specified by modifiers; "overall options" have
  727. added options that are taken or deduced from the pattern. If both sets of
  728. options are the same, just a single "options" line is output; if there are no
  729. options, the line is omitted. "First code unit" is where any match must start;
  730. if there is more than one they are listed as "starting code units". "Last code
  731. unit" is the last literal code unit that must be present in any match. This is
  732. not necessarily the last character. These lines are omitted if no starting or
  733. ending code units are recorded. The subject length line is omitted when
  734. \fBno_start_optimize\fP is set because the minimum length is not calculated
  735. when it can never be used.
  736. .P
  737. The \fBframesize\fP modifier shows the size, in bytes, of each storage frame
  738. used by \fBpcre2_match()\fP for handling backtracking. The size depends on the
  739. number of capturing parentheses in the pattern. A vector of these frames is
  740. used at matching time; its overall size is shown when the \fBheaframes_size\fP
  741. subject modifier is set.
  742. .P
  743. The \fBcallout_info\fP modifier requests information about all the callouts in
  744. the pattern. A list of them is output at the end of any other information that
  745. is requested. For each callout, either its number or string is given, followed
  746. by the item that follows it in the pattern.
  747. .
  748. .
  749. .SS "Passing a NULL context"
  750. .rs
  751. .sp
  752. Normally, \fBpcre2test\fP passes a context block to \fBpcre2_compile()\fP. If
  753. the \fBnull_context\fP modifier is set, however, NULL is passed. This is for
  754. testing that \fBpcre2_compile()\fP behaves correctly in this case (it uses
  755. default values).
  756. .
  757. .
  758. .SS "Passing a NULL pattern"
  759. .rs
  760. .sp
  761. The \fBnull_pattern\fP modifier is for testing the behaviour of
  762. \fBpcre2_compile()\fP when the pattern argument is NULL. The length value
  763. passed is the default PCRE2_ZERO_TERMINATED unless \fBuse_length\fP is set.
  764. Any length other than zero causes an error.
  765. .
  766. .
  767. .SS "Specifying pattern characters in hexadecimal"
  768. .rs
  769. .sp
  770. The \fBhex\fP modifier specifies that the characters of the pattern, except for
  771. substrings enclosed in single or double quotes, are to be interpreted as pairs
  772. of hexadecimal digits. This feature is provided as a way of creating patterns
  773. that contain binary zeros and other non-printing characters. White space is
  774. permitted between pairs of digits. For example, this pattern contains three
  775. characters:
  776. .sp
  777. /ab 32 59/hex
  778. .sp
  779. Parts of such a pattern are taken literally if quoted. This pattern contains
  780. nine characters, only two of which are specified in hexadecimal:
  781. .sp
  782. /ab "literal" 32/hex
  783. .sp
  784. Either single or double quotes may be used. There is no way of including
  785. the delimiter within a substring. The \fBhex\fP and \fBexpand\fP modifiers are
  786. mutually exclusive.
  787. .
  788. .
  789. .SS "Specifying the pattern's length"
  790. .rs
  791. .sp
  792. By default, patterns are passed to the compiling functions as zero-terminated
  793. strings but can be passed by length instead of being zero-terminated. The
  794. \fBuse_length\fP modifier causes this to happen. Using a length happens
  795. automatically (whether or not \fBuse_length\fP is set) when \fBhex\fP is set,
  796. because patterns specified in hexadecimal may contain binary zeros.
  797. .P
  798. If \fBhex\fP or \fBuse_length\fP is used with the POSIX wrapper API (see
  799. .\" HTML <a href="#posixwrapper">
  800. .\" </a>
  801. "Using the POSIX wrapper API"
  802. .\"
  803. below), the REG_PEND extension is used to pass the pattern's length.
  804. .
  805. .
  806. .SS "Specifying a maximum for variable lookbehinds"
  807. .rs
  808. .sp
  809. Variable lookbehind assertions are supported only if, for each one, there is a
  810. maximum length (in characters) that it can match. There is a limit on this,
  811. whose default can be set at build time, with an ultimate default of 255. The
  812. \fBmax_varlookbehind\fP modifier uses the \fBpcre2_set_max_varlookbehind()\fP
  813. function to change the limit. Lookbehinds whose branches each match a fixed
  814. length are limited to 65535 characters per branch.
  815. .
  816. .
  817. .SS "Specifying wide characters in 16-bit and 32-bit modes"
  818. .rs
  819. .sp
  820. In 16-bit and 32-bit modes, all input is automatically treated as UTF-8 and
  821. translated to UTF-16 or UTF-32 when the \fButf\fP modifier is set. For testing
  822. the 16-bit and 32-bit libraries in non-UTF mode, the \fButf8_input\fP modifier
  823. can be used. It is mutually exclusive with \fButf\fP. Input lines are
  824. interpreted as UTF-8 as a means of specifying wide characters. More details are
  825. given in
  826. .\" HTML <a href="#inputencoding">
  827. .\" </a>
  828. "Input encoding"
  829. .\"
  830. above.
  831. .
  832. .
  833. .SS "Generating long repetitive patterns"
  834. .rs
  835. .sp
  836. Some tests use long patterns that are very repetitive. Instead of creating a
  837. very long input line for such a pattern, you can use a special repetition
  838. feature, similar to the one described for subject lines above. If the
  839. \fBexpand\fP modifier is present on a pattern, parts of the pattern that have
  840. the form
  841. .sp
  842. \e[<characters>]{<count>}
  843. .sp
  844. are expanded before the pattern is passed to \fBpcre2_compile()\fP. For
  845. example, \e[AB]{6000} is expanded to "ABAB..." 6000 times. This construction
  846. cannot be nested. An initial "\e[" sequence is recognized only if "]{" followed
  847. by decimal digits and "}" is found later in the pattern. If not, the characters
  848. remain in the pattern unaltered. The \fBexpand\fP and \fBhex\fP modifiers are
  849. mutually exclusive.
  850. .P
  851. If part of an expanded pattern looks like an expansion, but is really part of
  852. the actual pattern, unwanted expansion can be avoided by giving two values in
  853. the quantifier. For example, \e[AB]{6000,6000} is not recognized as an
  854. expansion item.
  855. .P
  856. If the \fBinfo\fP modifier is set on an expanded pattern, the result of the
  857. expansion is included in the information that is output.
  858. .
  859. .
  860. .SS "JIT compilation"
  861. .rs
  862. .sp
  863. Just-in-time (JIT) compiling is a heavyweight optimization that can greatly
  864. speed up pattern matching. See the
  865. .\" HREF
  866. \fBpcre2jit\fP
  867. .\"
  868. documentation for details. JIT compiling happens, optionally, after a pattern
  869. has been successfully compiled into an internal form. The JIT compiler converts
  870. this to optimized machine code. It needs to know whether the match-time options
  871. PCRE2_PARTIAL_HARD and PCRE2_PARTIAL_SOFT are going to be used, because
  872. different code is generated for the different cases. See the \fBpartial\fP
  873. modifier in "Subject Modifiers"
  874. .\" HTML <a href="#subjectmodifiers">
  875. .\" </a>
  876. below
  877. .\"
  878. for details of how these options are specified for each match attempt.
  879. .P
  880. JIT compilation is requested by the \fBjit\fP pattern modifier, which may
  881. optionally be followed by an equals sign and a number in the range 0 to 7.
  882. The three bits that make up the number specify which of the three JIT operating
  883. modes are to be compiled:
  884. .sp
  885. 1 compile JIT code for non-partial matching
  886. 2 compile JIT code for soft partial matching
  887. 4 compile JIT code for hard partial matching
  888. .sp
  889. The possible values for the \fBjit\fP modifier are therefore:
  890. .sp
  891. 0 disable JIT
  892. 1 normal matching only
  893. 2 soft partial matching only
  894. 3 normal and soft partial matching
  895. 4 hard partial matching only
  896. 6 soft and hard partial matching only
  897. 7 all three modes
  898. .sp
  899. If no number is given, 7 is assumed. The phrase "partial matching" means a call
  900. to \fBpcre2_match()\fP with either the PCRE2_PARTIAL_SOFT or the
  901. PCRE2_PARTIAL_HARD option set. Note that such a call may return a complete
  902. match; the options enable the possibility of a partial match, but do not
  903. require it. Note also that if you request JIT compilation only for partial
  904. matching (for example, jit=2) but do not set the \fBpartial\fP modifier on a
  905. subject line, that match will not use JIT code because none was compiled for
  906. non-partial matching.
  907. .P
  908. If JIT compilation is successful, the compiled JIT code will automatically be
  909. used when an appropriate type of match is run, except when incompatible
  910. run-time options are specified. For more details, see the
  911. .\" HREF
  912. \fBpcre2jit\fP
  913. .\"
  914. documentation. See also the \fBjitstack\fP modifier below for a way of
  915. setting the size of the JIT stack.
  916. .P
  917. If the \fBjitfast\fP modifier is specified, matching is done using the JIT
  918. "fast path" interface, \fBpcre2_jit_match()\fP, which skips some of the sanity
  919. checks that are done by \fBpcre2_match()\fP, and of course does not work when
  920. JIT is not supported. If \fBjitfast\fP is specified without \fBjit\fP, jit=7 is
  921. assumed.
  922. .P
  923. If the \fBjitverify\fP modifier is specified, information about the compiled
  924. pattern shows whether JIT compilation was or was not successful. If
  925. \fBjitverify\fP is specified without \fBjit\fP, jit=7 is assumed. If JIT
  926. compilation is successful when \fBjitverify\fP is set, the text "(JIT)" is
  927. added to the first output line after a match or non match when JIT-compiled
  928. code was actually used in the match.
  929. .
  930. .
  931. .SS "Setting a locale"
  932. .rs
  933. .sp
  934. The \fBlocale\fP modifier must specify the name of a locale, for example:
  935. .sp
  936. /pattern/locale=fr_FR
  937. .sp
  938. The given locale is set, \fBpcre2_maketables()\fP is called to build a set of
  939. character tables for the locale, and this is then passed to
  940. \fBpcre2_compile()\fP when compiling the regular expression. The same tables
  941. are used when matching the following subject lines. The \fBlocale\fP modifier
  942. applies only to the pattern on which it appears, but can be given in a
  943. \fB#pattern\fP command if a default is needed. Setting a locale and alternate
  944. character tables are mutually exclusive.
  945. .
  946. .
  947. .SS "Showing pattern memory"
  948. .rs
  949. .sp
  950. The \fBmemory\fP modifier causes the size in bytes of the memory used to hold
  951. the compiled pattern to be output. This does not include the size of the
  952. \fBpcre2_code\fP block; it is just the actual compiled data. If the pattern is
  953. subsequently passed to the JIT compiler, the size of the JIT compiled code is
  954. also output. Here is an example:
  955. .sp
  956. re> /a(b)c/jit,memory
  957. Memory allocation (code space): 21
  958. Memory allocation (JIT code): 1910
  959. .sp
  960. .
  961. .
  962. .SS "Limiting nested parentheses"
  963. .rs
  964. .sp
  965. The \fBparens_nest_limit\fP modifier sets a limit on the depth of nested
  966. parentheses in a pattern. Breaching the limit causes a compilation error.
  967. The default for the library is set when PCRE2 is built, but \fBpcre2test\fP
  968. sets its own default of 220, which is required for running the standard test
  969. suite.
  970. .
  971. .
  972. .SS "Limiting the pattern length"
  973. .rs
  974. .sp
  975. The \fBmax_pattern_length\fP modifier sets a limit, in code units, to the
  976. length of pattern that \fBpcre2_compile()\fP will accept. Breaching the limit
  977. causes a compilation error. The default is the largest number a PCRE2_SIZE
  978. variable can hold (essentially unlimited).
  979. .
  980. .
  981. .SS "Limiting the size of a compiled pattern"
  982. .rs
  983. .sp
  984. The \fBmax_pattern_compiled_length\fP modifier sets a limit, in bytes, to the
  985. amount of memory used by a compiled pattern. Breaching the limit causes a
  986. compilation error. The default is the largest number a PCRE2_SIZE variable can
  987. hold (essentially unlimited).
  988. .
  989. .
  990. .\" HTML <a name="posixwrapper"></a>
  991. .SS "Using the POSIX wrapper API"
  992. .rs
  993. .sp
  994. The \fBposix\fP and \fBposix_nosub\fP modifiers cause \fBpcre2test\fP to call
  995. PCRE2 via the POSIX wrapper API rather than its native API. When
  996. \fBposix_nosub\fP is used, the POSIX option REG_NOSUB is passed to
  997. \fBregcomp()\fP. The POSIX wrapper supports only the 8-bit library. Note that
  998. it does not imply POSIX matching semantics; for more detail see the
  999. .\" HREF
  1000. \fBpcre2posix\fP
  1001. .\"
  1002. documentation. The following pattern modifiers set options for the
  1003. \fBregcomp()\fP function:
  1004. .sp
  1005. caseless REG_ICASE
  1006. multiline REG_NEWLINE
  1007. dotall REG_DOTALL )
  1008. ungreedy REG_UNGREEDY ) These options are not part of
  1009. ucp REG_UCP ) the POSIX standard
  1010. utf REG_UTF8 )
  1011. .sp
  1012. The \fBregerror_buffsize\fP modifier specifies a size for the error buffer that
  1013. is passed to \fBregerror()\fP in the event of a compilation error. For example:
  1014. .sp
  1015. /abc/posix,regerror_buffsize=20
  1016. .sp
  1017. This provides a means of testing the behaviour of \fBregerror()\fP when the
  1018. buffer is too small for the error message. If this modifier has not been set, a
  1019. large buffer is used.
  1020. .P
  1021. The \fBaftertext\fP and \fBallaftertext\fP subject modifiers work as described
  1022. below. All other modifiers are either ignored, with a warning message, or cause
  1023. an error.
  1024. .P
  1025. The pattern is passed to \fBregcomp()\fP as a zero-terminated string by
  1026. default, but if the \fBuse_length\fP or \fBhex\fP modifiers are set, the
  1027. REG_PEND extension is used to pass it by length.
  1028. .
  1029. .
  1030. .SS "Testing the stack guard feature"
  1031. .rs
  1032. .sp
  1033. The \fBstackguard\fP modifier is used to test the use of
  1034. \fBpcre2_set_compile_recursion_guard()\fP, a function that is provided to
  1035. enable stack availability to be checked during compilation (see the
  1036. .\" HREF
  1037. \fBpcre2api\fP
  1038. .\"
  1039. documentation for details). If the number specified by the modifier is greater
  1040. than zero, \fBpcre2_set_compile_recursion_guard()\fP is called to set up
  1041. callback from \fBpcre2_compile()\fP to a local function. The argument it
  1042. receives is the current nesting parenthesis depth; if this is greater than the
  1043. value given by the modifier, non-zero is returned, causing the compilation to
  1044. be aborted.
  1045. .
  1046. .
  1047. .SS "Using alternative character tables"
  1048. .rs
  1049. .sp
  1050. The value specified for the \fBtables\fP modifier must be one of the digits 0,
  1051. 1, 2, or 3. It causes a specific set of built-in character tables to be passed
  1052. to \fBpcre2_compile()\fP. This is used in the PCRE2 tests to check behaviour
  1053. with different character tables. The digit specifies the tables as follows:
  1054. .sp
  1055. 0 do not pass any special character tables
  1056. 1 the default ASCII tables, as distributed in
  1057. pcre2_chartables.c.dist
  1058. 2 a set of tables defining ISO 8859 characters
  1059. 3 a set of tables loaded by the #loadtables command
  1060. .sp
  1061. In tables 2, some characters whose codes are greater than 128 are identified as
  1062. letters, digits, spaces, etc. Tables 3 can be used only after a
  1063. \fB#loadtables\fP command has loaded them from a binary file. Setting alternate
  1064. character tables and a locale are mutually exclusive.
  1065. .
  1066. .
  1067. .SS "Setting certain match controls"
  1068. .rs
  1069. .sp
  1070. The following modifiers are really subject modifiers, and are described under
  1071. "Subject Modifiers" below. However, they may be included in a pattern's
  1072. modifier list, in which case they are applied to every subject line that is
  1073. processed with that pattern. These modifiers do not affect the compilation
  1074. process.
  1075. .sp
  1076. aftertext show text after match
  1077. allaftertext show text after captures
  1078. allcaptures show all captures
  1079. allvector show the entire ovector
  1080. allusedtext show all consulted text
  1081. altglobal alternative global matching
  1082. /g global global matching
  1083. heapframes_size show match data heapframes size
  1084. jitstack=<n> set size of JIT stack
  1085. mark show mark values
  1086. replace=<string> specify a replacement string
  1087. startchar show starting character when relevant
  1088. substitute_callout use substitution callouts
  1089. substitute_extended use PCRE2_SUBSTITUTE_EXTENDED
  1090. substitute_literal use PCRE2_SUBSTITUTE_LITERAL
  1091. substitute_matched use PCRE2_SUBSTITUTE_MATCHED
  1092. substitute_overflow_length use PCRE2_SUBSTITUTE_OVERFLOW_LENGTH
  1093. substitute_replacement_only use PCRE2_SUBSTITUTE_REPLACEMENT_ONLY
  1094. substitute_skip=<n> skip substitution <n>
  1095. substitute_stop=<n> skip substitution <n> and following
  1096. substitute_unknown_unset use PCRE2_SUBSTITUTE_UNKNOWN_UNSET
  1097. substitute_unset_empty use PCRE2_SUBSTITUTE_UNSET_EMPTY
  1098. .sp
  1099. These modifiers may not appear in a \fB#pattern\fP command. If you want them as
  1100. defaults, set them in a \fB#subject\fP command.
  1101. .
  1102. .
  1103. .SS "Specifying literal subject lines"
  1104. .rs
  1105. .sp
  1106. If the \fBsubject_literal\fP modifier is present on a pattern, all the subject
  1107. lines that it matches are taken as literal strings, with no interpretation of
  1108. backslashes. It is not possible to set subject modifiers on such lines, but any
  1109. that are set as defaults by a \fB#subject\fP command are recognized.
  1110. .
  1111. .
  1112. .SS "Saving a compiled pattern"
  1113. .rs
  1114. .sp
  1115. When a pattern with the \fBpush\fP modifier is successfully compiled, it is
  1116. pushed onto a stack of compiled patterns, and \fBpcre2test\fP expects the next
  1117. line to contain a new pattern (or a command) instead of a subject line. This
  1118. facility is used when saving compiled patterns to a file, as described in the
  1119. section entitled "Saving and restoring compiled patterns"
  1120. .\" HTML <a href="#saverestore">
  1121. .\" </a>
  1122. below.
  1123. .\"
  1124. If \fBpushcopy\fP is used instead of \fBpush\fP, a copy of the compiled
  1125. pattern is stacked, leaving the original as current, ready to match the
  1126. following input lines. This provides a way of testing the
  1127. \fBpcre2_code_copy()\fP function.
  1128. .\"
  1129. The \fBpush\fP and \fBpushcopy \fP modifiers are incompatible with compilation
  1130. modifiers such as \fBglobal\fP that act at match time. Any that are specified
  1131. are ignored (for the stacked copy), with a warning message, except for
  1132. \fBreplace\fP, which causes an error. Note that \fBjitverify\fP, which is
  1133. allowed, does not carry through to any subsequent matching that uses a stacked
  1134. pattern.
  1135. .
  1136. .
  1137. .SS "Testing foreign pattern conversion"
  1138. .rs
  1139. .sp
  1140. The experimental foreign pattern conversion functions in PCRE2 can be tested by
  1141. setting the \fBconvert\fP modifier. Its argument is a colon-separated list of
  1142. options, which set the equivalent option for the \fBpcre2_pattern_convert()\fP
  1143. function:
  1144. .sp
  1145. glob PCRE2_CONVERT_GLOB
  1146. glob_no_starstar PCRE2_CONVERT_GLOB_NO_STARSTAR
  1147. glob_no_wild_separator PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR
  1148. posix_basic PCRE2_CONVERT_POSIX_BASIC
  1149. posix_extended PCRE2_CONVERT_POSIX_EXTENDED
  1150. unset Unset all options
  1151. .sp
  1152. The "unset" value is useful for turning off a default that has been set by a
  1153. \fB#pattern\fP command. When one of these options is set, the input pattern is
  1154. passed to \fBpcre2_pattern_convert()\fP. If the conversion is successful, the
  1155. result is reflected in the output and then passed to \fBpcre2_compile()\fP. The
  1156. normal \fButf\fP and \fBno_utf_check\fP options, if set, cause the
  1157. PCRE2_CONVERT_UTF and PCRE2_CONVERT_NO_UTF_CHECK options to be passed to
  1158. \fBpcre2_pattern_convert()\fP.
  1159. .P
  1160. By default, the conversion function is allowed to allocate a buffer for its
  1161. output. However, if the \fBconvert_length\fP modifier is set to a value greater
  1162. than zero, \fBpcre2test\fP passes a buffer of the given length. This makes it
  1163. possible to test the length check.
  1164. .P
  1165. The \fBconvert_glob_escape\fP and \fBconvert_glob_separator\fP modifiers can be
  1166. used to specify the escape and separator characters for glob processing,
  1167. overriding the defaults, which are operating-system dependent.
  1168. .
  1169. .
  1170. .\" HTML <a name="subjectmodifiers"></a>
  1171. .SH "SUBJECT MODIFIERS"
  1172. .rs
  1173. .sp
  1174. The modifiers that can appear in subject lines and the \fB#subject\fP
  1175. command are of two types.
  1176. .
  1177. .
  1178. .SS "Setting match options"
  1179. .rs
  1180. .sp
  1181. The following modifiers set options for \fBpcre2_match()\fP or
  1182. \fBpcre2_dfa_match()\fP. See
  1183. .\" HREF
  1184. \fBpcreapi\fP
  1185. .\"
  1186. for a description of their effects.
  1187. .sp
  1188. anchored set PCRE2_ANCHORED
  1189. endanchored set PCRE2_ENDANCHORED
  1190. dfa_restart set PCRE2_DFA_RESTART
  1191. dfa_shortest set PCRE2_DFA_SHORTEST
  1192. disable_recurseloop_check set PCRE2_DISABLE_RECURSELOOP_CHECK
  1193. no_jit set PCRE2_NO_JIT
  1194. no_utf_check set PCRE2_NO_UTF_CHECK
  1195. notbol set PCRE2_NOTBOL
  1196. notempty set PCRE2_NOTEMPTY
  1197. notempty_atstart set PCRE2_NOTEMPTY_ATSTART
  1198. noteol set PCRE2_NOTEOL
  1199. partial_hard (or ph) set PCRE2_PARTIAL_HARD
  1200. partial_soft (or ps) set PCRE2_PARTIAL_SOFT
  1201. .sp
  1202. The partial matching modifiers are provided with abbreviations because they
  1203. appear frequently in tests.
  1204. .P
  1205. If the \fBposix\fP or \fBposix_nosub\fP modifier was present on the pattern,
  1206. causing the POSIX wrapper API to be used, the only option-setting modifiers
  1207. that have any effect are \fBnotbol\fP, \fBnotempty\fP, and \fBnoteol\fP,
  1208. causing REG_NOTBOL, REG_NOTEMPTY, and REG_NOTEOL, respectively, to be passed to
  1209. \fBregexec()\fP. The other modifiers are ignored, with a warning message.
  1210. .P
  1211. There is one additional modifier that can be used with the POSIX wrapper. It is
  1212. ignored (with a warning) if used for non-POSIX matching.
  1213. .sp
  1214. posix_startend=<n>[:<m>]
  1215. .sp
  1216. This causes the subject string to be passed to \fBregexec()\fP using the
  1217. REG_STARTEND option, which uses offsets to specify which part of the string is
  1218. searched. If only one number is given, the end offset is passed as the end of
  1219. the subject string. For more detail of REG_STARTEND, see the
  1220. .\" HREF
  1221. \fBpcre2posix\fP
  1222. .\"
  1223. documentation. If the subject string contains binary zeros (coded as escapes
  1224. such as \ex{00} because \fBpcre2test\fP does not support actual binary zeros in
  1225. its input), you must use \fBposix_startend\fP to specify its length.
  1226. .
  1227. .
  1228. .SS "Setting match controls"
  1229. .rs
  1230. .sp
  1231. The following modifiers affect the matching process or request additional
  1232. information. Some of them may also be specified on a pattern line (see above),
  1233. in which case they apply to every subject line that is matched against that
  1234. pattern, but can be overridden by modifiers on the subject.
  1235. .sp
  1236. aftertext show text after match
  1237. allaftertext show text after captures
  1238. allcaptures show all captures
  1239. allvector show the entire ovector
  1240. allusedtext show all consulted text (non-JIT only)
  1241. altglobal alternative global matching
  1242. callout_capture show captures at callout time
  1243. callout_data=<n> set a value to pass via callouts
  1244. callout_error=<n>[:<m>] control callout error
  1245. callout_extra show extra callout information
  1246. callout_fail=<n>[:<m>] control callout failure
  1247. callout_no_where do not show position of a callout
  1248. callout_none do not supply a callout function
  1249. copy=<number or name> copy captured substring
  1250. depth_limit=<n> set a depth limit
  1251. dfa use \fBpcre2_dfa_match()\fP
  1252. find_limits find heap, match and depth limits
  1253. find_limits_noheap find match and depth limits
  1254. get=<number or name> extract captured substring
  1255. getall extract all captured substrings
  1256. /g global global matching
  1257. heapframes_size show match data heapframes size
  1258. heap_limit=<n> set a limit on heap memory (Kbytes)
  1259. jitstack=<n> set size of JIT stack
  1260. mark show mark values
  1261. match_limit=<n> set a match limit
  1262. memory show heap memory usage
  1263. null_context match with a NULL context
  1264. null_replacement substitute with NULL replacement
  1265. null_subject match with NULL subject
  1266. offset=<n> set starting offset
  1267. offset_limit=<n> set offset limit
  1268. ovector=<n> set size of output vector
  1269. recursion_limit=<n> obsolete synonym for depth_limit
  1270. replace=<string> specify a replacement string
  1271. startchar show startchar when relevant
  1272. startoffset=<n> same as offset=<n>
  1273. substitute_callout use substitution callouts
  1274. substitute_extedded use PCRE2_SUBSTITUTE_EXTENDED
  1275. substitute_literal use PCRE2_SUBSTITUTE_LITERAL
  1276. substitute_matched use PCRE2_SUBSTITUTE_MATCHED
  1277. substitute_overflow_length use PCRE2_SUBSTITUTE_OVERFLOW_LENGTH
  1278. substitute_replacement_only use PCRE2_SUBSTITUTE_REPLACEMENT_ONLY
  1279. substitute_skip=<n> skip substitution number n
  1280. substitute_stop=<n> skip substitution number n and greater
  1281. substitute_unknown_unset use PCRE2_SUBSTITUTE_UNKNOWN_UNSET
  1282. substitute_unset_empty use PCRE2_SUBSTITUTE_UNSET_EMPTY
  1283. zero_terminate pass the subject as zero-terminated
  1284. .sp
  1285. The effects of these modifiers are described in the following sections. When
  1286. matching via the POSIX wrapper API, the \fBaftertext\fP, \fBallaftertext\fP,
  1287. and \fBovector\fP subject modifiers work as described below. All other
  1288. modifiers are either ignored, with a warning message, or cause an error.
  1289. .
  1290. .
  1291. .SS "Showing more text"
  1292. .rs
  1293. .sp
  1294. The \fBaftertext\fP modifier requests that as well as outputting the part of
  1295. the subject string that matched the entire pattern, \fBpcre2test\fP should in
  1296. addition output the remainder of the subject string. This is useful for tests
  1297. where the subject contains multiple copies of the same substring. The
  1298. \fBallaftertext\fP modifier requests the same action for captured substrings as
  1299. well as the main matched substring. In each case the remainder is output on the
  1300. following line with a plus character following the capture number.
  1301. .P
  1302. The \fBallusedtext\fP modifier requests that all the text that was consulted
  1303. during a successful pattern match by the interpreter should be shown, for both
  1304. full and partial matches. This feature is not supported for JIT matching, and
  1305. if requested with JIT it is ignored (with a warning message). Setting this
  1306. modifier affects the output if there is a lookbehind at the start of a match,
  1307. or, for a complete match, a lookahead at the end, or if \eK is used in the
  1308. pattern. Characters that precede or follow the start and end of the actual
  1309. match are indicated in the output by '<' or '>' characters underneath them.
  1310. Here is an example:
  1311. .sp
  1312. re> /(?<=pqr)abc(?=xyz)/
  1313. data> 123pqrabcxyz456\e=allusedtext
  1314. 0: pqrabcxyz
  1315. <<< >>>
  1316. data> 123pqrabcxy\e=ph,allusedtext
  1317. Partial match: pqrabcxy
  1318. <<<
  1319. .sp
  1320. The first, complete match shows that the matched string is "abc", with the
  1321. preceding and following strings "pqr" and "xyz" having been consulted during
  1322. the match (when processing the assertions). The partial match can indicate only
  1323. the preceding string.
  1324. .P
  1325. The \fBstartchar\fP modifier requests that the starting character for the match
  1326. be indicated, if it is different to the start of the matched string. The only
  1327. time when this occurs is when \eK has been processed as part of the match. In
  1328. this situation, the output for the matched string is displayed from the
  1329. starting character instead of from the match point, with circumflex characters
  1330. under the earlier characters. For example:
  1331. .sp
  1332. re> /abc\eKxyz/
  1333. data> abcxyz\e=startchar
  1334. 0: abcxyz
  1335. ^^^
  1336. .sp
  1337. Unlike \fBallusedtext\fP, the \fBstartchar\fP modifier can be used with JIT.
  1338. However, these two modifiers are mutually exclusive.
  1339. .
  1340. .
  1341. .SS "Showing the value of all capture groups"
  1342. .rs
  1343. .sp
  1344. The \fBallcaptures\fP modifier requests that the values of all potential
  1345. captured parentheses be output after a match. By default, only those up to the
  1346. highest one actually used in the match are output (corresponding to the return
  1347. code from \fBpcre2_match()\fP). Groups that did not take part in the match
  1348. are output as "<unset>". This modifier is not relevant for DFA matching (which
  1349. does no capturing) and does not apply when \fBreplace\fP is specified; it is
  1350. ignored, with a warning message, if present.
  1351. .
  1352. .
  1353. .SS "Showing the entire ovector, for all outcomes"
  1354. .rs
  1355. .sp
  1356. The \fBallvector\fP modifier requests that the entire ovector be shown,
  1357. whatever the outcome of the match. Compare \fBallcaptures\fP, which shows only
  1358. up to the maximum number of capture groups for the pattern, and then only for a
  1359. successful complete non-DFA match. This modifier, which acts after any match
  1360. result, and also for DFA matching, provides a means of checking that there are
  1361. no unexpected modifications to ovector fields. Before each match attempt, the
  1362. ovector is filled with a special value, and if this is found in both elements
  1363. of a capturing pair, "<unchanged>" is output. After a successful match, this
  1364. applies to all groups after the maximum capture group for the pattern. In other
  1365. cases it applies to the entire ovector. After a partial match, the first two
  1366. elements are the only ones that should be set. After a DFA match, the amount of
  1367. ovector that is used depends on the number of matches that were found.
  1368. .
  1369. .
  1370. .SS "Testing pattern callouts"
  1371. .rs
  1372. .sp
  1373. A callout function is supplied when \fBpcre2test\fP calls the library matching
  1374. functions, unless \fBcallout_none\fP is specified. Its behaviour can be
  1375. controlled by various modifiers listed above whose names begin with
  1376. \fBcallout_\fP. Details are given in the section entitled "Callouts"
  1377. .\" HTML <a href="#callouts">
  1378. .\" </a>
  1379. below.
  1380. .\"
  1381. Testing callouts from \fBpcre2_substitute()\fP is described separately in
  1382. "Testing the substitution function"
  1383. .\" HTML <a href="#substitution">
  1384. .\" </a>
  1385. below.
  1386. .\"
  1387. .
  1388. .
  1389. .SS "Finding all matches in a string"
  1390. .rs
  1391. .sp
  1392. Searching for all possible matches within a subject can be requested by the
  1393. \fBglobal\fP or \fBaltglobal\fP modifier. After finding a match, the matching
  1394. function is called again to search the remainder of the subject. The difference
  1395. between \fBglobal\fP and \fBaltglobal\fP is that the former uses the
  1396. \fIstart_offset\fP argument to \fBpcre2_match()\fP or \fBpcre2_dfa_match()\fP
  1397. to start searching at a new point within the entire string (which is what Perl
  1398. does), whereas the latter passes over a shortened subject. This makes a
  1399. difference to the matching process if the pattern begins with a lookbehind
  1400. assertion (including \eb or \eB).
  1401. .P
  1402. If an empty string is matched, the next match is done with the
  1403. PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED flags set, in order to search for
  1404. another, non-empty, match at the same point in the subject. If this match
  1405. fails, the start offset is advanced, and the normal match is retried. This
  1406. imitates the way Perl handles such cases when using the \fB/g\fP modifier or
  1407. the \fBsplit()\fP function. Normally, the start offset is advanced by one
  1408. character, but if the newline convention recognizes CRLF as a newline, and the
  1409. current character is CR followed by LF, an advance of two characters occurs.
  1410. .
  1411. .
  1412. .SS "Testing substring extraction functions"
  1413. .rs
  1414. .sp
  1415. The \fBcopy\fP and \fBget\fP modifiers can be used to test the
  1416. \fBpcre2_substring_copy_xxx()\fP and \fBpcre2_substring_get_xxx()\fP functions.
  1417. They can be given more than once, and each can specify a capture group name or
  1418. number, for example:
  1419. .sp
  1420. abcd\e=copy=1,copy=3,get=G1
  1421. .sp
  1422. If the \fB#subject\fP command is used to set default copy and/or get lists,
  1423. these can be unset by specifying a negative number to cancel all numbered
  1424. groups and an empty name to cancel all named groups.
  1425. .P
  1426. The \fBgetall\fP modifier tests \fBpcre2_substring_list_get()\fP, which
  1427. extracts all captured substrings.
  1428. .P
  1429. If the subject line is successfully matched, the substrings extracted by the
  1430. convenience functions are output with C, G, or L after the string number
  1431. instead of a colon. This is in addition to the normal full list. The string
  1432. length (that is, the return from the extraction function) is given in
  1433. parentheses after each substring, followed by the name when the extraction was
  1434. by name.
  1435. .
  1436. .
  1437. .\" HTML <a name="substitution"></a>
  1438. .SS "Testing the substitution function"
  1439. .rs
  1440. .sp
  1441. If the \fBreplace\fP modifier is set, the \fBpcre2_substitute()\fP function is
  1442. called instead of one of the matching functions (or after one call of
  1443. \fBpcre2_match()\fP in the case of PCRE2_SUBSTITUTE_MATCHED). Note that
  1444. replacement strings cannot contain commas, because a comma signifies the end of
  1445. a modifier. This is not thought to be an issue in a test program.
  1446. .P
  1447. Specifying a completely empty replacement string disables this modifier.
  1448. However, it is possible to specify an empty replacement by providing a buffer
  1449. length, as described below, for an otherwise empty replacement.
  1450. .P
  1451. Unlike subject strings, \fBpcre2test\fP does not process replacement strings
  1452. for escape sequences. In UTF mode, a replacement string is checked to see if it
  1453. is a valid UTF-8 string. If so, it is correctly converted to a UTF string of
  1454. the appropriate code unit width. If it is not a valid UTF-8 string, the
  1455. individual code units are copied directly. This provides a means of passing an
  1456. invalid UTF-8 string for testing purposes.
  1457. .P
  1458. The following modifiers set options (in additional to the normal match options)
  1459. for \fBpcre2_substitute()\fP:
  1460. .sp
  1461. global PCRE2_SUBSTITUTE_GLOBAL
  1462. substitute_extended PCRE2_SUBSTITUTE_EXTENDED
  1463. substitute_literal PCRE2_SUBSTITUTE_LITERAL
  1464. substitute_matched PCRE2_SUBSTITUTE_MATCHED
  1465. substitute_overflow_length PCRE2_SUBSTITUTE_OVERFLOW_LENGTH
  1466. substitute_replacement_only PCRE2_SUBSTITUTE_REPLACEMENT_ONLY
  1467. substitute_unknown_unset PCRE2_SUBSTITUTE_UNKNOWN_UNSET
  1468. substitute_unset_empty PCRE2_SUBSTITUTE_UNSET_EMPTY
  1469. .sp
  1470. See the
  1471. .\" HREF
  1472. \fBpcre2api\fP
  1473. .\"
  1474. documentation for details of these options.
  1475. .P
  1476. After a successful substitution, the modified string is output, preceded by the
  1477. number of replacements. This may be zero if there were no matches. Here is a
  1478. simple example of a substitution test:
  1479. .sp
  1480. /abc/replace=xxx
  1481. =abc=abc=
  1482. 1: =xxx=abc=
  1483. =abc=abc=\e=global
  1484. 2: =xxx=xxx=
  1485. .sp
  1486. Subject and replacement strings should be kept relatively short (fewer than 256
  1487. characters) for substitution tests, as fixed-size buffers are used. To make it
  1488. easy to test for buffer overflow, if the replacement string starts with a
  1489. number in square brackets, that number is passed to \fBpcre2_substitute()\fP as
  1490. the size of the output buffer, with the replacement string starting at the next
  1491. character. Here is an example that tests the edge case:
  1492. .sp
  1493. /abc/
  1494. 123abc123\e=replace=[10]XYZ
  1495. 1: 123XYZ123
  1496. 123abc123\e=replace=[9]XYZ
  1497. Failed: error -47: no more memory
  1498. .sp
  1499. The default action of \fBpcre2_substitute()\fP is to return
  1500. PCRE2_ERROR_NOMEMORY when the output buffer is too small. However, if the
  1501. PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option is set (by using the
  1502. \fBsubstitute_overflow_length\fP modifier), \fBpcre2_substitute()\fP continues
  1503. to go through the motions of matching and substituting (but not doing any
  1504. callouts), in order to compute the size of buffer that is required. When this
  1505. happens, \fBpcre2test\fP shows the required buffer length (which includes space
  1506. for the trailing zero) as part of the error message. For example:
  1507. .sp
  1508. /abc/substitute_overflow_length
  1509. 123abc123\e=replace=[9]XYZ
  1510. Failed: error -47: no more memory: 10 code units are needed
  1511. .sp
  1512. A replacement string is ignored with POSIX and DFA matching. Specifying partial
  1513. matching provokes an error return ("bad option value") from
  1514. \fBpcre2_substitute()\fP.
  1515. .
  1516. .
  1517. .SS "Testing substitute callouts"
  1518. .rs
  1519. .sp
  1520. If the \fBsubstitute_callout\fP modifier is set, a substitution callout
  1521. function is set up. The \fBnull_context\fP modifier must not be set, because
  1522. the address of the callout function is passed in a match context. When the
  1523. callout function is called (after each substitution), details of the input
  1524. and output strings are output. For example:
  1525. .sp
  1526. /abc/g,replace=<$0>,substitute_callout
  1527. abcdefabcpqr
  1528. 1(1) Old 0 3 "abc" New 0 5 "<abc>"
  1529. 2(1) Old 6 9 "abc" New 8 13 "<abc>"
  1530. 2: <abc>def<abc>pqr
  1531. .sp
  1532. The first number on each callout line is the count of matches. The
  1533. parenthesized number is the number of pairs that are set in the ovector (that
  1534. is, one more than the number of capturing groups that were set). Then are
  1535. listed the offsets of the old substring, its contents, and the same for the
  1536. replacement.
  1537. .P
  1538. By default, the substitution callout function returns zero, which accepts the
  1539. replacement and causes matching to continue if /g was used. Two further
  1540. modifiers can be used to test other return values. If \fBsubstitute_skip\fP is
  1541. set to a value greater than zero the callout function returns +1 for the match
  1542. of that number, and similarly \fBsubstitute_stop\fP returns -1. These cause the
  1543. replacement to be rejected, and -1 causes no further matching to take place. If
  1544. either of them are set, \fBsubstitute_callout\fP is assumed. For example:
  1545. .sp
  1546. /abc/g,replace=<$0>,substitute_skip=1
  1547. abcdefabcpqr
  1548. 1(1) Old 0 3 "abc" New 0 5 "<abc> SKIPPED"
  1549. 2(1) Old 6 9 "abc" New 6 11 "<abc>"
  1550. 2: abcdef<abc>pqr
  1551. abcdefabcpqr\e=substitute_stop=1
  1552. 1(1) Old 0 3 "abc" New 0 5 "<abc> STOPPED"
  1553. 1: abcdefabcpqr
  1554. .sp
  1555. If both are set for the same number, stop takes precedence. Only a single skip
  1556. or stop is supported, which is sufficient for testing that the feature works.
  1557. .
  1558. .
  1559. .SS "Setting the JIT stack size"
  1560. .rs
  1561. .sp
  1562. The \fBjitstack\fP modifier provides a way of setting the maximum stack size
  1563. that is used by the just-in-time optimization code. It is ignored if JIT
  1564. optimization is not being used. The value is a number of kibibytes (units of
  1565. 1024 bytes). Setting zero reverts to the default of 32KiB. Providing a stack
  1566. that is larger than the default is necessary only for very complicated
  1567. patterns. If \fBjitstack\fP is set non-zero on a subject line it overrides any
  1568. value that was set on the pattern.
  1569. .
  1570. .
  1571. .SS "Setting heap, match, and depth limits"
  1572. .rs
  1573. .sp
  1574. The \fBheap_limit\fP, \fBmatch_limit\fP, and \fBdepth_limit\fP modifiers set
  1575. the appropriate limits in the match context. These values are ignored when the
  1576. \fBfind_limits\fP or \fBfind_limits_noheap\fP modifier is specified.
  1577. .
  1578. .
  1579. .SS "Finding minimum limits"
  1580. .rs
  1581. .sp
  1582. If the \fBfind_limits\fP modifier is present on a subject line, \fBpcre2test\fP
  1583. calls the relevant matching function several times, setting different values in
  1584. the match context via \fBpcre2_set_heap_limit()\fP,
  1585. \fBpcre2_set_match_limit()\fP, or \fBpcre2_set_depth_limit()\fP until it finds
  1586. the smallest value for each parameter that allows the match to complete without
  1587. a "limit exceeded" error. The match itself may succeed or fail. An alternative
  1588. modifier, \fBfind_limits_noheap\fP, omits the heap limit. This is used in the
  1589. standard tests, because the minimum heap limit varies between systems. If JIT
  1590. is being used, only the match limit is relevant, and the other two are
  1591. automatically omitted.
  1592. .P
  1593. When using this modifier, the pattern should not contain any limit settings
  1594. such as (*LIMIT_MATCH=...) within it. If such a setting is present and is
  1595. lower than the minimum matching value, the minimum value cannot be found
  1596. because \fBpcre2_set_match_limit()\fP etc. are only able to reduce the value of
  1597. an in-pattern limit; they cannot increase it.
  1598. .P
  1599. For non-DFA matching, the minimum \fIdepth_limit\fP number is a measure of how
  1600. much nested backtracking happens (that is, how deeply the pattern's tree is
  1601. searched). In the case of DFA matching, \fIdepth_limit\fP controls the depth of
  1602. recursive calls of the internal function that is used for handling pattern
  1603. recursion, lookaround assertions, and atomic groups.
  1604. .P
  1605. For non-DFA matching, the \fImatch_limit\fP number is a measure of the amount
  1606. of backtracking that takes place, and learning the minimum value can be
  1607. instructive. For most simple matches, the number is quite small, but for
  1608. patterns with very large numbers of matching possibilities, it can become large
  1609. very quickly with increasing length of subject string. In the case of DFA
  1610. matching, \fImatch_limit\fP controls the total number of calls, both recursive
  1611. and non-recursive, to the internal matching function, thus controlling the
  1612. overall amount of computing resource that is used.
  1613. .P
  1614. For both kinds of matching, the \fIheap_limit\fP number, which is in kibibytes
  1615. (units of 1024 bytes), limits the amount of heap memory used for matching.
  1616. .
  1617. .
  1618. .SS "Showing MARK names"
  1619. .rs
  1620. .sp
  1621. .P
  1622. The \fBmark\fP modifier causes the names from backtracking control verbs that
  1623. are returned from calls to \fBpcre2_match()\fP to be displayed. If a mark is
  1624. returned for a match, non-match, or partial match, \fBpcre2test\fP shows it.
  1625. For a match, it is on a line by itself, tagged with "MK:". Otherwise, it
  1626. is added to the non-match message.
  1627. .
  1628. .
  1629. .SS "Showing memory usage"
  1630. .rs
  1631. .sp
  1632. The \fBmemory\fP modifier causes \fBpcre2test\fP to log the sizes of all heap
  1633. memory allocation and freeing calls that occur during a call to
  1634. \fBpcre2_match()\fP or \fBpcre2_dfa_match()\fP. In the latter case, heap memory
  1635. is used only when a match requires more internal workspace that the default
  1636. allocation on the stack, so in many cases there will be no output. No heap
  1637. memory is allocated during matching with JIT. For this modifier to work, the
  1638. \fBnull_context\fP modifier must not be set on both the pattern and the
  1639. subject, though it can be set on one or the other.
  1640. .
  1641. .
  1642. .SS "Showing the heap frame overall vector size"
  1643. .rs
  1644. .sp
  1645. The \fBheapframes_size\fP modifier is relevant for matches using
  1646. \fBpcre2_match()\fP without JIT. After a match has run (whether successful or
  1647. not) the size, in bytes, of the allocated heap frames vector that is left
  1648. attached to the match data block is shown. If the matching action involved
  1649. several calls to \fBpcre2_match()\fP (for example, global matching or for
  1650. timing) only the final value is shown.
  1651. .P
  1652. This modifier is ignored, with a warning, for POSIX or DFA matching. JIT
  1653. matching does not use the heap frames vector, so the size is always zero,
  1654. unless there was a previous non-JIT match. Note that specifing a size of zero
  1655. for the output vector (see below) causes \fBpcre2test\fP to free its match data
  1656. block (and associated heap frames vector) and allocate a new one.
  1657. .
  1658. .
  1659. .SS "Setting a starting offset"
  1660. .rs
  1661. .sp
  1662. The \fBoffset\fP modifier sets an offset in the subject string at which
  1663. matching starts. Its value is a number of code units, not characters.
  1664. .
  1665. .
  1666. .SS "Setting an offset limit"
  1667. .rs
  1668. .sp
  1669. The \fBoffset_limit\fP modifier sets a limit for unanchored matches. If a match
  1670. cannot be found starting at or before this offset in the subject, a "no match"
  1671. return is given. The data value is a number of code units, not characters. When
  1672. this modifier is used, the \fBuse_offset_limit\fP modifier must have been set
  1673. for the pattern; if not, an error is generated.
  1674. .
  1675. .
  1676. .SS "Setting the size of the output vector"
  1677. .rs
  1678. .sp
  1679. The \fBovector\fP modifier applies only to the subject line in which it
  1680. appears, though of course it can also be used to set a default in a
  1681. \fB#subject\fP command. It specifies the number of pairs of offsets that are
  1682. available for storing matching information. The default is 15.
  1683. .P
  1684. A value of zero is useful when testing the POSIX API because it causes
  1685. \fBregexec()\fP to be called with a NULL capture vector. When not testing the
  1686. POSIX API, a value of zero is used to cause
  1687. \fBpcre2_match_data_create_from_pattern()\fP to be called, in order to create a
  1688. new match block of exactly the right size for the pattern. (It is not possible
  1689. to create a match block with a zero-length ovector; there is always at least
  1690. one pair of offsets.) The old match data block is freed.
  1691. .
  1692. .
  1693. .SS "Passing the subject as zero-terminated"
  1694. .rs
  1695. .sp
  1696. By default, the subject string is passed to a native API matching function with
  1697. its correct length. In order to test the facility for passing a zero-terminated
  1698. string, the \fBzero_terminate\fP modifier is provided. It causes the length to
  1699. be passed as PCRE2_ZERO_TERMINATED. When matching via the POSIX interface,
  1700. this modifier is ignored, with a warning.
  1701. .P
  1702. When testing \fBpcre2_substitute()\fP, this modifier also has the effect of
  1703. passing the replacement string as zero-terminated.
  1704. .
  1705. .
  1706. .SS "Passing a NULL context, subject, or replacement"
  1707. .rs
  1708. .sp
  1709. Normally, \fBpcre2test\fP passes a context block to \fBpcre2_match()\fP,
  1710. \fBpcre2_dfa_match()\fP, \fBpcre2_jit_match()\fP or \fBpcre2_substitute()\fP.
  1711. If the \fBnull_context\fP modifier is set, however, NULL is passed. This is for
  1712. testing that the matching and substitution functions behave correctly in this
  1713. case (they use default values). This modifier cannot be used with the
  1714. \fBfind_limits\fP, \fBfind_limits_noheap\fP, or \fBsubstitute_callout\fP
  1715. modifiers.
  1716. .P
  1717. Similarly, for testing purposes, if the \fBnull_subject\fP or
  1718. \fBnull_replacement\fP modifier is set, the subject or replacement string
  1719. pointers are passed as NULL, respectively, to the relevant functions.
  1720. .
  1721. .
  1722. .SH "THE ALTERNATIVE MATCHING FUNCTION"
  1723. .rs
  1724. .sp
  1725. By default, \fBpcre2test\fP uses the standard PCRE2 matching function,
  1726. \fBpcre2_match()\fP to match each subject line. PCRE2 also supports an
  1727. alternative matching function, \fBpcre2_dfa_match()\fP, which operates in a
  1728. different way, and has some restrictions. The differences between the two
  1729. functions are described in the
  1730. .\" HREF
  1731. \fBpcre2matching\fP
  1732. .\"
  1733. documentation.
  1734. .P
  1735. If the \fBdfa\fP modifier is set, the alternative matching function is used.
  1736. This function finds all possible matches at a given point in the subject. If,
  1737. however, the \fBdfa_shortest\fP modifier is set, processing stops after the
  1738. first match is found. This is always the shortest possible match.
  1739. .
  1740. .
  1741. .SH "DEFAULT OUTPUT FROM pcre2test"
  1742. .rs
  1743. .sp
  1744. This section describes the output when the normal matching function,
  1745. \fBpcre2_match()\fP, is being used.
  1746. .P
  1747. When a match succeeds, \fBpcre2test\fP outputs the list of captured substrings,
  1748. starting with number 0 for the string that matched the whole pattern.
  1749. Otherwise, it outputs "No match" when the return is PCRE2_ERROR_NOMATCH, or
  1750. "Partial match:" followed by the partially matching substring when the
  1751. return is PCRE2_ERROR_PARTIAL. (Note that this is the
  1752. entire substring that was inspected during the partial match; it may include
  1753. characters before the actual match start if a lookbehind assertion, \eK, \eb,
  1754. or \eB was involved.)
  1755. .P
  1756. For any other return, \fBpcre2test\fP outputs the PCRE2 negative error number
  1757. and a short descriptive phrase. If the error is a failed UTF string check, the
  1758. code unit offset of the start of the failing character is also output. Here is
  1759. an example of an interactive \fBpcre2test\fP run.
  1760. .sp
  1761. $ pcre2test
  1762. PCRE2 version 10.22 2016-07-29
  1763. .sp
  1764. re> /^abc(\ed+)/
  1765. data> abc123
  1766. 0: abc123
  1767. 1: 123
  1768. data> xyz
  1769. No match
  1770. .sp
  1771. Unset capturing substrings that are not followed by one that is set are not
  1772. shown by \fBpcre2test\fP unless the \fBallcaptures\fP modifier is specified. In
  1773. the following example, there are two capturing substrings, but when the first
  1774. data line is matched, the second, unset substring is not shown. An "internal"
  1775. unset substring is shown as "<unset>", as for the second data line.
  1776. .sp
  1777. re> /(a)|(b)/
  1778. data> a
  1779. 0: a
  1780. 1: a
  1781. data> b
  1782. 0: b
  1783. 1: <unset>
  1784. 2: b
  1785. .sp
  1786. If the strings contain any non-printing characters, they are output as \exhh
  1787. escapes if the value is less than 256 and UTF mode is not set. Otherwise they
  1788. are output as \ex{hh...} escapes. See below for the definition of non-printing
  1789. characters. If the \fBaftertext\fP modifier is set, the output for substring 0
  1790. is followed by the rest of the subject string, identified by "0+" like this:
  1791. .sp
  1792. re> /cat/aftertext
  1793. data> cataract
  1794. 0: cat
  1795. 0+ aract
  1796. .sp
  1797. If global matching is requested, the results of successive matching attempts
  1798. are output in sequence, like this:
  1799. .sp
  1800. re> /\eBi(\ew\ew)/g
  1801. data> Mississippi
  1802. 0: iss
  1803. 1: ss
  1804. 0: iss
  1805. 1: ss
  1806. 0: ipp
  1807. 1: pp
  1808. .sp
  1809. "No match" is output only if the first match attempt fails. Here is an example
  1810. of a failure message (the offset 4 that is specified by the \fBoffset\fP
  1811. modifier is past the end of the subject string):
  1812. .sp
  1813. re> /xyz/
  1814. data> xyz\e=offset=4
  1815. Error -24 (bad offset value)
  1816. .P
  1817. Note that whereas patterns can be continued over several lines (a plain ">"
  1818. prompt is used for continuations), subject lines may not. However newlines can
  1819. be included in a subject by means of the \en escape (or \er, \er\en, etc.,
  1820. depending on the newline sequence setting).
  1821. .
  1822. .
  1823. .
  1824. .SH "OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION"
  1825. .rs
  1826. .sp
  1827. When the alternative matching function, \fBpcre2_dfa_match()\fP, is used, the
  1828. output consists of a list of all the matches that start at the first point in
  1829. the subject where there is at least one match. For example:
  1830. .sp
  1831. re> /(tang|tangerine|tan)/
  1832. data> yellow tangerine\e=dfa
  1833. 0: tangerine
  1834. 1: tang
  1835. 2: tan
  1836. .sp
  1837. Using the normal matching function on this data finds only "tang". The
  1838. longest matching string is always given first (and numbered zero). After a
  1839. PCRE2_ERROR_PARTIAL return, the output is "Partial match:", followed by the
  1840. partially matching substring. Note that this is the entire substring that was
  1841. inspected during the partial match; it may include characters before the actual
  1842. match start if a lookbehind assertion, \eb, or \eB was involved. (\eK is not
  1843. supported for DFA matching.)
  1844. .P
  1845. If global matching is requested, the search for further matches resumes
  1846. at the end of the longest match. For example:
  1847. .sp
  1848. re> /(tang|tangerine|tan)/g
  1849. data> yellow tangerine and tangy sultana\e=dfa
  1850. 0: tangerine
  1851. 1: tang
  1852. 2: tan
  1853. 0: tang
  1854. 1: tan
  1855. 0: tan
  1856. .sp
  1857. The alternative matching function does not support substring capture, so the
  1858. modifiers that are concerned with captured substrings are not relevant.
  1859. .
  1860. .
  1861. .SH "RESTARTING AFTER A PARTIAL MATCH"
  1862. .rs
  1863. .sp
  1864. When the alternative matching function has given the PCRE2_ERROR_PARTIAL
  1865. return, indicating that the subject partially matched the pattern, you can
  1866. restart the match with additional subject data by means of the
  1867. \fBdfa_restart\fP modifier. For example:
  1868. .sp
  1869. re> /^\ed?\ed(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\ed\ed$/
  1870. data> 23ja\e=ps,dfa
  1871. Partial match: 23ja
  1872. data> n05\e=dfa,dfa_restart
  1873. 0: n05
  1874. .sp
  1875. For further information about partial matching, see the
  1876. .\" HREF
  1877. \fBpcre2partial\fP
  1878. .\"
  1879. documentation.
  1880. .
  1881. .
  1882. .\" HTML <a name="callouts"></a>
  1883. .SH CALLOUTS
  1884. .rs
  1885. .sp
  1886. If the pattern contains any callout requests, \fBpcre2test\fP's callout
  1887. function is called during matching unless \fBcallout_none\fP is specified. This
  1888. works with both matching functions, and with JIT, though there are some
  1889. differences in behaviour. The output for callouts with numerical arguments and
  1890. those with string arguments is slightly different.
  1891. .
  1892. .
  1893. .SS "Callouts with numerical arguments"
  1894. .rs
  1895. .sp
  1896. By default, the callout function displays the callout number, the start and
  1897. current positions in the subject text at the callout time, and the next pattern
  1898. item to be tested. For example:
  1899. .sp
  1900. --->pqrabcdef
  1901. 0 ^ ^ \ed
  1902. .sp
  1903. This output indicates that callout number 0 occurred for a match attempt
  1904. starting at the fourth character of the subject string, when the pointer was at
  1905. the seventh character, and when the next pattern item was \ed. Just
  1906. one circumflex is output if the start and current positions are the same, or if
  1907. the current position precedes the start position, which can happen if the
  1908. callout is in a lookbehind assertion.
  1909. .P
  1910. Callouts numbered 255 are assumed to be automatic callouts, inserted as a
  1911. result of the \fBauto_callout\fP pattern modifier. In this case, instead of
  1912. showing the callout number, the offset in the pattern, preceded by a plus, is
  1913. output. For example:
  1914. .sp
  1915. re> /\ed?[A-E]\e*/auto_callout
  1916. data> E*
  1917. --->E*
  1918. +0 ^ \ed?
  1919. +3 ^ [A-E]
  1920. +8 ^^ \e*
  1921. +10 ^ ^
  1922. 0: E*
  1923. .sp
  1924. If a pattern contains (*MARK) items, an additional line is output whenever
  1925. a change of latest mark is passed to the callout function. For example:
  1926. .sp
  1927. re> /a(*MARK:X)bc/auto_callout
  1928. data> abc
  1929. --->abc
  1930. +0 ^ a
  1931. +1 ^^ (*MARK:X)
  1932. +10 ^^ b
  1933. Latest Mark: X
  1934. +11 ^ ^ c
  1935. +12 ^ ^
  1936. 0: abc
  1937. .sp
  1938. The mark changes between matching "a" and "b", but stays the same for the rest
  1939. of the match, so nothing more is output. If, as a result of backtracking, the
  1940. mark reverts to being unset, the text "<unset>" is output.
  1941. .
  1942. .
  1943. .SS "Callouts with string arguments"
  1944. .rs
  1945. .sp
  1946. The output for a callout with a string argument is similar, except that instead
  1947. of outputting a callout number before the position indicators, the callout
  1948. string and its offset in the pattern string are output before the reflection of
  1949. the subject string, and the subject string is reflected for each callout. For
  1950. example:
  1951. .sp
  1952. re> /^ab(?C'first')cd(?C"second")ef/
  1953. data> abcdefg
  1954. Callout (7): 'first'
  1955. --->abcdefg
  1956. ^ ^ c
  1957. Callout (20): "second"
  1958. --->abcdefg
  1959. ^ ^ e
  1960. 0: abcdef
  1961. .sp
  1962. .
  1963. .
  1964. .SS "Callout modifiers"
  1965. .rs
  1966. .sp
  1967. The callout function in \fBpcre2test\fP returns zero (carry on matching) by
  1968. default, but you can use a \fBcallout_fail\fP modifier in a subject line to
  1969. change this and other parameters of the callout (see below).
  1970. .P
  1971. If the \fBcallout_capture\fP modifier is set, the current captured groups are
  1972. output when a callout occurs. This is useful only for non-DFA matching, as
  1973. \fBpcre2_dfa_match()\fP does not support capturing, so no captures are ever
  1974. shown.
  1975. .P
  1976. The normal callout output, showing the callout number or pattern offset (as
  1977. described above) is suppressed if the \fBcallout_no_where\fP modifier is set.
  1978. .P
  1979. When using the interpretive matching function \fBpcre2_match()\fP without JIT,
  1980. setting the \fBcallout_extra\fP modifier causes additional output from
  1981. \fBpcre2test\fP's callout function to be generated. For the first callout in a
  1982. match attempt at a new starting position in the subject, "New match attempt" is
  1983. output. If there has been a backtrack since the last callout (or start of
  1984. matching if this is the first callout), "Backtrack" is output, followed by "No
  1985. other matching paths" if the backtrack ended the previous match attempt. For
  1986. example:
  1987. .sp
  1988. re> /(a+)b/auto_callout,no_start_optimize,no_auto_possess
  1989. data> aac\e=callout_extra
  1990. New match attempt
  1991. --->aac
  1992. +0 ^ (
  1993. +1 ^ a+
  1994. +3 ^ ^ )
  1995. +4 ^ ^ b
  1996. Backtrack
  1997. --->aac
  1998. +3 ^^ )
  1999. +4 ^^ b
  2000. Backtrack
  2001. No other matching paths
  2002. New match attempt
  2003. --->aac
  2004. +0 ^ (
  2005. +1 ^ a+
  2006. +3 ^^ )
  2007. +4 ^^ b
  2008. Backtrack
  2009. No other matching paths
  2010. New match attempt
  2011. --->aac
  2012. +0 ^ (
  2013. +1 ^ a+
  2014. Backtrack
  2015. No other matching paths
  2016. New match attempt
  2017. --->aac
  2018. +0 ^ (
  2019. +1 ^ a+
  2020. No match
  2021. .sp
  2022. Notice that various optimizations must be turned off if you want all possible
  2023. matching paths to be scanned. If \fBno_start_optimize\fP is not used, there is
  2024. an immediate "no match", without any callouts, because the starting
  2025. optimization fails to find "b" in the subject, which it knows must be present
  2026. for any match. If \fBno_auto_possess\fP is not used, the "a+" item is turned
  2027. into "a++", which reduces the number of backtracks.
  2028. .P
  2029. The \fBcallout_extra\fP modifier has no effect if used with the DFA matching
  2030. function, or with JIT.
  2031. .
  2032. .
  2033. .SS "Return values from callouts"
  2034. .rs
  2035. .sp
  2036. The default return from the callout function is zero, which allows matching to
  2037. continue. The \fBcallout_fail\fP modifier can be given one or two numbers. If
  2038. there is only one number, 1 is returned instead of 0 (causing matching to
  2039. backtrack) when a callout of that number is reached. If two numbers (<n>:<m>)
  2040. are given, 1 is returned when callout <n> is reached and there have been at
  2041. least <m> callouts. The \fBcallout_error\fP modifier is similar, except that
  2042. PCRE2_ERROR_CALLOUT is returned, causing the entire matching process to be
  2043. aborted. If both these modifiers are set for the same callout number,
  2044. \fBcallout_error\fP takes precedence. Note that callouts with string arguments
  2045. are always given the number zero.
  2046. .P
  2047. The \fBcallout_data\fP modifier can be given an unsigned or a negative number.
  2048. This is set as the "user data" that is passed to the matching function, and
  2049. passed back when the callout function is invoked. Any value other than zero is
  2050. used as a return from \fBpcre2test\fP's callout function.
  2051. .P
  2052. Inserting callouts can be helpful when using \fBpcre2test\fP to check
  2053. complicated regular expressions. For further information about callouts, see
  2054. the
  2055. .\" HREF
  2056. \fBpcre2callout\fP
  2057. .\"
  2058. documentation.
  2059. .
  2060. .
  2061. .
  2062. .SH "NON-PRINTING CHARACTERS"
  2063. .rs
  2064. .sp
  2065. When \fBpcre2test\fP is outputting text in the compiled version of a pattern,
  2066. bytes other than 32-126 are always treated as non-printing characters and are
  2067. therefore shown as hex escapes.
  2068. .P
  2069. When \fBpcre2test\fP is outputting text that is a matched part of a subject
  2070. string, it behaves in the same way, unless a different locale has been set for
  2071. the pattern (using the \fBlocale\fP modifier). In this case, the
  2072. \fBisprint()\fP function is used to distinguish printing and non-printing
  2073. characters.
  2074. .
  2075. .
  2076. .
  2077. .\" HTML <a name="saverestore"></a>
  2078. .SH "SAVING AND RESTORING COMPILED PATTERNS"
  2079. .rs
  2080. .sp
  2081. It is possible to save compiled patterns on disc or elsewhere, and reload them
  2082. later, subject to a number of restrictions. JIT data cannot be saved. The host
  2083. on which the patterns are reloaded must be running the same version of PCRE2,
  2084. with the same code unit width, and must also have the same endianness, pointer
  2085. width and PCRE2_SIZE type. Before compiled patterns can be saved they must be
  2086. serialized, that is, converted to a stream of bytes. A single byte stream may
  2087. contain any number of compiled patterns, but they must all use the same
  2088. character tables. A single copy of the tables is included in the byte stream
  2089. (its size is 1088 bytes).
  2090. .P
  2091. The functions whose names begin with \fBpcre2_serialize_\fP are used
  2092. for serializing and de-serializing. They are described in the
  2093. .\" HREF
  2094. \fBpcre2serialize\fP
  2095. .\"
  2096. documentation. In this section we describe the features of \fBpcre2test\fP that
  2097. can be used to test these functions.
  2098. .P
  2099. Note that "serialization" in PCRE2 does not convert compiled patterns to an
  2100. abstract format like Java or .NET. It just makes a reloadable byte code stream.
  2101. Hence the restrictions on reloading mentioned above.
  2102. .P
  2103. In \fBpcre2test\fP, when a pattern with \fBpush\fP modifier is successfully
  2104. compiled, it is pushed onto a stack of compiled patterns, and \fBpcre2test\fP
  2105. expects the next line to contain a new pattern (or command) instead of a
  2106. subject line. By contrast, the \fBpushcopy\fP modifier causes a copy of the
  2107. compiled pattern to be stacked, leaving the original available for immediate
  2108. matching. By using \fBpush\fP and/or \fBpushcopy\fP, a number of patterns can
  2109. be compiled and retained. These modifiers are incompatible with \fBposix\fP,
  2110. and control modifiers that act at match time are ignored (with a message) for
  2111. the stacked patterns. The \fBjitverify\fP modifier applies only at compile
  2112. time.
  2113. .P
  2114. The command
  2115. .sp
  2116. #save <filename>
  2117. .sp
  2118. causes all the stacked patterns to be serialized and the result written to the
  2119. named file. Afterwards, all the stacked patterns are freed. The command
  2120. .sp
  2121. #load <filename>
  2122. .sp
  2123. reads the data in the file, and then arranges for it to be de-serialized, with
  2124. the resulting compiled patterns added to the pattern stack. The pattern on the
  2125. top of the stack can be retrieved by the #pop command, which must be followed
  2126. by lines of subjects that are to be matched with the pattern, terminated as
  2127. usual by an empty line or end of file. This command may be followed by a
  2128. modifier list containing only
  2129. .\" HTML <a href="#controlmodifiers">
  2130. .\" </a>
  2131. control modifiers
  2132. .\"
  2133. that act after a pattern has been compiled. In particular, \fBhex\fP,
  2134. \fBposix\fP, \fBposix_nosub\fP, \fBpush\fP, and \fBpushcopy\fP are not allowed,
  2135. nor are any
  2136. .\" HTML <a href="#optionmodifiers">
  2137. .\" </a>
  2138. option-setting modifiers.
  2139. .\"
  2140. The JIT modifiers are, however permitted. Here is an example that saves and
  2141. reloads two patterns.
  2142. .sp
  2143. /abc/push
  2144. /xyz/push
  2145. #save tempfile
  2146. #load tempfile
  2147. #pop info
  2148. xyz
  2149. .sp
  2150. #pop jit,bincode
  2151. abc
  2152. .sp
  2153. If \fBjitverify\fP is used with #pop, it does not automatically imply
  2154. \fBjit\fP, which is different behaviour from when it is used on a pattern.
  2155. .P
  2156. The #popcopy command is analogous to the \fBpushcopy\fP modifier in that it
  2157. makes current a copy of the topmost stack pattern, leaving the original still
  2158. on the stack.
  2159. .
  2160. .
  2161. .
  2162. .SH "SEE ALSO"
  2163. .rs
  2164. .sp
  2165. \fBpcre2\fP(3), \fBpcre2api\fP(3), \fBpcre2callout\fP(3),
  2166. \fBpcre2jit\fP, \fBpcre2matching\fP(3), \fBpcre2partial\fP(d),
  2167. \fBpcre2pattern\fP(3), \fBpcre2serialize\fP(3).
  2168. .
  2169. .
  2170. .SH AUTHOR
  2171. .rs
  2172. .sp
  2173. .nf
  2174. Philip Hazel
  2175. Retired from University Computing Service
  2176. Cambridge, England.
  2177. .fi
  2178. .
  2179. .
  2180. .SH REVISION
  2181. .rs
  2182. .sp
  2183. .nf
  2184. Last updated: 24 April 2024
  2185. Copyright (c) 1997-2024 University of Cambridge.
  2186. .fi