/[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 91 - (hide annotations) (download) (as text)
Sat Feb 24 21:41:34 2007 UTC (7 years, 4 months ago) by nigel
File MIME type: text/html
File size: 26252 byte(s)
Load pcre-6.7 into code/trunk.

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

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12