/[pcre]/code/trunk/doc/html/pcretest.html
ViewVC logotype

Diff of /code/trunk/doc/html/pcretest.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.63  
changed lines
  Added in v.155

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12