ViewVC logotype

Contents of /code/tags/pcre-6.4/doc/html/pcretest.html

Parent Directory Parent Directory | Revision Log Revision Log

Revision 73 - (hide annotations) (download) (as text)
Sat Feb 24 21:40:30 2007 UTC (8 years, 2 months ago) by nigel
Original Path: code/trunk/doc/html/pcretest.html
File MIME type: text/html
File size: 16742 byte(s)
Load pcre-4.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     This HTML document has been generated automatically from the original man page.
7     If there is any nonsense in it, please consult the man page, in case the
8     conversion went wrong.<br>
9     <ul>
10     <li><a name="TOC1" href="#SEC1">SYNOPSIS</a>
11     <li><a name="TOC2" href="#SEC2">OPTIONS</a>
12     <li><a name="TOC3" href="#SEC3">DESCRIPTION</a>
13     <li><a name="TOC4" href="#SEC4">PATTERN MODIFIERS</a>
14     <li><a name="TOC5" href="#SEC5">CALLOUTS</a>
15     <li><a name="TOC6" href="#SEC6">DATA LINES</a>
16     <li><a name="TOC7" href="#SEC7">OUTPUT FROM PCRETEST</a>
17     <li><a name="TOC8" href="#SEC8">AUTHOR</a>
18     </ul>
19     <br><a name="SEC1" href="#TOC1">SYNOPSIS</a><br>
20     <P>
21     <b>pcretest [-d] [-i] [-m] [-o osize] [-p] [-t] [source] [destination]</b>
22     </P>
23     <P>
24     <b>pcretest</b> was written as a test program for the PCRE regular expression
25     library itself, but it can also be used for experimenting with regular
26     expressions. This document describes the features of the test program; for
27     details of the regular expressions themselves, see the
28     <a href="pcrepattern.html"><b>pcrepattern</b></a>
29     documentation. For details of PCRE and its options, see the
30     <a href="pcreapi.html"><b>pcreapi</b></a>
31     documentation.
32     </P>
33     <br><a name="SEC2" href="#TOC1">OPTIONS</a><br>
34     <P>
35     <b>-C</b>
36     Output the version number of the PCRE library, and all available information
37     about the optional features that are included, and then exit.
38     </P>
39     <P>
40     <b>-d</b>
41     Behave as if each regex had the <b>/D</b> modifier (see below); the internal
42     form is output after compilation.
43     </P>
44     <P>
45     <b>-i</b>
46     Behave as if each regex had the <b>/I</b> modifier; information about the
47     compiled pattern is given after compilation.
48     </P>
49     <P>
50     <b>-m</b>
51     Output the size of each compiled pattern after it has been compiled. This is
52     equivalent to adding /M to each regular expression. For compatibility with
53     earlier versions of pcretest, <b>-s</b> is a synonym for <b>-m</b>.
54     </P>
55     <P>
56     <b>-o</b> <i>osize</i>
57     Set the number of elements in the output vector that is used when calling PCRE
58     to be <i>osize</i>. The default value is 45, which is enough for 14 capturing
59     subexpressions. The vector size can be changed for individual matching calls by
60     including \O in the data line (see below).
61     </P>
62     <P>
63     <b>-p</b>
64     Behave as if each regex has <b>/P</b> modifier; the POSIX wrapper API is used
65     to call PCRE. None of the other options has any effect when <b>-p</b> is set.
66     </P>
67     <P>
68     <b>-t</b>
69     Run each compile, study, and match many times with a timer, and output
70     resulting time per compile or match (in milliseconds). Do not set <b>-t</b> with
71     <b>-m</b>, because you will then get the size output 20000 times and the timing
72     will be distorted.
73     </P>
74     <br><a name="SEC3" href="#TOC1">DESCRIPTION</a><br>
75     <P>
76     If <b>pcretest</b> is given two filename arguments, it reads from the first and
77     writes to the second. If it is given only one filename argument, it reads from
78     that file and writes to stdout. Otherwise, it reads from stdin and writes to
79     stdout, and prompts for each line of input, using "re&#62;" to prompt for regular
80     expressions, and "data&#62;" to prompt for data lines.
81     </P>
82     <P>
83     The program handles any number of sets of input on a single input file. Each
84     set starts with a regular expression, and continues with any number of data
85     lines to be matched against the pattern.
86     </P>
87     <P>
88     Each line is matched separately and independently. If you want to do
89     multiple-line matches, you have to use the \n escape sequence in a single line
90     of input to encode the newline characters. The maximum length of data line is
91     30,000 characters.
92     </P>
93     <P>
94     An empty line signals the end of the data lines, at which point a new regular
95     expression is read. The regular expressions are given enclosed in any
96     non-alphameric delimiters other than backslash, for example
97     </P>
98     <P>
99     <pre>
100     /(a|bc)x+yz/
101     </PRE>
102     </P>
103     <P>
104     White space before the initial delimiter is ignored. A regular expression may
105     be continued over several input lines, in which case the newline characters are
106     included within it. It is possible to include the delimiter within the pattern
107     by escaping it, for example
108     </P>
109     <P>
110     <pre>
111     /abc\/def/
112     </PRE>
113     </P>
114     <P>
115     If you do so, the escape and the delimiter form part of the pattern, but since
116     delimiters are always non-alphameric, this does not affect its interpretation.
117     If the terminating delimiter is immediately followed by a backslash, for
118     example,
119     </P>
120     <P>
121     <pre>
122     /abc/\
123     </PRE>
124     </P>
125     <P>
126     then a backslash is added to the end of the pattern. This is done to provide a
127     way of testing the error condition that arises if a pattern finishes with a
128     backslash, because
129     </P>
130     <P>
131     <pre>
132     /abc\/
133     </PRE>
134     </P>
135     <P>
136     is interpreted as the first line of a pattern that starts with "abc/", causing
137     pcretest to read the next line as a continuation of the regular expression.
138     </P>
139     <br><a name="SEC4" href="#TOC1">PATTERN MODIFIERS</a><br>
140     <P>
141     The pattern may be followed by <b>i</b>, <b>m</b>, <b>s</b>, or <b>x</b> to set the
143     respectively. For example:
144     </P>
145     <P>
146     <pre>
147     /caseless/i
148     </PRE>
149     </P>
150     <P>
151     These modifier letters have the same effect as they do in Perl. There are
152 nigel 71 others that set PCRE options that do not correspond to anything in Perl:
153     <b>/A</b>, <b>/E</b>, <b>/N</b>, <b>/U</b>, and <b>/X</b> set PCRE_ANCHORED,
155     respectively.
156 nigel 63 </P>
157     <P>
158     Searching for all possible matches within each subject string can be requested
159     by the <b>/g</b> or <b>/G</b> modifier. After finding a match, PCRE is called
160     again to search the remainder of the subject string. The difference between
161     <b>/g</b> and <b>/G</b> is that the former uses the <i>startoffset</i> argument to
162     <b>pcre_exec()</b> to start searching at a new point within the entire string
163     (which is in effect what Perl does), whereas the latter passes over a shortened
164     substring. This makes a difference to the matching process if the pattern
165     begins with a lookbehind assertion (including \b or \B).
166     </P>
167     <P>
168     If any call to <b>pcre_exec()</b> in a <b>/g</b> or <b>/G</b> sequence matches an
169     empty string, the next call is done with the PCRE_NOTEMPTY and PCRE_ANCHORED
170     flags set in order to search for another, non-empty, match at the same point.
171     If this second match fails, the start offset is advanced by one, and the normal
172     match is retried. This imitates the way Perl handles such cases when using the
173     <b>/g</b> modifier or the <b>split()</b> function.
174     </P>
175     <P>
176     There are a number of other modifiers for controlling the way <b>pcretest</b>
177     operates.
178     </P>
179     <P>
180     The <b>/+</b> modifier requests that as well as outputting the substring that
181     matched the entire pattern, pcretest should in addition output the remainder of
182     the subject string. This is useful for tests where the subject contains
183     multiple copies of the same substring.
184     </P>
185     <P>
186     The <b>/L</b> modifier must be followed directly by the name of a locale, for
187     example,
188     </P>
189     <P>
190     <pre>
191     /pattern/Lfr
192     </PRE>
193     </P>
194     <P>
195     For this reason, it must be the last modifier letter. The given locale is set,
196     <b>pcre_maketables()</b> is called to build a set of character tables for the
197     locale, and this is then passed to <b>pcre_compile()</b> when compiling the
198     regular expression. Without an <b>/L</b> modifier, NULL is passed as the tables
199     pointer; that is, <b>/L</b> applies only to the expression on which it appears.
200     </P>
201     <P>
202     The <b>/I</b> modifier requests that <b>pcretest</b> output information about the
203     compiled expression (whether it is anchored, has a fixed first character, and
204     so on). It does this by calling <b>pcre_fullinfo()</b> after compiling an
205     expression, and outputting the information it gets back. If the pattern is
206     studied, the results of that are also output.
207     </P>
208     <P>
209     The <b>/D</b> modifier is a PCRE debugging feature, which also assumes <b>/I</b>.
210     It causes the internal form of compiled regular expressions to be output after
211     compilation. If the pattern was studied, the information returned is also
212     output.
213     </P>
214     <P>
215     The <b>/S</b> modifier causes <b>pcre_study()</b> to be called after the
216     expression has been compiled, and the results used when the expression is
217     matched.
218     </P>
219     <P>
220     The <b>/M</b> modifier causes the size of memory block used to hold the compiled
221     pattern to be output.
222     </P>
223     <P>
224     The <b>/P</b> modifier causes <b>pcretest</b> to call PCRE via the POSIX wrapper
225     API rather than its native API. When this is done, all other modifiers except
226     <b>/i</b>, <b>/m</b>, and <b>/+</b> are ignored. REG_ICASE is set if <b>/i</b> is
227     present, and REG_NEWLINE is set if <b>/m</b> is present. The wrapper functions
228     force PCRE_DOLLAR_ENDONLY always, and PCRE_DOTALL unless REG_NEWLINE is set.
229     </P>
230     <P>
231     The <b>/8</b> modifier causes <b>pcretest</b> to call PCRE with the PCRE_UTF8
232     option set. This turns on support for UTF-8 character handling in PCRE,
233     provided that it was compiled with this support enabled. This modifier also
234     causes any non-printing characters in output strings to be printed using the
235     \x{hh...} notation if they are valid UTF-8 sequences.
236     </P>
237 nigel 71 <P>
238     If the <b>/?</b> modifier is used with <b>/8</b>, it causes <b>pcretest</b> to
239     call <b>pcre_compile()</b> with the PCRE_NO_UTF8_CHECK option, to suppress the
240     checking of the string for UTF-8 validity.
241     </P>
242 nigel 63 <br><a name="SEC5" href="#TOC1">CALLOUTS</a><br>
243     <P>
244     If the pattern contains any callout requests, <b>pcretest</b>'s callout function
245     will be called. By default, it displays the callout number, and the start and
246     current positions in the text at the callout time. For example, the output
247     </P>
248     <P>
249     <pre>
250     ---&#62;pqrabcdef
251     0 ^ ^
252     </PRE>
253     </P>
254     <P>
255     indicates that callout number 0 occurred for a match attempt starting at the
256     fourth character of the subject string, when the pointer was at the seventh
257     character. The callout function returns zero (carry on matching) by default.
258     </P>
259     <P>
260     Inserting callouts may be helpful when using <b>pcretest</b> to check
261     complicated regular expressions. For further information about callouts, see
262     the
263     <a href="pcrecallout.html"><b>pcrecallout</b></a>
264     documentation.
265     </P>
266     <P>
267     For testing the PCRE library, additional control of callout behaviour is
268     available via escape sequences in the data, as described in the following
269     section. In particular, it is possible to pass in a number as callout data (the
270     default is zero). If the callout function receives a non-zero number, it
271     returns that value instead of zero.
272     </P>
273     <br><a name="SEC6" href="#TOC1">DATA LINES</a><br>
274     <P>
275     Before each data line is passed to <b>pcre_exec()</b>, leading and trailing
276     whitespace is removed, and it is then scanned for \ escapes. Some of these are
277     pretty esoteric features, intended for checking out some of the more
278     complicated features of PCRE. If you are just testing "ordinary" regular
279     expressions, you probably don't need any of these. The following escapes are
280     recognized:
281     </P>
282     <P>
283     <pre>
284     \a alarm (= BEL)
285     \b backspace
286     \e escape
287     \f formfeed
288     \n newline
289     \r carriage return
290     \t tab
291     \v vertical tab
292     \nnn octal character (up to 3 octal digits)
293     \xhh hexadecimal character (up to 2 hex digits)
294     \x{hh...} hexadecimal character, any number of digits
295     in UTF-8 mode
296     \A pass the PCRE_ANCHORED option to <b>pcre_exec()</b>
297     \B pass the PCRE_NOTBOL option to <b>pcre_exec()</b>
298     \Cdd call pcre_copy_substring() for substring dd
299     after a successful match (any decimal number
300     less than 32)
301     \Cname call pcre_copy_named_substring() for substring
302     "name" after a successful match (name termin-
303     ated by next non alphanumeric character)
304     \C+ show the current captured substrings at callout
305     time
306     \C- do not supply a callout function
307     \C!n return 1 instead of 0 when callout number n is
308     reached
309     \C!n!m return 1 instead of 0 when callout number n is
310     reached for the nth time
311     \C*n pass the number n (may be negative) as callout
312     data
313     \Gdd call pcre_get_substring() for substring dd
314     after a successful match (any decimal number
315     less than 32)
316     \Gname call pcre_get_named_substring() for substring
317     "name" after a successful match (name termin-
318     ated by next non-alphanumeric character)
319     \L call pcre_get_substringlist() after a
320     successful match
321     \M discover the minimum MATCH_LIMIT setting
322     \N pass the PCRE_NOTEMPTY option to <b>pcre_exec()</b>
323     \Odd set the size of the output vector passed to
324     <b>pcre_exec()</b> to dd (any number of decimal
325     digits)
326 nigel 73 \S output details of memory get/free calls during matching
327 nigel 63 \Z pass the PCRE_NOTEOL option to <b>pcre_exec()</b>
328 nigel 71 \? pass the PCRE_NO_UTF8_CHECK option to
329     <b>pcre_exec()</b>
330 nigel 63 </PRE>
331     </P>
332     <P>
333     If \M is present, <b>pcretest</b> calls <b>pcre_exec()</b> several times, with
334     different values in the <i>match_limit</i> field of the <b>pcre_extra</b> data
335     structure, until it finds the minimum number that is needed for
336     <b>pcre_exec()</b> to complete. This number is a measure of the amount of
337     recursion and backtracking that takes place, and checking it out can be
338     instructive. For most simple matches, the number is quite small, but for
339     patterns with very large numbers of matching possibilities, it can become large
340     very quickly with increasing length of subject string.
341     </P>
342     <P>
343     When \O is used, it may be higher or lower than the size set by the <b>-O</b>
344     option (or defaulted to 45); \O applies only to the call of <b>pcre_exec()</b>
345     for the line in which it appears.
346     </P>
347     <P>
348     A backslash followed by anything else just escapes the anything else. If the
349     very last character is a backslash, it is ignored. This gives a way of passing
350     an empty line as data, since a real empty line terminates the data input.
351     </P>
352     <P>
353     If <b>/P</b> was present on the regex, causing the POSIX wrapper API to be used,
354     only <b>\B</b>, and <b>\Z</b> have any effect, causing REG_NOTBOL and REG_NOTEOL
355     to be passed to <b>regexec()</b> respectively.
356     </P>
357     <P>
358     The use of \x{hh...} to represent UTF-8 characters is not dependent on the use
359     of the <b>/8</b> modifier on the pattern. It is recognized always. There may be
360     any number of hexadecimal digits inside the braces. The result is from one to
361     six bytes, encoded according to the UTF-8 rules.
362     </P>
363     <br><a name="SEC7" href="#TOC1">OUTPUT FROM PCRETEST</a><br>
364     <P>
365     When a match succeeds, pcretest outputs the list of captured substrings that
366     <b>pcre_exec()</b> returns, starting with number 0 for the string that matched
367     the whole pattern. Here is an example of an interactive pcretest run.
368     </P>
369     <P>
370     <pre>
371     $ pcretest
372     PCRE version 4.00 08-Jan-2003
373     </PRE>
374     </P>
375     <P>
376     <pre>
377     re&#62; /^abc(\d+)/
378     data&#62; abc123
379     0: abc123
380     1: 123
381     data&#62; xyz
382     No match
383     </PRE>
384     </P>
385     <P>
386     If the strings contain any non-printing characters, they are output as \0x
387     escapes, or as \x{...} escapes if the <b>/8</b> modifier was present on the
388     pattern. If the pattern has the <b>/+</b> modifier, then the output for
389     substring 0 is followed by the the rest of the subject string, identified by
390     "0+" like this:
391     </P>
392     <P>
393     <pre>
394     re&#62; /cat/+
395     data&#62; cataract
396     0: cat
397     0+ aract
398     </PRE>
399     </P>
400     <P>
401     If the pattern has the <b>/g</b> or <b>/G</b> modifier, the results of successive
402     matching attempts are output in sequence, like this:
403     </P>
404     <P>
405     <pre>
406     re&#62; /\Bi(\w\w)/g
407     data&#62; Mississippi
408     0: iss
409     1: ss
410     0: iss
411     1: ss
412     0: ipp
413     1: pp
414     </PRE>
415     </P>
416     <P>
417     "No match" is output only if the first match attempt fails.
418     </P>
419     <P>
420     If any of the sequences <b>\C</b>, <b>\G</b>, or <b>\L</b> are present in a
421     data line that is successfully matched, the substrings extracted by the
422     convenience functions are output with C, G, or L after the string number
423     instead of a colon. This is in addition to the normal full list. The string
424     length (that is, the return from the extraction function) is given in
425     parentheses after each string for <b>\C</b> and <b>\G</b>.
426     </P>
427     <P>
428     Note that while patterns can be continued over several lines (a plain "&#62;"
429     prompt is used for continuations), data lines may not. However newlines can be
430     included in data by means of the \n escape.
431     </P>
432     <br><a name="SEC8" href="#TOC1">AUTHOR</a><br>
433     <P>
434     Philip Hazel &#60;ph10@cam.ac.uk&#62;
435     <br>
436     University Computing Service,
437     <br>
438     Cambridge CB2 3QG, England.
439     </P>
440     <P>
441 nigel 73 Last updated: 09 December 2003
442 nigel 63 <br>
443     Copyright &copy; 1997-2003 University of Cambridge.

ViewVC Help
Powered by ViewVC 1.1.12