ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

Revision 96 - (hide annotations) (download) (as text)
Fri Mar 2 13:10:43 2007 UTC (8 years, 1 month ago) by nigel
File MIME type: text/html
File size: 28441 byte(s)
 r6896@hex:  nm | 2007-03-02 13:09:14 +0000
 Added EOL and keywork properties throughout

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


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

ViewVC Help
Powered by ViewVC 1.1.12