~ubuntu-branches/ubuntu/maverick/ncbi-tools6/maverick

« back to all changes in this revision

Viewing changes to regexp/doc/pcretest.html

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<HTML>
 
2
<HEAD>
 
3
<TITLE>pcretest specification</TITLE>
 
4
</HEAD>
 
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
 
9
conversion went wrong.
 
10
<UL>
 
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>
 
19
</UL>
 
20
<LI><A NAME="SEC1" HREF="#TOC1">NAME</A>
 
21
<P>
 
22
pcretest - a program for testing Perl-compatible regular expressions.
 
23
</P>
 
24
<LI><A NAME="SEC2" HREF="#TOC1">SYNOPSIS</A>
 
25
<P>
 
26
<B>pcretest [-d] [-i] [-m] [-o osize] [-p] [-t] [source] [destination]</B>
 
27
</P>
 
28
<P>
 
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.
 
33
</P>
 
34
<LI><A NAME="SEC3" HREF="#TOC1">OPTIONS</A>
 
35
<P>
 
36
<B>-d</B>
 
37
Behave as if each regex had the <B>/D</B> modifier (see below); the internal
 
38
form is output after compilation.
 
39
</P>
 
40
<P>
 
41
<B>-i</B>
 
42
Behave as if each regex had the <B>/I</B> modifier; information about the
 
43
compiled pattern is given after compilation.
 
44
</P>
 
45
<P>
 
46
<B>-m</B>
 
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>.
 
50
</P>
 
51
<P>
 
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).
 
57
</P>
 
58
<P>
 
59
<B>-p</B>
 
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.
 
62
</P>
 
63
<P>
 
64
<B>-t</B>
 
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
 
68
will be distorted.
 
69
</P>
 
70
<LI><A NAME="SEC4" HREF="#TOC1">DESCRIPTION</A>
 
71
<P>
 
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&#62;" to prompt for regular
 
76
expressions, and "data&#62;" to prompt for data lines.
 
77
</P>
 
78
<P>
 
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
 
85
</P>
 
86
<P>
 
87
<PRE>
 
88
  /(a|bc)x+yz/
 
89
</PRE>
 
90
</P>
 
91
<P>
 
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
 
96
</P>
 
97
<P>
 
98
<PRE>
 
99
  /abc\/def/
 
100
</PRE>
 
101
</P>
 
102
<P>
 
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
 
106
example,
 
107
</P>
 
108
<P>
 
109
<PRE>
 
110
  /abc/\
 
111
</PRE>
 
112
</P>
 
113
<P>
 
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
 
116
backslash, because
 
117
</P>
 
118
<P>
 
119
<PRE>
 
120
  /abc\/
 
121
</PRE>
 
122
</P>
 
123
<P>
 
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.
 
126
</P>
 
127
<LI><A NAME="SEC5" HREF="#TOC1">PATTERN MODIFIERS</A>
 
128
<P>
 
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:
 
132
</P>
 
133
<P>
 
134
<PRE>
 
135
  /caseless/i
 
136
</PRE>
 
137
</P>
 
138
<P>
 
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.
 
143
</P>
 
144
<P>
 
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).
 
153
</P>
 
154
<P>
 
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.
 
161
</P>
 
162
<P>
 
163
There are a number of other modifiers for controlling the way <B>pcretest</B>
 
164
operates.
 
165
</P>
 
166
<P>
 
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.
 
171
</P>
 
172
<P>
 
173
The <B>/L</B> modifier must be followed directly by the name of a locale, for
 
174
example,
 
175
</P>
 
176
<P>
 
177
<PRE>
 
178
  /pattern/Lfr
 
179
</PRE>
 
180
</P>
 
181
<P>
 
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.
 
187
</P>
 
188
<P>
 
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.
 
194
</P>
 
195
<P>
 
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
 
198
compilation.
 
199
</P>
 
200
<P>
 
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
 
