/[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 392 by ph10, Tue Mar 17 21:30:30 2009 UTC revision 429 by ph10, Tue Sep 1 16:10:16 2009 UTC
# Line 326  DATA LINES Line 326  DATA LINES
326                        or pcre_dfa_exec()                        or pcre_dfa_exec()
327           \Odd       set the size of the output vector passed to           \Odd       set the size of the output vector passed to
328                        pcre_exec() to dd (any number of digits)                        pcre_exec() to dd (any number of digits)
329           \P         pass the PCRE_PARTIAL option to pcre_exec()           \P         pass the PCRE_PARTIAL_SOFT option to pcre_exec()
330                        or pcre_dfa_exec()                        or pcre_dfa_exec(); if used twice, pass the
331                          PCRE_PARTIAL_HARD option
332           \Qdd       set the PCRE_MATCH_LIMIT_RECURSION limit to dd           \Qdd       set the PCRE_MATCH_LIMIT_RECURSION limit to dd
333                        (any number of digits)                        (any number of digits)
334           \R         pass the PCRE_DFA_RESTART option to pcre_dfa_exec()           \R         pass the PCRE_DFA_RESTART option to pcre_dfa_exec()
# Line 413  DEFAULT OUTPUT FROM PCRETEST Line 414  DEFAULT OUTPUT FROM PCRETEST
414         When a match succeeds, pcretest outputs the list of captured substrings         When a match succeeds, pcretest outputs the list of captured substrings
415         that  pcre_exec()  returns,  starting with number 0 for the string that         that  pcre_exec()  returns,  starting with number 0 for the string that
416         matched the whole pattern. Otherwise, it outputs "No match" or "Partial         matched the whole pattern. Otherwise, it outputs "No match" or "Partial
417         match"  when  pcre_exec() returns PCRE_ERROR_NOMATCH or PCRE_ERROR_PAR-         match:"  followed  by the partially matching substring when pcre_exec()
418         TIAL, respectively, and otherwise the PCRE negative error number.  Here         returns PCRE_ERROR_NOMATCH  or  PCRE_ERROR_PARTIAL,  respectively,  and
419         is an example of an interactive pcretest run.         otherwise  the  PCRE  negative  error  number. Here is an example of an
420           interactive pcretest run.
421    
422           $ pcretest           $ pcretest
423           PCRE version 7.0 30-Nov-2006           PCRE version 7.0 30-Nov-2006
# Line 427  DEFAULT OUTPUT FROM PCRETEST Line 429  DEFAULT OUTPUT FROM PCRETEST
429           data> xyz           data> xyz
430           No match           No match
431    
432         Note  that unset capturing substrings that are not followed by one that         Note that unset capturing substrings that are not followed by one  that
433         is set are not returned by pcre_exec(), and are not shown by  pcretest.         is  set are not returned by pcre_exec(), and are not shown by pcretest.
434         In  the following example, there are two capturing substrings, but when         In the following example, there are two capturing substrings, but  when
435         the first data line is matched, the  second,  unset  substring  is  not         the  first  data  line  is  matched, the second, unset substring is not
436         shown.  An "internal" unset substring is shown as "<unset>", as for the         shown. An "internal" unset substring is shown as "<unset>", as for  the
437         second data line.         second data line.
438    
439             re> /(a)|(b)/             re> /(a)|(b)/
# Line 443  DEFAULT OUTPUT FROM PCRETEST Line 445  DEFAULT OUTPUT FROM PCRETEST
445            1: <unset>            1: <unset>
446            2: b            2: b
447    
448         If the strings contain any non-printing characters, they are output  as         If  the strings contain any non-printing characters, they are output as
449         \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
450         the pattern. See below for the definition of  non-printing  characters.         the  pattern.  See below for the definition of non-printing characters.
451         If  the pattern has the /+ modifier, the output for substring 0 is fol-         If the pattern has the /+ modifier, the output for substring 0 is  fol-
452         lowed by the the rest of the subject string, identified  by  "0+"  like         lowed  by  the  the rest of the subject string, identified by "0+" like
453         this:         this:
454    
455             re> /cat/+             re> /cat/+
# Line 455  DEFAULT OUTPUT FROM PCRETEST Line 457  DEFAULT OUTPUT FROM PCRETEST
457            0: cat            0: cat
458            0+ aract            0+ aract
459    
460         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
461         matching attempts are output in sequence, like this:         matching attempts are output in sequence, like this:
462    
463             re> /\Bi(\w\w)/g             re> /\Bi(\w\w)/g
# Line 469  DEFAULT OUTPUT FROM PCRETEST Line 471  DEFAULT OUTPUT FROM PCRETEST
471    
472         "No match" is output only if the first match attempt fails.         "No match" is output only if the first match attempt fails.
473    
474         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
475         is  successfully  matched,  the substrings extracted by the convenience         is successfully matched, the substrings extracted  by  the  convenience
476         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
477         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
478         (that is, the return from the extraction function) is given  in  paren-         (that  is,  the return from the extraction function) is given in paren-
479         theses after each string for \C and \G.         theses after each string for \C and \G.
480    
481         Note that whereas patterns can be continued over several lines (a plain         Note that whereas patterns can be continued over several lines (a plain
482         ">" prompt is used for continuations), data lines may not. However new-         ">" prompt is used for continuations), data lines may not. However new-
483         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,
484         etc., depending on the newline sequence setting).         etc., depending on the newline sequence setting).
485    
486    
487  OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION  OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION
488    
489         When the alternative matching function, pcre_dfa_exec(),  is  used  (by         When  the  alternative  matching function, pcre_dfa_exec(), is used (by
490         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
491         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
492         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:
493    
494             re> /(tang|tangerine|tan)/             re> /(tang|tangerine|tan)/
# Line 495  OUTPUT FROM THE ALTERNATIVE MATCHING FUN Line 497  OUTPUT FROM THE ALTERNATIVE MATCHING FUN
497            1: tang            1: tang
498            2: tan            2: tan
499    
500         (Using  the  normal  matching function on this data finds only "tang".)         (Using the normal matching function on this data  finds  only  "tang".)
501         The longest matching string is always given first (and numbered zero).         The  longest matching string is always given first (and numbered zero).
502           After a PCRE_ERROR_PARTIAL return, the output is "Partial match:", fol-
503           lowed by the partially matching substring.
504    
505         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
506         at the end of the longest match. For example:         at the end of the longest match. For example:
# Line 510  OUTPUT FROM THE ALTERNATIVE MATCHING FUN Line 514  OUTPUT FROM THE ALTERNATIVE MATCHING FUN
514            1: tan            1: tan
515            0: tan            0: tan
516    
517         Since  the  matching  function  does not support substring capture, the         Since the matching function does not  support  substring  capture,  the
518         escape sequences that are concerned with captured  substrings  are  not         escape  sequences  that  are concerned with captured substrings are not
519         relevant.         relevant.
520    
521    
522  RESTARTING AFTER A PARTIAL MATCH  RESTARTING AFTER A PARTIAL MATCH
523    
524         When the alternative matching function has given the PCRE_ERROR_PARTIAL         When the alternative matching function has given the PCRE_ERROR_PARTIAL
525         return, indicating that the subject partially matched the pattern,  you         return,  indicating that the subject partially matched the pattern, you
526         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
527         escape sequence. For example:         escape sequence. For example:
528    
529             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 528  RESTARTING AFTER A PARTIAL MATCH Line 532  RESTARTING AFTER A PARTIAL MATCH
532           data> n05\R\D           data> n05\R\D
533            0: n05            0: n05
534    
535         For further information about partial  matching,  see  the  pcrepartial         For  further  information  about  partial matching, see the pcrepartial
536         documentation.         documentation.
537    
538    
539  CALLOUTS  CALLOUTS
540    
541         If  the pattern contains any callout requests, pcretest's callout func-         If the pattern contains any callout requests, pcretest's callout  func-
542         tion is called during matching. This works  with  both  matching  func-         tion  is  called  during  matching. This works with both matching func-
543         tions. By default, the called function displays the callout number, the         tions. By default, the called function displays the callout number, the
544         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
545         next pattern item to be tested. For example, the output         next pattern item to be tested. For example, the output
546    
547           --->pqrabcdef           --->pqrabcdef
548             0    ^  ^     \d             0    ^  ^     \d
549    
550         indicates  that  callout number 0 occurred for a match attempt starting         indicates that callout number 0 occurred for a match  attempt  starting
551         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
552         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
553         \d. Just one circumflex is output if the start  and  current  positions         \d.  Just  one  circumflex is output if the start and current positions
554         are the same.         are the same.
555    
556         Callouts numbered 255 are assumed to be automatic callouts, inserted as         Callouts numbered 255 are assumed to be automatic callouts, inserted as
557         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
558         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
559         output. For example:         output. For example:
560    
561             re> /\d?[A-E]\*/C             re> /\d?[A-E]\*/C
# Line 563  CALLOUTS Line 567  CALLOUTS
567           +10 ^ ^           +10 ^ ^
568            0: E*            0: E*
569    
570         The callout function in pcretest returns zero (carry  on  matching)  by         The  callout  function  in pcretest returns zero (carry on matching) by
571         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)
572         to change this.         to change this.
573    
574         Inserting callouts can be helpful when using pcretest to check  compli-         Inserting  callouts can be helpful when using pcretest to check compli-
575         cated  regular expressions. For further information about callouts, see         cated regular expressions. For further information about callouts,  see
576         the pcrecallout documentation.         the pcrecallout documentation.
577    
578    
579  NON-PRINTING CHARACTERS  NON-PRINTING CHARACTERS
580    
581         When pcretest is outputting text in the compiled version of a  pattern,         When  pcretest is outputting text in the compiled version of a pattern,
582         bytes  other  than 32-126 are always treated as non-printing characters         bytes other than 32-126 are always treated as  non-printing  characters
583         are are therefore shown as hex escapes.         are are therefore shown as hex escapes.
584    
585         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
586         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
587         set for the  pattern  (using  the  /L  modifier).  In  this  case,  the         set  for  the  pattern  (using  the  /L  modifier).  In  this case, the
588         isprint() function to distinguish printing and non-printing characters.         isprint() function to distinguish printing and non-printing characters.
589    
590    
591  SAVING AND RELOADING COMPILED PATTERNS  SAVING AND RELOADING COMPILED PATTERNS
592    
593         The  facilities  described  in  this section are not available when the         The facilities described in this section are  not  available  when  the
594         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-
595         ifier is specified.         ifier is specified.
596    
597         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
598         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
599         file name.  For example:         file name.  For example:
600    
601           /pattern/im >/some/file           /pattern/im >/some/file
602    
603         See  the pcreprecompile documentation for a discussion about saving and         See the pcreprecompile documentation for a discussion about saving  and
604         re-using compiled patterns.         re-using compiled patterns.
605    
606         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
607         length  of  the  compiled  pattern  data  followed by the length of the         length of the compiled pattern data  followed  by  the  length  of  the
608         optional study data, each written as four  bytes  in  big-endian  order         optional  study  data,  each  written as four bytes in big-endian order
609         (most  significant  byte  first). If there is no study data (either the         (most significant byte first). If there is no study  data  (either  the
610         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-
611         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
612         compiled pattern. If there is additional study data, this follows imme-         compiled pattern. If there is additional study data, this follows imme-
613         diately  after  the  compiled pattern. After writing the file, pcretest         diately after the compiled pattern. After writing  the  file,  pcretest
614         expects to read a new pattern.         expects to read a new pattern.
615    
616         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
617         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  <
618         character, as otherwise pcretest will interpret the line as  a  pattern         character,  as  otherwise pcretest will interpret the line as a pattern
619         delimited by < characters.  For example:         delimited by < characters.  For example:
620    
621            re> </some/file            re> </some/file
622           Compiled regex loaded from /some/file           Compiled regex loaded from /some/file
623           No study data           No study data
624    
625         When  the pattern has been loaded, pcretest proceeds to read data lines         When the pattern has been loaded, pcretest proceeds to read data  lines
626         in the usual way.         in the usual way.
627    
628         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
629         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
630         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
631         machine and run on a SPARC machine.         machine and run on a SPARC machine.
632    
633         File  names  for  saving and reloading can be absolute or relative, but         File names for saving and reloading can be absolute  or  relative,  but
634         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
635         a tilde (~) is not available.         a tilde (~) is not available.
636    
637         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-
638         ing and experimentation. It is not intended for production use  because         ing  and experimentation. It is not intended for production use because
639         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
640         no facility for supplying  custom  character  tables  for  use  with  a         no  facility  for  supplying  custom  character  tables  for use with a
641         reloaded  pattern.  If  the  original  pattern was compiled with custom         reloaded pattern. If the original  pattern  was  compiled  with  custom
642         tables, an attempt to match a subject string using a  reloaded  pattern         tables,  an  attempt to match a subject string using a reloaded pattern
643         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
644         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.
645    
646    
647  SEE ALSO  SEE ALSO
648    
649         pcre(3), pcreapi(3), pcrecallout(3),  pcrematching(3),  pcrepartial(d),         pcre(3),  pcreapi(3),  pcrecallout(3), pcrematching(3), pcrepartial(d),
650         pcrepattern(3), pcreprecompile(3).         pcrepattern(3), pcreprecompile(3).
651    
652    
# Line 655  AUTHOR Line 659  AUTHOR
659    
660  REVISION  REVISION
661    
662         Last updated: 10 March 2009         Last updated: 29 August 2009
663         Copyright (c) 1997-2009 University of Cambridge.         Copyright (c) 1997-2009 University of Cambridge.

Legend:
Removed from v.392  
changed lines
  Added in v.429

  ViewVC Help
Powered by ViewVC 1.1.5