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

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

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

revision 87 by nigel, Sat Feb 24 21:41:21 2007 UTC revision 93 by nigel, Sat Feb 24 21:41:42 2007 UTC
# Line 4  pcretest - a program for testing Perl-co Line 4  pcretest - a program for testing Perl-co
4  .SH SYNOPSIS  .SH SYNOPSIS
5  .rs  .rs
6  .sp  .sp
7  .B pcretest "[-C] [-d] [-dfa] [-i] [-m] [-o osize] [-p] [-t] [source]"  .B pcretest "[options] [source] [destination]"
8  .ti +5n  .sp
 .B "[destination]"  
 .P  
9  \fBpcretest\fP was written as a test program for the PCRE regular expression  \fBpcretest\fP was written as a test program for the PCRE regular expression
10  library itself, but it can also be used for experimenting with regular  library itself, but it can also be used for experimenting with regular
11  expressions. This document describes the features of the test program; for  expressions. This document describes the features of the test program; for
# Line 26  documentation. Line 24  documentation.
24  .SH OPTIONS  .SH OPTIONS
25  .rs  .rs
26  .TP 10  .TP 10
27    \fB-b\fP
28    Behave as if each regex has the \fB/B\fP (show bytecode) modifier; the internal
29    form is output after compilation.
30    .TP 10
31  \fB-C\fP  \fB-C\fP
32  Output the version number of the PCRE library, and all available information  Output the version number of the PCRE library, and all available information
33  about the optional features that are included, and then exit.  about the optional features that are included, and then exit.
34  .TP 10  .TP 10
35  \fB-d\fP  \fB-d\fP
36  Behave as if each regex has the \fB/D\fP (debug) modifier; the internal  Behave as if each regex has the \fB/D\fP (debug) modifier; the internal
37  form is output after compilation.  form and information about the compiled pattern is output after compilation;
38    \fB-d\fP is equivalent to \fB-b -i\fP.
39  .TP 10  .TP 10
40  \fB-dfa\fP  \fB-dfa\fP
41  Behave as if each data line contains the \eD escape sequence; this causes the  Behave as if each data line contains the \eD escape sequence; this causes the
42  alternative matching function, \fBpcre_dfa_exec()\fP, to be used instead of the  alternative matching function, \fBpcre_dfa_exec()\fP, to be used instead of the
43  standard \fBpcre_exec()\fP function (more detail is given below).  standard \fBpcre_exec()\fP function (more detail is given below).
44  .TP 10  .TP 10
45    \fB-help\fP
46    Output a brief summary these options and then exit.
47    .TP 10
48  \fB-i\fP  \fB-i\fP
49  Behave as if each regex has the \fB/I\fP modifier; information about the  Behave as if each regex has the \fB/I\fP modifier; information about the
50  compiled pattern is given after compilation.  compiled pattern is given after compilation.
# Line 50  with earlier versions of pcretest, \fB-s Line 56  with earlier versions of pcretest, \fB-s
56  .TP 10  .TP 10
57  \fB-o\fP \fIosize\fP  \fB-o\fP \fIosize\fP
58  Set the number of elements in the output vector that is used when calling  Set the number of elements in the output vector that is used when calling
59  \fBpcre_exec()\fP to be \fIosize\fP. The default value is 45, which is enough  \fBpcre_exec()\fP or \fBpcre_dfa_exec()\fP to be \fIosize\fP. The default value
60  for 14 capturing subexpressions. The vector size can be changed for individual  is 45, which is enough for 14 capturing subexpressions for \fBpcre_exec()\fP or
61  matching calls by including \eO in the data line (see below).  22 different matches for \fBpcre_dfa_exec()\fP. The vector size can be
62    changed for individual matching calls by including \eO in the data line (see
63    below).
64  .TP 10  .TP 10
65  \fB-p\fP  \fB-p\fP
66  Behave as if each regex has the \fB/P\fP modifier; the POSIX wrapper API is  Behave as if each regex has the \fB/P\fP modifier; the POSIX wrapper API is
67  used to call PCRE. None of the other options has any effect when \fB-p\fP is  used to call PCRE. None of the other options has any effect when \fB-p\fP is
68  set.  set.
69  .TP 10  .TP 10
70  \fP-q\fP  \fB-q\fP
71  Do not output the version number of \fBpcretest\fP at the start of execution.  Do not output the version number of \fBpcretest\fP at the start of execution.
72  .TP 10  .TP 10
73    \fB-S\fP \fIsize\fP
74    On Unix-like systems, set the size of the runtime stack to \fIsize\fP
75    megabytes.
76    .TP 10
77  \fB-t\fP  \fB-t\fP
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 \fB-m\fP with  resulting time per compile or match (in milliseconds). Do not set \fB-m\fP with
80  \fB-t\fP, because you will then get the size output a zillion times, and the  \fB-t\fP, because you will then get the size output a zillion times, and the
81  timing will be distorted.  timing will be distorted. You can control the number of iterations that are
82    used for timing by following \fB-t\fP with a number (as a separate item on the
83    command line). For example, "-t 1000" would iterate 1000 times. The default is
84    to iterate 500000 times.
85    .TP 10
86    \fB-tm\fP
87    This is like \fB-t\fP except that it times only the matching phase, not the
88    compile or study phases.
89  .  .
90  .  .
91  .SH DESCRIPTION  .SH DESCRIPTION
# Line 83  set starts with a regular expression, an Line 102  set starts with a regular expression, an
102  lines to be matched against the pattern.  lines to be matched against the pattern.
103  .P  .P
104  Each data line is matched separately and independently. If you want to do  Each data line is matched separately and independently. If you want to do
105  multiple-line matches, you have to use the \en escape sequence in a single line  multi-line matches, you have to use the \en escape sequence (or \er or \er\en,
106  of input to encode the newline characters. The maximum length of data line is  etc., depending on the newline setting) in a single line of input to encode the
107  30,000 characters.  newline sequences. There is no limit on the length of data lines; the input
108    buffer is automatically extended if it is too small.
109  .P  .P
110  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
111  expression is read. The regular expressions are given enclosed in any  expression is read. The regular expressions are given enclosed in any
112  non-alphanumeric delimiters other than backslash, for example  non-alphanumeric delimiters other than backslash, for example:
113  .sp  .sp
114    /(a|bc)x+yz/    /(a|bc)x+yz/
115  .sp  .sp
# Line 137  effect as they do in Perl. For example: Line 157  effect as they do in Perl. For example:
157  The following table shows additional modifiers for setting PCRE options that do  The following table shows additional modifiers for setting PCRE options that do
158  not correspond to anything in Perl:  not correspond to anything in Perl:
159  .sp  .sp
160    \fB/A\fP    PCRE_ANCHORED    \fB/A\fP       PCRE_ANCHORED
161    \fB/C\fP    PCRE_AUTO_CALLOUT    \fB/C\fP       PCRE_AUTO_CALLOUT
162    \fB/E\fP    PCRE_DOLLAR_ENDONLY    \fB/E\fP       PCRE_DOLLAR_ENDONLY
163    \fB/f\fP    PCRE_FIRSTLINE    \fB/f\fP       PCRE_FIRSTLINE
164    \fB/N\fP    PCRE_NO_AUTO_CAPTURE    \fB/J\fP       PCRE_DUPNAMES
165    \fB/U\fP    PCRE_UNGREEDY    \fB/N\fP       PCRE_NO_AUTO_CAPTURE
166    \fB/X\fP    PCRE_EXTRA    \fB/U\fP       PCRE_UNGREEDY
167      \fB/X\fP       PCRE_EXTRA
168      \fB/<cr>\fP    PCRE_NEWLINE_CR
169      \fB/<lf>\fP    PCRE_NEWLINE_LF
170      \fB/<crlf>\fP  PCRE_NEWLINE_CRLF
171      \fB/<any>\fP   PCRE_NEWLINE_ANY
172    .sp
173    Those specifying line ending sequencess are literal strings as shown. This
174    example sets multiline matching with CRLF as the line ending sequence:
175    .sp
176      /^abc/m<crlf>
177    .sp
178    Details of the meanings of these PCRE options are given in the
179    .\" HREF
180    \fBpcreapi\fP
181    .\"
182    documentation.
183    .
184    .
185    .SS "Finding all matches in a string"
186    .rs
187  .sp  .sp
188  Searching for all possible matches within each subject string can be requested  Searching for all possible matches within each subject string can be requested
189  by the \fB/g\fP or \fB/G\fP modifier. After finding a match, PCRE is called  by the \fB/g\fP or \fB/G\fP modifier. After finding a match, PCRE is called
# Line 160  flags set in order to search for another Line 200  flags set in order to search for another
200  If this second match fails, the start offset is advanced by one, and the normal  If this second match fails, the start offset is advanced by one, and the normal
201  match is retried. This imitates the way Perl handles such cases when using the  match is retried. This imitates the way Perl handles such cases when using the
202  \fB/g\fP modifier or the \fBsplit()\fP function.  \fB/g\fP modifier or the \fBsplit()\fP function.
203  .P  .
204    .
205    .SS "Other modifiers"
206    .rs
207    .sp
208  There are yet more modifiers for controlling the way \fBpcretest\fP  There are yet more modifiers for controlling the way \fBpcretest\fP
209  operates.  operates.
210  .P  .P
# Line 169  matched the entire pattern, pcretest sho Line 213  matched the entire pattern, pcretest sho
213  the subject string. This is useful for tests where the subject contains  the subject string. This is useful for tests where the subject contains
214  multiple copies of the same substring.  multiple copies of the same substring.
215  .P  .P
216    The \fB/B\fP modifier is a debugging feature. It requests that \fBpcretest\fP
217    output a representation of the compiled byte code after compilation.
218    .P
219  The \fB/L\fP modifier must be followed directly by the name of a locale, for  The \fB/L\fP modifier must be followed directly by the name of a locale, for
220  example,  example,
221  .sp  .sp
# Line 185  compiled pattern (whether it is anchored Line 232  compiled pattern (whether it is anchored
232  so on). It does this by calling \fBpcre_fullinfo()\fP after compiling a  so on). It does this by calling \fBpcre_fullinfo()\fP after compiling a
233  pattern. If the pattern is studied, the results of that are also output.  pattern. If the pattern is studied, the results of that are also output.
234  .P  .P
235  The \fB/D\fP modifier is a PCRE debugging feature, which also assumes \fB/I\fP.  The \fB/D\fP modifier is a PCRE debugging feature, and is equivalent to
236  It causes the internal form of compiled regular expressions to be output after  \fB/BI\fP, that is, both the \fP/B\fP and the \fB/I\fP modifiers.
 compilation. If the pattern was studied, the information returned is also  
 output.  
