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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1335 - (hide annotations) (download)
Tue May 28 09:13:59 2013 UTC (3 weeks, 1 day ago) by ph10
File size: 46568 byte(s)
Final source file tidies for 8.33 release.

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

Properties

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

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12