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

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

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

revision 93 by nigel, Sat Feb 24 21:41:42 2007 UTC revision 510 by ph10, Sat Mar 27 17:45:29 2010 UTC
# Line 49  Output a brief summary these options and Line 49  Output a brief summary these options and
49  Behave as if each regex has the \fB/I\fP modifier; information about the  Behave as if each regex has the \fB/I\fP modifier; information about the
50  compiled pattern is given after compilation.  compiled pattern is given after compilation.
51  .TP 10  .TP 10
52    \fB-M\fP
53    Behave as if each data line contains the \eM escape sequence; this causes
54    PCRE to discover the minimum MATCH_LIMIT and MATCH_LIMIT_RECURSION settings by
55    calling \fBpcre_exec()\fP repeatedly with different limits.
56    .TP 10
57  \fB-m\fP  \fB-m\fP
58  Output the size of each compiled pattern after it has been compiled. This is  Output the size of each compiled pattern after it has been compiled. This is
59  equivalent to adding \fB/M\fP to each regular expression. For compatibility  equivalent to adding \fB/M\fP to each regular expression. For compatibility
# Line 97  that file and writes to stdout. Otherwis Line 102  that file and writes to stdout. Otherwis
102  stdout, and prompts for each line of input, using "re>" to prompt for regular  stdout, and prompts for each line of input, using "re>" to prompt for regular
103  expressions, and "data>" to prompt for data lines.  expressions, and "data>" to prompt for data lines.
104  .P  .P
105    When \fBpcretest\fP is built, a configuration option can specify that it should
106    be linked with the \fBlibreadline\fP library. When this is done, if the input
107    is from a terminal, it is read using the \fBreadline()\fP function. This
108    provides line-editing and history facilities. The output from the \fB-help\fP
109    option states whether or not \fBreadline()\fP will be used.
110    .P
111  The program handles any number of sets of input on a single input file. Each  The program handles any number of sets of input on a single input file. Each
112  set starts with a regular expression, and continues with any number of data  set starts with a regular expression, and continues with any number of data
113  lines to be matched against the pattern.  lines to be matched against the pattern.
# Line 157  effect as they do in Perl. For example: Line 168  effect as they do in Perl. For example:
168  The following table shows additional modifiers for setting PCRE options that do  The following table shows additional modifiers for setting PCRE options that do
169  not correspond to anything in Perl:  not correspond to anything in Perl:
170  .sp  .sp
171    \fB/A\fP       PCRE_ANCHORED    \fB/A\fP              PCRE_ANCHORED
172    \fB/C\fP       PCRE_AUTO_CALLOUT    \fB/C\fP              PCRE_AUTO_CALLOUT
173    \fB/E\fP       PCRE_DOLLAR_ENDONLY    \fB/E\fP              PCRE_DOLLAR_ENDONLY
174    \fB/f\fP       PCRE_FIRSTLINE    \fB/f\fP              PCRE_FIRSTLINE
175    \fB/J\fP       PCRE_DUPNAMES    \fB/J\fP              PCRE_DUPNAMES
176    \fB/N\fP       PCRE_NO_AUTO_CAPTURE    \fB/N\fP              PCRE_NO_AUTO_CAPTURE
177    \fB/U\fP       PCRE_UNGREEDY    \fB/U\fP              PCRE_UNGREEDY
178    \fB/X\fP       PCRE_EXTRA    \fB/X\fP              PCRE_EXTRA
179    \fB/<cr>\fP    PCRE_NEWLINE_CR    \fB/<JS>\fP           PCRE_JAVASCRIPT_COMPAT
180    \fB/<lf>\fP    PCRE_NEWLINE_LF    \fB/<cr>\fP           PCRE_NEWLINE_CR
181    \fB/<crlf>\fP  PCRE_NEWLINE_CRLF    \fB/<lf>\fP           PCRE_NEWLINE_LF
182    \fB/<any>\fP   PCRE_NEWLINE_ANY    \fB/<crlf>\fP         PCRE_NEWLINE_CRLF
183  .sp    \fB/<anycrlf>\fP      PCRE_NEWLINE_ANYCRLF
184  Those specifying line ending sequencess are literal strings as shown. This    \fB/<any>\fP          PCRE_NEWLINE_ANY
185  example sets multiline matching with CRLF as the line ending sequence:    \fB/<bsr_anycrlf>\fP  PCRE_BSR_ANYCRLF
186      \fB/<bsr_unicode>\fP  PCRE_BSR_UNICODE
187    .sp
188    Those specifying line ending sequences are literal strings as shown, but the
189    letters can be in either case. This example sets multiline matching with CRLF
190    as the line ending sequence:
191  .sp  .sp
192    /^abc/m<crlf>    /^abc/m<crlf>
193  .sp  .sp
# Line 195  substring. This makes a difference to th Line 211  substring. This makes a difference to th
211  begins with a lookbehind assertion (including \eb or \eB).  begins with a lookbehind assertion (including \eb or \eB).
212  .P  .P
213  If any call to \fBpcre_exec()\fP in a \fB/g\fP or \fB/G\fP sequence matches an  If any call to \fBpcre_exec()\fP in a \fB/g\fP or \fB/G\fP sequence matches an
214  empty string, the next call is done with the PCRE_NOTEMPTY and PCRE_ANCHORED  empty string, the next call is done with the PCRE_NOTEMPTY_ATSTART and
215  flags set in order to search for another, non-empty, match at the same point.  PCRE_ANCHORED flags set in order to search for another, non-empty, match at the
216  If this second match fails, the start offset is advanced by one, and the normal  same point. If this second match fails, the start offset is advanced by one
217  match is retried. This imitates the way Perl handles such cases when using the  character, and the normal match is retried. This imitates the way Perl handles
218  \fB/g\fP modifier or the \fBsplit()\fP function.  such cases when using the \fB/g\fP modifier or the \fBsplit()\fP function.
219  .  .
220  .  .
221  .SS "Other modifiers"  .SS "Other modifiers"
# Line 208  match is retried. This imitates the way Line 224  match is retried. This imitates the way
224  There are yet more modifiers for controlling the way \fBpcretest\fP  There are yet more modifiers for controlling the way \fBpcretest\fP
225  operates.  operates.
226  .P  .P
227    The \fB/8\fP modifier causes \fBpcretest\fP to call PCRE with the PCRE_UTF8
228    option set. This turns on support for UTF-8 character handling in PCRE,
229    provided that it was compiled with this support enabled. This modifier also
230    causes any non-printing characters in output strings to be printed using the
231    \ex{hh...} notation if they are valid UTF-8 sequences.
232    .P
233    If the \fB/?\fP modifier is used with \fB/8\fP, it causes \fBpcretest\fP to
234    call \fBpcre_compile()\fP with the PCRE_NO_UTF8_CHECK option, to suppress the
235    checking of the string for UTF-8 validity.
236    .P
237  The \fB/+\fP modifier requests that as well as outputting the substring that  The \fB/+\fP modifier requests that as well as outputting the substring that
238  matched the entire pattern, pcretest should in addition output the remainder of  matched the entire pattern, pcretest should in addition output the remainder of
239  the subject string. This is useful for tests where the subject contains  the subject string. This is useful for tests where the subject contains
240  multiple copies of the same substring.  multiple copies of the same substring.
241  .P  .P
242  The \fB/B\fP modifier is a debugging feature. It requests that \fBpcretest\fP  The \fB/B\fP modifier is a debugging feature. It requests that \fBpcretest\fP
243  output a representation of the compiled byte code after compilation.  output a representation of the compiled byte code after compilation. Normally
244  .P  this information contains length and offset values; however, if \fB/Z\fP is
245  The \fB/L\fP modifier must be followed directly by the name of a locale, for  also present, this data is replaced by spaces. This is a special feature for
246  example,  use in the automatic test scripts; it ensures that the same output is generated
247  .sp  for different internal link sizes.
   /pattern/Lfr_FR  
 .sp  
 For this reason, it must be the last modifier. The given locale is set,  
 \fBpcre_maketables()\fP is called to build a set of character tables for the  
 locale, and this is then passed to \fBpcre_compile()\fP when compiling the  
 regular expression. Without an \fB/L\fP modifier, NULL is passed as the tables  
 pointer; that is, \fB/L\fP applies only to the expression on which it appears.  
 .P  
 The \fB/I\fP modifier requests that \fBpcretest\fP output information about the  
 compiled pattern (whether it is anchored, has a fixed first character, and  
 so on). It does this by calling \fBpcre_fullinfo()\fP after compiling a  
 pattern. If the pattern is studied, the results of that are also output.  
