/[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 75 by nigel, Sat Feb 24 21:40:37 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">OUTPUT FROM PCRETEST</a>
22  <li><a name="TOC7" href="#SEC7">OUTPUT FROM PCRETEST</a>  <li><a name="TOC7" href="#SEC7">CALLOUTS</a>
23  <li><a name="TOC8" href="#SEC8">AUTHOR</a>  <li><a name="TOC8" href="#SEC8">SAVING AND RELOADING COMPILED PATTERNS</a>
24    <li><a name="TOC9" href="#SEC9">AUTHOR</a>
25  </ul>  </ul>
26  <br><a name="SEC1" href="#TOC1">SYNOPSIS</a><br>  <br><a name="SEC1" href="#TOC1">SYNOPSIS</a><br>
27  <P>  <P>
28  <b>pcretest [-d] [-i] [-m] [-o osize] [-p] [-t] [source] [destination]</b>  <b>pcretest [-C] [-d] [-i] [-m] [-o osize] [-p] [-t] [source]</b>
29    <b>[destination]</b>
30  </P>  </P>
31  <P>  <P>
32  <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 34  library itself, but it can also be used
34  expressions. This document describes the features of the test program; for  expressions. This document describes the features of the test program; for
35  details of the regular expressions themselves, see the  details of the regular expressions themselves, see the
36  <a href="pcrepattern.html"><b>pcrepattern</b></a>  <a href="pcrepattern.html"><b>pcrepattern</b></a>
37  documentation. For details of PCRE and its options, see the  documentation. For details of the PCRE library function calls and their
38    options, see the
39  <a href="pcreapi.html"><b>pcreapi</b></a>  <a href="pcreapi.html"><b>pcreapi</b></a>
40  documentation.  documentation.
41  </P>  </P>
# Line 38  about the optional features that are inc Line 47  about the optional features that are inc
47  </P>  </P>
48  <P>  <P>
49  <b>-d</b>  <b>-d</b>
50  Behave as if each regex had the <b>/D</b> modifier (see below); the internal  Behave as if each regex had the <b>/D</b> (debug) modifier; the internal
51  form is output after compilation.  form is output after compilation.
52  </P>  </P>
53  <P>  <P>
# Line 49  compiled pattern is given after compilat Line 58  compiled pattern is given after compilat
58  <P>  <P>
59  <b>-m</b>  <b>-m</b>
60  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
61  equivalent to adding /M to each regular expression. For compatibility with  equivalent to adding <b>/M</b> to each regular expression. For compatibility
62  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>.
63  </P>  </P>
64  <P>  <P>
65  <b>-o</b> <i>osize</i>  <b>-o</b> <i>osize</i>
66  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
67  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
68  subexpressions. The vector size can be changed for individual matching calls by  for 14 capturing subexpressions. The vector size can be changed for individual
69  including \O in the data line (see below).  matching calls by including \O in the data line (see below).
70  </P>  </P>
71  <P>  <P>
72  <b>-p</b>  <b>-p</b>
# Line 67  to call PCRE. None of the other options Line 76  to call PCRE. None of the other options
76  <P>  <P>
77  <b>-t</b>  <b>-t</b>
78  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
79  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
80  <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
81  will be distorted.  timing will be distorted.
82  </P>  </P>
83  <br><a name="SEC3" href="#TOC1">DESCRIPTION</a><br>  <br><a name="SEC3" href="#TOC1">DESCRIPTION</a><br>
84  <P>  <P>
# Line 85  set starts with a regular expression, an Line 94  set starts with a regular expression, an
94  lines to be matched against the pattern.  lines to be matched against the pattern.
95  </P>  </P>
96  <P>  <P>
97  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
98  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
99  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
100  30,000 characters.  30,000 characters.
# Line 93  of input to encode the newline character Line 102  of input to encode the newline character
102  <P>  <P>
103  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
104  expression is read. The regular expressions are given enclosed in any  expression is read. The regular expressions are given enclosed in any
105  non-alphameric delimiters other than backslash, for example  non-alphanumeric delimiters other than backslash, for example
 </P>  
 <P>  
106  <pre>  <pre>
107    /(a|bc)x+yz/    /(a|bc)x+yz/
108  </PRE>  </pre>
 </P>  
 <P>  
109  White space before the initial delimiter is ignored. A regular expression may  White space before the initial delimiter is ignored. A regular expression may
110  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
111  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
112  by escaping it, for example  by escaping it, for example
 </P>  
 <P>  
113  <pre>  <pre>
114    /abc\/def/    /abc\/def/
115  </PRE>  </pre>
 </P>  
 <P>  
116  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
117  delimiters are always non-alphameric, this does not affect its interpretation.  delimiters are always non-alphanumeric, this does not affect its interpretation.
118  If the terminating delimiter is immediately followed by a backslash, for  If the terminating delimiter is immediately followed by a backslash, for
119  example,  example,
 </P>  
 <P>  
120  <pre>  <pre>
121    /abc/\    /abc/\
122  </PRE>  </pre>
 </P>  
 <P>  
123  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
124  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
125  backslash, because  backslash, because
 </P>  
 <P>  
126  <pre>  <pre>
127    /abc\/    /abc\/
128  </PRE>  </pre>
 </P>  
 <P>  
129  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
130  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.
131  </P>  </P>
132  <br><a name="SEC4" href="#TOC1">PATTERN MODIFIERS</a><br>  <br><a name="SEC4" href="#TOC1">PATTERN MODIFIERS</a><br>
133  <P>  <P>
134  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
135  PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, or PCRE_EXTENDED options,  characters. Following Perl usage, these are referred to below as, for example,
136  respectively. For example:  "the <b>/i</b> modifier", even though the delimiter of the pattern need not
137    always be a slash, and no slash is used when writing modifiers. Whitespace may
138    appear between the final pattern delimiter and the first modifier, and between
139    the modifiers themselves.
140  </P>  </P>
141  <P>  <P>
142    The <b>/i</b>, <b>/m</b>, <b>/s</b>, and <b>/x</b> modifiers set the PCRE_CASELESS,
143    PCRE_MULTILINE, PCRE_DOTALL, or PCRE_EXTENDED options, respectively, when
144    <b>pcre_compile()</b> is called. These four modifier letters have the same
145    effect as they do in Perl. For example:
146  <pre>  <pre>
147    /caseless/i    /caseless/i
148  </PRE>  </pre>
149  </P>  The following table shows additional modifiers for setting PCRE options that do
150  <P>  not correspond to anything in Perl:
151  These modifier letters have the same effect as they do in Perl. There are  <pre>
152  others that set PCRE options that do not correspond to anything in Perl:    <b>/A</b>    PCRE_ANCHORED
153  <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
154  PCRE_DOLLAR_ENDONLY, PCRE_NO_AUTO_CAPTURE, PCRE_UNGREEDY, and PCRE_EXTRA    <b>/E</b>    PCRE_DOLLAR_ENDONLY
155  respectively.    <b>/N</b>    PCRE_NO_AUTO_CAPTURE
156  </P>    <b>/U</b>    PCRE_UNGREEDY
157  <P>    <b>/X</b>    PCRE_EXTRA
158    </pre>
159  Searching for all possible matches within each subject string can be requested  Searching for all possible matches within each subject string can be requested
160  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
161  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 174  match is retried. This imitates the way
174  <b>/g</b> modifier or the <b>split()</b> function.  <b>/g</b> modifier or the <b>split()</b> function.
175  </P>  </P>
176  <P>  <P>
177  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>
178  operates.  operates.
179  </P>  </P>
180  <P>  <P>
# Line 185  multiple copies of the same substring. Line 186  multiple copies of the same substring.
186  <P>  <P>
187  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
188  example,  example,
 </P>  
 <P>  
189  <pre>  <pre>
190    /pattern/Lfr    /pattern/Lfr_FR
191  </PRE>  </pre>
192  </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,  
193  <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
194  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
195  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, /L applies only Line 197  pointer; that is, /L applies only
197  </P>  </P>
198  <P>  <P>
199  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
200  compiled expression (whether it is anchored, has a fixed first character, and  compiled pattern (whether it is anchored, has a fixed first character, and
201  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
202  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.  
203  </P>  </P>
204  <P>  <P>
205  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 208  compilation. If the pattern was studied,
208  output.  output.
209  </P>  </P>
210  <P>  <P>
211    The <b>/F</b> modifier causes <b>pcretest</b> to flip the byte order of the
212    fields in the compiled pattern that contain 2-byte and 4-byte numbers. This
213    facility is for testing the feature in PCRE that allows it to execute patterns
214    that were compiled on a host with a different endianness. This feature is not
215    available when the POSIX interface to PCRE is being used, that is, when the
216    <b>/P</b> pattern modifier is specified. See also the section about saving and
217    reloading compiled patterns below.
218    </P>
219    <P>
220  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
221  expression has been compiled, and the results used when the expression is  expression has been compiled, and the results used when the expression is
222  matched.  matched.
# Line 239  If the /? modifier is used with < Line 244  If the /? modifier is used with <
244  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
245  checking of the string for UTF-8 validity.  checking of the string for UTF-8 validity.
246  </P>  </P>
247  <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>  
248  <P>  <P>
249  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
250  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 252  pretty esoteric features, intended for c
252  complicated features of PCRE. If you are just testing "ordinary" regular  complicated features of PCRE. If you are just testing "ordinary" regular
253  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
254  recognized:  recognized:
 </P>  
 <P>  
255  <pre>  <pre>
256    \a         alarm (= BEL)    \a         alarm (= BEL)
257    \b         backspace    \b         backspace
# Line 291  recognized: Line 263  recognized:
263    \v         vertical tab    \v         vertical tab
264    \nnn       octal character (up to 3 octal digits)    \nnn       octal character (up to 3 octal digits)
265    \xhh       hexadecimal character (up to 2 hex digits)    \xhh       hexadecimal character (up to 2 hex digits)
266    \x{hh...}  hexadecimal character, any number of digits    \x{hh...}  hexadecimal character, any number of digits in UTF-8 mode
                in UTF-8 mode  
267    \A         pass the PCRE_ANCHORED option to <b>pcre_exec()</b>    \A         pass the PCRE_ANCHORED option to <b>pcre_exec()</b>
268    \B         pass the PCRE_NOTBOL option to <b>pcre_exec()</b>    \B         pass the PCRE_NOTBOL option to <b>pcre_exec()</b>
269    \Cdd       call pcre_copy_substring() for substring dd    \Cdd       call pcre_copy_substring() for substring dd after a successful match (number less than 32)
270                 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-  
271                 ated by next non alphanumeric character)                 ated by next non alphanumeric character)
272    \C+        show the current captured substrings at callout    \C+        show the current captured substrings at callout time
                time  
273    \C-        do not supply a callout function    \C-        do not supply a callout function
274    \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
275                 reached    \C!n!m     return 1 instead of 0 when callout number n is reached for the nth time
276    \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
277                 reached for the nth time    \Gdd       call pcre_get_substring() for substring dd after a successful match (number less than 32)
278    \C*n       pass the number n (may be negative) as callout    \Gname     call pcre_get_named_substring() for substring "name" after a successful match (name termin-
                data  
   \Gdd       call pcre_get_substring() for substring dd  
                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-  
279                 ated by next non-alphanumeric character)                 ated by next non-alphanumeric character)
280    \L         call pcre_get_substringlist() after a    \L         call pcre_get_substringlist() after a successful match
                successful match  
