1PCRE2TEST(1)                General Commands Manual               PCRE2TEST(1)
2
3
4

NAME

6       pcre2test - a program for testing Perl-compatible regular expressions.
7

SYNOPSIS

9
10       pcre2test [options] [input file [output file]]
11
12       pcre2test is a test program for the PCRE2 regular expression libraries,
13       but it can also be used for  experimenting  with  regular  expressions.
14       This  document  describes the features of the test program; for details
15       of the regular expressions themselves, see the pcre2pattern  documenta‐
16       tion.  For  details  of  the  PCRE2  library  function  calls and their
17       options, see the pcre2api documentation.
18
19       The input for pcre2test is a sequence of  regular  expression  patterns
20       and  subject  strings  to  be matched. There are also command lines for
21       setting defaults and controlling some special actions. The output shows
22       the  result  of  each  match attempt. Modifiers on external or internal
23       command lines, the patterns, and the subject lines specify PCRE2  func‐
24       tion  options, control how the subject is processed, and what output is
25       produced.
26
27       As the original fairly simple PCRE library evolved,  it  acquired  many
28       different  features,  and  as  a  result, the original pcretest program
29       ended up with a lot of options in a messy, arcane  syntax  for  testing
30       all the features. The move to the new PCRE2 API provided an opportunity
31       to re-implement the test program as pcre2test, with a cleaner  modifier
32       syntax.  Nevertheless,  there are still many obscure modifiers, some of
33       which are specifically designed for use in conjunction  with  the  test
34       script  and  data  files that are distributed as part of PCRE2. All the
35       modifiers are documented here, some  without  much  justification,  but
36       many  of  them  are  unlikely  to  be  of  use  except when testing the
37       libraries.
38

PCRE2's 8-BIT, 16-BIT AND 32-BIT LIBRARIES

40
41       Different versions of the PCRE2 library can be built to support charac‐
42       ter  strings  that  are encoded in 8-bit, 16-bit, or 32-bit code units.
43       One, two, or  all  three  of  these  libraries  may  be  simultaneously
44       installed. The pcre2test program can be used to test all the libraries.
45       However, its own input and output are  always  in  8-bit  format.  When
46       testing  the  16-bit  or 32-bit libraries, patterns and subject strings
47       are converted to 16-bit or 32-bit format before  being  passed  to  the
48       library  functions.  Results are converted back to 8-bit code units for
49       output.
50
51       In the rest of this document, the names of library functions and struc‐
52       tures  are  given  in  generic  form,  for example, pcre_compile(). The
53       actual names used in the libraries have a suffix _8, _16,  or  _32,  as
54       appropriate.
55

INPUT ENCODING

