ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

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


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

  ViewVC Help
Powered by ViewVC 1.1.5