/[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 73 by nigel, Sat Feb 24 21:40:30 2007 UTC revision 77 by nigel, Sat Feb 24 21:40:45 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">SAVING AND RELOADING COMPILED PATTERNS</a>
27    <li><a name="TOC12" href="#SEC12">AUTHOR</a>
28  </ul>  </ul>
29  <br><a name="SEC1" href="#TOC1">SYNOPSIS</a><br>  <br><a name="SEC1" href="#TOC1">SYNOPSIS</a><br>
30  <P>  <P>
31  <b>pcretest [-d] [-i] [-m] [-o osize] [-p] [-t] [source] [destination]</b>  <b>pcretest [-C] [-d] [-dfa] [-i] [-m] [-o osize] [-p] [-t] [source]</b>
32    <b>[destination]</b>
33  </P>  </P>
34  <P>  <P>
35  <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
# Line 26  library itself, but it can also be used Line 37  library itself, but it can also be used
37  expressions. This document describes the features of the test program; for  expressions. This document describes the features of the test program; for
38  details of the regular expressions themselves, see the  details of the regular expressions themselves, see the
39  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
40  documentation. For details of PCRE and its options, see the  documentation. For details of the PCRE library function calls and their
41    options, see the
42  <a href="pcreapi.html"><b>pcreapi</b></a>  <a href="pcreapi.html"><b>pcreapi</b></a>
43  documentation.  documentation.
44  </P>  </P>
# Line 38  about the optional features that are inc Line 50  about the optional features that are inc
50  </P>  </P>
51  <P>  <P>
52  <b>-d</b>  <b>-d</b>
53  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
54  form is output after compilation.  form is output after compilation.
55  </P>  </P>
56  <P>  <P>
57    <b>-dfa</b>
58    Behave as if each data line contains the \D escape sequence; this causes the
59    alternative matching function, <b>pcre_dfa_exec()</b>, to be used instead of the
60    standard <b>pcre_exec()</b> function (more detail is given below).
61    </P>
62    <P>
63  <b>-i</b>  <b>-i</b>
64  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
65  compiled pattern is given after compilation.  compiled pattern is given after compilation.
66  </P>  </P>
67  <P>  <P>
68  <b>-m</b>  <b>-m</b>
69  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
70  equivalent to adding /M to each regular expression. For compatibility with  equivalent to adding <b>/M</b> to each regular expression. For compatibility
71  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>.
72  </P>  </P>
73  <P>  <P>
74  <b>-o</b> <i>osize</i>  <b>-o</b> <i>osize</i>
75  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
76  to be <i>osize</i>. The default value is 45, which is enough for 14 capturing  <b>pcre_exec()</b> to be <i>osize</i>. The default value is 45, which is enough
77  subexpressions. The vector size can be changed for individual matching calls by  for 14 capturing subexpressions. The vector size can be changed for individual
78  including \O in the data line (see below).  matching calls by including \O in the data line (see below).
79  </P>  </P>
80  <P>  <P>
81  <b>-p</b>  <b>-p</b>
82  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
83  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
84    set.
85  </P>  </P>
86  <P>  <P>
87  <b>-t</b>  <b>-t</b>
88  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
89  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
90  <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
91  will be distorted.  timing will be distorted.
92  </P>  </P>
93  <br><a name="SEC3" href="#TOC1">DESCRIPTION</a><br>  <br><a name="SEC3" href="#TOC1">DESCRIPTION</a><br>
94  <P>  <P>
# Line 85  set starts with a regular expression, an Line 104  set starts with a regular expression, an
104  lines to be matched against the pattern.  lines to be matched against the pattern.
105  </P>  </P>
106  <P>  <P>
107  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
108  multiple-line matches, you have to use the \n escape sequence in a single line  multiple-line matches, you have to use the \n escape sequence in a single line
109  of input to encode the newline characters. The maximum length of data line is  of input to encode the newline characters. The maximum length of data line is
110  30,000 characters.  30,000 characters.
# Line 93  of input to encode the newline character Line 112  of input to encode the newline character
112  <P>  <P>
113  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
114  expression is read. The regular expressions are given enclosed in any  expression is read. The regular expressions are given enclosed in any
115  non-alphameric delimiters other than backslash, for example  non-alphanumeric delimiters other than backslash, for example
 </P>  
 <P>  
116  <pre>  <pre>
117    /(a|bc)x+yz/    /(a|bc)x+yz/
118  </PRE>  </pre>
 </P>  
 <P>  
119  White space before the initial delimiter is ignored. A regular expression may  White space before the initial delimiter is ignored. A regular expression may
120  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
121  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
122  by escaping it, for example  by escaping it, for example
 </P>  
 <P>  
123  <pre>  <pre>
124    /abc\/def/    /abc\/def/
125  </PRE>  </pre>
 </P>  
 <P>  
126  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
127  delimiters are always non-alphameric, this does not affect its interpretation.  delimiters are always non-alphanumeric, this does not affect its interpretation.
128  If the terminating delimiter is immediately followed by a backslash, for  If the terminating delimiter is immediately followed by a backslash, for
129  example,  example,
 </P>  
 <P>  
130  <pre>  <pre>
131    /abc/\    /abc/\
132  </PRE>  </pre>
 </P>  
 <P>  
133  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
134  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
135  backslash, because  backslash, because
 </P>  
 <P>  
136  <pre>  <pre>
137    /abc\/    /abc\/
138  </PRE>  </pre>
 </P>  
 <P>  
139  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
140  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.
141  </P>  </P>
142  <br><a name="SEC4" href="#TOC1">PATTERN MODIFIERS</a><br>  <br><a name="SEC4" href="#TOC1">PATTERN MODIFIERS</a><br>
143  <P>  <P>
144  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
145  PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, or PCRE_EXTENDED options,  characters. Following Perl usage, these are referred to below as, for example,
146  respectively. For example:  "the <b>/i</b> modifier", even though the delimiter of the pattern need not
147    always be a slash, and no slash is used when writing modifiers. Whitespace may
148    appear between the final pattern delimiter and the first modifier, and between
149    the modifiers themselves.
150  </P>  </P>
151  <P>  <P>
152    The <b>/i</b>, <b>/m</b>, <b>/s</b>, and <b>/x</b> modifiers set the PCRE_CASELESS,
153    PCRE_MULTILINE, PCRE_DOTALL, or PCRE_EXTENDED options, respectively, when
154    <b>pcre_compile()</b> is called. These four modifier letters have the same
155    effect as they do in Perl. For example:
156  <pre>  <pre>
157    /caseless/i    /caseless/i
158  </PRE>  </pre>
159  </P>  The following table shows additional modifiers for setting PCRE options that do
160  <P>  not correspond to anything in Perl:
161  These modifier letters have the same effect as they do in Perl. There are  <pre>
162  others that set PCRE options that do not correspond to anything in Perl:    <b>/A</b>    PCRE_ANCHORED
163  <b>/A</b>, <b>/E</b>, <b>/N</b>, <b>/U</b>, and <b>/X</b> set PCRE_ANCHORED,    <b>/C</b>    PCRE_AUTO_CALLOUT
164  PCRE_DOLLAR_ENDONLY, PCRE_NO_AUTO_CAPTURE, PCRE_UNGREEDY, and PCRE_EXTRA    <b>/E</b>    PCRE_DOLLAR_ENDONLY
165  respectively.    <b>/f</b>    PCRE_FIRSTLINE
166  </P>    <b>/N</b>    PCRE_NO_AUTO_CAPTURE
167  <P>    <b>/U</b>    PCRE_UNGREEDY
168      <b>/X</b>    PCRE_EXTRA
169    </pre>
170  Searching for all possible matches within each subject string can be requested  Searching for all possible matches within each subject string can be requested
171  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
172  again to search the remainder of the subject string. The difference between  again to search the remainder of the subject string. The difference between
# Line 173  match is retried. This imitates the way Line 185  match is retried. This imitates the way
185  <b>/g</b> modifier or the <b>split()</b> function.  <b>/g</b> modifier or the <b>split()</b> function.
186  </P>  </P>
187  <P>  <P>
188  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>
189  operates.  operates.
190  </P>  </P>
191  <P>  <P>
# Line 185  multiple copies of the same substring. Line 197  multiple copies of the same substring.
197  <P>  <P>
198  The <b>/L</b> modifier must be followed directly by the name of a locale, for  The <b>/L</b> modifier must be followed directly by the name of a locale, for
199  example,  example,
 </P>  
 <P>  
200  <pre>  <pre>
201    /pattern/Lfr    /pattern/Lfr_FR
202  </PRE>  </pre>
203  </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,  
204  <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
205  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
206  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 200  pointer; that is, <b>/L</b> applies only Line 208  pointer; that is, <b>/L</b> applies only
208  </P>  </P>
209  <P>  <P>
210  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
211  compiled expression (whether it is anchored, has a fixed first character, and  compiled pattern (whether it is anchored, has a fixed first character, and
212  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
213  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.
 studied, the results of that are also output.  
214  </P>  </P>
215  <P>  <P>
216  The <b>/D</b> modifier is a PCRE debugging feature, which also assumes <b>/I</b>.  The <b>/D</b> modifier is a PCRE debugging feature, which also assumes <b>/I</b>.
# Line 212  compilation. If the pattern was studied, Line 219  compilation. If the pattern was studied,
219  output.  output.
220  </P>  </P>
221  <P>  <P>
222    The <b>/F</b> modifier causes <b>pcretest</b> to flip the byte order of the
223    fields in the compiled pattern that contain 2-byte and 4-byte numbers. This
224    facility is for testing the feature in PCRE that allows it to execute patterns
225    that were compiled on a host with a different endianness. This feature is not
226    available when the POSIX interface to PCRE is being used, that is, when the
227    <b>/P</b> pattern modifier is specified. See also the section about saving and
228    reloading compiled patterns below.
229    </P>
230    <P>
231  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
232  expression has been compiled, and the results used when the expression is  expression has been compiled, and the results used when the expression is
233  matched.  matched.
# Line 239  If the <b>/?</b> modifier is used with < Line 255  If the <b>/?</b> modifier is used with <
255  call <b>pcre_compile()</b> with the PCRE_NO_UTF8_CHECK option, to suppress the  call <b>pcre_compile()</b> with the PCRE_NO_UTF8_CHECK option, to suppress the
256  checking of the string for UTF-8 validity.  checking of the string for UTF-8 validity.
257  </P>  </P>
258  <br><a name="SEC5" href="#TOC1">CALLOUTS</a><br>  <br><a name="SEC5" href="#TOC1">DATA LINES</a><br>
 <P>  
 If the pattern contains any callout requests, <b>pcretest</b>'s callout function  
 will be called. By default, it displays the callout number, and the start and  
 current positions in the text at the callout time. For example, the output  
 </P>  
 <P>  
 <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>  
259  <P>  <P>
260  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
261  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 278  pretty esoteric features, intended for c Line 263  pretty esoteric features, intended for c
263  complicated features of PCRE. If you are just testing "ordinary" regular  complicated features of PCRE. If you are just testing "ordinary" regular
264  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
265  recognized:  recognized:
 </P>  
 <P>  
266  <pre>  <pre>
267    \a         alarm (= BEL)    \a         alarm (= BEL)
268    \b         backspace    \b         backspace
# Line 291  recognized: Line 274  recognized:
274    \v         vertical tab    \v         vertical tab
275    \nnn       octal character (up to 3 octal digits)    \nnn       octal character (up to 3 octal digits)
276    \xhh       hexadecimal character (up to 2 hex digits)    \xhh       hexadecimal character (up to 2 hex digits)
277    \x{hh...}  hexadecimal character, any number of digits    \x{hh...}  hexadecimal character, any number of digits in UTF-8 mode
                in UTF-8 mode  
278    \A         pass the PCRE_ANCHORED option to <b>pcre_exec()</b>    \A         pass the PCRE_ANCHORED option to <b>pcre_exec()</b>
279    \B         pass the PCRE_NOTBOL option to <b>pcre_exec()</b>    \B         pass the PCRE_NOTBOL option to <b>pcre_exec()</b>
280    \Cdd       call pcre_copy_substring() for substring dd    \Cdd       call pcre_copy_substring() for substring dd after a successful match (number less than 32)
281                 after a successful match (any decimal number    \Cname     call pcre_copy_named_substring() for substring "name" after a successful match (name termin-
                less than 32)  
   \Cname     call pcre_copy_named_substring() for substring  
                "name" after a successful match (name termin-  
282                 ated by next non alphanumeric character)                 ated by next non alphanumeric character)
283    \C+        show the current captured substrings at callout    \C+        show the current captured substrings at callout time
                time  
284    \C-        do not supply a callout function    \C-        do not supply a callout function
285    \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
286                 reached    \C!n!m     return 1 instead of 0 when callout number n is reached for the nth time
287    \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
288                 reached for the nth time    \D         use the <b>pcre_dfa_exec()</b> match function
289    \C*n       pass the number n (may be negative) as callout    \F         only shortest match for <b>pcre_dfa_exec()</b>
290                 data    \Gdd       call pcre_get_substring() for substring dd after a successful match (number less than 32)
291    \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-  
292                 ated by next non-alphanumeric character)                 ated by next non-alphanumeric character)
293    \L         call pcre_get_substringlist() after a    \L         call pcre_get_substringlist() after a successful match
                successful match  
294    \M         discover the minimum MATCH_LIMIT setting    \M         discover the minimum MATCH_LIMIT setting
295    \N         pass the PCRE_NOTEMPTY option to <b>pcre_exec()</b>    \N         pass the PCRE_NOTEMPTY option to <b>pcre_exec()</b>
296    \Odd       set the size of the output vector passed to    \Odd       set the size of the output vector passed to <b>pcre_exec()</b> to dd (any number of digits)
297                 <b>pcre_exec()</b> to dd (any number of decimal    \P         pass the PCRE_PARTIAL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
298                 digits)    \R         pass the PCRE_DFA_RESTART option to <b>pcre_dfa_exec()</b>
299    \S         output details of memory get/free calls during matching    \S         output details of memory get/free calls during matching
300    \Z         pass the PCRE_NOTEOL option to <b>pcre_exec()</b>    \Z         pass the PCRE_NOTEOL option to <b>pcre_exec()</b>
301    \?         pass the PCRE_NO_UTF8_CHECK option to    \?         pass the PCRE_NO_UTF8_CHECK option to <b>pcre_exec()</b>
302                 <b>pcre_exec()</b>    \&#62;dd       start the match at offset dd (any number of digits);
303  </PRE>                 this sets the <i>startoffset</i> argument for <b>pcre_exec()</b>
304    </pre>
305    A backslash followed by anything else just escapes the anything else. If the
306    very last character is a backslash, it is ignored. This gives a way of passing
307    an empty line as data, since a real empty line terminates the data input.
308  </P>  </P>
309  <P>  <P>
310  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
# Line 340  patterns with very large numbers of matc Line 317  patterns with very large numbers of matc
317  very quickly with increasing length of subject string.  very quickly with increasing length of subject string.
318  </P>  </P>
319  <P>  <P>
320  When \O is used, it may be higher or lower than the size set by the <b>-O</b>  When \O is used, the value specified may be higher or lower than the size set
321  option (or defaulted to 45); \O applies only to the call of <b>pcre_exec()</b>  by the <b>-O</b> command line option (or defaulted to 45); \O applies only to
322  for the line in which it appears.  the call of <b>pcre_exec()</b> for the line in which it appears.
 </P>  
 <P>  
 A backslash followed by anything else just escapes the anything else. If the  
 very last character is a backslash, it is ignored. This gives a way of passing  
 an empty line as data, since a real empty line terminates the data input.  
323  </P>  </P>
324  <P>  <P>
325  If <b>/P</b> was present on the regex, causing the POSIX wrapper API to be used,  If the <b>/P</b> modifier was present on the pattern, causing the POSIX wrapper
326  only <b>\B</b>, and <b>\Z</b> have any effect, causing REG_NOTBOL and REG_NOTEOL  API to be used, only \B and \Z have any effect, causing REG_NOTBOL and
327  to be passed to <b>regexec()</b> respectively.  REG_NOTEOL to be passed to <b>regexec()</b> respectively.
328  </P>  </P>
329  <P>  <P>
330  The use of \x{hh...} to represent UTF-8 characters is not dependent on the use  The use of \x{hh...} to represent UTF-8 characters is not dependent on the use
# Line 360  of the <b>/8</b> modifier on the pattern Line 332  of the <b>/8</b> modifier on the pattern
332  any number of hexadecimal digits inside the braces. The result is from one to  any number of hexadecimal digits inside the braces. The result is from one to
333  six bytes, encoded according to the UTF-8 rules.  six bytes, encoded according to the UTF-8 rules.
334  </P>  </P>
335  <br><a name="SEC7" href="#TOC1">OUTPUT FROM PCRETEST</a><br>  <br><a name="SEC6" href="#TOC1">THE ALTERNATIVE MATCHING FUNCTION</a><br>
336  <P>  <P>
337  When a match succeeds, pcretest outputs the list of captured substrings that  By default, <b>pcretest</b> uses the standard PCRE matching function,
338  <b>pcre_exec()</b> returns, starting with number 0 for the string that matched  <b>pcre_exec()</b> to match each data line. From release 6.0, PCRE supports an
339  the whole pattern. Here is an example of an interactive pcretest run.  alternative matching function, <b>pcre_dfa_test()</b>, which operates in a
340    different way, and has some restrictions. The differences between the two
341    functions are described in the
342    <a href="pcrematching.html"><b>pcrematching</b></a>
343    documentation.
344  </P>  </P>
345  <P>  <P>
346  <pre>  If a data line contains the \D escape sequence, or if the command line
347    $ pcretest  contains the <b>-dfa</b> option, the alternative matching function is called.
348    PCRE version 4.00 08-Jan-2003  This function finds all possible matches at a given point. If, however, the \F
349  </PRE>  escape sequence is present in the data line, it stops after the first match is
350    found. This is always the shortest possible match.
351  </P>  </P>
352    <br><a name="SEC7" href="#TOC1">DEFAULT OUTPUT FROM PCRETEST</a><br>
353  <P>  <P>
354    This section describes the output when the normal matching function,
355    <b>pcre_exec()</b>, is being used.
356    </P>
357    <P>
358    When a match succeeds, pcretest outputs the list of captured substrings that
359    <b>pcre_exec()</b> returns, starting with number 0 for the string that matched
360    the whole pattern. Otherwise, it outputs "No match" or "Partial match"
361    when <b>pcre_exec()</b> returns PCRE_ERROR_NOMATCH or PCRE_ERROR_PARTIAL,
362    respectively, and otherwise the PCRE negative error number. Here is an example
363    of an interactive <b>pcretest</b> run.
364  <pre>  <pre>
365      $ pcretest
366      PCRE version 5.00 07-Sep-2004
367    
368      re&#62; /^abc(\d+)/      re&#62; /^abc(\d+)/
369    data&#62; abc123    data&#62; abc123
370     0: abc123     0: abc123
371     1: 123     1: 123
372    data&#62; xyz    data&#62; xyz
373    No match    No match
374  </PRE>  </pre>
 </P>  
 <P>  
375  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
376  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
377  pattern. If the pattern has the <b>/+</b> modifier, then the output for  pattern. If the pattern has the <b>/+</b> modifier, the output for substring 0
378  substring 0 is followed by the the rest of the subject string, identified by  is followed by the the rest of the subject string, identified by "0+" like
379  "0+" like this:  this:
 </P>  
 <P>  
380  <pre>  <pre>
381      re&#62; /cat/+      re&#62; /cat/+
382    data&#62; cataract    data&#62; cataract
383     0: cat     0: cat
384     0+ aract     0+ aract
385  </PRE>  </pre>
 </P>  
 <P>  
386  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
387  matching attempts are output in sequence, like this:  matching attempts are output in sequence, like this:
 </P>  
 <P>  
388  <pre>  <pre>
389      re&#62; /\Bi(\w\w)/g      re&#62; /\Bi(\w\w)/g
390    data&#62; Mississippi    data&#62; Mississippi
# Line 411  matching attempts are output in sequence Line 394  matching attempts are output in sequence
394     1: ss     1: ss
395     0: ipp     0: ipp
396     1: pp     1: pp
397  </PRE>  </pre>
 </P>  
 <P>  
398  "No match" is output only if the first match attempt fails.  "No match" is output only if the first match attempt fails.
399  </P>  </P>
400  <P>  <P>
# Line 429  Note that while patterns can be continue Line 410  Note that while patterns can be continue
410  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
411  included in data by means of the \n escape.  included in data by means of the \n escape.
412  </P>  </P>
413  <br><a name="SEC8" href="#TOC1">AUTHOR</a><br>  <br><a name="SEC8" href="#TOC1">OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION</a><br>
414    <P>
415    When the alternative matching function, <b>pcre_dfa_exec()</b>, is used (by
416    means of the \D escape sequence or the <b>-dfa</b> command line option), the
417    output consists of a list of all the matches that start at the first point in
418    the subject where there is at least one match. For example:
419    <pre>
420        re&#62; /(tang|tangerine|tan)/
421      data&#62; yellow tangerine\D
422       0: tangerine
423       1: tang
424       2: tan
425    </pre>
426    (Using the normal matching function on this data finds only "tang".) The
427    longest matching string is always given first (and numbered zero).
428    </P>
429    <P>
430    If \fB/g\P is present on the pattern, the search for further matches resumes
431    at the end of the longest match. For example:
432    <pre>
433        re&#62; /(tang|tangerine|tan)/g
434      data&#62; yellow tangerine and tangy sultana\D
435       0: tangerine
436       1: tang
437       2: tan
438       0: tang
439       1: tan
440       0: tan
441    </pre>
442    Since the matching function does not support substring capture, the escape
443    sequences that are concerned with captured substrings are not relevant.
444    </P>
445    <br><a name="SEC9" href="#TOC1">RESTARTING AFTER A PARTIAL MATCH</a><br>
446    <P>
447    When the alternative matching function has given the PCRE_ERROR_PARTIAL return,
448    indicating that the subject partially matched the pattern, you can restart the
449    match with additional subject data by means of the \R escape sequence. For
450    example:
451    <pre>
452        re&#62; /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
453      data&#62; 23ja\P\D
454      Partial match: 23ja
455      data&#62; n05\R\D
456       0: n05
457    </pre>
458    For further information about partial matching, see the
459    <a href="pcrepartial.html"><b>pcrepartial</b></a>
460    documentation.
461    </P>
462    <br><a name="SEC10" href="#TOC1">CALLOUTS</a><br>
463    <P>
464    If the pattern contains any callout requests, <b>pcretest</b>'s callout function
465    is called during matching. This works with both matching functions. By default,
466    the called function displays the callout number, the start and current
467    positions in the text at the callout time, and the next pattern item to be
468    tested. For example, the output
469    <pre>
470      ---&#62;pqrabcdef
471        0    ^  ^     \d
472    </pre>
473    indicates that callout number 0 occurred for a match attempt starting at the
474    fourth character of the subject string, when the pointer was at the seventh
475    character of the data, and when the next pattern item was \d. Just one
476    circumflex is output if the start and current positions are the same.
477    </P>
478    <P>
479    Callouts numbered 255 are assumed to be automatic callouts, inserted as a
480    result of the <b>/C</b> pattern modifier. In this case, instead of showing the
481    callout number, the offset in the pattern, preceded by a plus, is output. For
482    example:
483    <pre>
484        re&#62; /\d?[A-E]\*/C
485      data&#62; E*
486      ---&#62;E*
487       +0 ^      \d?
488       +3 ^      [A-E]
489       +8 ^^     \*
490      +10 ^ ^
491       0: E*
492    </pre>
493    The callout function in <b>pcretest</b> returns zero (carry on matching) by
494    default, but you can use a \C item in a data line (as described above) to
495    change this.
496    </P>
497    <P>
498    Inserting callouts can be helpful when using <b>pcretest</b> to check
499    complicated regular expressions. For further information about callouts, see
500    the
501    <a href="pcrecallout.html"><b>pcrecallout</b></a>
502    documentation.
503    </P>
504    <br><a name="SEC11" href="#TOC1">SAVING AND RELOADING COMPILED PATTERNS</a><br>
505    <P>
506    The facilities described in this section are not available when the POSIX
507    inteface to PCRE is being used, that is, when the <b>/P</b> pattern modifier is
508    specified.
509    </P>
510    <P>
511    When the POSIX interface is not in use, you can cause <b>pcretest</b> to write a
512    compiled pattern to a file, by following the modifiers with &#62; and a file name.
513    For example:
514    <pre>
515      /pattern/im &#62;/some/file
516    </pre>
517    See the
518    <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
519    documentation for a discussion about saving and re-using compiled patterns.
520    </P>
521    <P>
522    The data that is written is binary. The first eight bytes are the length of the
523    compiled pattern data followed by the length of the optional study data, each
524    written as four bytes in big-endian order (most significant byte first). If
525    there is no study data (either the pattern was not studied, or studying did not
526    return any data), the second length is zero. The lengths are followed by an
527    exact copy of the compiled pattern. If there is additional study data, this
528    follows immediately after the compiled pattern. After writing the file,
529    <b>pcretest</b> expects to read a new pattern.
530    </P>
531    <P>
532    A saved pattern can be reloaded into <b>pcretest</b> by specifing &#60; and a file
533    name instead of a pattern. The name of the file must not contain a &#60; character,
534    as otherwise <b>pcretest</b> will interpret the line as a pattern delimited by &#60;
535    characters.
536    For example:
537    <pre>
538       re&#62; &#60;/some/file
539      Compiled regex loaded from /some/file
540      No study data
541    </pre>
542    When the pattern has been loaded, <b>pcretest</b> proceeds to read data lines in
543    the usual way.
544    </P>
545    <P>
546    You can copy a file written by <b>pcretest</b> to a different host and reload it
547    there, even if the new host has opposite endianness to the one on which the
548    pattern was compiled. For example, you can compile on an i86 machine and run on
549    a SPARC machine.
550    </P>
551    <P>
552    File names for saving and reloading can be absolute or relative, but note that
553    the shell facility of expanding a file name that starts with a tilde (~) is not
554    available.
555    </P>
556    <P>
557    The ability to save and reload files in <b>pcretest</b> is intended for testing
558    and experimentation. It is not intended for production use because only a
559    single pattern can be written to a file. Furthermore, there is no facility for
560    supplying custom character tables for use with a reloaded pattern. If the
561    original pattern was compiled with custom tables, an attempt to match a subject
562    string using a reloaded pattern is likely to cause <b>pcretest</b> to crash.
563    Finally, if you attempt to load a file that is not in the correct format, the
564    result is undefined.
565    </P>
566    <br><a name="SEC12" href="#TOC1">AUTHOR</a><br>
567  <P>  <P>
568  Philip Hazel &#60;ph10@cam.ac.uk&#62;  Philip Hazel
569  <br>  <br>
570  University Computing Service,  University Computing Service,
571  <br>  <br>
572  Cambridge CB2 3QG, England.  Cambridge CB2 3QG, England.
573  </P>  </P>
574  <P>  <P>
575  Last updated: 09 December 2003  Last updated: 28 February 2005
576  <br>  <br>
577  Copyright &copy; 1997-2003 University of Cambridge.  Copyright &copy; 1997-2005 University of Cambridge.
578    <p>
579    Return to the <a href="index.html">PCRE index page</a>.
580    </p>

Legend:
Removed from v.73  
changed lines
  Added in v.77

  ViewVC Help
Powered by ViewVC 1.1.5