ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

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


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

  ViewVC Help
Powered by ViewVC 1.1.5