/[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 512 - (hide annotations) (download) (as text)
Tue Mar 30 11:11:52 2010 UTC (3 years, 2 months ago) by ph10
File MIME type: text/html
File size: 31710 byte(s)
Fix compile problems when heap is in use

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

Properties

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

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12