ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

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


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

  ViewVC Help
Powered by ViewVC 1.1.5