pcre2test.1 87 KB

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