/[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 227 by ph10, Tue Aug 21 15:00:15 2007 UTC revision 579 by ph10, Wed Nov 24 17:39:25 2010 UTC
# Line 77  Behave as if each regex has the <b>/I</b Line 77  Behave as if each regex has the <b>/I</b
77  compiled pattern is given after compilation.  compiled pattern is given after compilation.
78  </P>  </P>
79  <P>  <P>
80    <b>-M</b>
81    Behave as if each data line contains the \M escape sequence; this causes
82    PCRE to discover the minimum MATCH_LIMIT and MATCH_LIMIT_RECURSION settings by
83    calling <b>pcre_exec()</b> repeatedly with different limits.
84    </P>
85    <P>
86  <b>-m</b>  <b>-m</b>
87  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
88  equivalent to adding <b>/M</b> to each regular expression. For compatibility  equivalent to adding <b>/M</b> to each regular expression. For compatibility
# Line 130  stdout, and prompts for each line of inp Line 136  stdout, and prompts for each line of inp
136  expressions, and "data&#62;" to prompt for data lines.  expressions, and "data&#62;" to prompt for data lines.
137  </P>  </P>
138  <P>  <P>
139    When <b>pcretest</b> is built, a configuration option can specify that it should
140    be linked with the <b>libreadline</b> library. When this is done, if the input
141    is from a terminal, it is read using the <b>readline()</b> function. This
142    provides line-editing and history facilities. The output from the <b>-help</b>
143    option states whether or not <b>readline()</b> will be used.
144    </P>
145    <P>
146  The program handles any number of sets of input on a single input file. Each  The program handles any number of sets of input on a single input file. Each
147  set starts with a regular expression, and continues with any number of data  set starts with a regular expression, and continues with any number of data
148  lines to be matched against the pattern.  lines to be matched against the pattern.
# Line 188  effect as they do in Perl. For example: Line 201  effect as they do in Perl. For example:
201  <pre>  <pre>
202    /caseless/i    /caseless/i
203  </pre>  </pre>
204  The following table shows additional modifiers for setting PCRE options that do  The following table shows additional modifiers for setting PCRE compile-time
205  not correspond to anything in Perl:  options that do not correspond to anything in Perl:
206  <pre>  <pre>
207    <b>/A</b>          PCRE_ANCHORED    <b>/8</b>              PCRE_UTF8
208    <b>/C</b>          PCRE_AUTO_CALLOUT    <b>/?</b>              PCRE_NO_UTF8_CHECK
209    <b>/E</b>          PCRE_DOLLAR_ENDONLY    <b>/A</b>              PCRE_ANCHORED
210    <b>/f</b>          PCRE_FIRSTLINE    <b>/C</b>              PCRE_AUTO_CALLOUT
211    <b>/J</b>          PCRE_DUPNAMES    <b>/E</b>              PCRE_DOLLAR_ENDONLY
212    <b>/N</b>          PCRE_NO_AUTO_CAPTURE    <b>/f</b>              PCRE_FIRSTLINE
213    <b>/U</b>          PCRE_UNGREEDY    <b>/J</b>              PCRE_DUPNAMES
214    <b>/X</b>          PCRE_EXTRA    <b>/N</b>              PCRE_NO_AUTO_CAPTURE
215    <b>/&#60;cr&#62;</b>       PCRE_NEWLINE_CR    <b>/U</b>              PCRE_UNGREEDY
216    <b>/&#60;lf&#62;</b>       PCRE_NEWLINE_LF    <b>/W</b>              PCRE_UCP
217    <b>/&#60;crlf&#62;</b>     PCRE_NEWLINE_CRLF    <b>/X</b>              PCRE_EXTRA
218    <b>/&#60;anycrlf&#62;</b>  PCRE_NEWLINE_ANYCRLF    <b>/Y</b>              PCRE_NO_START_OPTIMIZE
219    <b>/&#60;any&#62;</b>      PCRE_NEWLINE_ANY    <b>/&#60;JS&#62;</b>           PCRE_JAVASCRIPT_COMPAT
220  </pre>    <b>/&#60;cr&#62;</b>           PCRE_NEWLINE_CR
221  Those specifying line ending sequences are literal strings as shown, but the    <b>/&#60;lf&#62;</b>           PCRE_NEWLINE_LF
222  letters can be in either case. This example sets multiline matching with CRLF    <b>/&#60;crlf&#62;</b>         PCRE_NEWLINE_CRLF
223  as the line ending sequence:    <b>/&#60;anycrlf&#62;</b>      PCRE_NEWLINE_ANYCRLF
224      <b>/&#60;any&#62;</b>          PCRE_NEWLINE_ANY
225      <b>/&#60;bsr_anycrlf&#62;</b>  PCRE_BSR_ANYCRLF
226      <b>/&#60;bsr_unicode&#62;</b>  PCRE_BSR_UNICODE
227    </pre>
228    The modifiers that are enclosed in angle brackets are literal strings as shown,
229    including the angle brackets, but the letters can be in either case. This
230    example sets multiline matching with CRLF as the line ending sequence:
231  <pre>  <pre>
232    /^abc/m&#60;crlf&#62;    /^abc/m&#60;crlf&#62;
233  </pre>  </pre>
234  Details of the meanings of these PCRE options are given in the  As well as turning on the PCRE_UTF8 option, the <b>/8</b> modifier also causes
235    any non-printing characters in output strings to be printed using the
236    \x{hh...} notation if they are valid UTF-8 sequences. Full details of the PCRE
237    options are given in the
238  <a href="pcreapi.html"><b>pcreapi</b></a>  <a href="pcreapi.html"><b>pcreapi</b></a>
239  documentation.  documentation.
240  </P>  </P>
# Line 230  begins with a lookbehind assertion (incl Line 253  begins with a lookbehind assertion (incl
253  </P>  </P>
254  <P>  <P>
255  If any call to <b>pcre_exec()</b> in a <b>/g</b> or <b>/G</b> sequence matches an  If any call to <b>pcre_exec()</b> in a <b>/g</b> or <b>/G</b> sequence matches an
256  empty string, the next call is done with the PCRE_NOTEMPTY and PCRE_ANCHORED  empty string, the next call is done with the PCRE_NOTEMPTY_ATSTART and
257  flags set in order to search for another, non-empty, match at the same point.  PCRE_ANCHORED flags set in order to search for another, non-empty, match at the
258  If this second match fails, the start offset is advanced by one, and the normal  same point. If this second match fails, the start offset is advanced, and the
259  match is retried. This imitates the way Perl handles such cases when using the  normal match is retried. This imitates the way Perl handles such cases when
260  <b>/g</b> modifier or the <b>split()</b> function.  using the <b>/g</b> modifier or the <b>split()</b> function. Normally, the start
261    offset is advanced by one character, but if the newline convention recognizes
262    CRLF as a newline, and the current character is CR followed by LF, an advance
263    of two is used.
264  </P>  </P>
265  <br><b>  <br><b>
266  Other modifiers  Other modifiers
# Line 258  use in the automatic test scripts; it en Line 284  use in the automatic test scripts; it en
284  for different internal link sizes.  for different internal link sizes.
285  </P>  </P>
286  <P>  <P>
 The <b>/L</b> modifier must be followed directly by the name of a locale, for  
 example,  
 <pre>  
   /pattern/Lfr_FR  
 </pre>  
 For this reason, it must be the last modifier. The given locale is set,  
 <b>pcre_maketables()</b> is called to build a set of character tables for the  
 locale, and this is then passed to <b>pcre_compile()</b> when compiling the  
 regular expression. Without an <b>/L</b> modifier, NULL is passed as the tables  
 pointer; that is, <b>/L</b> applies only to the expression on which it appears.  
 </P>  
 <P>  
 The <b>/I</b> modifier requests that <b>pcretest</b> output information about the  
 compiled pattern (whether it is anchored, has a fixed first character, and  
 so on). It does this by calling <b>pcre_fullinfo()</b> after compiling a  
 pattern. If the pattern is studied, the results of that are also output.  
 </P>  
 <P>  
287  The <b>/D</b> modifier is a PCRE debugging feature, and is equivalent to  The <b>/D</b> modifier is a PCRE debugging feature, and is equivalent to
288  <b>/BI</b>, that is, both the <b>/B</b> and the <b>/I</b> modifiers.  <b>/BI</b>, that is, both the <b>/B</b> and the <b>/I</b> modifiers.
289  </P>  </P>
# Line 289  available when the POSIX interface to PC Line 297  available when the POSIX interface to PC
297  reloading compiled patterns below.  reloading compiled patterns below.
298  </P>  </P>
299  <P>  <P>
300    The <b>/I</b> modifier requests that <b>pcretest</b> output information about the
301    compiled pattern (whether it is anchored, has a fixed first character, and
302    so on). It does this by calling <b>pcre_fullinfo()</b> after compiling a
303    pattern. If the pattern is studied, the results of that are also output.
304    </P>
305    <P>
306    The <b>/K</b> modifier requests <b>pcretest</b> to show names from backtracking
307    control verbs that are returned from calls to <b>pcre_exec()</b>. It causes
308    <b>pcretest</b> to create a <b>pcre_extra</b> block if one has not already been
309    created by a call to <b>pcre_study()</b>, and to set the PCRE_EXTRA_MARK flag
310    and the <b>mark</b> field within it, every time that <b>pcre_exec()</b> is
311    called. If the variable that the <b>mark</b> field points to is non-NULL for a
312    match, non-match, or partial match, <b>pcretest</b> prints the string to which
313    it points. For a match, this is shown on a line by itself, tagged with "MK:".
314    For a non-match it is added to the message.
315    </P>
316    <P>
317    The <b>/L</b> modifier must be followed directly by the name of a locale, for
318    example,
319    <pre>
320      /pattern/Lfr_FR
321    </pre>
322    For this reason, it must be the last modifier. The given locale is set,
323    <b>pcre_maketables()</b> is called to build a set of character tables for the
324    locale, and this is then passed to <b>pcre_compile()</b> when compiling the
325    regular expression. Without an <b>/L</b> (or <b>/T</b>) modifier, NULL is passed
326    as the tables pointer; that is, <b>/L</b> applies only to the expression on
327    which it appears.
328    </P>
329    <P>
330    The <b>/M</b> modifier causes the size of memory block used to hold the compiled
331    pattern to be output.
332    </P>
333    <P>
334  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
335  expression has been compiled, and the results used when the expression is  expression has been compiled, and the results used when the expression is
336  matched.  matched.
337  </P>  </P>
338  <P>  <P>
339  The <b>/M</b> modifier causes the size of memory block used to hold the compiled  The <b>/T</b> modifier must be followed by a single digit. It causes a specific
340  pattern to be output.  set of built-in character tables to be passed to <b>pcre_compile()</b>. It is
341    used in the standard PCRE tests to check behaviour with different character
342    tables. The digit specifies the tables as follows:
343    <pre>
344      0   the default ASCII tables, as distributed in
345            pcre_chartables.c.dist
346      1   a set of tables defining ISO 8859 characters
347    </pre>
348    In table 1, some characters whose codes are greater than 128 are identified as
349    letters, digits, spaces, etc.
350  </P>  </P>
351    <br><b>
352    Using the POSIX wrapper API
353    </b><br>
354  <P>  <P>
355  The <b>/P</b> modifier causes <b>pcretest</b> to call PCRE via the POSIX wrapper  The <b>/P</b> modifier causes <b>pcretest</b> to call PCRE via the POSIX wrapper
356  API rather than its native API. When this is done, all other modifiers except  API rather than its native API. When <b>/P</b> is set, the following modifiers
357  <b>/i</b>, <b>/m</b>, and <b>/+</b> are ignored. REG_ICASE is set if <b>/i</b> is  set options for the <b>regcomp()</b> function:
358  present, and REG_NEWLINE is set if <b>/m</b> is present. The wrapper functions  <pre>
359  force PCRE_DOLLAR_ENDONLY always, and PCRE_DOTALL unless REG_NEWLINE is set.    /i    REG_ICASE
360  </P>    /m    REG_NEWLINE
361  <P>    /N    REG_NOSUB
362  The <b>/8</b> modifier causes <b>pcretest</b> to call PCRE with the PCRE_UTF8    /s    REG_DOTALL     )
363  option set. This turns on support for UTF-8 character handling in PCRE,    /U    REG_UNGREEDY   ) These options are not part of
364  provided that it was compiled with this support enabled. This modifier also    /W    REG_UCP        )   the POSIX standard
365  causes any non-printing characters in output strings to be printed using the    /8    REG_UTF8       )
366  \x{hh...} notation if they are valid UTF-8 sequences.  </pre>
367  </P>  The <b>/+</b> modifier works as described above. All other modifiers are
368  <P>  ignored.
 If the <b>/?</b> modifier is used with <b>/8</b>, it causes <b>pcretest</b> to  
 call <b>pcre_compile()</b> with the PCRE_NO_UTF8_CHECK option, to suppress the  
 checking of the string for UTF-8 validity.  