57
58       Input  to  pcre2test is processed line by line, either by calling the C
59       library's fgets() function, or via the  libreadline  library.  In  some
60       Windows  environments  character 26 (hex 1A) causes an immediate end of
61       file, and no further data is read, so this character should be  avoided
62       unless you really want that action.
63
64       The  input  is  processed using using C's string functions, so must not
65       contain binary zeroes, even though in Unix-like  environments,  fgets()
66       treats  any  bytes  other  than newline as data characters. An error is
67       generated if a binary zero is encountered. Subject lines are  processed
68       for  backslash  escapes,  which  makes  it possible to include any data
69       value in strings that are passed to the library for matching. For  pat‐
70       terns,  there  is  a  facility  for specifying some or all of the 8-bit
71       input characters as hexadecimal  pairs,  which  makes  it  possible  to
72       include binary zeros.
73
74   Input for the 16-bit and 32-bit libraries
75
76       When testing the 16-bit or 32-bit libraries, there is a need to be able
77       to generate character code points greater than 255 in the strings  that
78       are  passed to the library. For subject lines, backslash escapes can be
79       used. In addition, when the  utf  modifier  (see  "Setting  compilation
80       options" below) is set, the pattern and any following subject lines are
81       interpreted as UTF-8 strings and translated  to  UTF-16  or  UTF-32  as
82       appropriate.
83
84       For  non-UTF testing of wide characters, the utf8_input modifier can be
85       used. This is mutually exclusive with  utf,  and  is  allowed  only  in
86       16-bit  or  32-bit  mode.  It  causes the pattern and following subject
87       lines to be treated as UTF-8 according to the original definition  (RFC
88       2279), which allows for character values up to 0x7fffffff. Each charac‐
89       ter is placed in one 16-bit or 32-bit code unit (in  the  16-bit  case,
90       values greater than 0xffff cause an error to occur).
91
92       UTF-8  is  not  capable of encoding values greater than 0x7fffffff, but
93       such values can be handled by the 32-bit  library.  When  testing  this
94       library  in  non-UTF mode with utf8_input set, if any character is pre‐
95       ceded by the byte 0xff (which is an illegal byte in  UTF-8)  0x80000000
96       is added to the character's value. This is the only way of passing such
97       code points in a pattern string. For subject strings, using  an  escape
98       sequence is preferable.
99

COMMAND LINE OPTIONS

101
102       -8        If the 8-bit library has been built, this option causes it to
103                 be used (this is the default). If the 8-bit library  has  not
104                 been built, this option causes an error.
105
106       -16       If  the  16-bit library has been built, this option causes it
107                 to be used. If only the 16-bit library has been  built,  this
108                 is  the  default.  If  the 16-bit library has not been built,
109                 this option causes an error.
110
111       -32       If the 32-bit library has been built, this option  causes  it
112                 to  be  used. If only the 32-bit library has been built, this
113                 is the default. If the 32-bit library  has  not  been  built,
114                 this option causes an error.
115
116       -ac       Behave as if each pattern has the auto_callout modifier, that
117                 is, insert automatic callouts into every pattern that is com‐
118                 piled.
119
120       -b        Behave  as  if each pattern has the fullbincode modifier; the
121                 full internal binary form of the pattern is output after com‐
122                 pilation.
123
124       -C        Output  the  version  number  of  the  PCRE2 library, and all
125                 available information about the optional  features  that  are
126                 included,  and  then  exit  with  zero  exit  code. All other
127                 options are ignored.
128
129       -C option Output information about a specific build-time  option,  then
130                 exit.  This functionality is intended for use in scripts such
131                 as RunTest. The following options output the  value  and  set
132                 the exit code as indicated:
133
134                   ebcdic-nl  the code for LF (= NL) in an EBCDIC environment:
135                                0x15 or 0x25
136                                0 if used in an ASCII environment
137                                exit code is always 0
138                   linksize   the configured internal link size (2, 3, or 4)
139                                exit code is set to the link size
140                   newline    the default newline setting:
141                                CR, LF, CRLF, ANYCRLF, or ANY
142                                exit code is always 0
143                   bsr        the default setting for what \R matches:
144                                ANYCRLF or ANY
145                                exit code is always 0
146
147                 The  following  options output 1 for true or 0 for false, and
148                 set the exit code to the same value:
149
150                   backslash-C  \C is supported (not locked out)
151                   ebcdic       compiled for an EBCDIC environment
152                   jit          just-in-time support is available
153                   pcre2-16     the 16-bit library was built
154                   pcre2-32     the 32-bit library was built
155                   pcre2-8      the 8-bit library was built
156                   unicode      Unicode support is available
157
158                 If an unknown option is given, an error  message  is  output;
159                 the exit code is 0.
160
161       -d        Behave  as if each pattern has the debug modifier; the inter‐
162                 nal form and information about the compiled pattern is output
163                 after compilation; -d is equivalent to -b -i.
164
165       -dfa      Behave as if each subject line has the dfa modifier; matching
166                 is done using the pcre2_dfa_match() function instead  of  the
167                 default pcre2_match().
168
169       -error number[,number,...]
170                 Call  pcre2_get_error_message() for each of the error numbers
171                 in the comma-separated list, display the  resulting  messages
172                 on  the  standard  output, then exit with zero exit code. The
173                 numbers may be positive or negative. This  is  a  convenience
174                 facility for PCRE2 maintainers.
175
176       -help     Output a brief summary these options and then exit.
177
178       -i        Behave  as if each pattern has the info modifier; information
179                 about the compiled pattern is given after compilation.
180
181       -jit      Behave as if each pattern line has the  jit  modifier;  after
182                 successful  compilation,  each pattern is passed to the just-
183                 in-time compiler, if available.
184
185       -pattern modifier-list
186                 Behave as if each pattern line contains the given modifiers.
187
188       -q        Do not output the version number of pcre2test at the start of
189                 execution.
190
191       -S size   On  Unix-like  systems, set the size of the run-time stack to
192                 size megabytes.
193
194       -subject modifier-list
195                 Behave as if each subject line contains the given modifiers.
196
197       -t        Run each compile and match many times with a timer, and  out‐
198                 put  the  resulting  times  per compile or match. When JIT is
199                 used, separate times are given for the  initial  compile  and
200                 the  JIT  compile.  You  can control the number of iterations
201                 that are used for timing by following -t with a number (as  a
202                 separate  item  on  the command line). For example, "-t 1000"
203                 iterates 1000 times. The default is to iterate 500,000 times.
204
205       -tm       This is like -t except that it times only the matching phase,
206                 not the compile phase.
207
208       -T -TM    These  behave like -t and -tm, but in addition, at the end of
209                 a run, the total times for all compiles and matches are  out‐
210                 put.
211
212       -version  Output the PCRE2 version number and then exit.
213

DESCRIPTION

215
216       If  pcre2test  is given two filename arguments, it reads from the first
217       and writes to the second. If the first name is "-", input is taken from
218       the  standard  input. If pcre2test is given only one argument, it reads
219       from that file and writes to stdout. Otherwise, it reads from stdin and
220       writes to stdout.
221
222       When  pcre2test  is  built,  a configuration option can specify that it
223       should be linked with the libreadline or libedit library. When this  is
224       done,  if the input is from a terminal, it is read using the readline()
225       function. This provides line-editing and history facilities. The output
226       from the -help option states whether or not readline() will be used.
227
228       The  program  handles  any number of tests, each of which consists of a
229       set of input lines. Each set starts with a regular expression  pattern,
230       followed by any number of subject lines to be matched against that pat‐
231       tern. In between sets of test data, command lines that begin with # may
232       appear. This file format, with some restrictions, can also be processed
233       by the perltest.sh script that is distributed with PCRE2 as a means  of
234       checking that the behaviour of PCRE2 and Perl is the same.
235
236       When the input is a terminal, pcre2test prompts for each line of input,
237       using "re>" to prompt for regular expression patterns, and  "data>"  to
238       prompt  for subject lines. Command lines starting with # can be entered
239       only in response to the "re>" prompt.
240
241       Each subject line is matched separately and independently. If you  want
242       to do multi-line matches, you have to use the \n escape sequence (or \r
243       or \r\n, etc., depending on the newline setting) in a  single  line  of
244       input  to encode the newline sequences. There is no limit on the length
245       of subject lines; the input buffer is automatically extended if  it  is
246       too  small.  There  are  replication features that makes it possible to
247       generate long repetitive pattern or subject  lines  without  having  to
248       supply them explicitly.
249
250       An  empty  line  or  the end of the file signals the end of the subject
251       lines for a test, at which point a  new  pattern  or  command  line  is
252       expected if there is still input to be read.
253

COMMAND LINES

255
256       In  between sets of test data, a line that begins with # is interpreted
257       as a command line. If the first character is followed by white space or
258       an  exclamation  mark,  the  line is treated as a comment, and ignored.
259       Otherwise, the following commands are recognized:
260
261         #forbid_utf
262
263       Subsequent  patterns  automatically  have   the   PCRE2_NEVER_UTF   and
264       PCRE2_NEVER_UCP  options  set, which locks out the use of the PCRE2_UTF
265       and PCRE2_UCP options and the use of (*UTF) and (*UCP) at the start  of
266       patterns.  This  command  also  forces an error if a subsequent pattern
267       contains any occurrences of \P, \p, or \X, which  are  still  supported
268       when  PCRE2_UTF  is not set, but which require Unicode property support
269       to be included in the library.
270
271       This is a trigger guard that is used in test files to ensure  that  UTF
272       or  Unicode property tests are not accidentally added to files that are
273       used when Unicode support is  not  included  in  the  library.  Setting
274       PCRE2_NEVER_UTF  and  PCRE2_NEVER_UCP as a default can also be obtained
275       by the use of #pattern; the difference is that  #forbid_utf  cannot  be
276       unset,  and the automatic options are not displayed in pattern informa‐
277       tion, to avoid cluttering up test output.
278
279         #load <filename>
280
281       This command is used to load a set of precompiled patterns from a file,
282       as  described  in  the  section entitled "Saving and restoring compiled
283       patterns" below.
284
285         #newline_default [<newline-list>]
286
287       When PCRE2 is built, a default newline  convention  can  be  specified.
288       This  determines which characters and/or character pairs are recognized
289       as indicating a newline in a pattern or subject string. The default can
290       be  overridden when a pattern is compiled. The standard test files con‐
291       tain tests of various newline conventions,  but  the  majority  of  the
292       tests  expect  a  single  linefeed  to  be  recognized  as a newline by
293       default. Without special action the tests would fail when PCRE2 is com‐
294       piled with either CR or CRLF as the default newline.
295
296       The #newline_default command specifies a list of newline types that are
297       acceptable as the default. The types must be one of CR, LF, CRLF,  ANY‐
298       CRLF, or ANY (in upper or lower case), for example:
299
300         #newline_default LF Any anyCRLF
301
302       If the default newline is in the list, this command has no effect. Oth‐
303       erwise, except when testing the POSIX  API,  a  newline  modifier  that
304       specifies  the  first  newline  convention in the list (LF in the above
305       example) is added to any pattern that does not already have  a  newline
306       modifier. If the newline list is empty, the feature is turned off. This
307       command is present in a number of the standard test input files.
308
309       When the POSIX API is being tested there is  no  way  to  override  the
310       default  newline  convention,  though it is possible to set the newline
311       convention from within the pattern. A warning is  given  if  the  posix
312       modifier is used when #newline_default would set a default for the non-
313       POSIX API.
314
315         #pattern <modifier-list>
316
317       This command sets a default modifier list that applies  to  all  subse‐
318       quent patterns. Modifiers on a pattern can change these settings.
319
320         #perltest
321
322       The  appearance of this line causes all subsequent modifier settings to
323       be checked for compatibility with the perltest.sh script, which is used
324       to  confirm that Perl gives the same results as PCRE2. Also, apart from
325       comment lines, none of the other command lines are  permitted,  because
326       they  and  many  of the modifiers are specific to pcre2test, and should
327       not be used in test files that are also processed by  perltest.sh.  The
328       #perltest  command  helps detect tests that are accidentally put in the
329       wrong file.
330
331         #pop [<modifiers>]
332         #popcopy [<modifiers>]
333
334       These commands are used to manipulate the stack of  compiled  patterns,
335       as  described  in  the  section entitled "Saving and restoring compiled
336       patterns" below.
337
338         #save <filename>
339
340       This command is used to save a set of compiled patterns to a  file,  as
341       described  in  the section entitled "Saving and restoring compiled pat‐
342       terns" below.
343
344         #subject <modifier-list>
345
346       This command sets a default modifier list that applies  to  all  subse‐
347       quent  subject lines. Modifiers on a subject line can change these set‐
348       tings.
349

MODIFIER SYNTAX

351
352       Modifier lists are used with both pattern and subject lines. Items in a
353       list are separated by commas followed by optional white space. Trailing
354       whitespace in a modifier list is ignored. Some modifiers may  be  given
355       for  both patterns and subject lines, whereas others are valid only for
356       one  or  the  other.  Each  modifier  has  a  long  name,  for  example
357       "anchored",  and  some of them must be followed by an equals sign and a
358       value, for example, "offset=12". Values cannot  contain  comma  charac‐
359       ters,  but may contain spaces. Modifiers that do not take values may be
360       preceded by a minus sign to turn off a previous setting.
361
362       A few of the more common modifiers can also be specified as single let‐
363       ters,  for  example "i" for "caseless". In documentation, following the
364       Perl convention, these are written with a slash ("the /i modifier") for
365       clarity.  Abbreviated  modifiers  must all be concatenated in the first
366       item of a modifier list. If the first item is not recognized as a  long
367       modifier  name, it is interpreted as a sequence of these abbreviations.
368       For example:
369
370         /abc/ig,newline=cr,jit=3
371
372       This is a pattern line whose modifier list starts with  two  one-letter
373       modifiers  (/i  and  /g).  The lower-case abbreviated modifiers are the
374       same as used in Perl.
375

PATTERN SYNTAX

377
378       A pattern line must start with one of the following characters  (common
379       symbols, excluding pattern meta-characters):
380
381         / ! " ' ` - = _ : ; , % & @ ~
382
383       This  is  interpreted  as the pattern's delimiter. A regular expression
384       may be continued over several input lines, in which  case  the  newline
385       characters are included within it. It is possible to include the delim‐
386       iter within the pattern by escaping it with a backslash, for example
387
388         /abc\/def/
389
390       If you do this, the escape and the delimiter form part of the  pattern,
391       but since the delimiters are all non-alphanumeric, this does not affect
392       its interpretation. If the terminating delimiter  is  immediately  fol‐
393       lowed by a backslash, for example,
394
395         /abc/\
396
397       then  a  backslash  is added to the end of the pattern. This is done to
398       provide a way of testing the error condition that arises if  a  pattern
399       finishes with a backslash, because
400
401         /abc\/
402
403       is  interpreted as the first line of a pattern that starts with "abc/",
404       causing pcre2test to read the next line as a continuation of the  regu‐
405       lar expression.
406
407       A pattern can be followed by a modifier list (details below).
408

SUBJECT LINE SYNTAX

410
411       Before    each   subject   line   is   passed   to   pcre2_match()   or
412       pcre2_dfa_match(), leading and trailing white space is removed, and the
413       line is scanned for backslash escapes. The following provide a means of
414       encoding non-printing characters in a visible way:
415
416         \a         alarm (BEL, \x07)
417         \b         backspace (\x08)
418         \e         escape (\x27)
419         \f         form feed (\x0c)
420         \n         newline (\x0a)
421         \r         carriage return (\x0d)
422         \t         tab (\x09)
423         \v         vertical tab (\x0b)
424         \nnn       octal character (up to 3 octal digits); always
425                      a byte unless > 255 in UTF-8 or 16-bit or 32-bit mode
426         \o{dd...}  octal character (any number of octal digits}
427         \xhh       hexadecimal byte (up to 2 hex digits)
428         \x{hh...}  hexadecimal character (any number of hex digits)
429
430       The use of \x{hh...} is not dependent on the use of the utf modifier on
431       the  pattern. It is recognized always. There may be any number of hexa‐
432       decimal digits inside the braces; invalid  values  provoke  error  mes‐
433       sages.
434
435       Note  that  \xhh  specifies one byte rather than one character in UTF-8
436       mode; this makes it possible to construct invalid UTF-8  sequences  for
437       testing  purposes.  On the other hand, \x{hh} is interpreted as a UTF-8
438       character in UTF-8 mode, generating more than one byte if the value  is
439       greater  than  127.   When testing the 8-bit library not in UTF-8 mode,
440       \x{hh} generates one byte for values less than 256, and causes an error
441       for greater values.
442
443       In UTF-16 mode, all 4-digit \x{hhhh} values are accepted. This makes it
444       possible to construct invalid UTF-16 sequences for testing purposes.
445
446       In UTF-32 mode, all 4- to 8-digit \x{...}  values  are  accepted.  This
447       makes  it  possible  to  construct invalid UTF-32 sequences for testing
448       purposes.
449
450       There is a special backslash sequence that specifies replication of one
451       or more characters:
452
453         \[<characters>]{<count>}
454
455       This  makes  it possible to test long strings without having to provide
456       them as part of the file. For example:
457
458         \[abc]{4}
459
460       is converted to "abcabcabcabc". This feature does not support  nesting.
461       To include a closing square bracket in the characters, code it as \x5D.
462
463       A  backslash  followed  by  an equals sign marks the end of the subject
464       string and the start of a modifier list. For example:
465
466         abc\=notbol,notempty
467
468       If the subject string is empty and \= is followed  by  whitespace,  the
469       line  is  treated  as a comment line, and is not used for matching. For
470       example:
471
472         \= This is a comment.
473         abc\= This is an invalid modifier list.
474
475       A backslash followed  by  any  other  non-alphanumeric  character  just
476       escapes that character. A backslash followed by anything else causes an
477       error. However, if the very last character in the line is  a  backslash
478       (and  there  is  no  modifier list), it is ignored. This gives a way of
479       passing an empty line as data, since a real empty line  terminates  the
480       data input.
481

PATTERN MODIFIERS

483
484       There  are  several types of modifier that can appear in pattern lines.
485       Except where noted below, they may also be used in #pattern commands. A
486       pattern's  modifier  list can add to or override default modifiers that
487       were set by a previous #pattern command.
488
489   Setting compilation options
490
491       The following modifiers set options for pcre2_compile(). The most  com‐
492       mon  ones have single-letter abbreviations. See pcre2api for a descrip‐
493       tion of their effects.
494
495             allow_empty_class         set PCRE2_ALLOW_EMPTY_CLASS
496             alt_bsux                  set PCRE2_ALT_BSUX
497             alt_circumflex            set PCRE2_ALT_CIRCUMFLEX
498             alt_verbnames             set PCRE2_ALT_VERBNAMES
499             anchored                  set PCRE2_ANCHORED
500             auto_callout              set PCRE2_AUTO_CALLOUT
501         /i  caseless                  set PCRE2_CASELESS
502             dollar_endonly            set PCRE2_DOLLAR_ENDONLY
503         /s  dotall                    set PCRE2_DOTALL
504             dupnames                  set PCRE2_DUPNAMES
505         /x  extended                  set PCRE2_EXTENDED
506             firstline                 set PCRE2_FIRSTLINE
507             match_unset_backref       set PCRE2_MATCH_UNSET_BACKREF
508         /m  multiline                 set PCRE2_MULTILINE
509             never_backslash_c         set PCRE2_NEVER_BACKSLASH_C
510             never_ucp                 set PCRE2_NEVER_UCP
511             never_utf                 set PCRE2_NEVER_UTF
512             no_auto_capture           set PCRE2_NO_AUTO_CAPTURE
513             no_auto_possess           set PCRE2_NO_AUTO_POSSESS
514             no_dotstar_anchor         set PCRE2_NO_DOTSTAR_ANCHOR
515             no_start_optimize         set PCRE2_NO_START_OPTIMIZE
516             no_utf_check              set PCRE2_NO_UTF_CHECK
517             ucp                       set PCRE2_UCP
518             ungreedy                  set PCRE2_UNGREEDY
519             use_offset_limit          set PCRE2_USE_OFFSET_LIMIT
520             utf                       set PCRE2_UTF
521
522       As well as turning on the PCRE2_UTF option, the utf modifier causes all
523       non-printing  characters  in  output  strings  to  be printed using the
524       \x{hh...} notation. Otherwise, those less than 0x100 are output in  hex
525       without  the  curly brackets. Setting utf in 16-bit or 32-bit mode also
526       causes pattern and subject  strings  to  be  translated  to  UTF-16  or
527       UTF-32, respectively, before being passed to library functions.
528
529   Setting compilation controls
530
531       The  following  modifiers  affect  the  compilation  process or request
532       information about the pattern:
533
534             bsr=[anycrlf|unicode]     specify \R handling
535         /B  bincode                   show binary code without lengths
536             callout_info              show callout information
537             debug                     same as info,fullbincode
538             fullbincode               show binary code with lengths
539         /I  info                      show info about compiled pattern
540             hex                       unquoted characters are hexadecimal
541             jit[=<number>]            use JIT
542             jitfast                   use JIT fast path
543             jitverify                 verify JIT use
544             locale=<name>             use this locale
545             max_pattern_length=<n>    set the maximum pattern length
546             memory                    show memory used
547             newline=<type>            set newline type
548             null_context              compile with a NULL context
549             parens_nest_limit=<n>     set maximum parentheses depth
550             posix                     use the POSIX API
551             posix_nosub               use the POSIX API with REG_NOSUB
552             push                      push compiled pattern onto the stack
553             pushcopy                  push a copy onto the stack
554             stackguard=<number>       test the stackguard feature
555             tables=[0|1|2]            select internal tables
556             use_length                do not zero-terminate the pattern
557             utf8_input                treat input as UTF-8
558
559       The effects of these modifiers are described in the following sections.
560
561   Newline and \R handling
562
563       The bsr modifier specifies what \R in a pattern should match. If it  is
564       set  to  "anycrlf",  \R  matches  CR, LF, or CRLF only. If it is set to
565       "unicode", \R matches any Unicode  newline  sequence.  The  default  is
566       specified when PCRE2 is built, with the default default being Unicode.
567
568       The  newline  modifier specifies which characters are to be interpreted
569       as newlines, both in the pattern and in subject lines. The type must be
570       one of CR, LF, CRLF, ANYCRLF, or ANY (in upper or lower case).
571
572   Information about a pattern
573
574       The  debug modifier is a shorthand for info,fullbincode, requesting all
575       available information.
576
577       The bincode modifier causes a representation of the compiled code to be
578       output  after compilation. This information does not contain length and
579       offset values, which ensures that the same output is generated for dif‐
580       ferent  internal  link  sizes  and different code unit widths. By using
581       bincode, the same regression tests can be used  in  different  environ‐
582       ments.
583
584       The  fullbincode  modifier, by contrast, does include length and offset
585       values. This is used in a few special tests that run only for  specific
586       code unit widths and link sizes, and is also useful for one-off tests.
587
588       The  info  modifier  requests  information  about  the compiled pattern
589       (whether it is anchored, has a fixed first character, and so  on).  The
590       information  is  obtained  from the pcre2_pattern_info() function. Here
591       are some typical examples:
592
593           re> /(?i)(^a|^b)/m,info
594         Capturing subpattern count = 1
595         Compile options: multiline
596         Overall options: caseless multiline
597         First code unit at start or follows newline
598         Subject length lower bound = 1
599
600           re> /(?i)abc/info
601         Capturing subpattern count = 0
602         Compile options: <none>
603         Overall options: caseless
604         First code unit = 'a' (caseless)
605         Last code unit = 'c' (caseless)
606         Subject length lower bound = 3
607
608       "Compile options" are those specified by modifiers;  "overall  options"
609       have  added options that are taken or deduced from the pattern. If both
610       sets of options are the same, just a single "options" line  is  output;
611       if  there  are  no  options,  the line is omitted. "First code unit" is
612       where any match must start; if there is more than one they  are  listed
613       as  "starting  code  units".  "Last code unit" is the last literal code
614       unit that must be present in any match. This  is  not  necessarily  the
615       last  character.  These lines are omitted if no starting or ending code
616       units are recorded.
617
618       The callout_info modifier requests information about all  the  callouts
619       in the pattern. A list of them is output at the end of any other infor‐
620       mation that is requested. For each callout, either its number or string
621       is given, followed by the item that follows it in the pattern.
622
623   Passing a NULL context
624
625       Normally,  pcre2test  passes a context block to pcre2_compile(). If the
626       null_context modifier is set, however, NULL  is  passed.  This  is  for
627       testing  that  pcre2_compile()  behaves correctly in this case (it uses
628       default values).
629
630   Specifying the pattern's length
631
632       By default, patterns are passed to the compiling functions as zero-ter‐
633       minated  strings.  When  using the POSIX wrapper API, there is no other
634       option. However, when using PCRE2's native API, patterns can be  passed
635       by  length  instead  of  being zero-terminated. The use_length modifier
636       causes this to happen.  Using a length happens  automatically  (whether
637       or  not  use_length is set) when hex is set, because patterns specified
638       in hexadecimal may contain binary zeros.
639
640   Specifying pattern characters in hexadecimal
641
642       The hex modifier specifies that the characters of the  pattern,  except
643       for  substrings  enclosed  in single or double quotes, are to be inter‐
644       preted as pairs of hexadecimal digits. This feature is  provided  as  a
645       way of creating patterns that contain binary zeros and other non-print‐
646       ing characters. White space is permitted between pairs of  digits.  For
647       example, this pattern contains three characters:
648
649         /ab 32 59/hex
650
651       Parts  of  such  a  pattern are taken literally if quoted. This pattern
652       contains nine characters, only two of which are specified in  hexadeci‐
653       mal:
654
655         /ab "literal" 32/hex
656
657       Either  single or double quotes may be used. There is no way of includ‐
658       ing the delimiter within a substring. The hex and expand modifiers  are
659       mutually exclusive.
660
661       The  POSIX  API  cannot  be used with patterns specified in hexadecimal
662       because they may contain binary zeros, which conflicts with regcomp()'s
663       requirement  for  a  zero-terminated  string.  Such patterns are always
664       passed to pcre2_compile() as a string with a length, not as zero-termi‐
665       nated.
666
667   Specifying wide characters in 16-bit and 32-bit modes
668
669       In 16-bit and 32-bit modes, all input is automatically treated as UTF-8
670       and translated to UTF-16 or UTF-32 when the utf modifier  is  set.  For
671       testing the 16-bit and 32-bit libraries in non-UTF mode, the utf8_input
672       modifier can be used. It is mutually exclusive with  utf.  Input  lines
673       are interpreted as UTF-8 as a means of specifying wide characters. More
674       details are given in "Input encoding" above.
675
676   Generating long repetitive patterns
677
678       Some tests use long patterns that are very repetitive. Instead of  cre‐
679       ating  a very long input line for such a pattern, you can use a special
680       repetition feature, similar to the  one  described  for  subject  lines
681       above.  If  the  expand  modifier is present on a pattern, parts of the
682       pattern that have the form
683
684         \[<characters>]{<count>}
685
686       are expanded before the pattern is passed to pcre2_compile(). For exam‐
687       ple, \[AB]{6000} is expanded to "ABAB..." 6000 times. This construction
688       cannot be nested. An initial "\[" sequence is recognized only  if  "]{"
689       followed  by  decimal  digits and "}" is found later in the pattern. If
690       not, the characters remain in the pattern unaltered. The expand and hex
691       modifiers are mutually exclusive.
692
693       If  part  of an expanded pattern looks like an expansion, but is really
694       part of the actual pattern, unwanted expansion can be avoided by giving
695       two values in the quantifier. For example, \[AB]{6000,6000} is not rec‐
696       ognized as an expansion item.
697
698       If the info modifier is set on an expanded pattern, the result  of  the
699       expansion is included in the information that is output.
700
701   JIT compilation
702
703       Just-in-time  (JIT)  compiling  is  a heavyweight optimization that can
704       greatly speed up pattern matching. See the pcre2jit  documentation  for
705       details.  JIT  compiling  happens, optionally, after a pattern has been
706       successfully compiled into an internal form. The JIT compiler  converts
707       this to optimized machine code. It needs to know whether the match-time
708       options PCRE2_PARTIAL_HARD and PCRE2_PARTIAL_SOFT are going to be used,
709       because  different  code  is generated for the different cases. See the
710       partial modifier in "Subject Modifiers" below for details of how  these
711       options are specified for each match attempt.
712
713       JIT  compilation  is  requested by the /jit pattern modifier, which may
714       optionally be followed by an equals sign and a number in the range 0 to
715       7.   The  three bits that make up the number specify which of the three
716       JIT operating modes are to be compiled:
717
718         1  compile JIT code for non-partial matching
719         2  compile JIT code for soft partial matching
720         4  compile JIT code for hard partial matching
721
722       The possible values for the jit modifier are therefore:
723
724         0  disable JIT
725         1  normal matching only
726         2  soft partial matching only
727         3  normal and soft partial matching
728         4  hard partial matching only
729         6  soft and hard partial matching only
730         7  all three modes
731
732       If no number is given, 7 is  assumed.  The  phrase  "partial  matching"
733       means a call to pcre2_match() with either the PCRE2_PARTIAL_SOFT or the
734       PCRE2_PARTIAL_HARD option set. Note that such a call may return a  com‐
735       plete match; the options enable the possibility of a partial match, but
736       do not require it. Note also that if you request JIT  compilation  only
737       for  partial  matching (for example, /jit=2) but do not set the partial
738       modifier on a subject line, that match will not use  JIT  code  because
739       none was compiled for non-partial matching.
740
741       If  JIT compilation is successful, the compiled JIT code will automati‐
742       cally be used when an appropriate type of match  is  run,  except  when
743       incompatible  run-time options are specified. For more details, see the
744       pcre2jit documentation. See also the jitstack modifier below for a  way
745       of setting the size of the JIT stack.
746
747       If  the  jitfast  modifier is specified, matching is done using the JIT
748       "fast path" interface, pcre2_jit_match(), which skips some of the  san‐
749       ity  checks that are done by pcre2_match(), and of course does not work
750       when JIT is not supported. If jitfast is specified without  jit,  jit=7
751       is assumed.
752
753       If  the jitverify modifier is specified, information about the compiled
754       pattern shows whether JIT compilation was or  was  not  successful.  If
755       jitverify  is  specified without jit, jit=7 is assumed. If JIT compila‐
756       tion is successful when jitverify is set, the text "(JIT)" is added  to
757       the first output line after a match or non match when JIT-compiled code
758       was actually used in the match.
759
760   Setting a locale
761
762       The locale modifier must specify the name of a locale, for example:
763
764         /pattern/locale=fr_FR
765
766       The given locale is set, pcre2_maketables() is called to build a set of
767       character  tables for the locale, and this is then passed to pcre2_com‐
768       pile() when compiling the regular expression. The same tables are  used
769       when  matching the following subject lines. The locale modifier applies
770       only to the pattern on which it appears, but can be given in a #pattern
771       command  if a default is needed. Setting a locale and alternate charac‐
772       ter tables are mutually exclusive.
773
774   Showing pattern memory
775
776       The memory modifier causes the size in bytes of the memory used to hold
777       the  compiled  pattern  to be output. This does not include the size of
778       the pcre2_code block; it is just the actual compiled data. If the  pat‐
779       tern  is  subsequently  passed to the JIT compiler, the size of the JIT
780       compiled code is also output. Here is an example:
781
782           re> /a(b)c/jit,memory
783         Memory allocation (code space): 21
784         Memory allocation (JIT code): 1910
785
786
787   Limiting nested parentheses
788
789       The parens_nest_limit modifier sets a limit  on  the  depth  of  nested
790       parentheses  in  a  pattern.  Breaching  the limit causes a compilation
791       error.  The default for the library is set when  PCRE2  is  built,  but
792       pcre2test  sets  its  own default of 220, which is required for running
793       the standard test suite.
794
795   Limiting the pattern length
796
797       The max_pattern_length modifier sets a limit, in  code  units,  to  the
798       length of pattern that pcre2_compile() will accept. Breaching the limit
799       causes a compilation  error.  The  default  is  the  largest  number  a
800       PCRE2_SIZE variable can hold (essentially unlimited).
801
802   Using the POSIX wrapper API
803
804       The  /posix and posix_nosub modifiers cause pcre2test to call PCRE2 via
805       the POSIX wrapper API rather than its native API. When  posix_nosub  is
806       used,  the  POSIX  option  REG_NOSUB  is passed to regcomp(). The POSIX
807       wrapper supports only the 8-bit library. Note that it  does  not  imply
808       POSIX matching semantics; for more detail see the pcre2posix documenta‐
809       tion. The following pattern modifiers set  options  for  the  regcomp()
810       function:
811
812         caseless           REG_ICASE
813         multiline          REG_NEWLINE
814         dotall             REG_DOTALL     )
815         ungreedy           REG_UNGREEDY   ) These options are not part of
816         ucp                REG_UCP        )   the POSIX standard
817         utf                REG_UTF8       )
818
819       The  regerror_buffsize  modifier  specifies a size for the error buffer
820       that is passed to regerror() in the event of a compilation  error.  For
821       example:
822
823         /abc/posix,regerror_buffsize=20
824
825       This  provides  a means of testing the behaviour of regerror() when the
826       buffer is too small for the error message. If  this  modifier  has  not
827       been set, a large buffer is used.
828
829       The  aftertext  and  allaftertext  subject  modifiers work as described
830       below. All other modifiers are either ignored, with a warning  message,
831       or cause an error.
832
833   Testing the stack guard feature
834
835       The  stackguard  modifier  is  used  to  test the use of pcre2_set_com‐
836       pile_recursion_guard(), a function that is  provided  to  enable  stack
837       availability  to  be checked during compilation (see the pcre2api docu‐
838       mentation for details). If the number  specified  by  the  modifier  is
839       greater than zero, pcre2_set_compile_recursion_guard() is called to set
840       up callback from pcre2_compile() to a local function. The  argument  it
841       receives  is  the current nesting parenthesis depth; if this is greater
842       than the value given by the modifier, non-zero is returned, causing the
843       compilation to be aborted.
844
845   Using alternative character tables
846
847       The  value  specified for the tables modifier must be one of the digits
848       0, 1, or 2. It causes a specific set of built-in character tables to be
849       passed to pcre2_compile(). This is used in the PCRE2 tests to check be‐
850       haviour with different character tables. The digit specifies the tables
851       as follows:
852
853         0   do not pass any special character tables
854         1   the default ASCII tables, as distributed in
855               pcre2_chartables.c.dist
856         2   a set of tables defining ISO 8859 characters
857
858       In  table 2, some characters whose codes are greater than 128 are iden‐
859       tified as letters, digits, spaces,  etc.  Setting  alternate  character
860       tables and a locale are mutually exclusive.
861
862   Setting certain match controls
863
864       The following modifiers are really subject modifiers, and are described
865       below.  However, they may be included in a pattern's modifier list,  in
866       which  case  they  are  applied to every subject line that is processed
867       with that pattern. They may not appear in #pattern commands. These mod‐
868       ifiers do not affect the compilation process.
869
870             aftertext                  show text after match
871             allaftertext               show text after captures
872             allcaptures                show all captures
873             allusedtext                show all consulted text
874         /g  global                     global matching
875             mark                       show mark values
876             replace=<string>           specify a replacement string
877             startchar                  show starting character when relevant
878             substitute_extended        use PCRE2_SUBSTITUTE_EXTENDED
879             substitute_overflow_length use PCRE2_SUBSTITUTE_OVERFLOW_LENGTH
880             substitute_unknown_unset   use PCRE2_SUBSTITUTE_UNKNOWN_UNSET
881             substitute_unset_empty     use PCRE2_SUBSTITUTE_UNSET_EMPTY
882
883       These  modifiers may not appear in a #pattern command. If you want them
884       as defaults, set them in a #subject command.
885
886   Saving a compiled pattern
887
888       When a pattern with the push modifier is successfully compiled,  it  is
889       pushed  onto  a  stack  of compiled patterns, and pcre2test expects the
890       next line to contain a new pattern (or a command) instead of a  subject
891       line. This facility is used when saving compiled patterns to a file, as
892       described in the section entitled "Saving and restoring  compiled  pat‐
893       terns"  below.  If pushcopy is used instead of push, a copy of the com‐
894       piled pattern is stacked, leaving the original  as  current,  ready  to
895       match  the  following  input  lines. This provides a way of testing the
896       pcre2_code_copy() function.   The  push  and  pushcopy   modifiers  are
897       incompatible  with  compilation  modifiers  such  as global that act at
898       match time. Any that are specified are ignored (for the stacked  copy),
899       with a warning message, except for replace, which causes an error. Note
900       that jitverify, which is allowed, does not carry through to any  subse‐
901       quent matching that uses a stacked pattern.
902

