| 1 |
ph10 |
954 |
.TH PCRETEST 1 "21 February 2012" "PCRE 8.31" |
| 2 |
nigel |
53 |
.SH NAME |
| 3 |
|
|
pcretest - a program for testing Perl-compatible regular expressions. |
| 4 |
|
|
.SH SYNOPSIS |
| 5 |
nigel |
75 |
.rs |
| 6 |
|
|
.sp |
| 7 |
ph10 |
612 |
.B pcretest "[options] [input file [output file]]" |
| 8 |
nigel |
91 |
.sp |
| 9 |
nigel |
75 |
\fBpcretest\fP was written as a test program for the PCRE regular expression |
| 10 |
nigel |
53 |
library itself, but it can also be used for experimenting with regular |
| 11 |
nigel |
63 |
expressions. This document describes the features of the test program; for |
| 12 |
|
|
details of the regular expressions themselves, see the |
| 13 |
|
|
.\" HREF |
| 14 |
nigel |
75 |
\fBpcrepattern\fP |
| 15 |
nigel |
63 |
.\" |
| 16 |
nigel |
75 |
documentation. For details of the PCRE library function calls and their |
| 17 |
|
|
options, see the |
| 18 |
nigel |
63 |
.\" HREF |
| 19 |
nigel |
75 |
\fBpcreapi\fP |
| 20 |
nigel |
63 |
.\" |
| 21 |
ph10 |
866 |
and |
| 22 |
|
|
.\" HREF |
| 23 |
|
|
\fBpcre16\fP |
| 24 |
|
|
.\" |
| 25 |
ph10 |
654 |
documentation. The input for \fBpcretest\fP is a sequence of regular expression |
| 26 |
|
|
patterns and strings to be matched, as described below. The output shows the |
| 27 |
|
|
result of each match. Options on the command line and the patterns control PCRE |
| 28 |
ph10 |
612 |
options and exactly what is output. |
| 29 |
nigel |
75 |
. |
| 30 |
|
|
. |
| 31 |
ph10 |
866 |
.SH "PCRE's 8-BIT and 16-BIT LIBRARIES" |
| 32 |
nigel |
63 |
.rs |
| 33 |
ph10 |
866 |
.sp |
| 34 |
ph10 |
903 |
From release 8.30, two separate PCRE libraries can be built. The original one |
| 35 |
|
|
supports 8-bit character strings, whereas the newer 16-bit library supports |
| 36 |
|
|
character strings encoded in 16-bit units. The \fBpcretest\fP program can be |
| 37 |
ph10 |
866 |
used to test both libraries. However, it is itself still an 8-bit program, |
| 38 |
|
|
reading 8-bit input and writing 8-bit output. When testing the 16-bit library, |
| 39 |
|
|
the patterns and data strings are converted to 16-bit format before being |
| 40 |
ph10 |
903 |
passed to the PCRE library functions. Results are converted to 8-bit for |
| 41 |
ph10 |
866 |
output. |
| 42 |
|
|
.P |
| 43 |
ph10 |
903 |
References to functions and structures of the form \fBpcre[16]_xx\fP below |
| 44 |
|
|
mean "\fBpcre_xx\fP when using the 8-bit library or \fBpcre16_xx\fP when using |
| 45 |
ph10 |
866 |
the 16-bit library". |
| 46 |
|
|
. |
| 47 |
|
|
. |
| 48 |
|
|
.SH "COMMAND LINE OPTIONS" |
| 49 |
|
|
.rs |
| 50 |
nigel |
53 |
.TP 10 |
| 51 |
ph10 |
866 |
\fB-16\fP |
| 52 |
ph10 |
903 |
If both the 8-bit and the 16-bit libraries have been built, this option causes |
| 53 |
|
|
the 16-bit library to be used. If only the 16-bit library has been built, this |
| 54 |
|
|
is the default (so has no effect). If only the 8-bit library has been built, |
| 55 |
ph10 |
866 |
this option causes an error. |
| 56 |
|
|
.TP 10 |
| 57 |
nigel |
93 |
\fB-b\fP |
| 58 |
ph10 |
612 |
Behave as if each pattern has the \fB/B\fP (show byte code) modifier; the |
| 59 |
ph10 |
599 |
internal form is output after compilation. |
| 60 |
nigel |
93 |
.TP 10 |
| 61 |
nigel |
75 |
\fB-C\fP |
| 62 |
nigel |
63 |
Output the version number of the PCRE library, and all available information |
| 63 |
ph10 |
903 |
about the optional features that are included, and then exit. All other options |
| 64 |
ph10 |
866 |
are ignored. |
| 65 |
nigel |
63 |
.TP 10 |
| 66 |
ph10 |
866 |
\fB-C\fP \fIoption\fP |
| 67 |
ph10 |
903 |
Output information about a specific build-time option, then exit. This |
| 68 |
|
|
functionality is intended for use in scripts such as \fBRunTest\fP. The |
| 69 |
ph10 |
866 |
following options output the value indicated: |
| 70 |
|
|
.sp |
| 71 |
|
|
linksize the internal link size (2, 3, or 4) |
| 72 |
ph10 |
903 |
newline the default newline setting: |
| 73 |
|
|
CR, LF, CRLF, ANYCRLF, or ANY |
| 74 |
ph10 |
866 |
.sp |
| 75 |
|
|
The following options output 1 for true or zero for false: |
| 76 |
ph10 |
903 |
.sp |
| 77 |
ph10 |
866 |
jit just-in-time support is available |
| 78 |
|
|
pcre16 the 16-bit library was built |
| 79 |
|
|
pcre8 the 8-bit library was built |
| 80 |
ph10 |
903 |
ucp Unicode property support is available |
| 81 |
ph10 |
866 |
utf UTF-8 and/or UTF-16 support is available |
| 82 |
|
|
.TP 10 |
| 83 |
nigel |
75 |
\fB-d\fP |
| 84 |
ph10 |
612 |
Behave as if each pattern has the \fB/D\fP (debug) modifier; the internal |
| 85 |
nigel |
93 |
form and information about the compiled pattern is output after compilation; |
| 86 |
|
|
\fB-d\fP is equivalent to \fB-b -i\fP. |
| 87 |
nigel |
53 |
.TP 10 |
| 88 |
nigel |
77 |
\fB-dfa\fP |
| 89 |
|
|
Behave as if each data line contains the \eD escape sequence; this causes the |
| 90 |
ph10 |
866 |
alternative matching function, \fBpcre[16]_dfa_exec()\fP, to be used instead of |
| 91 |
|
|
the standard \fBpcre[16]_exec()\fP function (more detail is given below). |
| 92 |
nigel |
77 |
.TP 10 |
| 93 |
nigel |
93 |
\fB-help\fP |
| 94 |
|
|
Output a brief summary these options and then exit. |
| 95 |
|
|
.TP 10 |
| 96 |
nigel |
75 |
\fB-i\fP |
| 97 |
ph10 |
612 |
Behave as if each pattern has the \fB/I\fP modifier; information about the |
| 98 |
nigel |
53 |
compiled pattern is given after compilation. |
| 99 |
|
|
.TP 10 |
| 100 |
ph10 |
386 |
\fB-M\fP |
| 101 |
|
|
Behave as if each data line contains the \eM escape sequence; this causes |
| 102 |
ph10 |
392 |
PCRE to discover the minimum MATCH_LIMIT and MATCH_LIMIT_RECURSION settings by |
| 103 |
ph10 |
866 |
calling \fBpcre[16]_exec()\fP repeatedly with different limits. |
| 104 |
ph10 |
386 |
.TP 10 |
| 105 |
nigel |
75 |
\fB-m\fP |
| 106 |
nigel |
53 |
Output the size of each compiled pattern after it has been compiled. This is |
| 107 |
ph10 |
903 |
equivalent to adding \fB/M\fP to each regular expression. The size is given in |
| 108 |
ph10 |
866 |
bytes for both libraries. |
| 109 |
nigel |
53 |
.TP 10 |
| 110 |
nigel |
75 |
\fB-o\fP \fIosize\fP |
| 111 |
|
|
Set the number of elements in the output vector that is used when calling |
| 112 |
ph10 |
866 |
\fBpcre[16]_exec()\fP or \fBpcre[16]_dfa_exec()\fP to be \fIosize\fP. The |
| 113 |
|
|
default value is 45, which is enough for 14 capturing subexpressions for |
| 114 |
|
|
\fBpcre[16]_exec()\fP or 22 different matches for \fBpcre[16]_dfa_exec()\fP. |
| 115 |
|
|
The vector size can be changed for individual matching calls by including \eO |
| 116 |
|
|
in the data line (see below). |
| 117 |
nigel |
53 |
.TP 10 |
| 118 |
nigel |
75 |
\fB-p\fP |
| 119 |
ph10 |
612 |
Behave as if each pattern has the \fB/P\fP modifier; the POSIX wrapper API is |
| 120 |
nigel |
77 |
used to call PCRE. None of the other options has any effect when \fB-p\fP is |
| 121 |
ph10 |
866 |
set. This option can be used only with the 8-bit library. |
| 122 |
nigel |
53 |
.TP 10 |
| 123 |
nigel |
91 |
\fB-q\fP |
| 124 |
nigel |
87 |
Do not output the version number of \fBpcretest\fP at the start of execution. |
| 125 |
|
|
.TP 10 |
| 126 |
nigel |
91 |
\fB-S\fP \fIsize\fP |
| 127 |
ph10 |
599 |
On Unix-like systems, set the size of the run-time stack to \fIsize\fP |
| 128 |
nigel |
91 |
megabytes. |
| 129 |
|
|
.TP 10 |
| 130 |
ph10 |
678 |
\fB-s\fP or \fB-s+\fP |
| 131 |
ph10 |
612 |
Behave as if each pattern has the \fB/S\fP modifier; in other words, force each |
| 132 |
ph10 |
922 |
pattern to be studied. If \fB-s+\fP is used, all the JIT compile options are |
| 133 |
ph10 |
866 |
passed to \fBpcre[16]_study()\fP, causing just-in-time optimization to be set |
| 134 |
ph10 |
975 |
up if it is available, for both full and partial matching. Specific JIT compile |
| 135 |
|
|
options can be selected by following \fB-s+\fP with a digit in the range 1 to |
| 136 |
ph10 |
923 |
7, which selects the JIT compile modes as follows: |
| 137 |
|
|
.sp |
| 138 |
|
|
1 normal match only |
| 139 |
|
|
2 soft partial match only |
| 140 |
|
|
3 normal match and soft partial match |
| 141 |
|
|
4 hard partial match only |
| 142 |
|
|
6 soft and hard partial match |
| 143 |
|
|
7 all three modes (default) |
| 144 |
ph10 |
975 |
.sp |
| 145 |
ph10 |
923 |
If \fB-s++\fP is used instead of \fB-s+\fP (with or without a following digit), |
| 146 |
|
|
the text "(JIT)" is added to the first output line after a match or no match |
| 147 |
|
|
when JIT-compiled code was actually used. |
| 148 |
ph10 |
922 |
.P |
| 149 |
|
|
If the \fB/I\fP or \fB/D\fP option is present on a pattern (requesting output |
| 150 |
|
|
about the compiled pattern), information about the result of studying is not |
| 151 |
|
|
included when studying is caused only by \fB-s\fP and neither \fB-i\fP nor |
| 152 |
|
|
\fB-d\fP is present on the command line. This behaviour means that the output |
| 153 |
|
|
from tests that are run with and without \fB-s\fP should be identical, except |
| 154 |
|
|
when options that output information about the actual running of a match are |
| 155 |
|
|
set. |
| 156 |
ph10 |
866 |
.sp |
| 157 |
|
|
The \fB-M\fP, \fB-t\fP, and \fB-tm\fP options, which give information about |
| 158 |
|
|
resources used, are likely to produce different output with and without |
| 159 |
|
|
\fB-s\fP. Output may also differ if the \fB/C\fP option is present on an |
| 160 |
|
|
individual pattern. This uses callouts to trace the the matching process, and |
| 161 |
|
|
this may be different between studied and non-studied patterns. If the pattern |
| 162 |
|
|
contains (*MARK) items there may also be differences, for the same reason. The |
| 163 |
|
|
\fB-s\fP command line option can be overridden for specific patterns that |
| 164 |
|
|
should never be studied (see the \fB/S\fP pattern modifier below). |
| 165 |
ph10 |
606 |
.TP 10 |
| 166 |
nigel |
75 |
\fB-t\fP |
| 167 |
nigel |
63 |
Run each compile, study, and match many times with a timer, and output |
| 168 |
nigel |
75 |
resulting time per compile or match (in milliseconds). Do not set \fB-m\fP with |
| 169 |
|
|
\fB-t\fP, because you will then get the size output a zillion times, and the |
| 170 |
nigel |
93 |
timing will be distorted. You can control the number of iterations that are |
| 171 |
|
|
used for timing by following \fB-t\fP with a number (as a separate item on the |
| 172 |
|
|
command line). For example, "-t 1000" would iterate 1000 times. The default is |
| 173 |
|
|
to iterate 500000 times. |
| 174 |
|
|
.TP 10 |
| 175 |
|
|
\fB-tm\fP |
| 176 |
|
|
This is like \fB-t\fP except that it times only the matching phase, not the |
| 177 |
|
|
compile or study phases. |
| 178 |
nigel |
75 |
. |
| 179 |
|
|
. |
| 180 |
nigel |
53 |
.SH DESCRIPTION |
| 181 |
nigel |
63 |
.rs |
| 182 |
|
|
.sp |
| 183 |
nigel |
75 |
If \fBpcretest\fP is given two filename arguments, it reads from the first and |
| 184 |
nigel |
53 |
writes to the second. If it is given only one filename argument, it reads from |
| 185 |
|
|
that file and writes to stdout. Otherwise, it reads from stdin and writes to |
| 186 |
|
|
stdout, and prompts for each line of input, using "re>" to prompt for regular |
| 187 |
|
|
expressions, and "data>" to prompt for data lines. |
| 188 |
nigel |
75 |
.P |
| 189 |
ph10 |
289 |
When \fBpcretest\fP is built, a configuration option can specify that it should |
| 190 |
ph10 |
287 |
be linked with the \fBlibreadline\fP library. When this is done, if the input |
| 191 |
|
|
is from a terminal, it is read using the \fBreadline()\fP function. This |
| 192 |
|
|
provides line-editing and history facilities. The output from the \fB-help\fP |
| 193 |
|
|
option states whether or not \fBreadline()\fP will be used. |
| 194 |
|
|
.P |
| 195 |
nigel |
53 |
The program handles any number of sets of input on a single input file. Each |
| 196 |
|
|
set starts with a regular expression, and continues with any number of data |
| 197 |
nigel |
63 |
lines to be matched against the pattern. |
| 198 |
nigel |
75 |
.P |
| 199 |
|
|
Each data line is matched separately and independently. If you want to do |
| 200 |
nigel |
91 |
multi-line matches, you have to use the \en escape sequence (or \er or \er\en, |
| 201 |
nigel |
93 |
etc., depending on the newline setting) in a single line of input to encode the |
| 202 |
|
|
newline sequences. There is no limit on the length of data lines; the input |
| 203 |
nigel |
91 |
buffer is automatically extended if it is too small. |
| 204 |
nigel |
75 |
.P |
| 205 |
nigel |
63 |
An empty line signals the end of the data lines, at which point a new regular |
| 206 |
|
|
expression is read. The regular expressions are given enclosed in any |
| 207 |
nigel |
91 |
non-alphanumeric delimiters other than backslash, for example: |
| 208 |
nigel |
75 |
.sp |
| 209 |
nigel |
53 |
/(a|bc)x+yz/ |
| 210 |
nigel |
75 |
.sp |
| 211 |
nigel |
53 |
White space before the initial delimiter is ignored. A regular expression may |
| 212 |
|
|
be continued over several input lines, in which case the newline characters are |
| 213 |
|
|
included within it. It is possible to include the delimiter within the pattern |
| 214 |
|
|
by escaping it, for example |
| 215 |
nigel |
75 |
.sp |
| 216 |
|
|
/abc\e/def/ |
| 217 |
|
|
.sp |
| 218 |
nigel |
53 |
If you do so, the escape and the delimiter form part of the pattern, but since |
| 219 |
nigel |
75 |
delimiters are always non-alphanumeric, this does not affect its interpretation. |
| 220 |
nigel |
53 |
If the terminating delimiter is immediately followed by a backslash, for |
| 221 |
|
|
example, |
| 222 |
nigel |
75 |
.sp |
| 223 |
|
|
/abc/\e |
| 224 |
|
|
.sp |
| 225 |
nigel |
53 |
then a backslash is added to the end of the pattern. This is done to provide a |
| 226 |
|
|
way of testing the error condition that arises if a pattern finishes with a |
| 227 |
|
|
backslash, because |
| 228 |
nigel |
75 |
.sp |
| 229 |
|
|
/abc\e/ |
| 230 |
|
|
.sp |
| 231 |
nigel |
53 |
is interpreted as the first line of a pattern that starts with "abc/", causing |
| 232 |
|
|
pcretest to read the next line as a continuation of the regular expression. |
| 233 |
nigel |
75 |
. |
| 234 |
|
|
. |
| 235 |
|
|
.SH "PATTERN MODIFIERS" |
| 236 |
nigel |
63 |
.rs |
| 237 |
|
|
.sp |
| 238 |
nigel |
75 |
A pattern may be followed by any number of modifiers, which are mostly single |
| 239 |
|
|
characters. Following Perl usage, these are referred to below as, for example, |
| 240 |
|
|
"the \fB/i\fP modifier", even though the delimiter of the pattern need not |
| 241 |
ph10 |
599 |
always be a slash, and no slash is used when writing modifiers. White space may |
| 242 |
nigel |
75 |
appear between the final pattern delimiter and the first modifier, and between |
| 243 |
|
|
the modifiers themselves. |
| 244 |
|
|
.P |
| 245 |
|
|
The \fB/i\fP, \fB/m\fP, \fB/s\fP, and \fB/x\fP modifiers set the PCRE_CASELESS, |
| 246 |
|
|
PCRE_MULTILINE, PCRE_DOTALL, or PCRE_EXTENDED options, respectively, when |
| 247 |
ph10 |
866 |
\fBpcre[16]_compile()\fP is called. These four modifier letters have the same |
| 248 |
nigel |
75 |
effect as they do in Perl. For example: |
| 249 |
|
|
.sp |
| 250 |
nigel |
53 |
/caseless/i |
| 251 |
nigel |
75 |
.sp |
| 252 |
ph10 |
518 |
The following table shows additional modifiers for setting PCRE compile-time |
| 253 |
|
|
options that do not correspond to anything in Perl: |
| 254 |
nigel |
75 |
.sp |
| 255 |
ph10 |
903 |
\fB/8\fP PCRE_UTF8 ) when using the 8-bit |
| 256 |
ph10 |
866 |
\fB/?\fP PCRE_NO_UTF8_CHECK ) library |
| 257 |
ph10 |
903 |
.sp |
| 258 |
ph10 |
866 |
\fB/8\fP PCRE_UTF16 ) when using the 16-bit |
| 259 |
|
|
\fB/?\fP PCRE_NO_UTF16_CHECK ) library |
| 260 |
ph10 |
903 |
.sp |
| 261 |
ph10 |
231 |
\fB/A\fP PCRE_ANCHORED |
| 262 |
|
|
\fB/C\fP PCRE_AUTO_CALLOUT |
| 263 |
|
|
\fB/E\fP PCRE_DOLLAR_ENDONLY |
| 264 |
|
|
\fB/f\fP PCRE_FIRSTLINE |
| 265 |
|
|
\fB/J\fP PCRE_DUPNAMES |
| 266 |
|
|
\fB/N\fP PCRE_NO_AUTO_CAPTURE |
| 267 |
|
|
\fB/U\fP PCRE_UNGREEDY |
| 268 |
ph10 |
535 |
\fB/W\fP PCRE_UCP |
| 269 |
ph10 |
231 |
\fB/X\fP PCRE_EXTRA |
| 270 |
ph10 |
579 |
\fB/Y\fP PCRE_NO_START_OPTIMIZE |
| 271 |
ph10 |
345 |
\fB/<JS>\fP PCRE_JAVASCRIPT_COMPAT |
| 272 |
ph10 |
231 |
\fB/<cr>\fP PCRE_NEWLINE_CR |
| 273 |
|
|
\fB/<lf>\fP PCRE_NEWLINE_LF |
| 274 |
|
|
\fB/<crlf>\fP PCRE_NEWLINE_CRLF |
| 275 |
|
|
\fB/<anycrlf>\fP PCRE_NEWLINE_ANYCRLF |
| 276 |
|
|
\fB/<any>\fP PCRE_NEWLINE_ANY |
| 277 |
|
|
\fB/<bsr_anycrlf>\fP PCRE_BSR_ANYCRLF |
| 278 |
|
|
\fB/<bsr_unicode>\fP PCRE_BSR_UNICODE |
| 279 |
nigel |
75 |
.sp |
| 280 |
ph10 |
518 |
The modifiers that are enclosed in angle brackets are literal strings as shown, |
| 281 |
ph10 |
612 |
including the angle brackets, but the letters within can be in either case. |
| 282 |
|
|
This example sets multiline matching with CRLF as the line ending sequence: |
| 283 |
nigel |
93 |
.sp |
| 284 |
ph10 |
612 |
/^abc/m<CRLF> |
| 285 |
nigel |
93 |
.sp |
| 286 |
ph10 |
866 |
As well as turning on the PCRE_UTF8/16 option, the \fB/8\fP modifier causes |
| 287 |
|
|
all non-printing characters in output strings to be printed using the |
| 288 |
ph10 |
903 |
\ex{hh...} notation. Otherwise, those less than 0x100 are output in hex without |
| 289 |
ph10 |
866 |
the curly brackets. |
| 290 |
|
|
.P |
| 291 |
|
|
Full details of the PCRE options are given in the |
| 292 |
nigel |
91 |
.\" HREF |
| 293 |
|
|
\fBpcreapi\fP |
| 294 |
|
|
.\" |
| 295 |
ph10 |
535 |
documentation. |
| 296 |
nigel |
91 |
. |
| 297 |
|
|
. |
| 298 |
|
|
.SS "Finding all matches in a string" |
| 299 |
|
|
.rs |
| 300 |
|
|
.sp |
| 301 |
nigel |
53 |
Searching for all possible matches within each subject string can be requested |
| 302 |
nigel |
75 |
by the \fB/g\fP or \fB/G\fP modifier. After finding a match, PCRE is called |
| 303 |
nigel |
53 |
again to search the remainder of the subject string. The difference between |
| 304 |
nigel |
75 |
\fB/g\fP and \fB/G\fP is that the former uses the \fIstartoffset\fP argument to |
| 305 |
ph10 |
866 |
\fBpcre[16]_exec()\fP to start searching at a new point within the entire |
| 306 |
|
|
string (which is in effect what Perl does), whereas the latter passes over a |
| 307 |
|
|
shortened substring. This makes a difference to the matching process if the |
| 308 |
|
|
pattern begins with a lookbehind assertion (including \eb or \eB). |
| 309 |
nigel |
75 |
.P |
| 310 |
ph10 |
866 |
If any call to \fBpcre[16]_exec()\fP in a \fB/g\fP or \fB/G\fP sequence matches |
| 311 |
|
|
an empty string, the next call is done with the PCRE_NOTEMPTY_ATSTART and |
| 312 |
ph10 |
442 |
PCRE_ANCHORED flags set in order to search for another, non-empty, match at the |
| 313 |
ph10 |
566 |
same point. If this second match fails, the start offset is advanced, and the |
| 314 |
|
|
normal match is retried. This imitates the way Perl handles such cases when |
| 315 |
ph10 |
579 |
using the \fB/g\fP modifier or the \fBsplit()\fP function. Normally, the start |
| 316 |
|
|
offset is advanced by one character, but if the newline convention recognizes |
| 317 |
|
|
CRLF as a newline, and the current character is CR followed by LF, an advance |
| 318 |
ph10 |
566 |
of two is used. |
| 319 |
nigel |
91 |
. |
| 320 |
|
|
. |
| 321 |
|
|
.SS "Other modifiers" |
| 322 |
|
|
.rs |
| 323 |
|
|
.sp |
| 324 |
nigel |
75 |
There are yet more modifiers for controlling the way \fBpcretest\fP |
| 325 |
nigel |
53 |
operates. |
| 326 |
nigel |
75 |
.P |
| 327 |
|
|
The \fB/+\fP modifier requests that as well as outputting the substring that |
| 328 |
ph10 |
616 |
matched the entire pattern, \fBpcretest\fP should in addition output the |
| 329 |
|
|
remainder of the subject string. This is useful for tests where the subject |
| 330 |
|
|
contains multiple copies of the same substring. If the \fB+\fP modifier appears |
| 331 |
ph10 |
654 |
twice, the same action is taken for captured substrings. In each case the |
| 332 |
|
|
remainder is output on the following line with a plus character following the |
| 333 |
ph10 |
691 |
capture number. Note that this modifier must not immediately follow the /S |
| 334 |
ph10 |
930 |
modifier because /S+ and /S++ have other meanings. |
| 335 |
nigel |
75 |
.P |
| 336 |
ph10 |
654 |
The \fB/=\fP modifier requests that the values of all potential captured |
| 337 |
ph10 |
866 |
parentheses be output after a match. By default, only those up to the highest |
| 338 |
|
|
one actually used in the match are output (corresponding to the return code |
| 339 |
|
|
from \fBpcre[16]_exec()\fP). Values in the offsets vector corresponding to |
| 340 |
|
|
higher numbers should be set to -1, and these are output as "<unset>". This |
| 341 |
|
|
modifier gives a way of checking that this is happening. |
| 342 |
ph10 |
626 |
.P |
| 343 |
nigel |
93 |
The \fB/B\fP modifier is a debugging feature. It requests that \fBpcretest\fP |
| 344 |
ph10 |
866 |
output a representation of the compiled code after compilation. Normally this |
| 345 |
|
|
information contains length and offset values; however, if \fB/Z\fP is also |
| 346 |
|
|
present, this data is replaced by spaces. This is a special feature for use in |
| 347 |
|
|
the automatic test scripts; it ensures that the same output is generated for |
| 348 |
|
|
different internal link sizes. |
| 349 |
nigel |
93 |
.P |
| 350 |
|
|
The \fB/D\fP modifier is a PCRE debugging feature, and is equivalent to |
| 351 |
ph10 |
148 |
\fB/BI\fP, that is, both the \fB/B\fP and the \fB/I\fP modifiers. |
| 352 |
nigel |
75 |
.P |
| 353 |
|
|
The \fB/F\fP modifier causes \fBpcretest\fP to flip the byte order of the |
| 354 |
ph10 |
866 |
2-byte and 4-byte fields in the compiled pattern. This facility is for testing |
| 355 |
|
|
the feature in PCRE that allows it to execute patterns that were compiled on a |
| 356 |
|
|
host with a different endianness. This feature is not available when the POSIX |
| 357 |
|
|
interface to PCRE is being used, that is, when the \fB/P\fP pattern modifier is |
| 358 |
|
|
specified. See also the section about saving and reloading compiled patterns |
| 359 |
|
|
below. |
| 360 |
nigel |
75 |
.P |
| 361 |
ph10 |
510 |
The \fB/I\fP modifier requests that \fBpcretest\fP output information about the |
| 362 |
|
|
compiled pattern (whether it is anchored, has a fixed first character, and |
| 363 |
ph10 |
866 |
so on). It does this by calling \fBpcre[16]_fullinfo()\fP after compiling a |
| 364 |
ph10 |
510 |
pattern. If the pattern is studied, the results of that are also output. |
| 365 |
nigel |
75 |
.P |
| 366 |
ph10 |
510 |
The \fB/K\fP modifier requests \fBpcretest\fP to show names from backtracking |
| 367 |
ph10 |
866 |
control verbs that are returned from calls to \fBpcre[16]_exec()\fP. It causes |
| 368 |
|
|
\fBpcretest\fP to create a \fBpcre[16]_extra\fP block if one has not already |
| 369 |
|
|
been created by a call to \fBpcre[16]_study()\fP, and to set the |
| 370 |
|
|
PCRE_EXTRA_MARK flag and the \fBmark\fP field within it, every time that |
| 371 |
|
|
\fBpcre[16]_exec()\fP is called. If the variable that the \fBmark\fP field |
| 372 |
|
|
points to is non-NULL for a match, non-match, or partial match, \fBpcretest\fP |
| 373 |
|
|
prints the string to which it points. For a match, this is shown on a line by |
| 374 |
|
|
itself, tagged with "MK:". For a non-match it is added to the message. |
| 375 |
ph10 |
510 |
.P |
| 376 |
|
|
The \fB/L\fP modifier must be followed directly by the name of a locale, for |
| 377 |
|
|
example, |
| 378 |
|
|
.sp |
| 379 |
|
|
/pattern/Lfr_FR |
| 380 |
|
|
.sp |
| 381 |
|
|
For this reason, it must be the last modifier. The given locale is set, |
| 382 |
ph10 |
866 |
\fBpcre[16]_maketables()\fP is called to build a set of character tables for |
| 383 |
|
|
the locale, and this is then passed to \fBpcre[16]_compile()\fP when compiling |
| 384 |
|
|
the regular expression. Without an \fB/L\fP (or \fB/T\fP) modifier, NULL is |
| 385 |
|
|
passed as the tables pointer; that is, \fB/L\fP applies only to the expression |
| 386 |
|
|
on which it appears. |
| 387 |
ph10 |
510 |
.P |
| 388 |
ph10 |
866 |
The \fB/M\fP modifier causes the size in bytes of the memory block used to hold |
| 389 |
|
|
the compiled pattern to be output. This does not include the size of the |
| 390 |
|
|
\fBpcre[16]\fP block; it is just the actual compiled data. If the pattern is |
| 391 |
|
|
successfully studied with the PCRE_STUDY_JIT_COMPILE option, the size of the |
| 392 |
|
|
JIT compiled code is also output. |
| 393 |
nigel |
75 |
.P |
| 394 |
ph10 |
866 |
If the \fB/S\fP modifier appears once, it causes \fBpcre[16]_study()\fP to be |
| 395 |
ph10 |
612 |
called after the expression has been compiled, and the results used when the |
| 396 |
ph10 |
654 |
expression is matched. If \fB/S\fP appears twice, it suppresses studying, even |
| 397 |
|
|
if it was requested externally by the \fB-s\fP command line option. This makes |
| 398 |
|
|
it possible to specify that certain patterns are always studied, and others are |
| 399 |
|
|
never studied, independently of \fB-s\fP. This feature is used in the test |
| 400 |
ph10 |
612 |
files in a few cases where the output is different when the pattern is studied. |
| 401 |
ph10 |
541 |
.P |
| 402 |
ph10 |
691 |
If the \fB/S\fP modifier is immediately followed by a + character, the call to |
| 403 |
ph10 |
923 |
\fBpcre[16]_study()\fP is made with all the JIT study options, requesting |
| 404 |
|
|
just-in-time optimization support if it is available, for both normal and |
| 405 |
ph10 |
975 |
partial matching. If you want to restrict the JIT compiling modes, you can |
| 406 |
ph10 |
923 |
follow \fB/S+\fP with a digit in the range 1 to 7: |
| 407 |
|
|
.sp |
| 408 |
|
|
1 normal match only |
| 409 |
|
|
2 soft partial match only |
| 410 |
|
|
3 normal match and soft partial match |
| 411 |
|
|
4 hard partial match only |
| 412 |
|
|
6 soft and hard partial match |
| 413 |
|
|
7 all three modes (default) |
| 414 |
ph10 |
975 |
.sp |
| 415 |
ph10 |
923 |
If \fB/S++\fP is used instead of \fB/S+\fP (with or without a following digit), |
| 416 |
|
|
the text "(JIT)" is added to the first output line after a match or no match |
| 417 |
|
|
when JIT-compiled code was actually used. |
| 418 |
|
|
.P |
| 419 |
|
|
Note that there is also an independent \fB/+\fP modifier; it must not be given |
| 420 |
ph10 |
975 |
immediately after \fB/S\fP or \fB/S+\fP because this will be misinterpreted. |
| 421 |
ph10 |
923 |
.P |
| 422 |
|
|
If JIT studying is successful, the compiled JIT code will automatically be used |
| 423 |
|
|
when \fBpcre[16]_exec()\fP is run, except when incompatible run-time options |
| 424 |
|
|
are specified. For more details, see the |
| 425 |
ph10 |
678 |
.\" HREF |
| 426 |
|
|
\fBpcrejit\fP |
| 427 |
|
|
.\" |
| 428 |
ph10 |
691 |
documentation. See also the \fB\eJ\fP escape sequence below for a way of |
| 429 |
ph10 |
678 |
setting the size of the JIT stack. |
| 430 |
|
|
.P |
| 431 |
ph10 |
545 |
The \fB/T\fP modifier must be followed by a single digit. It causes a specific |
| 432 |
ph10 |
866 |
set of built-in character tables to be passed to \fBpcre[16]_compile()\fP. It |
| 433 |
|
|
is used in the standard PCRE tests to check behaviour with different character |
| 434 |
ph10 |
541 |
tables. The digit specifies the tables as follows: |
| 435 |
|
|
.sp |
| 436 |
ph10 |
545 |
0 the default ASCII tables, as distributed in |
| 437 |
ph10 |
541 |
pcre_chartables.c.dist |
| 438 |
|
|
1 a set of tables defining ISO 8859 characters |
| 439 |
|
|
.sp |
| 440 |
ph10 |
545 |
In table 1, some characters whose codes are greater than 128 are identified as |
| 441 |
ph10 |
541 |
letters, digits, spaces, etc. |
| 442 |
nigel |
75 |
. |
| 443 |
|
|
. |
| 444 |
ph10 |
518 |
.SS "Using the POSIX wrapper API" |
| 445 |
|
|
.rs |
| 446 |
|
|
.sp |
| 447 |
|
|
The \fB/P\fP modifier causes \fBpcretest\fP to call PCRE via the POSIX wrapper |
| 448 |
ph10 |
866 |
API rather than its native API. This supports only the 8-bit library. When |
| 449 |
|
|
\fB/P\fP is set, the following modifiers set options for the \fBregcomp()\fP |
| 450 |
|
|
function: |
| 451 |
ph10 |
518 |
.sp |
| 452 |
|
|
/i REG_ICASE |
| 453 |
|
|
/m REG_NEWLINE |
| 454 |
|
|
/N REG_NOSUB |
| 455 |
|
|
/s REG_DOTALL ) |
| 456 |
ph10 |
535 |
/U REG_UNGREEDY ) These options are not part of |
| 457 |
ph10 |
518 |
/W REG_UCP ) the POSIX standard |
| 458 |
|
|
/8 REG_UTF8 ) |
| 459 |
|
|
.sp |
| 460 |
|
|
The \fB/+\fP modifier works as described above. All other modifiers are |
| 461 |
|
|
ignored. |
| 462 |
|
|
. |
| 463 |
|
|
. |
| 464 |
nigel |
75 |
.SH "DATA LINES" |
| 465 |
nigel |
63 |
.rs |
| 466 |
|
|
.sp |
| 467 |
ph10 |
866 |
Before each data line is passed to \fBpcre[16]_exec()\fP, leading and trailing |
| 468 |
ph10 |
599 |
white space is removed, and it is then scanned for \e escapes. Some of these |
| 469 |
|
|
are pretty esoteric features, intended for checking out some of the more |
| 470 |
nigel |
63 |
complicated features of PCRE. If you are just testing "ordinary" regular |
| 471 |
|
|
expressions, you probably don't need any of these. The following escapes are |
| 472 |
nigel |
53 |
recognized: |
| 473 |
nigel |
75 |
.sp |
| 474 |
nigel |
93 |
\ea alarm (BEL, \ex07) |
| 475 |
|
|
\eb backspace (\ex08) |
| 476 |
|
|
\ee escape (\ex27) |
| 477 |
ph10 |
599 |
\ef form feed (\ex0c) |
| 478 |
nigel |
93 |
\en newline (\ex0a) |
| 479 |
nigel |
91 |
.\" JOIN |
| 480 |
|
|
\eqdd set the PCRE_MATCH_LIMIT limit to dd |
| 481 |
|
|
(any number of digits) |
| 482 |
nigel |
93 |
\er carriage return (\ex0d) |
| 483 |
|
|
\et tab (\ex09) |
| 484 |
|
|
\ev vertical tab (\ex0b) |
| 485 |
ph10 |
866 |
\ennn octal character (up to 3 octal digits); always |
| 486 |
|
|
a byte unless > 255 in UTF-8 or 16-bit mode |
| 487 |
ph10 |
570 |
\exhh hexadecimal byte (up to 2 hex digits) |
| 488 |
ph10 |
866 |
\ex{hh...} hexadecimal character (any number of hex digits) |
| 489 |
nigel |
75 |
.\" JOIN |
| 490 |
ph10 |
866 |
\eA pass the PCRE_ANCHORED option to \fBpcre[16]_exec()\fP |
| 491 |
|
|
or \fBpcre[16]_dfa_exec()\fP |
| 492 |
nigel |
91 |
.\" JOIN |
| 493 |
ph10 |
866 |
\eB pass the PCRE_NOTBOL option to \fBpcre[16]_exec()\fP |
| 494 |
|
|
or \fBpcre[16]_dfa_exec()\fP |
| 495 |
nigel |
91 |
.\" JOIN |
| 496 |
ph10 |
866 |
\eCdd call pcre[16]_copy_substring() for substring dd |
| 497 |
nigel |
75 |
after a successful match (number less than 32) |
| 498 |
|
|
.\" JOIN |
| 499 |
ph10 |
866 |
\eCname call pcre[16]_copy_named_substring() for substring |
| 500 |
nigel |
63 |
"name" after a successful match (name termin- |
| 501 |
|
|
ated by next non alphanumeric character) |
| 502 |
nigel |
75 |
.\" JOIN |
| 503 |
|
|
\eC+ show the current captured substrings at callout |
| 504 |
nigel |
63 |
time |
| 505 |
nigel |
75 |
\eC- do not supply a callout function |
| 506 |
|
|
.\" JOIN |
| 507 |
|
|
\eC!n return 1 instead of 0 when callout number n is |
| 508 |
nigel |
63 |
reached |
| 509 |
nigel |
75 |
.\" JOIN |
| 510 |
|
|
\eC!n!m return 1 instead of 0 when callout number n is |
| 511 |
nigel |
63 |
reached for the nth time |
| 512 |
nigel |
75 |
.\" JOIN |
| 513 |
|
|
\eC*n pass the number n (may be negative) as callout |
| 514 |
|
|
data; this is used as the callout return value |
| 515 |
ph10 |
866 |
\eD use the \fBpcre[16]_dfa_exec()\fP match function |
| 516 |
|
|
\eF only shortest match for \fBpcre[16]_dfa_exec()\fP |
| 517 |
nigel |
75 |
.\" JOIN |
| 518 |
ph10 |
866 |
\eGdd call pcre[16]_get_substring() for substring dd |
| 519 |
nigel |
75 |
after a successful match (number less than 32) |
| 520 |
|
|
.\" JOIN |
| 521 |
ph10 |
866 |
\eGname call pcre[16]_get_named_substring() for substring |
| 522 |
nigel |
63 |
"name" after a successful match (name termin- |
| 523 |
|
|
ated by next non-alphanumeric character) |
| 524 |
nigel |
75 |
.\" JOIN |
| 525 |
ph10 |
678 |
\eJdd set up a JIT stack of dd kilobytes maximum (any |
| 526 |
ph10 |
691 |
number of digits) |
| 527 |
ph10 |
678 |
.\" JOIN |
| 528 |
ph10 |
866 |
\eL call pcre[16]_get_substringlist() after a |
| 529 |
nigel |
63 |
successful match |
| 530 |
nigel |
91 |
.\" JOIN |
| 531 |
nigel |
87 |
\eM discover the minimum MATCH_LIMIT and |
| 532 |
|
|
MATCH_LIMIT_RECURSION settings |
| 533 |
nigel |
91 |
.\" JOIN |
| 534 |
ph10 |
866 |
\eN pass the PCRE_NOTEMPTY option to \fBpcre[16]_exec()\fP |
| 535 |
|
|
or \fBpcre[16]_dfa_exec()\fP; if used twice, pass the |
| 536 |
ph10 |
461 |
PCRE_NOTEMPTY_ATSTART option |
| 537 |
nigel |
75 |
.\" JOIN |
| 538 |
|
|
\eOdd set the size of the output vector passed to |
| 539 |
ph10 |
866 |
\fBpcre[16]_exec()\fP to dd (any number of digits) |
| 540 |
nigel |
77 |
.\" JOIN |
| 541 |
ph10 |
866 |
\eP pass the PCRE_PARTIAL_SOFT option to \fBpcre[16]_exec()\fP |
| 542 |
|
|
or \fBpcre[16]_dfa_exec()\fP; if used twice, pass the |
| 543 |
ph10 |
461 |
PCRE_PARTIAL_HARD option |
| 544 |
nigel |
91 |
.\" JOIN |
| 545 |
|
|
\eQdd set the PCRE_MATCH_LIMIT_RECURSION limit to dd |
| 546 |
|
|
(any number of digits) |
| 547 |
ph10 |
866 |
\eR pass the PCRE_DFA_RESTART option to \fBpcre[16]_dfa_exec()\fP |
| 548 |
nigel |
75 |
\eS output details of memory get/free calls during matching |
| 549 |
nigel |
91 |
.\" JOIN |
| 550 |
ph10 |
866 |
\eY pass the PCRE_NO_START_OPTIMIZE option to \fBpcre[16]_exec()\fP |
| 551 |
|
|
or \fBpcre[16]_dfa_exec()\fP |
| 552 |
ph10 |
455 |
.\" JOIN |
| 553 |
ph10 |
866 |
\eZ pass the PCRE_NOTEOL option to \fBpcre[16]_exec()\fP |
| 554 |
|
|
or \fBpcre[16]_dfa_exec()\fP |
| 555 |
nigel |
75 |
.\" JOIN |
| 556 |
ph10 |
866 |
\e? pass the PCRE_NO_UTF[8|16]_CHECK option to |
| 557 |
|
|
\fBpcre[16]_exec()\fP or \fBpcre[16]_dfa_exec()\fP |
| 558 |
nigel |
91 |
.\" JOIN |
| 559 |
ph10 |
567 |
\e>dd start the match at offset dd (optional "-"; then |
| 560 |
ph10 |
579 |
any number of digits); this sets the \fIstartoffset\fP |
| 561 |
ph10 |
866 |
argument for \fBpcre[16]_exec()\fP or \fBpcre[16]_dfa_exec()\fP |
| 562 |
nigel |
91 |
.\" JOIN |
| 563 |
ph10 |
866 |
\e<cr> pass the PCRE_NEWLINE_CR option to \fBpcre[16]_exec()\fP |
| 564 |
|
|
or \fBpcre[16]_dfa_exec()\fP |
| 565 |
nigel |
91 |
.\" JOIN |
| 566 |
ph10 |
866 |
\e<lf> pass the PCRE_NEWLINE_LF option to \fBpcre[16]_exec()\fP |
| 567 |
|
|
or \fBpcre[16]_dfa_exec()\fP |
| 568 |
nigel |
91 |
.\" JOIN |
| 569 |
ph10 |
866 |
\e<crlf> pass the PCRE_NEWLINE_CRLF option to \fBpcre[16]_exec()\fP |
| 570 |
|
|
or \fBpcre[16]_dfa_exec()\fP |
| 571 |
nigel |
93 |
.\" JOIN |
| 572 |
ph10 |
866 |
\e<anycrlf> pass the PCRE_NEWLINE_ANYCRLF option to \fBpcre[16]_exec()\fP |
| 573 |
|
|
or \fBpcre[16]_dfa_exec()\fP |
| 574 |
ph10 |
149 |
.\" JOIN |
| 575 |
ph10 |
866 |
\e<any> pass the PCRE_NEWLINE_ANY option to \fBpcre[16]_exec()\fP |
| 576 |
|
|
or \fBpcre[16]_dfa_exec()\fP |
| 577 |
nigel |
75 |
.sp |
| 578 |
ph10 |
866 |
The use of \ex{hh...} is not dependent on the use of the \fB/8\fP modifier on |
| 579 |
|
|
the pattern. It is recognized always. There may be any number of hexadecimal |
| 580 |
|
|
digits inside the braces; invalid values provoke error messages. |
| 581 |
ph10 |
570 |
.P |
| 582 |
ph10 |
873 |
Note that \exhh specifies one byte rather than one character in UTF-8 mode; |
| 583 |
|
|
this makes it possible to construct invalid UTF-8 sequences for testing |
| 584 |
|
|
purposes. On the other hand, \ex{hh} is interpreted as a UTF-8 character in |
| 585 |
|
|
UTF-8 mode, generating more than one byte if the value is greater than 127. |
| 586 |
|
|
When testing the 8-bit library not in UTF-8 mode, \ex{hh} generates one byte |
| 587 |
|
|
for values less than 256, and causes an error for greater values. |
| 588 |
ph10 |
866 |
.P |
| 589 |
|
|
In UTF-16 mode, all 4-digit \ex{hhhh} values are accepted. This makes it |
| 590 |
|
|
possible to construct invalid UTF-16 sequences for testing purposes. |
| 591 |
|
|
.P |
| 592 |
nigel |
93 |
The escapes that specify line ending sequences are literal strings, exactly as |
| 593 |
|
|
shown. No more than one newline setting should be present in any data line. |
| 594 |
nigel |
75 |
.P |
| 595 |
nigel |
93 |
A backslash followed by anything else just escapes the anything else. If |
| 596 |
|
|
the very last character is a backslash, it is ignored. This gives a way of |
| 597 |
|
|
passing an empty line as data, since a real empty line terminates the data |
| 598 |
|
|
input. |
| 599 |
|
|
.P |
| 600 |
ph10 |
678 |
The \fB\eJ\fP escape provides a way of setting the maximum stack size that is |
| 601 |
ph10 |
691 |
used by the just-in-time optimization code. It is ignored if JIT optimization |
| 602 |
|
|
is not being used. Providing a stack that is larger than the default 32K is |
| 603 |
ph10 |
678 |
necessary only for very complicated patterns. |
| 604 |
|
|
.P |
| 605 |
ph10 |
866 |
If \eM is present, \fBpcretest\fP calls \fBpcre[16]_exec()\fP several times, |
| 606 |
|
|
with different values in the \fImatch_limit\fP and \fImatch_limit_recursion\fP |
| 607 |
|
|
fields of the \fBpcre[16]_extra\fP data structure, until it finds the minimum |
| 608 |
|
|
numbers for each parameter that allow \fBpcre[16]_exec()\fP to complete without |
| 609 |
ph10 |
691 |
error. Because this is testing a specific feature of the normal interpretive |
| 610 |
ph10 |
866 |
\fBpcre[16]_exec()\fP execution, the use of any JIT optimization that might |
| 611 |
|
|
have been set up by the \fB/S+\fP qualifier of \fB-s+\fP option is disabled. |
| 612 |
nigel |
75 |
.P |
| 613 |
ph10 |
678 |
The \fImatch_limit\fP number is a measure of the amount of backtracking |
| 614 |
|
|
that takes place, and checking it out can be instructive. For most simple |
| 615 |
|
|
matches, the number is quite small, but for patterns with very large numbers of |
| 616 |
|
|
matching possibilities, it can become large very quickly with increasing length |
| 617 |
|
|
of subject string. The \fImatch_limit_recursion\fP number is a measure of how |
| 618 |
|
|
much stack (or, if PCRE is compiled with NO_RECURSE, how much heap) memory is |
| 619 |
|
|
needed to complete the match attempt. |
| 620 |
|
|
.P |
| 621 |
nigel |
75 |
When \eO is used, the value specified may be higher or lower than the size set |
| 622 |
|
|
by the \fB-O\fP command line option (or defaulted to 45); \eO applies only to |
| 623 |
ph10 |
866 |
the call of \fBpcre[16]_exec()\fP for the line in which it appears. |
| 624 |
nigel |
75 |
.P |
| 625 |
|
|
If the \fB/P\fP modifier was present on the pattern, causing the POSIX wrapper |
| 626 |
ph10 |
518 |
API to be used, the only option-setting sequences that have any effect are \eB, |
| 627 |
|
|
\eN, and \eZ, causing REG_NOTBOL, REG_NOTEMPTY, and REG_NOTEOL, respectively, |
| 628 |
|
|
to be passed to \fBregexec()\fP. |
| 629 |
nigel |
75 |
. |
| 630 |
|
|
. |
| 631 |
nigel |
77 |
.SH "THE ALTERNATIVE MATCHING FUNCTION" |
| 632 |
nigel |
63 |
.rs |
| 633 |
|
|
.sp |
| 634 |
nigel |
77 |
By default, \fBpcretest\fP uses the standard PCRE matching function, |
| 635 |
ph10 |
866 |
\fBpcre[16]_exec()\fP to match each data line. PCRE also supports an |
| 636 |
|
|
alternative matching function, \fBpcre[16]_dfa_test()\fP, which operates in a |
| 637 |
nigel |
77 |
different way, and has some restrictions. The differences between the two |
| 638 |
|
|
functions are described in the |
| 639 |
|
|
.\" HREF |
| 640 |
|
|
\fBpcrematching\fP |
| 641 |
|
|
.\" |
| 642 |
|
|
documentation. |
| 643 |
|
|
.P |
| 644 |
|
|
If a data line contains the \eD escape sequence, or if the command line |
| 645 |
ph10 |
866 |
contains the \fB-dfa\fP option, the alternative matching function is used. |
| 646 |
nigel |
77 |
This function finds all possible matches at a given point. If, however, the \eF |
| 647 |
|
|
escape sequence is present in the data line, it stops after the first match is |
| 648 |
|
|
found. This is always the shortest possible match. |
| 649 |
|
|
. |
| 650 |
|
|
. |
| 651 |
|
|
.SH "DEFAULT OUTPUT FROM PCRETEST" |
| 652 |
|
|
.rs |
| 653 |
|
|
.sp |
| 654 |
|
|
This section describes the output when the normal matching function, |
| 655 |
ph10 |
866 |
\fBpcre[16]_exec()\fP, is being used. |
| 656 |
nigel |
77 |
.P |
| 657 |
ph10 |
598 |
When a match succeeds, \fBpcretest\fP outputs the list of captured substrings |
| 658 |
ph10 |
866 |
that \fBpcre[16]_exec()\fP returns, starting with number 0 for the string that |
| 659 |
ph10 |
598 |
matched the whole pattern. Otherwise, it outputs "No match" when the return is |
| 660 |
ph10 |
435 |
PCRE_ERROR_NOMATCH, and "Partial match:" followed by the partially matching |
| 661 |
ph10 |
866 |
substring when \fBpcre[16]_exec()\fP returns PCRE_ERROR_PARTIAL. (Note that |
| 662 |
|
|
this is the entire substring that was inspected during the partial match; it |
| 663 |
|
|
may include characters before the actual match start if a lookbehind assertion, |
| 664 |
ph10 |
598 |
\eK, \eb, or \eB was involved.) For any other return, \fBpcretest\fP outputs |
| 665 |
|
|
the PCRE negative error number and a short descriptive phrase. If the error is |
| 666 |
ph10 |
866 |
a failed UTF string check, the offset of the start of the failing character and |
| 667 |
|
|
the reason code are also output, provided that the size of the output vector is |
| 668 |
|
|
at least two. Here is an example of an interactive \fBpcretest\fP run. |
| 669 |
nigel |
75 |
.sp |
| 670 |
nigel |
53 |
$ pcretest |
| 671 |
ph10 |
598 |
PCRE version 8.13 2011-04-30 |
| 672 |
nigel |
75 |
.sp |
| 673 |
|
|
re> /^abc(\ed+)/ |
| 674 |
nigel |
53 |
data> abc123 |
| 675 |
|
|
0: abc123 |
| 676 |
|
|
1: 123 |
| 677 |
|
|
data> xyz |
| 678 |
|
|
No match |
| 679 |
nigel |
75 |
.sp |
| 680 |
ph10 |
598 |
Unset capturing substrings that are not followed by one that is set are not |
| 681 |
ph10 |
866 |
returned by \fBpcre[16]_exec()\fP, and are not shown by \fBpcretest\fP. In the |
| 682 |
ph10 |
598 |
following example, there are two capturing substrings, but when the first data |
| 683 |
|
|
line is matched, the second, unset substring is not shown. An "internal" unset |
| 684 |
|
|
substring is shown as "<unset>", as for the second data line. |
| 685 |
ph10 |
273 |
.sp |
| 686 |
|
|
re> /(a)|(b)/ |
| 687 |
|
|
data> a |
| 688 |
|
|
0: a |
| 689 |
|
|
1: a |
| 690 |
|
|
data> b |
| 691 |
|
|
0: b |
| 692 |
|
|
1: <unset> |
| 693 |
ph10 |
286 |
2: b |
| 694 |
ph10 |
273 |
.sp |
| 695 |
ph10 |
866 |
If the strings contain any non-printing characters, they are output as \exhh |
| 696 |
ph10 |
903 |
escapes if the value is less than 256 and UTF mode is not set. Otherwise they |
| 697 |
ph10 |
866 |
are output as \ex{hh...} escapes. See below for the definition of non-printing |
| 698 |
|
|
characters. If the pattern has the \fB/+\fP modifier, the output for substring |
| 699 |
|
|
0 is followed by the the rest of the subject string, identified by "0+" like |
| 700 |
|
|
this: |
| 701 |
nigel |
75 |
.sp |
| 702 |
nigel |
53 |
re> /cat/+ |
| 703 |
|
|
data> cataract |
| 704 |
|
|
0: cat |
| 705 |
|
|
0+ aract |
| 706 |
nigel |
75 |
.sp |
| 707 |
|
|
If the pattern has the \fB/g\fP or \fB/G\fP modifier, the results of successive |
| 708 |
nigel |
53 |
matching attempts are output in sequence, like this: |
| 709 |
nigel |
75 |
.sp |
| 710 |
|
|
re> /\eBi(\ew\ew)/g |
| 711 |
nigel |
53 |
data> Mississippi |
| 712 |
|
|
0: iss |
| 713 |
|
|
1: ss |
| 714 |
|
|
0: iss |
| 715 |
|
|
1: ss |
| 716 |
|
|
0: ipp |
| 717 |
|
|
1: pp |
| 718 |
nigel |
75 |
.sp |
| 719 |
ph10 |
654 |
"No match" is output only if the first match attempt fails. Here is an example |
| 720 |
|
|
of a failure message (the offset 4 that is specified by \e>4 is past the end of |
| 721 |
ph10 |
598 |
the subject string): |
| 722 |
|
|
.sp |
| 723 |
|
|
re> /xyz/ |
| 724 |
ph10 |
654 |
data> xyz\e>4 |
| 725 |
|
|
Error -24 (bad offset value) |
| 726 |
nigel |
75 |
.P |
| 727 |
|
|
If any of the sequences \fB\eC\fP, \fB\eG\fP, or \fB\eL\fP are present in a |
| 728 |
nigel |
53 |
data line that is successfully matched, the substrings extracted by the |
| 729 |
|
|
convenience functions are output with C, G, or L after the string number |
| 730 |
|
|
instead of a colon. This is in addition to the normal full list. The string |
| 731 |
|
|
length (that is, the return from the extraction function) is given in |
| 732 |
nigel |
75 |
parentheses after each string for \fB\eC\fP and \fB\eG\fP. |
| 733 |
|
|
.P |
| 734 |
nigel |
93 |
Note that whereas patterns can be continued over several lines (a plain ">" |
| 735 |
nigel |
53 |
prompt is used for continuations), data lines may not. However newlines can be |
| 736 |
nigel |
93 |
included in data by means of the \en escape (or \er, \er\en, etc., depending on |
| 737 |
|
|
the newline sequence setting). |
| 738 |
nigel |
75 |
. |
| 739 |
|
|
. |
| 740 |
nigel |
93 |
. |
| 741 |
nigel |
77 |
.SH "OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION" |
| 742 |
|
|
.rs |
| 743 |
|
|
.sp |
| 744 |
ph10 |
866 |
When the alternative matching function, \fBpcre[16]_dfa_exec()\fP, is used (by |
| 745 |
nigel |
77 |
means of the \eD escape sequence or the \fB-dfa\fP command line option), the |
| 746 |
|
|
output consists of a list of all the matches that start at the first point in |
| 747 |
|
|
the subject where there is at least one match. For example: |
| 748 |
|
|
.sp |
| 749 |
|
|
re> /(tang|tangerine|tan)/ |
| 750 |
|
|
data> yellow tangerine\eD |
| 751 |
|
|
0: tangerine |
| 752 |
|
|
1: tang |
| 753 |
|
|
2: tan |
| 754 |
|
|
.sp |
| 755 |
|
|
(Using the normal matching function on this data finds only "tang".) The |
| 756 |
ph10 |
428 |
longest matching string is always given first (and numbered zero). After a |
| 757 |
ph10 |
461 |
PCRE_ERROR_PARTIAL return, the output is "Partial match:", followed by the |
| 758 |
ph10 |
553 |
partially matching substring. (Note that this is the entire substring that was |
| 759 |
|
|
inspected during the partial match; it may include characters before the actual |
| 760 |
|
|
match start if a lookbehind assertion, \eK, \eb, or \eB was involved.) |
| 761 |
nigel |
77 |
.P |
| 762 |
nigel |
93 |
If \fB/g\fP is present on the pattern, the search for further matches resumes |
| 763 |
nigel |
77 |
at the end of the longest match. For example: |
| 764 |
|
|
.sp |
| 765 |
|
|
re> /(tang|tangerine|tan)/g |
| 766 |
|
|
data> yellow tangerine and tangy sultana\eD |
| 767 |
|
|
0: tangerine |
| 768 |
|
|
1: tang |
| 769 |
|
|
2: tan |
| 770 |
|
|
0: tang |
| 771 |
|
|
1: tan |
| 772 |
|
|
0: tan |
| 773 |
|
|
.sp |
| 774 |
|
|
Since the matching function does not support substring capture, the escape |
| 775 |
|
|
sequences that are concerned with captured substrings are not relevant. |
| 776 |
|
|
. |
| 777 |
|
|
. |
| 778 |
|
|
.SH "RESTARTING AFTER A PARTIAL MATCH" |
| 779 |
|
|
.rs |
| 780 |
|
|
.sp |
| 781 |
|
|
When the alternative matching function has given the PCRE_ERROR_PARTIAL return, |
| 782 |
|
|
indicating that the subject partially matched the pattern, you can restart the |
| 783 |
|
|
match with additional subject data by means of the \eR escape sequence. For |
| 784 |
|
|
example: |
| 785 |
|
|
.sp |
| 786 |
ph10 |
155 |
re> /^\ed?\ed(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\ed\ed$/ |
| 787 |
nigel |
77 |
data> 23ja\eP\eD |
| 788 |
|
|
Partial match: 23ja |
| 789 |
|
|
data> n05\eR\eD |
| 790 |
|
|
0: n05 |
| 791 |
|
|
.sp |
| 792 |
|
|
For further information about partial matching, see the |
| 793 |
|
|
.\" HREF |
| 794 |
|
|
\fBpcrepartial\fP |
| 795 |
|
|
.\" |
| 796 |
|
|
documentation. |
| 797 |
|
|
. |
| 798 |
|
|
. |
| 799 |
nigel |
75 |
.SH CALLOUTS |
| 800 |
|
|
.rs |
| 801 |
|
|
.sp |
| 802 |
|
|
If the pattern contains any callout requests, \fBpcretest\fP's callout function |
| 803 |
nigel |
77 |
is called during matching. This works with both matching functions. By default, |
| 804 |
|
|
the called function displays the callout number, the start and current |
| 805 |
|
|
positions in the text at the callout time, and the next pattern item to be |
| 806 |
ph10 |
866 |
tested. For example: |
| 807 |
nigel |
75 |
.sp |
| 808 |
|
|
--->pqrabcdef |
| 809 |
|
|
0 ^ ^ \ed |
| 810 |
|
|
.sp |
| 811 |
ph10 |
866 |
This output indicates that callout number 0 occurred for a match attempt |
| 812 |
|
|
starting at the fourth character of the subject string, when the pointer was at |
| 813 |
|
|
the seventh character of the data, and when the next pattern item was \ed. Just |
| 814 |
|
|
one circumflex is output if the start and current positions are the same. |
| 815 |
nigel |
75 |
.P |
| 816 |
|
|
Callouts numbered 255 are assumed to be automatic callouts, inserted as a |
| 817 |
|
|
result of the \fB/C\fP pattern modifier. In this case, instead of showing the |
| 818 |
|
|
callout number, the offset in the pattern, preceded by a plus, is output. For |
| 819 |
|
|
example: |
| 820 |
|
|
.sp |
| 821 |
|
|
re> /\ed?[A-E]\e*/C |
| 822 |
|
|
data> E* |
| 823 |
|
|
--->E* |
| 824 |
|
|
+0 ^ \ed? |
| 825 |
|
|
+3 ^ [A-E] |
| 826 |
|
|
+8 ^^ \e* |
| 827 |
|
|
+10 ^ ^ |
| 828 |
|
|
0: E* |
| 829 |
|
|
.sp |
| 830 |
ph10 |
647 |
If a pattern contains (*MARK) items, an additional line is output whenever |
| 831 |
|
|
a change of latest mark is passed to the callout function. For example: |
| 832 |
|
|
.sp |
| 833 |
|
|
re> /a(*MARK:X)bc/C |
| 834 |
|
|
data> abc |
| 835 |
|
|
--->abc |
| 836 |
|
|
+0 ^ a |
| 837 |
|
|
+1 ^^ (*MARK:X) |
| 838 |
|
|
+10 ^^ b |
| 839 |
|
|
Latest Mark: X |
| 840 |
|
|
+11 ^ ^ c |
| 841 |
ph10 |
654 |
+12 ^ ^ |
| 842 |
ph10 |
647 |
0: abc |
| 843 |
|
|
.sp |
| 844 |
|
|
The mark changes between matching "a" and "b", but stays the same for the rest |
| 845 |
|
|
of the match, so nothing more is output. If, as a result of backtracking, the |
| 846 |
|
|
mark reverts to being unset, the text "<unset>" is output. |
| 847 |
|
|
.P |
| 848 |
nigel |
75 |
The callout function in \fBpcretest\fP returns zero (carry on matching) by |
| 849 |
nigel |
77 |
default, but you can use a \eC item in a data line (as described above) to |
| 850 |
ph10 |
647 |
change this and other parameters of the callout. |
| 851 |
nigel |
75 |
.P |
| 852 |
|
|
Inserting callouts can be helpful when using \fBpcretest\fP to check |
| 853 |
|
|
complicated regular expressions. For further information about callouts, see |
| 854 |
|
|
the |
| 855 |
|
|
.\" HREF |
| 856 |
|
|
\fBpcrecallout\fP |
| 857 |
|
|
.\" |
| 858 |
|
|
documentation. |
| 859 |
|
|
. |
| 860 |
|
|
. |
| 861 |
nigel |
93 |
. |
| 862 |
|
|
.SH "NON-PRINTING CHARACTERS" |
| 863 |
|
|
.rs |
| 864 |
|
|
.sp |
| 865 |
|
|
When \fBpcretest\fP is outputting text in the compiled version of a pattern, |
| 866 |
|
|
bytes other than 32-126 are always treated as non-printing characters are are |
| 867 |
|
|
therefore shown as hex escapes. |
| 868 |
|
|
.P |
| 869 |
|
|
When \fBpcretest\fP is outputting text that is a matched part of a subject |
| 870 |
|
|
string, it behaves in the same way, unless a different locale has been set for |
| 871 |
|
|
the pattern (using the \fB/L\fP modifier). In this case, the \fBisprint()\fP |
| 872 |
|
|
function to distinguish printing and non-printing characters. |
| 873 |
|
|
. |
| 874 |
|
|
. |
| 875 |
|
|
. |
| 876 |
nigel |
75 |
.SH "SAVING AND RELOADING COMPILED PATTERNS" |
| 877 |
|
|
.rs |
| 878 |
|
|
.sp |
| 879 |
|
|
The facilities described in this section are not available when the POSIX |
| 880 |
ph10 |
599 |
interface to PCRE is being used, that is, when the \fB/P\fP pattern modifier is |
| 881 |
ph10 |
691 |
specified. |
| 882 |
nigel |
75 |
.P |
| 883 |
|
|
When the POSIX interface is not in use, you can cause \fBpcretest\fP to write a |
| 884 |
|
|
compiled pattern to a file, by following the modifiers with > and a file name. |
| 885 |
|
|
For example: |
| 886 |
|
|
.sp |
| 887 |
|
|
/pattern/im >/some/file |
| 888 |
|
|
.sp |
| 889 |
|
|
See the |
| 890 |
|
|
.\" HREF |
| 891 |
|
|
\fBpcreprecompile\fP |
| 892 |
|
|
.\" |
| 893 |
|
|
documentation for a discussion about saving and re-using compiled patterns. |
| 894 |
ph10 |
678 |
Note that if the pattern was successfully studied with JIT optimization, the |
| 895 |
|
|
JIT data cannot be saved. |
| 896 |
nigel |
75 |
.P |
| 897 |
|
|
The data that is written is binary. The first eight bytes are the length of the |
| 898 |
|
|
compiled pattern data followed by the length of the optional study data, each |
| 899 |
|
|
written as four bytes in big-endian order (most significant byte first). If |
| 900 |
|
|
there is no study data (either the pattern was not studied, or studying did not |
| 901 |
|
|
return any data), the second length is zero. The lengths are followed by an |
| 902 |
|
|
exact copy of the compiled pattern. If there is additional study data, this |
| 903 |
ph10 |
678 |
(excluding any JIT data) follows immediately after the compiled pattern. After |
| 904 |
|
|
writing the file, \fBpcretest\fP expects to read a new pattern. |
| 905 |
nigel |
75 |
.P |
| 906 |
ph10 |
599 |
A saved pattern can be reloaded into \fBpcretest\fP by specifying < and a file |
| 907 |
nigel |
75 |
name instead of a pattern. The name of the file must not contain a < character, |
| 908 |
|
|
as otherwise \fBpcretest\fP will interpret the line as a pattern delimited by < |
| 909 |
|
|
characters. |
| 910 |
|
|
For example: |
| 911 |
|
|
.sp |
| 912 |
|
|
re> </some/file |
| 913 |
ph10 |
612 |
Compiled pattern loaded from /some/file |
| 914 |
nigel |
75 |
No study data |
| 915 |
|
|
.sp |
| 916 |
ph10 |
678 |
If the pattern was previously studied with the JIT optimization, the JIT |
| 917 |
|
|
information cannot be saved and restored, and so is lost. When the pattern has |
| 918 |
|
|
been loaded, \fBpcretest\fP proceeds to read data lines in the usual way. |
| 919 |
nigel |
75 |
.P |
| 920 |
|
|
You can copy a file written by \fBpcretest\fP to a different host and reload it |
| 921 |
|
|
there, even if the new host has opposite endianness to the one on which the |
| 922 |
|
|
pattern was compiled. For example, you can compile on an i86 machine and run on |
| 923 |
ph10 |
903 |
a SPARC machine. When a pattern is reloaded on a host with different |
| 924 |
ph10 |
866 |
endianness, the confirmation message is changed to: |
| 925 |
|
|
.sp |
| 926 |
|
|
Compiled pattern (byte-inverted) loaded from /some/file |
| 927 |
|
|
.sp |
| 928 |
ph10 |
903 |
The test suite contains some saved pre-compiled patterns with different |
| 929 |
|
|
endianness. These are reloaded using "<!" instead of just "<". This suppresses |
| 930 |
|
|
the "(byte-inverted)" text so that the output is the same on all hosts. It also |
| 931 |
|
|
forces debugging output once the pattern has been reloaded. |
| 932 |
nigel |
75 |
.P |
| 933 |
|
|
File names for saving and reloading can be absolute or relative, but note that |
| 934 |
|
|
the shell facility of expanding a file name that starts with a tilde (~) is not |
| 935 |
|
|
available. |
| 936 |
|
|
.P |
| 937 |
|
|
The ability to save and reload files in \fBpcretest\fP is intended for testing |
| 938 |
|
|
and experimentation. It is not intended for production use because only a |
| 939 |
|
|
single pattern can be written to a file. Furthermore, there is no facility for |
| 940 |
|
|
supplying custom character tables for use with a reloaded pattern. If the |
| 941 |
|
|
original pattern was compiled with custom tables, an attempt to match a subject |
| 942 |
|
|
string using a reloaded pattern is likely to cause \fBpcretest\fP to crash. |
| 943 |
|
|
Finally, if you attempt to load a file that is not in the correct format, the |
| 944 |
|
|
result is undefined. |
| 945 |
|
|
. |
| 946 |
|
|
. |
| 947 |
nigel |
93 |
.SH "SEE ALSO" |
| 948 |
|
|
.rs |
| 949 |
|
|
.sp |
| 950 |
ph10 |
866 |
\fBpcre\fP(3), \fBpcre16\fP(3), \fBpcreapi\fP(3), \fBpcrecallout\fP(3), |
| 951 |
|
|
\fBpcrejit\fP, \fBpcrematching\fP(3), \fBpcrepartial\fP(d), |
| 952 |
|
|
\fBpcrepattern\fP(3), \fBpcreprecompile\fP(3). |
| 953 |
nigel |
93 |
. |
| 954 |
|
|
. |
| 955 |
nigel |
53 |
.SH AUTHOR |
| 956 |
nigel |
63 |
.rs |
| 957 |
|
|
.sp |
| 958 |
ph10 |
99 |
.nf |
| 959 |
nigel |
77 |
Philip Hazel |
| 960 |
ph10 |
99 |
University Computing Service |
| 961 |
nigel |
93 |
Cambridge CB2 3QH, England. |
| 962 |
ph10 |
99 |
.fi |
| 963 |
|
|
. |
| 964 |
|
|
. |
| 965 |
|
|
.SH REVISION |
| 966 |
|
|
.rs |
| 967 |
|
|
.sp |
| 968 |
|
|
.nf |
| 969 |
ph10 |
923 |
Last updated: 21 February 2012 |
| 970 |
ph10 |
866 |
Copyright (c) 1997-2012 University of Cambridge. |
| 971 |
ph10 |
99 |
.fi |