203
matched.
 
204
</P>
 
205
<P>
 
206
The <B>/M</B> modifier causes the size of memory block used to hold the compiled
 
207
pattern to be output.
 
208
</P>
 
209
<P>
 
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.
 
215
</P>
 
216
<P>
 
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
 
222
sequences.
 
223
</P>
 
224
<LI><A NAME="SEC6" HREF="#TOC1">DATA LINES</A>
 
225
<P>
 
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
 
228
recognized:
 
229
</P>
 
230
<P>
 
231
<PRE>
 
232
  \a         alarm (= BEL)
 
233
  \b         backspace
 
234
  \e         escape
 
235
  \f         formfeed
 
236
  \n         newline
 
237
  \r         carriage return
 
238
  \t         tab
 
239
  \v         vertical tab
 
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
 
243
</PRE>
 
244
</P>
 
245
<P>
 
246
<PRE>
 
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
 
251
                less than 32)
 
252
  \Gdd       call pcre_get_substring() for substring dd
 
253
                after a successful match (any decimal number
 
254
                less than 32)
 
255
  \L         call pcre_get_substringlist() after a
 
256
                successful match
 
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
 
260
                digits)
 
261
  \Z         pass the PCRE_NOTEOL option to <B>pcre_exec()</B>
 
262
</PRE>
 
263
</P>
 
264
<P>
 
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.
 
268
</P>
 
269
<P>
 
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.
 
273
</P>
 
274
<P>
 
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.
 
278
</P>
 
279
<P>
 
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.
 
284
</P>
 
285
<LI><A NAME="SEC7" HREF="#TOC1">OUTPUT FROM PCRETEST</A>
 
286
<P>
 
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.
 
290
</P>
 
291
<P>
 
292
<PRE>
 
293
  $ pcretest
 
294
  PCRE version 2.06 08-Jun-1999
 
295
</PRE>
 
296
</P>
 
297
<P>
 
298
<PRE>
 
299
    re&#62; /^abc(\d+)/
 
300
  data&#62; abc123
 
301
   0: abc123
 
302
   1: 123
 
303
  data&#62; xyz
 
304
  No match
 
305
</PRE>
 
306
</P>
 
307
<P>
 
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
 
312
"0+" like this:
 
313
</P>
 
314
<P>
 
315
<PRE>
 
316
    re&#62; /cat/+
 
317
  data&#62; cataract
 
318
   0: cat
 
319
   0+ aract
 
320
</PRE>
 
321
</P>
 
322
<P>
 
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:
 
325
</P>
 
326
<P>
 
327
<PRE>
 
328
    re&#62; /\Bi(\w\w)/g
 
329
  data&#62; Mississippi
 
330
   0: iss
 
331
   1: ss
 
332
   0: iss
 
333
   1: ss
 
334
   0: ipp
 
335
   1: pp
 
336
</PRE>
 
337
</P>
 
338
<P>
 
339
"No match" is output only if the first match attempt fails.
 
340
</P>
 
341
<P>
 
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>.
 
348
</P>
 
349
<P>
 
350
Note that while patterns can be continued over several lines (a plain "&#62;"
 
351
prompt is used for continuations), data lines may not. However newlines can be
 
352
included in data by means of the \n escape.
 
353
</P>
 
354
<LI><A NAME="SEC8" HREF="#TOC1">AUTHOR</A>
 
355
<P>
 
356
Philip Hazel &#60;ph10@cam.ac.uk&#62;
 
357
<BR>
 
358
University Computing Service,
 
359
<BR>
 
360
New Museums Site,
 
361
<BR>
 
362
Cambridge CB2 3QG, England.
 
363
<BR>
 
364
Phone: +44 1223 334714
 
365
</P>
 
366
<P>
 
367
Last updated: 15 August 2001
 
368
<BR>
 
369
Copyright (c) 1997-2001 University of Cambridge.