SUBJECT MODIFIERS

904
905       The modifiers that can appear in subject lines and the #subject command
906       are of two types.
907
908   Setting match options
909
910       The   following   modifiers   set   options   for   pcre2_match()    or
911       pcre2_dfa_match(). See pcreapi for a description of their effects.
912
913             anchored                  set PCRE2_ANCHORED
914             dfa_restart               set PCRE2_DFA_RESTART
915             dfa_shortest              set PCRE2_DFA_SHORTEST
916             no_jit                    set PCRE2_NO_JIT
917             no_utf_check              set PCRE2_NO_UTF_CHECK
918             notbol                    set PCRE2_NOTBOL
919             notempty                  set PCRE2_NOTEMPTY
920             notempty_atstart          set PCRE2_NOTEMPTY_ATSTART
921             noteol                    set PCRE2_NOTEOL
922             partial_hard (or ph)      set PCRE2_PARTIAL_HARD
923             partial_soft (or ps)      set PCRE2_PARTIAL_SOFT
924
925       The  partial matching modifiers are provided with abbreviations because
926       they appear frequently in tests.
927
928       If the posix modifier was present on the  pattern,  causing  the  POSIX
929       wrapper API to be used, the only option-setting modifiers that have any
930       effect  are  notbol,  notempty,   and   noteol,   causing   REG_NOTBOL,
931       REG_NOTEMPTY,  and REG_NOTEOL, respectively, to be passed to regexec().
932       The other modifiers are ignored, with a warning message.
933
934   Setting match controls
935
936       The following modifiers affect the matching process  or  request  addi‐
937       tional  information.  Some  of  them may also be specified on a pattern
938       line (see above), in which case they apply to every subject  line  that
939       is matched against that pattern.
940
941             aftertext                  show text after match
942             allaftertext               show text after captures
943             allcaptures                show all captures
944             allusedtext                show all consulted text (non-JIT only)
945             altglobal                  alternative global matching
946             callout_capture            show captures at callout time
947             callout_data=<n>           set a value to pass via callouts
948             callout_error=<n>[:<m>]    control callout error
949             callout_fail=<n>[:<m>]     control callout failure
950             callout_none               do not supply a callout function
951             copy=<number or name>      copy captured substring
952             dfa                        use pcre2_dfa_match()
953             find_limits                find match and recursion limits
954             get=<number or name>       extract captured substring
955             getall                     extract all captured substrings
956         /g  global                     global matching
957             jitstack=<n>               set size of JIT stack
958             mark                       show mark values
959             match_limit=<n>            set a match limit
960             memory                     show memory usage
961             null_context               match with a NULL context
962             offset=<n>                 set starting offset
963             offset_limit=<n>           set offset limit
964             ovector=<n>                set size of output vector
965             recursion_limit=<n>        set a recursion limit
966             replace=<string>           specify a replacement string
967             startchar                  show startchar when relevant
968             startoffset=<n>            same as offset=<n>
969             substitute_extedded        use PCRE2_SUBSTITUTE_EXTENDED
970             substitute_overflow_length use PCRE2_SUBSTITUTE_OVERFLOW_LENGTH
971             substitute_unknown_unset   use PCRE2_SUBSTITUTE_UNKNOWN_UNSET
972             substitute_unset_empty     use PCRE2_SUBSTITUTE_UNSET_EMPTY
973             zero_terminate             pass the subject as zero-terminated
974
975       The effects of these modifiers are described in the following sections.
976       When matching via the POSIX wrapper API, the  aftertext,  allaftertext,
977       and  ovector subject modifiers work as described below. All other modi‐
978       fiers are either ignored, with a warning message, or cause an error.
979
980   Showing more text
981
982       The aftertext modifier requests that as well as outputting the part  of
983       the subject string that matched the entire pattern, pcre2test should in
984       addition output the remainder of the subject string. This is useful for
985       tests where the subject contains multiple copies of the same substring.
986       The allaftertext modifier requests the same action  for  captured  sub‐
987       strings as well as the main matched substring. In each case the remain‐
988       der is output on the following line with a plus character following the
989       capture number.
990
991       The  allusedtext modifier requests that all the text that was consulted
992       during a successful pattern match by the interpreter should  be  shown.
993       This  feature  is not supported for JIT matching, and if requested with
994       JIT it is ignored (with  a  warning  message).  Setting  this  modifier
995       affects the output if there is a lookbehind at the start of a match, or
996       a lookahead at the end, or if \K is used  in  the  pattern.  Characters
997       that  precede or follow the start and end of the actual match are indi‐
998       cated in the output by '<' or '>' characters underneath them.  Here  is
999       an example:
1000
1001           re> /(?<=pqr)abc(?=xyz)/
1002         data> 123pqrabcxyz456\=allusedtext
1003          0: pqrabcxyz
1004             <<<   >>>
1005
1006       This  shows  that  the  matched string is "abc", with the preceding and
1007       following strings "pqr" and "xyz"  having  been  consulted  during  the
1008       match (when processing the assertions).
1009
1010       The  startchar  modifier  requests  that the starting character for the
1011       match be indicated, if it is different to  the  start  of  the  matched
1012       string. The only time when this occurs is when \K has been processed as
1013       part of the match. In this situation, the output for the matched string
1014       is  displayed  from  the  starting  character instead of from the match
1015       point, with circumflex characters under  the  earlier  characters.  For
1016       example:
1017
1018           re> /abc\Kxyz/
1019         data> abcxyz\=startchar
1020          0: abcxyz
1021             ^^^
1022
1023       Unlike  allusedtext, the startchar modifier can be used with JIT.  How‐
1024       ever, these two modifiers are mutually exclusive.
1025
1026   Showing the value of all capture groups
1027
1028       The allcaptures modifier requests that the values of all potential cap‐
1029       tured parentheses be output after a match. By default, only those up to
1030       the highest one actually used in the match are output (corresponding to
1031       the  return  code from pcre2_match()). Groups that did not take part in
1032       the match are output as "<unset>". This modifier is  not  relevant  for
1033       DFA  matching  (which does no capturing); it is ignored, with a warning
1034       message, if present.
1035
1036   Testing callouts
1037
1038       A callout function is supplied when pcre2test calls the library  match‐
1039       ing  functions, unless callout_none is specified. If callout_capture is
1040       set, the current captured groups are output when a callout occurs.  The
1041       default return from the callout function is zero, which allows matching
1042       to continue.
1043
1044       The callout_fail modifier can be given one or two numbers. If there  is
1045       only  one number, 1 is returned instead of 0 (causing matching to back‐
1046       track) when a callout  of  that  number  is  reached.  If  two  numbers
1047       (<n>:<m>)  are  given,  1  is  returned when callout <n> is reached and
1048       there have been at least <m> callouts. The  callout_error  modifier  is
1049       similar,  except  that  PCRE2_ERROR_CALLOUT  is  returned,  causing the
1050       entire matching process to be aborted. If both these modifiers are  set
1051       for the same callout number, callout_error takes precedence.
1052
1053       Note  that  callouts  with string arguments are always given the number
1054       zero. See "Callouts" below for a description of the output when a call‐
1055       out it taken.
1056
1057       The  callout_data  modifier can be given an unsigned or a negative num‐
1058       ber.  This is set as the "user data" that is  passed  to  the  matching
1059       function,  and  passed  back  when the callout function is invoked. Any
1060       value other than zero is used as  a  return  from  pcre2test's  callout
1061       function.
1062
1063   Finding all matches in a string
1064
1065       Searching for all possible matches within a subject can be requested by
1066       the global or altglobal modifier. After finding a match,  the  matching
1067       function  is  called  again to search the remainder of the subject. The
1068       difference between global and altglobal is that  the  former  uses  the
1069       start_offset  argument  to  pcre2_match() or pcre2_dfa_match() to start
1070       searching at a new point within the entire string (which is  what  Perl
1071       does), whereas the latter passes over a shortened subject. This makes a
1072       difference to the matching process if the pattern begins with a lookbe‐
1073       hind assertion (including \b or \B).
1074
1075       If  an  empty  string  is  matched,  the  next  match  is done with the
1076       PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED flags set, in order to search
1077       for another, non-empty, match at the same point in the subject. If this
1078       match fails, the start offset is advanced,  and  the  normal  match  is
1079       retried.  This  imitates the way Perl handles such cases when using the
1080       /g modifier or the split() function.  Normally,  the  start  offset  is
1081       advanced  by  one  character,  but if the newline convention recognizes
1082       CRLF as a newline, and the current character is CR followed by  LF,  an
1083       advance of two characters occurs.
1084
1085   Testing substring extraction functions
1086
1087       The  copy  and  get  modifiers  can  be  used  to  test  the pcre2_sub‐
1088       string_copy_xxx() and pcre2_substring_get_xxx() functions.  They can be
1089       given  more than once, and each can specify a group name or number, for
1090       example:
1091
1092          abcd\=copy=1,copy=3,get=G1
1093
1094       If the #subject command is used to set default copy and/or  get  lists,
1095       these  can  be unset by specifying a negative number to cancel all num‐
1096       bered groups and an empty name to cancel all named groups.
1097
1098       The getall modifier tests  pcre2_substring_list_get(),  which  extracts
1099       all captured substrings.
1100
1101       If  the  subject line is successfully matched, the substrings extracted
1102       by the convenience functions are output with  C,  G,  or  L  after  the
1103       string  number  instead  of  a colon. This is in addition to the normal
1104       full list. The string length (that is, the return from  the  extraction
1105       function) is given in parentheses after each substring, followed by the
1106       name when the extraction was by name.
1107
1108   Testing the substitution function
1109
1110       If the replace modifier is  set,  the  pcre2_substitute()  function  is
1111       called  instead of one of the matching functions. Note that replacement
1112       strings cannot contain commas, because a comma signifies the end  of  a
1113       modifier. This is not thought to be an issue in a test program.
1114
1115       Unlike  subject strings, pcre2test does not process replacement strings
1116       for escape sequences. In UTF mode, a replacement string is  checked  to
1117       see  if it is a valid UTF-8 string. If so, it is correctly converted to
1118       a UTF string of the appropriate code unit width. If it is not  a  valid
1119       UTF-8  string, the individual code units are copied directly. This pro‐
1120       vides a means of passing an invalid UTF-8 string for testing purposes.
1121
1122       The following modifiers set options (in additional to the normal  match
1123       options) for pcre2_substitute():
1124
1125         global                      PCRE2_SUBSTITUTE_GLOBAL
1126         substitute_extended         PCRE2_SUBSTITUTE_EXTENDED
1127         substitute_overflow_length  PCRE2_SUBSTITUTE_OVERFLOW_LENGTH
1128         substitute_unknown_unset    PCRE2_SUBSTITUTE_UNKNOWN_UNSET
1129         substitute_unset_empty      PCRE2_SUBSTITUTE_UNSET_EMPTY
1130
1131
1132       After  a  successful  substitution, the modified string is output, pre‐
1133       ceded by the number of replacements. This may be zero if there were  no
1134       matches. Here is a simple example of a substitution test:
1135
1136         /abc/replace=xxx
1137             =abc=abc=
1138          1: =xxx=abc=
1139             =abc=abc=\=global
1140          2: =xxx=xxx=
1141
1142       Subject  and replacement strings should be kept relatively short (fewer
1143       than 256 characters) for substitution tests, as fixed-size buffers  are
1144       used.  To  make it easy to test for buffer overflow, if the replacement
1145       string starts with a number in square brackets, that number  is  passed
1146       to  pcre2_substitute()  as  the  size  of  the  output buffer, with the
1147       replacement string starting at the next character. Here is  an  example
1148       that tests the edge case:
1149
1150         /abc/
1151             123abc123\=replace=[10]XYZ
1152          1: 123XYZ123
1153             123abc123\=replace=[9]XYZ
1154         Failed: error -47: no more memory
1155
1156       The    default    action    of    pcre2_substitute()   is   to   return
1157       PCRE2_ERROR_NOMEMORY when the output buffer is too small.  However,  if
1158       the  PCRE2_SUBSTITUTE_OVERFLOW_LENGTH  option is set (by using the sub‐
1159       stitute_overflow_length modifier), pcre2_substitute() continues  to  go
1160       through  the  motions of matching and substituting, in order to compute
1161       the size of buffer that is required. When this happens, pcre2test shows
1162       the required buffer length (which includes space for the trailing zero)
1163       as part of the error message. For example:
1164
1165         /abc/substitute_overflow_length
1166             123abc123\=replace=[9]XYZ
1167         Failed: error -47: no more memory: 10 code units are needed
1168
1169       A replacement string is ignored with POSIX and DFA matching. Specifying
1170       partial  matching  provokes  an  error return ("bad option value") from
1171       pcre2_substitute().
1172
1173   Setting the JIT stack size
1174
1175       The jitstack modifier provides a way of setting the maximum stack  size
1176       that  is  used  by the just-in-time optimization code. It is ignored if
1177       JIT optimization is not being used. The value is a number of kilobytes.
1178       Providing a stack that is larger than the default 32K is necessary only
1179       for very complicated patterns.
1180
1181   Setting match and recursion limits
1182
1183       The match_limit and recursion_limit modifiers set the appropriate  lim‐
1184       its in the match context. These values are ignored when the find_limits
1185       modifier is specified.
1186
1187   Finding minimum limits
1188
1189       If the find_limits modifier is present, pcre2test  calls  pcre2_match()
1190       several  times,  setting  different  values  in  the  match context via
1191       pcre2_set_match_limit() and pcre2_set_recursion_limit() until it  finds
1192       the  minimum values for each parameter that allow pcre2_match() to com‐
1193       plete without error.
1194
1195       If JIT is being used, only the match limit is relevant. If DFA matching
1196       is  being used, neither limit is relevant, and this modifier is ignored
1197       (with a warning message).
1198
1199       The match_limit number is a measure of the amount of backtracking  that
1200       takes  place,  and  learning  the minimum value can be instructive. For
1201       most simple matches, the number is quite small, but for  patterns  with
1202       very  large numbers of matching possibilities, it can become large very
1203       quickly   with   increasing   length    of    subject    string.    The
1204       match_limit_recursion  number  is  a  measure of how much stack (or, if
1205       PCRE2 is compiled with NO_RECURSE, how much heap) memory is  needed  to
1206       complete the match attempt.
1207
1208   Showing MARK names
1209
1210
1211       The mark modifier causes the names from backtracking control verbs that
1212       are returned from calls to pcre2_match() to be displayed. If a mark  is
1213       returned  for a match, non-match, or partial match, pcre2test shows it.
1214       For a match, it is on a line by itself, tagged with  "MK:".  Otherwise,
1215       it is added to the non-match message.
1216
1217   Showing memory usage
1218
1219       The  memory  modifier causes pcre2test to log all memory allocation and
1220       freeing calls that occur during a match operation.
1221
1222   Setting a starting offset
1223
1224       The offset modifier sets an offset  in  the  subject  string  at  which
1225       matching starts. Its value is a number of code units, not characters.
1226
1227   Setting an offset limit
1228
1229       The  offset_limit  modifier  sets  a limit for unanchored matches. If a
1230       match cannot be found starting at or before this offset in the subject,
1231       a "no match" return is given. The data value is a number of code units,
1232       not characters. When this modifier is used, the use_offset_limit  modi‐
1233       fier must have been set for the pattern; if not, an error is generated.
1234
1235   Setting the size of the output vector
1236
1237       The  ovector  modifier  applies  only  to  the subject line in which it
1238       appears, though of course it can also be used to set  a  default  in  a
1239       #subject  command. It specifies the number of pairs of offsets that are
1240       available for storing matching information. The default is 15.
1241
1242       A value of zero is useful when testing the POSIX API because it  causes
1243       regexec() to be called with a NULL capture vector. When not testing the
1244       POSIX API, a value of  zero  is  used  to  cause  pcre2_match_data_cre‐
1245       ate_from_pattern()  to  be  called, in order to create a match block of
1246       exactly the right size for the pattern. (It is not possible to create a
1247       match  block  with  a zero-length ovector; there is always at least one
1248       pair of offsets.)
1249
1250   Passing the subject as zero-terminated
1251
1252       By default, the subject string is passed to a native API matching func‐
1253       tion with its correct length. In order to test the facility for passing
1254       a zero-terminated string, the zero_terminate modifier is  provided.  It
1255       causes the length to be passed as PCRE2_ZERO_TERMINATED. (When matching
1256       via the POSIX interface, this modifier has no effect, as  there  is  no
1257       facility for passing a length.)
1258
1259       When  testing  pcre2_substitute(), this modifier also has the effect of
1260       passing the replacement string as zero-terminated.
1261
1262   Passing a NULL context
1263
1264       Normally,  pcre2test  passes  a   context   block   to   pcre2_match(),
1265       pcre2_dfa_match() or pcre2_jit_match(). If the null_context modifier is
1266       set, however, NULL is passed. This is for  testing  that  the  matching
1267       functions behave correctly in this case (they use default values). This
1268       modifier cannot be used with the find_limits modifier or  when  testing
1269       the substitution function.
1270

