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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5