281    \M         discover the minimum MATCH_LIMIT setting    \M         discover the minimum MATCH_LIMIT setting
282    \N         pass the PCRE_NOTEMPTY option to <b>pcre_exec()</b>    \N         pass the PCRE_NOTEMPTY option to <b>pcre_exec()</b>
283    \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)
284                 <b>pcre_exec()</b> to dd (any number of decimal    \P         pass the PCRE_PARTIAL option to <b>pcre_exec()</b>
                digits)  
285    \S         output details of memory get/free calls during matching    \S         output details of memory get/free calls during matching
286    \Z         pass the PCRE_NOTEOL option to <b>pcre_exec()</b>    \Z         pass the PCRE_NOTEOL option to <b>pcre_exec()</b>
287    \?         pass the PCRE_NO_UTF8_CHECK option to    \?         pass the PCRE_NO_UTF8_CHECK option to <b>pcre_exec()</b>
288                 <b>pcre_exec()</b>    \&#62;dd       start the match at offset dd (any number of digits);
289  </PRE>                 this sets the <i>startoffset</i> argument for <b>pcre_exec()</b>
290    </pre>
291    A backslash followed by anything else just escapes the anything else. If the
292    very last character is a backslash, it is ignored. This gives a way of passing
293    an empty line as data, since a real empty line terminates the data input.
294  </P>  </P>
295  <P>  <P>
296  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 303  patterns with very large numbers of matc
303  very quickly with increasing length of subject string.  very quickly with increasing length of subject string.
304  </P>  </P>
305  <P>  <P>
306  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
307  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
308  for the line in which it appears.  the call of <b>pcre_exec()</b> for the line in which it appears.
309  </P>  </P>
310  <P>  <P>
311  A backslash followed by anything else just escapes the anything else. If the  If the <b>/P</b> modifier was present on the pattern, causing the POSIX wrapper
312  very last character is a backslash, it is ignored. This gives a way of passing  API to be used, only \B and \Z have any effect, causing REG_NOTBOL and
313  an empty line as data, since a real empty line terminates the data input.  REG_NOTEOL to be passed to <b>regexec()</b> respectively.
 </P>  
 <P>  
 If <b>/P</b> was present on the regex, causing the POSIX wrapper API to be used,  
 only <b>\B</b>, and <b>\Z</b> have any effect, causing REG_NOTBOL and REG_NOTEOL  
 to be passed to <b>regexec()</b> respectively.  