THE ALTERNATIVE MATCHING FUNCTION

1272
1273       By  default,  pcre2test  uses  the  standard  PCRE2  matching function,
1274       pcre2_match() to match each subject line. PCRE2 also supports an alter‐
1275       native  matching  function, pcre2_dfa_match(), which operates in a dif‐
1276       ferent way, and has some restrictions. The differences between the  two
1277       functions are described in the pcre2matching documentation.
1278
1279       If  the dfa modifier is set, the alternative matching function is used.
1280       This function finds all possible matches at a given point in  the  sub‐
1281       ject.  If,  however, the dfa_shortest modifier is set, processing stops
1282       after the first match is found. This is always  the  shortest  possible
1283       match.
1284

DEFAULT OUTPUT FROM pcre2test

1286
1287       This  section  describes  the output when the normal matching function,
1288       pcre2_match(), is being used.
1289
1290       When a match succeeds, pcre2test outputs  the  list  of  captured  sub‐
1291       strings,  starting  with number 0 for the string that matched the whole
1292       pattern.   Otherwise,  it  outputs  "No  match"  when  the  return   is
1293       PCRE2_ERROR_NOMATCH,  or  "Partial  match:"  followed  by the partially
1294       matching substring when the return is PCRE2_ERROR_PARTIAL.  (Note  that
1295       this  is  the  entire  substring  that was inspected during the partial
1296       match; it may include characters before the actual  match  start  if  a
1297       lookbehind assertion, \K, \b, or \B was involved.)
1298
1299       For any other return, pcre2test outputs the PCRE2 negative error number
1300       and a short descriptive phrase. If the error is  a  failed  UTF  string
1301       check,  the  code  unit offset of the start of the failing character is
1302       also output. Here is an example of an interactive pcre2test run.
1303
1304         $ pcre2test
1305         PCRE2 version 9.00 2014-05-10
1306
1307           re> /^abc(\d+)/
1308         data> abc123
1309          0: abc123
1310          1: 123
1311         data> xyz
1312         No match
1313
1314       Unset capturing substrings that are not followed by one that is set are
1315       not shown by pcre2test unless the allcaptures modifier is specified. In
1316       the following example, there are two capturing substrings, but when the
1317       first  data  line is matched, the second, unset substring is not shown.
1318       An "internal" unset substring is shown as "<unset>", as for the  second
1319       data line.
1320
1321           re> /(a)|(b)/
1322         data> a
1323          0: a
1324          1: a
1325         data> b
1326          0: b
1327          1: <unset>
1328          2: b
1329
1330       If  the strings contain any non-printing characters, they are output as
1331       \xhh escapes if the value is less than 256 and UTF  mode  is  not  set.
1332       Otherwise they are output as \x{hh...} escapes. See below for the defi‐
1333       nition of non-printing characters. If the aftertext  modifier  is  set,
1334       the  output  for substring 0 is followed by the the rest of the subject
1335       string, identified by "0+" like this:
1336
1337           re> /cat/aftertext
1338         data> cataract
1339          0: cat
1340          0+ aract
1341
1342       If global matching is requested, the  results  of  successive  matching
1343       attempts are output in sequence, like this:
1344
1345           re> /\Bi(\w\w)/g
1346         data> Mississippi
1347          0: iss
1348          1: ss
1349          0: iss
1350          1: ss
1351          0: ipp
1352          1: pp
1353
1354       "No  match" is output only if the first match attempt fails. Here is an
1355       example of a failure message (the offset 4 that  is  specified  by  the
1356       offset modifier is past the end of the subject string):
1357
1358           re> /xyz/
1359         data> xyz\=offset=4
1360         Error -24 (bad offset value)
1361
1362       Note that whereas patterns can be continued over several lines (a plain
1363       ">" prompt is used for continuations), subject lines may  not.  However
1364       newlines can be included in a subject by means of the \n escape (or \r,
1365       \r\n, etc., depending on the newline sequence setting).
1366

OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION

1368
1369       When the alternative matching function, pcre2_dfa_match(), is used, the
1370       output  consists  of  a list of all the matches that start at the first
1371       point in the subject where there is at least one match. For example:
1372
1373           re> /(tang|tangerine|tan)/
1374         data> yellow tangerine\=dfa
1375          0: tangerine
1376          1: tang
1377          2: tan
1378
1379       Using the normal matching function on this data finds only "tang".  The
1380       longest  matching  string  is  always  given first (and numbered zero).
1381       After a PCRE2_ERROR_PARTIAL return, the  output  is  "Partial  match:",
1382       followed  by  the  partially  matching substring. Note that this is the
1383       entire substring that was inspected during the partial  match;  it  may
1384       include characters before the actual match start if a lookbehind asser‐
1385       tion, \b, or \B was involved. (\K is not supported for DFA matching.)
1386
1387       If global matching is requested, the search for further matches resumes
1388       at the end of the longest match. For example:
1389
1390           re> /(tang|tangerine|tan)/g
1391         data> yellow tangerine and tangy sultana\=dfa
1392          0: tangerine
1393          1: tang
1394          2: tan
1395          0: tang
1396          1: tan
1397          0: tan
1398
1399       The  alternative  matching function does not support substring capture,
1400       so the modifiers that are concerned with captured  substrings  are  not
1401       relevant.
1402

