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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 691 - (show annotations)
Sun Sep 11 14:31:21 2011 UTC (3 years, 8 months ago) by ph10
File MIME type: text/html
File size: 38755 byte(s)
Error occurred while calculating annotation data.
Final source and document tidies for 8.20-RC1.
1 <html>
2 <head>
3 <title>pcretest specification</title>
4 </head>
5 <body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
6 <h1>pcretest man page</h1>
7 <p>
8 Return to the <a href="index.html">PCRE index page</a>.
9 </p>
10 <p>
11 This page is part of the PCRE HTML documentation. It was generated automatically
12 from the original man page. If there is any nonsense in it, please consult the
13 man page, in case the conversion went wrong.
14 <br>
15 <ul>
16 <li><a name="TOC1" href="#SEC1">SYNOPSIS</a>
17 <li><a name="TOC2" href="#SEC2">COMMAND LINE OPTIONS</a>
18 <li><a name="TOC3" href="#SEC3">DESCRIPTION</a>
19 <li><a name="TOC4" href="#SEC4">PATTERN MODIFIERS</a>
20 <li><a name="TOC5" href="#SEC5">DATA LINES</a>
21 <li><a name="TOC6" href="#SEC6">THE ALTERNATIVE MATCHING FUNCTION</a>
22 <li><a name="TOC7" href="#SEC7">DEFAULT OUTPUT FROM PCRETEST</a>
23 <li><a name="TOC8" href="#SEC8">OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION</a>
24 <li><a name="TOC9" href="#SEC9">RESTARTING AFTER A PARTIAL MATCH</a>
25 <li><a name="TOC10" href="#SEC10">CALLOUTS</a>
26 <li><a name="TOC11" href="#SEC11">NON-PRINTING CHARACTERS</a>
27 <li><a name="TOC12" href="#SEC12">SAVING AND RELOADING COMPILED PATTERNS</a>
28 <li><a name="TOC13" href="#SEC13">SEE ALSO</a>
29 <li><a name="TOC14" href="#SEC14">AUTHOR</a>
30 <li><a name="TOC15" href="#SEC15">REVISION</a>
31 </ul>
32 <br><a name="SEC1" href="#TOC1">SYNOPSIS</a><br>
33 <P>
34 <b>pcretest [options] [input file [output file]]</b>
35 <br>
36 <br>
37 <b>pcretest</b> was written as a test program for the PCRE regular expression
38 library itself, but it can also be used for experimenting with regular
39 expressions. This document describes the features of the test program; for
40 details of the regular expressions themselves, see the
41 <a href="pcrepattern.html"><b>pcrepattern</b></a>
42 documentation. For details of the PCRE library function calls and their
43 options, see the
44 <a href="pcreapi.html"><b>pcreapi</b></a>
45 documentation. The input for <b>pcretest</b> is a sequence of regular expression
46 patterns and strings to be matched, as described below. The output shows the
47 result of each match. Options on the command line and the patterns control PCRE
48 options and exactly what is output.
49 </P>
50 <br><a name="SEC2" href="#TOC1">COMMAND LINE OPTIONS</a><br>
51 <P>
52 <b>-b</b>
53 Behave as if each pattern has the <b>/B</b> (show byte code) modifier; the
54 internal form is output after compilation.
55 </P>
56 <P>
57 <b>-C</b>
58 Output the version number of the PCRE library, and all available information
59 about the optional features that are included, and then exit.
60 </P>
61 <P>
62 <b>-d</b>
63 Behave as if each pattern has the <b>/D</b> (debug) modifier; the internal
64 form and information about the compiled pattern is output after compilation;
65 <b>-d</b> is equivalent to <b>-b -i</b>.
66 </P>
67 <P>
68 <b>-dfa</b>
69 Behave as if each data line contains the \D escape sequence; this causes the
70 alternative matching function, <b>pcre_dfa_exec()</b>, to be used instead of the
71 standard <b>pcre_exec()</b> function (more detail is given below).
72 </P>
73 <P>
74 <b>-help</b>
75 Output a brief summary these options and then exit.
76 </P>
77 <P>
78 <b>-i</b>
79 Behave as if each pattern has the <b>/I</b> modifier; information about the
80 compiled pattern is given after compilation.
81 </P>
82 <P>
83 <b>-M</b>
84 Behave as if each data line contains the \M escape sequence; this causes
85 PCRE to discover the minimum MATCH_LIMIT and MATCH_LIMIT_RECURSION settings by
86 calling <b>pcre_exec()</b> repeatedly with different limits.
87 </P>
88 <P>
89 <b>-m</b>
90 Output the size of each compiled pattern after it has been compiled. This is
91 equivalent to adding <b>/M</b> to each regular expression.
92 </P>
93 <P>
94 <b>-o</b> <i>osize</i>
95 Set the number of elements in the output vector that is used when calling
96 <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b> to be <i>osize</i>. The default value
97 is 45, which is enough for 14 capturing subexpressions for <b>pcre_exec()</b> or
98 22 different matches for <b>pcre_dfa_exec()</b>. The vector size can be
99 changed for individual matching calls by including \O in the data line (see
100 below).
101 </P>
102 <P>
103 <b>-p</b>
104 Behave as if each pattern has the <b>/P</b> modifier; the POSIX wrapper API is
105 used to call PCRE. None of the other options has any effect when <b>-p</b> is
106 set.
107 </P>
108 <P>
109 <b>-q</b>
110 Do not output the version number of <b>pcretest</b> at the start of execution.
111 </P>
112 <P>
113 <b>-S</b> <i>size</i>
114 On Unix-like systems, set the size of the run-time stack to <i>size</i>
115 megabytes.
116 </P>
117 <P>
118 <b>-s</b> or <b>-s+</b>
119 Behave as if each pattern has the <b>/S</b> modifier; in other words, force each
120 pattern to be studied. If <b>-s+</b> is used, the PCRE_STUDY_JIT_COMPILE flag is
121 passed to <b>pcre_study()</b>, causing just-in-time optimization to be set up if
122 it is available. If the <b>/I</b> or <b>/D</b> option is present on a pattern
123 (requesting output about the compiled pattern), information about the result of
124 studying is not included when studying is caused only by <b>-s</b> and neither
125 <b>-i</b> nor <b>-d</b> is present on the command line. This behaviour means that
126 the output from tests that are run with and without <b>-s</b> should be
127 identical, except when options that output information about the actual running
128 of a match are set. The <b>-M</b>, <b>-t</b>, and <b>-tm</b> options, which give
129 information about resources used, are likely to produce different output with
130 and without <b>-s</b>. Output may also differ if the <b>/C</b> option is present
131 on an individual pattern. This uses callouts to trace the the matching process,
132 and this may be different between studied and non-studied patterns. If the
133 pattern contains (*MARK) items there may also be differences, for the same
134 reason. The <b>-s</b> command line option can be overridden for specific
135 patterns that should never be studied (see the <b>/S</b> pattern modifier
136 below).
137 </P>
138 <P>
139 <b>-t</b>
140 Run each compile, study, and match many times with a timer, and output
141 resulting time per compile or match (in milliseconds). Do not set <b>-m</b> with
142 <b>-t</b>, because you will then get the size output a zillion times, and the
143 timing will be distorted. You can control the number of iterations that are
144 used for timing by following <b>-t</b> with a number (as a separate item on the
145 command line). For example, "-t 1000" would iterate 1000 times. The default is
146 to iterate 500000 times.
147 </P>
148 <P>
149 <b>-tm</b>
150 This is like <b>-t</b> except that it times only the matching phase, not the
151 compile or study phases.
152 </P>
153 <br><a name="SEC3" href="#TOC1">DESCRIPTION</a><br>
154 <P>
155 If <b>pcretest</b> is given two filename arguments, it reads from the first and
156 writes to the second. If it is given only one filename argument, it reads from
157 that file and writes to stdout. Otherwise, it reads from stdin and writes to
158 stdout, and prompts for each line of input, using "re&#62;" to prompt for regular
159 expressions, and "data&#62;" to prompt for data lines.
160 </P>
161 <P>
162 When <b>pcretest</b> is built, a configuration option can specify that it should
163 be linked with the <b>libreadline</b> library. When this is done, if the input
164 is from a terminal, it is read using the <b>readline()</b> function. This
165 provides line-editing and history facilities. The output from the <b>-help</b>
166 option states whether or not <b>readline()</b> will be used.
167 </P>
168 <P>
169 The program handles any number of sets of input on a single input file. Each
170 set starts with a regular expression, and continues with any number of data
171 lines to be matched against the pattern.
172 </P>
173 <P>
174 Each data line is matched separately and independently. If you want to do
175 multi-line matches, you have to use the \n escape sequence (or \r or \r\n,
176 etc., depending on the newline setting) in a single line of input to encode the
177 newline sequences. There is no limit on the length of data lines; the input
178 buffer is automatically extended if it is too small.
179 </P>
180 <P>
181 An empty line signals the end of the data lines, at which point a new regular
182 expression is read. The regular expressions are given enclosed in any
183 non-alphanumeric delimiters other than backslash, for example:
184 <pre>
185 /(a|bc)x+yz/
186 </pre>
187 White space before the initial delimiter is ignored. A regular expression may
188 be continued over several input lines, in which case the newline characters are
189 included within it. It is possible to include the delimiter within the pattern
190 by escaping it, for example
191 <pre>
192 /abc\/def/
193 </pre>
194 If you do so, the escape and the delimiter form part of the pattern, but since
195 delimiters are always non-alphanumeric, this does not affect its interpretation.
196 If the terminating delimiter is immediately followed by a backslash, for
197 example,
198 <pre>
199 /abc/\
200 </pre>
201 then a backslash is added to the end of the pattern. This is done to provide a
202 way of testing the error condition that arises if a pattern finishes with a
203 backslash, because
204 <pre>
205 /abc\/
206 </pre>
207 is interpreted as the first line of a pattern that starts with "abc/", causing
208 pcretest to read the next line as a continuation of the regular expression.
209 </P>
210 <br><a name="SEC4" href="#TOC1">PATTERN MODIFIERS</a><br>
211 <P>
212 A pattern may be followed by any number of modifiers, which are mostly single
213 characters. Following Perl usage, these are referred to below as, for example,
214 "the <b>/i</b> modifier", even though the delimiter of the pattern need not
215 always be a slash, and no slash is used when writing modifiers. White space may
216 appear between the final pattern delimiter and the first modifier, and between
217 the modifiers themselves.
218 </P>
219 <P>
220 The <b>/i</b>, <b>/m</b>, <b>/s</b>, and <b>/x</b> modifiers set the PCRE_CASELESS,
221 PCRE_MULTILINE, PCRE_DOTALL, or PCRE_EXTENDED options, respectively, when
222 <b>pcre_compile()</b> is called. These four modifier letters have the same
223 effect as they do in Perl. For example:
224 <pre>
225 /caseless/i
226 </pre>
227 The following table shows additional modifiers for setting PCRE compile-time
228 options that do not correspond to anything in Perl:
229 <pre>
230 <b>/8</b> PCRE_UTF8
231 <b>/?</b> PCRE_NO_UTF8_CHECK
232 <b>/A</b> PCRE_ANCHORED
233 <b>/C</b> PCRE_AUTO_CALLOUT
234 <b>/E</b> PCRE_DOLLAR_ENDONLY
235 <b>/f</b> PCRE_FIRSTLINE
236 <b>/J</b> PCRE_DUPNAMES
237 <b>/N</b> PCRE_NO_AUTO_CAPTURE
238 <b>/U</b> PCRE_UNGREEDY
239 <b>/W</b> PCRE_UCP
240 <b>/X</b> PCRE_EXTRA
241 <b>/Y</b> PCRE_NO_START_OPTIMIZE
242 <b>/&#60;JS&#62;</b> PCRE_JAVASCRIPT_COMPAT
243 <b>/&#60;cr&#62;</b> PCRE_NEWLINE_CR
244 <b>/&#60;lf&#62;</b> PCRE_NEWLINE_LF
245 <b>/&#60;crlf&#62;</b> PCRE_NEWLINE_CRLF
246 <b>/&#60;anycrlf&#62;</b> PCRE_NEWLINE_ANYCRLF
247 <b>/&#60;any&#62;</b> PCRE_NEWLINE_ANY
248 <b>/&#60;bsr_anycrlf&#62;</b> PCRE_BSR_ANYCRLF
249 <b>/&#60;bsr_unicode&#62;</b> PCRE_BSR_UNICODE
250 </pre>
251 The modifiers that are enclosed in angle brackets are literal strings as shown,
252 including the angle brackets, but the letters within can be in either case.
253 This example sets multiline matching with CRLF as the line ending sequence:
254 <pre>
255 /^abc/m&#60;CRLF&#62;
256 </pre>
257 As well as turning on the PCRE_UTF8 option, the <b>/8</b> modifier also causes
258 any non-printing characters in output strings to be printed using the
259 \x{hh...} notation if they are valid UTF-8 sequences. Full details of the PCRE
260 options are given in the
261 <a href="pcreapi.html"><b>pcreapi</b></a>
262 documentation.
263 </P>
264 <br><b>
265 Finding all matches in a string
266 </b><br>
267 <P>
268 Searching for all possible matches within each subject string can be requested
269 by the <b>/g</b> or <b>/G</b> modifier. After finding a match, PCRE is called
270 again to search the remainder of the subject string. The difference between
271 <b>/g</b> and <b>/G</b> is that the former uses the <i>startoffset</i> argument to
272 <b>pcre_exec()</b> to start searching at a new point within the entire string
273 (which is in effect what Perl does), whereas the latter passes over a shortened
274 substring. This makes a difference to the matching process if the pattern
275 begins with a lookbehind assertion (including \b or \B).
276 </P>
277 <P>
278 If any call to <b>pcre_exec()</b> in a <b>/g</b> or <b>/G</b> sequence matches an
279 empty string, the next call is done with the PCRE_NOTEMPTY_ATSTART and
280 PCRE_ANCHORED flags set in order to search for another, non-empty, match at the
281 same point. If this second match fails, the start offset is advanced, and the
282 normal match is retried. This imitates the way Perl handles such cases when
283 using the <b>/g</b> modifier or the <b>split()</b> function. Normally, the start
284 offset is advanced by one character, but if the newline convention recognizes
285 CRLF as a newline, and the current character is CR followed by LF, an advance
286 of two is used.
287 </P>
288 <br><b>
289 Other modifiers
290 </b><br>
291 <P>
292 There are yet more modifiers for controlling the way <b>pcretest</b>
293 operates.
294 </P>
295 <P>
296 The <b>/+</b> modifier requests that as well as outputting the substring that
297 matched the entire pattern, <b>pcretest</b> should in addition output the
298 remainder of the subject string. This is useful for tests where the subject
299 contains multiple copies of the same substring. If the <b>+</b> modifier appears
300 twice, the same action is taken for captured substrings. In each case the
301 remainder is output on the following line with a plus character following the
302 capture number. Note that this modifier must not immediately follow the /S
303 modifier because /S+ has another meaning.
304 </P>
305 <P>
306 The <b>/=</b> modifier requests that the values of all potential captured
307 parentheses be output after a match by <b>pcre_exec()</b>. By default, only
308 those up to the highest one actually used in the match are output
309 (corresponding to the return code from <b>pcre_exec()</b>). Values in the
310 offsets vector corresponding to higher numbers should be set to -1, and these
311 are output as "&#60;unset&#62;". This modifier gives a way of checking that this is
312 happening.
313 </P>
314 <P>
315 The <b>/B</b> modifier is a debugging feature. It requests that <b>pcretest</b>
316 output a representation of the compiled byte code after compilation. Normally
317 this information contains length and offset values; however, if <b>/Z</b> is
318 also present, this data is replaced by spaces. This is a special feature for
319 use in the automatic test scripts; it ensures that the same output is generated
320 for different internal link sizes.
321 </P>
322 <P>
323 The <b>/D</b> modifier is a PCRE debugging feature, and is equivalent to
324 <b>/BI</b>, that is, both the <b>/B</b> and the <b>/I</b> modifiers.
325 </P>
326 <P>
327 The <b>/F</b> modifier causes <b>pcretest</b> to flip the byte order of the
328 fields in the compiled pattern that contain 2-byte and 4-byte numbers. This
329 facility is for testing the feature in PCRE that allows it to execute patterns
330 that were compiled on a host with a different endianness. This feature is not
331 available when the POSIX interface to PCRE is being used, that is, when the
332 <b>/P</b> pattern modifier is specified. See also the section about saving and
333 reloading compiled patterns below.
334 </P>
335 <P>
336 The <b>/I</b> modifier requests that <b>pcretest</b> output information about the
337 compiled pattern (whether it is anchored, has a fixed first character, and
338 so on). It does this by calling <b>pcre_fullinfo()</b> after compiling a
339 pattern. If the pattern is studied, the results of that are also output.
340 </P>
341 <P>
342 The <b>/K</b> modifier requests <b>pcretest</b> to show names from backtracking
343 control verbs that are returned from calls to <b>pcre_exec()</b>. It causes
344 <b>pcretest</b> to create a <b>pcre_extra</b> block if one has not already been
345 created by a call to <b>pcre_study()</b>, and to set the PCRE_EXTRA_MARK flag
346 and the <b>mark</b> field within it, every time that <b>pcre_exec()</b> is
347 called. If the variable that the <b>mark</b> field points to is non-NULL for a
348 match, non-match, or partial match, <b>pcretest</b> prints the string to which
349 it points. For a match, this is shown on a line by itself, tagged with "MK:".
350 For a non-match it is added to the message.
351 </P>
352 <P>
353 The <b>/L</b> modifier must be followed directly by the name of a locale, for
354 example,
355 <pre>
356 /pattern/Lfr_FR
357 </pre>
358 For this reason, it must be the last modifier. The given locale is set,
359 <b>pcre_maketables()</b> is called to build a set of character tables for the
360 locale, and this is then passed to <b>pcre_compile()</b> when compiling the
361 regular expression. Without an <b>/L</b> (or <b>/T</b>) modifier, NULL is passed
362 as the tables pointer; that is, <b>/L</b> applies only to the expression on
363 which it appears.
364 </P>
365 <P>
366 The <b>/M</b> modifier causes the size of memory block used to hold the compiled
367 pattern to be output.
368 </P>
369 <P>
370 If the <b>/S</b> modifier appears once, it causes <b>pcre_study()</b> to be
371 called after the expression has been compiled, and the results used when the
372 expression is matched. If <b>/S</b> appears twice, it suppresses studying, even
373 if it was requested externally by the <b>-s</b> command line option. This makes
374 it possible to specify that certain patterns are always studied, and others are
375 never studied, independently of <b>-s</b>. This feature is used in the test
376 files in a few cases where the output is different when the pattern is studied.
377 </P>
378 <P>
379 If the <b>/S</b> modifier is immediately followed by a + character, the call to
380 <b>pcre_study()</b> is made with the PCRE_STUDY_JIT_COMPILE option, requesting
381 just-in-time optimization support if it is available. Note that there is also a
382 <b>/+</b> modifier; it must not be given immediately after <b>/S</b> because this
383 will be misinterpreted. If JIT studying is successful, it will automatically be
384 used when <b>pcre_exec()</b> is run, except when incompatible run-time options
385 are specified. These include the partial matching options; a complete list is
386 given in the
387 <a href="pcrejit.html"><b>pcrejit</b></a>
388 documentation. See also the <b>\J</b> escape sequence below for a way of
389 setting the size of the JIT stack.
390 </P>
391 <P>
392 The <b>/T</b> modifier must be followed by a single digit. It causes a specific
393 set of built-in character tables to be passed to <b>pcre_compile()</b>. It is
394 used in the standard PCRE tests to check behaviour with different character
395 tables. The digit specifies the tables as follows:
396 <pre>
397 0 the default ASCII tables, as distributed in
398 pcre_chartables.c.dist
399 1 a set of tables defining ISO 8859 characters
400 </pre>
401 In table 1, some characters whose codes are greater than 128 are identified as
402 letters, digits, spaces, etc.
403 </P>
404 <br><b>
405 Using the POSIX wrapper API
406 </b><br>
407 <P>
408 The <b>/P</b> modifier causes <b>pcretest</b> to call PCRE via the POSIX wrapper
409 API rather than its native API. When <b>/P</b> is set, the following modifiers
410 set options for the <b>regcomp()</b> function:
411 <pre>
412 /i REG_ICASE
413 /m REG_NEWLINE
414 /N REG_NOSUB
415 /s REG_DOTALL )
416 /U REG_UNGREEDY ) These options are not part of
417 /W REG_UCP ) the POSIX standard
418 /8 REG_UTF8 )
419 </pre>
420 The <b>/+</b> modifier works as described above. All other modifiers are
421 ignored.
422 </P>
423 <br><a name="SEC5" href="#TOC1">DATA LINES</a><br>
424 <P>
425 Before each data line is passed to <b>pcre_exec()</b>, leading and trailing
426 white space is removed, and it is then scanned for \ escapes. Some of these
427 are pretty esoteric features, intended for checking out some of the more
428 complicated features of PCRE. If you are just testing "ordinary" regular
429 expressions, you probably don't need any of these. The following escapes are
430 recognized:
431 <pre>
432 \a alarm (BEL, \x07)
433 \b backspace (\x08)
434 \e escape (\x27)
435 \f form feed (\x0c)
436 \n newline (\x0a)
437 \qdd set the PCRE_MATCH_LIMIT limit to dd (any number of digits)
438 \r carriage return (\x0d)
439 \t tab (\x09)
440 \v vertical tab (\x0b)
441 \nnn octal character (up to 3 octal digits)
442 always a byte unless &#62; 255 in UTF-8 mode
443 \xhh hexadecimal byte (up to 2 hex digits)
444 \x{hh...} hexadecimal character, any number of digits in UTF-8 mode
445 \A pass the PCRE_ANCHORED option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
446 \B pass the PCRE_NOTBOL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
447 \Cdd call pcre_copy_substring() for substring dd after a successful match (number less than 32)
448 \Cname call pcre_copy_named_substring() for substring "name" after a successful match (name termin-
449 ated by next non alphanumeric character)
450 \C+ show the current captured substrings at callout time
451 \C- do not supply a callout function
452 \C!n return 1 instead of 0 when callout number n is reached
453 \C!n!m return 1 instead of 0 when callout number n is reached for the nth time
454 \C*n pass the number n (may be negative) as callout data; this is used as the callout return value
455 \D use the <b>pcre_dfa_exec()</b> match function
456 \F only shortest match for <b>pcre_dfa_exec()</b>
457 \Gdd call pcre_get_substring() for substring dd after a successful match (number less than 32)
458 \Gname call pcre_get_named_substring() for substring "name" after a successful match (name termin-
459 ated by next non-alphanumeric character)
460 \Jdd set up a JIT stack of dd kilobytes maximum (any number of digits)
461 \L call pcre_get_substringlist() after a successful match
462 \M discover the minimum MATCH_LIMIT and MATCH_LIMIT_RECURSION settings
463 \N pass the PCRE_NOTEMPTY option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>; if used twice, pass the
464 PCRE_NOTEMPTY_ATSTART option
465 \Odd set the size of the output vector passed to <b>pcre_exec()</b> to dd (any number of digits)
466 \P pass the PCRE_PARTIAL_SOFT option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>; if used twice, pass the
467 PCRE_PARTIAL_HARD option
468 \Qdd set the PCRE_MATCH_LIMIT_RECURSION limit to dd (any number of digits)
469 \R pass the PCRE_DFA_RESTART option to <b>pcre_dfa_exec()</b>
470 \S output details of memory get/free calls during matching
471 \Y pass the PCRE_NO_START_OPTIMIZE option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
472 \Z pass the PCRE_NOTEOL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
473 \? pass the PCRE_NO_UTF8_CHECK option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
474 \&#62;dd start the match at offset dd (optional "-"; then any number of digits); this sets the <i>startoffset</i>
475 argument for <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
476 \&#60;cr&#62; pass the PCRE_NEWLINE_CR option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
477 \&#60;lf&#62; pass the PCRE_NEWLINE_LF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
478 \&#60;crlf&#62; pass the PCRE_NEWLINE_CRLF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
479 \&#60;anycrlf&#62; pass the PCRE_NEWLINE_ANYCRLF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
480 \&#60;any&#62; pass the PCRE_NEWLINE_ANY option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
481 </pre>
482 Note that \xhh always specifies one byte, even in UTF-8 mode; this makes it
483 possible to construct invalid UTF-8 sequences for testing purposes. On the
484 other hand, \x{hh} is interpreted as a UTF-8 character in UTF-8 mode,
485 generating more than one byte if the value is greater than 127. When not in
486 UTF-8 mode, it generates one byte for values less than 256, and causes an error
487 for greater values.
488 </P>
489 <P>
490 The escapes that specify line ending sequences are literal strings, exactly as
491 shown. No more than one newline setting should be present in any data line.
492 </P>
493 <P>
494 A backslash followed by anything else just escapes the anything else. If
495 the very last character is a backslash, it is ignored. This gives a way of
496 passing an empty line as data, since a real empty line terminates the data
497 input.
498 </P>
499 <P>
500 The <b>\J</b> escape provides a way of setting the maximum stack size that is
501 used by the just-in-time optimization code. It is ignored if JIT optimization
502 is not being used. Providing a stack that is larger than the default 32K is
503 necessary only for very complicated patterns.
504 </P>
505 <P>
506 If \M is present, <b>pcretest</b> calls <b>pcre_exec()</b> several times, with
507 different values in the <i>match_limit</i> and <i>match_limit_recursion</i>
508 fields of the <b>pcre_extra</b> data structure, until it finds the minimum
509 numbers for each parameter that allow <b>pcre_exec()</b> to complete without
510 error. Because this is testing a specific feature of the normal interpretive
511 <b>pcre_exec()</b> execution, the use of any JIT optimization that might have
512 been set up by the <b>/S+</b> qualifier of <b>-s+</b> option is disabled.
513 </P>
514 <P>
515 The <i>match_limit</i> number is a measure of the amount of backtracking
516 that takes place, and checking it out can be instructive. For most simple
517 matches, the number is quite small, but for patterns with very large numbers of
518 matching possibilities, it can become large very quickly with increasing length
519 of subject string. The <i>match_limit_recursion</i> number is a measure of how
520 much stack (or, if PCRE is compiled with NO_RECURSE, how much heap) memory is
521 needed to complete the match attempt.
522 </P>
523 <P>
524 When \O is used, the value specified may be higher or lower than the size set
525 by the <b>-O</b> command line option (or defaulted to 45); \O applies only to
526 the call of <b>pcre_exec()</b> for the line in which it appears.
527 </P>
528 <P>
529 If the <b>/P</b> modifier was present on the pattern, causing the POSIX wrapper
530 API to be used, the only option-setting sequences that have any effect are \B,
531 \N, and \Z, causing REG_NOTBOL, REG_NOTEMPTY, and REG_NOTEOL, respectively,
532 to be passed to <b>regexec()</b>.
533 </P>
534 <P>
535 The use of \x{hh...} to represent UTF-8 characters is not dependent on the use
536 of the <b>/8</b> modifier on the pattern. It is recognized always. There may be
537 any number of hexadecimal digits inside the braces. The result is from one to
538 six bytes, encoded according to the original UTF-8 rules of RFC 2279. This
539 allows for values in the range 0 to 0x7FFFFFFF. Note that not all of those are
540 valid Unicode code points, or indeed valid UTF-8 characters according to the
541 later rules in RFC 3629.
542 </P>
543 <br><a name="SEC6" href="#TOC1">THE ALTERNATIVE MATCHING FUNCTION</a><br>
544 <P>
545 By default, <b>pcretest</b> uses the standard PCRE matching function,
546 <b>pcre_exec()</b> to match each data line. From release 6.0, PCRE supports an
547 alternative matching function, <b>pcre_dfa_test()</b>, which operates in a
548 different way, and has some restrictions. The differences between the two
549 functions are described in the
550 <a href="pcrematching.html"><b>pcrematching</b></a>
551 documentation.
552 </P>
553 <P>
554 If a data line contains the \D escape sequence, or if the command line
555 contains the <b>-dfa</b> option, the alternative matching function is called.
556 This function finds all possible matches at a given point. If, however, the \F
557 escape sequence is present in the data line, it stops after the first match is
558 found. This is always the shortest possible match.
559 </P>
560 <br><a name="SEC7" href="#TOC1">DEFAULT OUTPUT FROM PCRETEST</a><br>
561 <P>
562 This section describes the output when the normal matching function,
563 <b>pcre_exec()</b>, is being used.
564 </P>
565 <P>
566 When a match succeeds, <b>pcretest</b> outputs the list of captured substrings
567 that <b>pcre_exec()</b> returns, starting with number 0 for the string that
568 matched the whole pattern. Otherwise, it outputs "No match" when the return is
569 PCRE_ERROR_NOMATCH, and "Partial match:" followed by the partially matching
570 substring when <b>pcre_exec()</b> returns PCRE_ERROR_PARTIAL. (Note that this is
571 the entire substring that was inspected during the partial match; it may
572 include characters before the actual match start if a lookbehind assertion,
573 \K, \b, or \B was involved.) For any other return, <b>pcretest</b> outputs
574 the PCRE negative error number and a short descriptive phrase. If the error is
575 a failed UTF-8 string check, the byte offset of the start of the failing
576 character and the reason code are also output, provided that the size of the
577 output vector is at least two. Here is an example of an interactive
578 <b>pcretest</b> run.
579 <pre>
580 $ pcretest
581 PCRE version 8.13 2011-04-30
582
583 re&#62; /^abc(\d+)/
584 data&#62; abc123
585 0: abc123
586 1: 123
587 data&#62; xyz
588 No match
589 </pre>
590 Unset capturing substrings that are not followed by one that is set are not
591 returned by <b>pcre_exec()</b>, and are not shown by <b>pcretest</b>. In the
592 following example, there are two capturing substrings, but when the first data
593 line is matched, the second, unset substring is not shown. An "internal" unset
594 substring is shown as "&#60;unset&#62;", as for the second data line.
595 <pre>
596 re&#62; /(a)|(b)/
597 data&#62; a
598 0: a
599 1: a
600 data&#62; b
601 0: b
602 1: &#60;unset&#62;
603 2: b
604 </pre>
605 If the strings contain any non-printing characters, they are output as \0x
606 escapes, or as \x{...} escapes if the <b>/8</b> modifier was present on the
607 pattern. See below for the definition of non-printing characters. If the
608 pattern has the <b>/+</b> modifier, the output for substring 0 is followed by
609 the the rest of the subject string, identified by "0+" like this:
610 <pre>
611 re&#62; /cat/+
612 data&#62; cataract
613 0: cat
614 0+ aract
615 </pre>
616 If the pattern has the <b>/g</b> or <b>/G</b> modifier, the results of successive
617 matching attempts are output in sequence, like this:
618 <pre>
619 re&#62; /\Bi(\w\w)/g
620 data&#62; Mississippi
621 0: iss
622 1: ss
623 0: iss
624 1: ss
625 0: ipp
626 1: pp
627 </pre>
628 "No match" is output only if the first match attempt fails. Here is an example
629 of a failure message (the offset 4 that is specified by \&#62;4 is past the end of
630 the subject string):
631 <pre>
632 re&#62; /xyz/
633 data&#62; xyz\&#62;4
634 Error -24 (bad offset value)
635 </PRE>
636 </P>
637 <P>
638 If any of the sequences <b>\C</b>, <b>\G</b>, or <b>\L</b> are present in a
639 data line that is successfully matched, the substrings extracted by the
640 convenience functions are output with C, G, or L after the string number
641 instead of a colon. This is in addition to the normal full list. The string
642 length (that is, the return from the extraction function) is given in
643 parentheses after each string for <b>\C</b> and <b>\G</b>.
644 </P>
645 <P>
646 Note that whereas patterns can be continued over several lines (a plain "&#62;"
647 prompt is used for continuations), data lines may not. However newlines can be
648 included in data by means of the \n escape (or \r, \r\n, etc., depending on
649 the newline sequence setting).
650 </P>
651 <br><a name="SEC8" href="#TOC1">OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION</a><br>
652 <P>
653 When the alternative matching function, <b>pcre_dfa_exec()</b>, is used (by
654 means of the \D escape sequence or the <b>-dfa</b> command line option), the
655 output consists of a list of all the matches that start at the first point in
656 the subject where there is at least one match. For example:
657 <pre>
658 re&#62; /(tang|tangerine|tan)/
659 data&#62; yellow tangerine\D
660 0: tangerine
661 1: tang
662 2: tan
663 </pre>
664 (Using the normal matching function on this data finds only "tang".) The
665 longest matching string is always given first (and numbered zero). After a
666 PCRE_ERROR_PARTIAL return, the output is "Partial match:", followed by the
667 partially matching substring. (Note that this is the entire substring that was
668 inspected during the partial match; it may include characters before the actual
669 match start if a lookbehind assertion, \K, \b, or \B was involved.)
670 </P>
671 <P>
672 If <b>/g</b> is present on the pattern, the search for further matches resumes
673 at the end of the longest match. For example:
674 <pre>
675 re&#62; /(tang|tangerine|tan)/g
676 data&#62; yellow tangerine and tangy sultana\D
677 0: tangerine
678 1: tang
679 2: tan
680 0: tang
681 1: tan
682 0: tan
683 </pre>
684 Since the matching function does not support substring capture, the escape
685 sequences that are concerned with captured substrings are not relevant.
686 </P>
687 <br><a name="SEC9" href="#TOC1">RESTARTING AFTER A PARTIAL MATCH</a><br>
688 <P>
689 When the alternative matching function has given the PCRE_ERROR_PARTIAL return,
690 indicating that the subject partially matched the pattern, you can restart the
691 match with additional subject data by means of the \R escape sequence. For
692 example:
693 <pre>
694 re&#62; /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
695 data&#62; 23ja\P\D
696 Partial match: 23ja
697 data&#62; n05\R\D
698 0: n05
699 </pre>
700 For further information about partial matching, see the
701 <a href="pcrepartial.html"><b>pcrepartial</b></a>
702 documentation.
703 </P>
704 <br><a name="SEC10" href="#TOC1">CALLOUTS</a><br>
705 <P>
706 If the pattern contains any callout requests, <b>pcretest</b>'s callout function
707 is called during matching. This works with both matching functions. By default,
708 the called function displays the callout number, the start and current
709 positions in the text at the callout time, and the next pattern item to be
710 tested. For example, the output
711 <pre>
712 ---&#62;pqrabcdef
713 0 ^ ^ \d
714 </pre>
715 indicates that callout number 0 occurred for a match attempt starting at the
716 fourth character of the subject string, when the pointer was at the seventh
717 character of the data, and when the next pattern item was \d. Just one
718 circumflex is output if the start and current positions are the same.
719 </P>
720 <P>
721 Callouts numbered 255 are assumed to be automatic callouts, inserted as a
722 result of the <b>/C</b> pattern modifier. In this case, instead of showing the
723 callout number, the offset in the pattern, preceded by a plus, is output. For
724 example:
725 <pre>
726 re&#62; /\d?[A-E]\*/C
727 data&#62; E*
728 ---&#62;E*
729 +0 ^ \d?
730 +3 ^ [A-E]
731 +8 ^^ \*
732 +10 ^ ^
733 0: E*
734 </pre>
735 If a pattern contains (*MARK) items, an additional line is output whenever
736 a change of latest mark is passed to the callout function. For example:
737 <pre>
738 re&#62; /a(*MARK:X)bc/C
739 data&#62; abc
740 ---&#62;abc
741 +0 ^ a
742 +1 ^^ (*MARK:X)
743 +10 ^^ b
744 Latest Mark: X
745 +11 ^ ^ c
746 +12 ^ ^
747 0: abc
748 </pre>
749 The mark changes between matching "a" and "b", but stays the same for the rest
750 of the match, so nothing more is output. If, as a result of backtracking, the
751 mark reverts to being unset, the text "&#60;unset&#62;" is output.
752 </P>
753 <P>
754 The callout function in <b>pcretest</b> returns zero (carry on matching) by
755 default, but you can use a \C item in a data line (as described above) to
756 change this and other parameters of the callout.
757 </P>
758 <P>
759 Inserting callouts can be helpful when using <b>pcretest</b> to check
760 complicated regular expressions. For further information about callouts, see
761 the
762 <a href="pcrecallout.html"><b>pcrecallout</b></a>
763 documentation.
764 </P>
765 <br><a name="SEC11" href="#TOC1">NON-PRINTING CHARACTERS</a><br>
766 <P>
767 When <b>pcretest</b> is outputting text in the compiled version of a pattern,
768 bytes other than 32-126 are always treated as non-printing characters are are
769 therefore shown as hex escapes.
770 </P>
771 <P>
772 When <b>pcretest</b> is outputting text that is a matched part of a subject
773 string, it behaves in the same way, unless a different locale has been set for
774 the pattern (using the <b>/L</b> modifier). In this case, the <b>isprint()</b>
775 function to distinguish printing and non-printing characters.
776 </P>
777 <br><a name="SEC12" href="#TOC1">SAVING AND RELOADING COMPILED PATTERNS</a><br>
778 <P>
779 The facilities described in this section are not available when the POSIX
780 interface to PCRE is being used, that is, when the <b>/P</b> pattern modifier is
781 specified.
782 </P>
783 <P>
784 When the POSIX interface is not in use, you can cause <b>pcretest</b> to write a
785 compiled pattern to a file, by following the modifiers with &#62; and a file name.
786 For example:
787 <pre>
788 /pattern/im &#62;/some/file
789 </pre>
790 See the
791 <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
792 documentation for a discussion about saving and re-using compiled patterns.
793 Note that if the pattern was successfully studied with JIT optimization, the
794 JIT data cannot be saved.
795 </P>
796 <P>
797 The data that is written is binary. The first eight bytes are the length of the
798 compiled pattern data followed by the length of the optional study data, each
799 written as four bytes in big-endian order (most significant byte first). If
800 there is no study data (either the pattern was not studied, or studying did not
801 return any data), the second length is zero. The lengths are followed by an
802 exact copy of the compiled pattern. If there is additional study data, this
803 (excluding any JIT data) follows immediately after the compiled pattern. After
804 writing the file, <b>pcretest</b> expects to read a new pattern.
805 </P>
806 <P>
807 A saved pattern can be reloaded into <b>pcretest</b> by specifying &#60; and a file
808 name instead of a pattern. The name of the file must not contain a &#60; character,
809 as otherwise <b>pcretest</b> will interpret the line as a pattern delimited by &#60;
810 characters.
811 For example:
812 <pre>
813 re&#62; &#60;/some/file
814 Compiled pattern loaded from /some/file
815 No study data
816 </pre>
817 If the pattern was previously studied with the JIT optimization, the JIT
818 information cannot be saved and restored, and so is lost. When the pattern has
819 been loaded, <b>pcretest</b> proceeds to read data lines in the usual way.
820 </P>
821 <P>
822 You can copy a file written by <b>pcretest</b> to a different host and reload it
823 there, even if the new host has opposite endianness to the one on which the
824 pattern was compiled. For example, you can compile on an i86 machine and run on
825 a SPARC machine.
826 </P>
827 <P>
828 File names for saving and reloading can be absolute or relative, but note that
829 the shell facility of expanding a file name that starts with a tilde (~) is not
830 available.
831 </P>
832 <P>
833 The ability to save and reload files in <b>pcretest</b> is intended for testing
834 and experimentation. It is not intended for production use because only a
835 single pattern can be written to a file. Furthermore, there is no facility for
836 supplying custom character tables for use with a reloaded pattern. If the
837 original pattern was compiled with custom tables, an attempt to match a subject
838 string using a reloaded pattern is likely to cause <b>pcretest</b> to crash.
839 Finally, if you attempt to load a file that is not in the correct format, the
840 result is undefined.
841 </P>
842 <br><a name="SEC13" href="#TOC1">SEE ALSO</a><br>
843 <P>
844 <b>pcre</b>(3), <b>pcreapi</b>(3), <b>pcrecallout</b>(3), <b>pcrejit</b>,
845 <b>pcrematching</b>(3), <b>pcrepartial</b>(d), <b>pcrepattern</b>(3),
846 <b>pcreprecompile</b>(3).
847 </P>
848 <br><a name="SEC14" href="#TOC1">AUTHOR</a><br>
849 <P>
850 Philip Hazel
851 <br>
852 University Computing Service
853 <br>
854 Cambridge CB2 3QH, England.
855 <br>
856 </P>
857 <br><a name="SEC15" href="#TOC1">REVISION</a><br>
858 <P>
859 Last updated: 26 August 2011
860 <br>
861 Copyright &copy; 1997-2011 University of Cambridge.
862 <br>
863 <p>
864 Return to the <a href="index.html">PCRE index page</a>.
865 </p>

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5