ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

Revision 286 - (show annotations)
Mon Dec 17 14:46:11 2007 UTC (12 years, 10 months ago) by ph10
File MIME type: text/html
File size: 29924 byte(s)
Add .gz and .bz2 optional support to pcregrep.
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">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>
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>
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] [source] [destination]</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.
46 </P>
47 <br><a name="SEC2" href="#TOC1">OPTIONS</a><br>
48 <P>
49 <b>-b</b>
50 Behave as if each regex has the <b>/B</b> (show bytecode) modifier; the internal
51 form is output after compilation.
52 </P>
53 <P>
54 <b>-C</b>
55 Output the version number of the PCRE library, and all available information
56 about the optional features that are included, and then exit.
57 </P>
58 <P>
59 <b>-d</b>
60 Behave as if each regex has the <b>/D</b> (debug) modifier; the internal
61 form and information about the compiled pattern is output after compilation;
62 <b>-d</b> is equivalent to <b>-b -i</b>.
63 </P>
64 <P>
65 <b>-dfa</b>
66 Behave as if each data line contains the \D escape sequence; this causes the
67 alternative matching function, <b>pcre_dfa_exec()</b>, to be used instead of the
68 standard <b>pcre_exec()</b> function (more detail is given below).
69 </P>
70 <P>
71 <b>-help</b>
72 Output a brief summary these options and then exit.
73 </P>
74 <P>
75 <b>-i</b>
76 Behave as if each regex has the <b>/I</b> modifier; information about the
77 compiled pattern is given after compilation.
78 </P>
79 <P>
80 <b>-m</b>
81 Output the size of each compiled pattern after it has been compiled. This is
82 equivalent to adding <b>/M</b> to each regular expression. For compatibility
83 with earlier versions of pcretest, <b>-s</b> is a synonym for <b>-m</b>.
84 </P>
85 <P>
86 <b>-o</b> <i>osize</i>
87 Set the number of elements in the output vector that is used when calling
88 <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b> to be <i>osize</i>. The default value
89 is 45, which is enough for 14 capturing subexpressions for <b>pcre_exec()</b> or
90 22 different matches for <b>pcre_dfa_exec()</b>. The vector size can be
91 changed for individual matching calls by including \O in the data line (see
92 below).
93 </P>
94 <P>
95 <b>-p</b>
96 Behave as if each regex has the <b>/P</b> modifier; the POSIX wrapper API is
97 used to call PCRE. None of the other options has any effect when <b>-p</b> is
98 set.
99 </P>
100 <P>
101 <b>-q</b>
102 Do not output the version number of <b>pcretest</b> at the start of execution.
103 </P>
104 <P>
105 <b>-S</b> <i>size</i>
106 On Unix-like systems, set the size of the runtime stack to <i>size</i>
107 megabytes.
108 </P>
109 <P>
110 <b>-t</b>
111 Run each compile, study, and match many times with a timer, and output
112 resulting time per compile or match (in milliseconds). Do not set <b>-m</b> with
113 <b>-t</b>, because you will then get the size output a zillion times, and the
114 timing will be distorted. You can control the number of iterations that are
115 used for timing by following <b>-t</b> with a number (as a separate item on the
116 command line). For example, "-t 1000" would iterate 1000 times. The default is
117 to iterate 500000 times.
118 </P>
119 <P>
120 <b>-tm</b>
121 This is like <b>-t</b> except that it times only the matching phase, not the
122 compile or study phases.
123 </P>
124 <br><a name="SEC3" href="#TOC1">DESCRIPTION</a><br>
125 <P>
126 If <b>pcretest</b> is given two filename arguments, it reads from the first and
127 writes to the second. If it is given only one filename argument, it reads from
128 that file and writes to stdout. Otherwise, it reads from stdin and writes to
129 stdout, and prompts for each line of input, using "re&#62;" to prompt for regular
130 expressions, and "data&#62;" to prompt for data lines.
131 </P>
132 <P>
133 The program handles any number of sets of input on a single input file. Each
134 set starts with a regular expression, and continues with any number of data
135 lines to be matched against the pattern.
136 </P>
137 <P>
138 Each data line is matched separately and independently. If you want to do
139 multi-line matches, you have to use the \n escape sequence (or \r or \r\n,
140 etc., depending on the newline setting) in a single line of input to encode the
141 newline sequences. There is no limit on the length of data lines; the input
142 buffer is automatically extended if it is too small.
143 </P>
144 <P>
145 An empty line signals the end of the data lines, at which point a new regular
146 expression is read. The regular expressions are given enclosed in any
147 non-alphanumeric delimiters other than backslash, for example:
148 <pre>
149 /(a|bc)x+yz/
150 </pre>
151 White space before the initial delimiter is ignored. A regular expression may
152 be continued over several input lines, in which case the newline characters are
153 included within it. It is possible to include the delimiter within the pattern
154 by escaping it, for example
155 <pre>
156 /abc\/def/
157 </pre>
158 If you do so, the escape and the delimiter form part of the pattern, but since
159 delimiters are always non-alphanumeric, this does not affect its interpretation.
160 If the terminating delimiter is immediately followed by a backslash, for
161 example,
162 <pre>
163 /abc/\
164 </pre>
165 then a backslash is added to the end of the pattern. This is done to provide a
166 way of testing the error condition that arises if a pattern finishes with a
167 backslash, because
168 <pre>
169 /abc\/
170 </pre>
171 is interpreted as the first line of a pattern that starts with "abc/", causing
172 pcretest to read the next line as a continuation of the regular expression.
173 </P>
174 <br><a name="SEC4" href="#TOC1">PATTERN MODIFIERS</a><br>
175 <P>
176 A pattern may be followed by any number of modifiers, which are mostly single
177 characters. Following Perl usage, these are referred to below as, for example,
178 "the <b>/i</b> modifier", even though the delimiter of the pattern need not
179 always be a slash, and no slash is used when writing modifiers. Whitespace may
180 appear between the final pattern delimiter and the first modifier, and between
181 the modifiers themselves.
182 </P>
183 <P>
184 The <b>/i</b>, <b>/m</b>, <b>/s</b>, and <b>/x</b> modifiers set the PCRE_CASELESS,
185 PCRE_MULTILINE, PCRE_DOTALL, or PCRE_EXTENDED options, respectively, when
186 <b>pcre_compile()</b> is called. These four modifier letters have the same
187 effect as they do in Perl. For example:
188 <pre>
189 /caseless/i
190 </pre>
191 The following table shows additional modifiers for setting PCRE options that do
192 not correspond to anything in Perl:
193 <pre>
194 <b>/A</b> PCRE_ANCHORED
197 <b>/f</b> PCRE_FIRSTLINE
198 <b>/J</b> PCRE_DUPNAMES
200 <b>/U</b> PCRE_UNGREEDY
201 <b>/X</b> PCRE_EXTRA
202 <b>/&#60;cr&#62;</b> PCRE_NEWLINE_CR
203 <b>/&#60;lf&#62;</b> PCRE_NEWLINE_LF
204 <b>/&#60;crlf&#62;</b> PCRE_NEWLINE_CRLF
205 <b>/&#60;anycrlf&#62;</b> PCRE_NEWLINE_ANYCRLF
206 <b>/&#60;any&#62;</b> PCRE_NEWLINE_ANY
207 <b>/&#60;bsr_anycrlf&#62;</b> PCRE_BSR_ANYCRLF
208 <b>/&#60;bsr_unicode&#62;</b> PCRE_BSR_UNICODE
209 </pre>
210 Those specifying line ending sequences are literal strings as shown, but the
211 letters can be in either case. This example sets multiline matching with CRLF
212 as the line ending sequence:
213 <pre>
214 /^abc/m&#60;crlf&#62;
215 </pre>
216 Details of the meanings of these PCRE options are given in the
217 <a href="pcreapi.html"><b>pcreapi</b></a>
218 documentation.
219 </P>
220 <br><b>
221 Finding all matches in a string
222 </b><br>
223 <P>
224 Searching for all possible matches within each subject string can be requested
225 by the <b>/g</b> or <b>/G</b> modifier. After finding a match, PCRE is called
226 again to search the remainder of the subject string. The difference between
227 <b>/g</b> and <b>/G</b> is that the former uses the <i>startoffset</i> argument to
228 <b>pcre_exec()</b> to start searching at a new point within the entire string
229 (which is in effect what Perl does), whereas the latter passes over a shortened
230 substring. This makes a difference to the matching process if the pattern
231 begins with a lookbehind assertion (including \b or \B).
232 </P>
233 <P>
234 If any call to <b>pcre_exec()</b> in a <b>/g</b> or <b>/G</b> sequence matches an
235 empty string, the next call is done with the PCRE_NOTEMPTY and PCRE_ANCHORED
236 flags set in order to search for another, non-empty, match at the same point.
237 If this second match fails, the start offset is advanced by one, and the normal
238 match is retried. This imitates the way Perl handles such cases when using the
239 <b>/g</b> modifier or the <b>split()</b> function.
240 </P>
241 <br><b>
242 Other modifiers
243 </b><br>
244 <P>
245 There are yet more modifiers for controlling the way <b>pcretest</b>
246 operates.
247 </P>
248 <P>
249 The <b>/+</b> modifier requests that as well as outputting the substring that
250 matched the entire pattern, pcretest should in addition output the remainder of
251 the subject string. This is useful for tests where the subject contains
252 multiple copies of the same substring.
253 </P>
254 <P>
255 The <b>/B</b> modifier is a debugging feature. It requests that <b>pcretest</b>
256 output a representation of the compiled byte code after compilation. Normally
257 this information contains length and offset values; however, if <b>/Z</b> is
258 also present, this data is replaced by spaces. This is a special feature for
259 use in the automatic test scripts; it ensures that the same output is generated
260 for different internal link sizes.
261 </P>
262 <P>
263 The <b>/L</b> modifier must be followed directly by the name of a locale, for
264 example,
265 <pre>
266 /pattern/Lfr_FR
267 </pre>
268 For this reason, it must be the last modifier. The given locale is set,
269 <b>pcre_maketables()</b> is called to build a set of character tables for the
270 locale, and this is then passed to <b>pcre_compile()</b> when compiling the
271 regular expression. Without an <b>/L</b> modifier, NULL is passed as the tables
272 pointer; that is, <b>/L</b> applies only to the expression on which it appears.
273 </P>
274 <P>
275 The <b>/I</b> modifier requests that <b>pcretest</b> output information about the
276 compiled pattern (whether it is anchored, has a fixed first character, and
277 so on). It does this by calling <b>pcre_fullinfo()</b> after compiling a
278 pattern. If the pattern is studied, the results of that are also output.
279 </P>
280 <P>
281 The <b>/D</b> modifier is a PCRE debugging feature, and is equivalent to
282 <b>/BI</b>, that is, both the <b>/B</b> and the <b>/I</b> modifiers.
283 </P>
284 <P>
285 The <b>/F</b> modifier causes <b>pcretest</b> to flip the byte order of the
286 fields in the compiled pattern that contain 2-byte and 4-byte numbers. This
287 facility is for testing the feature in PCRE that allows it to execute patterns
288 that were compiled on a host with a different endianness. This feature is not
289 available when the POSIX interface to PCRE is being used, that is, when the
290 <b>/P</b> pattern modifier is specified. See also the section about saving and
291 reloading compiled patterns below.
292 </P>
293 <P>
294 The <b>/S</b> modifier causes <b>pcre_study()</b> to be called after the
295 expression has been compiled, and the results used when the expression is
296 matched.
297 </P>
298 <P>
299 The <b>/M</b> modifier causes the size of memory block used to hold the compiled
300 pattern to be output.
301 </P>
302 <P>
303 The <b>/P</b> modifier causes <b>pcretest</b> to call PCRE via the POSIX wrapper
304 API rather than its native API. When this is done, all other modifiers except
305 <b>/i</b>, <b>/m</b>, and <b>/+</b> are ignored. REG_ICASE is set if <b>/i</b> is
306 present, and REG_NEWLINE is set if <b>/m</b> is present. The wrapper functions
307 force PCRE_DOLLAR_ENDONLY always, and PCRE_DOTALL unless REG_NEWLINE is set.
308 </P>
309 <P>
310 The <b>/8</b> modifier causes <b>pcretest</b> to call PCRE with the PCRE_UTF8
311 option set. This turns on support for UTF-8 character handling in PCRE,
312 provided that it was compiled with this support enabled. This modifier also
313 causes any non-printing characters in output strings to be printed using the
314 \x{hh...} notation if they are valid UTF-8 sequences.
315 </P>
316 <P>
317 If the <b>/?</b> modifier is used with <b>/8</b>, it causes <b>pcretest</b> to
318 call <b>pcre_compile()</b> with the PCRE_NO_UTF8_CHECK option, to suppress the
319 checking of the string for UTF-8 validity.
320 </P>
321 <br><a name="SEC5" href="#TOC1">DATA LINES</a><br>
322 <P>
323 Before each data line is passed to <b>pcre_exec()</b>, leading and trailing
324 whitespace is removed, and it is then scanned for \ escapes. Some of these are
325 pretty esoteric features, intended for checking out some of the more
326 complicated features of PCRE. If you are just testing "ordinary" regular
327 expressions, you probably don't need any of these. The following escapes are
328 recognized:
329 <pre>
330 \a alarm (BEL, \x07)
331 \b backspace (\x08)
332 \e escape (\x27)
333 \f formfeed (\x0c)
334 \n newline (\x0a)
335 \qdd set the PCRE_MATCH_LIMIT limit to dd (any number of digits)
336 \r carriage return (\x0d)
337 \t tab (\x09)
338 \v vertical tab (\x0b)
339 \nnn octal character (up to 3 octal digits)
340 \xhh hexadecimal character (up to 2 hex digits)
341 \x{hh...} hexadecimal character, any number of digits in UTF-8 mode
342 \A pass the PCRE_ANCHORED option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
343 \B pass the PCRE_NOTBOL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
344 \Cdd call pcre_copy_substring() for substring dd after a successful match (number less than 32)
345 \Cname call pcre_copy_named_substring() for substring "name" after a successful match (name termin-
346 ated by next non alphanumeric character)
347 \C+ show the current captured substrings at callout time
348 \C- do not supply a callout function
349 \C!n return 1 instead of 0 when callout number n is reached
350 \C!n!m return 1 instead of 0 when callout number n is reached for the nth time
351 \C*n pass the number n (may be negative) as callout data; this is used as the callout return value
352 \D use the <b>pcre_dfa_exec()</b> match function
353 \F only shortest match for <b>pcre_dfa_exec()</b>
354 \Gdd call pcre_get_substring() for substring dd after a successful match (number less than 32)
355 \Gname call pcre_get_named_substring() for substring "name" after a successful match (name termin-
356 ated by next non-alphanumeric character)
357 \L call pcre_get_substringlist() after a successful match
358 \M discover the minimum MATCH_LIMIT and MATCH_LIMIT_RECURSION settings
359 \N pass the PCRE_NOTEMPTY option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
360 \Odd set the size of the output vector passed to <b>pcre_exec()</b> to dd (any number of digits)
361 \P pass the PCRE_PARTIAL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
362 \Qdd set the PCRE_MATCH_LIMIT_RECURSION limit to dd (any number of digits)
363 \R pass the PCRE_DFA_RESTART option to <b>pcre_dfa_exec()</b>
364 \S output details of memory get/free calls during matching
365 \Z pass the PCRE_NOTEOL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
366 \? pass the PCRE_NO_UTF8_CHECK option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
367 \&#62;dd start the match at offset dd (any number of digits);
368 this sets the <i>startoffset</i> argument for <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
369 \&#60;cr&#62; pass the PCRE_NEWLINE_CR option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
370 \&#60;lf&#62; pass the PCRE_NEWLINE_LF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
371 \&#60;crlf&#62; pass the PCRE_NEWLINE_CRLF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
372 \&#60;anycrlf&#62; pass the PCRE_NEWLINE_ANYCRLF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
373 \&#60;any&#62; pass the PCRE_NEWLINE_ANY option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
374 </pre>
375 The escapes that specify line ending sequences are literal strings, exactly as
376 shown. No more than one newline setting should be present in any data line.
377 </P>
378 <P>
379 A backslash followed by anything else just escapes the anything else. If
380 the very last character is a backslash, it is ignored. This gives a way of
381 passing an empty line as data, since a real empty line terminates the data
382 input.
383 </P>
384 <P>
385 If \M is present, <b>pcretest</b> calls <b>pcre_exec()</b> several times, with
386 different values in the <i>match_limit</i> and <i>match_limit_recursion</i>
387 fields of the <b>pcre_extra</b> data structure, until it finds the minimum
388 numbers for each parameter that allow <b>pcre_exec()</b> to complete. The
389 <i>match_limit</i> number is a measure of the amount of backtracking that takes
390 place, and checking it out can be instructive. For most simple matches, the
391 number is quite small, but for patterns with very large numbers of matching
392 possibilities, it can become large very quickly with increasing length of
393 subject string. The <i>match_limit_recursion</i> number is a measure of how much
394 stack (or, if PCRE is compiled with NO_RECURSE, how much heap) memory is needed
395 to complete the match attempt.
396 </P>
397 <P>
398 When \O is used, the value specified may be higher or lower than the size set
399 by the <b>-O</b> command line option (or defaulted to 45); \O applies only to
400 the call of <b>pcre_exec()</b> for the line in which it appears.
401 </P>
402 <P>
403 If the <b>/P</b> modifier was present on the pattern, causing the POSIX wrapper
404 API to be used, the only option-setting sequences that have any effect are \B
405 and \Z, causing REG_NOTBOL and REG_NOTEOL, respectively, to be passed to
406 <b>regexec()</b>.
407 </P>
408 <P>
409 The use of \x{hh...} to represent UTF-8 characters is not dependent on the use
410 of the <b>/8</b> modifier on the pattern. It is recognized always. There may be
411 any number of hexadecimal digits inside the braces. The result is from one to
412 six bytes, encoded according to the original UTF-8 rules of RFC 2279. This
413 allows for values in the range 0 to 0x7FFFFFFF. Note that not all of those are
414 valid Unicode code points, or indeed valid UTF-8 characters according to the
415 later rules in RFC 3629.
416 </P>
417 <br><a name="SEC6" href="#TOC1">THE ALTERNATIVE MATCHING FUNCTION</a><br>
418 <P>
419 By default, <b>pcretest</b> uses the standard PCRE matching function,
420 <b>pcre_exec()</b> to match each data line. From release 6.0, PCRE supports an
421 alternative matching function, <b>pcre_dfa_test()</b>, which operates in a
422 different way, and has some restrictions. The differences between the two
423 functions are described in the
424 <a href="pcrematching.html"><b>pcrematching</b></a>
425 documentation.
426 </P>
427 <P>
428 If a data line contains the \D escape sequence, or if the command line
429 contains the <b>-dfa</b> option, the alternative matching function is called.
430 This function finds all possible matches at a given point. If, however, the \F
431 escape sequence is present in the data line, it stops after the first match is
432 found. This is always the shortest possible match.
433 </P>
434 <br><a name="SEC7" href="#TOC1">DEFAULT OUTPUT FROM PCRETEST</a><br>
435 <P>
436 This section describes the output when the normal matching function,
437 <b>pcre_exec()</b>, is being used.
438 </P>
439 <P>
440 When a match succeeds, pcretest outputs the list of captured substrings that
441 <b>pcre_exec()</b> returns, starting with number 0 for the string that matched
442 the whole pattern. Otherwise, it outputs "No match" or "Partial match"
443 when <b>pcre_exec()</b> returns PCRE_ERROR_NOMATCH or PCRE_ERROR_PARTIAL,
444 respectively, and otherwise the PCRE negative error number. Here is an example
445 of an interactive <b>pcretest</b> run.
446 <pre>
447 $ pcretest
448 PCRE version 7.0 30-Nov-2006
450 re&#62; /^abc(\d+)/
451 data&#62; abc123
452 0: abc123
453 1: 123
454 data&#62; xyz
455 No match
456 </pre>
457 Note that unset capturing substrings that are not followed by one that is set
458 are not returned by <b>pcre_exec()</b>, and are not shown by <b>pcretest</b>. In
459 the following example, there are two capturing substrings, but when the first
460 data line is matched, the second, unset substring is not shown. An "internal"
461 unset substring is shown as "&#60;unset&#62;", as for the second data line.
462 <pre>
463 re&#62; /(a)|(b)/
464 data&#62; a
465 0: a
466 1: a
467 data&#62; b
468 0: b
469 1: &#60;unset&#62;
470 2: b
471 </pre>
472 If the strings contain any non-printing characters, they are output as \0x
473 escapes, or as \x{...} escapes if the <b>/8</b> modifier was present on the
474 pattern. See below for the definition of non-printing characters. If the
475 pattern has the <b>/+</b> modifier, the output for substring 0 is followed by
476 the the rest of the subject string, identified by "0+" like this:
477 <pre>
478 re&#62; /cat/+
479 data&#62; cataract
480 0: cat
481 0+ aract
482 </pre>
483 If the pattern has the <b>/g</b> or <b>/G</b> modifier, the results of successive
484 matching attempts are output in sequence, like this:
485 <pre>
486 re&#62; /\Bi(\w\w)/g
487 data&#62; Mississippi
488 0: iss
489 1: ss
490 0: iss
491 1: ss
492 0: ipp
493 1: pp
494 </pre>
495 "No match" is output only if the first match attempt fails.
496 </P>
497 <P>
498 If any of the sequences <b>\C</b>, <b>\G</b>, or <b>\L</b> are present in a
499 data line that is successfully matched, the substrings extracted by the
500 convenience functions are output with C, G, or L after the string number
501 instead of a colon. This is in addition to the normal full list. The string
502 length (that is, the return from the extraction function) is given in
503 parentheses after each string for <b>\C</b> and <b>\G</b>.
504 </P>
505 <P>
506 Note that whereas patterns can be continued over several lines (a plain "&#62;"
507 prompt is used for continuations), data lines may not. However newlines can be
508 included in data by means of the \n escape (or \r, \r\n, etc., depending on
509 the newline sequence setting).
510 </P>
512 <P>
513 When the alternative matching function, <b>pcre_dfa_exec()</b>, is used (by
514 means of the \D escape sequence or the <b>-dfa</b> command line option), the
515 output consists of a list of all the matches that start at the first point in
516 the subject where there is at least one match. For example:
517 <pre>
518 re&#62; /(tang|tangerine|tan)/
519 data&#62; yellow tangerine\D
520 0: tangerine
521 1: tang
522 2: tan
523 </pre>
524 (Using the normal matching function on this data finds only "tang".) The
525 longest matching string is always given first (and numbered zero).
526 </P>
527 <P>
528 If <b>/g</b> is present on the pattern, the search for further matches resumes
529 at the end of the longest match. For example:
530 <pre>
531 re&#62; /(tang|tangerine|tan)/g
532 data&#62; yellow tangerine and tangy sultana\D
533 0: tangerine
534 1: tang
535 2: tan
536 0: tang
537 1: tan
538 0: tan
539 </pre>
540 Since the matching function does not support substring capture, the escape
541 sequences that are concerned with captured substrings are not relevant.
542 </P>
543 <br><a name="SEC9" href="#TOC1">RESTARTING AFTER A PARTIAL MATCH</a><br>
544 <P>
545 When the alternative matching function has given the PCRE_ERROR_PARTIAL return,
546 indicating that the subject partially matched the pattern, you can restart the
547 match with additional subject data by means of the \R escape sequence. For
548 example:
549 <pre>
550 re&#62; /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
551 data&#62; 23ja\P\D
552 Partial match: 23ja
553 data&#62; n05\R\D
554 0: n05
555 </pre>
556 For further information about partial matching, see the
557 <a href="pcrepartial.html"><b>pcrepartial</b></a>
558 documentation.
559 </P>
560 <br><a name="SEC10" href="#TOC1">CALLOUTS</a><br>
561 <P>
562 If the pattern contains any callout requests, <b>pcretest</b>'s callout function
563 is called during matching. This works with both matching functions. By default,
564 the called function displays the callout number, the start and current
565 positions in the text at the callout time, and the next pattern item to be
566 tested. For example, the output
567 <pre>
568 ---&#62;pqrabcdef
569 0 ^ ^ \d
570 </pre>
571 indicates that callout number 0 occurred for a match attempt starting at the
572 fourth character of the subject string, when the pointer was at the seventh
573 character of the data, and when the next pattern item was \d. Just one
574 circumflex is output if the start and current positions are the same.
575 </P>
576 <P>
577 Callouts numbered 255 are assumed to be automatic callouts, inserted as a
578 result of the <b>/C</b> pattern modifier. In this case, instead of showing the
579 callout number, the offset in the pattern, preceded by a plus, is output. For
580 example:
581 <pre>
582 re&#62; /\d?[A-E]\*/C
583 data&#62; E*
584 ---&#62;E*
585 +0 ^ \d?
586 +3 ^ [A-E]
587 +8 ^^ \*
588 +10 ^ ^
589 0: E*
590 </pre>
591 The callout function in <b>pcretest</b> returns zero (carry on matching) by
592 default, but you can use a \C item in a data line (as described above) to
593 change this.
594 </P>
595 <P>
596 Inserting callouts can be helpful when using <b>pcretest</b> to check
597 complicated regular expressions. For further information about callouts, see
598 the
599 <a href="pcrecallout.html"><b>pcrecallout</b></a>
600 documentation.
601 </P>
602 <br><a name="SEC11" href="#TOC1">NON-PRINTING CHARACTERS</a><br>
603 <P>
604 When <b>pcretest</b> is outputting text in the compiled version of a pattern,
605 bytes other than 32-126 are always treated as non-printing characters are are
606 therefore shown as hex escapes.
607 </P>
608 <P>
609 When <b>pcretest</b> is outputting text that is a matched part of a subject
610 string, it behaves in the same way, unless a different locale has been set for
611 the pattern (using the <b>/L</b> modifier). In this case, the <b>isprint()</b>
612 function to distinguish printing and non-printing characters.
613 </P>
614 <br><a name="SEC12" href="#TOC1">SAVING AND RELOADING COMPILED PATTERNS</a><br>
615 <P>
616 The facilities described in this section are not available when the POSIX
617 inteface to PCRE is being used, that is, when the <b>/P</b> pattern modifier is
618 specified.
619 </P>
620 <P>
621 When the POSIX interface is not in use, you can cause <b>pcretest</b> to write a
622 compiled pattern to a file, by following the modifiers with &#62; and a file name.
623 For example:
624 <pre>
625 /pattern/im &#62;/some/file
626 </pre>
627 See the
628 <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
629 documentation for a discussion about saving and re-using compiled patterns.
630 </P>
631 <P>
632 The data that is written is binary. The first eight bytes are the length of the
633 compiled pattern data followed by the length of the optional study data, each
634 written as four bytes in big-endian order (most significant byte first). If
635 there is no study data (either the pattern was not studied, or studying did not
636 return any data), the second length is zero. The lengths are followed by an
637 exact copy of the compiled pattern. If there is additional study data, this
638 follows immediately after the compiled pattern. After writing the file,
639 <b>pcretest</b> expects to read a new pattern.
640 </P>
641 <P>
642 A saved pattern can be reloaded into <b>pcretest</b> by specifing &#60; and a file
643 name instead of a pattern. The name of the file must not contain a &#60; character,
644 as otherwise <b>pcretest</b> will interpret the line as a pattern delimited by &#60;
645 characters.
646 For example:
647 <pre>
648 re&#62; &#60;/some/file
649 Compiled regex loaded from /some/file
650 No study data
651 </pre>
652 When the pattern has been loaded, <b>pcretest</b> proceeds to read data lines in
653 the usual way.
654 </P>
655 <P>
656 You can copy a file written by <b>pcretest</b> to a different host and reload it
657 there, even if the new host has opposite endianness to the one on which the
658 pattern was compiled. For example, you can compile on an i86 machine and run on
659 a SPARC machine.
660 </P>
661 <P>
662 File names for saving and reloading can be absolute or relative, but note that
663 the shell facility of expanding a file name that starts with a tilde (~) is not
664 available.
665 </P>
666 <P>
667 The ability to save and reload files in <b>pcretest</b> is intended for testing
668 and experimentation. It is not intended for production use because only a
669 single pattern can be written to a file. Furthermore, there is no facility for
670 supplying custom character tables for use with a reloaded pattern. If the
671 original pattern was compiled with custom tables, an attempt to match a subject
672 string using a reloaded pattern is likely to cause <b>pcretest</b> to crash.
673 Finally, if you attempt to load a file that is not in the correct format, the
674 result is undefined.
675 </P>
676 <br><a name="SEC13" href="#TOC1">SEE ALSO</a><br>
677 <P>
678 <b>pcre</b>(3), <b>pcreapi</b>(3), <b>pcrecallout</b>(3), <b>pcrematching</b>(3),
679 <b>pcrepartial</b>(d), <b>pcrepattern</b>(3), <b>pcreprecompile</b>(3).
680 </P>
681 <br><a name="SEC14" href="#TOC1">AUTHOR</a><br>
682 <P>
683 Philip Hazel
684 <br>
685 University Computing Service
686 <br>
687 Cambridge CB2 3QH, England.
688 <br>
689 </P>
690 <br><a name="SEC15" href="#TOC1">REVISION</a><br>
691 <P>
692 Last updated: 19 November 2007
693 <br>
694 Copyright &copy; 1997-2007 University of Cambridge.
695 <br>
696 <p>
697 Return to the <a href="index.html">PCRE index page</a>.
698 </p>


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

  ViewVC Help
Powered by ViewVC 1.1.5