RESTARTING AFTER A PARTIAL MATCH

1404
1405       When  the  alternative matching function has given the PCRE2_ERROR_PAR‐
1406       TIAL return, indicating that the subject partially matched the pattern,
1407       you  can restart the match with additional subject data by means of the
1408       dfa_restart modifier. For example:
1409
1410           re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
1411         data> 23ja\=P,dfa
1412         Partial match: 23ja
1413         data> n05\=dfa,dfa_restart
1414          0: n05
1415
1416       For further information about partial matching,  see  the  pcre2partial
1417       documentation.
1418

CALLOUTS

1420
1421       If the pattern contains any callout requests, pcre2test's callout func‐
1422       tion is called during matching unless callout_none is specified.   This
1423       works with both matching functions.
1424
1425       The  callout  function in pcre2test returns zero (carry on matching) by
1426       default, but you can use a callout_fail modifier in a subject line  (as
1427       described above) to change this and other parameters of the callout.
1428
1429       Inserting callouts can be helpful when using pcre2test to check compli‐
1430       cated regular expressions. For further information about callouts,  see
1431       the pcre2callout documentation.
1432
1433       The  output for callouts with numerical arguments and those with string
1434       arguments is slightly different.
1435
1436   Callouts with numerical arguments
1437
1438       By default, the callout function displays the callout number, the start
1439       and  current positions in the subject text at the callout time, and the
1440       next pattern item to be tested. For example:
1441
1442         --->pqrabcdef
1443           0    ^  ^     \d
1444
1445       This output indicates that  callout  number  0  occurred  for  a  match
1446       attempt  starting  at  the fourth character of the subject string, when
1447       the pointer was at the seventh character, and  when  the  next  pattern
1448       item  was  \d.  Just  one circumflex is output if the start and current
1449       positions are the same, or if the current position precedes  the  start
1450       position, which can happen if the callout is in a lookbehind assertion.
1451
1452       Callouts numbered 255 are assumed to be automatic callouts, inserted as
1453       a result of the /auto_callout pattern modifier. In this  case,  instead
1454       of showing the callout number, the offset in the pattern, preceded by a
1455       plus, is output. For example:
1456
1457           re> /\d?[A-E]\*/auto_callout
1458         data> E*
1459         --->E*
1460          +0 ^      \d?
1461          +3 ^      [A-E]
1462          +8 ^^     \*
1463         +10 ^ ^
1464          0: E*
1465
1466       If a pattern contains (*MARK) items, an additional line is output when‐
1467       ever  a  change  of  latest mark is passed to the callout function. For
1468       example:
1469
1470           re> /a(*MARK:X)bc/auto_callout
1471         data> abc
1472         --->abc
1473          +0 ^       a
1474          +1 ^^      (*MARK:X)
1475         +10 ^^      b
1476         Latest Mark: X
1477         +11 ^ ^     c
1478         +12 ^  ^
1479          0: abc
1480
1481       The mark changes between matching "a" and "b", but stays the  same  for
1482       the  rest  of  the match, so nothing more is output. If, as a result of
1483       backtracking, the mark reverts to being unset, the  text  "<unset>"  is
1484       output.
1485
1486   Callouts with string arguments
1487
1488       The output for a callout with a string argument is similar, except that
1489       instead of outputting a callout number before the position  indicators,
1490       the  callout  string  and  its  offset in the pattern string are output
1491       before the reflection of the subject string, and the subject string  is
1492       reflected for each callout. For example:
1493
1494           re> /^ab(?C'first')cd(?C"second")ef/
1495         data> abcdefg
1496         Callout (7): 'first'
1497         --->abcdefg
1498             ^ ^         c
1499         Callout (20): "second"
1500         --->abcdefg
1501             ^   ^       e
1502          0: abcdef
1503
1504

