/[pcre]/code/trunk/doc/pcretest.txt
ViewVC logotype

Contents of /code/trunk/doc/pcretest.txt

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1194 - (show annotations)
Wed Oct 31 17:42:29 2012 UTC (6 years, 8 months ago) by ph10
File MIME type: text/plain
File size: 50116 byte(s)
Error occurred while calculating annotation data.
More documentation updates
1 PCRETEST(1) PCRETEST(1)
2
3
4 NAME
5 pcretest - a program for testing Perl-compatible regular expressions.
6
7
8 SYNOPSIS
9
10 pcretest [options] [input file [output file]]
11
12 pcretest was written as a test program for the PCRE regular expression
13 library itself, but it can also be used for experimenting with regular
14 expressions. This document describes the features of the test program;
15 for details of the regular expressions themselves, see the pcrepattern
16 documentation. For details of the PCRE library function calls and their
17 options, see the pcreapi , pcre16 and pcre32 documentation.
18
19 The input for pcretest is a sequence of regular expression patterns and
20 strings to be matched, as described below. The output shows the result
21 of each match. Options on the command line and the patterns control
22 PCRE options and exactly what is output.
23
24 As PCRE has evolved, it has acquired many different features, and as a
25 result, pcretest now has rather a lot of obscure options for testing
26 every possible feature. Some of these options are specifically designed
27 for use in conjunction with the test script and data files that are
28 distributed as part of PCRE, and are unlikely to be of use otherwise.
29 They are all documented here, but without much justification.
30
31
32 PCRE's 8-BIT, 16-BIT AND 32-BIT LIBRARIES
33
34 From release 8.30, two separate PCRE libraries can be built. The origi-
35 nal one supports 8-bit character strings, whereas the newer 16-bit
36 library supports character strings encoded in 16-bit units. From
37 release 8.32, a third library can be built, supporting character
38 strings encoded in 32-bit units. The pcretest program can be used to
39 test all three libraries. However, it is itself still an 8-bit program,
40 reading 8-bit input and writing 8-bit output. When testing the 16-bit
41 or 32-bit library, the patterns and data strings are converted to 16-
42 or 32-bit format before being passed to the PCRE library functions.
43 Results are converted to 8-bit for output.
44
45 References to functions and structures of the form pcre[16|32]_xx below
46 mean "pcre_xx when using the 8-bit library or pcre16_xx when using the
47 16-bit library".
48
49
50 COMMAND LINE OPTIONS
51
52 -8 If both the 8-bit library has been built, this option causes
53 the 8-bit library to be used (which is the default); if the
54 8-bit library has not been built, this option causes an
55 error.
56
57 -16 If both the 8-bit or the 32-bit, and the 16-bit libraries
58 have been built, this option causes the 16-bit library to be
59 used. If only the 16-bit library has been built, this is the
60 default (so has no effect). If only the 8-bit or the 32-bit
61 library has been built, this option causes an error.
62
63 -32 If both the 8-bit or the 16-bit, and the 32-bit libraries
64 have been built, this option causes the 32-bit library to be
65 used. If only the 32-bit library has been built, this is the
66 default (so has no effect). If only the 8-bit or the 16-bit
67 library has been built, this option causes an error.
68
69 -b Behave as if each pattern has the /B (show byte code) modi-
70 fier; the internal form is output after compilation.
71
72 -C Output the version number of the PCRE library, and all avail-
73 able information about the optional features that are
74 included, and then exit. All other options are ignored.
75
76 -C option Output information about a specific build-time option, then
77 exit. This functionality is intended for use in scripts such
78 as RunTest. The following options output the value indicated:
79
80 ebcdic-nl the code for LF (= NL) in an EBCDIC environment:
81 0x15 or 0x25
82 0 if used in an ASCII environment
83 linksize the internal link size (2, 3, or 4)
84 newline the default newline setting:
85 CR, LF, CRLF, ANYCRLF, or ANY
86
87 The following options output 1 for true or zero for false:
88
89 ebcdic compiled for an EBCDIC environment
90 jit just-in-time support is available
91 pcre16 the 16-bit library was built
92 pcre32 the 32-bit library was built
93 pcre8 the 8-bit library was built
94 ucp Unicode property support is available
95 utf UTF-8 and/or UTF-16 and/or UTF-32 support is
96 available
97
98 -d Behave as if each pattern has the /D (debug) modifier; the
99 internal form and information about the compiled pattern is
100 output after compilation; -d is equivalent to -b -i.
101
102 -dfa Behave as if each data line contains the \D escape sequence;
103 this causes the alternative matching function,
104 pcre[16|32]_dfa_exec(), to be used instead of the standard
105 pcre[16|32]_exec() function (more detail is given below).
106
107 -help Output a brief summary these options and then exit.
108
109 -i Behave as if each pattern has the /I modifier; information
110 about the compiled pattern is given after compilation.
111
112 -M Behave as if each data line contains the \M escape sequence;
113 this causes PCRE to discover the minimum MATCH_LIMIT and
114 MATCH_LIMIT_RECURSION settings by calling pcre[16|32]_exec()
115 repeatedly with different limits.
116
117 -m Output the size of each compiled pattern after it has been
118 compiled. This is equivalent to adding /M to each regular
119 expression. The size is given in bytes for both libraries.
120
121 -o osize Set the number of elements in the output vector that is used
122 when calling pcre[16|32]_exec() or pcre[16|32]_dfa_exec() to
123 be osize. The default value is 45, which is enough for 14
124 capturing subexpressions for pcre[16|32]_exec() or 22 differ-
125 ent matches for pcre[16|32]_dfa_exec(). The vector size can
126 be changed for individual matching calls by including \O in
127 the data line (see below).
128
129 -p Behave as if each pattern has the /P modifier; the POSIX
130 wrapper API is used to call PCRE. None of the other options
131 has any effect when -p is set. This option can be used only
132 with the 8-bit library.
133
134 -q Do not output the version number of pcretest at the start of
135 execution.
136
137 -S size On Unix-like systems, set the size of the run-time stack to
138 size megabytes.
139
140 -s or -s+ Behave as if each pattern has the /S modifier; in other
141 words, force each pattern to be studied. If -s+ is used, all
142 the JIT compile options are passed to pcre[16|32]_study(),
143 causing just-in-time optimization to be set up if it is
144 available, for both full and partial matching. Specific JIT
145 compile options can be selected by following -s+ with a digit
146 in the range 1 to 7, which selects the JIT compile modes as
147 follows:
148
149 1 normal match only
150 2 soft partial match only
151 3 normal match and soft partial match
152 4 hard partial match only
153 6 soft and hard partial match
154 7 all three modes (default)
155
156 If -s++ is used instead of -s+ (with or without a following
157 digit), the text "(JIT)" is added to the first output line
158 after a match or no match when JIT-compiled code was actually
159 used.
160
161 Note that there are pattern options that can override -s,
162 either specifying no studying at all, or suppressing JIT com-
163 pilation.
164
165 If the /I or /D option is present on a pattern (requesting
166 output about the compiled pattern), information about the
167 result of studying is not included when studying is caused
168 only by -s and neither -i nor -d is present on the command
169 line. This behaviour means that the output from tests that
170 are run with and without -s should be identical, except when
171 options that output information about the actual running of a
172 match are set.
173
174 The -M, -t, and -tm options, which give information about
175 resources used, are likely to produce different output with
176 and without -s. Output may also differ if the /C option is
177 present on an individual pattern. This uses callouts to trace
178 the the matching process, and this may be different between
179 studied and non-studied patterns. If the pattern contains
180 (*MARK) items there may also be differences, for the same
181 reason. The -s command line option can be overridden for spe-
182 cific patterns that should never be studied (see the /S pat-
183 tern modifier below).
184
185 -t Run each compile, study, and match many times with a timer,
186 and output resulting time per compile or match (in millisec-
187 onds). Do not set -m with -t, because you will then get the
188 size output a zillion times, and the timing will be dis-
189 torted. You can control the number of iterations that are
190 used for timing by following -t with a number (as a separate
191 item on the command line). For example, "-t 1000" would iter-
192 ate 1000 times. The default is to iterate 500000 times.
193
194 -tm This is like -t except that it times only the matching phase,
195 not the compile or study phases.
196
197
198 DESCRIPTION
199
200 If pcretest is given two filename arguments, it reads from the first
201 and writes to the second. If it is given only one filename argument, it
202 reads from that file and writes to stdout. Otherwise, it reads from
203 stdin and writes to stdout, and prompts for each line of input, using
204 "re>" to prompt for regular expressions, and "data>" to prompt for data
205 lines.
206
207 When pcretest is built, a configuration option can specify that it
208 should be linked with the libreadline library. When this is done, if
209 the input is from a terminal, it is read using the readline() function.
210 This provides line-editing and history facilities. The output from the
211 -help option states whether or not readline() will be used.
212
213 The program handles any number of sets of input on a single input file.
214 Each set starts with a regular expression, and continues with any num-
215 ber of data lines to be matched against the pattern.
216
217 Each data line is matched separately and independently. If you want to
218 do multi-line matches, you have to use the \n escape sequence (or \r or
219 \r\n, etc., depending on the newline setting) in a single line of input
220 to encode the newline sequences. There is no limit on the length of
221 data lines; the input buffer is automatically extended if it is too
222 small.
223
224 An empty line signals the end of the data lines, at which point a new
225 regular expression is read. The regular expressions are given enclosed
226 in any non-alphanumeric delimiters other than backslash, for example:
227
228 /(a|bc)x+yz/
229
230 White space before the initial delimiter is ignored. A regular expres-
231 sion may be continued over several input lines, in which case the new-
232 line characters are included within it. It is possible to include the
233 delimiter within the pattern by escaping it, for example
234
235 /abc\/def/
236
237 If you do so, the escape and the delimiter form part of the pattern,
238 but since delimiters are always non-alphanumeric, this does not affect
239 its interpretation. If the terminating delimiter is immediately fol-
240 lowed by a backslash, for example,
241
242 /abc/\
243
244 then a backslash is added to the end of the pattern. This is done to
245 provide a way of testing the error condition that arises if a pattern
246 finishes with a backslash, because
247
248 /abc\/
249
250 is interpreted as the first line of a pattern that starts with "abc/",
251 causing pcretest to read the next line as a continuation of the regular
252 expression.
253
254
255 PATTERN MODIFIERS
256
257 A pattern may be followed by any number of modifiers, which are mostly
258 single characters, though some of these can be qualified by further
259 characters. Following Perl usage, these are referred to below as, for
260 example, "the /i modifier", even though the delimiter of the pattern
261 need not always be a slash, and no slash is used when writing modi-
262 fiers. White space may appear between the final pattern delimiter and
263 the first modifier, and between the modifiers themselves. For refer-
264 ence, here is a complete list of modifiers. They fall into several
265 groups that are described in detail in the following sections.
266
267 /8 set UTF mode
268 /? disable UTF validity check
269 /+ show remainder of subject after match
270 /= show all captures (not just those that are set)
271
272 /A set PCRE_ANCHORED
273 /B show compiled code
274 /C set PCRE_AUTO_CALLOUT
275 /D same as /B plus /I
276 /E set PCRE_DOLLAR_ENDONLY
277 /F flip byte order in compiled pattern
278 /f set PCRE_FIRSTLINE
279 /G find all matches (shorten string)
280 /g find all matches (use startoffset)
281 /I show information about pattern
282 /i set PCRE_CASELESS
283 /J set PCRE_DUPNAMES
284 /K show backtracking control names
285 /L set locale
286 /M show compiled memory size
287 /m set PCRE_MULTILINE
288 /N set PCRE_NO_AUTO_CAPTURE
289 /P use the POSIX wrapper
290 /S study the pattern after compilation
291 /s set PCRE_DOTALL
292 /T select character tables
293 /U set PCRE_UNGREEDY
294 /W set PCRE_UCP
295 /X set PCRE_EXTRA
296 /x set PCRE_EXTENDED
297 /Y set PCRE_NO_START_OPTIMIZE
298 /Z don't show lengths in /B output
299
300 /<any> set PCRE_NEWLINE_ANY
301 /<anycrlf> set PCRE_NEWLINE_ANYCRLF
302 /<cr> set PCRE_NEWLINE_CR
303 /<crlf> set PCRE_NEWLINE_CRLF
304 /<lf> set PCRE_NEWLINE_LF
305 /<bsr_anycrlf> set PCRE_BSR_ANYCRLF
306 /<bsr_unicode> set PCRE_BSR_UNICODE
307 /<JS> set PCRE_JAVASCRIPT_COMPAT
308
309
310 Perl-compatible modifiers
311
312 The /i, /m, /s, and /x modifiers set the PCRE_CASELESS, PCRE_MULTILINE,
313 PCRE_DOTALL, or PCRE_EXTENDED options, respectively, when
314 pcre[16|32]_compile() is called. These four modifier letters have the
315 same effect as they do in Perl. For example:
316
317 /caseless/i
318
319
320 Modifiers for other PCRE options
321
322 The following table shows additional modifiers for setting PCRE com-
323 pile-time options that do not correspond to anything in Perl:
324
325 /8 PCRE_UTF8 ) when using the 8-bit
326 /? PCRE_NO_UTF8_CHECK ) library
327
328 /8 PCRE_UTF16 ) when using the 16-bit
329 /? PCRE_NO_UTF16_CHECK ) library
330
331 /8 PCRE_UTF32 ) when using the 32-bit
332 /? PCRE_NO_UTF32_CHECK ) library
333
334 /A PCRE_ANCHORED
335 /C PCRE_AUTO_CALLOUT
336 /E PCRE_DOLLAR_ENDONLY
337 /f PCRE_FIRSTLINE
338 /J PCRE_DUPNAMES
339 /N PCRE_NO_AUTO_CAPTURE
340 /U PCRE_UNGREEDY
341 /W PCRE_UCP
342 /X PCRE_EXTRA
343 /Y PCRE_NO_START_OPTIMIZE
344 /<any> PCRE_NEWLINE_ANY
345 /<anycrlf> PCRE_NEWLINE_ANYCRLF
346 /<cr> PCRE_NEWLINE_CR
347 /<crlf> PCRE_NEWLINE_CRLF
348 /<lf> PCRE_NEWLINE_LF
349 /<bsr_anycrlf> PCRE_BSR_ANYCRLF
350 /<bsr_unicode> PCRE_BSR_UNICODE
351 /<JS> PCRE_JAVASCRIPT_COMPAT
352
353 The modifiers that are enclosed in angle brackets are literal strings
354 as shown, including the angle brackets, but the letters within can be
355 in either case. This example sets multiline matching with CRLF as the
356 line ending sequence:
357
358 /^abc/m<CRLF>
359
360 As well as turning on the PCRE_UTF8/16/32 option, the /8 modifier
361 causes all non-printing characters in output strings to be printed
362 using the \x{hh...} notation. Otherwise, those less than 0x100 are out-
363 put in hex without the curly brackets.
364
365 Full details of the PCRE options are given in the pcreapi documenta-
366 tion.
367
368 Finding all matches in a string
369
370 Searching for all possible matches within each subject string can be
371 requested by the /g or /G modifier. After finding a match, PCRE is
372 called again to search the remainder of the subject string. The differ-
373 ence between /g and /G is that the former uses the startoffset argument
374 to pcre[16|32]_exec() to start searching at a new point within the
375 entire string (which is in effect what Perl does), whereas the latter
376 passes over a shortened substring. This makes a difference to the
377 matching process if the pattern begins with a lookbehind assertion
378 (including \b or \B).
379
380 If any call to pcre[16|32]_exec() in a /g or /G sequence matches an
381 empty string, the next call is done with the PCRE_NOTEMPTY_ATSTART and
382 PCRE_ANCHORED flags set in order to search for another, non-empty,
383 match at the same point. If this second match fails, the start offset
384 is advanced, and the normal match is retried. This imitates the way
385 Perl handles such cases when using the /g modifier or the split() func-
386 tion. Normally, the start offset is advanced by one character, but if
387 the newline convention recognizes CRLF as a newline, and the current
388 character is CR followed by LF, an advance of two is used.
389
390 Other modifiers
391
392 There are yet more modifiers for controlling the way pcretest operates.
393
394 The /+ modifier requests that as well as outputting the substring that
395 matched the entire pattern, pcretest should in addition output the
396 remainder of the subject string. This is useful for tests where the
397 subject contains multiple copies of the same substring. If the + modi-
398 fier appears twice, the same action is taken for captured substrings.
399 In each case the remainder is output on the following line with a plus
400 character following the capture number. Note that this modifier must
401 not immediately follow the /S modifier because /S+ and /S++ have other
402 meanings.
403
404 The /= modifier requests that the values of all potential captured
405 parentheses be output after a match. By default, only those up to the
406 highest one actually used in the match are output (corresponding to the
407 return code from pcre[16|32]_exec()). Values in the offsets vector cor-
408 responding to higher numbers should be set to -1, and these are output
409 as "<unset>". This modifier gives a way of checking that this is hap-
410 pening.
411
412 The /B modifier is a debugging feature. It requests that pcretest out-
413 put a representation of the compiled code after compilation. Normally
414 this information contains length and offset values; however, if /Z is
415 also present, this data is replaced by spaces. This is a special fea-
416 ture for use in the automatic test scripts; it ensures that the same
417 output is generated for different internal link sizes.
418
419 The /D modifier is a PCRE debugging feature, and is equivalent to /BI,
420 that is, both the /B and the /I modifiers.
421
422 The /F modifier causes pcretest to flip the byte order of the 2-byte
423 and 4-byte fields in the compiled pattern. This facility is for testing
424 the feature in PCRE that allows it to execute patterns that were com-
425 piled on a host with a different endianness. This feature is not avail-
426 able when the POSIX interface to PCRE is being used, that is, when the
427 /P pattern modifier is specified. See also the section about saving and
428 reloading compiled patterns below.
429
430 The /I modifier requests that pcretest output information about the
431 compiled pattern (whether it is anchored, has a fixed first character,
432 and so on). It does this by calling pcre[16|32]_fullinfo() after com-
433 piling a pattern. If the pattern is studied, the results of that are
434 also output.
435
436 The /K modifier requests pcretest to show names from backtracking con-
437 trol verbs that are returned from calls to pcre[16|32]_exec(). It
438 causes pcretest to create a pcre[16|32]_extra block if one has not
439 already been created by a call to pcre[16|32]_study(), and to set the
440 PCRE_EXTRA_MARK flag and the mark field within it, every time that
441 pcre[16|32]_exec() is called. If the variable that the mark field
442 points to is non-NULL for a match, non-match, or partial match,
443 pcretest prints the string to which it points. For a match, this is
444 shown on a line by itself, tagged with "MK:". For a non-match it is
445 added to the message.
446
447 The /L modifier must be followed directly by the name of a locale, for
448 example,
449
450 /pattern/Lfr_FR
451
452 For this reason, it must be the last modifier. The given locale is set,
453 pcre[16|32]_maketables() is called to build a set of character tables
454 for the locale, and this is then passed to pcre[16|32]_compile() when
455 compiling the regular expression. Without an /L (or /T) modifier, NULL
456 is passed as the tables pointer; that is, /L applies only to the
457 expression on which it appears.
458
459 The /M modifier causes the size in bytes of the memory block used to
460 hold the compiled pattern to be output. This does not include the size
461 of the pcre[16|32] block; it is just the actual compiled data. If the
462 pattern is successfully studied with the PCRE_STUDY_JIT_COMPILE option,
463 the size of the JIT compiled code is also output.
464
465 The /S modifier causes pcre[16|32]_study() to be called after the
466 expression has been compiled, and the results used when the expression
467 is matched. There are a number of qualifying characters that may follow
468 /S. They may appear in any order.
469
470 If S is followed by an exclamation mark, pcre[16|32]_study() is called
471 with the PCRE_STUDY_EXTRA_NEEDED option, causing it always to return a
472 pcre_extra block, even when studying discovers no useful information.
473
474 If /S is followed by a second S character, it suppresses studying, even
475 if it was requested externally by the -s command line option. This
476 makes it possible to specify that certain patterns are always studied,
477 and others are never studied, independently of -s. This feature is used
478 in the test files in a few cases where the output is different when the
479 pattern is studied.
480
481 If the /S modifier is followed by a + character, the call to
482 pcre[16|32]_study() is made with all the JIT study options, requesting
483 just-in-time optimization support if it is available, for both normal
484 and partial matching. If you want to restrict the JIT compiling modes,
485 you can follow /S+ with a digit in the range 1 to 7:
486
487 1 normal match only
488 2 soft partial match only
489 3 normal match and soft partial match
490 4 hard partial match only
491 6 soft and hard partial match
492 7 all three modes (default)
493
494 If /S++ is used instead of /S+ (with or without a following digit), the
495 text "(JIT)" is added to the first output line after a match or no
496 match when JIT-compiled code was actually used.
497
498 Note that there is also an independent /+ modifier; it must not be
499 given immediately after /S or /S+ because this will be misinterpreted.
500
501 If JIT studying is successful, the compiled JIT code will automatically
502 be used when pcre[16|32]_exec() is run, except when incompatible run-
503 time options are specified. For more details, see the pcrejit documen-
504 tation. See also the \J escape sequence below for a way of setting the
505 size of the JIT stack.
506
507 Finally, if /S is followed by a minus character, JIT compilation is
508 suppressed, even if it was requested externally by the -s command line
509 option. This makes it possible to specify that JIT is never to be used
510 for certain patterns.
511
512 The /T modifier must be followed by a single digit. It causes a spe-
513 cific set of built-in character tables to be passed to pcre[16|32]_com-
514 pile(). It is used in the standard PCRE tests to check behaviour with
515 different character tables. The digit specifies the tables as follows:
516
517 0 the default ASCII tables, as distributed in
518 pcre_chartables.c.dist
519 1 a set of tables defining ISO 8859 characters
520
521 In table 1, some characters whose codes are greater than 128 are iden-
522 tified as letters, digits, spaces, etc.
523
524 Using the POSIX wrapper API
525
526 The /P modifier causes pcretest to call PCRE via the POSIX wrapper API
527 rather than its native API. This supports only the 8-bit library. When
528 /P is set, the following modifiers set options for the regcomp() func-
529 tion:
530
531 /i REG_ICASE
532 /m REG_NEWLINE
533 /N REG_NOSUB
534 /s REG_DOTALL )
535 /U REG_UNGREEDY ) These options are not part of
536 /W REG_UCP ) the POSIX standard
537 /8 REG_UTF8 )
538
539 The /+ modifier works as described above. All other modifiers are
540 ignored.
541
542
543 DATA LINES
544
545 Before each data line is passed to pcre[16|32]_exec(), leading and
546 trailing white space is removed, and it is then scanned for \ escapes.
547 Some of these are pretty esoteric features, intended for checking out
548 some of the more complicated features of PCRE. If you are just testing
549 "ordinary" regular expressions, you probably don't need any of these.
550 The following escapes are recognized:
551
552 \a alarm (BEL, \x07)
553 \b backspace (\x08)
554 \e escape (\x27)
555 \f form feed (\x0c)
556 \n newline (\x0a)
557 \qdd set the PCRE_MATCH_LIMIT limit to dd
558 (any number of digits)
559 \r carriage return (\x0d)
560 \t tab (\x09)
561 \v vertical tab (\x0b)
562 \nnn octal character (up to 3 octal digits); always
563 a byte unless > 255 in UTF-8 or 16-bit or 32-bit mode
564 \xhh hexadecimal byte (up to 2 hex digits)
565 \x{hh...} hexadecimal character (any number of hex digits)
566 \A pass the PCRE_ANCHORED option to pcre[16|32]_exec()
567 or pcre[16|32]_dfa_exec()
568 \B pass the PCRE_NOTBOL option to pcre[16|32]_exec()
569 or pcre[16|32]_dfa_exec()
570 \Cdd call pcre[16|32]_copy_substring() for substring dd
571 after a successful match (number less than 32)
572 \Cname call pcre[16|32]_copy_named_substring() for substring
573 "name" after a successful match (name termin-
574 ated by next non alphanumeric character)
575 \C+ show the current captured substrings at callout
576 time
577 \C- do not supply a callout function
578 \C!n return 1 instead of 0 when callout number n is
579 reached
580 \C!n!m return 1 instead of 0 when callout number n is
581 reached for the nth time
582 \C*n pass the number n (may be negative) as callout
583 data; this is used as the callout return value
584 \D use the pcre[16|32]_dfa_exec() match function
585 \F only shortest match for pcre[16|32]_dfa_exec()
586 \Gdd call pcre[16|32]_get_substring() for substring dd
587 after a successful match (number less than 32)
588 \Gname call pcre[16|32]_get_named_substring() for substring
589 "name" after a successful match (name termin-
590 ated by next non-alphanumeric character)
591 \Jdd set up a JIT stack of dd kilobytes maximum (any
592 number of digits)
593 \L call pcre[16|32]_get_substringlist() after a
594 successful match
595 \M discover the minimum MATCH_LIMIT and
596 MATCH_LIMIT_RECURSION settings
597 \N pass the PCRE_NOTEMPTY option to pcre[16|32]_exec()
598 or pcre[16|32]_dfa_exec(); if used twice, pass the
599 PCRE_NOTEMPTY_ATSTART option
600 \Odd set the size of the output vector passed to
601 pcre[16|32]_exec() to dd (any number of digits)
602 \P pass the PCRE_PARTIAL_SOFT option to pcre[16|32]_exec()
603 or pcre[16|32]_dfa_exec(); if used twice, pass the
604 PCRE_PARTIAL_HARD option
605 \Qdd set the PCRE_MATCH_LIMIT_RECURSION limit to dd
606 (any number of digits)
607 \R pass the PCRE_DFA_RESTART option to pcre[16|32]_dfa_exec()
608 \S output details of memory get/free calls during matching
609 \Y pass the PCRE_NO_START_OPTIMIZE option to
610 pcre[16|32]_exec()
611 or pcre[16|32]_dfa_exec()
612 \Z pass the PCRE_NOTEOL option to pcre[16|32]_exec()
613 or pcre[16|32]_dfa_exec()
614 \? pass the PCRE_NO_UTF[8|16|32]_CHECK option to
615 pcre[16|32]_exec() or pcre[16|32]_dfa_exec()
616 \>dd start the match at offset dd (optional "-"; then
617 any number of digits); this sets the startoffset
618 argument for pcre[16|32]_exec() or
619 pcre[16|32]_dfa_exec()
620 \<cr> pass the PCRE_NEWLINE_CR option to pcre[16|32]_exec()
621 or pcre[16|32]_dfa_exec()
622 \<lf> pass the PCRE_NEWLINE_LF option to pcre[16|32]_exec()
623 or pcre[16|32]_dfa_exec()
624 \<crlf> pass the PCRE_NEWLINE_CRLF option to pcre[16|32]_exec()
625 or pcre[16|32]_dfa_exec()
626 \<anycrlf> pass the PCRE_NEWLINE_ANYCRLF option to pcre[16|32]_exec()
627 or pcre[16|32]_dfa_exec()
628 \<any> pass the PCRE_NEWLINE_ANY option to pcre[16|32]_exec()
629 or pcre[16|32]_dfa_exec()
630
631 The use of \x{hh...} is not dependent on the use of the /8 modifier on
632 the pattern. It is recognized always. There may be any number of hexa-
633 decimal digits inside the braces; invalid values provoke error mes-
634 sages.
635
636 Note that \xhh specifies one byte rather than one character in UTF-8
637 mode; this makes it possible to construct invalid UTF-8 sequences for
638 testing purposes. On the other hand, \x{hh} is interpreted as a UTF-8
639 character in UTF-8 mode, generating more than one byte if the value is
640 greater than 127. When testing the 8-bit library not in UTF-8 mode,
641 \x{hh} generates one byte for values less than 256, and causes an error
642 for greater values.
643
644 In UTF-16 mode, all 4-digit \x{hhhh} values are accepted. This makes it
645 possible to construct invalid UTF-16 sequences for testing purposes.
646
647 In UTF-32 mode, all 4- to 8-digit \x{...} values are accepted. This
648 makes it possible to construct invalid UTF-32 sequences for testing
649 purposes.
650
651 The escapes that specify line ending sequences are literal strings,
652 exactly as shown. No more than one newline setting should be present in
653 any data line.
654
655 A backslash followed by anything else just escapes the anything else.
656 If the very last character is a backslash, it is ignored. This gives a
657 way of passing an empty line as data, since a real empty line termi-
658 nates the data input.
659
660 The \J escape provides a way of setting the maximum stack size that is
661 used by the just-in-time optimization code. It is ignored if JIT opti-
662 mization is not being used. Providing a stack that is larger than the
663 default 32K is necessary only for very complicated patterns.
664
665 If \M is present, pcretest calls pcre[16|32]_exec() several times, with
666 different values in the match_limit and match_limit_recursion fields of
667 the pcre[16|32]_extra data structure, until it finds the minimum num-
668 bers for each parameter that allow pcre[16|32]_exec() to complete with-
669 out error. Because this is testing a specific feature of the normal
670 interpretive pcre[16|32]_exec() execution, the use of any JIT optimiza-
671 tion that might have been set up by the /S+ qualifier of -s+ option is
672 disabled.
673
674 The match_limit number is a measure of the amount of backtracking that
675 takes place, and checking it out can be instructive. For most simple
676 matches, the number is quite small, but for patterns with very large
677 numbers of matching possibilities, it can become large very quickly
678 with increasing length of subject string. The match_limit_recursion
679 number is a measure of how much stack (or, if PCRE is compiled with
680 NO_RECURSE, how much heap) memory is needed to complete the match
681 attempt.
682
683 When \O is used, the value specified may be higher or lower than the
684 size set by the -O command line option (or defaulted to 45); \O applies
685 only to the call of pcre[16|32]_exec() for the line in which it
686 appears.
687
688 If the /P modifier was present on the pattern, causing the POSIX wrap-
689 per API to be used, the only option-setting sequences that have any
690 effect are \B, \N, and \Z, causing REG_NOTBOL, REG_NOTEMPTY, and
691 REG_NOTEOL, respectively, to be passed to regexec().
692
693
694 THE ALTERNATIVE MATCHING FUNCTION
695
696 By default, pcretest uses the standard PCRE matching function,
697 pcre[16|32]_exec() to match each data line. PCRE also supports an
698 alternative matching function, pcre[16|32]_dfa_test(), which operates
699 in a different way, and has some restrictions. The differences between
700 the two functions are described in the pcrematching documentation.
701
702 If a data line contains the \D escape sequence, or if the command line
703 contains the -dfa option, the alternative matching function is used.
704 This function finds all possible matches at a given point. If, however,
705 the \F escape sequence is present in the data line, it stops after the
706 first match is found. This is always the shortest possible match.
707
708
709 DEFAULT OUTPUT FROM PCRETEST
710
711 This section describes the output when the normal matching function,
712 pcre[16|32]_exec(), is being used.
713
714 When a match succeeds, pcretest outputs the list of captured substrings
715 that pcre[16|32]_exec() returns, starting with number 0 for the string
716 that matched the whole pattern. Otherwise, it outputs "No match" when
717 the return is PCRE_ERROR_NOMATCH, and "Partial match:" followed by the
718 partially matching substring when pcre[16|32]_exec() returns
719 PCRE_ERROR_PARTIAL. (Note that this is the entire substring that was
720 inspected during the partial match; it may include characters before
721 the actual match start if a lookbehind assertion, \K, \b, or \B was
722 involved.) For any other return, pcretest outputs the PCRE negative
723 error number and a short descriptive phrase. If the error is a failed
724 UTF string check, the offset of the start of the failing character and
725 the reason code are also output, provided that the size of the output
726 vector is at least two. Here is an example of an interactive pcretest
727 run.
728
729 $ pcretest
730 PCRE version 8.13 2011-04-30
731
732 re> /^abc(\d+)/
733 data> abc123
734 0: abc123
735 1: 123
736 data> xyz
737 No match
738
739 Unset capturing substrings that are not followed by one that is set are
740 not returned by pcre[16|32]_exec(), and are not shown by pcretest. In
741 the following example, there are two capturing substrings, but when the
742 first data line is matched, the second, unset substring is not shown.
743 An "internal" unset substring is shown as "<unset>", as for the second
744 data line.
745
746 re> /(a)|(b)/
747 data> a
748 0: a
749 1: a
750 data> b
751 0: b
752 1: <unset>
753 2: b
754
755 If the strings contain any non-printing characters, they are output as
756 \xhh escapes if the value is less than 256 and UTF mode is not set.
757 Otherwise they are output as \x{hh...} escapes. See below for the defi-
758 nition of non-printing characters. If the pattern has the /+ modifier,
759 the output for substring 0 is followed by the the rest of the subject
760 string, identified by "0+" like this:
761
762 re> /cat/+
763 data> cataract
764 0: cat
765 0+ aract
766
767 If the pattern has the /g or /G modifier, the results of successive
768 matching attempts are output in sequence, like this:
769
770 re> /\Bi(\w\w)/g
771 data> Mississippi
772 0: iss
773 1: ss
774 0: iss
775 1: ss
776 0: ipp
777 1: pp
778
779 "No match" is output only if the first match attempt fails. Here is an
780 example of a failure message (the offset 4 that is specified by \>4 is
781 past the end of the subject string):
782
783 re> /xyz/
784 data> xyz\>4
785 Error -24 (bad offset value)
786
787 If any of the sequences \C, \G, or \L are present in a data line that
788 is successfully matched, the substrings extracted by the convenience
789 functions are output with C, G, or L after the string number instead of
790 a colon. This is in addition to the normal full list. The string length
791 (that is, the return from the extraction function) is given in paren-
792 theses after each string for \C and \G.
793
794 Note that whereas patterns can be continued over several lines (a plain
795 ">" prompt is used for continuations), data lines may not. However new-
796 lines can be included in data by means of the \n escape (or \r, \r\n,
797 etc., depending on the newline sequence setting).
798
799
800 OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION
801
802 When the alternative matching function, pcre[16|32]_dfa_exec(), is used
803 (by means of the \D escape sequence or the -dfa command line option),
804 the output consists of a list of all the matches that start at the
805 first point in the subject where there is at least one match. For exam-
806 ple:
807
808 re> /(tang|tangerine|tan)/
809 data> yellow tangerine\D
810 0: tangerine
811 1: tang
812 2: tan
813
814 (Using the normal matching function on this data finds only "tang".)
815 The longest matching string is always given first (and numbered zero).
816 After a PCRE_ERROR_PARTIAL return, the output is "Partial match:", fol-
817 lowed by the partially matching substring. (Note that this is the
818 entire substring that was inspected during the partial match; it may
819 include characters before the actual match start if a lookbehind asser-
820 tion, \K, \b, or \B was involved.)
821
822 If /g is present on the pattern, the search for further matches resumes
823 at the end of the longest match. For example:
824
825 re> /(tang|tangerine|tan)/g
826 data> yellow tangerine and tangy sultana\D
827 0: tangerine
828 1: tang
829 2: tan
830 0: tang
831 1: tan
832 0: tan
833
834 Since the matching function does not support substring capture, the
835 escape sequences that are concerned with captured substrings are not
836 relevant.
837
838
839 RESTARTING AFTER A PARTIAL MATCH
840
841 When the alternative matching function has given the PCRE_ERROR_PARTIAL
842 return, indicating that the subject partially matched the pattern, you
843 can restart the match with additional subject data by means of the \R
844 escape sequence. For example:
845
846 re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
847 data> 23ja\P\D
848 Partial match: 23ja
849 data> n05\R\D
850 0: n05
851
852 For further information about partial matching, see the pcrepartial
853 documentation.
854
855
856 CALLOUTS
857
858 If the pattern contains any callout requests, pcretest's callout func-
859 tion is called during matching. This works with both matching func-
860 tions. By default, the called function displays the callout number, the
861 start and current positions in the text at the callout time, and the
862 next pattern item to be tested. For example:
863
864 --->pqrabcdef
865 0 ^ ^ \d
866
867 This output indicates that callout number 0 occurred for a match
868 attempt starting at the fourth character of the subject string, when
869 the pointer was at the seventh character of the data, and when the next
870 pattern item was \d. Just one circumflex is output if the start and
871 current positions are the same.
872
873 Callouts numbered 255 are assumed to be automatic callouts, inserted as
874 a result of the /C pattern modifier. In this case, instead of showing
875 the callout number, the offset in the pattern, preceded by a plus, is
876 output. For example:
877
878 re> /\d?[A-E]\*/C
879 data> E*
880 --->E*
881 +0 ^ \d?
882 +3 ^ [A-E]
883 +8 ^^ \*
884 +10 ^ ^
885 0: E*
886
887 If a pattern contains (*MARK) items, an additional line is output when-
888 ever a change of latest mark is passed to the callout function. For
889 example:
890
891 re> /a(*MARK:X)bc/C
892 data> abc
893 --->abc
894 +0 ^ a
895 +1 ^^ (*MARK:X)
896 +10 ^^ b
897 Latest Mark: X
898 +11 ^ ^ c
899 +12 ^ ^
900 0: abc
901
902 The mark changes between matching "a" and "b", but stays the same for
903 the rest of the match, so nothing more is output. If, as a result of
904 backtracking, the mark reverts to being unset, the text "<unset>" is
905 output.
906
907 The callout function in pcretest returns zero (carry on matching) by
908 default, but you can use a \C item in a data line (as described above)
909 to change this and other parameters of the callout.
910
911 Inserting callouts can be helpful when using pcretest to check compli-
912 cated regular expressions. For further information about callouts, see
913 the pcrecallout documentation.
914
915
916 NON-PRINTING CHARACTERS
917
918 When pcretest is outputting text in the compiled version of a pattern,
919 bytes other than 32-126 are always treated as non-printing characters
920 are are therefore shown as hex escapes.
921
922 When pcretest is outputting text that is a matched part of a subject
923 string, it behaves in the same way, unless a different locale has been
924 set for the pattern (using the /L modifier). In this case, the
925 isprint() function to distinguish printing and non-printing characters.
926
927
928 SAVING AND RELOADING COMPILED PATTERNS
929
930 The facilities described in this section are not available when the
931 POSIX interface to PCRE is being used, that is, when the /P pattern
932 modifier is specified.
933
934 When the POSIX interface is not in use, you can cause pcretest to write
935 a compiled pattern to a file, by following the modifiers with > and a
936 file name. For example:
937
938 /pattern/im >/some/file
939
940 See the pcreprecompile documentation for a discussion about saving and
941 re-using compiled patterns. Note that if the pattern was successfully
942 studied with JIT optimization, the JIT data cannot be saved.
943
944 The data that is written is binary. The first eight bytes are the
945 length of the compiled pattern data followed by the length of the
946 optional study data, each written as four bytes in big-endian order
947 (most significant byte first). If there is no study data (either the
948 pattern was not studied, or studying did not return any data), the sec-
949 ond length is zero. The lengths are followed by an exact copy of the
950 compiled pattern. If there is additional study data, this (excluding
951 any JIT data) follows immediately after the compiled pattern. After
952 writing the file, pcretest expects to read a new pattern.
953
954 A saved pattern can be reloaded into pcretest by specifying < and a
955 file name instead of a pattern. The name of the file must not contain a
956 < character, as otherwise pcretest will interpret the line as a pattern
957 delimited by < characters. For example:
958
959 re> </some/file
960 Compiled pattern loaded from /some/file
961 No study data
962
963 If the pattern was previously studied with the JIT optimization, the
964 JIT information cannot be saved and restored, and so is lost. When the
965 pattern has been loaded, pcretest proceeds to read data lines in the
966 usual way.
967
968 You can copy a file written by pcretest to a different host and reload
969 it there, even if the new host has opposite endianness to the one on
970 which the pattern was compiled. For example, you can compile on an i86
971 machine and run on a SPARC machine. When a pattern is reloaded on a
972 host with different endianness, the confirmation message is changed to:
973
974 Compiled pattern (byte-inverted) loaded from /some/file
975
976 The test suite contains some saved pre-compiled patterns with different
977 endianness. These are reloaded using "<!" instead of just "<". This
978 suppresses the "(byte-inverted)" text so that the output is the same on
979 all hosts. It also forces debugging output once the pattern has been
980 reloaded.
981
982 File names for saving and reloading can be absolute or relative, but
983 note that the shell facility of expanding a file name that starts with
984 a tilde (~) is not available.
985
986 The ability to save and reload files in pcretest is intended for test-
987 ing and experimentation. It is not intended for production use because
988 only a single pattern can be written to a file. Furthermore, there is
989 no facility for supplying custom character tables for use with a
990 reloaded pattern. If the original pattern was compiled with custom
991 tables, an attempt to match a subject string using a reloaded pattern
992 is likely to cause pcretest to crash. Finally, if you attempt to load
993 a file that is not in the correct format, the result is undefined.
994
995
996 SEE ALSO
997
998 pcre(3), pcre16(3), pcre32(3), pcreapi(3), pcrecallout(3), pcrejit,
999 pcrematching(3), pcrepartial(d), pcrepattern(3), pcreprecompile(3).
1000
1001
1002 AUTHOR
1003
1004 Philip Hazel
1005 University Computing Service
1006 Cambridge CB2 3QH, England.
1007
1008
1009 REVISION
1010
1011 Last updated: 10 September 2012
1012 Copyright (c) 1997-2012 University of Cambridge.

Properties

Name Value
svn:eol-style native
svn:keywords "Author Date Id Revision Url"

  ViewVC Help
Powered by ViewVC 1.1.5