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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5