ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

Revision 654 - (hide annotations) (download) (as text)
Tue Aug 2 11:00:40 2011 UTC (3 years, 8 months ago) by ph10
File MIME type: text/html
File size: 36851 byte(s)
Documentation and general text tidies in preparation for test release.

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


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

ViewVC Help
Powered by ViewVC 1.1.12