369  </P>  </P>
370  <br><a name="SEC5" href="#TOC1">DATA LINES</a><br>  <br><a name="SEC5" href="#TOC1">DATA LINES</a><br>
371  <P>  <P>
# Line 335  recognized: Line 386  recognized:
386    \t         tab (\x09)    \t         tab (\x09)
387    \v         vertical tab (\x0b)    \v         vertical tab (\x0b)
388    \nnn       octal character (up to 3 octal digits)    \nnn       octal character (up to 3 octal digits)
389    \xhh       hexadecimal character (up to 2 hex digits)                 always a byte unless &#62; 255 in UTF-8 mode
390      \xhh       hexadecimal byte (up to 2 hex digits)
391    \x{hh...}  hexadecimal character, any number of digits in UTF-8 mode    \x{hh...}  hexadecimal character, any number of digits in UTF-8 mode
392    \A         pass the PCRE_ANCHORED option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>    \A         pass the PCRE_ANCHORED option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
393    \B         pass the PCRE_NOTBOL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>    \B         pass the PCRE_NOTBOL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
# Line 354  recognized: Line 406  recognized:
406                 ated by next non-alphanumeric character)                 ated by next non-alphanumeric character)
407    \L         call pcre_get_substringlist() after a successful match    \L         call pcre_get_substringlist() after a successful match
408    \M         discover the minimum MATCH_LIMIT and MATCH_LIMIT_RECURSION settings    \M         discover the minimum MATCH_LIMIT and MATCH_LIMIT_RECURSION settings
409    \N         pass the PCRE_NOTEMPTY option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>    \N         pass the PCRE_NOTEMPTY option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>; if used twice, pass the
410                   PCRE_NOTEMPTY_ATSTART option
411    \Odd       set the size of the output vector passed to <b>pcre_exec()</b> to dd (any number of digits)    \Odd       set the size of the output vector passed to <b>pcre_exec()</b> to dd (any number of digits)
412    \P         pass the PCRE_PARTIAL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>    \P         pass the PCRE_PARTIAL_SOFT option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>; if used twice, pass the
413                   PCRE_PARTIAL_HARD option
414    \Qdd       set the PCRE_MATCH_LIMIT_RECURSION limit to dd (any number of digits)    \Qdd       set the PCRE_MATCH_LIMIT_RECURSION limit to dd (any number of digits)
415    \R         pass the PCRE_DFA_RESTART option to <b>pcre_dfa_exec()</b>    \R         pass the PCRE_DFA_RESTART option to <b>pcre_dfa_exec()</b>
416    \S         output details of memory get/free calls during matching    \S         output details of memory get/free calls during matching
417      \Y         pass the PCRE_NO_START_OPTIMIZE option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
418    \Z         pass the PCRE_NOTEOL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>    \Z         pass the PCRE_NOTEOL option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
419    \?         pass the PCRE_NO_UTF8_CHECK option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>    \?         pass the PCRE_NO_UTF8_CHECK option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
420    \&#62;dd       start the match at offset dd (any number of digits);    \&#62;dd       start the match at offset dd (optional "-"; then any number of digits); this sets the <i>startoffset</i>
421                 this sets the <i>startoffset</i> argument for <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>                 argument for <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
422    \&#60;cr&#62;      pass the PCRE_NEWLINE_CR option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>    \&#60;cr&#62;      pass the PCRE_NEWLINE_CR option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
423    \&#60;lf&#62;      pass the PCRE_NEWLINE_LF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>    \&#60;lf&#62;      pass the PCRE_NEWLINE_LF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
424    \&#60;crlf&#62;    pass the PCRE_NEWLINE_CRLF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>    \&#60;crlf&#62;    pass the PCRE_NEWLINE_CRLF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
425    \&#60;anycrlf&#62; pass the PCRE_NEWLINE_ANYCRLF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>    \&#60;anycrlf&#62; pass the PCRE_NEWLINE_ANYCRLF option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
426    \&#60;any&#62;     pass the PCRE_NEWLINE_ANY option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>    \&#60;any&#62;     pass the PCRE_NEWLINE_ANY option to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>
427  </pre>  </pre>
428    Note that \xhh always specifies one byte, even in UTF-8 mode; this makes it
429    possible to construct invalid UTF-8 sequences for testing purposes. On the
430    other hand, \x{hh} is interpreted as a UTF-8 character in UTF-8 mode,
431    generating more than one byte if the value is greater than 127. When not in
432    UTF-8 mode, it generates one byte for values less than 256, and causes an error
433    for greater values.
434    </P>
435    <P>
436  The escapes that specify line ending sequences are literal strings, exactly as  The escapes that specify line ending sequences are literal strings, exactly as
437  shown. No more than one newline setting should be present in any data line.  shown. No more than one newline setting should be present in any data line.
438  </P>  </P>
# Line 399  the call of <b>pcre_exec()</b> for the l Line 462  the call of <b>pcre_exec()</b> for the l
462  </P>  </P>
463  <P>  <P>
464  If the <b>/P</b> modifier was present on the pattern, causing the POSIX wrapper  If the <b>/P</b> modifier was present on the pattern, causing the POSIX wrapper
465  API to be used, the only option-setting sequences that have any effect are \B  API to be used, the only option-setting sequences that have any effect are \B,
466  and \Z, causing REG_NOTBOL and REG_NOTEOL, respectively, to be passed to  \N, and \Z, causing REG_NOTBOL, REG_NOTEMPTY, and REG_NOTEOL, respectively,
467  <b>regexec()</b>.  to be passed to <b>regexec()</b>.
468  </P>  </P>
469  <P>  <P>
470  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 437  This section describes the output when t Line 500  This section describes the output when t
500  <P>  <P>
501  When a match succeeds, pcretest outputs the list of captured substrings that  When a match succeeds, pcretest outputs the list of captured substrings that
502  <b>pcre_exec()</b> returns, starting with number 0 for the string that matched  <b>pcre_exec()</b> returns, starting with number 0 for the string that matched
503  the whole pattern. Otherwise, it outputs "No match" or "Partial match"  the whole pattern. Otherwise, it outputs "No match" when the return is
504  when <b>pcre_exec()</b> returns PCRE_ERROR_NOMATCH or PCRE_ERROR_PARTIAL,  PCRE_ERROR_NOMATCH, and "Partial match:" followed by the partially matching
505  respectively, and otherwise the PCRE negative error number. Here is an example  substring when <b>pcre_exec()</b> returns PCRE_ERROR_PARTIAL. (Note that this is
506  of an interactive <b>pcretest</b> run.  the entire substring that was inspected during the partial match; it may
507    include characters before the actual match start if a lookbehind assertion,
508    \K, \b, or \B was involved.) For any other returns, it outputs the PCRE
509    negative error number. Here is an example of an interactive <b>pcretest</b> run.
510  <pre>  <pre>
511    $ pcretest    $ pcretest
512    PCRE version 7.0 30-Nov-2006    PCRE version 7.0 30-Nov-2006
# Line 452  of an interactive <b>pcretest</b> run. Line 518  of an interactive <b>pcretest</b> run.
518    data&#62; xyz    data&#62; xyz
519    No match    No match
520  </pre>  </pre>
521    Note that unset capturing substrings that are not followed by one that is set
522    are not returned by <b>pcre_exec()</b>, and are not shown by <b>pcretest</b>. In
523    the following example, there are two capturing substrings, but when the first
524    data line is matched, the second, unset substring is not shown. An "internal"
525    unset substring is shown as "&#60;unset&#62;", as for the second data line.
526    <pre>
527        re&#62; /(a)|(b)/
528      data&#62; a
529       0: a
530       1: a
531      data&#62; b
532       0: b
533       1: &#60;unset&#62;
534       2: b
535    </pre>
536  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
537  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
538  pattern. See below for the definition of non-printing characters. If the  pattern. See below for the definition of non-printing characters. If the
# Line 505  the subject where there is at least one Line 586  the subject where there is at least one
586     2: tan     2: tan
587  </pre>  </pre>
588  (Using the normal matching function on this data finds only "tang".) The  (Using the normal matching function on this data finds only "tang".) The
589  longest matching string is always given first (and numbered zero).  longest matching string is always given first (and numbered zero). After a
590    PCRE_ERROR_PARTIAL return, the output is "Partial match:", followed by the
591    partially matching substring. (Note that this is the entire substring that was
592    inspected during the partial match; it may include characters before the actual
593    match start if a lookbehind assertion, \K, \b, or \B was involved.)
594  </P>  </P>
595  <P>  <P>
596  If <b>/g</b> is present on the pattern, the search for further matches resumes  If <b>/g</b> is present on the pattern, the search for further matches resumes
# Line 672  Cambridge CB2 3QH, England. Line 757  Cambridge CB2 3QH, England.
757  </P>  </P>
758  <br><a name="SEC15" href="#TOC1">REVISION</a><br>  <br><a name="SEC15" href="#TOC1">REVISION</a><br>
759  <P>  <P>
760  Last updated: 21 August 2007  Last updated: 21 November 2010
761  <br>  <br>
762  Copyright &copy; 1997-2007 University of Cambridge.  Copyright &copy; 1997-2010 University of Cambridge.
763  <br>  <br>
764  <p>  <p>
765  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.

Legend:
Removed from v.227  
changed lines
  Added in v.579

  ViewVC Help
Powered by ViewVC 1.1.5