pcre2test.1 87 KB

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