NON-PRINTING CHARACTERS

1506
1507       When pcre2test is outputting text in the compiled version of a pattern,
1508       bytes other than 32-126 are always treated as  non-printing  characters
1509       and are therefore shown as hex escapes.
1510
1511       When  pcre2test  is outputting text that is a matched part of a subject
1512       string, it behaves in the same way, unless a different locale has  been
1513       set  for  the  pattern  (using  the locale modifier). In this case, the
1514       isprint() function is used to  distinguish  printing  and  non-printing
1515       characters.
1516

SAVING AND RESTORING COMPILED PATTERNS

1518
1519       It  is  possible  to  save  compiled patterns on disc or elsewhere, and
1520       reload them later, subject to a number of restrictions. JIT data cannot
1521       be  saved.  The host on which the patterns are reloaded must be running
1522       the same version of PCRE2, with the same code unit width, and must also
1523       have  the  same  endianness,  pointer width and PCRE2_SIZE type. Before
1524       compiled patterns can be saved they must be serialized, that  is,  con‐
1525       verted  to a stream of bytes. A single byte stream may contain any num‐
1526       ber of compiled patterns, but they must  all  use  the  same  character
1527       tables. A single copy of the tables is included in the byte stream (its
1528       size is 1088 bytes).
1529
1530       The functions whose names begin  with  pcre2_serialize_  are  used  for
1531       serializing  and de-serializing. They are described in the pcre2serial‐
1532       ize  documentation.  In  this  section  we  describe  the  features  of
1533       pcre2test that can be used to test these functions.
1534
1535       When  a  pattern  with  push  modifier  is successfully compiled, it is
1536       pushed onto a stack of compiled patterns,  and  pcre2test  expects  the
1537       next  line  to  contain a new pattern (or command) instead of a subject
1538       line. By contrast, the pushcopy modifier causes a copy of the  compiled
1539       pattern  to  be  stacked,  leaving the original available for immediate
1540       matching. By using push and/or pushcopy, a number of  patterns  can  be
1541       compiled and retained. These modifiers are incompatible with posix, and
1542       control modifiers that act at match time are ignored (with  a  message)
1543       for  the  stacked patterns. The jitverify modifier applies only at com‐
1544       pile time.
1545
1546       The command
1547
1548         #save <filename>
1549
1550       causes all the stacked patterns to be serialized and the result written
1551       to  the named file. Afterwards, all the stacked patterns are freed. The
1552       command
1553
1554         #load <filename>
1555
1556       reads the data in the file, and then arranges for it to  be  de-serial‐
1557       ized,  with the resulting compiled patterns added to the pattern stack.
1558       The pattern on the top of the stack can be retrieved by the  #pop  com‐
1559       mand,  which  must  be  followed  by  lines  of subjects that are to be
1560       matched with the pattern, terminated as usual by an empty line  or  end
1561       of  file.  This  command  may be followed by a modifier list containing
1562       only control modifiers that act after a pattern has been  compiled.  In
1563       particular,  hex,  posix,  posix_nosub,  push,  and  pushcopy  are  not
1564       allowed, nor are any option-setting modifiers.  The JIT modifiers  are,
1565       however  permitted.  Here is an example that saves and reloads two pat‐
1566       terns.
1567
1568         /abc/push
1569         /xyz/push
1570         #save tempfile
1571         #load tempfile
1572         #pop info
1573         xyz
1574
1575         #pop jit,bincode
1576         abc
1577
1578       If jitverify is used with #pop, it does not  automatically  imply  jit,
1579       which is different behaviour from when it is used on a pattern.
1580
1581       The  #popcopy  command is analagous to the pushcopy modifier in that it
1582       makes current a copy of the topmost stack pattern, leaving the original
1583       still on the stack.
1584

SEE ALSO

1586
1587       pcre2(3),  pcre2api(3),  pcre2callout(3),  pcre2jit,  pcre2matching(3),
1588       pcre2partial(d), pcre2pattern(3), pcre2serialize(3).
1589

AUTHOR

1591
1592       Philip Hazel
1593       University Computing Service
1594       Cambridge, England.
1595

REVISION

1597
1598       Last updated: 28 December 2016
1599       Copyright (c) 1997-2016 University of Cambridge.
1600
1601
1602
1603PCRE 10.23                     28 December 2016                   PCRE2TEST(1)
Impressum