Sortix cross-volatile manual
This manual documents Sortix cross-volatile. You can instead view this document in the latest official manual.
PCRETEST(1) | General Commands Manual | PCRETEST(1) |
NAME
pcretest - a program for testing Perl-compatible regular expressions.SYNOPSIS
pcretest [options] [input file [output file]]INPUT DATA FORMAT
Input to pcretest is processed line by line, either by calling the C library's fgets() function, or via the libreadline library (see below). In Unix-like environments, fgets() treats any bytes other than newline as data characters. However, in some Windows environments character 26 (hex 1A) causes an immediate end of file, and no further data is read. For maximum portability, therefore, it is safest to use only ASCII characters in pcretest input files.PCRE's 8-BIT, 16-BIT AND 32-BIT LIBRARIES
From release 8.30, two separate PCRE libraries can be built. The original one supports 8-bit character strings, whereas the newer 16-bit library supports character strings encoded in 16-bit units. From release 8.32, a third library can be built, supporting character strings encoded in 32-bit units. The pcretest program can be used to test all three libraries. However, it is itself still an 8-bit program, reading 8-bit input and writing 8-bit output. When testing the 16-bit or 32-bit library, the patterns and data strings are converted to 16- or 32-bit format before being passed to the PCRE library functions. Results are converted to 8-bit for output.COMMAND LINE OPTIONS
- -8
- If the 8-bit library has been built, this option causes it to be used (this is the default). If the 8-bit library has not been built, this option causes an error.
- -16
- If the 16-bit library has been built, this option causes it to be used. If only the 16-bit library has been built, this is the default. If the 16-bit library has not been built, this option causes an error.
- -32
- If the 32-bit library has been built, this option causes it to be used. If only the 32-bit library has been built, this is the default. If the 32-bit library has not been built, this option causes an error.
- -b
- Behave as if each pattern has the /B (show byte code) modifier; the internal form is output after compilation.
- -C
- Output the version number of the PCRE library, and all available information about the optional features that are included, and then exit with zero exit code. All other options are ignored.
- -C option
-
Output information about a specific build-time option, then exit. This functionality is intended for use in scripts such as RunTest. The following options output the value and set the exit code as indicated:
ebcdic-nl the code for LF (= NL) in an EBCDIC environment:
0x15 or 0x25
0 if used in an ASCII environment
exit code is always 0
linksize the configured internal link size (2, 3, or 4)
exit code is set to the link size
newline the default newline setting:
CR, LF, CRLF, ANYCRLF, or ANY
exit code is always 0
bsr the default setting for what \R matches:
ANYCRLF or ANY
exit code is always 0
ebcdic compiled for an EBCDIC environment
jit just-in-time support is available
pcre16 the 16-bit library was built
pcre32 the 32-bit library was built
pcre8 the 8-bit library was built
ucp Unicode property support is available
utf UTF-8 and/or UTF-16 and/or UTF-32 support
is available
- -d
- Behave as if each pattern has the /D (debug) modifier; the internal form and information about the compiled pattern is output after compilation; -d is equivalent to -b -i.
- -dfa
- Behave as if each data line contains the \D escape sequence; this causes the alternative matching function, pcre[16|32]_dfa_exec(), to be used instead of the standard pcre[16|32]_exec() function (more detail is given below).
- -help
- Output a brief summary these options and then exit.
- -i
- Behave as if each pattern has the /I modifier; information about the compiled pattern is given after compilation.
- -M
- Behave as if each data line contains the \M escape sequence; this causes PCRE to discover the minimum MATCH_LIMIT and MATCH_LIMIT_RECURSION settings by calling pcre[16|32]_exec() repeatedly with different limits.
- -m
- Output the size of each compiled pattern after it has been compiled. This is equivalent to adding /M to each regular expression. The size is given in bytes for both libraries.
- -O
- Behave as if each pattern has the /O modifier, that is disable auto-possessification for all patterns.
- -o osize
- Set the number of elements in the output vector that is used when calling pcre[16|32]_exec() or pcre[16|32]_dfa_exec() to be osize. The default value is 45, which is enough for 14 capturing subexpressions for pcre[16|32]_exec() or 22 different matches for pcre[16|32]_dfa_exec(). The vector size can be changed for individual matching calls by including \O in the data line (see below).
- -p
- Behave as if each pattern has the /P modifier; the POSIX wrapper API is used to call PCRE. None of the other options has any effect when -p is set. This option can be used only with the 8-bit library.
- -q
- Do not output the version number of pcretest at the start of execution.
- -S size
- On Unix-like systems, set the size of the run-time stack to size megabytes.
- -s or -s+
-
Behave as if each pattern has the /S modifier; in other words, force each pattern to be studied. If -s+ is used, all the JIT compile options are passed to pcre[16|32]_study(), causing just-in-time optimization to be set up if it is available, for both full and partial matching. Specific JIT compile options can be selected by following -s+ with a digit in the range 1 to 7, which selects the JIT compile modes as follows:
1 normal match only
2 soft partial match only
3 normal match and soft partial match
4 hard partial match only
6 soft and hard partial match
7 all three modes (default)
- -t
- Run each compile, study, and match many times with a timer, and output the resulting times per compile, study, or match (in milliseconds). Do not set -m with -t, because you will then get the size output a zillion times, and the timing will be distorted. You can control the number of iterations that are used for timing by following -t with a number (as a separate item on the command line). For example, "-t 1000" iterates 1000 times. The default is to iterate 500000 times.
- -tm
- This is like -t except that it times only the matching phase, not the compile or study phases.
- -T -TM
- These behave like -t and -tm, but in addition, at the end of a run, the total times for all compiles, studies, and matches are output.
DESCRIPTION
If pcretest is given two filename arguments, it reads from the first and writes to the second. If it is given only one filename argument, it reads from that file and writes to stdout. Otherwise, it reads from stdin and writes to stdout, and prompts for each line of input, using "re>" to prompt for regular expressions, and "data>" to prompt for data lines./(a|bc)x+yz/
/abc\/def/
/abc/\
/abc\/
PATTERN MODIFIERS
A pattern may be followed by any number of modifiers, which are mostly single characters, though some of these can be qualified by further characters. Following Perl usage, these are referred to below as, for example, "the /i modifier", even though the delimiter of the pattern need not always be a slash, and no slash is used when writing modifiers. White space may appear between the final pattern delimiter and the first modifier, and between the modifiers themselves. For reference, here is a complete list of modifiers. They fall into several groups that are described in detail in the following sections./8 set UTF mode
/9 set PCRE_NEVER_UTF (locks out UTF mode)
/? disable UTF validity check
/+ show remainder of subject after match
/= show all captures (not just those that are set)
/A set PCRE_ANCHORED
/B show compiled code
/C set PCRE_AUTO_CALLOUT
/D same as /B plus /I
/E set PCRE_DOLLAR_ENDONLY
/F flip byte order in compiled pattern
/f set PCRE_FIRSTLINE
/G find all matches (shorten string)
/g find all matches (use startoffset)
/I show information about pattern
/i set PCRE_CASELESS
/J set PCRE_DUPNAMES
/K show backtracking control names
/L set locale
/M show compiled memory size
/m set PCRE_MULTILINE
/N set PCRE_NO_AUTO_CAPTURE
/O set PCRE_NO_AUTO_POSSESS
/P use the POSIX wrapper
/Q test external stack check function
/S study the pattern after compilation
/s set PCRE_DOTALL
/T select character tables
/U set PCRE_UNGREEDY
/W set PCRE_UCP
/X set PCRE_EXTRA
/x set PCRE_EXTENDED
/Y set PCRE_NO_START_OPTIMIZE
/Z don't show lengths in /B output
/<any> set PCRE_NEWLINE_ANY
/<anycrlf> set PCRE_NEWLINE_ANYCRLF
/<cr> set PCRE_NEWLINE_CR
/<crlf> set PCRE_NEWLINE_CRLF
/<lf> set PCRE_NEWLINE_LF
/<bsr_anycrlf> set PCRE_BSR_ANYCRLF
/<bsr_unicode> set PCRE_BSR_UNICODE
/<JS> set PCRE_JAVASCRIPT_COMPAT
Perl-compatible modifiers
The /i, /m, /s, and /x modifiers set the PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, or PCRE_EXTENDED options, respectively, when pcre[16|32]_compile() is called. These four modifier letters have the same effect as they do in Perl. For example:/caseless/i
Modifiers for other PCRE options
The following table shows additional modifiers for setting PCRE compile-time options that do not correspond to anything in Perl:/8 PCRE_UTF8 ) when using the 8-bit
/? PCRE_NO_UTF8_CHECK ) library
/8 PCRE_UTF16 ) when using the 16-bit
/? PCRE_NO_UTF16_CHECK ) library
/8 PCRE_UTF32 ) when using the 32-bit
/? PCRE_NO_UTF32_CHECK ) library
/9 PCRE_NEVER_UTF
/A PCRE_ANCHORED
/C PCRE_AUTO_CALLOUT
/E PCRE_DOLLAR_ENDONLY
/f PCRE_FIRSTLINE
/J PCRE_DUPNAMES
/N PCRE_NO_AUTO_CAPTURE
/O PCRE_NO_AUTO_POSSESS
/U PCRE_UNGREEDY
/W PCRE_UCP
/X PCRE_EXTRA
/Y PCRE_NO_START_OPTIMIZE
/<any> PCRE_NEWLINE_ANY
/<anycrlf> PCRE_NEWLINE_ANYCRLF
/<cr> PCRE_NEWLINE_CR
/<crlf> PCRE_NEWLINE_CRLF
/<lf> PCRE_NEWLINE_LF
/<bsr_anycrlf> PCRE_BSR_ANYCRLF
/<bsr_unicode> PCRE_BSR_UNICODE
/<JS> PCRE_JAVASCRIPT_COMPAT
/^abc/m<CRLF>
Finding all matches in a string
Searching for all possible matches within each subject string can be requested by the /g or /G modifier. After finding a match, PCRE is called again to search the remainder of the subject string. The difference between /g and /G is that the former uses the startoffset argument to pcre[16|32]_exec() to start searching at a new point within the entire string (which is in effect what Perl does), whereas the latter passes over a shortened substring. This makes a difference to the matching process if the pattern begins with a lookbehind assertion (including \b or \B).Other modifiers
There are yet more modifiers for controlling the way pcretest operates./pattern/Lfr_FR
1 normal match only
2 soft partial match only
3 normal match and soft partial match
4 hard partial match only
6 soft and hard partial match
7 all three modes (default)
0 the default ASCII tables, as distributed in
pcre_chartables.c.dist
1 a set of tables defining ISO 8859 characters
Using the POSIX wrapper API
The /P modifier causes pcretest to call PCRE via the POSIX wrapper API rather than its native API. This supports only the 8-bit library. When /P is set, the following modifiers set options for the regcomp() function:/i REG_ICASE
/m REG_NEWLINE
/N REG_NOSUB
/s REG_DOTALL )
/U REG_UNGREEDY ) These options are not part of
/W REG_UCP ) the POSIX standard
/8 REG_UTF8 )
Locking out certain modifiers
PCRE can be compiled with or without support for certain features such as UTF-8/16/32 or Unicode properties. Accordingly, the standard tests are split up into a number of different files that are selected for running depending on which features are available. When updating the tests, it is all too easy to put a new test into the wrong file by mistake; for example, to put a test that requires UTF support into a file that is used when it is not available. To help detect such mistakes as early as possible, there is a facility for locking out specific modifiers. If an input line for pcretest starts with the string "< forbid " the following sequence of characters is taken as a list of forbidden modifiers. For example, in the test files that must not use UTF or Unicode property support, this line appears:< forbid 8W
< forbid <JS><cr>
DATA LINES
Before each data line is passed to pcre[16|32]_exec(), leading and trailing white space is removed, and it is then scanned for \ escapes. Some of these are pretty esoteric features, intended for checking out some of the more complicated features of PCRE. If you are just testing "ordinary" regular expressions, you probably don't need any of these. The following escapes are recognized:\a alarm (BEL, \x07)
\b backspace (\x08)
\e escape (\x27)
\f form feed (\x0c)
\n newline (\x0a)
\qdd set the PCRE_MATCH_LIMIT limit to dd
(any number of digits)
\r carriage return (\x0d)
\t tab (\x09)
\v vertical tab (\x0b)
\nnn octal character (up to 3 octal digits); always
a byte unless > 255 in UTF-8 or 16-bit or 32-bit mode
\o{dd...} octal character (any number of octal digits}
\xhh hexadecimal byte (up to 2 hex digits)
\x{hh...} hexadecimal character (any number of hex digits)
\A pass the PCRE_ANCHORED option to pcre[16|32]_exec()
or pcre[16|32]_dfa_exec()
\B pass the PCRE_NOTBOL option to pcre[16|32]_exec()
or pcre[16|32]_dfa_exec()
\Cdd call pcre[16|32]_copy_substring() for substring dd
after a successful match (number less than 32)
\Cname call pcre[16|32]_copy_named_substring() for substring
"name" after a successful match (name termin-
ated by next non alphanumeric character)
\C+ show the current captured substrings at callout
time
\C- do not supply a callout function
\C!n return 1 instead of 0 when callout number n is
reached
\C!n!m return 1 instead of 0 when callout number n is
reached for the nth time
\C*n pass the number n (may be negative) as callout
data; this is used as the callout return value
\D use the pcre[16|32]_dfa_exec() match function
\F only shortest match for pcre[16|32]_dfa_exec()
\Gdd call pcre[16|32]_get_substring() for substring dd
after a successful match (number less than 32)
\Gname call pcre[16|32]_get_named_substring() for substring
"name" after a successful match (name termin-
ated by next non-alphanumeric character)
\Jdd set up a JIT stack of dd kilobytes maximum (any
number of digits)
\L call pcre[16|32]_get_substringlist() after a
successful match
\M discover the minimum MATCH_LIMIT and
MATCH_LIMIT_RECURSION settings
\N pass the PCRE_NOTEMPTY option to pcre[16|32]_exec()
or pcre[16|32]_dfa_exec(); if used twice, pass the
PCRE_NOTEMPTY_ATSTART option
\Odd set the size of the output vector passed to
pcre[16|32]_exec() to dd (any number of digits)
\P pass the PCRE_PARTIAL_SOFT option to pcre[16|32]_exec()
or pcre[16|32]_dfa_exec(); if used twice, pass the
PCRE_PARTIAL_HARD option
\Qdd set the PCRE_MATCH_LIMIT_RECURSION limit to dd
(any number of digits)
\R pass the PCRE_DFA_RESTART option to pcre[16|32]_dfa_exec()
\S output details of memory get/free calls during matching
\Y pass the PCRE_NO_START_OPTIMIZE option to pcre[16|32]_exec()
or pcre[16|32]_dfa_exec()
\Z pass the PCRE_NOTEOL option to pcre[16|32]_exec()
or pcre[16|32]_dfa_exec()
\? pass the PCRE_NO_UTF[8|16|32]_CHECK option to
pcre[16|32]_exec() or pcre[16|32]_dfa_exec()
\>dd start the match at offset dd (optional "-"; then
any number of digits); this sets the startoffset
argument for pcre[16|32]_exec() or pcre[16|32]_dfa_exec()
\<cr> pass the PCRE_NEWLINE_CR option to pcre[16|32]_exec()
or pcre[16|32]_dfa_exec()
\<lf> pass the PCRE_NEWLINE_LF option to pcre[16|32]_exec()
or pcre[16|32]_dfa_exec()
\<crlf> pass the PCRE_NEWLINE_CRLF option to pcre[16|32]_exec()
or pcre[16|32]_dfa_exec()
\<anycrlf> pass the PCRE_NEWLINE_ANYCRLF option to pcre[16|32]_exec()
or pcre[16|32]_dfa_exec()
\<any> pass the PCRE_NEWLINE_ANY option to pcre[16|32]_exec()
or pcre[16|32]_dfa_exec()
THE ALTERNATIVE MATCHING FUNCTION
By default, pcretest uses the standard PCRE matching function, pcre[16|32]_exec() to match each data line. PCRE also supports an alternative matching function, pcre[16|32]_dfa_test(), which operates in a different way, and has some restrictions. The differences between the two functions are described in the pcrematching documentation.DEFAULT OUTPUT FROM PCRETEST
This section describes the output when the normal matching function, pcre[16|32]_exec(), is being used.$ pcretest
PCRE version 8.13 2011-04-30
re> /^abc(\d+)/
data> abc123
0: abc123
1: 123
data> xyz
No match
re> /(a)|(b)/
data> a
0: a
1: a
data> b
0: b
1: <unset>
2: b
re> /cat/+
data> cataract
0: cat
0+ aract
re> /\Bi(\w\w)/g
data> Mississippi
0: iss
1: ss
0: iss
1: ss
0: ipp
1: pp
re> /xyz/
data> xyz\>4
Error -24 (bad offset value)
OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION
When the alternative matching function, pcre[16|32]_dfa_exec(), is used (by means of the \D escape sequence or the -dfa command line option), the output consists of a list of all the matches that start at the first point in the subject where there is at least one match. For example:re> /(tang|tangerine|tan)/
data> yellow tangerine\D
0: tangerine
1: tang
2: tan
re> /(tang|tangerine|tan)/g
data> yellow tangerine and tangy sultana\D
0: tangerine
1: tang
2: tan
0: tang
1: tan
0: tan
RESTARTING AFTER A PARTIAL MATCH
When the alternative matching function has given the PCRE_ERROR_PARTIAL return, indicating that the subject partially matched the pattern, you can restart the match with additional subject data by means of the \R escape sequence. For example:re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/
data> 23ja\P\D
Partial match: 23ja
data> n05\R\D
0: n05
CALLOUTS
If the pattern contains any callout requests, pcretest's callout function is called during matching. This works with both matching functions. By default, the called function displays the callout number, the start and current positions in the text at the callout time, and the next pattern item to be tested. For example:--->pqrabcdef
0 ^ ^ \d
re> /\d?[A-E]\*/C
data> E*
--->E*
+0 ^ \d?
+3 ^ [A-E]
+8 ^^ \*
+10 ^ ^
0: E*
re> /a(*MARK:X)bc/C
data> abc
--->abc
+0 ^ a
+1 ^^ (*MARK:X)
+10 ^^ b
Latest Mark: X
+11 ^ ^ c
+12 ^ ^
0: abc
NON-PRINTING CHARACTERS
When pcretest is outputting text in the compiled version of a pattern, bytes other than 32-126 are always treated as non-printing characters are are therefore shown as hex escapes.SAVING AND RELOADING COMPILED PATTERNS
The facilities described in this section are not available when the POSIX interface to PCRE is being used, that is, when the /P pattern modifier is specified./pattern/im >/some/file
re> </some/file
Compiled pattern loaded from /some/file
No study data
Compiled pattern (byte-inverted) loaded from /some/file
SEE ALSO
pcre(3), pcre16(3), pcre32(3), pcreapi(3), pcrecallout(3), pcrejit, pcrematching(3), pcrepartial(d), pcrepattern(3), pcreprecompile(3).10 February 2020 | PCRE 8.44 |