pcre2test.1 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175
  1. .TH PCRE2TEST 1 "27 January 2024" "PCRE 10.43"
  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_length=<n> set maximum pattern length
  656. max_varlookbehind=<n> set maximum variable lookbehind length
  657. memory show memory used
  658. newline=<type> set newline type
  659. null_context compile with a NULL context
  660. null_pattern pass pattern as NULL
  661. parens_nest_limit=<n> set maximum parentheses depth
  662. posix use the POSIX API
  663. posix_nosub use the POSIX API with REG_NOSUB
  664. push push compiled pattern onto the stack
  665. pushcopy push a copy onto the stack
  666. stackguard=<number> test the stackguard feature
  667. subject_literal treat all subject lines as literal
  668. tables=[0|1|2|3] select internal tables
  669. use_length do not zero-terminate the pattern
  670. utf8_input treat input as UTF-8
  671. .sp
  672. The effects of these modifiers are described in the following sections.
  673. .
  674. .
  675. .SS "Newline and \eR handling"
  676. .rs
  677. .sp
  678. The \fBbsr\fP modifier specifies what \eR in a pattern should match. If it is
  679. set to "anycrlf", \eR matches CR, LF, or CRLF only. If it is set to "unicode",
  680. \eR matches any Unicode newline sequence. The default can be specified when
  681. PCRE2 is built; if it is not, the default is set to Unicode.
  682. .P
  683. The \fBnewline\fP modifier specifies which characters are to be interpreted as
  684. newlines, both in the pattern and in subject lines. The type must be one of CR,
  685. LF, CRLF, ANYCRLF, ANY, or NUL (in upper or lower case).
  686. .
  687. .
  688. .SS "Information about a pattern"
  689. .rs
  690. .sp
  691. The \fBdebug\fP modifier is a shorthand for \fBinfo,fullbincode\fP, requesting
  692. all available information.
  693. .P
  694. The \fBbincode\fP modifier causes a representation of the compiled code to be
  695. output after compilation. This information does not contain length and offset
  696. values, which ensures that the same output is generated for different internal
  697. link sizes and different code unit widths. By using \fBbincode\fP, the same
  698. regression tests can be used in different environments.
  699. .P
  700. The \fBfullbincode\fP modifier, by contrast, \fIdoes\fP include length and
  701. offset values. This is used in a few special tests that run only for specific
  702. code unit widths and link sizes, and is also useful for one-off tests.
  703. .P
  704. The \fBinfo\fP modifier requests information about the compiled pattern
  705. (whether it is anchored, has a fixed first character, and so on). The
  706. information is obtained from the \fBpcre2_pattern_info()\fP function. Here are
  707. some typical examples:
  708. .sp
  709. re> /(?i)(^a|^b)/m,info
  710. Capture group count = 1
  711. Compile options: multiline
  712. Overall options: caseless multiline
  713. First code unit at start or follows newline
  714. Subject length lower bound = 1
  715. .sp
  716. re> /(?i)abc/info
  717. Capture group count = 0
  718. Compile options: <none>
  719. Overall options: caseless
  720. First code unit = 'a' (caseless)
  721. Last code unit = 'c' (caseless)
  722. Subject length lower bound = 3
  723. .sp
  724. "Compile options" are those specified by modifiers; "overall options" have
  725. added options that are taken or deduced from the pattern. If both sets of
  726. options are the same, just a single "options" line is output; if there are no
  727. options, the line is omitted. "First code unit" is where any match must start;
  728. if there is more than one they are listed as "starting code units". "Last code
  729. unit" is the last literal code unit that must be present in any match. This is
  730. not necessarily the last character. These lines are omitted if no starting or
  731. ending code units are recorded. The subject length line is omitted when
  732. \fBno_start_optimize\fP is set because the minimum length is not calculated
  733. when it can never be used.
  734. .P
  735. The \fBframesize\fP modifier shows the size, in bytes, of each storage frame
  736. used by \fBpcre2_match()\fP for handling backtracking. The size depends on the
  737. number of capturing parentheses in the pattern. A vector of these frames is
  738. used at matching time; its overall size is shown when the \fBheaframes_size\fP
  739. subject modifier is set.
  740. .P
  741. The \fBcallout_info\fP modifier requests information about all the callouts in
  742. the pattern. A list of them is output at the end of any other information that
  743. is requested. For each callout, either its number or string is given, followed
  744. by the item that follows it in the pattern.
  745. .
  746. .
  747. .SS "Passing a NULL context"
  748. .rs
  749. .sp
  750. Normally, \fBpcre2test\fP passes a context block to \fBpcre2_compile()\fP. If
  751. the \fBnull_context\fP modifier is set, however, NULL is passed. This is for
  752. testing that \fBpcre2_compile()\fP behaves correctly in this case (it uses
  753. default values).
  754. .
  755. .
  756. .SS "Passing a NULL pattern"
  757. .rs
  758. .sp
  759. The \fBnull_pattern\fP modifier is for testing the behaviour of
  760. \fBpcre2_compile()\fP when the pattern argument is NULL. The length value
  761. passed is the default PCRE2_ZERO_TERMINATED unless \fBuse_length\fP is set.
  762. Any length other than zero causes an error.
  763. .
  764. .
  765. .SS "Specifying pattern characters in hexadecimal"
  766. .rs
  767. .sp
  768. The \fBhex\fP modifier specifies that the characters of the pattern, except for
  769. substrings enclosed in single or double quotes, are to be interpreted as pairs
  770. of hexadecimal digits. This feature is provided as a way of creating patterns
  771. that contain binary zeros and other non-printing characters. White space is
  772. permitted between pairs of digits. For example, this pattern contains three
  773. characters:
  774. .sp
  775. /ab 32 59/hex
  776. .sp
  777. Parts of such a pattern are taken literally if quoted. This pattern contains
  778. nine characters, only two of which are specified in hexadecimal:
  779. .sp
  780. /ab "literal" 32/hex
  781. .sp
  782. Either single or double quotes may be used. There is no way of including
  783. the delimiter within a substring. The \fBhex\fP and \fBexpand\fP modifiers are
  784. mutually exclusive.
  785. .
  786. .
  787. .SS "Specifying the pattern's length"
  788. .rs
  789. .sp
  790. By default, patterns are passed to the compiling functions as zero-terminated
  791. strings but can be passed by length instead of being zero-terminated. The
  792. \fBuse_length\fP modifier causes this to happen. Using a length happens
  793. automatically (whether or not \fBuse_length\fP is set) when \fBhex\fP is set,
  794. because patterns specified in hexadecimal may contain binary zeros.
  795. .P
  796. If \fBhex\fP or \fBuse_length\fP is used with the POSIX wrapper API (see
  797. .\" HTML <a href="#posixwrapper">
  798. .\" </a>
  799. "Using the POSIX wrapper API"
  800. .\"
  801. below), the REG_PEND extension is used to pass the pattern's length.
  802. .
  803. .
  804. .SS "Specifying a maximum for variable lookbehinds"
  805. .rs
  806. .sp
  807. Variable lookbehind assertions are supported only if, for each one, there is a
  808. maximum length (in characters) that it can match. There is a limit on this,
  809. whose default can be set at build time, with an ultimate default of 255. The
  810. \fBmax_varlookbehind\fP modifier uses the \fBpcre2_set_max_varlookbehind()\fP
  811. function to change the limit. Lookbehinds whose branches each match a fixed
  812. length are limited to 65535 characters per branch.
  813. .
  814. .
  815. .SS "Specifying wide characters in 16-bit and 32-bit modes"
  816. .rs
  817. .sp
  818. In 16-bit and 32-bit modes, all input is automatically treated as UTF-8 and
  819. translated to UTF-16 or UTF-32 when the \fButf\fP modifier is set. For testing
  820. the 16-bit and 32-bit libraries in non-UTF mode, the \fButf8_input\fP modifier
  821. can be used. It is mutually exclusive with \fButf\fP. Input lines are
  822. interpreted as UTF-8 as a means of specifying wide characters. More details are
  823. given in
  824. .\" HTML <a href="#inputencoding">
  825. .\" </a>
  826. "Input encoding"
  827. .\"
  828. above.
  829. .
  830. .
  831. .SS "Generating long repetitive patterns"
  832. .rs
  833. .sp
  834. Some tests use long patterns that are very repetitive. Instead of creating a
  835. very long input line for such a pattern, you can use a special repetition
  836. feature, similar to the one described for subject lines above. If the
  837. \fBexpand\fP modifier is present on a pattern, parts of the pattern that have
  838. the form
  839. .sp
  840. \e[<characters>]{<count>}
  841. .sp
  842. are expanded before the pattern is passed to \fBpcre2_compile()\fP. For
  843. example, \e[AB]{6000} is expanded to "ABAB..." 6000 times. This construction
  844. cannot be nested. An initial "\e[" sequence is recognized only if "]{" followed
  845. by decimal digits and "}" is found later in the pattern. If not, the characters
  846. remain in the pattern unaltered. The \fBexpand\fP and \fBhex\fP modifiers are
  847. mutually exclusive.
  848. .P
  849. If part of an expanded pattern looks like an expansion, but is really part of
  850. the actual pattern, unwanted expansion can be avoided by giving two values in
  851. the quantifier. For example, \e[AB]{6000,6000} is not recognized as an
  852. expansion item.
  853. .P
  854. If the \fBinfo\fP modifier is set on an expanded pattern, the result of the
  855. expansion is included in the information that is output.
  856. .
  857. .
  858. .SS "JIT compilation"
  859. .rs
  860. .sp
  861. Just-in-time (JIT) compiling is a heavyweight optimization that can greatly
  862. speed up pattern matching. See the
  863. .\" HREF
  864. \fBpcre2jit\fP
  865. .\"
  866. documentation for details. JIT compiling happens, optionally, after a pattern
  867. has been successfully compiled into an internal form. The JIT compiler converts
  868. this to optimized machine code. It needs to know whether the match-time options
  869. PCRE2_PARTIAL_HARD and PCRE2_PARTIAL_SOFT are going to be used, because
  870. different code is generated for the different cases. See the \fBpartial\fP
  871. modifier in "Subject Modifiers"
  872. .\" HTML <a href="#subjectmodifiers">
  873. .\" </a>
  874. below
  875. .\"
  876. for details of how these options are specified for each match attempt.
  877. .P
  878. JIT compilation is requested by the \fBjit\fP pattern modifier, which may
  879. optionally be followed by an equals sign and a number in the range 0 to 7.
  880. The three bits that make up the number specify which of the three JIT operating
  881. modes are to be compiled:
  882. .sp
  883. 1 compile JIT code for non-partial matching
  884. 2 compile JIT code for soft partial matching
  885. 4 compile JIT code for hard partial matching
  886. .sp
  887. The possible values for the \fBjit\fP modifier are therefore:
  888. .sp
  889. 0 disable JIT
  890. 1 normal matching only
  891. 2 soft partial matching only
  892. 3 normal and soft partial matching
  893. 4 hard partial matching only
  894. 6 soft and hard partial matching only
  895. 7 all three modes
  896. .sp
  897. If no number is given, 7 is assumed. The phrase "partial matching" means a call
  898. to \fBpcre2_match()\fP with either the PCRE2_PARTIAL_SOFT or the
  899. PCRE2_PARTIAL_HARD option set. Note that such a call may return a complete
  900. match; the options enable the possibility of a partial match, but do not
  901. require it. Note also that if you request JIT compilation only for partial
  902. matching (for example, jit=2) but do not set the \fBpartial\fP modifier on a
  903. subject line, that match will not use JIT code because none was compiled for
  904. non-partial matching.
  905. .P
  906. If JIT compilation is successful, the compiled JIT code will automatically be
  907. used when an appropriate type of match is run, except when incompatible
  908. run-time options are specified. For more details, see the
  909. .\" HREF
  910. \fBpcre2jit\fP
  911. .\"
  912. documentation. See also the \fBjitstack\fP modifier below for a way of
  913. setting the size of the JIT stack.
  914. .P
  915. If the \fBjitfast\fP modifier is specified, matching is done using the JIT
  916. "fast path" interface, \fBpcre2_jit_match()\fP, which skips some of the sanity
  917. checks that are done by \fBpcre2_match()\fP, and of course does not work when
  918. JIT is not supported. If \fBjitfast\fP is specified without \fBjit\fP, jit=7 is
  919. assumed.
  920. .P
  921. If the \fBjitverify\fP modifier is specified, information about the compiled
  922. pattern shows whether JIT compilation was or was not successful. If
  923. \fBjitverify\fP is specified without \fBjit\fP, jit=7 is assumed. If JIT
  924. compilation is successful when \fBjitverify\fP is set, the text "(JIT)" is
  925. added to the first output line after a match or non match when JIT-compiled
  926. code was actually used in the match.
  927. .
  928. .
  929. .SS "Setting a locale"
  930. .rs
  931. .sp
  932. The \fBlocale\fP modifier must specify the name of a locale, for example:
  933. .sp
  934. /pattern/locale=fr_FR
  935. .sp
  936. The given locale is set, \fBpcre2_maketables()\fP is called to build a set of
  937. character tables for the locale, and this is then passed to
  938. \fBpcre2_compile()\fP when compiling the regular expression. The same tables
  939. are used when matching the following subject lines. The \fBlocale\fP modifier
  940. applies only to the pattern on which it appears, but can be given in a
  941. \fB#pattern\fP command if a default is needed. Setting a locale and alternate
  942. character tables are mutually exclusive.
  943. .
  944. .
  945. .SS "Showing pattern memory"
  946. .rs
  947. .sp
  948. The \fBmemory\fP modifier causes the size in bytes of the memory used to hold
  949. the compiled pattern to be output. This does not include the size of the
  950. \fBpcre2_code\fP block; it is just the actual compiled data. If the pattern is
  951. subsequently passed to the JIT compiler, the size of the JIT compiled code is
  952. also output. Here is an example:
  953. .sp
  954. re> /a(b)c/jit,memory
  955. Memory allocation (code space): 21
  956. Memory allocation (JIT code): 1910
  957. .sp
  958. .
  959. .
  960. .SS "Limiting nested parentheses"
  961. .rs
  962. .sp
  963. The \fBparens_nest_limit\fP modifier sets a limit on the depth of nested
  964. parentheses in a pattern. Breaching the limit causes a compilation error.
  965. The default for the library is set when PCRE2 is built, but \fBpcre2test\fP
  966. sets its own default of 220, which is required for running the standard test
  967. suite.
  968. .
  969. .
  970. .SS "Limiting the pattern length"
  971. .rs
  972. .sp
  973. The \fBmax_pattern_length\fP modifier sets a limit, in code units, to the
  974. length of pattern that \fBpcre2_compile()\fP will accept. Breaching the limit
  975. causes a compilation error. The default is the largest number a PCRE2_SIZE
  976. variable can hold (essentially unlimited).
  977. .
  978. .
  979. .\" HTML <a name="posixwrapper"></a>
  980. .SS "Using the POSIX wrapper API"
  981. .rs
  982. .sp
  983. The \fBposix\fP and \fBposix_nosub\fP modifiers cause \fBpcre2test\fP to call
  984. PCRE2 via the POSIX wrapper API rather than its native API. When
  985. \fBposix_nosub\fP is used, the POSIX option REG_NOSUB is passed to
  986. \fBregcomp()\fP. The POSIX wrapper supports only the 8-bit library. Note that
  987. it does not imply POSIX matching semantics; for more detail see the
  988. .\" HREF
  989. \fBpcre2posix\fP
  990. .\"
  991. documentation. The following pattern modifiers set options for the
  992. \fBregcomp()\fP function:
  993. .sp
  994. caseless REG_ICASE
  995. multiline REG_NEWLINE
  996. dotall REG_DOTALL )
  997. ungreedy REG_UNGREEDY ) These options are not part of
  998. ucp REG_UCP ) the POSIX standard
  999. utf REG_UTF8 )
  1000. .sp
  1001. The \fBregerror_buffsize\fP modifier specifies a size for the error buffer that
  1002. is passed to \fBregerror()\fP in the event of a compilation error. For example:
  1003. .sp
  1004. /abc/posix,regerror_buffsize=20
  1005. .sp
  1006. This provides a means of testing the behaviour of \fBregerror()\fP when the
  1007. buffer is too small for the error message. If this modifier has not been set, a
  1008. large buffer is used.
  1009. .P
  1010. The \fBaftertext\fP and \fBallaftertext\fP subject modifiers work as described
  1011. below. All other modifiers are either ignored, with a warning message, or cause
  1012. an error.
  1013. .P
  1014. The pattern is passed to \fBregcomp()\fP as a zero-terminated string by
  1015. default, but if the \fBuse_length\fP or \fBhex\fP modifiers are set, the
  1016. REG_PEND extension is used to pass it by length.
  1017. .
  1018. .
  1019. .SS "Testing the stack guard feature"
  1020. .rs
  1021. .sp
  1022. The \fBstackguard\fP modifier is used to test the use of
  1023. \fBpcre2_set_compile_recursion_guard()\fP, a function that is provided to
  1024. enable stack availability to be checked during compilation (see the
  1025. .\" HREF
  1026. \fBpcre2api\fP
  1027. .\"
  1028. documentation for details). If the number specified by the modifier is greater
  1029. than zero, \fBpcre2_set_compile_recursion_guard()\fP is called to set up
  1030. callback from \fBpcre2_compile()\fP to a local function. The argument it
  1031. receives is the current nesting parenthesis depth; if this is greater than the
  1032. value given by the modifier, non-zero is returned, causing the compilation to
  1033. be aborted.
  1034. .
  1035. .
  1036. .SS "Using alternative character tables"
  1037. .rs
  1038. .sp
  1039. The value specified for the \fBtables\fP modifier must be one of the digits 0,
  1040. 1, 2, or 3. It causes a specific set of built-in character tables to be passed
  1041. to \fBpcre2_compile()\fP. This is used in the PCRE2 tests to check behaviour
  1042. with different character tables. The digit specifies the tables as follows:
  1043. .sp
  1044. 0 do not pass any special character tables
  1045. 1 the default ASCII tables, as distributed in
  1046. pcre2_chartables.c.dist
  1047. 2 a set of tables defining ISO 8859 characters
  1048. 3 a set of tables loaded by the #loadtables command
  1049. .sp
  1050. In tables 2, some characters whose codes are greater than 128 are identified as
  1051. letters, digits, spaces, etc. Tables 3 can be used only after a
  1052. \fB#loadtables\fP command has loaded them from a binary file. Setting alternate
  1053. character tables and a locale are mutually exclusive.
  1054. .
  1055. .
  1056. .SS "Setting certain match controls"
  1057. .rs
  1058. .sp
  1059. The following modifiers are really subject modifiers, and are described under
  1060. "Subject Modifiers" below. However, they may be included in a pattern's
  1061. modifier list, in which case they are applied to every subject line that is
  1062. processed with that pattern. These modifiers do not affect the compilation
  1063. process.
  1064. .sp
  1065. aftertext show text after match
  1066. allaftertext show text after captures
  1067. allcaptures show all captures
  1068. allvector show the entire ovector
  1069. allusedtext show all consulted text
  1070. altglobal alternative global matching
  1071. /g global global matching
  1072. heapframes_size show match data heapframes size
  1073. jitstack=<n> set size of JIT stack
  1074. mark show mark values
  1075. replace=<string> specify a replacement string
  1076. startchar show starting character when relevant
  1077. substitute_callout use substitution callouts
  1078. substitute_extended use PCRE2_SUBSTITUTE_EXTENDED
  1079. substitute_literal use PCRE2_SUBSTITUTE_LITERAL
  1080. substitute_matched use PCRE2_SUBSTITUTE_MATCHED
  1081. substitute_overflow_length use PCRE2_SUBSTITUTE_OVERFLOW_LENGTH
  1082. substitute_replacement_only use PCRE2_SUBSTITUTE_REPLACEMENT_ONLY
  1083. substitute_skip=<n> skip substitution <n>
  1084. substitute_stop=<n> skip substitution <n> and following
  1085. substitute_unknown_unset use PCRE2_SUBSTITUTE_UNKNOWN_UNSET
  1086. substitute_unset_empty use PCRE2_SUBSTITUTE_UNSET_EMPTY
  1087. .sp
  1088. These modifiers may not appear in a \fB#pattern\fP command. If you want them as
  1089. defaults, set them in a \fB#subject\fP command.
  1090. .
  1091. .
  1092. .SS "Specifying literal subject lines"
  1093. .rs
  1094. .sp
  1095. If the \fBsubject_literal\fP modifier is present on a pattern, all the subject
  1096. lines that it matches are taken as literal strings, with no interpretation of
  1097. backslashes. It is not possible to set subject modifiers on such lines, but any
  1098. that are set as defaults by a \fB#subject\fP command are recognized.
  1099. .
  1100. .
  1101. .SS "Saving a compiled pattern"
  1102. .rs
  1103. .sp
  1104. When a pattern with the \fBpush\fP modifier is successfully compiled, it is
  1105. pushed onto a stack of compiled patterns, and \fBpcre2test\fP expects the next
  1106. line to contain a new pattern (or a command) instead of a subject line. This
  1107. facility is used when saving compiled patterns to a file, as described in the
  1108. section entitled "Saving and restoring compiled patterns"
  1109. .\" HTML <a href="#saverestore">
  1110. .\" </a>
  1111. below.
  1112. .\"
  1113. If \fBpushcopy\fP is used instead of \fBpush\fP, a copy of the compiled
  1114. pattern is stacked, leaving the original as current, ready to match the
  1115. following input lines. This provides a way of testing the
  1116. \fBpcre2_code_copy()\fP function.
  1117. .\"
  1118. The \fBpush\fP and \fBpushcopy \fP modifiers are incompatible with compilation
  1119. modifiers such as \fBglobal\fP that act at match time. Any that are specified
  1120. are ignored (for the stacked copy), with a warning message, except for
  1121. \fBreplace\fP, which causes an error. Note that \fBjitverify\fP, which is
  1122. allowed, does not carry through to any subsequent matching that uses a stacked
  1123. pattern.
  1124. .
  1125. .
  1126. .SS "Testing foreign pattern conversion"
  1127. .rs
  1128. .sp
  1129. The experimental foreign pattern conversion functions in PCRE2 can be tested by
  1130. setting the \fBconvert\fP modifier. Its argument is a colon-separated list of
  1131. options, which set the equivalent option for the \fBpcre2_pattern_convert()\fP
  1132. function:
  1133. .sp
  1134. glob PCRE2_CONVERT_GLOB
  1135. glob_no_starstar PCRE2_CONVERT_GLOB_NO_STARSTAR
  1136. glob_no_wild_separator PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR
  1137. posix_basic PCRE2_CONVERT_POSIX_BASIC
  1138. posix_extended PCRE2_CONVERT_POSIX_EXTENDED
  1139. unset Unset all options
  1140. .sp
  1141. The "unset" value is useful for turning off a default that has been set by a
  1142. \fB#pattern\fP command. When one of these options is set, the input pattern is
  1143. passed to \fBpcre2_pattern_convert()\fP. If the conversion is successful, the
  1144. result is reflected in the output and then passed to \fBpcre2_compile()\fP. The
  1145. normal \fButf\fP and \fBno_utf_check\fP options, if set, cause the
  1146. PCRE2_CONVERT_UTF and PCRE2_CONVERT_NO_UTF_CHECK options to be passed to
  1147. \fBpcre2_pattern_convert()\fP.
  1148. .P
  1149. By default, the conversion function is allowed to allocate a buffer for its
  1150. output. However, if the \fBconvert_length\fP modifier is set to a value greater
  1151. than zero, \fBpcre2test\fP passes a buffer of the given length. This makes it
  1152. possible to test the length check.
  1153. .P
  1154. The \fBconvert_glob_escape\fP and \fBconvert_glob_separator\fP modifiers can be
  1155. used to specify the escape and separator characters for glob processing,
  1156. overriding the defaults, which are operating-system dependent.
  1157. .
  1158. .
  1159. .\" HTML <a name="subjectmodifiers"></a>
  1160. .SH "SUBJECT MODIFIERS"
  1161. .rs
  1162. .sp
  1163. The modifiers that can appear in subject lines and the \fB#subject\fP
  1164. command are of two types.
  1165. .
  1166. .
  1167. .SS "Setting match options"
  1168. .rs
  1169. .sp
  1170. The following modifiers set options for \fBpcre2_match()\fP or
  1171. \fBpcre2_dfa_match()\fP. See
  1172. .\" HREF
  1173. \fBpcreapi\fP
  1174. .\"
  1175. for a description of their effects.
  1176. .sp
  1177. anchored set PCRE2_ANCHORED
  1178. endanchored set PCRE2_ENDANCHORED
  1179. dfa_restart set PCRE2_DFA_RESTART
  1180. dfa_shortest set PCRE2_DFA_SHORTEST
  1181. disable_recurseloop_check set PCRE2_DISABLE_RECURSELOOP_CHECK
  1182. no_jit set PCRE2_NO_JIT
  1183. no_utf_check set PCRE2_NO_UTF_CHECK
  1184. notbol set PCRE2_NOTBOL
  1185. notempty set PCRE2_NOTEMPTY
  1186. notempty_atstart set PCRE2_NOTEMPTY_ATSTART
  1187. noteol set PCRE2_NOTEOL
  1188. partial_hard (or ph) set PCRE2_PARTIAL_HARD
  1189. partial_soft (or ps) set PCRE2_PARTIAL_SOFT
  1190. .sp
  1191. The partial matching modifiers are provided with abbreviations because they
  1192. appear frequently in tests.
  1193. .P
  1194. If the \fBposix\fP or \fBposix_nosub\fP modifier was present on the pattern,
  1195. causing the POSIX wrapper API to be used, the only option-setting modifiers
  1196. that have any effect are \fBnotbol\fP, \fBnotempty\fP, and \fBnoteol\fP,
  1197. causing REG_NOTBOL, REG_NOTEMPTY, and REG_NOTEOL, respectively, to be passed to
  1198. \fBregexec()\fP. The other modifiers are ignored, with a warning message.
  1199. .P
  1200. There is one additional modifier that can be used with the POSIX wrapper. It is
  1201. ignored (with a warning) if used for non-POSIX matching.
  1202. .sp
  1203. posix_startend=<n>[:<m>]
  1204. .sp
  1205. This causes the subject string to be passed to \fBregexec()\fP using the
  1206. REG_STARTEND option, which uses offsets to specify which part of the string is
  1207. searched. If only one number is given, the end offset is passed as the end of
  1208. the subject string. For more detail of REG_STARTEND, see the
  1209. .\" HREF
  1210. \fBpcre2posix\fP
  1211. .\"
  1212. documentation. If the subject string contains binary zeros (coded as escapes
  1213. such as \ex{00} because \fBpcre2test\fP does not support actual binary zeros in
  1214. its input), you must use \fBposix_startend\fP to specify its length.
  1215. .
  1216. .
  1217. .SS "Setting match controls"
  1218. .rs
  1219. .sp
  1220. The following modifiers affect the matching process or request additional
  1221. information. Some of them may also be specified on a pattern line (see above),
  1222. in which case they apply to every subject line that is matched against that
  1223. pattern, but can be overridden by modifiers on the subject.
  1224. .sp
  1225. aftertext show text after match
  1226. allaftertext show text after captures
  1227. allcaptures show all captures
  1228. allvector show the entire ovector
  1229. allusedtext show all consulted text (non-JIT only)
  1230. altglobal alternative global matching
  1231. callout_capture show captures at callout time
  1232. callout_data=<n> set a value to pass via callouts
  1233. callout_error=<n>[:<m>] control callout error
  1234. callout_extra show extra callout information
  1235. callout_fail=<n>[:<m>] control callout failure
  1236. callout_no_where do not show position of a callout
  1237. callout_none do not supply a callout function
  1238. copy=<number or name> copy captured substring
  1239. depth_limit=<n> set a depth limit
  1240. dfa use \fBpcre2_dfa_match()\fP
  1241. find_limits find heap, match and depth limits
  1242. find_limits_noheap find match and depth limits
  1243. get=<number or name> extract captured substring
  1244. getall extract all captured substrings
  1245. /g global global matching
  1246. heapframes_size show match data heapframes size
  1247. heap_limit=<n> set a limit on heap memory (Kbytes)
  1248. jitstack=<n> set size of JIT stack
  1249. mark show mark values
  1250. match_limit=<n> set a match limit
  1251. memory show heap memory usage
  1252. null_context match with a NULL context
  1253. null_replacement substitute with NULL replacement
  1254. null_subject match with NULL subject
  1255. offset=<n> set starting offset
  1256. offset_limit=<n> set offset limit
  1257. ovector=<n> set size of output vector
  1258. recursion_limit=<n> obsolete synonym for depth_limit
  1259. replace=<string> specify a replacement string
  1260. startchar show startchar when relevant
  1261. startoffset=<n> same as offset=<n>
  1262. substitute_callout use substitution callouts
  1263. substitute_extedded use PCRE2_SUBSTITUTE_EXTENDED
  1264. substitute_literal use PCRE2_SUBSTITUTE_LITERAL
  1265. substitute_matched use PCRE2_SUBSTITUTE_MATCHED
  1266. substitute_overflow_length use PCRE2_SUBSTITUTE_OVERFLOW_LENGTH
  1267. substitute_replacement_only use PCRE2_SUBSTITUTE_REPLACEMENT_ONLY
  1268. substitute_skip=<n> skip substitution number n
  1269. substitute_stop=<n> skip substitution number n and greater
  1270. substitute_unknown_unset use PCRE2_SUBSTITUTE_UNKNOWN_UNSET
  1271. substitute_unset_empty use PCRE2_SUBSTITUTE_UNSET_EMPTY
  1272. zero_terminate pass the subject as zero-terminated
  1273. .sp
  1274. The effects of these modifiers are described in the following sections. When
  1275. matching via the POSIX wrapper API, the \fBaftertext\fP, \fBallaftertext\fP,
  1276. and \fBovector\fP subject modifiers work as described below. All other
  1277. modifiers are either ignored, with a warning message, or cause an error.
  1278. .
  1279. .
  1280. .SS "Showing more text"
  1281. .rs
  1282. .sp
  1283. The \fBaftertext\fP modifier requests that as well as outputting the part of
  1284. the subject string that matched the entire pattern, \fBpcre2test\fP should in
  1285. addition output the remainder of the subject string. This is useful for tests
  1286. where the subject contains multiple copies of the same substring. The
  1287. \fBallaftertext\fP modifier requests the same action for captured substrings as
  1288. well as the main matched substring. In each case the remainder is output on the
  1289. following line with a plus character following the capture number.
  1290. .P
  1291. The \fBallusedtext\fP modifier requests that all the text that was consulted
  1292. during a successful pattern match by the interpreter should be shown, for both
  1293. full and partial matches. This feature is not supported for JIT matching, and
  1294. if requested with JIT it is ignored (with a warning message). Setting this
  1295. modifier affects the output if there is a lookbehind at the start of a match,
  1296. or, for a complete match, a lookahead at the end, or if \eK is used in the
  1297. pattern. Characters that precede or follow the start and end of the actual
  1298. match are indicated in the output by '<' or '>' characters underneath them.
  1299. Here is an example:
  1300. .sp
  1301. re> /(?<=pqr)abc(?=xyz)/
  1302. data> 123pqrabcxyz456\e=allusedtext
  1303. 0: pqrabcxyz
  1304. <<< >>>
  1305. data> 123pqrabcxy\e=ph,allusedtext
  1306. Partial match: pqrabcxy
  1307. <<<
  1308. .sp
  1309. The first, complete match shows that the matched string is "abc", with the
  1310. preceding and following strings "pqr" and "xyz" having been consulted during
  1311. the match (when processing the assertions). The partial match can indicate only
  1312. the preceding string.
  1313. .P
  1314. The \fBstartchar\fP modifier requests that the starting character for the match
  1315. be indicated, if it is different to the start of the matched string. The only
  1316. time when this occurs is when \eK has been processed as part of the match. In
  1317. this situation, the output for the matched string is displayed from the
  1318. starting character instead of from the match point, with circumflex characters
  1319. under the earlier characters. For example:
  1320. .sp
  1321. re> /abc\eKxyz/
  1322. data> abcxyz\e=startchar
  1323. 0: abcxyz
  1324. ^^^
  1325. .sp
  1326. Unlike \fBallusedtext\fP, the \fBstartchar\fP modifier can be used with JIT.
  1327. However, these two modifiers are mutually exclusive.
  1328. .
  1329. .
  1330. .SS "Showing the value of all capture groups"
  1331. .rs
  1332. .sp
  1333. The \fBallcaptures\fP modifier requests that the values of all potential
  1334. captured parentheses be output after a match. By default, only those up to the
  1335. highest one actually used in the match are output (corresponding to the return
  1336. code from \fBpcre2_match()\fP). Groups that did not take part in the match
  1337. are output as "<unset>". This modifier is not relevant for DFA matching (which
  1338. does no capturing) and does not apply when \fBreplace\fP is specified; it is
  1339. ignored, with a warning message, if present.
  1340. .
  1341. .
  1342. .SS "Showing the entire ovector, for all outcomes"
  1343. .rs
  1344. .sp
  1345. The \fBallvector\fP modifier requests that the entire ovector be shown,
  1346. whatever the outcome of the match. Compare \fBallcaptures\fP, which shows only
  1347. up to the maximum number of capture groups for the pattern, and then only for a
  1348. successful complete non-DFA match. This modifier, which acts after any match
  1349. result, and also for DFA matching, provides a means of checking that there are
  1350. no unexpected modifications to ovector fields. Before each match attempt, the
  1351. ovector is filled with a special value, and if this is found in both elements
  1352. of a capturing pair, "<unchanged>" is output. After a successful match, this
  1353. applies to all groups after the maximum capture group for the pattern. In other
  1354. cases it applies to the entire ovector. After a partial match, the first two
  1355. elements are the only ones that should be set. After a DFA match, the amount of
  1356. ovector that is used depends on the number of matches that were found.
  1357. .
  1358. .
  1359. .SS "Testing pattern callouts"
  1360. .rs
  1361. .sp
  1362. A callout function is supplied when \fBpcre2test\fP calls the library matching
  1363. functions, unless \fBcallout_none\fP is specified. Its behaviour can be
  1364. controlled by various modifiers listed above whose names begin with
  1365. \fBcallout_\fP. Details are given in the section entitled "Callouts"
  1366. .\" HTML <a href="#callouts">
  1367. .\" </a>
  1368. below.
  1369. .\"
  1370. Testing callouts from \fBpcre2_substitute()\fP is described separately in
  1371. "Testing the substitution function"
  1372. .\" HTML <a href="#substitution">
  1373. .\" </a>
  1374. below.
  1375. .\"
  1376. .
  1377. .
  1378. .SS "Finding all matches in a string"
  1379. .rs
  1380. .sp
  1381. Searching for all possible matches within a subject can be requested by the
  1382. \fBglobal\fP or \fBaltglobal\fP modifier. After finding a match, the matching
  1383. function is called again to search the remainder of the subject. The difference
  1384. between \fBglobal\fP and \fBaltglobal\fP is that the former uses the
  1385. \fIstart_offset\fP argument to \fBpcre2_match()\fP or \fBpcre2_dfa_match()\fP
  1386. to start searching at a new point within the entire string (which is what Perl
  1387. does), whereas the latter passes over a shortened subject. This makes a
  1388. difference to the matching process if the pattern begins with a lookbehind
  1389. assertion (including \eb or \eB).
  1390. .P
  1391. If an empty string is matched, the next match is done with the
  1392. PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED flags set, in order to search for
  1393. another, non-empty, match at the same point in the subject. If this match
  1394. fails, the start offset is advanced, and the normal match is retried. This
  1395. imitates the way Perl handles such cases when using the \fB/g\fP modifier or
  1396. the \fBsplit()\fP function. Normally, the start offset is advanced by one
  1397. character, but if the newline convention recognizes CRLF as a newline, and the
  1398. current character is CR followed by LF, an advance of two characters occurs.
  1399. .
  1400. .
  1401. .SS "Testing substring extraction functions"
  1402. .rs
  1403. .sp
  1404. The \fBcopy\fP and \fBget\fP modifiers can be used to test the
  1405. \fBpcre2_substring_copy_xxx()\fP and \fBpcre2_substring_get_xxx()\fP functions.
  1406. They can be given more than once, and each can specify a capture group name or
  1407. number, for example:
  1408. .sp
  1409. abcd\e=copy=1,copy=3,get=G1
  1410. .sp
  1411. If the \fB#subject\fP command is used to set default copy and/or get lists,
  1412. these can be unset by specifying a negative number to cancel all numbered
  1413. groups and an empty name to cancel all named groups.
  1414. .P
  1415. The \fBgetall\fP modifier tests \fBpcre2_substring_list_get()\fP, which
  1416. extracts all captured substrings.
  1417. .P
  1418. If the subject line is successfully matched, the substrings extracted by the
  1419. convenience functions are output with C, G, or L after the string number
  1420. instead of a colon. This is in addition to the normal full list. The string
  1421. length (that is, the return from the extraction function) is given in
  1422. parentheses after each substring, followed by the name when the extraction was
  1423. by name.
  1424. .
  1425. .
  1426. .\" HTML <a name="substitution"></a>
  1427. .SS "Testing the substitution function"
  1428. .rs
  1429. .sp
  1430. If the \fBreplace\fP modifier is set, the \fBpcre2_substitute()\fP function is
  1431. called instead of one of the matching functions (or after one call of
  1432. \fBpcre2_match()\fP in the case of PCRE2_SUBSTITUTE_MATCHED). Note that
  1433. replacement strings cannot contain commas, because a comma signifies the end of
  1434. a modifier. This is not thought to be an issue in a test program.
  1435. .P
  1436. Specifying a completely empty replacement string disables this modifier.
  1437. However, it is possible to specify an empty replacement by providing a buffer
  1438. length, as described below, for an otherwise empty replacement.
  1439. .P
  1440. Unlike subject strings, \fBpcre2test\fP does not process replacement strings
  1441. for escape sequences. In UTF mode, a replacement string is checked to see if it
  1442. is a valid UTF-8 string. If so, it is correctly converted to a UTF string of
  1443. the appropriate code unit width. If it is not a valid UTF-8 string, the
  1444. individual code units are copied directly. This provides a means of passing an
  1445. invalid UTF-8 string for testing purposes.
  1446. .P
  1447. The following modifiers set options (in additional to the normal match options)
  1448. for \fBpcre2_substitute()\fP:
  1449. .sp
  1450. global PCRE2_SUBSTITUTE_GLOBAL
  1451. substitute_extended PCRE2_SUBSTITUTE_EXTENDED
  1452. substitute_literal PCRE2_SUBSTITUTE_LITERAL
  1453. substitute_matched PCRE2_SUBSTITUTE_MATCHED
  1454. substitute_overflow_length PCRE2_SUBSTITUTE_OVERFLOW_LENGTH
  1455. substitute_replacement_only PCRE2_SUBSTITUTE_REPLACEMENT_ONLY
  1456. substitute_unknown_unset PCRE2_SUBSTITUTE_UNKNOWN_UNSET
  1457. substitute_unset_empty PCRE2_SUBSTITUTE_UNSET_EMPTY
  1458. .sp
  1459. See the
  1460. .\" HREF
  1461. \fBpcre2api\fP
  1462. .\"
  1463. documentation for details of these options.
  1464. .P
  1465. After a successful substitution, the modified string is output, preceded by the
  1466. number of replacements. This may be zero if there were no matches. Here is a
  1467. simple example of a substitution test:
  1468. .sp
  1469. /abc/replace=xxx
  1470. =abc=abc=
  1471. 1: =xxx=abc=
  1472. =abc=abc=\e=global
  1473. 2: =xxx=xxx=
  1474. .sp
  1475. Subject and replacement strings should be kept relatively short (fewer than 256
  1476. characters) for substitution tests, as fixed-size buffers are used. To make it
  1477. easy to test for buffer overflow, if the replacement string starts with a
  1478. number in square brackets, that number is passed to \fBpcre2_substitute()\fP as
  1479. the size of the output buffer, with the replacement string starting at the next
  1480. character. Here is an example that tests the edge case:
  1481. .sp
  1482. /abc/
  1483. 123abc123\e=replace=[10]XYZ
  1484. 1: 123XYZ123
  1485. 123abc123\e=replace=[9]XYZ
  1486. Failed: error -47: no more memory
  1487. .sp
  1488. The default action of \fBpcre2_substitute()\fP is to return
  1489. PCRE2_ERROR_NOMEMORY when the output buffer is too small. However, if the
  1490. PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option is set (by using the
  1491. \fBsubstitute_overflow_length\fP modifier), \fBpcre2_substitute()\fP continues
  1492. to go through the motions of matching and substituting (but not doing any
  1493. callouts), in order to compute the size of buffer that is required. When this
  1494. happens, \fBpcre2test\fP shows the required buffer length (which includes space
  1495. for the trailing zero) as part of the error message. For example:
  1496. .sp
  1497. /abc/substitute_overflow_length
  1498. 123abc123\e=replace=[9]XYZ
  1499. Failed: error -47: no more memory: 10 code units are needed
  1500. .sp
  1501. A replacement string is ignored with POSIX and DFA matching. Specifying partial
  1502. matching provokes an error return ("bad option value") from
  1503. \fBpcre2_substitute()\fP.
  1504. .
  1505. .
  1506. .SS "Testing substitute callouts"
  1507. .rs
  1508. .sp
  1509. If the \fBsubstitute_callout\fP modifier is set, a substitution callout
  1510. function is set up. The \fBnull_context\fP modifier must not be set, because
  1511. the address of the callout function is passed in a match context. When the
  1512. callout function is called (after each substitution), details of the input
  1513. and output strings are output. For example:
  1514. .sp
  1515. /abc/g,replace=<$0>,substitute_callout
  1516. abcdefabcpqr
  1517. 1(1) Old 0 3 "abc" New 0 5 "<abc>"
  1518. 2(1) Old 6 9 "abc" New 8 13 "<abc>"
  1519. 2: <abc>def<abc>pqr
  1520. .sp
  1521. The first number on each callout line is the count of matches. The
  1522. parenthesized number is the number of pairs that are set in the ovector (that
  1523. is, one more than the number of capturing groups that were set). Then are
  1524. listed the offsets of the old substring, its contents, and the same for the
  1525. replacement.
  1526. .P
  1527. By default, the substitution callout function returns zero, which accepts the
  1528. replacement and causes matching to continue if /g was used. Two further
  1529. modifiers can be used to test other return values. If \fBsubstitute_skip\fP is
  1530. set to a value greater than zero the callout function returns +1 for the match
  1531. of that number, and similarly \fBsubstitute_stop\fP returns -1. These cause the
  1532. replacement to be rejected, and -1 causes no further matching to take place. If
  1533. either of them are set, \fBsubstitute_callout\fP is assumed. For example:
  1534. .sp
  1535. /abc/g,replace=<$0>,substitute_skip=1
  1536. abcdefabcpqr
  1537. 1(1) Old 0 3 "abc" New 0 5 "<abc> SKIPPED"
  1538. 2(1) Old 6 9 "abc" New 6 11 "<abc>"
  1539. 2: abcdef<abc>pqr
  1540. abcdefabcpqr\e=substitute_stop=1
  1541. 1(1) Old 0 3 "abc" New 0 5 "<abc> STOPPED"
  1542. 1: abcdefabcpqr
  1543. .sp
  1544. If both are set for the same number, stop takes precedence. Only a single skip
  1545. or stop is supported, which is sufficient for testing that the feature works.
  1546. .
  1547. .
  1548. .SS "Setting the JIT stack size"
  1549. .rs
  1550. .sp
  1551. The \fBjitstack\fP modifier provides a way of setting the maximum stack size
  1552. that is used by the just-in-time optimization code. It is ignored if JIT
  1553. optimization is not being used. The value is a number of kibibytes (units of
  1554. 1024 bytes). Setting zero reverts to the default of 32KiB. Providing a stack
  1555. that is larger than the default is necessary only for very complicated
  1556. patterns. If \fBjitstack\fP is set non-zero on a subject line it overrides any
  1557. value that was set on the pattern.
  1558. .
  1559. .
  1560. .SS "Setting heap, match, and depth limits"
  1561. .rs
  1562. .sp
  1563. The \fBheap_limit\fP, \fBmatch_limit\fP, and \fBdepth_limit\fP modifiers set
  1564. the appropriate limits in the match context. These values are ignored when the
  1565. \fBfind_limits\fP or \fBfind_limits_noheap\fP modifier is specified.
  1566. .
  1567. .
  1568. .SS "Finding minimum limits"
  1569. .rs
  1570. .sp
  1571. If the \fBfind_limits\fP modifier is present on a subject line, \fBpcre2test\fP
  1572. calls the relevant matching function several times, setting different values in
  1573. the match context via \fBpcre2_set_heap_limit()\fP,
  1574. \fBpcre2_set_match_limit()\fP, or \fBpcre2_set_depth_limit()\fP until it finds
  1575. the smallest value for each parameter that allows the match to complete without
  1576. a "limit exceeded" error. The match itself may succeed or fail. An alternative
  1577. modifier, \fBfind_limits_noheap\fP, omits the heap limit. This is used in the
  1578. standard tests, because the minimum heap limit varies between systems. If JIT
  1579. is being used, only the match limit is relevant, and the other two are
  1580. automatically omitted.
  1581. .P
  1582. When using this modifier, the pattern should not contain any limit settings
  1583. such as (*LIMIT_MATCH=...) within it. If such a setting is present and is
  1584. lower than the minimum matching value, the minimum value cannot be found
  1585. because \fBpcre2_set_match_limit()\fP etc. are only able to reduce the value of
  1586. an in-pattern limit; they cannot increase it.
  1587. .P
  1588. For non-DFA matching, the minimum \fIdepth_limit\fP number is a measure of how
  1589. much nested backtracking happens (that is, how deeply the pattern's tree is
  1590. searched). In the case of DFA matching, \fIdepth_limit\fP controls the depth of
  1591. recursive calls of the internal function that is used for handling pattern
  1592. recursion, lookaround assertions, and atomic groups.
  1593. .P
  1594. For non-DFA matching, the \fImatch_limit\fP number is a measure of the amount
  1595. of backtracking that takes place, and learning the minimum value can be
  1596. instructive. For most simple matches, the number is quite small, but for
  1597. patterns with very large numbers of matching possibilities, it can become large
  1598. very quickly with increasing length of subject string. In the case of DFA
  1599. matching, \fImatch_limit\fP controls the total number of calls, both recursive
  1600. and non-recursive, to the internal matching function, thus controlling the
  1601. overall amount of computing resource that is used.
  1602. .P
  1603. For both kinds of matching, the \fIheap_limit\fP number, which is in kibibytes
  1604. (units of 1024 bytes), limits the amount of heap memory used for matching.
  1605. .
  1606. .
  1607. .SS "Showing MARK names"
  1608. .rs
  1609. .sp
  1610. .P
  1611. The \fBmark\fP modifier causes the names from backtracking control verbs that
  1612. are returned from calls to \fBpcre2_match()\fP to be displayed. If a mark is
  1613. returned for a match, non-match, or partial match, \fBpcre2test\fP shows it.
  1614. For a match, it is on a line by itself, tagged with "MK:". Otherwise, it
  1615. is added to the non-match message.
  1616. .
  1617. .
  1618. .SS "Showing memory usage"
  1619. .rs
  1620. .sp
  1621. The \fBmemory\fP modifier causes \fBpcre2test\fP to log the sizes of all heap
  1622. memory allocation and freeing calls that occur during a call to
  1623. \fBpcre2_match()\fP or \fBpcre2_dfa_match()\fP. In the latter case, heap memory
  1624. is used only when a match requires more internal workspace that the default
  1625. allocation on the stack, so in many cases there will be no output. No heap
  1626. memory is allocated during matching with JIT. For this modifier to work, the
  1627. \fBnull_context\fP modifier must not be set on both the pattern and the
  1628. subject, though it can be set on one or the other.
  1629. .
  1630. .
  1631. .SS "Showing the heap frame overall vector size"
  1632. .rs
  1633. .sp
  1634. The \fBheapframes_size\fP modifier is relevant for matches using
  1635. \fBpcre2_match()\fP without JIT. After a match has run (whether successful or
  1636. not) the size, in bytes, of the allocated heap frames vector that is left
  1637. attached to the match data block is shown. If the matching action involved
  1638. several calls to \fBpcre2_match()\fP (for example, global matching or for
  1639. timing) only the final value is shown.
  1640. .P
  1641. This modifier is ignored, with a warning, for POSIX or DFA matching. JIT
  1642. matching does not use the heap frames vector, so the size is always zero,
  1643. unless there was a previous non-JIT match. Note that specifing a size of zero
  1644. for the output vector (see below) causes \fBpcre2test\fP to free its match data
  1645. block (and associated heap frames vector) and allocate a new one.
  1646. .
  1647. .
  1648. .SS "Setting a starting offset"
  1649. .rs
  1650. .sp
  1651. The \fBoffset\fP modifier sets an offset in the subject string at which
  1652. matching starts. Its value is a number of code units, not characters.
  1653. .
  1654. .
  1655. .SS "Setting an offset limit"
  1656. .rs
  1657. .sp
  1658. The \fBoffset_limit\fP modifier sets a limit for unanchored matches. If a match
  1659. cannot be found starting at or before this offset in the subject, a "no match"
  1660. return is given. The data value is a number of code units, not characters. When
  1661. this modifier is used, the \fBuse_offset_limit\fP modifier must have been set
  1662. for the pattern; if not, an error is generated.
  1663. .
  1664. .
  1665. .SS "Setting the size of the output vector"
  1666. .rs
  1667. .sp
  1668. The \fBovector\fP modifier applies only to the subject line in which it
  1669. appears, though of course it can also be used to set a default in a
  1670. \fB#subject\fP command. It specifies the number of pairs of offsets that are
  1671. available for storing matching information. The default is 15.
  1672. .P
  1673. A value of zero is useful when testing the POSIX API because it causes
  1674. \fBregexec()\fP to be called with a NULL capture vector. When not testing the
  1675. POSIX API, a value of zero is used to cause
  1676. \fBpcre2_match_data_create_from_pattern()\fP to be called, in order to create a
  1677. new match block of exactly the right size for the pattern. (It is not possible
  1678. to create a match block with a zero-length ovector; there is always at least
  1679. one pair of offsets.) The old match data block is freed.
  1680. .
  1681. .
  1682. .SS "Passing the subject as zero-terminated"
  1683. .rs
  1684. .sp
  1685. By default, the subject string is passed to a native API matching function with
  1686. its correct length. In order to test the facility for passing a zero-terminated
  1687. string, the \fBzero_terminate\fP modifier is provided. It causes the length to
  1688. be passed as PCRE2_ZERO_TERMINATED. When matching via the POSIX interface,
  1689. this modifier is ignored, with a warning.
  1690. .P
  1691. When testing \fBpcre2_substitute()\fP, this modifier also has the effect of
  1692. passing the replacement string as zero-terminated.
  1693. .
  1694. .
  1695. .SS "Passing a NULL context, subject, or replacement"
  1696. .rs
  1697. .sp
  1698. Normally, \fBpcre2test\fP passes a context block to \fBpcre2_match()\fP,
  1699. \fBpcre2_dfa_match()\fP, \fBpcre2_jit_match()\fP or \fBpcre2_substitute()\fP.
  1700. If the \fBnull_context\fP modifier is set, however, NULL is passed. This is for
  1701. testing that the matching and substitution functions behave correctly in this
  1702. case (they use default values). This modifier cannot be used with the
  1703. \fBfind_limits\fP, \fBfind_limits_noheap\fP, or \fBsubstitute_callout\fP
  1704. modifiers.
  1705. .P
  1706. Similarly, for testing purposes, if the \fBnull_subject\fP or
  1707. \fBnull_replacement\fP modifier is set, the subject or replacement string
  1708. pointers are passed as NULL, respectively, to the relevant functions.
  1709. .
  1710. .
  1711. .SH "THE ALTERNATIVE MATCHING FUNCTION"
  1712. .rs
  1713. .sp
  1714. By default, \fBpcre2test\fP uses the standard PCRE2 matching function,
  1715. \fBpcre2_match()\fP to match each subject line. PCRE2 also supports an
  1716. alternative matching function, \fBpcre2_dfa_match()\fP, which operates in a
  1717. different way, and has some restrictions. The differences between the two
  1718. functions are described in the
  1719. .\" HREF
  1720. \fBpcre2matching\fP
  1721. .\"
  1722. documentation.
  1723. .P
  1724. If the \fBdfa\fP modifier is set, the alternative matching function is used.
  1725. This function finds all possible matches at a given point in the subject. If,
  1726. however, the \fBdfa_shortest\fP modifier is set, processing stops after the
  1727. first match is found. This is always the shortest possible match.
  1728. .
  1729. .
  1730. .SH "DEFAULT OUTPUT FROM pcre2test"
  1731. .rs
  1732. .sp
  1733. This section describes the output when the normal matching function,
  1734. \fBpcre2_match()\fP, is being used.
  1735. .P
  1736. When a match succeeds, \fBpcre2test\fP outputs the list of captured substrings,
  1737. starting with number 0 for the string that matched the whole pattern.
  1738. Otherwise, it outputs "No match" when the return is PCRE2_ERROR_NOMATCH, or
  1739. "Partial match:" followed by the partially matching substring when the
  1740. return is PCRE2_ERROR_PARTIAL. (Note that this is the
  1741. entire substring that was inspected during the partial match; it may include
  1742. characters before the actual match start if a lookbehind assertion, \eK, \eb,
  1743. or \eB was involved.)
  1744. .P
  1745. For any other return, \fBpcre2test\fP outputs the PCRE2 negative error number
  1746. and a short descriptive phrase. If the error is a failed UTF string check, the
  1747. code unit offset of the start of the failing character is also output. Here is
  1748. an example of an interactive \fBpcre2test\fP run.
  1749. .sp
  1750. $ pcre2test
  1751. PCRE2 version 10.22 2016-07-29
  1752. .sp
  1753. re> /^abc(\ed+)/
  1754. data> abc123
  1755. 0: abc123
  1756. 1: 123
  1757. data> xyz
  1758. No match
  1759. .sp
  1760. Unset capturing substrings that are not followed by one that is set are not
  1761. shown by \fBpcre2test\fP unless the \fBallcaptures\fP modifier is specified. In
  1762. the following example, there are two capturing substrings, but when the first
  1763. data line is matched, the second, unset substring is not shown. An "internal"
  1764. unset substring is shown as "<unset>", as for the second data line.
  1765. .sp
  1766. re> /(a)|(b)/
  1767. data> a
  1768. 0: a
  1769. 1: a
  1770. data> b
  1771. 0: b
  1772. 1: <unset>
  1773. 2: b
  1774. .sp
  1775. If the strings contain any non-printing characters, they are output as \exhh
  1776. escapes if the value is less than 256 and UTF mode is not set. Otherwise they
  1777. are output as \ex{hh...} escapes. See below for the definition of non-printing
  1778. characters. If the \fBaftertext\fP modifier is set, the output for substring 0
  1779. is followed by the rest of the subject string, identified by "0+" like this:
  1780. .sp
  1781. re> /cat/aftertext
  1782. data> cataract
  1783. 0: cat
  1784. 0+ aract
  1785. .sp
  1786. If global matching is requested, the results of successive matching attempts
  1787. are output in sequence, like this:
  1788. .sp
  1789. re> /\eBi(\ew\ew)/g
  1790. data> Mississippi
  1791. 0: iss
  1792. 1: ss
  1793. 0: iss
  1794. 1: ss
  1795. 0: ipp
  1796. 1: pp
  1797. .sp
  1798. "No match" is output only if the first match attempt fails. Here is an example
  1799. of a failure message (the offset 4 that is specified by the \fBoffset\fP
  1800. modifier is past the end of the subject string):
  1801. .sp
  1802. re> /xyz/
  1803. data> xyz\e=offset=4
  1804. Error -24 (bad offset value)
  1805. .P
  1806. Note that whereas patterns can be continued over several lines (a plain ">"
  1807. prompt is used for continuations), subject lines may not. However newlines can
  1808. be included in a subject by means of the \en escape (or \er, \er\en, etc.,
  1809. depending on the newline sequence setting).
  1810. .
  1811. .
  1812. .
  1813. .SH "OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION"
  1814. .rs
  1815. .sp
  1816. When the alternative matching function, \fBpcre2_dfa_match()\fP, is used, the
  1817. output consists of a list of all the matches that start at the first point in
  1818. the subject where there is at least one match. For example:
  1819. .sp
  1820. re> /(tang|tangerine|tan)/
  1821. data> yellow tangerine\e=dfa
  1822. 0: tangerine
  1823. 1: tang
  1824. 2: tan
  1825. .sp
  1826. Using the normal matching function on this data finds only "tang". The
  1827. longest matching string is always given first (and numbered zero). After a
  1828. PCRE2_ERROR_PARTIAL return, the output is "Partial match:", followed by the
  1829. partially matching substring. Note that this is the entire substring that was
  1830. inspected during the partial match; it may include characters before the actual
  1831. match start if a lookbehind assertion, \eb, or \eB was involved. (\eK is not
  1832. supported for DFA matching.)
  1833. .P
  1834. If global matching is requested, the search for further matches resumes
  1835. at the end of the longest match. For example:
  1836. .sp
  1837. re> /(tang|tangerine|tan)/g
  1838. data> yellow tangerine and tangy sultana\e=dfa
  1839. 0: tangerine
  1840. 1: tang
  1841. 2: tan
  1842. 0: tang
  1843. 1: tan
  1844. 0: tan
  1845. .sp
  1846. The alternative matching function does not support substring capture, so the
  1847. modifiers that are concerned with captured substrings are not relevant.
  1848. .
  1849. .
  1850. .SH "RESTARTING AFTER A PARTIAL MATCH"
  1851. .rs
  1852. .sp
  1853. When the alternative matching function has given the PCRE2_ERROR_PARTIAL
  1854. return, indicating that the subject partially matched the pattern, you can
  1855. restart the match with additional subject data by means of the
  1856. \fBdfa_restart\fP modifier. For example:
  1857. .sp
  1858. re> /^\ed?\ed(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\ed\ed$/
  1859. data> 23ja\e=ps,dfa
  1860. Partial match: 23ja
  1861. data> n05\e=dfa,dfa_restart
  1862. 0: n05
  1863. .sp
  1864. For further information about partial matching, see the
  1865. .\" HREF
  1866. \fBpcre2partial\fP
  1867. .\"
  1868. documentation.
  1869. .
  1870. .
  1871. .\" HTML <a name="callouts"></a>
  1872. .SH CALLOUTS
  1873. .rs
  1874. .sp
  1875. If the pattern contains any callout requests, \fBpcre2test\fP's callout
  1876. function is called during matching unless \fBcallout_none\fP is specified. This
  1877. works with both matching functions, and with JIT, though there are some
  1878. differences in behaviour. The output for callouts with numerical arguments and
  1879. those with string arguments is slightly different.
  1880. .
  1881. .
  1882. .SS "Callouts with numerical arguments"
  1883. .rs
  1884. .sp
  1885. By default, the callout function displays the callout number, the start and
  1886. current positions in the subject text at the callout time, and the next pattern
  1887. item to be tested. For example:
  1888. .sp
  1889. --->pqrabcdef
  1890. 0 ^ ^ \ed
  1891. .sp
  1892. This output indicates that callout number 0 occurred for a match attempt
  1893. starting at the fourth character of the subject string, when the pointer was at
  1894. the seventh character, and when the next pattern item was \ed. Just
  1895. one circumflex is output if the start and current positions are the same, or if
  1896. the current position precedes the start position, which can happen if the
  1897. callout is in a lookbehind assertion.
  1898. .P
  1899. Callouts numbered 255 are assumed to be automatic callouts, inserted as a
  1900. result of the \fBauto_callout\fP pattern modifier. In this case, instead of
  1901. showing the callout number, the offset in the pattern, preceded by a plus, is
  1902. output. For example:
  1903. .sp
  1904. re> /\ed?[A-E]\e*/auto_callout
  1905. data> E*
  1906. --->E*
  1907. +0 ^ \ed?
  1908. +3 ^ [A-E]
  1909. +8 ^^ \e*
  1910. +10 ^ ^
  1911. 0: E*
  1912. .sp
  1913. If a pattern contains (*MARK) items, an additional line is output whenever
  1914. a change of latest mark is passed to the callout function. For example:
  1915. .sp
  1916. re> /a(*MARK:X)bc/auto_callout
  1917. data> abc
  1918. --->abc
  1919. +0 ^ a
  1920. +1 ^^ (*MARK:X)
  1921. +10 ^^ b
  1922. Latest Mark: X
  1923. +11 ^ ^ c
  1924. +12 ^ ^
  1925. 0: abc
  1926. .sp
  1927. The mark changes between matching "a" and "b", but stays the same for the rest
  1928. of the match, so nothing more is output. If, as a result of backtracking, the
  1929. mark reverts to being unset, the text "<unset>" is output.
  1930. .
  1931. .
  1932. .SS "Callouts with string arguments"
  1933. .rs
  1934. .sp
  1935. The output for a callout with a string argument is similar, except that instead
  1936. of outputting a callout number before the position indicators, the callout
  1937. string and its offset in the pattern string are output before the reflection of
  1938. the subject string, and the subject string is reflected for each callout. For
  1939. example:
  1940. .sp
  1941. re> /^ab(?C'first')cd(?C"second")ef/
  1942. data> abcdefg
  1943. Callout (7): 'first'
  1944. --->abcdefg
  1945. ^ ^ c
  1946. Callout (20): "second"
  1947. --->abcdefg
  1948. ^ ^ e
  1949. 0: abcdef
  1950. .sp
  1951. .
  1952. .
  1953. .SS "Callout modifiers"
  1954. .rs
  1955. .sp
  1956. The callout function in \fBpcre2test\fP returns zero (carry on matching) by
  1957. default, but you can use a \fBcallout_fail\fP modifier in a subject line to
  1958. change this and other parameters of the callout (see below).
  1959. .P
  1960. If the \fBcallout_capture\fP modifier is set, the current captured groups are
  1961. output when a callout occurs. This is useful only for non-DFA matching, as
  1962. \fBpcre2_dfa_match()\fP does not support capturing, so no captures are ever
  1963. shown.
  1964. .P
  1965. The normal callout output, showing the callout number or pattern offset (as
  1966. described above) is suppressed if the \fBcallout_no_where\fP modifier is set.
  1967. .P
  1968. When using the interpretive matching function \fBpcre2_match()\fP without JIT,
  1969. setting the \fBcallout_extra\fP modifier causes additional output from
  1970. \fBpcre2test\fP's callout function to be generated. For the first callout in a
  1971. match attempt at a new starting position in the subject, "New match attempt" is
  1972. output. If there has been a backtrack since the last callout (or start of
  1973. matching if this is the first callout), "Backtrack" is output, followed by "No
  1974. other matching paths" if the backtrack ended the previous match attempt. For
  1975. example:
  1976. .sp
  1977. re> /(a+)b/auto_callout,no_start_optimize,no_auto_possess
  1978. data> aac\e=callout_extra
  1979. New match attempt
  1980. --->aac
  1981. +0 ^ (
  1982. +1 ^ a+
  1983. +3 ^ ^ )
  1984. +4 ^ ^ b
  1985. Backtrack
  1986. --->aac
  1987. +3 ^^ )
  1988. +4 ^^ b
  1989. Backtrack
  1990. No other matching paths
  1991. New match attempt
  1992. --->aac
  1993. +0 ^ (
  1994. +1 ^ a+
  1995. +3 ^^ )
  1996. +4 ^^ b
  1997. Backtrack
  1998. No other matching paths
  1999. New match attempt
  2000. --->aac
  2001. +0 ^ (
  2002. +1 ^ a+
  2003. Backtrack
  2004. No other matching paths
  2005. New match attempt
  2006. --->aac
  2007. +0 ^ (
  2008. +1 ^ a+
  2009. No match
  2010. .sp
  2011. Notice that various optimizations must be turned off if you want all possible
  2012. matching paths to be scanned. If \fBno_start_optimize\fP is not used, there is
  2013. an immediate "no match", without any callouts, because the starting
  2014. optimization fails to find "b" in the subject, which it knows must be present
  2015. for any match. If \fBno_auto_possess\fP is not used, the "a+" item is turned
  2016. into "a++", which reduces the number of backtracks.
  2017. .P
  2018. The \fBcallout_extra\fP modifier has no effect if used with the DFA matching
  2019. function, or with JIT.
  2020. .
  2021. .
  2022. .SS "Return values from callouts"
  2023. .rs
  2024. .sp
  2025. The default return from the callout function is zero, which allows matching to
  2026. continue. The \fBcallout_fail\fP modifier can be given one or two numbers. If
  2027. there is only one number, 1 is returned instead of 0 (causing matching to
  2028. backtrack) when a callout of that number is reached. If two numbers (<n>:<m>)
  2029. are given, 1 is returned when callout <n> is reached and there have been at
  2030. least <m> callouts. The \fBcallout_error\fP modifier is similar, except that
  2031. PCRE2_ERROR_CALLOUT is returned, causing the entire matching process to be
  2032. aborted. If both these modifiers are set for the same callout number,
  2033. \fBcallout_error\fP takes precedence. Note that callouts with string arguments
  2034. are always given the number zero.
  2035. .P
  2036. The \fBcallout_data\fP modifier can be given an unsigned or a negative number.
  2037. This is set as the "user data" that is passed to the matching function, and
  2038. passed back when the callout function is invoked. Any value other than zero is
  2039. used as a return from \fBpcre2test\fP's callout function.
  2040. .P
  2041. Inserting callouts can be helpful when using \fBpcre2test\fP to check
  2042. complicated regular expressions. For further information about callouts, see
  2043. the
  2044. .\" HREF
  2045. \fBpcre2callout\fP
  2046. .\"
  2047. documentation.
  2048. .
  2049. .
  2050. .
  2051. .SH "NON-PRINTING CHARACTERS"
  2052. .rs
  2053. .sp
  2054. When \fBpcre2test\fP is outputting text in the compiled version of a pattern,
  2055. bytes other than 32-126 are always treated as non-printing characters and are
  2056. therefore shown as hex escapes.
  2057. .P
  2058. When \fBpcre2test\fP is outputting text that is a matched part of a subject
  2059. string, it behaves in the same way, unless a different locale has been set for
  2060. the pattern (using the \fBlocale\fP modifier). In this case, the
  2061. \fBisprint()\fP function is used to distinguish printing and non-printing
  2062. characters.
  2063. .
  2064. .
  2065. .
  2066. .\" HTML <a name="saverestore"></a>
  2067. .SH "SAVING AND RESTORING COMPILED PATTERNS"
  2068. .rs
  2069. .sp
  2070. It is possible to save compiled patterns on disc or elsewhere, and reload them
  2071. later, subject to a number of restrictions. JIT data cannot be saved. The host
  2072. on which the patterns are reloaded must be running the same version of PCRE2,
  2073. with the same code unit width, and must also have the same endianness, pointer
  2074. width and PCRE2_SIZE type. Before compiled patterns can be saved they must be
  2075. serialized, that is, converted to a stream of bytes. A single byte stream may
  2076. contain any number of compiled patterns, but they must all use the same
  2077. character tables. A single copy of the tables is included in the byte stream
  2078. (its size is 1088 bytes).
  2079. .P
  2080. The functions whose names begin with \fBpcre2_serialize_\fP are used
  2081. for serializing and de-serializing. They are described in the
  2082. .\" HREF
  2083. \fBpcre2serialize\fP
  2084. .\"
  2085. documentation. In this section we describe the features of \fBpcre2test\fP that
  2086. can be used to test these functions.
  2087. .P
  2088. Note that "serialization" in PCRE2 does not convert compiled patterns to an
  2089. abstract format like Java or .NET. It just makes a reloadable byte code stream.
  2090. Hence the restrictions on reloading mentioned above.
  2091. .P
  2092. In \fBpcre2test\fP, when a pattern with \fBpush\fP modifier is successfully
  2093. compiled, it is pushed onto a stack of compiled patterns, and \fBpcre2test\fP
  2094. expects the next line to contain a new pattern (or command) instead of a
  2095. subject line. By contrast, the \fBpushcopy\fP modifier causes a copy of the
  2096. compiled pattern to be stacked, leaving the original available for immediate
  2097. matching. By using \fBpush\fP and/or \fBpushcopy\fP, a number of patterns can
  2098. be compiled and retained. These modifiers are incompatible with \fBposix\fP,
  2099. and control modifiers that act at match time are ignored (with a message) for
  2100. the stacked patterns. The \fBjitverify\fP modifier applies only at compile
  2101. time.
  2102. .P
  2103. The command
  2104. .sp
  2105. #save <filename>
  2106. .sp
  2107. causes all the stacked patterns to be serialized and the result written to the
  2108. named file. Afterwards, all the stacked patterns are freed. The command
  2109. .sp
  2110. #load <filename>
  2111. .sp
  2112. reads the data in the file, and then arranges for it to be de-serialized, with
  2113. the resulting compiled patterns added to the pattern stack. The pattern on the
  2114. top of the stack can be retrieved by the #pop command, which must be followed
  2115. by lines of subjects that are to be matched with the pattern, terminated as
  2116. usual by an empty line or end of file. This command may be followed by a
  2117. modifier list containing only
  2118. .\" HTML <a href="#controlmodifiers">
  2119. .\" </a>
  2120. control modifiers
  2121. .\"
  2122. that act after a pattern has been compiled. In particular, \fBhex\fP,
  2123. \fBposix\fP, \fBposix_nosub\fP, \fBpush\fP, and \fBpushcopy\fP are not allowed,
  2124. nor are any
  2125. .\" HTML <a href="#optionmodifiers">
  2126. .\" </a>
  2127. option-setting modifiers.
  2128. .\"
  2129. The JIT modifiers are, however permitted. Here is an example that saves and
  2130. reloads two patterns.
  2131. .sp
  2132. /abc/push
  2133. /xyz/push
  2134. #save tempfile
  2135. #load tempfile
  2136. #pop info
  2137. xyz
  2138. .sp
  2139. #pop jit,bincode
  2140. abc
  2141. .sp
  2142. If \fBjitverify\fP is used with #pop, it does not automatically imply
  2143. \fBjit\fP, which is different behaviour from when it is used on a pattern.
  2144. .P
  2145. The #popcopy command is analogous to the \fBpushcopy\fP modifier in that it
  2146. makes current a copy of the topmost stack pattern, leaving the original still
  2147. on the stack.
  2148. .
  2149. .
  2150. .
  2151. .SH "SEE ALSO"
  2152. .rs
  2153. .sp
  2154. \fBpcre2\fP(3), \fBpcre2api\fP(3), \fBpcre2callout\fP(3),
  2155. \fBpcre2jit\fP, \fBpcre2matching\fP(3), \fBpcre2partial\fP(d),
  2156. \fBpcre2pattern\fP(3), \fBpcre2serialize\fP(3).
  2157. .
  2158. .
  2159. .SH AUTHOR
  2160. .rs
  2161. .sp
  2162. .nf
  2163. Philip Hazel
  2164. Retired from University Computing Service
  2165. Cambridge, England.
  2166. .fi
  2167. .
  2168. .
  2169. .SH REVISION
  2170. .rs
  2171. .sp
  2172. .nf
  2173. Last updated: 27 January 2024
  2174. Copyright (c) 1997-2024 University of Cambridge.
  2175. .fi