237  .P  .P
238  The \fB/F\fP modifier causes \fBpcretest\fP to flip the byte order of the  The \fB/F\fP modifier causes \fBpcretest\fP to flip the byte order of the
239  fields in the compiled pattern that contain 2-byte and 4-byte numbers. This  fields in the compiled pattern that contain 2-byte and 4-byte numbers. This
# Line 232  complicated features of PCRE. If you are Line 277  complicated features of PCRE. If you are
277  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
278  recognized:  recognized:
279  .sp  .sp
280    \ea         alarm (= BEL)    \ea         alarm (BEL, \ex07)
281    \eb         backspace    \eb         backspace (\ex08)
282    \ee         escape    \ee         escape (\ex27)
283    \ef         formfeed    \ef         formfeed (\ex0c)
284    \en         newline    \en         newline (\ex0a)
285    \er         carriage return  .\" JOIN
286    \et         tab    \eqdd       set the PCRE_MATCH_LIMIT limit to dd
287    \ev         vertical tab                 (any number of digits)
288      \er         carriage return (\ex0d)
289      \et         tab (\ex09)
290      \ev         vertical tab (\ex0b)
291    \ennn       octal character (up to 3 octal digits)    \ennn       octal character (up to 3 octal digits)
292    \exhh       hexadecimal character (up to 2 hex digits)    \exhh       hexadecimal character (up to 2 hex digits)
293  .\" JOIN  .\" JOIN
294    \ex{hh...}  hexadecimal character, any number of digits    \ex{hh...}  hexadecimal character, any number of digits
295                 in UTF-8 mode                 in UTF-8 mode
296    .\" JOIN
297    \eA         pass the PCRE_ANCHORED option to \fBpcre_exec()\fP    \eA         pass the PCRE_ANCHORED option to \fBpcre_exec()\fP
298                   or \fBpcre_dfa_exec()\fP
299    .\" JOIN
300    \eB         pass the PCRE_NOTBOL option to \fBpcre_exec()\fP    \eB         pass the PCRE_NOTBOL option to \fBpcre_exec()\fP
301                   or \fBpcre_dfa_exec()\fP
302  .\" JOIN  .\" JOIN
303    \eCdd       call pcre_copy_substring() for substring dd    \eCdd       call pcre_copy_substring() for substring dd
304                 after a successful match (number less than 32)                 after a successful match (number less than 32)
# Line 279  recognized: Line 331  recognized:
331  .\" JOIN  .\" JOIN
332    \eL         call pcre_get_substringlist() after a    \eL         call pcre_get_substringlist() after a
333                 successful match                 successful match
334    .\" JOIN
335    \eM         discover the minimum MATCH_LIMIT and    \eM         discover the minimum MATCH_LIMIT and
336                 MATCH_LIMIT_RECURSION settings                 MATCH_LIMIT_RECURSION settings
337    .\" JOIN
338    \eN         pass the PCRE_NOTEMPTY option to \fBpcre_exec()\fP    \eN         pass the PCRE_NOTEMPTY option to \fBpcre_exec()\fP
339                   or \fBpcre_dfa_exec()\fP
340  .\" JOIN  .\" JOIN
341    \eOdd       set the size of the output vector passed to    \eOdd       set the size of the output vector passed to
342                 \fBpcre_exec()\fP to dd (any number of digits)                 \fBpcre_exec()\fP to dd (any number of digits)
343  .\" JOIN  .\" JOIN
344    \eP         pass the PCRE_PARTIAL option to \fBpcre_exec()\fP    \eP         pass the PCRE_PARTIAL option to \fBpcre_exec()\fP
345                 or \fBpcre_dfa_exec()\fP                 or \fBpcre_dfa_exec()\fP
346    .\" JOIN
347      \eQdd       set the PCRE_MATCH_LIMIT_RECURSION limit to dd
348                   (any number of digits)
349    \eR         pass the PCRE_DFA_RESTART option to \fBpcre_dfa_exec()\fP    \eR         pass the PCRE_DFA_RESTART option to \fBpcre_dfa_exec()\fP
350    \eS         output details of memory get/free calls during matching    \eS         output details of memory get/free calls during matching
351    .\" JOIN
352    \eZ         pass the PCRE_NOTEOL option to \fBpcre_exec()\fP    \eZ         pass the PCRE_NOTEOL option to \fBpcre_exec()\fP
353                   or \fBpcre_dfa_exec()\fP
354  .\" JOIN  .\" JOIN
355    \e?         pass the PCRE_NO_UTF8_CHECK option to    \e?         pass the PCRE_NO_UTF8_CHECK option to
356                 \fBpcre_exec()\fP                 \fBpcre_exec()\fP or \fBpcre_dfa_exec()\fP
357    \e>dd       start the match at offset dd (any number of digits);    \e>dd       start the match at offset dd (any number of digits);
358    .\" JOIN
359                 this sets the \fIstartoffset\fP argument for \fBpcre_exec()\fP                 this sets the \fIstartoffset\fP argument for \fBpcre_exec()\fP
360                   or \fBpcre_dfa_exec()\fP
361    .\" JOIN
362      \e<cr>      pass the PCRE_NEWLINE_CR option to \fBpcre_exec()\fP
363                   or \fBpcre_dfa_exec()\fP
364    .\" JOIN
365      \e<lf>      pass the PCRE_NEWLINE_LF option to \fBpcre_exec()\fP
366                   or \fBpcre_dfa_exec()\fP
367    .\" JOIN
368      \e<crlf>    pass the PCRE_NEWLINE_CRLF option to \fBpcre_exec()\fP
369                   or \fBpcre_dfa_exec()\fP
370    .\" JOIN
371      \e<any>     pass the PCRE_NEWLINE_ANY option to \fBpcre_exec()\fP
372                   or \fBpcre_dfa_exec()\fP
373  .sp  .sp
374  A backslash followed by anything else just escapes the anything else. If the  The escapes that specify line ending sequences are literal strings, exactly as
375  very last character is a backslash, it is ignored. This gives a way of passing  shown. No more than one newline setting should be present in any data line.
376  an empty line as data, since a real empty line terminates the data input.  .P
377    A backslash followed by anything else just escapes the anything else. If
378    the very last character is a backslash, it is ignored. This gives a way of
379    passing an empty line as data, since a real empty line terminates the data
380    input.
381  .P  .P
382  If \eM is present, \fBpcretest\fP calls \fBpcre_exec()\fP several times, with  If \eM is present, \fBpcretest\fP calls \fBpcre_exec()\fP several times, with
383  different values in the \fImatch_limit\fP and \fImatch_limit_recursion\fP  different values in the \fImatch_limit\fP and \fImatch_limit_recursion\fP
# Line 362  respectively, and otherwise the PCRE neg Line 440  respectively, and otherwise the PCRE neg
440  of an interactive \fBpcretest\fP run.  of an interactive \fBpcretest\fP run.
441  .sp  .sp
442    $ pcretest    $ pcretest
443    PCRE version 5.00 07-Sep-2004    PCRE version 7.0 30-Nov-2006
444  .sp  .sp
445      re> /^abc(\ed+)/      re> /^abc(\ed+)/
446    data> abc123    data> abc123
# Line 373  of an interactive \fBpcretest\fP run. Line 451  of an interactive \fBpcretest\fP run.
451  .sp  .sp
452  If the strings contain any non-printing characters, they are output as \e0x  If the strings contain any non-printing characters, they are output as \e0x
453  escapes, or as \ex{...} escapes if the \fB/8\fP modifier was present on the  escapes, or as \ex{...} escapes if the \fB/8\fP modifier was present on the
454  pattern. If the pattern has the \fB/+\fP modifier, the output for substring 0  pattern. See below for the definition of non-printing characters. If the
455  is followed by the the rest of the subject string, identified by "0+" like  pattern has the \fB/+\fP modifier, the output for substring 0 is followed by
456  this:  the the rest of the subject string, identified by "0+" like this:
457  .sp  .sp
458      re> /cat/+      re> /cat/+
459    data> cataract    data> cataract
# Line 403  instead of a colon. This is in addition Line 481  instead of a colon. This is in addition
481  length (that is, the return from the extraction function) is given in  length (that is, the return from the extraction function) is given in
482  parentheses after each string for \fB\eC\fP and \fB\eG\fP.  parentheses after each string for \fB\eC\fP and \fB\eG\fP.
483  .P  .P
484  Note that while patterns can be continued over several lines (a plain ">"  Note that whereas patterns can be continued over several lines (a plain ">"
485  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
486  included in data by means of the \en escape.  included in data by means of the \en escape (or \er, \er\en, etc., depending on
487    the newline sequence setting).
488    .
489  .  .
490  .  .
491  .SH "OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION"  .SH "OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION"
# Line 425  the subject where there is at least one Line 505  the subject where there is at least one
505  (Using the normal matching function on this data finds only "tang".) The  (Using the normal matching function on this data finds only "tang".) The
506  longest matching string is always given first (and numbered zero).  longest matching string is always given first (and numbered zero).
507  .P  .P
508  If \fB/g\P is present on the pattern, the search for further matches resumes  If \fB/g\fP is present on the pattern, the search for further matches resumes
509  at the end of the longest match. For example:  at the end of the longest match. For example:
510  .sp  .sp
511      re> /(tang|tangerine|tan)/g      re> /(tang|tangerine|tan)/g
# Line 506  the Line 586  the
586  documentation.  documentation.
587  .  .
588  .  .
589    .
590    .SH "NON-PRINTING CHARACTERS"
591    .rs
592    .sp
593    When \fBpcretest\fP is outputting text in the compiled version of a pattern,
594    bytes other than 32-126 are always treated as non-printing characters are are
595    therefore shown as hex escapes.
596    .P
597    When \fBpcretest\fP is outputting text that is a matched part of a subject
598    string, it behaves in the same way, unless a different locale has been set for
599    the pattern (using the \fB/L\fP modifier). In this case, the \fBisprint()\fP
600    function to distinguish printing and non-printing characters.
601    .
602    .
603    .
604  .SH "SAVING AND RELOADING COMPILED PATTERNS"  .SH "SAVING AND RELOADING COMPILED PATTERNS"
605  .rs  .rs
606  .sp  .sp
# Line 566  Finally, if you attempt to load a file t Line 661  Finally, if you attempt to load a file t
661  result is undefined.  result is undefined.
662  .  .
663  .  .
664    .SH "SEE ALSO"
665    .rs
666    .sp
667    \fBpcre\fP(3), \fBpcreapi\fP(3), \fBpcrecallout\fP(3), \fBpcrematching\fP(3),
668    \fBpcrepartial\fP(d), \fPpcrepattern\fP(3), \fBpcreprecompile\fP(3).
669    .
670    .
671  .SH AUTHOR  .SH AUTHOR
672  .rs  .rs
673  .sp  .sp
# Line 573  Philip Hazel Line 675  Philip Hazel
675  .br  .br
676  University Computing Service,  University Computing Service,
677  .br  .br
678  Cambridge CB2 3QG, England.  Cambridge CB2 3QH, England.
679  .P  .P
680  .in 0  .in 0
681  Last updated: 18 January 2006  Last updated: 30 November 2006
682  .br  .br
683  Copyright (c) 1997-2006 University of Cambridge.  Copyright (c) 1997-2006 University of Cambridge.

Legend:
Removed from v.87  
changed lines
  Added in v.93

  ViewVC Help
Powered by ViewVC 1.1.5