3
<TITLE>pcretest specification</TITLE>
5
<body bgcolor="#FFFFFF" text="#00005A">
6
<H1>pcretest specification</H1>
7
This HTML document has been generated automatically from the original man page.
8
If there is any nonsense in it, please consult the man page in case the
11
<LI><A NAME="TOC1" HREF="#SEC1">NAME</A>
12
<LI><A NAME="TOC2" HREF="#SEC2">SYNOPSIS</A>
13
<LI><A NAME="TOC3" HREF="#SEC3">OPTIONS</A>
14
<LI><A NAME="TOC4" HREF="#SEC4">DESCRIPTION</A>
15
<LI><A NAME="TOC5" HREF="#SEC5">PATTERN MODIFIERS</A>
16
<LI><A NAME="TOC6" HREF="#SEC6">DATA LINES</A>
17
<LI><A NAME="TOC7" HREF="#SEC7">OUTPUT FROM PCRETEST</A>
18
<LI><A NAME="TOC8" HREF="#SEC8">AUTHOR</A>
20
<LI><A NAME="SEC1" HREF="#TOC1">NAME</A>
22
pcretest - a program for testing Perl-compatible regular expressions.
24
<LI><A NAME="SEC2" HREF="#TOC1">SYNOPSIS</A>
26
<B>pcretest [-d] [-i] [-m] [-o osize] [-p] [-t] [source] [destination]</B>
29
<B>pcretest</B> was written as a test program for the PCRE regular expression
30
library itself, but it can also be used for experimenting with regular
31
expressions. This man page describes the features of the test program; for
32
details of the regular expressions themselves, see the <B>pcre</B> man page.
34
<LI><A NAME="SEC3" HREF="#TOC1">OPTIONS</A>
37
Behave as if each regex had the <B>/D</B> modifier (see below); the internal
38
form is output after compilation.
42
Behave as if each regex had the <B>/I</B> modifier; information about the
43
compiled pattern is given after compilation.
47
Output the size of each compiled pattern after it has been compiled. This is
48
equivalent to adding /M to each regular expression. For compatibility with
49
earlier versions of pcretest, <B>-s</B> is a synonym for <B>-m</B>.
52
<B>-o</B> <I>osize</I>
53
Set the number of elements in the output vector that is used when calling PCRE
54
to be <I>osize</I>. The default value is 45, which is enough for 14 capturing
55
subexpressions. The vector size can be changed for individual matching calls by
56
including \O in the data line (see below).
60
Behave as if each regex has <B>/P</B> modifier; the POSIX wrapper API is used
61
to call PCRE. None of the other options has any effect when <B>-p</B> is set.
65
Run each compile, study, and match 20000 times with a timer, and output
66
resulting time per compile or match (in milliseconds). Do not set <B>-t</B> with
67
<B>-m</B>, because you will then get the size output 20000 times and the timing
70
<LI><A NAME="SEC4" HREF="#TOC1">DESCRIPTION</A>
72
If <B>pcretest</B> is given two filename arguments, it reads from the first and
73
writes to the second. If it is given only one filename argument, it reads from
74
that file and writes to stdout. Otherwise, it reads from stdin and writes to
75
stdout, and prompts for each line of input, using "re>" to prompt for regular
76
expressions, and "data>" to prompt for data lines.
79
The program handles any number of sets of input on a single input file. Each
80
set starts with a regular expression, and continues with any number of data
81
lines to be matched against the pattern. An empty line signals the end of the
82
data lines, at which point a new regular expression is read. The regular
83
expressions are given enclosed in any non-alphameric delimiters other than
84
backslash, for example
92
White space before the initial delimiter is ignored. A regular expression may
93
be continued over several input lines, in which case the newline characters are
94
included within it. It is possible to include the delimiter within the pattern
95
by escaping it, for example
103
If you do so, the escape and the delimiter form part of the pattern, but since
104
delimiters are always non-alphameric, this does not affect its interpretation.
105
If the terminating delimiter is immediately followed by a backslash, for
114
then a backslash is added to the end of the pattern. This is done to provide a
115
way of testing the error condition that arises if a pattern finishes with a
124
is interpreted as the first line of a pattern that starts with "abc/", causing
125
pcretest to read the next line as a continuation of the regular expression.
127
<LI><A NAME="SEC5" HREF="#TOC1">PATTERN MODIFIERS</A>
129
The pattern may be followed by <B>i</B>, <B>m</B>, <B>s</B>, or <B>x</B> to set the
130
PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, or PCRE_EXTENDED options,
131
respectively. For example:
139
These modifier letters have the same effect as they do in Perl. There are
140
others which set PCRE options that do not correspond to anything in Perl:
141
<B>/A</B>, <B>/E</B>, and <B>/X</B> set PCRE_ANCHORED, PCRE_DOLLAR_ENDONLY, and
142
PCRE_EXTRA respectively.
145
Searching for all possible matches within each subject string can be requested
146
by the <B>/g</B> or <B>/G</B> modifier. After finding a match, PCRE is called
147
again to search the remainder of the subject string. The difference between
148
<B>/g</B> and <B>/G</B> is that the former uses the <I>startoffset</I> argument to
149
<B>pcre_exec()</B> to start searching at a new point within the entire string
150
(which is in effect what Perl does), whereas the latter passes over a shortened
151
substring. This makes a difference to the matching process if the pattern
152
begins with a lookbehind assertion (including \b or \B).
155
If any call to <B>pcre_exec()</B> in a <B>/g</B> or <B>/G</B> sequence matches an
156
empty string, the next call is done with the PCRE_NOTEMPTY and PCRE_ANCHORED
157
flags set in order to search for another, non-empty, match at the same point.
158
If this second match fails, the start offset is advanced by one, and the normal
159
match is retried. This imitates the way Perl handles such cases when using the
160
<B>/g</B> modifier or the <B>split()</B> function.
163
There are a number of other modifiers for controlling the way <B>pcretest</B>
167
The <B>/+</B> modifier requests that as well as outputting the substring that
168
matched the entire pattern, pcretest should in addition output the remainder of
169
the subject string. This is useful for tests where the subject contains
170
multiple copies of the same substring.
173
The <B>/L</B> modifier must be followed directly by the name of a locale, for
182
For this reason, it must be the last modifier letter. The given locale is set,
183
<B>pcre_maketables()</B> is called to build a set of character tables for the
184
locale, and this is then passed to <B>pcre_compile()</B> when compiling the
185
regular expression. Without an <B>/L</B> modifier, NULL is passed as the tables
186
pointer; that is, <B>/L</B> applies only to the expression on which it appears.
189
The <B>/I</B> modifier requests that <B>pcretest</B> output information about the
190
compiled expression (whether it is anchored, has a fixed first character, and
191
so on). It does this by calling <B>pcre_fullinfo()</B> after compiling an
192
expression, and outputting the information it gets back. If the pattern is
193
studied, the results of that are also output.
196
The <B>/D</B> modifier is a PCRE debugging feature, which also assumes <B>/I</B>.
197
It causes the internal form of compiled regular expressions to be output after
201
The <B>/S</B> modifier causes <B>pcre_study()</B> to be called after the
202
expression has been compiled, and the results used when the expression is
206
The <B>/M</B> modifier causes the size of memory block used to hold the compiled
207
pattern to be output.
210
The <B>/P</B> modifier causes <B>pcretest</B> to call PCRE via the POSIX wrapper
211
API rather than its native API. When this is done, all other modifiers except
212
<B>/i</B>, <B>/m</B>, and <B>/+</B> are ignored. REG_ICASE is set if <B>/i</B> is
213
present, and REG_NEWLINE is set if <B>/m</B> is present. The wrapper functions
214
force PCRE_DOLLAR_ENDONLY always, and PCRE_DOTALL unless REG_NEWLINE is set.
217
The <B>/8</B> modifier causes <B>pcretest</B> to call PCRE with the PCRE_UTF8
218
option set. This turns on the (currently incomplete) support for UTF-8
219
character handling in PCRE, provided that it was compiled with this support
220
enabled. This modifier also causes any non-printing characters in output
221
strings to be printed using the \x{hh...} notation if they are valid UTF-8
224
<LI><A NAME="SEC6" HREF="#TOC1">DATA LINES</A>
226
Before each data line is passed to <B>pcre_exec()</B>, leading and trailing
227
whitespace is removed, and it is then scanned for \ escapes. The following are
240
\nnn octal character (up to 3 octal digits)
241
\xhh hexadecimal character (up to 2 hex digits)
242
\x{hh...} hexadecimal UTF-8 character
247
\A pass the PCRE_ANCHORED option to <B>pcre_exec()</B>
248
\B pass the PCRE_NOTBOL option to <B>pcre_exec()</B>
249
\Cdd call pcre_copy_substring() for substring dd
250
after a successful match (any decimal number
252
\Gdd call pcre_get_substring() for substring dd
253
after a successful match (any decimal number
255
\L call pcre_get_substringlist() after a
257
\N pass the PCRE_NOTEMPTY option to <B>pcre_exec()</B>
258
\Odd set the size of the output vector passed to
259
<B>pcre_exec()</B> to dd (any number of decimal
261
\Z pass the PCRE_NOTEOL option to <B>pcre_exec()</B>
265
When \O is used, it may be higher or lower than the size set by the <B>-O</B>
266
option (or defaulted to 45); \O applies only to the call of <B>pcre_exec()</B>
267
for the line in which it appears.
270
A backslash followed by anything else just escapes the anything else. If the
271
very last character is a backslash, it is ignored. This gives a way of passing
272
an empty line as data, since a real empty line terminates the data input.
275
If <B>/P</B> was present on the regex, causing the POSIX wrapper API to be used,
276
only <B>\B</B>, and <B>\Z</B> have any effect, causing REG_NOTBOL and REG_NOTEOL
277
to be passed to <B>regexec()</B> respectively.
280
The use of \x{hh...} to represent UTF-8 characters is not dependent on the use
281
of the <B>/8</B> modifier on the pattern. It is recognized always. There may be
282
any number of hexadecimal digits inside the braces. The result is from one to
283
six bytes, encoded according to the UTF-8 rules.
285
<LI><A NAME="SEC7" HREF="#TOC1">OUTPUT FROM PCRETEST</A>
287
When a match succeeds, pcretest outputs the list of captured substrings that
288
<B>pcre_exec()</B> returns, starting with number 0 for the string that matched
289
the whole pattern. Here is an example of an interactive pcretest run.
294
PCRE version 2.06 08-Jun-1999
308
If the strings contain any non-printing characters, they are output as \0x
309
escapes, or as \x{...} escapes if the <B>/8</B> modifier was present on the
310
pattern. If the pattern has the <B>/+</B> modifier, then the output for
311
substring 0 is followed by the the rest of the subject string, identified by
323
If the pattern has the <B>/g</B> or <B>/G</B> modifier, the results of successive
324
matching attempts are output in sequence, like this:
329
data> Mississippi
339
"No match" is output only if the first match attempt fails.
342
If any of the sequences <B>\C</B>, <B>\G</B>, or <B>\L</B> are present in a
343
data line that is successfully matched, the substrings extracted by the
344
convenience functions are output with C, G, or L after the string number
345
instead of a colon. This is in addition to the normal full list. The string
346
length (that is, the return from the extraction function) is given in
347
parentheses after each string for <B>\C</B> and <B>\G</B>.
350
Note that while patterns can be continued over several lines (a plain ">"
351
prompt is used for continuations), data lines may not. However newlines can be
352
included in data by means of the \n escape.
354
<LI><A NAME="SEC8" HREF="#TOC1">AUTHOR</A>
356
Philip Hazel <ph10@cam.ac.uk>
358
University Computing Service,
362
Cambridge CB2 3QG, England.
364
Phone: +44 1223 334714
367
Last updated: 15 August 2001
369
Copyright (c) 1997-2001 University of Cambridge.