314  </P>  </P>
315  <P>  <P>
316  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 /8 modifier on the pattern Line 318  of the /8 modifier on the pattern
318  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
319  six bytes, encoded according to the UTF-8 rules.  six bytes, encoded according to the UTF-8 rules.
320  </P>  </P>
321  <br><a name="SEC7" href="#TOC1">OUTPUT FROM PCRETEST</a><br>  <br><a name="SEC6" href="#TOC1">OUTPUT FROM PCRETEST</a><br>
322  <P>  <P>
323  When a match succeeds, pcretest outputs the list of captured substrings that  When a match succeeds, pcretest outputs the list of captured substrings that
324  <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
325  the whole pattern. Here is an example of an interactive pcretest run.  the whole pattern. Otherwise, it outputs "No match" or "Partial match"
326  </P>  when <b>pcre_exec()</b> returns PCRE_ERROR_NOMATCH or PCRE_ERROR_PARTIAL,
327  <P>  respectively, and otherwise the PCRE negative error number. Here is an example
328    of an interactive pcretest run.
329  <pre>  <pre>
330    $ pcretest    $ pcretest
331    PCRE version 4.00 08-Jan-2003    PCRE version 5.00 07-Sep-2004
332  </PRE>  
 </P>  
 <P>  
 <pre>  
