3
<title>pcretest specification</title>
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>
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>
19
<br><a name="SEC1" href="#TOC1">SYNOPSIS</a><br>
21
<b>pcretest [-d] [-i] [-m] [-o osize] [-p] [-t] [source] [destination]</b>
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>
33
<br><a name="SEC2" href="#TOC1">OPTIONS</a><br>
36
Output the version number of the PCRE library, and all available information
37
about the optional features that are included, and then exit.
41
Behave as if each regex had the <b>/D</b> modifier (see below); the internal
42
form is output after compilation.
46
Behave as if each regex had the <b>/I</b> modifier; information about the
47
compiled pattern is given after compilation.
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>.
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).
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.
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
74
<br><a name="SEC3" href="#TOC1">DESCRIPTION</a><br>
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>" to prompt for regular
80
expressions, and "data>" to prompt for data lines.
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.
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
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
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
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
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
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.
139
<br><a name="SEC4" href="#TOC1">PATTERN MODIFIERS</a><br>
141
The pattern may be followed by <b>i</b>, <b>m</b>, <b>s</b>, or <b>x</b> to set the
142
PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, or PCRE_EXTENDED options,
143
respectively. For example:
151
These modifier letters have the same effect as they do in Perl. There are
152
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,
154
PCRE_DOLLAR_ENDONLY, PCRE_NO_AUTO_CAPTURE, PCRE_UNGREEDY, and PCRE_EXTRA
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).
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.
176
There are a number of other modifiers for controlling the way <b>pcretest</b>
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.
186
The <b>/L</b> modifier must be followed directly by the name of a locale, for
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.
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.
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
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
220
The <b>/M</b> modifier causes the size of memory block used to hold the compiled
221
pattern to be output.
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.
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.
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.
242
<br><a name="SEC5" href="#TOC1">CALLOUTS</a><br>
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
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.
260
Inserting callouts may be helpful when using <b>pcretest</b> to check
261
complicated regular expressions. For further information about callouts, see
263
<a href="pcrecallout.html"><b>pcrecallout</b></a>
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.
273
<br><a name="SEC6" href="#TOC1">DATA LINES</a><br>
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
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
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
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
306
\C- do not supply a callout function
307
\C!n return 1 instead of 0 when callout number n is
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
313
\Gdd call pcre_get_substring() for substring dd
314
after a successful match (any decimal number
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
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
326
\S output details of memory get/free calls during matching
327
\Z pass the PCRE_NOTEOL option to <b>pcre_exec()</b>
328
\? pass the PCRE_NO_UTF8_CHECK option to
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.
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.
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.
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.
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.
363
<br><a name="SEC7" href="#TOC1">OUTPUT FROM PCRETEST</a><br>
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.
372
PCRE version 4.00 08-Jan-2003
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
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:
407
data> Mississippi
417
"No match" is output only if the first match attempt fails.
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>.
428
Note that while patterns can be continued over several lines (a plain ">"
429
prompt is used for continuations), data lines may not. However newlines can be
430
included in data by means of the \n escape.
432
<br><a name="SEC8" href="#TOC1">AUTHOR</a><br>
434
Philip Hazel <ph10@cam.ac.uk>
436
University Computing Service,
438
Cambridge CB2 3QG, England.
441
Last updated: 09 December 2003
443
Copyright © 1997-2003 University of Cambridge.