• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<title>pcretest specification</title>
4</head>
5<body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
6<h1>pcretest man page</h1>
7<p>
8Return to the <a href="index.html">PCRE index page</a>.
9</p>
10<p>
11This page is part of the PCRE HTML documentation. It was generated automatically
12from the original man page. If there is any nonsense in it, please consult the
13man page, in case the conversion went wrong.
14<br>
15<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<li><a name="TOC5" href="#SEC5">DATA LINES</a>
21<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">NON-PRINTING CHARACTERS</a>
27<li><a name="TOC12" href="#SEC12">SAVING AND RELOADING COMPILED PATTERNS</a>
28<li><a name="TOC13" href="#SEC13">SEE ALSO</a>
29<li><a name="TOC14" href="#SEC14">AUTHOR</a>
30<li><a name="TOC15" href="#SEC15">REVISION</a>
31</ul>
32<br><a name="SEC1" href="#TOC1">SYNOPSIS</a><br>
33<P>
34<b>pcretest [options] [source] [destination]</b>
35<br>
36<br>
37<b>pcretest</b> was written as a test program for the PCRE regular expression
38library itself, but it can also be used for experimenting with regular
39expressions. This document describes the features of the test program; for
40details of the regular expressions themselves, see the
41<a href="pcrepattern.html"><b>pcrepattern</b></a>
42documentation. For details of the PCRE library function calls and their
43options, see the
44<a href="pcreapi.html"><b>pcreapi</b></a>
45documentation.
46</P>
47<br><a name="SEC2" href="#TOC1">OPTIONS</a><br>
48<P>
49<b>-b</b>
50Behave as if each regex has the <b>/B</b> (show bytecode) modifier; the internal
51form is output after compilation.
52</P>
53<P>
54<b>-C</b>
55Output the version number of the PCRE library, and all available information
56about the optional features that are included, and then exit.
57</P>
58<P>
59<b>-d</b>
60Behave as if each regex has the <b>/D</b> (debug) modifier; the internal
61form and information about the compiled pattern is output after compilation;
62<b>-d</b> is equivalent to <b>-b -i</b>.
63</P>
64<P>
65<b>-dfa</b>
66Behave as if each data line contains the \D escape sequence; this causes the
67alternative matching function, <b>pcre_dfa_exec()</b>, to be used instead of the
68standard <b>pcre_exec()</b> function (more detail is given below).
69</P>
70<P>
71<b>-help</b>
72Output a brief summary these options and then exit.
73</P>
74<P>
75<b>-i</b>
76Behave as if each regex has the <b>/I</b> modifier; information about the
77compiled pattern is given after compilation.
78</P>
79<P>
80<b>-M</b>
81Behave as if each data line contains the \M escape sequence; this causes
82PCRE to discover the minimum MATCH_LIMIT and MATCH_LIMIT_RECURSION settings by
83calling <b>pcre_exec()</b> repeatedly with different limits.
84</P>
85<P>
86<b>-m</b>
87Output the size of each compiled pattern after it has been compiled. This is
88equivalent to adding <b>/M</b> to each regular expression. For compatibility
89with earlier versions of pcretest, <b>-s</b> is a synonym for <b>-m</b>.
90</P>
91<P>
92<b>-o</b> <i>osize</i>
93Set the number of elements in the output vector that is used when calling
94<b>pcre_exec()</b> or <b>pcre_dfa_exec()</b> to be <i>osize</i>. The default value
95is 45, which is enough for 14 capturing subexpressions for <b>pcre_exec()</b> or
9622 different matches for <b>pcre_dfa_exec()</b>. The vector size can be
97changed for individual matching calls by including \O in the data line (see
98below).
99</P>
100<P>
101<b>-p</b>
102Behave as if each regex has the <b>/P</b> modifier; the POSIX wrapper API is
103used to call PCRE. None of the other options has any effect when <b>-p</b> is
104set.
105</P>
106<P>
107<b>-q</b>
108Do not output the version number of <b>pcretest</b> at the start of execution.
109</P>
110<P>
111<b>-S</b> <i>size</i>
112On Unix-like systems, set the size of the runtime stack to <i>size</i>
113megabytes.
114</P>
115<P>
116<b>-t</b>
117Run each compile, study, and match many times with a timer, and output
118resulting time per compile or match (in milliseconds). Do not set <b>-m</b> with
119<b>-t</b>, because you will then get the size output a zillion times, and the
120timing will be distorted. You can control the number of iterations that are
121used for timing by following <b>-t</b> with a number (as a separate item on the
122command line). For example, "-t 1000" would iterate 1000 times. The default is
123to iterate 500000 times.
124</P>
125<P>
126<b>-tm</b>
127This is like <b>-t</b> except that it times only the matching phase, not the
128compile or study phases.
129</P>
130<br><a name="SEC3" href="#TOC1">DESCRIPTION</a><br>
131<P>
132If <b>pcretest</b> is given two filename arguments, it reads from the first and
133writes to the second. If it is given only one filename argument, it reads from
134that file and writes to stdout. Otherwise, it reads from stdin and writes to
135stdout, and prompts for each line of input, using "re&#62;" to prompt for regular
136expressions, and "data&#62;" to prompt for data lines.
137</P>
138<P>
139When <b>pcretest</b> is built, a configuration option can specify that it should
140be linked with the <b>libreadline</b> library. When this is done, if the input
141is from a terminal, it is read using the <b>readline()</b> function. This
142provides line-editing and history facilities. The output from the <b>-help</b>
143option states whether or not <b>readline()</b> will be used.
144</P>
145<P>
146The program handles any number of sets of input on a single input file. Each
147set starts with a regular expression, and continues with any number of data
148lines to be matched against the pattern.
149</P>
150<P>
151Each data line is matched separately and independently. If you want to do
152multi-line matches, you have to use the \n escape sequence (or \r or \r\n,
153etc., depending on the newline setting) in a single line of input to encode the
154newline sequences. There is no limit on the length of data lines; the input
155buffer is automatically extended if it is too small.
156</P>
157<P>
158An empty line signals the end of the data lines, at which point a new regular
159expression is read. The regular expressions are given enclosed in any
160non-alphanumeric delimiters other than backslash, for example:
161<pre>
162  /(a|bc)x+yz/
163</pre>
164White space before the initial delimiter is ignored. A regular expression may
165be continued over several input lines, in which case the newline characters are
166included within it. It is possible to include the delimiter within the pattern
167by escaping it, for example
168<pre>
169  /abc\/def/
170</pre>
171If you do so, the escape and the delimiter form part of the pattern, but since
172delimiters are always non-alphanumeric, this does not affect its interpretation.
173If the terminating delimiter is immediately followed by a backslash, for
174example,
175<pre>
176  /abc/\
177</pre>
178then a backslash is added to the end of the pattern. This is done to provide a
179way of testing the error condition that arises if a pattern finishes with a
180backslash, because
181<pre>
182  /abc\/
183</pre>
184is interpreted as the first line of a pattern that starts with "abc/", causing
185pcretest to read the next line as a continuation of the regular expression.
186</P>
187<br><a name="SEC4" href="#TOC1">PATTERN MODIFIERS</a><br>
188<P>
189A pattern may be followed by any number of modifiers, which are mostly single
190characters. Following Perl usage, these are referred to below as, for example,
191"the <b>/i</b> modifier", even though the delimiter of the pattern need not
192always be a slash, and no slash is used when writing modifiers. Whitespace may
193appear between the final pattern delimiter and the first modifier, and between
194the modifiers themselves.
195</P>
196<P>
197The <b>/i</b>, <b>/m</b>, <b>/s</b>, and <b>/x</b> modifiers set the PCRE_CASELESS,
198PCRE_MULTILINE, PCRE_DOTALL, or PCRE_EXTENDED options, respectively, when
199<b>pcre_compile()</b> is called. These four modifier letters have the same
200effect as they do in Perl. For example:
201<pre>
202  /caseless/i
203</pre>
204The following table shows additional modifiers for setting PCRE compile-time
205options that do not correspond to anything in Perl:
206<pre>
207  <b>/8</b>              PCRE_UTF8
208  <b>/?</b>              PCRE_NO_UTF8_CHECK
209  <b>/A</b>              PCRE_ANCHORED
210  <b>/C</b>              PCRE_AUTO_CALLOUT
211  <b>/E</b>              PCRE_DOLLAR_ENDONLY
212  <b>/f</b>              PCRE_FIRSTLINE
213  <b>/J</b>              PCRE_DUPNAMES
214  <b>/N</b>              PCRE_NO_AUTO_CAPTURE
215  <b>/U</b>              PCRE_UNGREEDY
216  <b>/W</b>              PCRE_UCP
217  <b>/X</b>              PCRE_EXTRA
218  <b>/Y</b>              PCRE_NO_START_OPTIMIZE
219  <b>/&#60;JS&#62;</b>           PCRE_JAVASCRIPT_COMPAT
220  <b>/&#60;cr&#62;</b>           PCRE_NEWLINE_CR
221  <b>/&#60;lf&#62;</b>           PCRE_NEWLINE_LF
222  <b>/&#60;crlf&#62;</b>         PCRE_NEWLINE_CRLF
223  <b>/&#60;anycrlf&#62;</b>      PCRE_NEWLINE_ANYCRLF
224  <b>/&#60;any&#62;</b>          PCRE_NEWLINE_ANY
225  <b>/&#60;bsr_anycrlf&#62;</b>  PCRE_BSR_ANYCRLF
226  <b>/&#60;bsr_unicode&#62;</b>  PCRE_BSR_UNICODE
227</pre>
228The modifiers that are enclosed in angle brackets are literal strings as shown,
229including the angle brackets, but the letters can be in either case. This
230example sets multiline matching with CRLF as the line ending sequence:
231<pre>
232  /^abc/m&#60;crlf&#62;
233</pre>
234As well as turning on the PCRE_UTF8 option, the <b>/8</b> modifier also causes
235any non-printing characters in output strings to be printed using the
236\x{hh...} notation if they are valid UTF-8 sequences. Full details of the PCRE
237options are given in the
238<a href="pcreapi.html"><b>pcreapi</b></a>
239documentation.
240</P>
241<br><b>
242Finding all matches in a string
243</b><br>
244<P>
245Searching for all possible matches within each subject string can be requested
246by the <b>/g</b> or <b>/G</b> modifier. After finding a match, PCRE is called
247again to search the remainder of the subject string. The difference between
248<b>/g</b> and <b>/G</b> is that the former uses the <i>startoffset</i> argument to
249<b>pcre_exec()</b> to start searching at a new point within the entire string
250(which is in effect what Perl does), whereas the latter passes over a shortened
251substring. This makes a difference to the matching process if the pattern
252begins with a lookbehind assertion (including \b or \B).
253</P>
254<P>
255If any call to <b>pcre_exec()</b> in a <b>/g</b> or <b>/G</b> sequence matches an
256empty string, the next call is done with the PCRE_NOTEMPTY_ATSTART and
257PCRE_ANCHORED flags set in order to search for another, non-empty, match at the
258same point. If this second match fails, the start offset is advanced, and the
259normal match is retried. This imitates the way Perl handles such cases when
260using the <b>/g</b> modifier or the <b>split()</b> function. Normally, the start
261offset is advanced by one character, but if the newline convention recognizes
262CRLF as a newline, and the current character is CR followed by LF, an advance
263of two is used.
264</P>
265<br><b>
266Other modifiers
267</b><br>
268<P>
269There are yet more modifiers for controlling the way <b>pcretest</b>
270operates.
271</P>
272<P>
273The <b>/+</b> modifier requests that as well as outputting the substring that
274matched the entire pattern, pcretest should in addition output the remainder of
275the subject string. This is useful for tests where the subject contains
276multiple copies of the same substring.
277</P>
278<P>
279The <b>/B</b> modifier is a debugging feature. It requests that <b>pcretest</b>
280output a representation of the compiled byte code after compilation. Normally
281this information contains length and offset values; however, if <b>/Z</b> is
282also present, this data is replaced by spaces. This is a special feature for
283use in the automatic test scripts; it ensures that the same output is generated
284for different internal link sizes.
285</P>
286<P>
287The <b>/D</b> modifier is a PCRE debugging feature, and is equivalent to
288<b>/BI</b>, that is, both the <b>/B</b> and the <b>/I</b> modifiers.
289</P>
290<P>
291The <b>/F</b> modifier causes <b>pcretest</b> to flip the byte order of the
292fields in the compiled pattern that contain 2-byte and 4-byte numbers. This
293facility is for testing the feature in PCRE that allows it to execute patterns
294that were compiled on a host with a different endianness. This feature is not
295available when the POSIX interface to PCRE is being used, that is, when the
296<b>/P</b> pattern modifier is specified. See also the section about saving and
297reloading compiled patterns below.
298</P>
299<P>
300The <b>/I</b> modifier requests that <b>pcretest</b> output information about the
301compiled pattern (whether it is anchored, has a fixed first character, and
302so on). It does this by calling <b>pcre_fullinfo()</b> after compiling a
303pattern. If the pattern is studied, the results of that are also output.
304</P>
305<P>
306The <b>/K</b> modifier requests <b>pcretest</b> to show names from backtracking
307control verbs that are returned from calls to <b>pcre_exec()</b>. It causes
308<b>pcretest</b> to create a <b>pcre_extra</b> block if one has not already been
309created by a call to <b>pcre_study()</b>, and to set the PCRE_EXTRA_MARK flag
310and the <b>mark</b> field within it, every time that <b>pcre_exec()</b> is
311called. If the variable that the <b>mark</b> field points to is non-NULL for a
312match, non-match, or partial match, <b>pcretest</b> prints the string to which
313it points. For a match, this is shown on a line by itself, tagged with "MK:".
314For a non-match it is added to the message.
315</P>
316<P>
317The <b>/L</b> modifier must be followed directly by the name of a locale, for
318example,
319<pre>
320  /pattern/Lfr_FR
321</pre>
322For this reason, it must be the last modifier. The given locale is set,
323<b>pcre_maketables()</b> is called to build a set of character tables for the
324locale, and this is then passed to <b>pcre_compile()</b> when compiling the
325regular expression. Without an <b>/L</b> (or <b>/T</b>) modifier, NULL is passed
326as the tables pointer; that is, <b>/L</b> applies only to the expression on
327which it appears.
328</P>
329<P>
330The <b>/M</b> modifier causes the size of memory block used to hold the compiled
331pattern to be output.
332</P>
333<P>
334The <b>/S</b> modifier causes <b>pcre_study()</b> to be called after the
335expression has been compiled, and the results used when the expression is
336matched.
337</P>
338<P>
339The <b>/T</b> modifier must be followed by a single digit. It causes a specific
340set of built-in character tables to be passed to <b>pcre_compile()</b>. It is
341used in the standard PCRE tests to check behaviour with different character
342tables. The digit specifies the tables as follows:
343<pre>
344  0   the default ASCII tables, as distributed in
345        pcre_chartables.c.dist
346  1   a set of tables defining ISO 8859 characters
347</pre>
348In table 1, some characters whose codes are greater than 128 are identified as
349letters, digits, spaces, etc.
350</P>
351<br><b>
352Using the POSIX wrapper API
353</b><br>
354<P>
355The <b>/P</b> modifier causes <b>pcretest</b> to call PCRE via the POSIX wrapper
356API rather than its native API. When <b>/P</b> is set, the following modifiers
357set options for the <b>regcomp()</b> function:
358<pre>
359  /i    REG_ICASE
360  /m    REG_NEWLINE
361  /N    REG_NOSUB
362  /s    REG_DOTALL     )
363  /U    REG_UNGREEDY   ) These options are not part of
364  /W    REG_UCP        )   the POSIX standard
365  /8    REG_UTF8       )
366</pre>
367The <b>/+</b> modifier works as described above. All other modifiers are
368ignored.
369</P>
370<br><a name="SEC5" href="#TOC1">DATA LINES</a><br>
371<P>
372Before each data line is passed to <b>pcre_exec()</b>, leading and trailing
373whitespace is removed, and it is then scanned for \ escapes. Some of these are
374pretty esoteric features, intended for checking out some of the more
375complicated features of PCRE. If you are just testing "ordinary" regular
376expressions, you probably don't need any of these. The following escapes are
377recognized:
378<pre>
379  \a         alarm (BEL, \x07)
380  \b         backspace (\x08)
381  \e         escape (\x27)
382  \f         formfeed (\x0c)
383  \n         newline (\x0a)
384  \qdd       set the PCRE_MATCH_LIMIT limit to dd (any number of digits)
385  \r         carriage return (\x0d)
386  \t         tab (\x09)
387  \v         vertical tab (\x0b)
388  \nnn       octal character (up to 3 octal digits)
389               always a byte unless &#62; 255 in UTF-8 mode
390  \xhh       hexadecimal byte (up to 2 hex digits)
391  \x{hh...}  hexadecimal character, any number of digits in UTF-8 mode
392  \A         pass the PCRE_ANCHORED option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
393  \B         pass the PCRE_NOTBOL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
394  \Cdd       call pcre_copy_substring() for substring dd after a successful match (number less than 32)
395  \Cname     call pcre_copy_named_substring() for substring "name" after a successful match (name termin-
396               ated by next non alphanumeric character)
397  \C+        show the current captured substrings at callout time
398  \C-        do not supply a callout function
399  \C!n       return 1 instead of 0 when callout number n is reached
400  \C!n!m     return 1 instead of 0 when callout number n is reached for the nth time
401  \C*n       pass the number n (may be negative) as callout data; this is used as the callout return value
402  \D         use the <b>pcre_dfa_exec()</b> match function
403  \F         only shortest match for <b>pcre_dfa_exec()</b>
404  \Gdd       call pcre_get_substring() for substring dd after a successful match (number less than 32)
405  \Gname     call pcre_get_named_substring() for substring "name" after a successful match (name termin-
406               ated by next non-alphanumeric character)
407  \L         call pcre_get_substringlist() after a successful match
408  \M         discover the minimum MATCH_LIMIT and MATCH_LIMIT_RECURSION settings
409  \N         pass the PCRE_NOTEMPTY option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>; if used twice, pass the
410               PCRE_NOTEMPTY_ATSTART option
411  \Odd       set the size of the output vector passed to <b>pcre_exec()</b> to dd (any number of digits)
412  \P         pass the PCRE_PARTIAL_SOFT option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>; if used twice, pass the
413               PCRE_PARTIAL_HARD option
414  \Qdd       set the PCRE_MATCH_LIMIT_RECURSION limit to dd (any number of digits)
415  \R         pass the PCRE_DFA_RESTART option to <b>pcre_dfa_exec()</b>
416  \S         output details of memory get/free calls during matching
417  \Y         pass the PCRE_NO_START_OPTIMIZE option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
418  \Z         pass the PCRE_NOTEOL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
419  \?         pass the PCRE_NO_UTF8_CHECK option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
420  \&#62;dd       start the match at offset dd (optional "-"; then any number of digits); this sets the <i>startoffset</i>
421               argument for <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
422  \&#60;cr&#62;      pass the PCRE_NEWLINE_CR option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
423  \&#60;lf&#62;      pass the PCRE_NEWLINE_LF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
424  \&#60;crlf&#62;    pass the PCRE_NEWLINE_CRLF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
425  \&#60;anycrlf&#62; pass the PCRE_NEWLINE_ANYCRLF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
426  \&#60;any&#62;     pass the PCRE_NEWLINE_ANY option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
427</pre>
428Note that \xhh always specifies one byte, even in UTF-8 mode; this makes it
429possible to construct invalid UTF-8 sequences for testing purposes. On the
430other hand, \x{hh} is interpreted as a UTF-8 character in UTF-8 mode,
431generating more than one byte if the value is greater than 127. When not in
432UTF-8 mode, it generates one byte for values less than 256, and causes an error
433for greater values.
434</P>
435<P>
436The escapes that specify line ending sequences are literal strings, exactly as
437shown. No more than one newline setting should be present in any data line.
438</P>
439<P>
440A backslash followed by anything else just escapes the anything else. If
441the very last character is a backslash, it is ignored. This gives a way of
442passing an empty line as data, since a real empty line terminates the data
443input.
444</P>
445<P>
446If \M is present, <b>pcretest</b> calls <b>pcre_exec()</b> several times, with
447different values in the <i>match_limit</i> and <i>match_limit_recursion</i>
448fields of the <b>pcre_extra</b> data structure, until it finds the minimum
449numbers for each parameter that allow <b>pcre_exec()</b> to complete. The
450<i>match_limit</i> number is a measure of the amount of backtracking that takes
451place, and checking it out can be instructive. For most simple matches, the
452number is quite small, but for patterns with very large numbers of matching
453possibilities, it can become large very quickly with increasing length of
454subject string. The <i>match_limit_recursion</i> number is a measure of how much
455stack (or, if PCRE is compiled with NO_RECURSE, how much heap) memory is needed
456to complete the match attempt.
457</P>
458<P>
459When \O is used, the value specified may be higher or lower than the size set
460by the <b>-O</b> command line option (or defaulted to 45); \O applies only to
461the call of <b>pcre_exec()</b> for the line in which it appears.
462</P>
463<P>
464If the <b>/P</b> modifier was present on the pattern, causing the POSIX wrapper
465API to be used, the only option-setting sequences that have any effect are \B,
466\N, and \Z, causing REG_NOTBOL, REG_NOTEMPTY, and REG_NOTEOL, respectively,
467to be passed to <b>regexec()</b>.
468</P>
469<P>
470The use of \x{hh...} to represent UTF-8 characters is not dependent on the use
471of the <b>/8</b> modifier on the pattern. It is recognized always. There may be
472any number of hexadecimal digits inside the braces. The result is from one to
473six bytes, encoded according to the original UTF-8 rules of RFC 2279. This
474allows for values in the range 0 to 0x7FFFFFFF. Note that not all of those are
475valid Unicode code points, or indeed valid UTF-8 characters according to the
476later rules in RFC 3629.
477</P>
478<br><a name="SEC6" href="#TOC1">THE ALTERNATIVE MATCHING FUNCTION</a><br>
479<P>
480By default, <b>pcretest</b> uses the standard PCRE matching function,
481<b>pcre_exec()</b> to match each data line. From release 6.0, PCRE supports an
482alternative matching function, <b>pcre_dfa_test()</b>, which operates in a
483different way, and has some restrictions. The differences between the two
484functions are described in the
485<a href="pcrematching.html"><b>pcrematching</b></a>
486documentation.
487</P>
488<P>
489If a data line contains the \D escape sequence, or if the command line
490contains the <b>-dfa</b> option, the alternative matching function is called.
491This function finds all possible matches at a given point. If, however, the \F
492escape sequence is present in the data line, it stops after the first match is
493found. This is always the shortest possible match.
494</P>
495<br><a name="SEC7" href="#TOC1">DEFAULT OUTPUT FROM PCRETEST</a><br>
496<P>
497This section describes the output when the normal matching function,
498<b>pcre_exec()</b>, is being used.
499</P>
500<P>
501When a match succeeds, pcretest outputs the list of captured substrings that
502<b>pcre_exec()</b> returns, starting with number 0 for the string that matched
503the whole pattern. Otherwise, it outputs "No match" when the return is
504PCRE_ERROR_NOMATCH, and "Partial match:" followed by the partially matching
505substring when <b>pcre_exec()</b> returns PCRE_ERROR_PARTIAL. (Note that this is
506the entire substring that was inspected during the partial match; it may
507include characters before the actual match start if a lookbehind assertion,
508\K, \b, or \B was involved.) For any other returns, it outputs the PCRE
509negative error number. Here is an example of an interactive <b>pcretest</b> run.
510<pre>
511  $ pcretest
512  PCRE version 7.0 30-Nov-2006
513
514    re&#62; /^abc(\d+)/
515  data&#62; abc123
516   0: abc123
517   1: 123
518  data&#62; xyz
519  No match
520</pre>
521Note that unset capturing substrings that are not followed by one that is set
522are not returned by <b>pcre_exec()</b>, and are not shown by <b>pcretest</b>. In
523the following example, there are two capturing substrings, but when the first
524data line is matched, the second, unset substring is not shown. An "internal"
525unset substring is shown as "&#60;unset&#62;", as for the second data line.
526<pre>
527    re&#62; /(a)|(b)/
528  data&#62; a
529   0: a
530   1: a
531  data&#62; b
532   0: b
533   1: &#60;unset&#62;
534   2: b
535</pre>
536If the strings contain any non-printing characters, they are output as \0x
537escapes, or as \x{...} escapes if the <b>/8</b> modifier was present on the
538pattern. See below for the definition of non-printing characters. If the
539pattern has the <b>/+</b> modifier, the output for substring 0 is followed by
540the the rest of the subject string, identified by "0+" like this:
541<pre>
542    re&#62; /cat/+
543  data&#62; cataract
544   0: cat
545   0+ aract
546</pre>
547If the pattern has the <b>/g</b> or <b>/G</b> modifier, the results of successive
548matching attempts are output in sequence, like this:
549<pre>
550    re&#62; /\Bi(\w\w)/g
551  data&#62; Mississippi
552   0: iss
553   1: ss
554   0: iss
555   1: ss
556   0: ipp
557   1: pp
558</pre>
559"No match" is output only if the first match attempt fails.
560</P>
561<P>
562If any of the sequences <b>\C</b>, <b>\G</b>, or <b>\L</b> are present in a
563data line that is successfully matched, the substrings extracted by the
564convenience functions are output with C, G, or L after the string number
565instead of a colon. This is in addition to the normal full list. The string
566length (that is, the return from the extraction function) is given in
567parentheses after each string for <b>\C</b> and <b>\G</b>.
568</P>
569<P>
570Note that whereas patterns can be continued over several lines (a plain "&#62;"
571prompt is used for continuations), data lines may not. However newlines can be
572included in data by means of the \n escape (or \r, \r\n, etc., depending on
573the newline sequence setting).
574</P>
575<br><a name="SEC8" href="#TOC1">OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION</a><br>
576<P>
577When the alternative matching function, <b>pcre_dfa_exec()</b>, is used (by
578means of the \D escape sequence or the <b>-dfa</b> command line option), the
579output consists of a list of all the matches that start at the first point in
580the subject where there is at least one match. For example:
581<pre>
582    re&#62; /(tang|tangerine|tan)/
583  data&#62; yellow tangerine\D
584   0: tangerine
585   1: tang
586   2: tan
587</pre>
588(Using the normal matching function on this data finds only "tang".) The
589longest matching string is always given first (and numbered zero). After a
590PCRE_ERROR_PARTIAL return, the output is "Partial match:", followed by the
591partially matching substring. (Note that this is the entire substring that was
592inspected during the partial match; it may include characters before the actual
593match start if a lookbehind assertion, \K, \b, or \B was involved.)
594</P>
595<P>
596If <b>/g</b> is present on the pattern, the search for further matches resumes
597at the end of the longest match. For example:
598<pre>
599    re&#62; /(tang|tangerine|tan)/g
600  data&#62; yellow tangerine and tangy sultana\D
601   0: tangerine
602   1: tang
603   2: tan
604   0: tang
605   1: tan
606   0: tan
607</pre>
608Since the matching function does not support substring capture, the escape
609sequences that are concerned with captured substrings are not relevant.
610</P>
611<br><a name="SEC9" href="#TOC1">RESTARTING AFTER A PARTIAL MATCH</a><br>
612<P>
613When the alternative matching function has given the PCRE_ERROR_PARTIAL return,
614indicating that the subject partially matched the pattern, you can restart the
615match with additional subject data by means of the \R escape sequence. For
616example:
617<pre>
618    re&#62; /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
619  data&#62; 23ja\P\D
620  Partial match: 23ja
621  data&#62; n05\R\D
622   0: n05
623</pre>
624For further information about partial matching, see the
625<a href="pcrepartial.html"><b>pcrepartial</b></a>
626documentation.
627</P>
628<br><a name="SEC10" href="#TOC1">CALLOUTS</a><br>
629<P>
630If the pattern contains any callout requests, <b>pcretest</b>'s callout function
631is called during matching. This works with both matching functions. By default,
632the called function displays the callout number, the start and current
633positions in the text at the callout time, and the next pattern item to be
634tested. For example, the output
635<pre>
636  ---&#62;pqrabcdef
637    0    ^  ^     \d
638</pre>
639indicates that callout number 0 occurred for a match attempt starting at the
640fourth character of the subject string, when the pointer was at the seventh
641character of the data, and when the next pattern item was \d. Just one
642circumflex is output if the start and current positions are the same.
643</P>
644<P>
645Callouts numbered 255 are assumed to be automatic callouts, inserted as a
646result of the <b>/C</b> pattern modifier. In this case, instead of showing the
647callout number, the offset in the pattern, preceded by a plus, is output. For
648example:
649<pre>
650    re&#62; /\d?[A-E]\*/C
651  data&#62; E*
652  ---&#62;E*
653   +0 ^      \d?
654   +3 ^      [A-E]
655   +8 ^^     \*
656  +10 ^ ^
657   0: E*
658</pre>
659The callout function in <b>pcretest</b> returns zero (carry on matching) by
660default, but you can use a \C item in a data line (as described above) to
661change this.
662</P>
663<P>
664Inserting callouts can be helpful when using <b>pcretest</b> to check
665complicated regular expressions. For further information about callouts, see
666the
667<a href="pcrecallout.html"><b>pcrecallout</b></a>
668documentation.
669</P>
670<br><a name="SEC11" href="#TOC1">NON-PRINTING CHARACTERS</a><br>
671<P>
672When <b>pcretest</b> is outputting text in the compiled version of a pattern,
673bytes other than 32-126 are always treated as non-printing characters are are
674therefore shown as hex escapes.
675</P>
676<P>
677When <b>pcretest</b> is outputting text that is a matched part of a subject
678string, it behaves in the same way, unless a different locale has been set for
679the pattern (using the <b>/L</b> modifier). In this case, the <b>isprint()</b>
680function to distinguish printing and non-printing characters.
681</P>
682<br><a name="SEC12" href="#TOC1">SAVING AND RELOADING COMPILED PATTERNS</a><br>
683<P>
684The facilities described in this section are not available when the POSIX
685inteface to PCRE is being used, that is, when the <b>/P</b> pattern modifier is
686specified.
687</P>
688<P>
689When the POSIX interface is not in use, you can cause <b>pcretest</b> to write a
690compiled pattern to a file, by following the modifiers with &#62; and a file name.
691For example:
692<pre>
693  /pattern/im &#62;/some/file
694</pre>
695See the
696<a href="pcreprecompile.html"><b>pcreprecompile</b></a>
697documentation for a discussion about saving and re-using compiled patterns.
698</P>
699<P>
700The data that is written is binary. The first eight bytes are the length of the
701compiled pattern data followed by the length of the optional study data, each
702written as four bytes in big-endian order (most significant byte first). If
703there is no study data (either the pattern was not studied, or studying did not
704return any data), the second length is zero. The lengths are followed by an
705exact copy of the compiled pattern. If there is additional study data, this
706follows immediately after the compiled pattern. After writing the file,
707<b>pcretest</b> expects to read a new pattern.
708</P>
709<P>
710A saved pattern can be reloaded into <b>pcretest</b> by specifing &#60; and a file
711name instead of a pattern. The name of the file must not contain a &#60; character,
712as otherwise <b>pcretest</b> will interpret the line as a pattern delimited by &#60;
713characters.
714For example:
715<pre>
716   re&#62; &#60;/some/file
717  Compiled regex loaded from /some/file
718  No study data
719</pre>
720When the pattern has been loaded, <b>pcretest</b> proceeds to read data lines in
721the usual way.
722</P>
723<P>
724You can copy a file written by <b>pcretest</b> to a different host and reload it
725there, even if the new host has opposite endianness to the one on which the
726pattern was compiled. For example, you can compile on an i86 machine and run on
727a SPARC machine.
728</P>
729<P>
730File names for saving and reloading can be absolute or relative, but note that
731the shell facility of expanding a file name that starts with a tilde (~) is not
732available.
733</P>
734<P>
735The ability to save and reload files in <b>pcretest</b> is intended for testing
736and experimentation. It is not intended for production use because only a
737single pattern can be written to a file. Furthermore, there is no facility for
738supplying custom character tables for use with a reloaded pattern. If the
739original pattern was compiled with custom tables, an attempt to match a subject
740string using a reloaded pattern is likely to cause <b>pcretest</b> to crash.
741Finally, if you attempt to load a file that is not in the correct format, the
742result is undefined.
743</P>
744<br><a name="SEC13" href="#TOC1">SEE ALSO</a><br>
745<P>
746<b>pcre</b>(3), <b>pcreapi</b>(3), <b>pcrecallout</b>(3), <b>pcrematching</b>(3),
747<b>pcrepartial</b>(d), <b>pcrepattern</b>(3), <b>pcreprecompile</b>(3).
748</P>
749<br><a name="SEC14" href="#TOC1">AUTHOR</a><br>
750<P>
751Philip Hazel
752<br>
753University Computing Service
754<br>
755Cambridge CB2 3QH, England.
756<br>
757</P>
758<br><a name="SEC15" href="#TOC1">REVISION</a><br>
759<P>
760Last updated: 21 November 2010
761<br>
762Copyright &copy; 1997-2010 University of Cambridge.
763<br>
764<p>
765Return to the <a href="index.html">PCRE index page</a>.
766</p>
767