248  .P  .P
249  The \fB/D\fP modifier is a PCRE debugging feature, and is equivalent to  The \fB/D\fP modifier is a PCRE debugging feature, and is equivalent to
250  \fB/BI\fP, that is, both the \fP/B\fP and the \fB/I\fP modifiers.  \fB/BI\fP, that is, both the \fB/B\fP and the \fB/I\fP modifiers.
251  .P  .P
252  The \fB/F\fP modifier causes \fBpcretest\fP to flip the byte order of the  The \fB/F\fP modifier causes \fBpcretest\fP to flip the byte order of the
253  fields in the compiled pattern that contain 2-byte and 4-byte numbers. This  fields in the compiled pattern that contain 2-byte and 4-byte numbers. This
# Line 243  available when the POSIX interface to PC Line 257  available when the POSIX interface to PC
257  \fB/P\fP pattern modifier is specified. See also the section about saving and  \fB/P\fP pattern modifier is specified. See also the section about saving and
258  reloading compiled patterns below.  reloading compiled patterns below.
259  .P  .P
260  The \fB/S\fP modifier causes \fBpcre_study()\fP to be called after the  The \fB/I\fP modifier requests that \fBpcretest\fP output information about the
261  expression has been compiled, and the results used when the expression is  compiled pattern (whether it is anchored, has a fixed first character, and
262  matched.  so on). It does this by calling \fBpcre_fullinfo()\fP after compiling a
263    pattern. If the pattern is studied, the results of that are also output.
264    .P
265    The \fB/K\fP modifier requests \fBpcretest\fP to show names from backtracking
266    control verbs that are returned from calls to \fBpcre_exec()\fP. It causes
267    \fBpcretest\fP to create a \fBpcre_extra\fP block if one has not already been
268    created by a call to \fBpcre_study()\fP, and to set the PCRE_EXTRA_MARK flag
269    and the \fBmark\fP field within it, every time that \fBpcre_exec()\fP is
270    called. If the variable that the \fBmark\fP field points to is non-NULL for a
271    match, non-match, or partial match, \fBpcretest\fP prints the string to which
272    it points. For a match, this is shown on a line by itself, tagged with "MK:".
273    For a non-match it is added to the message.
274    .P
275    The \fB/L\fP modifier must be followed directly by the name of a locale, for
276    example,
277    .sp
278      /pattern/Lfr_FR
279    .sp
280    For this reason, it must be the last modifier. The given locale is set,
281    \fBpcre_maketables()\fP is called to build a set of character tables for the
282    locale, and this is then passed to \fBpcre_compile()\fP when compiling the
283    regular expression. Without an \fB/L\fP modifier, NULL is passed as the tables
284    pointer; that is, \fB/L\fP applies only to the expression on which it appears.
285  .P  .P
286  The \fB/M\fP modifier causes the size of memory block used to hold the compiled  The \fB/M\fP modifier causes the size of memory block used to hold the compiled
287  pattern to be output.  pattern to be output.
# Line 256  API rather than its native API. When thi Line 292  API rather than its native API. When thi
292  present, and REG_NEWLINE is set if \fB/m\fP is present. The wrapper functions  present, and REG_NEWLINE is set if \fB/m\fP is present. The wrapper functions
293  force PCRE_DOLLAR_ENDONLY always, and PCRE_DOTALL unless REG_NEWLINE is set.  force PCRE_DOLLAR_ENDONLY always, and PCRE_DOTALL unless REG_NEWLINE is set.
294  .P  .P
295  The \fB/8\fP modifier causes \fBpcretest\fP to call PCRE with the PCRE_UTF8  The \fB/S\fP modifier causes \fBpcre_study()\fP to be called after the
296  option set. This turns on support for UTF-8 character handling in PCRE,  expression has been compiled, and the results used when the expression is
297  provided that it was compiled with this support enabled. This modifier also  matched.
 causes any non-printing characters in output strings to be printed using the  
 \ex{hh...} notation if they are valid UTF-8 sequences.  
 .P  
 If the \fB/?\fP modifier is used with \fB/8\fP, it causes \fBpcretest\fP to  
 call \fBpcre_compile()\fP with the PCRE_NO_UTF8_CHECK option, to suppress the  
 checking of the string for UTF-8 validity.  
