/[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 289 by ph10, Sun Dec 23 12:17:20 2007 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           /<cr>           PCRE_NEWLINE_CR
164           /<lf>       PCRE_NEWLINE_LF           /<lf>           PCRE_NEWLINE_LF
165           /<crlf>     PCRE_NEWLINE_CRLF           /<crlf>         PCRE_NEWLINE_CRLF
166           /<anycrlf>  PCRE_NEWLINE_ANYCRLF           /<anycrlf>      PCRE_NEWLINE_ANYCRLF
167           /<any>      PCRE_NEWLINE_ANY           /<any>          PCRE_NEWLINE_ANY
168             /<bsr_anycrlf>  PCRE_BSR_ANYCRLF
169         Those  specifying  line ending sequencess are literal strings as shown.           /<bsr_unicode>  PCRE_BSR_UNICODE
170         This example sets multiline matching  with  CRLF  as  the  line  ending  
171         sequence:         Those  specifying  line  ending sequences are literal strings as shown,
172           but the letters can be in either  case.  This  example  sets  multiline
173           matching with CRLF as the line ending sequence:
174    
175           /^abc/m<crlf>           /^abc/m<crlf>
176    
# Line 413  DEFAULT OUTPUT FROM PCRETEST Line 421  DEFAULT OUTPUT FROM PCRETEST
421           data> xyz           data> xyz
422           No match           No match
423    
424         If  the strings contain any non-printing characters, they are output as         Note  that unset capturing substrings that are not followed by one that
425         \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.
426         the  pattern.  See below for the definition of non-printing characters.         In  the following example, there are two capturing substrings, but when
427         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
428         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
429           second data line.
430    
431               re> /(a)|(b)/
432             data> a
433              0: a
434              1: a
435             data> b
436              0: b
437              1: <unset>
438              2: b
439    
440           If the strings contain any non-printing characters, they are output  as
441           \0x  escapes,  or  as \x{...} escapes if the /8 modifier was present on
442           the pattern. See below for the definition of  non-printing  characters.
443           If  the pattern has the /+ modifier, the output for substring 0 is fol-
444           lowed by the the rest of the subject string, identified  by  "0+"  like
445         this:         this:
446    
447             re> /cat/+             re> /cat/+
# Line 425  DEFAULT OUTPUT FROM PCRETEST Line 449  DEFAULT OUTPUT FROM PCRETEST
449            0: cat            0: cat
450            0+ aract            0+ aract
451    
452         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
453         matching attempts are output in sequence, like this:         matching attempts are output in sequence, like this:
454    
455             re> /\Bi(\w\w)/g             re> /\Bi(\w\w)/g
# Line 439  DEFAULT OUTPUT FROM PCRETEST Line 463  DEFAULT OUTPUT FROM PCRETEST
463    
464         "No match" is output only if the first match attempt fails.         "No match" is output only if the first match attempt fails.
465    
466         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
467         is successfully matched, the substrings extracted  by  the  convenience         is  successfully  matched,  the substrings extracted by the convenience
468         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
469         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
470         (that  is,  the return from the extraction function) is given in paren-         (that is, the return from the extraction function) is given  in  paren-
471         theses after each string for \C and \G.         theses after each string for \C and \G.
472    
473         Note that whereas patterns can be continued over several lines (a plain         Note that whereas patterns can be continued over several lines (a plain
474         ">" prompt is used for continuations), data lines may not. However new-         ">" prompt is used for continuations), data lines may not. However new-
475         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,
476         etc., depending on the newline sequence setting).         etc., depending on the newline sequence setting).
477    
478    
479  OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION  OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION
480    
481         When  the  alternative  matching function, pcre_dfa_exec(), is used (by         When the alternative matching function, pcre_dfa_exec(),  is  used  (by
482         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
483         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
484         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:
485    
486             re> /(tang|tangerine|tan)/             re> /(tang|tangerine|tan)/
# Line 465  OUTPUT FROM THE ALTERNATIVE MATCHING FUN Line 489  OUTPUT FROM THE ALTERNATIVE MATCHING FUN
489            1: tang            1: tang
490            2: tan            2: tan
491    
492         (Using the normal matching function on this data  finds  only  "tang".)         (Using  the  normal  matching function on this data finds only "tang".)
493         The  longest matching string is always given first (and numbered zero).         The longest matching string is always given first (and numbered  zero).
494    
495         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
496         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 504  OUTPUT FROM THE ALTERNATIVE MATCHING FUN
504            1: tan            1: tan
505            0: tan            0: tan
506    
507         Since  the  matching  function  does not support substring capture, the         Since the matching function does not  support  substring  capture,  the
508         escape sequences that are concerned with captured  substrings  are  not         escape  sequences  that  are concerned with captured substrings are not
509         relevant.         relevant.
510    
511    
512  RESTARTING AFTER A PARTIAL MATCH  RESTARTING AFTER A PARTIAL MATCH
513    
514         When the alternative matching function has given the PCRE_ERROR_PARTIAL         When the alternative matching function has given the PCRE_ERROR_PARTIAL
515         return, indicating that the subject partially matched the pattern,  you         return,  indicating that the subject partially matched the pattern, you
516         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
517         escape sequence. For example:         escape sequence. For example:
518    
519             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 522  RESTARTING AFTER A PARTIAL MATCH
522           data> n05\R\D           data> n05\R\D
523            0: n05            0: n05
524    
525         For further information about partial  matching,  see  the  pcrepartial         For  further  information  about  partial matching, see the pcrepartial
526         documentation.         documentation.
527    
528    
529  CALLOUTS  CALLOUTS
530    
531         If  the pattern contains any callout requests, pcretest's callout func-         If the pattern contains any callout requests, pcretest's callout  func-
532         tion is called during matching. This works  with  both  matching  func-         tion  is  called  during  matching. This works with both matching func-
533         tions. By default, the called function displays the callout number, the         tions. By default, the called function displays the callout number, the
534         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
535         next pattern item to be tested. For example, the output         next pattern item to be tested. For example, the output
536    
537           --->pqrabcdef           --->pqrabcdef
538             0    ^  ^     \d             0    ^  ^     \d
539    
540         indicates  that  callout number 0 occurred for a match attempt starting         indicates that callout number 0 occurred for a match  attempt  starting
541         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
542         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
543         \d. Just one circumflex is output if the start  and  current  positions         \d.  Just  one  circumflex is output if the start and current positions
544         are the same.         are the same.
545    
546         Callouts numbered 255 are assumed to be automatic callouts, inserted as         Callouts numbered 255 are assumed to be automatic callouts, inserted as
547         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
548         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
549         output. For example:         output. For example:
550    
551             re> /\d?[A-E]\*/C             re> /\d?[A-E]\*/C
# Line 533  CALLOUTS Line 557  CALLOUTS
557           +10 ^ ^           +10 ^ ^
558            0: E*            0: E*
559    
560         The callout function in pcretest returns zero (carry  on  matching)  by         The  callout  function  in pcretest returns zero (carry on matching) by
561         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)
562         to change this.         to change this.
563    
564         Inserting callouts can be helpful when using pcretest to check  compli-         Inserting  callouts can be helpful when using pcretest to check compli-
565         cated  regular expressions. For further information about callouts, see         cated regular expressions. For further information about callouts,  see
566         the pcrecallout documentation.         the pcrecallout documentation.
567    
568    
569  NON-PRINTING CHARACTERS  NON-PRINTING CHARACTERS
570    
571         When pcretest is outputting text in the compiled version of a  pattern,         When  pcretest is outputting text in the compiled version of a pattern,
572         bytes  other  than 32-126 are always treated as non-printing characters         bytes other than 32-126 are always treated as  non-printing  characters
573         are are therefore shown as hex escapes.         are are therefore shown as hex escapes.
574    
575         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
576         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
577         set for the  pattern  (using  the  /L  modifier).  In  this  case,  the         set  for  the  pattern  (using  the  /L  modifier).  In  this case, the
578         isprint() function to distinguish printing and non-printing characters.         isprint() function to distinguish printing and non-printing characters.
579    
580    
581  SAVING AND RELOADING COMPILED PATTERNS  SAVING AND RELOADING COMPILED PATTERNS
582    
583         The facilities described in this section are  not  available  when  the         The  facilities  described  in  this section are not available when the
584         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-
585         ifier is specified.         ifier is specified.
586    
587         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
588         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
589         file name.  For example:         file name.  For example:
590    
591           /pattern/im >/some/file           /pattern/im >/some/file
592    
593         See the pcreprecompile documentation for a discussion about saving  and         See  the pcreprecompile documentation for a discussion about saving and
594         re-using compiled patterns.         re-using compiled patterns.
595    
596         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
597         length of the compiled pattern data  followed  by  the  length  of  the         length  of  the  compiled  pattern  data  followed by the length of the
598         optional  study  data,  each  written as four bytes in big-endian order         optional study data, each written as four  bytes  in  big-endian  order
599         (most significant byte first). If there is no study  data  (either  the         (most  significant  byte  first). If there is no study data (either the
600         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-
601         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
602         compiled pattern. If there is additional study data, this follows imme-         compiled pattern. If there is additional study data, this follows imme-
603         diately after the compiled pattern. After writing  the  file,  pcretest         diately  after  the  compiled pattern. After writing the file, pcretest
604         expects to read a new pattern.         expects to read a new pattern.
605    
606         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
607         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 <
608         character,  as  otherwise pcretest will interpret the line as a pattern         character, as otherwise pcretest will interpret the line as  a  pattern
609         delimited by < characters.  For example:         delimited by < characters.  For example:
610    
611            re> </some/file            re> </some/file
612           Compiled regex loaded from /some/file           Compiled regex loaded from /some/file
613           No study data           No study data
614    
615         When the pattern has been loaded, pcretest proceeds to read data  lines         When  the pattern has been loaded, pcretest proceeds to read data lines
616         in the usual way.         in the usual way.
617    
618         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
619         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
620         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
621         machine and run on a SPARC machine.         machine and run on a SPARC machine.
622    
623         File names for saving and reloading can be absolute  or  relative,  but         File  names  for  saving and reloading can be absolute or relative, but
624         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
625         a tilde (~) is not available.         a tilde (~) is not available.
626    
627         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-
628         ing  and experimentation. It is not intended for production use because         ing and experimentation. It is not intended for production use  because
629         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
630         no  facility  for  supplying  custom  character  tables  for use with a         no facility for supplying  custom  character  tables  for  use  with  a
631         reloaded pattern. If the original  pattern  was  compiled  with  custom         reloaded  pattern.  If  the  original  pattern was compiled with custom
632         tables,  an  attempt to match a subject string using a reloaded pattern         tables, an attempt to match a subject string using a  reloaded  pattern
633         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
634         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.
635    
636    
637  SEE ALSO  SEE ALSO
638    
639         pcre(3),  pcreapi(3),  pcrecallout(3), pcrematching(3), pcrepartial(d),         pcre(3), pcreapi(3), pcrecallout(3),  pcrematching(3),  pcrepartial(d),
640         pcrepattern(3), pcreprecompile(3).         pcrepattern(3), pcreprecompile(3).
641    
642    
# Line 625  AUTHOR Line 649  AUTHOR
649    
650  REVISION  REVISION
651    
652         Last updated: 09 August 2007         Last updated: 18 December 2007
653         Copyright (c) 1997-2007 University of Cambridge.         Copyright (c) 1997-2007 University of Cambridge.

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

  ViewVC Help
Powered by ViewVC 1.1.5