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

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12