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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5