333      re&#62; /^abc(\d+)/      re&#62; /^abc(\d+)/
334    data&#62; abc123    data&#62; abc123
335     0: abc123     0: abc123
336     1: 123     1: 123
337    data&#62; xyz    data&#62; xyz
338    No match    No match
339  </PRE>  </pre>
 </P>  
 <P>  
340  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
341  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
342  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
343  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
344  "0+" like this:  this:
 </P>  
 <P>  
345  <pre>  <pre>
346      re&#62; /cat/+      re&#62; /cat/+
347    data&#62; cataract    data&#62; cataract
348     0: cat     0: cat
349     0+ aract     0+ aract
350  </PRE>  </pre>
 </P>  
 <P>  
351  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
352  matching attempts are output in sequence, like this:  matching attempts are output in sequence, like this:
 </P>  
 <P>  
353  <pre>  <pre>
354      re&#62; /\Bi(\w\w)/g      re&#62; /\Bi(\w\w)/g
355    data&#62; Mississippi    data&#62; Mississippi
# Line 411  matching attempts are output in sequence Line 359  matching attempts are output in sequence
359     1: ss     1: ss
360     0: ipp     0: ipp
361     1: pp     1: pp
362  </PRE>  </pre>
 </P>  
 <P>  
363  "No match" is output only if the first match attempt fails.  "No match" is output only if the first match attempt fails.
364  </P>  </P>
365  <P>  <P>
# Line 429  Note that while patterns can be continue Line 375  Note that while patterns can be continue
375  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
376  included in data by means of the \n escape.  included in data by means of the \n escape.
377  </P>  </P>
378  <br><a name="SEC8" href="#TOC1">AUTHOR</a><br>  <br><a name="SEC7" href="#TOC1">CALLOUTS</a><br>
379    <P>
380    If the pattern contains any callout requests, <b>pcretest</b>'s callout function
381    is called during matching. By default, it displays the callout number, the
382    start and current positions in the text at the callout time, and the next
383    pattern item to be tested. For example, the output
384    <pre>
385      ---&#62;pqrabcdef
386        0    ^  ^     \d
387    </pre>
388    indicates that callout number 0 occurred for a match attempt starting at the
389    fourth character of the subject string, when the pointer was at the seventh
390    character of the data, and when the next pattern item was \d. Just one
391    circumflex is output if the start and current positions are the same.
392    </P>
393    <P>
394    Callouts numbered 255 are assumed to be automatic callouts, inserted as a
395    result of the <b>/C</b> pattern modifier. In this case, instead of showing the
396    callout number, the offset in the pattern, preceded by a plus, is output. For
397    example:
398    <pre>
399        re&#62; /\d?[A-E]\*/C
400      data&#62; E*
401      ---&#62;E*
402       +0 ^      \d?
403       +3 ^      [A-E]
404       +8 ^^     \*
405      +10 ^ ^
406       0: E*
407    </pre>
408    The callout function in <b>pcretest</b> returns zero (carry on matching) by
409    default, but you can use an \C item in a data line (as described above) to
410    change this.
411    </P>
412    <P>
413    Inserting callouts can be helpful when using <b>pcretest</b> to check
414    complicated regular expressions. For further information about callouts, see
415    the
416    <a href="pcrecallout.html"><b>pcrecallout</b></a>
417    documentation.
418    </P>
419    <br><a name="SEC8" href="#TOC1">SAVING AND RELOADING COMPILED PATTERNS</a><br>
420    <P>
421    The facilities described in this section are not available when the POSIX
422    inteface to PCRE is being used, that is, when the <b>/P</b> pattern modifier is
423    specified.
424    </P>
425    <P>
426    When the POSIX interface is not in use, you can cause <b>pcretest</b> to write a
427    compiled pattern to a file, by following the modifiers with &#62; and a file name.
428    For example:
429    <pre>
430      /pattern/im &#62;/some/file
431    </pre>
432    See the
433    <a href="pcreprecompile.html"><b>pcreprecompile</b></a>
434    documentation for a discussion about saving and re-using compiled patterns.
435    </P>
436    <P>
437    The data that is written is binary. The first eight bytes are the length of the
438    compiled pattern data followed by the length of the optional study data, each
439    written as four bytes in big-endian order (most significant byte first). If
440    there is no study data (either the pattern was not studied, or studying did not
441    return any data), the second length is zero. The lengths are followed by an
442    exact copy of the compiled pattern. If there is additional study data, this
443    follows immediately after the compiled pattern. After writing the file,
444    <b>pcretest</b> expects to read a new pattern.
445    </P>
446    <P>
447    A saved pattern can be reloaded into <b>pcretest</b> by specifing &#60; and a file
448    name instead of a pattern. The name of the file must not contain a &#60; character,
449    as otherwise <b>pcretest</b> will interpret the line as a pattern delimited by &#60;
450    characters.
451    For example:
452    <pre>
453       re&#62; &#60;/some/file
454      Compiled regex loaded from /some/file
455      No study data
456    </pre>
457    When the pattern has been loaded, <b>pcretest</b> proceeds to read data lines in
458    the usual way.
459    </P>
460    <P>
461    You can copy a file written by <b>pcretest</b> to a different host and reload it
462    there, even if the new host has opposite endianness to the one on which the
463    pattern was compiled. For example, you can compile on an i86 machine and run on
464    a SPARC machine.
465    </P>
466    <P>
467    File names for saving and reloading can be absolute or relative, but note that
468    the shell facility of expanding a file name that starts with a tilde (~) is not
469    available.
470    </P>
471    <P>
472    The ability to save and reload files in <b>pcretest</b> is intended for testing
473    and experimentation. It is not intended for production use because only a
474    single pattern can be written to a file. Furthermore, there is no facility for
475    supplying custom character tables for use with a reloaded pattern. If the
476    original pattern was compiled with custom tables, an attempt to match a subject
477    string using a reloaded pattern is likely to cause <b>pcretest</b> to crash.
478    Finally, if you attempt to load a file that is not in the correct format, the
479    result is undefined.
480    </P>
481    <br><a name="SEC9" href="#TOC1">AUTHOR</a><br>
482  <P>  <P>
483  Philip Hazel &#60;ph10@cam.ac.uk&#62;  Philip Hazel &#60;ph10@cam.ac.uk&#62;
484  <br>  <br>
# Line 438  University Computing Service, Line 487  University Computing Service,
487  Cambridge CB2 3QG, England.  Cambridge CB2 3QG, England.
488  </P>  </P>
489  <P>  <P>
490  Last updated: 09 December 2003  Last updated: 10 September 2004
491  <br>  <br>
492  Copyright &copy; 1997-2003 University of Cambridge.  Copyright &copy; 1997-2004 University of Cambridge.
493    <p>
494    Return to the <a href="index.html">PCRE index page</a>.
495    </p>

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

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12