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

Legend:
Removed from v.285  
changed lines
  Added in v.286

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12