/[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 211 by ph10, Thu Aug 9 09:52:43 2007 UTC revision 345 by ph10, Mon Apr 28 15:10:02 2008 UTC
# Line 85  DESCRIPTION Line 85  DESCRIPTION
85         "re>" to prompt for regular expressions, and "data>" to prompt for data         "re>" to prompt for regular expressions, and "data>" to prompt for data
86         lines.         lines.
87    
88           When  pcretest  is  built,  a  configuration option can specify that it
89           should be linked with the libreadline library. When this  is  done,  if
90           the input is from a terminal, it is read using the readline() function.
91           This provides line-editing and history facilities. The output from  the
92           -help option states whether or not readline() will be used.
93    
94         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.
95         Each set starts with a regular expression, and continues with any  num-         Each set starts with a regular expression, and continues with any  num-
96         ber of data lines to be matched against the pattern.         ber of data lines to be matched against the pattern.
# Line 146  PATTERN MODIFIERS Line 152  PATTERN MODIFIERS
152         The following table shows additional modifiers for setting PCRE options         The following table shows additional modifiers for setting PCRE options
153         that do not correspond to anything in Perl:         that do not correspond to anything in Perl:
154    
155           /A          PCRE_ANCHORED           /A              PCRE_ANCHORED
156           /C          PCRE_AUTO_CALLOUT           /C              PCRE_AUTO_CALLOUT
157           /E          PCRE_DOLLAR_ENDONLY           /E              PCRE_DOLLAR_ENDONLY
158           /f          PCRE_FIRSTLINE           /f              PCRE_FIRSTLINE
159           /J          PCRE_DUPNAMES           /J              PCRE_DUPNAMES
160           /N          PCRE_NO_AUTO_CAPTURE           /N              PCRE_NO_AUTO_CAPTURE
161           /U          PCRE_UNGREEDY           /U              PCRE_UNGREEDY
162           /X          PCRE_EXTRA           /X              PCRE_EXTRA
163           /<cr>       PCRE_NEWLINE_CR           /<JS>           PCRE_JAVASCRIPT_COMPAT
164           /<lf>       PCRE_NEWLINE_LF           /<cr>           PCRE_NEWLINE_CR
165           /<crlf>     PCRE_NEWLINE_CRLF           /<lf>           PCRE_NEWLINE_LF
166           /<anycrlf>  PCRE_NEWLINE_ANYCRLF           /<crlf>         PCRE_NEWLINE_CRLF
167           /<any>      PCRE_NEWLINE_ANY           /<anycrlf>      PCRE_NEWLINE_ANYCRLF
168             /<any>          PCRE_NEWLINE_ANY
169         Those  specifying  line ending sequencess are literal strings as shown.           /<bsr_anycrlf>  PCRE_BSR_ANYCRLF
170         This example sets multiline matching  with  CRLF  as  the  line  ending           /<bsr_unicode>  PCRE_BSR_UNICODE
171         sequence:  
172           Those  specifying  line  ending sequences are literal strings as shown,
173           but the letters can be in either  case.  This  example  sets  multiline
174           matching with CRLF as the line ending sequence:
175    
176           /^abc/m<crlf>           /^abc/m<crlf>
177    
# Line 413  DEFAULT OUTPUT FROM PCRETEST Line 422  DEFAULT OUTPUT FROM PCRETEST
422           data> xyz           data> xyz
423           No match           No match
424    
425         If  the strings contain any non-printing characters, they are output as         Note  that unset capturing substrings that are not followed by one that
426         \0x escapes, or as \x{...} escapes if the /8 modifier  was  present  on         is set are not returned by pcre_exec(), and are not shown by  pcretest.
427         the  pattern.  See below for the definition of non-printing characters.         In  the following example, there are two capturing substrings, but when
428         If the pattern has the /+ modifier, the output for substring 0 is  fol-         the first data line is matched, the  second,  unset  substring  is  not
429         lowed  by  the  the rest of the subject string, identified by "0+" like         shown.  An "internal" unset substring is shown as "<unset>", as for the
430           second data line.
431    
432               re> /(a)|(b)/
433             data> a
434              0: a
435              1: a
436             data> b
437              0: b
438              1: <unset>
439              2: b
440    
441           If the strings contain any non-printing characters, they are output  as
442           \0x  escapes,  or  as \x{...} escapes if the /8 modifier was present on
443           the pattern. See below for the definition of  non-printing  characters.
444           If  the pattern has the /+ modifier, the output for substring 0 is fol-
445           lowed by the the rest of the subject string, identified  by  "0+"  like
446         this:         this:
447    
448             re> /cat/+             re> /cat/+
# Line 425  DEFAULT OUTPUT FROM PCRETEST Line 450  DEFAULT OUTPUT FROM PCRETEST
450            0: cat            0: cat
451            0+ aract            0+ aract
452    
453         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
454         matching attempts are output in sequence, like this:         matching attempts are output in sequence, like this:
455    
456             re> /\Bi(\w\w)/g             re> /\Bi(\w\w)/g
# Line 439  DEFAULT OUTPUT FROM PCRETEST Line 464  DEFAULT OUTPUT FROM PCRETEST
464    
465         "No match" is output only if the first match attempt fails.         "No match" is output only if the first match attempt fails.
466    
467         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
468         is successfully matched, the substrings extracted  by  the  convenience         is  successfully  matched,  the substrings extracted by the convenience
469         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
470         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
471         (that  is,  the return from the extraction function) is given in paren-         (that is, the return from the extraction function) is given  in  paren-
472         theses after each string for \C and \G.         theses after each string for \C and \G.
473    
474         Note that whereas patterns can be continued over several lines (a plain         Note that whereas patterns can be continued over several lines (a plain
475         ">" prompt is used for continuations), data lines may not. However new-         ">" prompt is used for continuations), data lines may not. However new-
476         lines can be included in data by means of the \n escape (or  \r,  \r\n,         lines  can  be included in data by means of the \n escape (or \r, \r\n,
477         etc., depending on the newline sequence setting).         etc., depending on the newline sequence setting).
478    
479    
480  OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION  OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION
481    
482         When  the  alternative  matching function, pcre_dfa_exec(), is used (by         When the alternative matching function, pcre_dfa_exec(),  is  used  (by
483         means of the \D escape sequence or the -dfa command line  option),  the         means  of  the \D escape sequence or the -dfa command line option), the
484         output  consists  of  a list of all the matches that start at the first         output consists of a list of all the matches that start  at  the  first
485         point in the subject where there is at least one match. For example:         point in the subject where there is at least one match. For example:
486    
487             re> /(tang|tangerine|tan)/             re> /(tang|tangerine|tan)/
# Line 465  OUTPUT FROM THE ALTERNATIVE MATCHING FUN Line 490  OUTPUT FROM THE ALTERNATIVE MATCHING FUN
490            1: tang            1: tang
491            2: tan            2: tan
492    
493         (Using the normal matching function on this data  finds  only  "tang".)         (Using  the  normal  matching function on this data finds only "tang".)
494         The  longest matching string is always given first (and numbered zero).         The longest matching string is always given first (and numbered  zero).
495    
496         If /g is present on the pattern, the search for further matches resumes         If /g is present on the pattern, the search for further matches resumes
497         at the end of the longest match. For example:         at the end of the longest match. For example:
# Line 480  OUTPUT FROM THE ALTERNATIVE MATCHING FUN Line 505  OUTPUT FROM THE ALTERNATIVE MATCHING FUN
505            1: tan            1: tan
506            0: tan            0: tan
507    
508         Since  the  matching  function  does not support substring capture, the         Since the matching function does not  support  substring  capture,  the
509         escape sequences that are concerned with captured  substrings  are  not         escape  sequences  that  are concerned with captured substrings are not
510         relevant.         relevant.
511    
512    
513  RESTARTING AFTER A PARTIAL MATCH  RESTARTING AFTER A PARTIAL MATCH
514    
515         When the alternative matching function has given the PCRE_ERROR_PARTIAL         When the alternative matching function has given the PCRE_ERROR_PARTIAL
516         return, indicating that the subject partially matched the pattern,  you         return,  indicating that the subject partially matched the pattern, you
517         can  restart  the match with additional subject data by means of the \R         can restart the match with additional subject data by means of  the  \R
518         escape sequence. For example:         escape sequence. For example:
519    
520             re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/             re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
# Line 498  RESTARTING AFTER A PARTIAL MATCH Line 523  RESTARTING AFTER A PARTIAL MATCH
523           data> n05\R\D           data> n05\R\D
524            0: n05            0: n05
525    
526         For further information about partial  matching,  see  the  pcrepartial         For  further  information  about  partial matching, see the pcrepartial
527         documentation.         documentation.
528    
529    
530  CALLOUTS  CALLOUTS
531    
532         If  the pattern contains any callout requests, pcretest's callout func-         If the pattern contains any callout requests, pcretest's callout  func-
533         tion is called during matching. This works  with  both  matching  func-         tion  is  called  during  matching. This works with both matching func-
534         tions. By default, the called function displays the callout number, the         tions. By default, the called function displays the callout number, the
535         start and current positions in the text at the callout  time,  and  the         start  and  current  positions in the text at the callout time, and the
536         next pattern item to be tested. For example, the output         next pattern item to be tested. For example, the output
537    
538           --->pqrabcdef           --->pqrabcdef
539             0    ^  ^     \d             0    ^  ^     \d
540    
541         indicates  that  callout number 0 occurred for a match attempt starting         indicates that callout number 0 occurred for a match  attempt  starting
542         at the fourth character of the subject string, when the pointer was  at         at  the fourth character of the subject string, when the pointer was at
543         the  seventh  character of the data, and when the next pattern item was         the seventh character of the data, and when the next pattern  item  was
544         \d. Just one circumflex is output if the start  and  current  positions         \d.  Just  one  circumflex is output if the start and current positions
545         are the same.         are the same.
546    
547         Callouts numbered 255 are assumed to be automatic callouts, inserted as         Callouts numbered 255 are assumed to be automatic callouts, inserted as
548         a result of the /C pattern modifier. In this case, instead  of  showing         a  result  of the /C pattern modifier. In this case, instead of showing
549         the  callout  number, the offset in the pattern, preceded by a plus, is         the callout number, the offset in the pattern, preceded by a  plus,  is
550         output. For example:         output. For example:
551    
552             re> /\d?[A-E]\*/C             re> /\d?[A-E]\*/C
# Line 533  CALLOUTS Line 558  CALLOUTS
558           +10 ^ ^           +10 ^ ^
559            0: E*            0: E*
560    
561         The callout function in pcretest returns zero (carry  on  matching)  by         The  callout  function  in pcretest returns zero (carry on matching) by
562         default,  but you can use a \C item in a data line (as described above)         default, but you can use a \C item in a data line (as described  above)
563         to change this.         to change this.
564    
565         Inserting callouts can be helpful when using pcretest to check  compli-         Inserting  callouts can be helpful when using pcretest to check compli-
566         cated  regular expressions. For further information about callouts, see         cated regular expressions. For further information about callouts,  see
567         the pcrecallout documentation.         the pcrecallout documentation.
568    
569    
570  NON-PRINTING CHARACTERS  NON-PRINTING CHARACTERS
571    
572         When pcretest is outputting text in the compiled version of a  pattern,         When  pcretest is outputting text in the compiled version of a pattern,
573         bytes  other  than 32-126 are always treated as non-printing characters         bytes other than 32-126 are always treated as  non-printing  characters
574         are are therefore shown as hex escapes.         are are therefore shown as hex escapes.
575    
576         When pcretest is outputting text that is a matched part  of  a  subject         When  pcretest  is  outputting text that is a matched part of a subject
577         string,  it behaves in the same way, unless a different locale has been         string, it behaves in the same way, unless a different locale has  been
578         set for the  pattern  (using  the  /L  modifier).  In  this  case,  the         set  for  the  pattern  (using  the  /L  modifier).  In  this case, the
579         isprint() function to distinguish printing and non-printing characters.         isprint() function to distinguish printing and non-printing characters.
580    
581    
582  SAVING AND RELOADING COMPILED PATTERNS  SAVING AND RELOADING COMPILED PATTERNS
583    
584         The facilities described in this section are  not  available  when  the         The  facilities  described  in  this section are not available when the
585         POSIX inteface to PCRE is being used, that is, when the /P pattern mod-         POSIX inteface to PCRE is being used, that is, when the /P pattern mod-
586         ifier is specified.         ifier is specified.
587    
588         When the POSIX interface is not in use, you can cause pcretest to write         When the POSIX interface is not in use, you can cause pcretest to write
589         a  compiled  pattern to a file, by following the modifiers with > and a         a compiled pattern to a file, by following the modifiers with >  and  a
590         file name.  For example:         file name.  For example:
591    
592           /pattern/im >/some/file           /pattern/im >/some/file
593    
594         See the pcreprecompile documentation for a discussion about saving  and         See  the pcreprecompile documentation for a discussion about saving and
595         re-using compiled patterns.         re-using compiled patterns.
596    
597         The  data  that  is  written  is  binary. The first eight bytes are the         The data that is written is binary.  The  first  eight  bytes  are  the
598         length of the compiled pattern data  followed  by  the  length  of  the         length  of  the  compiled  pattern  data  followed by the length of the
599         optional  study  data,  each  written as four bytes in big-endian order         optional study data, each written as four  bytes  in  big-endian  order
600         (most significant byte first). If there is no study  data  (either  the         (most  significant  byte  first). If there is no study data (either the
601         pattern was not studied, or studying did not return any data), the sec-         pattern was not studied, or studying did not return any data), the sec-
602         ond length is zero. The lengths are followed by an exact  copy  of  the         ond  length  is  zero. The lengths are followed by an exact copy of the
603         compiled pattern. If there is additional study data, this follows imme-         compiled pattern. If there is additional study data, this follows imme-
604         diately after the compiled pattern. After writing  the  file,  pcretest         diately  after  the  compiled pattern. After writing the file, pcretest
605         expects to read a new pattern.         expects to read a new pattern.
606    
607         A saved pattern can be reloaded into pcretest by specifing < and a file         A saved pattern can be reloaded into pcretest by specifing < and a file
608         name instead of a pattern. The name of the file must not  contain  a  <         name  instead  of  a pattern. The name of the file must not contain a <
609         character,  as  otherwise pcretest will interpret the line as a pattern         character, as otherwise pcretest will interpret the line as  a  pattern
610         delimited by < characters.  For example:         delimited by < characters.  For example:
611    
612            re> </some/file            re> </some/file
613           Compiled regex loaded from /some/file           Compiled regex loaded from /some/file
614           No study data           No study data
615    
616         When the pattern has been loaded, pcretest proceeds to read data  lines         When  the pattern has been loaded, pcretest proceeds to read data lines
617         in the usual way.         in the usual way.
618    
619         You  can copy a file written by pcretest to a different host and reload         You can copy a file written by pcretest to a different host and  reload
620         it there, even if the new host has opposite endianness to  the  one  on         it  there,  even  if the new host has opposite endianness to the one on
621         which  the pattern was compiled. For example, you can compile on an i86         which the pattern was compiled. For example, you can compile on an  i86
622         machine and run on a SPARC machine.         machine and run on a SPARC machine.
623    
624         File names for saving and reloading can be absolute  or  relative,  but         File  names  for  saving and reloading can be absolute or relative, but
625         note  that the shell facility of expanding a file name that starts with         note that the shell facility of expanding a file name that starts  with
626         a tilde (~) is not available.         a tilde (~) is not available.
627    
628         The ability to save and reload files in pcretest is intended for  test-         The  ability to save and reload files in pcretest is intended for test-
629         ing  and experimentation. It is not intended for production use because         ing and experimentation. It is not intended for production use  because
630         only a single pattern can be written to a file. Furthermore,  there  is         only  a  single pattern can be written to a file. Furthermore, there is
631         no  facility  for  supplying  custom  character  tables  for use with a         no facility for supplying  custom  character  tables  for  use  with  a
632         reloaded pattern. If the original  pattern  was  compiled  with  custom         reloaded  pattern.  If  the  original  pattern was compiled with custom
633         tables,  an  attempt to match a subject string using a reloaded pattern         tables, an attempt to match a subject string using a  reloaded  pattern
634         is likely to cause pcretest to crash.  Finally, if you attempt to  load         is  likely to cause pcretest to crash.  Finally, if you attempt to load
635         a file that is not in the correct format, the result is undefined.         a file that is not in the correct format, the result is undefined.
636    
637    
638  SEE ALSO  SEE ALSO
639    
640         pcre(3),  pcreapi(3),  pcrecallout(3), pcrematching(3), pcrepartial(d),         pcre(3), pcreapi(3), pcrecallout(3),  pcrematching(3),  pcrepartial(d),
641         pcrepattern(3), pcreprecompile(3).         pcrepattern(3), pcreprecompile(3).
642    
643    
# Line 625  AUTHOR Line 650  AUTHOR
650    
651  REVISION  REVISION
652    
653         Last updated: 09 August 2007         Last updated: 12 April 2008
654         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2008 University of Cambridge.

Legend:
Removed from v.211  
changed lines
  Added in v.345

  ViewVC Help
Powered by ViewVC 1.1.5