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

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

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

revision 87 by nigel, Sat Feb 24 21:41:21 2007 UTC revision 91 by nigel, Sat Feb 24 21:41:34 2007 UTC
# Line 7  NAME Line 7  NAME
7    
8  SYNOPSIS  SYNOPSIS
9    
10         pcretest [-C] [-d] [-dfa] [-i] [-m] [-o osize] [-p] [-t] [source]         pcretest [options] [source] [destination]
             [destination]  
11    
12         pcretest  was written as a test program for the PCRE regular expression         pcretest  was written as a test program for the PCRE regular expression
13         library itself, but it can also be used for experimenting with  regular         library itself, but it can also be used for experimenting with  regular
# Line 53  OPTIONS Line 52  OPTIONS
52         -q        Do not output the version number of pcretest at the start  of         -q        Do not output the version number of pcretest at the start  of
53                   execution.                   execution.
54    
55         -t        Run  each  compile, study, and match many times with a timer,         -S size   On  Unix-like  systems,  set the size of the runtime stack to
56                   and output resulting time per compile or match (in  millisec-                   size megabytes.
57                   onds).  Do  not set -m with -t, because you will then get the  
58                   size output a zillion times, and  the  timing  will  be  dis-         -t        Run each compile, study, and match many times with  a  timer,
59                     and  output resulting time per compile or match (in millisec-
60                     onds). Do not set -m with -t, because you will then  get  the
61                     size  output  a  zillion  times,  and the timing will be dis-
62                   torted.                   torted.
63    
64    
65  DESCRIPTION  DESCRIPTION
66    
67         If  pcretest  is  given two filename arguments, it reads from the first         If pcretest is given two filename arguments, it reads  from  the  first
68         and writes to the second. If it is given only one filename argument, it         and writes to the second. If it is given only one filename argument, it
69         reads  from  that  file  and writes to stdout. Otherwise, it reads from         reads from that file and writes to stdout.  Otherwise,  it  reads  from
70         stdin and writes to stdout, and prompts for each line of  input,  using         stdin  and  writes to stdout, and prompts for each line of input, using
71         "re>" to prompt for regular expressions, and "data>" to prompt for data         "re>" to prompt for regular expressions, and "data>" to prompt for data
72         lines.         lines.
73    
74         The program handles any number of sets of input on a single input file.         The program handles any number of sets of input on a single input file.
75         Each  set starts with a regular expression, and continues with any num-         Each set starts with a regular expression, and continues with any  num-
76         ber of data lines to be matched against the pattern.         ber of data lines to be matched against the pattern.
77    
78         Each data line is matched separately and independently. If you want  to         Each  data line is matched separately and independently. If you want to
79         do  multiple-line  matches, you have to use the \n escape sequence in a         do multi-line matches, you have to use the \n escape sequence (or \r or
80         single line of input to encode  the  newline  characters.  The  maximum         \r\n,  depending  on  the newline setting) in a single line of input to
81         length of data line is 30,000 characters.         encode the newline characters. There is no limit on the length of  data
82           lines; the input buffer is automatically extended if it is too small.
83    
84         An  empty  line signals the end of the data lines, at which point a new         An  empty  line signals the end of the data lines, at which point a new
85         regular expression is read. The regular expressions are given  enclosed         regular expression is read. The regular expressions are given  enclosed
86         in any non-alphanumeric delimiters other than backslash, for example         in any non-alphanumeric delimiters other than backslash, for example:
87    
88           /(a|bc)x+yz/           /(a|bc)x+yz/
89    
# Line 128  PATTERN MODIFIERS Line 131  PATTERN MODIFIERS
131         The following table shows additional modifiers for setting PCRE options         The following table shows additional modifiers for setting PCRE options
132         that do not correspond to anything in Perl:         that do not correspond to anything in Perl:
133    
134           /A    PCRE_ANCHORED           /A       PCRE_ANCHORED
135           /C    PCRE_AUTO_CALLOUT           /C       PCRE_AUTO_CALLOUT
136           /E    PCRE_DOLLAR_ENDONLY           /E       PCRE_DOLLAR_ENDONLY
137           /f    PCRE_FIRSTLINE           /f       PCRE_FIRSTLINE
138           /N    PCRE_NO_AUTO_CAPTURE           /J       PCRE_DUPNAMES
139           /U    PCRE_UNGREEDY           /N       PCRE_NO_AUTO_CAPTURE
140           /X    PCRE_EXTRA           /U       PCRE_UNGREEDY
141             /X       PCRE_EXTRA
142             /<cr>    PCRE_NEWLINE_CR
143             /<lf>    PCRE_NEWLINE_LF
144             /<crlf>  PCRE_NEWLINE_CRLF
145    
146           Those specifying line endings are literal strings as shown. Details  of
147           the  meanings of these PCRE options are given in the pcreapi documenta-
148           tion.
149    
150       Finding all matches in a string
151    
152         Searching for all possible matches within each subject  string  can  be         Searching for all possible matches within each subject  string  can  be
153         requested  by  the  /g  or  /G modifier. After finding a match, PCRE is         requested  by  the  /g  or  /G modifier. After finding a match, PCRE is
# Line 153  PATTERN MODIFIERS Line 166  PATTERN MODIFIERS
166         one, and the normal match is retried. This imitates the way  Perl  han-         one, and the normal match is retried. This imitates the way  Perl  han-
167         dles such cases when using the /g modifier or the split() function.         dles such cases when using the /g modifier or the split() function.
168    
169       Other modifiers
170    
171         There are yet more modifiers for controlling the way pcretest operates.         There are yet more modifiers for controlling the way pcretest operates.
172    
173         The /+ modifier requests that as well as outputting the substring  that         The /+ modifier requests that as well as outputting the substring  that
# Line 228  DATA LINES Line 243  DATA LINES
243           \e         escape           \e         escape
244           \f         formfeed           \f         formfeed
245           \n         newline           \n         newline
246             \qdd       set the PCRE_MATCH_LIMIT limit to dd
247                          (any number of digits)
248           \r         carriage return           \r         carriage return
249           \t         tab           \t         tab
250           \v         vertical tab           \v         vertical tab
# Line 236  DATA LINES Line 253  DATA LINES
253           \x{hh...}  hexadecimal character, any number of digits           \x{hh...}  hexadecimal character, any number of digits
254                        in UTF-8 mode                        in UTF-8 mode
255           \A         pass the PCRE_ANCHORED option to pcre_exec()           \A         pass the PCRE_ANCHORED option to pcre_exec()
256                          or pcre_dfa_exec()
257           \B         pass the PCRE_NOTBOL option to pcre_exec()           \B         pass the PCRE_NOTBOL option to pcre_exec()
258                          or pcre_dfa_exec()
259           \Cdd       call pcre_copy_substring() for substring dd           \Cdd       call pcre_copy_substring() for substring dd
260                        after a successful match (number less than 32)                        after a successful match (number less than 32)
261           \Cname     call pcre_copy_named_substring() for substring           \Cname     call pcre_copy_named_substring() for substring
# Line 263  DATA LINES Line 282  DATA LINES
282           \M         discover the minimum MATCH_LIMIT and           \M         discover the minimum MATCH_LIMIT and
283                        MATCH_LIMIT_RECURSION settings                        MATCH_LIMIT_RECURSION settings
284           \N         pass the PCRE_NOTEMPTY option to pcre_exec()           \N         pass the PCRE_NOTEMPTY option to pcre_exec()
285                          or pcre_dfa_exec()
286           \Odd       set the size of the output vector passed to           \Odd       set the size of the output vector passed to
287                        pcre_exec() to dd (any number of digits)                        pcre_exec() to dd (any number of digits)
288           \P         pass the PCRE_PARTIAL option to pcre_exec()           \P         pass the PCRE_PARTIAL option to pcre_exec()
289                        or pcre_dfa_exec()                        or pcre_dfa_exec()
290             \Qdd       set the PCRE_MATCH_LIMIT_RECURSION limit to dd
291                          (any number of digits)
292           \R         pass the PCRE_DFA_RESTART option to pcre_dfa_exec()           \R         pass the PCRE_DFA_RESTART option to pcre_dfa_exec()
293           \S         output details of memory get/free calls during matching           \S         output details of memory get/free calls during matching
294           \Z         pass the PCRE_NOTEOL option to pcre_exec()           \Z         pass the PCRE_NOTEOL option to pcre_exec()
295                          or pcre_dfa_exec()
296           \?         pass the PCRE_NO_UTF8_CHECK option to           \?         pass the PCRE_NO_UTF8_CHECK option to
297                        pcre_exec()                        pcre_exec() or pcre_dfa_exec()
298           \>dd       start the match at offset dd (any number of digits);           \>dd       start the match at offset dd (any number of digits);
299                        this sets the startoffset argument for pcre_exec()                        this sets the startoffset argument for pcre_exec()
300                          or pcre_dfa_exec()
301             \<cr>      pass the PCRE_NEWLINE_CR option to pcre_exec()
302                          or pcre_dfa_exec()
303             \<lf>      pass the PCRE_NEWLINE_LF option to pcre_exec()
304                          or pcre_dfa_exec()
305             \<crlf>    pass the PCRE_NEWLINE_CRLF option to pcre_exec()
306                          or pcre_dfa_exec()
307    
308         A  backslash  followed by anything else just escapes the anything else.         The  escapes  that specify line endings are literal strings, exactly as
309         If the very last character is a backslash, it is ignored. This gives  a         shown.  A backslash followed by anything else just escapes the anything
310         way  of  passing  an empty line as data, since a real empty line termi-         else.  If  the  very last character is a backslash, it is ignored. This
311         nates the data input.         gives a way of passing an empty line as data, since a real  empty  line
312           terminates the data input.
313         If \M is present, pcretest calls pcre_exec() several times,  with  dif-  
314         ferent  values  in  the match_limit and match_limit_recursion fields of         If  \M  is present, pcretest calls pcre_exec() several times, with dif-
315         the pcre_extra data structure, until it finds the minimum  numbers  for         ferent values in the match_limit and  match_limit_recursion  fields  of
316           the  pcre_extra  data structure, until it finds the minimum numbers for
317         each parameter that allow pcre_exec() to complete. The match_limit num-         each parameter that allow pcre_exec() to complete. The match_limit num-
318         ber is a measure of the amount of backtracking that  takes  place,  and         ber  is  a  measure of the amount of backtracking that takes place, and
319         checking it out can be instructive. For most simple matches, the number         checking it out can be instructive. For most simple matches, the number
320         is quite small, but for patterns with very large  numbers  of  matching         is  quite  small,  but for patterns with very large numbers of matching
321         possibilities,  it can become large very quickly with increasing length         possibilities, it can become large very quickly with increasing  length
322         of subject string. The match_limit_recursion number is a measure of how         of subject string. The match_limit_recursion number is a measure of how
323         much  stack  (or,  if  PCRE is compiled with NO_RECURSE, how much heap)         much stack (or, if PCRE is compiled with  NO_RECURSE,  how  much  heap)
324         memory is needed to complete the match attempt.         memory is needed to complete the match attempt.
325    
326         When \O is used, the value specified may be higher or  lower  than  the         When  \O  is  used, the value specified may be higher or lower than the
327         size set by the -O command line option (or defaulted to 45); \O applies         size set by the -O command line option (or defaulted to 45); \O applies
328         only to the call of pcre_exec() for the line in which it appears.         only to the call of pcre_exec() for the line in which it appears.
329    
330         If the /P modifier was present on the pattern, causing the POSIX  wrap-         If  the /P modifier was present on the pattern, causing the POSIX wrap-
331         per  API  to  be  used, the only option-setting sequences that have any         per API to be used, the only option-setting  sequences  that  have  any
332         effect are \B and \Z, causing REG_NOTBOL and REG_NOTEOL,  respectively,         effect  are \B and \Z, causing REG_NOTBOL and REG_NOTEOL, respectively,
333         to be passed to regexec().         to be passed to regexec().
334    
335         The  use of \x{hh...} to represent UTF-8 characters is not dependent on         The use of \x{hh...} to represent UTF-8 characters is not dependent  on
336         the use of the /8 modifier on the pattern.  It  is  recognized  always.         the  use  of  the  /8 modifier on the pattern. It is recognized always.
337         There  may  be  any number of hexadecimal digits inside the braces. The         There may be any number of hexadecimal digits inside  the  braces.  The
338         result is from one to six bytes, encoded according to the UTF-8  rules.         result  is from one to six bytes, encoded according to the UTF-8 rules.
339    
340    
341  THE ALTERNATIVE MATCHING FUNCTION  THE ALTERNATIVE MATCHING FUNCTION
342    
343         By   default,  pcretest  uses  the  standard  PCRE  matching  function,         By  default,  pcretest  uses  the  standard  PCRE  matching   function,
344         pcre_exec() to match each data line. From release 6.0, PCRE supports an         pcre_exec() to match each data line. From release 6.0, PCRE supports an
345         alternative  matching  function,  pcre_dfa_test(),  which operates in a         alternative matching function, pcre_dfa_test(),  which  operates  in  a
346         different way, and has some restrictions. The differences  between  the         different  way,  and has some restrictions. The differences between the
347         two functions are described in the pcrematching documentation.         two functions are described in the pcrematching documentation.
348    
349         If  a data line contains the \D escape sequence, or if the command line         If a data line contains the \D escape sequence, or if the command  line
350         contains the -dfa option, the alternative matching function is  called.         contains  the -dfa option, the alternative matching function is called.
351         This function finds all possible matches at a given point. If, however,         This function finds all possible matches at a given point. If, however,
352         the \F escape sequence is present in the data line, it stops after  the         the  \F escape sequence is present in the data line, it stops after the
353         first match is found. This is always the shortest possible match.         first match is found. This is always the shortest possible match.
354    
355    
356  DEFAULT OUTPUT FROM PCRETEST  DEFAULT OUTPUT FROM PCRETEST
357    
358         This  section  describes  the output when the normal matching function,         This section describes the output when the  normal  matching  function,
359         pcre_exec(), is being used.         pcre_exec(), is being used.
360    
361         When a match succeeds, pcretest outputs the list of captured substrings         When a match succeeds, pcretest outputs the list of captured substrings
362         that  pcre_exec()  returns,  starting with number 0 for the string that         that pcre_exec() returns, starting with number 0 for  the  string  that
363         matched the whole pattern. Otherwise, it outputs "No match" or "Partial         matched the whole pattern. Otherwise, it outputs "No match" or "Partial
364         match"  when  pcre_exec() returns PCRE_ERROR_NOMATCH or PCRE_ERROR_PAR-         match" when pcre_exec() returns PCRE_ERROR_NOMATCH  or  PCRE_ERROR_PAR-
365         TIAL, respectively, and otherwise the PCRE negative error number.  Here         TIAL,  respectively, and otherwise the PCRE negative error number. Here
366         is an example of an interactive pcretest run.         is an example of an interactive pcretest run.
367    
368           $ pcretest           $ pcretest
# Line 344  DEFAULT OUTPUT FROM PCRETEST Line 375  DEFAULT OUTPUT FROM PCRETEST
375           data> xyz           data> xyz
376           No match           No match
377    
378         If  the strings contain any non-printing characters, they are output as         If the strings contain any non-printing characters, they are output  as
379         \0x escapes, or as \x{...} escapes if the /8 modifier  was  present  on         \0x  escapes,  or  as \x{...} escapes if the /8 modifier was present on
380         the  pattern.  If  the pattern has the /+ modifier, the output for sub-         the pattern. If the pattern has the /+ modifier, the  output  for  sub-
381         string 0 is followed by the the rest of the subject string,  identified         string  0 is followed by the the rest of the subject string, identified
382         by "0+" like this:         by "0+" like this:
383    
384             re> /cat/+             re> /cat/+
# Line 355  DEFAULT OUTPUT FROM PCRETEST Line 386  DEFAULT OUTPUT FROM PCRETEST
386            0: cat            0: cat
387            0+ aract            0+ aract
388    
389         If  the  pattern  has  the /g or /G modifier, the results of successive         If the pattern has the /g or /G modifier,  the  results  of  successive
390         matching attempts are output in sequence, like this:         matching attempts are output in sequence, like this:
391    
392             re> /\Bi(\w\w)/g             re> /\Bi(\w\w)/g
# Line 369  DEFAULT OUTPUT FROM PCRETEST Line 400  DEFAULT OUTPUT FROM PCRETEST
400    
401         "No match" is output only if the first match attempt fails.         "No match" is output only if the first match attempt fails.
402    
403         If any of the sequences \C, \G, or \L are present in a data  line  that         If  any  of the sequences \C, \G, or \L are present in a data line that
404         is  successfully  matched,  the substrings extracted by the convenience         is successfully matched, the substrings extracted  by  the  convenience
405         functions are output with C, G, or L after the string number instead of         functions are output with C, G, or L after the string number instead of
406         a colon. This is in addition to the normal full list. The string length         a colon. This is in addition to the normal full list. The string length
407         (that is, the return from the extraction function) is given  in  paren-         (that  is,  the return from the extraction function) is given in paren-
408         theses after each string for \C and \G.         theses after each string for \C and \G.
409    
410         Note  that  while patterns can be continued over several lines (a plain         Note that while patterns can be continued over several lines  (a  plain
411         ">" prompt is used for continuations), data lines may not. However new-         ">" prompt is used for continuations), data lines may not. However new-
412         lines can be included in data by means of the \n escape.         lines can be included in data by means of the \n escape (or \r or  \r\n
413           for those newline settings).
414    
415    
416  OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION  OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION
# Line 533  AUTHOR Line 565  AUTHOR
565         University Computing Service,         University Computing Service,
566         Cambridge CB2 3QG, England.         Cambridge CB2 3QG, England.
567    
568  Last updated: 18 January 2006  Last updated: 29 June 2006
569  Copyright (c) 1997-2006 University of Cambridge.  Copyright (c) 1997-2006 University of Cambridge.

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

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12