298  .  .
299  .  .
300  .SH "DATA LINES"  .SH "DATA LINES"
# Line 336  recognized: Line 366  recognized:
366                 MATCH_LIMIT_RECURSION settings                 MATCH_LIMIT_RECURSION settings
367  .\" JOIN  .\" JOIN
368    \eN         pass the PCRE_NOTEMPTY option to \fBpcre_exec()\fP    \eN         pass the PCRE_NOTEMPTY option to \fBpcre_exec()\fP
369                 or \fBpcre_dfa_exec()\fP                 or \fBpcre_dfa_exec()\fP; if used twice, pass the
370                   PCRE_NOTEMPTY_ATSTART option
371  .\" JOIN  .\" JOIN
372    \eOdd       set the size of the output vector passed to    \eOdd       set the size of the output vector passed to
373                 \fBpcre_exec()\fP to dd (any number of digits)                 \fBpcre_exec()\fP to dd (any number of digits)
374  .\" JOIN  .\" JOIN
375    \eP         pass the PCRE_PARTIAL option to \fBpcre_exec()\fP    \eP         pass the PCRE_PARTIAL_SOFT option to \fBpcre_exec()\fP
376                 or \fBpcre_dfa_exec()\fP                 or \fBpcre_dfa_exec()\fP; if used twice, pass the
377                   PCRE_PARTIAL_HARD option
378  .\" JOIN  .\" JOIN
379    \eQdd       set the PCRE_MATCH_LIMIT_RECURSION limit to dd    \eQdd       set the PCRE_MATCH_LIMIT_RECURSION limit to dd
380                 (any number of digits)                 (any number of digits)
381    \eR         pass the PCRE_DFA_RESTART option to \fBpcre_dfa_exec()\fP    \eR         pass the PCRE_DFA_RESTART option to \fBpcre_dfa_exec()\fP
382    \eS         output details of memory get/free calls during matching    \eS         output details of memory get/free calls during matching
383  .\" JOIN  .\" JOIN
384      \eY         pass the PCRE_NO_START_OPTIMIZE option to \fBpcre_exec()\fP
385                   or \fBpcre_dfa_exec()\fP
386    .\" JOIN
387    \eZ         pass the PCRE_NOTEOL option to \fBpcre_exec()\fP    \eZ         pass the PCRE_NOTEOL option to \fBpcre_exec()\fP
388                 or \fBpcre_dfa_exec()\fP                 or \fBpcre_dfa_exec()\fP
389  .\" JOIN  .\" JOIN
# Line 368  recognized: Line 403  recognized:
403    \e<crlf>    pass the PCRE_NEWLINE_CRLF option to \fBpcre_exec()\fP    \e<crlf>    pass the PCRE_NEWLINE_CRLF option to \fBpcre_exec()\fP
404                 or \fBpcre_dfa_exec()\fP                 or \fBpcre_dfa_exec()\fP
405  .\" JOIN  .\" JOIN
406      \e<anycrlf> pass the PCRE_NEWLINE_ANYCRLF option to \fBpcre_exec()\fP
407                   or \fBpcre_dfa_exec()\fP
408    .\" JOIN
409    \e<any>     pass the PCRE_NEWLINE_ANY option to \fBpcre_exec()\fP    \e<any>     pass the PCRE_NEWLINE_ANY option to \fBpcre_exec()\fP
410                 or \fBpcre_dfa_exec()\fP                 or \fBpcre_dfa_exec()\fP
411  .sp  .sp
# Line 403  and \eZ, causing REG_NOTBOL and REG_NOTE Line 441  and \eZ, causing REG_NOTBOL and REG_NOTE
441  The use of \ex{hh...} to represent UTF-8 characters is not dependent on the use  The use of \ex{hh...} to represent UTF-8 characters is not dependent on the use
442  of the \fB/8\fP modifier on the pattern. It is recognized always. There may be  of the \fB/8\fP modifier on the pattern. It is recognized always. There may be
443  any number of hexadecimal digits inside the braces. The result is from one to  any number of hexadecimal digits inside the braces. The result is from one to
444  six bytes, encoded according to the UTF-8 rules.  six bytes, encoded according to the original UTF-8 rules of RFC 2279. This
445    allows for values in the range 0 to 0x7FFFFFFF. Note that not all of those are
446    valid Unicode code points, or indeed valid UTF-8 characters according to the
447    later rules in RFC 3629.
448  .  .
449  .  .
450  .SH "THE ALTERNATIVE MATCHING FUNCTION"  .SH "THE ALTERNATIVE MATCHING FUNCTION"
# Line 434  This section describes the output when t Line 475  This section describes the output when t
475  .P  .P
476  When a match succeeds, pcretest outputs the list of captured substrings that  When a match succeeds, pcretest outputs the list of captured substrings that
477  \fBpcre_exec()\fP returns, starting with number 0 for the string that matched  \fBpcre_exec()\fP returns, starting with number 0 for the string that matched
478  the whole pattern. Otherwise, it outputs "No match" or "Partial match"  the whole pattern. Otherwise, it outputs "No match" when the return is
479  when \fBpcre_exec()\fP returns PCRE_ERROR_NOMATCH or PCRE_ERROR_PARTIAL,  PCRE_ERROR_NOMATCH, and "Partial match:" followed by the partially matching
480  respectively, and otherwise the PCRE negative error number. Here is an example  substring when \fBpcre_exec()\fP returns PCRE_ERROR_PARTIAL. For any other
481  of an interactive \fBpcretest\fP run.  returns, it outputs the PCRE negative error number. Here is an example of an
482    interactive \fBpcretest\fP run.
483  .sp  .sp
484    $ pcretest    $ pcretest
485    PCRE version 7.0 30-Nov-2006    PCRE version 7.0 30-Nov-2006
# Line 449  of an interactive \fBpcretest\fP run. Line 491  of an interactive \fBpcretest\fP run.
491    data> xyz    data> xyz
492    No match    No match
493  .sp  .sp
494    Note that unset capturing substrings that are not followed by one that is set
495    are not returned by \fBpcre_exec()\fP, and are not shown by \fBpcretest\fP. In
496    the following example, there are two capturing substrings, but when the first
497    data line is matched, the second, unset substring is not shown. An "internal"
498    unset substring is shown as "<unset>", as for the second data line.
499    .sp
500        re> /(a)|(b)/
501      data> a
502       0: a
503       1: a
504      data> b
505       0: b
506       1: <unset>
507       2: b
508    .sp
509  If the strings contain any non-printing characters, they are output as \e0x  If the strings contain any non-printing characters, they are output as \e0x
510  escapes, or as \ex{...} escapes if the \fB/8\fP modifier was present on the  escapes, or as \ex{...} escapes if the \fB/8\fP modifier was present on the
511  pattern. See below for the definition of non-printing characters. If the  pattern. See below for the definition of non-printing characters. If the
# Line 503  the subject where there is at least one Line 560  the subject where there is at least one
560     2: tan     2: tan
561  .sp  .sp
562  (Using the normal matching function on this data finds only "tang".) The  (Using the normal matching function on this data finds only "tang".) The
563  longest matching string is always given first (and numbered zero).  longest matching string is always given first (and numbered zero). After a
564    PCRE_ERROR_PARTIAL return, the output is "Partial match:", followed by the
565    partially matching substring.
566  .P  .P
567  If \fB/g\fP is present on the pattern, the search for further matches resumes  If \fB/g\fP is present on the pattern, the search for further matches resumes
568  at the end of the longest match. For example:  at the end of the longest match. For example:
# Line 529  indicating that the subject partially ma Line 588  indicating that the subject partially ma
588  match with additional subject data by means of the \eR escape sequence. For  match with additional subject data by means of the \eR escape sequence. For
589  example:  example:
590  .sp  .sp
591      re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/      re> /^\ed?\ed(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\ed\ed$/
592    data> 23ja\eP\eD    data> 23ja\eP\eD
593    Partial match: 23ja    Partial match: 23ja
594    data> n05\eR\eD    data> n05\eR\eD
# Line 665  result is undefined. Line 724  result is undefined.
724  .rs  .rs
725  .sp  .sp
726  \fBpcre\fP(3), \fBpcreapi\fP(3), \fBpcrecallout\fP(3), \fBpcrematching\fP(3),  \fBpcre\fP(3), \fBpcreapi\fP(3), \fBpcrecallout\fP(3), \fBpcrematching\fP(3),
727  \fBpcrepartial\fP(d), \fPpcrepattern\fP(3), \fBpcreprecompile\fP(3).  \fBpcrepartial\fP(d), \fBpcrepattern\fP(3), \fBpcreprecompile\fP(3).
728  .  .
729  .  .
730  .SH AUTHOR  .SH AUTHOR
731  .rs  .rs
732  .sp  .sp
733    .nf
734  Philip Hazel  Philip Hazel
735  .br  University Computing Service
 University Computing Service,  
 .br  
736  Cambridge CB2 3QH, England.  Cambridge CB2 3QH, England.
737  .P  .fi
738  .in 0  .
739  Last updated: 30 November 2006  .
740  .br  .SH REVISION
741  Copyright (c) 1997-2006 University of Cambridge.  .rs
742    .sp
743    .nf
744    Last updated: 26 March 2010
745    Copyright (c) 1997-2010 University of Cambridge.
746    .fi

Legend:
Removed from v.93  
changed lines
  Added in v.510

  ViewVC Help
Powered by ViewVC 1.1.5