diff --git a/CMakeLists.txt b/CMakeLists.txt index bde940a..59f4ef5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,7 +146,7 @@ SET(PCRE2_PARENS_NEST_LIMIT "250" CACHE STRING "Default nested parentheses limit. See PARENS_NEST_LIMIT in config.h.in for details.") SET(PCRE2_HEAP_LIMIT "20000000" CACHE STRING - "Default limit on heap memory (kilobytes). See HEAP_LIMIT in config.h.in for details.") + "Default limit on heap memory (kibibytes). See HEAP_LIMIT in config.h.in for details.") SET(PCRE2_MATCH_LIMIT "10000000" CACHE STRING "Default limit on internal looping. See MATCH_LIMIT in config.h.in for details.") diff --git a/ChangeLog b/ChangeLog index 1aa9460..2600fbb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,7 +17,7 @@ groups altogether. Now it shows those that come before any actual captures as 3. Running "pcre2test -C" always stated "\R matches CR, LF, or CRLF only", whatever the build configuration was. It now correctly says "\R matches all Unicode newlines" in the default case when --enable-bsr-anycrlf has not been -specified. Similarly, running "pcfre2test -C bsr" never produced the result +specified. Similarly, running "pcre2test -C bsr" never produced the result ANY. 4. Matching the pattern /(*UTF)\C[^\v]+\x80/ against an 8-bit string containing @@ -370,7 +370,7 @@ tests to improve coverage. 31. If more than one of "push", "pushcopy", or "pushtablescopy" were set in pcre2test, a crash could occur. -32. Make -bigstack in RunTest allocate a 64Mb stack (instead of 16 MB) so that +32. Make -bigstack in RunTest allocate a 64MB stack (instead of 16 MB) so that all the tests can run with clang's sanitizing options. 33. Implement extra compile options in the compile context and add the first diff --git a/HACKING b/HACKING index d727add..c96f9e1 100644 --- a/HACKING +++ b/HACKING @@ -348,7 +348,7 @@ The /i, /m, or /s options (PCRE2_CASELESS, PCRE2_MULTILINE, PCRE2_DOTALL, and others) may be changed in the middle of patterns by items such as (?i). Their processing is handled entirely at compile time by generating different opcodes for the different settings. The runtime functions do not need to keep track of -an options state. +an option's state. PCRE2_DUPNAMES, PCRE2_EXTENDED, PCRE2_EXTENDED_MORE, and PCRE2_NO_AUTO_CAPTURE are tracked and processed during the parsing pre-pass. The others are handled @@ -764,7 +764,7 @@ OP_RECURSE is followed by a LINK_SIZE value that is the offset to the starting bracket from the start of the whole pattern. OP_RECURSE is also used for "subroutine" calls, even though they are not strictly a recursion. Up till release 10.30 recursions were treated as atomic groups, making them -incompatible with Perl (but PCRE had then well before Perl did). From 10.30, +incompatible with Perl (but PCRE had them well before Perl did). From 10.30, backtracking into recursions is supported. Repeated recursions used to be wrapped inside OP_ONCE brackets, which not only diff --git a/NEWS b/NEWS index 0093eb7..d52dffe 100644 --- a/NEWS +++ b/NEWS @@ -31,7 +31,7 @@ remembering backtracking positions. This makes --disable-stack-for-recursion a NOOP. The new implementation allows backtracking into recursive group calls in patterns, making it more compatible with Perl, and also fixes some other previously hard-to-do issues. For patterns that have a lot of backtracking, the -heap is now used, and there is explicit limit on the amount, settable by +heap is now used, and there is an explicit limit on the amount, settable by pcre2_set_heap_limit() or (*LIMIT_HEAP=xxx). The "recursion limit" is retained, but is renamed as "depth limit" (though the old names remain for compatibility). @@ -53,7 +53,7 @@ also supported. 5. Additional compile options in the compile context are now available, and the first two are: PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES and -PCRE2_EXTRA_BAD_ESCAPE_IS LITERAL. +PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL. 6. The newline type PCRE2_NEWLINE_NUL is now available. diff --git a/NON-AUTOTOOLS-BUILD b/NON-AUTOTOOLS-BUILD index 0bf4507..c5b25e8 100644 --- a/NON-AUTOTOOLS-BUILD +++ b/NON-AUTOTOOLS-BUILD @@ -127,7 +127,7 @@ can skip ahead to the CMake section. src/pcre2_jit_match.c and src/pcre2_jit_misc.c, so you should not compile these yourself. - Not also that the pcre2_fuzzsupport.c file contains special code that is + Note also that the pcre2_fuzzsupport.c file contains special code that is useful to those who want to run fuzzing tests on the PCRE2 library. Unless you are doing that, you can ignore it. @@ -186,7 +186,7 @@ can skip ahead to the CMake section. STACK SIZE IN WINDOWS ENVIRONMENTS -Prior to release 10.30 the default system stack size of 1Mb in some Windows +Prior to release 10.30 the default system stack size of 1MB in some Windows environments caused issues with some tests. This should no longer be the case for 10.30 and later releases. diff --git a/README b/README index e4729ac..7e4a7a3 100644 --- a/README +++ b/README @@ -257,9 +257,10 @@ library. They are also documented in the pcre2build man page. --with-heap-limit=500 - The units are kilobytes. This limit does not apply when the JIT optimization - (which has its own memory control features) is used. There is more discussion - on the pcre2api man page (search for pcre2_set_heap_limit). + The units are kibibytes (units of 1024 bytes). This limit does not apply when + the JIT optimization (which has its own memory control features) is used. + There is more discussion on the pcre2api man page (search for + pcre2_set_heap_limit). . In the 8-bit library, the default maximum compiled pattern size is around 64K bytes. You can increase this by adding --with-link-size=3 to the @@ -319,10 +320,10 @@ library. They are also documented in the pcre2build man page. . When JIT support is enabled, pcre2grep automatically makes use of it, unless you add --disable-pcre2grep-jit to the "configure" command. -. On non-Windows sytems there is support for calling external scripts during - matching in the pcre2grep command via PCRE2's callout facility with string - arguments. This support can be disabled by adding --disable-pcre2grep-callout - to the "configure" command. +. There is support for calling external programs during matching in the + pcre2grep command, using PCRE2's callout facility with string arguments. This + support can be disabled by adding --disable-pcre2grep-callout to the + "configure" command. . The pcre2grep program currently supports only 8-bit data files, and so requires the 8-bit PCRE2 library. It is possible to compile pcre2grep to use @@ -887,4 +888,4 @@ The distribution should contain the files listed below. Philip Hazel Email local part: ph10 Email domain: cam.ac.uk -Last updated: 27 April 2018 +Last updated: 17 June 2018 diff --git a/RunGrepTest b/RunGrepTest index 293e5a5..16c47eb 100755 --- a/RunGrepTest +++ b/RunGrepTest @@ -708,7 +708,7 @@ $valgrind $vjs $pcre2grep -n --newline=any "^(abc|def|ghi|jkl)" testNinputgrep > printf "%c--------------------------- Test N6 ------------------------------\r\n" - >>testtrygrep $valgrind $vjs $pcre2grep -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep -# It seems inpossible to handle NUL characters easily in Solaris (aka SunOS). +# It seems impossible to handle NUL characters easily in Solaris (aka SunOS). # The version of sed explicitly doesn't like them. For the moment, we just # don't run this test under SunOS. Fudge the output so that the comparison # works. A similar problem has also been reported for MacOS (Darwin). diff --git a/RunTest b/RunTest index bc912da..1b5607c 100755 --- a/RunTest +++ b/RunTest @@ -843,7 +843,7 @@ for bmode in "$test8" "$test16" "$test32"; do checkresult $? 24 "" fi - # UTF pattern converson tests + # UTF pattern conversion tests if [ "$do25" = yes ] ; then echo $title25 diff --git a/configure.ac b/configure.ac index e3ca650..5379a99 100644 --- a/configure.ac +++ b/configure.ac @@ -288,7 +288,7 @@ AC_ARG_WITH(parens-nest-limit, # Handle --with-heap-limit AC_ARG_WITH(heap-limit, AS_HELP_STRING([--with-heap-limit=N], - [default limit on heap memory (kilobytes, default=20000000)]), + [default limit on heap memory (kibibytes, default=20000000)]), , with_heap_limit=20000000) # Handle --with-match-limit=N @@ -754,7 +754,7 @@ AC_DEFINE_UNQUOTED([MATCH_LIMIT_DEPTH], [$with_match_limit_depth], [ AC_DEFINE_UNQUOTED([HEAP_LIMIT], [$with_heap_limit], [ This limits the amount of memory that may be used while matching a pattern. It applies to both pcre2_match() and pcre2_dfa_match(). It does - not apply to JIT matching. The value is in kilobytes.]) + not apply to JIT matching. The value is in kibibytes (units of 1024 bytes).]) AC_DEFINE([MAX_NAME_SIZE], [32], [ This limit is parameterized just in case anybody ever wants to @@ -1017,7 +1017,7 @@ $PACKAGE-$VERSION configuration summary: Rebuild char tables ................ : ${enable_rebuild_chartables} Internal link size ................. : ${with_link_size} Nested parentheses limit ........... : ${with_parens_nest_limit} - Heap limit ......................... : ${with_heap_limit} kilobytes + Heap limit ......................... : ${with_heap_limit} kibibytes Match limit ........................ : ${with_match_limit} Match depth limit .................. : ${with_match_limit_depth} Build shared libs .................. : ${enable_shared} diff --git a/doc/html/NON-AUTOTOOLS-BUILD.txt b/doc/html/NON-AUTOTOOLS-BUILD.txt index 0bf4507..c5b25e8 100644 --- a/doc/html/NON-AUTOTOOLS-BUILD.txt +++ b/doc/html/NON-AUTOTOOLS-BUILD.txt @@ -127,7 +127,7 @@ can skip ahead to the CMake section. src/pcre2_jit_match.c and src/pcre2_jit_misc.c, so you should not compile these yourself. - Not also that the pcre2_fuzzsupport.c file contains special code that is + Note also that the pcre2_fuzzsupport.c file contains special code that is useful to those who want to run fuzzing tests on the PCRE2 library. Unless you are doing that, you can ignore it. @@ -186,7 +186,7 @@ can skip ahead to the CMake section. STACK SIZE IN WINDOWS ENVIRONMENTS -Prior to release 10.30 the default system stack size of 1Mb in some Windows +Prior to release 10.30 the default system stack size of 1MB in some Windows environments caused issues with some tests. This should no longer be the case for 10.30 and later releases. diff --git a/doc/html/README.txt b/doc/html/README.txt index e4729ac..7e4a7a3 100644 --- a/doc/html/README.txt +++ b/doc/html/README.txt @@ -257,9 +257,10 @@ library. They are also documented in the pcre2build man page. --with-heap-limit=500 - The units are kilobytes. This limit does not apply when the JIT optimization - (which has its own memory control features) is used. There is more discussion - on the pcre2api man page (search for pcre2_set_heap_limit). + The units are kibibytes (units of 1024 bytes). This limit does not apply when + the JIT optimization (which has its own memory control features) is used. + There is more discussion on the pcre2api man page (search for + pcre2_set_heap_limit). . In the 8-bit library, the default maximum compiled pattern size is around 64K bytes. You can increase this by adding --with-link-size=3 to the @@ -319,10 +320,10 @@ library. They are also documented in the pcre2build man page. . When JIT support is enabled, pcre2grep automatically makes use of it, unless you add --disable-pcre2grep-jit to the "configure" command. -. On non-Windows sytems there is support for calling external scripts during - matching in the pcre2grep command via PCRE2's callout facility with string - arguments. This support can be disabled by adding --disable-pcre2grep-callout - to the "configure" command. +. There is support for calling external programs during matching in the + pcre2grep command, using PCRE2's callout facility with string arguments. This + support can be disabled by adding --disable-pcre2grep-callout to the + "configure" command. . The pcre2grep program currently supports only 8-bit data files, and so requires the 8-bit PCRE2 library. It is possible to compile pcre2grep to use @@ -887,4 +888,4 @@ The distribution should contain the files listed below. Philip Hazel Email local part: ph10 Email domain: cam.ac.uk -Last updated: 27 April 2018 +Last updated: 17 June 2018 diff --git a/doc/html/pcre2_compile.html b/doc/html/pcre2_compile.html index 0a9eafa..d109eeb 100644 --- a/doc/html/pcre2_compile.html +++ b/doc/html/pcre2_compile.html @@ -65,7 +65,7 @@ The option bits are: PCRE2_EXTENDED Ignore white space and # comments PCRE2_FIRSTLINE Force matching to be before newline PCRE2_LITERAL Pattern characters are all literal - PCRE2_MATCH_UNSET_BACKREF Match unset back references + PCRE2_MATCH_UNSET_BACKREF Match unset backreferences PCRE2_MULTILINE ^ and $ match newlines within data PCRE2_NEVER_BACKSLASH_C Lock out the use of \C in patterns PCRE2_NEVER_UCP Lock out PCRE2_UCP, e.g. via (*UCP) diff --git a/doc/html/pcre2_pattern_info.html b/doc/html/pcre2_pattern_info.html index 1ebf90b..2e35709 100644 --- a/doc/html/pcre2_pattern_info.html +++ b/doc/html/pcre2_pattern_info.html @@ -36,7 +36,7 @@ request are as follows:
   PCRE2_INFO_ALLOPTIONS      Final options after compiling
   PCRE2_INFO_ARGOPTIONS      Options passed to pcre2_compile()
-  PCRE2_INFO_BACKREFMAX      Number of highest back reference
+  PCRE2_INFO_BACKREFMAX      Number of highest backreference
   PCRE2_INFO_BSR             What \R matches:
                                PCRE2_BSR_UNICODE: Unicode line endings
                                PCRE2_BSR_ANYCRLF: CR, LF, or CRLF only
diff --git a/doc/html/pcre2_set_glob_separator.html b/doc/html/pcre2_set_glob_separator.html
index 538748d..283648e 100644
--- a/doc/html/pcre2_set_glob_separator.html
+++ b/doc/html/pcre2_set_glob_separator.html
@@ -28,7 +28,7 @@ DESCRIPTION
 

This function is part of an experimental set of pattern conversion functions. It sets the component separator character that is used when converting globs. -The second argument must one of the characters forward slash, backslash, or +The second argument must be one of the characters forward slash, backslash, or dot. The default is backslash when running under Windows, otherwise forward slash. The result of the function is zero for success or PCRE2_ERROR_BADDATA if the second argument is invalid. diff --git a/doc/html/pcre2api.html b/doc/html/pcre2api.html index 7498afb..ec40f3b 100644 --- a/doc/html/pcre2api.html +++ b/doc/html/pcre2api.html @@ -562,10 +562,10 @@ U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS

Each of the first three conventions is used by at least one operating system as its standard newline sequence. When PCRE2 is built, a default can be specified. -The default default is LF, which is the Unix standard. However, the newline -convention can be changed by an application when calling pcre2_compile(), -or it can be specified by special text at the start of the pattern itself; this -overrides any other settings. See the +If it is not, the default is set to LF, which is the Unix standard. However, +the newline convention can be changed by an application when calling +pcre2_compile(), or it can be specified by special text at the start of +the pattern itself; this overrides any other settings. See the pcre2pattern page for details of the special character sequences.

@@ -949,17 +949,18 @@ offset limit. In other words, whichever limit comes first is used. uint32_t value);

-The heap_limit parameter specifies, in units of kilobytes, the maximum -amount of heap memory that pcre2_match() may use to hold backtracking -information when running an interpretive match. This limit also applies to -pcre2_dfa_match(), which may use the heap when processing patterns with a -lot of nested pattern recursion or lookarounds or atomic groups. This limit -does not apply to matching with the JIT optimization, which has its own memory -control arrangements (see the +The heap_limit parameter specifies, in units of kibibytes (1024 bytes), +the maximum amount of heap memory that pcre2_match() may use to hold +backtracking information when running an interpretive match. This limit also +applies to pcre2_dfa_match(), which may use the heap when processing +patterns with a lot of nested pattern recursion or lookarounds or atomic +groups. This limit does not apply to matching with the JIT optimization, which +has its own memory control arrangements (see the pcre2jit documentation for more details). If the limit is reached, the negative error -code PCRE2_ERROR_HEAPLIMIT is returned. The default limit is set when PCRE2 is -built; the default default is very large and is essentially "unlimited". +code PCRE2_ERROR_HEAPLIMIT is returned. The default limit can be set when PCRE2 +is built; if it is not, the default is set very large and is essentially +"unlimited".

A value for the heap limit may also be supplied by an item at the start of a @@ -1044,7 +1045,7 @@ The depth limit is not relevant, and is ignored, when matching is done using JIT compiled code. However, it is supported by pcre2_dfa_match(), which uses it to limit the depth of nested internal recursive function calls that implement atomic groups, lookaround assertions, and pattern recursions. This -limits, indirectly, the amount of system stack this is used. It was more useful +limits, indirectly, the amount of system stack that is used. It was more useful in versions before 10.32, when stack memory was used for local workspace vectors for recursive function calls. From version 10.32, only local variables are allocated on the stack and as each call uses only a few hundred bytes, even @@ -1060,11 +1061,11 @@ probably better to limit heap usage directly by calling pcre2_set_heap_limit().

-The default value for the depth limit can be set when PCRE2 is built; the -default default is the same value as the default for the match limit. If the -limit is exceeded, pcre2_match() or pcre2_dfa_match() returns -PCRE2_ERROR_DEPTHLIMIT. A value for the depth limit may also be supplied by an -item at the start of a pattern of the form +The default value for the depth limit can be set when PCRE2 is built; if it is +not, the default is set to the same value as the default for the match limit. +If the limit is exceeded, pcre2_match() or pcre2_dfa_match() +returns PCRE2_ERROR_DEPTHLIMIT. A value for the depth limit may also be +supplied by an item at the start of a pattern of the form

   (*LIMIT_DEPTH=ddd)
 
@@ -1120,7 +1121,7 @@ given with pcre2_set_depth_limit() above.
   PCRE2_CONFIG_HEAPLIMIT
 
-The output is a uint32_t integer that gives, in kilobytes, the default limit +The output is a uint32_t integer that gives, in kibibytes, the default limit for the amount of heap memory used by pcre2_match() or pcre2_dfa_match(). Further details are given with pcre2_set_heap_limit() above. @@ -1431,7 +1432,7 @@ If this bit is set, letters in the pattern match both upper and lower case letters in the subject. It is equivalent to Perl's /i option, and it can be changed within a pattern by a (?i) option setting. If PCRE2_UTF is set, Unicode properties are used for all characters with more than one other case, and for -all characters whose code points are greater than U+007f. For lower valued +all characters whose code points are greater than U+007F. For lower valued characters with only one other case, a lookup table is used for speed. When PCRE2_UTF is not set, a lookup table is used for all code points less than 256, and higher code points (available only in 16-bit or 32-bit mode) are treated as @@ -1551,7 +1552,7 @@ error.
   PCRE2_MATCH_UNSET_BACKREF
 
-If this option is set, a back reference to an unset subpattern group matches an +If this option is set, a backreference to an unset subpattern group matches an empty string (by default this causes the current matching alternative to fail). A pattern such as (\1)(a) succeeds when this option is set (assuming it can find an "a" in the subject), whereas it fails by default, for Perl @@ -1613,8 +1614,8 @@ If this option is set, it disables the use of numbered capturing parentheses in the pattern. Any opening parenthesis that is not followed by ? behaves as if it were followed by ?: but named parentheses can still be used for capturing (and they acquire numbers in the usual way). This is the same as Perl's /n option. -Note that, when this option is set, references to capturing groups (back -references or recursion/subroutine calls) may only refer to named groups, +Note that, when this option is set, references to capturing groups +(backreferences or recursion/subroutine calls) may only refer to named groups, though the reference can be by name or by number.
   PCRE2_NO_AUTO_POSSESS
@@ -1633,7 +1634,7 @@ If this option is set, it disables an optimization that is applied when .* is
 the first significant item in a top-level branch of a pattern, and all the
 other branches also start with .* or with \A or \G or ^. The optimization is
 automatically disabled for .* if it is inside an atomic group or a capturing
-group that is the subject of a back reference, or if the pattern contains
+group that is the subject of a backreference, or if the pattern contains
 (*PRUNE) or (*SKIP). When the optimization is not disabled, such a pattern is
 automatically anchored if PCRE2_DOTALL is set for all the .* items and
 PCRE2_MULTILINE is not set for any ^ items. Otherwise, the fact that any match
@@ -1999,7 +2000,7 @@ When .* is the first significant item, anchoring is possible only when all the
 following are true:
 
   .* is not in an atomic group
-  .* is not in a capturing group that is the subject of a back reference
+  .* is not in a capturing group that is the subject of a backreference
   PCRE2_DOTALL is in force for .*
   Neither (*PRUNE) nor (*SKIP) appears in the pattern
   PCRE2_NO_DOTSTAR_ANCHOR is not set
@@ -2009,20 +2010,20 @@ options returned for PCRE2_INFO_ALLOPTIONS.
 
   PCRE2_INFO_BACKREFMAX
 
-Return the number of the highest back reference in the pattern. The third +Return the number of the highest backreference in the pattern. The third argument should point to an uint32_t variable. Named subpatterns acquire -numbers as well as names, and these count towards the highest back reference. -Back references such as \4 or \g{12} match the captured characters of the +numbers as well as names, and these count towards the highest backreference. +Backreferences such as \4 or \g{12} match the captured characters of the given group, but in addition, the check that a capturing group is set in a -conditional subpattern such as (?(3)a|b) is also a back reference. Zero is -returned if there are no back references. +conditional subpattern such as (?(3)a|b) is also a backreference. Zero is +returned if there are no backreferences.
   PCRE2_INFO_BSR
 
-The output is a uint32_t whose value indicates what character sequences the \R -escape sequence matches. A value of PCRE2_BSR_UNICODE means that \R matches -any Unicode line ending sequence; a value of PCRE2_BSR_ANYCRLF means that \R -matches only CR, LF, or CRLF. +The output is a uint32_t integer whose value indicates what character sequences +the \R escape sequence matches. A value of PCRE2_BSR_UNICODE means that \R +matches any Unicode line ending sequence; a value of PCRE2_BSR_ANYCRLF means +that \R matches only CR, LF, or CRLF.
   PCRE2_INFO_CAPTURECOUNT
 
@@ -2034,10 +2035,10 @@ The third argument should point to an uint32_t variable.
If the pattern set a backtracking depth limit by including an item of the form (*LIMIT_DEPTH=nnnn) at the start, the value is returned. The third argument -should point to an unsigned 32-bit integer. If no such value has been set, the -call to pcre2_pattern_info() returns the error PCRE2_ERROR_UNSET. Note -that this limit will only be used during matching if it is less than the limit -set or defaulted by the caller of the match function. +should point to a uint32_t integer. If no such value has been set, the call to +pcre2_pattern_info() returns the error PCRE2_ERROR_UNSET. Note that this +limit will only be used during matching if it is less than the limit set or +defaulted by the caller of the match function.
   PCRE2_INFO_FIRSTBITMAP
 
@@ -2047,7 +2048,7 @@ values for the first code unit in any match. For example, a pattern that starts with [abc] results in a table with three bits set. When code unit values greater than 255 are supported, the flag bit for 255 means "any code unit of value 255 or above". If such a table was constructed, a pointer to it is -returned. Otherwise NULL is returned. The third argument should point to an +returned. Otherwise NULL is returned. The third argument should point to a const uint8_t * variable.
   PCRE2_INFO_FIRSTCODETYPE
@@ -2074,7 +2075,7 @@ and up to 0xffffffff when not using UTF-32 mode.
 
Return the size (in bytes) of the data frames that are used to remember backtracking positions when the pattern is processed by pcre2_match() -without the use of JIT. The third argument should point to an size_t +without the use of JIT. The third argument should point to a size_t variable. The frame size depends on the number of capturing parentheses in the pattern. Each additional capturing group adds two PCRE2_SIZE variables.
@@ -2094,10 +2095,10 @@ the equivalent hexadecimal or octal escape sequences.
 
If the pattern set a heap memory limit by including an item of the form (*LIMIT_HEAP=nnnn) at the start, the value is returned. The third argument -should point to an unsigned 32-bit integer. If no such value has been set, the -call to pcre2_pattern_info() returns the error PCRE2_ERROR_UNSET. Note -that this limit will only be used during matching if it is less than the limit -set or defaulted by the caller of the match function. +should point to a uint32_t integer. If no such value has been set, the call to +pcre2_pattern_info() returns the error PCRE2_ERROR_UNSET. Note that this +limit will only be used during matching if it is less than the limit set or +defaulted by the caller of the match function.
   PCRE2_INFO_JCHANGED
 
@@ -2141,15 +2142,15 @@ in such cases.
If the pattern set a match limit by including an item of the form (*LIMIT_MATCH=nnnn) at the start, the value is returned. The third argument -should point to an unsigned 32-bit integer. If no such value has been set, the -call to pcre2_pattern_info() returns the error PCRE2_ERROR_UNSET. Note -that this limit will only be used during matching if it is less than the limit -set or defaulted by the caller of the match function. +should point to a uint32_t integer. If no such value has been set, the call to +pcre2_pattern_info() returns the error PCRE2_ERROR_UNSET. Note that this +limit will only be used during matching if it is less than the limit set or +defaulted by the caller of the match function.
   PCRE2_INFO_MAXLOOKBEHIND
 
Return the number of characters (not code units) in the longest lookbehind -assertion in the pattern. The third argument should point to an unsigned 32-bit +assertion in the pattern. The third argument should point to a uint32_t integer. This information is useful when doing multi-segment matching using the partial matching facilities. Note that the simple assertions \b and \B require a one-character lookbehind. \A also registers a one-character @@ -2417,7 +2418,7 @@ zero, the search for a match starts at the beginning of the subject, and this is by far the most common case. In UTF-8 or UTF-16 mode, the starting offset must point to the start of a character, or to the end of the subject (in UTF-32 mode, one code unit equals one character, so all offsets are valid). Like the -pattern string, the subject may contain binary zeroes. +pattern string, the subject may contain binary zeros.

A non-zero starting offset is useful when searching for another match in the @@ -3559,12 +3560,12 @@ There are in addition the following errors that are specific to

This return is given if pcre2_dfa_match() encounters an item in the pattern that it does not support, for instance, the use of \C in a UTF mode or -a back reference. +a backreference.
   PCRE2_ERROR_DFA_UCOND
 
This return is given if pcre2_dfa_match() encounters a condition item -that uses a back reference for the condition, or a test for recursion in a +that uses a backreference for the condition, or a test for recursion in a specific group. These are not supported.
   PCRE2_ERROR_DFA_WSSIZE
diff --git a/doc/html/pcre2build.html b/doc/html/pcre2build.html
index c9d9324..3ce64f6 100644
--- a/doc/html/pcre2build.html
+++ b/doc/html/pcre2build.html
@@ -227,7 +227,7 @@ separator, U+2028), and PS (paragraph separator, U+2029). The final option is
 
   --enable-newline-is-nul
 
-which causes NUL (binary zero) is set as the default line-ending character. +which causes NUL (binary zero) to be set as the default line-ending character.

Whatever default line ending convention is selected when PCRE2 is built can be @@ -286,15 +286,15 @@ The pcre2_match() function starts out using a 20K vector on the system stack to record backtracking points. The more nested backtracking points there are (that is, the deeper the search tree), the more memory is needed. If the initial vector is not large enough, heap memory is used, up to a certain limit, -which is specified in kilobytes. The limit can be changed at run time, as -described in the +which is specified in kibibytes (units of 1024 bytes). The limit can be changed +at run time, as described in the pcre2api documentation. The default limit (in effect unlimited) is 20 million. You can change this by a setting such as

   --with-heap-limit=500
 
-which limits the amount of heap to 500 kilobytes. This limit applies only to +which limits the amount of heap to 500 KiB. This limit applies only to interpretive matching in pcre2_match() and pcre2_dfa_match(), which may also use the heap for internal workspace when processing complicated patterns. This limit does not apply when JIT (which has its own memory @@ -542,7 +542,7 @@ generated from the string. Setting --enable-fuzz-support also causes a binary called pcre2fuzzcheck to be created. This is normally run under valgrind or used when PCRE2 is compiled with address sanitizing enabled. It calls the fuzzing function and -outputs information about it is doing. The input strings are specified by +outputs information about what it is doing. The input strings are specified by arguments: if an argument starts with "=" the rest of it is a literal input string. Otherwise, it is assumed to be a file name, and the contents of the file are the test string. diff --git a/doc/html/pcre2callout.html b/doc/html/pcre2callout.html index 4ff1673..9b6ae6f 100644 --- a/doc/html/pcre2callout.html +++ b/doc/html/pcre2callout.html @@ -143,7 +143,7 @@ branch, automatic anchoring occurs if all branches are anchorable.

This optimization is disabled, however, if .* is in an atomic group or if there -is a back reference to the capturing group in which it appears. It is also +is a backreference to the capturing group in which it appears. It is also disabled if the pattern contains (*PRUNE) or (*SKIP). However, the presence of callouts does not affect it.

diff --git a/doc/html/pcre2compat.html b/doc/html/pcre2compat.html index e6d2e7e..f7c694c 100644 --- a/doc/html/pcre2compat.html +++ b/doc/html/pcre2compat.html @@ -31,7 +31,7 @@ page. 2. Like Perl, PCRE2 allows repeat quantifiers on parenthesized assertions, but they do not mean what you might think. For example, (?!a){3} does not assert that the next three characters are not "a". It just asserts that the next -character is not "a" three times (in principle: PCRE2 optimizes this to run the +character is not "a" three times (in principle; PCRE2 optimizes this to run the assertion just once). Perl allows some repeat quantifiers on other assertions, for example, \b* (but not \b{3}), but these do not seem to have any use.

@@ -77,8 +77,8 @@ The \Q...\E sequence is recognized both inside and outside character classes.

7. Fairly obviously, PCRE2 does not support the (?{code}) and (??{code}) -constructions. However, there is support PCRE2's "callout" feature, which -allows an external function to be called during pattern matching. See the +constructions. However, PCRE2 does have a "callout" feature, which allows an +external function to be called during pattern matching. See the pcre2callout documentation for details.

@@ -156,7 +156,7 @@ each alternative branch of a lookbehind assertion can match a different length of string. Perl requires them all to have the same length.

-(b) From PCRE2 10.23, back references to groups of fixed length are supported +(b) From PCRE2 10.23, backreferences to groups of fixed length are supported in lookbehinds, provided that there is no possibility of referencing a non-unique number or name. Perl does not support backreferences in lookbehinds.
diff --git a/doc/html/pcre2grep.html b/doc/html/pcre2grep.html index 1ef8f42..c1ac969 100644 --- a/doc/html/pcre2grep.html +++ b/doc/html/pcre2grep.html @@ -86,9 +86,10 @@ controlled by parameters that can be set by the --buffer-size and that is obtained at the start of processing. If an input file contains very long lines, a larger buffer may be needed; this is handled by automatically extending the buffer, up to the limit specified by --max-buffer-size. The -default values for these parameters are specified when pcre2grep is -built, with the default defaults being 20K and 1M respectively. An error occurs -if a line is too long and the buffer can no longer be expanded. +default values for these parameters can be set when pcre2grep is +built; if nothing is specified, the defaults are set to 20K and 1M +respectively. An error occurs if a line is too long and the buffer can no +longer be expanded.

The block of memory that is actually used is three times the "buffer size", to @@ -500,13 +501,13 @@ short form for this option. When this option is given, non-compressed input is read and processed line by line, and the output is flushed after each write. By default, input is read in large chunks, unless pcre2grep can determine that it is reading from a -terminal (which is currently possible only in Unix-like environments). Output -to terminal is normally automatically flushed by the operating system. This -option can be useful when the input or output is attached to a pipe and you do -not want pcre2grep to buffer up large amounts of data. However, its use -will affect performance, and the -M (multiline) option ceases to work. -When input is from a compressed .gz or .bz2 file, --line-buffered is -ignored. +terminal (which is currently possible only in Unix-like environments or +Windows). Output to terminal is normally automatically flushed by the operating +system. This option can be useful when the input or output is attached to a +pipe and you do not want pcre2grep to buffer up large amounts of data. +However, its use will affect performance, and the -M (multiline) option +ceases to work. When input is from a compressed .gz or .bz2 file, +--line-buffered is ignored.

--line-offsets @@ -541,11 +542,11 @@ counter that is incremented each time around its main processing loop. If the value set by --match-limit is reached, an error occurs.

-The --heap-limit option specifies, as a number of kilobytes, the amount -of heap memory that may be used for matching. Heap memory is needed only if -matching the pattern requires a significant number of nested backtracking -points to be remembered. This parameter can be set to zero to forbid the use of -heap memory altogether. +The --heap-limit option specifies, as a number of kibibytes (units of +1024 bytes), the amount of heap memory that may be used for matching. Heap +memory is needed only if matching the pattern requires a significant number of +nested backtracking points to be remembered. This parameter can be set to zero +to forbid the use of heap memory altogether.

The --depth-limit option limits the depth of nested backtracking points, @@ -556,9 +557,9 @@ limit acts varies from pattern to pattern. This limit is of use only if it is set smaller than --match-limit.

-There are no short forms for these options. The default settings are specified -when the PCRE2 library is compiled, with the default defaults being very large -and so effectively unlimited. +There are no short forms for these options. The default limits can be set +when the PCRE2 library is compiled; if they are not specified, the defaults +are very large and so effectively unlimited.

\fB--max-buffer-size=number diff --git a/doc/html/pcre2limits.html b/doc/html/pcre2limits.html index 640fe3d..c763ca0 100644 --- a/doc/html/pcre2limits.html +++ b/doc/html/pcre2limits.html @@ -54,9 +54,9 @@ There is no limit to the number of parenthesized subpatterns, but there can be no more than 65535 capturing subpatterns. There is, however, a limit to the depth of nesting of parenthesized subpatterns of all kinds. This is imposed in order to limit the amount of system stack used at compile time. The default -limit can be specified when PCRE2 is built; the default default is 250. An -application can change this limit by calling pcre2_set_parens_nest_limit() to -set the limit in a compile context. +limit can be specified when PCRE2 is built; if not, the default is set to 250. +An application can change this limit by calling pcre2_set_parens_nest_limit() +to set the limit in a compile context.

The maximum length of name for a named subpattern is 32 code units, and the diff --git a/doc/html/pcre2matching.html b/doc/html/pcre2matching.html index 859bbb3..602f3b2 100644 --- a/doc/html/pcre2matching.html +++ b/doc/html/pcre2matching.html @@ -85,7 +85,7 @@ ungreedy repetition quantifiers are specified in the pattern. Because it ends up with a single path through the tree, it is relatively straightforward for this algorithm to keep track of the substrings that are matched by portions of the pattern in parentheses. This provides support for -capturing parentheses and back references. +capturing parentheses and backreferences.


THE ALTERNATIVE MATCHING ALGORITHM

@@ -158,7 +158,7 @@ possibilities, and PCRE2's implementation of this algorithm does not attempt to do this. This means that no captured substrings are available.

-3. Because no substrings are captured, back references within the pattern are +3. Because no substrings are captured, backreferences within the pattern are not supported, and cause errors if encountered.

@@ -215,7 +215,7 @@ because it has to search for all possible matches, but is also because it is less susceptible to optimization.

-2. Capturing parentheses and back references are not supported. +2. Capturing parentheses and backreferences are not supported.

3. Although atomic groups are supported, their use does not provide the diff --git a/doc/html/pcre2pattern.html b/doc/html/pcre2pattern.html index 1131c2a..bd71551 100644 --- a/doc/html/pcre2pattern.html +++ b/doc/html/pcre2pattern.html @@ -31,7 +31,7 @@ please consult the man page, in case the conversion went wrong.

  • NAMED SUBPATTERNS
  • REPETITION
  • ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS -
  • BACK REFERENCES +
  • BACKREFERENCES
  • ASSERTIONS
  • CONDITIONAL SUBPATTERNS
  • COMMENTS @@ -196,7 +196,7 @@ be less than the value set (or defaulted) by the caller of pcre2_match() for it to have any effect. In other words, the pattern writer can lower the limits set by the programmer, but not raise them. If there is more than one setting of one of these limits, the lower value is used. The heap limit is -specified in kilobytes. +specified in kibibytes (units of 1024 bytes).

    Prior to release 10.30, LIMIT_DEPTH was called LIMIT_RECURSION. This name is @@ -342,7 +342,7 @@ In particular, if you want to match a backslash, you write \\.

    In a UTF mode, only ASCII numbers and letters have any special meaning after a -backslash. All other characters (in particular, those whose codepoints are +backslash. All other characters (in particular, those whose code points are greater than 127) are treated as literals.

    @@ -390,7 +390,7 @@ these escapes are as follows: \r carriage return (hex 0D) \t tab (hex 09) \0dd character with octal code 0dd - \ddd character with octal code ddd, or back reference + \ddd character with octal code ddd, or backreference \o{ddd..} character with octal code ddd.. \xhh character with hex code hh \x{hhh..} character with hex code hhh.. (default mode) @@ -438,13 +438,13 @@ follows is itself an octal digit. The escape \o must be followed by a sequence of octal digits, enclosed in braces. An error occurs if this is not the case. This escape is a recent addition to Perl; it provides way of specifying character code points as octal -numbers greater than 0777, and it also allows octal numbers and back references +numbers greater than 0777, and it also allows octal numbers and backreferences to be unambiguously specified.

    For greater clarity and unambiguity, it is best to avoid following \ by a digit greater than zero. Instead, use \o{} or \x{} to specify character -numbers, and \g{} to specify back references. The following paragraphs +numbers, and \g{} to specify backreferences. The following paragraphs describe the old, ambiguous syntax.

    @@ -455,7 +455,7 @@ and Perl has changed over time, causing PCRE2 also to change. Outside a character class, PCRE2 reads the digit and any following digits as a decimal number. If the number is less than 10, begins with the digit 8 or 9, or if there are at least that many previous capturing left parentheses in the -expression, the entire sequence is taken as a back reference. A +expression, the entire sequence is taken as a backreference. A description of how this works is given later, following the discussion of @@ -470,13 +470,13 @@ for themselves. For example, outside a character class:

       \040   is another way of writing an ASCII space
       \40    is the same, provided there are fewer than 40 previous capturing subpatterns
    -  \7     is always a back reference
    -  \11    might be a back reference, or another way of writing a tab
    +  \7     is always a backreference
    +  \11    might be a backreference, or another way of writing a tab
       \011   is always a tab
       \0113  is a tab followed by the character "3"
    -  \113   might be a back reference, otherwise the character with octal code 113
    -  \377   might be a back reference, otherwise the value 255 (decimal)
    -  \81    is always a back reference .sp
    +  \113   might be a backreference, otherwise the character with octal code 113
    +  \377   might be a backreference, otherwise the value 255 (decimal)
    +  \81    is always a backreference .sp
     
    Note that octal values of 100 or greater that are specified using this syntax must not be introduced by a leading zero, because no more than three octal @@ -512,10 +512,10 @@ limited to certain values, as follows: 8-bit non-UTF mode no greater than 0xff 16-bit non-UTF mode no greater than 0xffff 32-bit non-UTF mode no greater than 0xffffffff - All UTF modes no greater than 0x10ffff and a valid codepoint + All UTF modes no greater than 0x10ffff and a valid code point
  • -Invalid Unicode codepoints are all those in the range 0xd800 to 0xdfff (the -so-called "surrogate" codepoints). The check for these can be disabled by the +Invalid Unicode code points are all those in the range 0xd800 to 0xdfff (the +so-called "surrogate" code points). The check for these can be disabled by the caller of pcre2_compile() by setting the option PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES.

    @@ -544,12 +544,12 @@ is set, \U matches a "U" character, and \u can be used to define a character by code point, as described above.


    -Absolute and relative back references +Absolute and relative backreferences

    The sequence \g followed by a signed or unsigned number, optionally enclosed -in braces, is an absolute or relative back reference. A named back reference -can be coded as \g{name}. Back references are discussed +in braces, is an absolute or relative backreference. A named backreference +can be coded as \g{name}. backreferences are discussed later, following the discussion of parenthesized subpatterns. @@ -563,7 +563,7 @@ a number enclosed either in angle brackets or single quotes, is an alternative syntax for referencing a subpattern as a "subroutine". Details are discussed later. Note that \g{...} (Perl syntax) and \g<...> (Oniguruma syntax) are not -synonymous. The former is a back reference; the latter is a +synonymous. The former is a backreference; the latter is a subroutine call.

    @@ -694,7 +694,7 @@ line, U+0085). Because this is an atomic group, the two-character sequence is treated as a single unit that cannot be split.

    -In other modes, two additional characters whose codepoints are greater than 255 +In other modes, two additional characters whose code points are greater than 255 are added: LS (line separator, U+2028) and PS (paragraph separator, U+2029). Unicode support is not needed for these characters to be recognized.

    @@ -729,8 +729,8 @@ Unicode character properties When PCRE2 is built with Unicode support (the default), three additional escape sequences that match characters with specific properties are available. In 8-bit non-UTF-8 mode, these sequences are of course limited to testing -characters whose codepoints are less than 256, but they do work in this mode. -In 32-bit non-UTF mode, codepoints greater than 0x10ffff (the Unicode limit) +characters whose code points are less than 256, but they do work in this mode. +In 32-bit non-UTF mode, code points greater than 0x10ffff (the Unicode limit) may be encountered. These are all treated as being in the Common script and with an unassigned type. The extra escape sequences are:
    @@ -1037,7 +1037,7 @@ joiner" characters. Characters with the "mark" property always have the
     modifier). Extending characters are allowed before the modifier.
     

    -7. Do not break within emoji zwj sequences (zero-width jointer followed by +7. Do not break within emoji zwj sequences (zero-width joiner followed by "glue after ZWJ" or "base glue after ZWJ").

    @@ -1731,7 +1731,7 @@ numbers underneath show in which buffer the captured content will be stored. / ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x # 1 2 2 3 2 3 4

    -A back reference to a numbered subpattern uses the most recent value that is +A backreference to a numbered subpattern uses the most recent value that is set for that number by any subpattern. The following pattern matches "abcabc" or "defdef":
    @@ -1771,7 +1771,7 @@ have different names, but PCRE2 does not.
     In PCRE2, a subpattern can be named in one of three ways: (?<name>...) or
     (?'name'...) as in Perl, or (?P<name>...) as in Python. References to capturing
     parentheses from other parts of the pattern, such as
    -back references,
    +backreferences,
     recursion,
     and
     conditions,
    @@ -1811,7 +1811,7 @@ for the first (and in this example, the only) subpattern of that name that
     matched. This saves searching to find which numbered subpattern it was.
     

    -If you make a back reference to a non-unique named subpattern from elsewhere in +If you make a backreference to a non-unique named subpattern from elsewhere in the pattern, the subpatterns to which the name refers are checked in the order in which they appear in the overall pattern. The first one that is set is used for the reference. For example, this pattern matches both "foofoo" and @@ -1859,7 +1859,7 @@ items: the \R escape sequence an escape such as \d or \pL that matches a single character a character class - a back reference + a backreference a parenthesized subpattern (including most assertions) a subroutine call to a subpattern (recursive or otherwise)

    @@ -1980,7 +1980,7 @@ alternatively, using ^ to indicate anchoring explicitly.

    However, there are some cases where the optimization cannot be used. When .* -is inside capturing parentheses that are the subject of a back reference +is inside capturing parentheses that are the subject of a backreference elsewhere in the pattern, a match at the start may fail where a later one succeeds. Consider, for example:

    @@ -2121,30 +2121,30 @@ an atomic group, like this:
     
    sequences of non-digits cannot be broken, and failure happens quickly.

    -
    BACK REFERENCES
    +
    BACKREFERENCES

    Outside a character class, a backslash followed by a digit greater than 0 (and -possibly further digits) is a back reference to a capturing subpattern earlier +possibly further digits) is a backreference to a capturing subpattern earlier (that is, to its left) in the pattern, provided there have been that many previous capturing left parentheses.

    However, if the decimal number following the backslash is less than 8, it is -always taken as a back reference, and causes an error only if there are not +always taken as a backreference, and causes an error only if there are not that many capturing left parentheses in the entire pattern. In other words, the parentheses that are referenced need not be to the left of the reference for -numbers less than 8. A "forward back reference" of this type can make sense +numbers less than 8. A "forward backreference" of this type can make sense when a repetition is involved and the subpattern to the right has participated in an earlier iteration.

    -It is not possible to have a numerical "forward back reference" to a subpattern +It is not possible to have a numerical "forward backreference" to a subpattern whose number is 8 or more using this syntax because a sequence such as \50 is interpreted as a character defined in octal. See the subsection entitled "Non-printing characters" above for further details of the handling of digits following a backslash. There is -no such problem when named parentheses are used. A back reference to any +no such problem when named parentheses are used. A backreference to any subpattern is possible using named parentheses (see below).

    @@ -2175,7 +2175,7 @@ of forward reference can be useful it patterns that repeat. Perl does not support the use of + in this way.

    -A back reference matches whatever actually matched the capturing subpattern in +A backreference matches whatever actually matched the capturing subpattern in the current subject string, rather than anything matching the subpattern itself (see "Subpatterns as subroutines" @@ -2185,7 +2185,7 @@ below for a way of doing that). So the pattern matches "sense and sensibility" and "response and responsibility", but not "sense and responsibility". If caseful matching is in force at the time of the -back reference, the case of letters is relevant. For example, +backreference, the case of letters is relevant. For example,

       ((?i)rah)\s+\1
     
    @@ -2193,10 +2193,10 @@ matches "rah rah" and "RAH RAH", but not "RAH rah", even though the original capturing subpattern is matched caselessly.

    -There are several different ways of writing back references to named +There are several different ways of writing backreferences to named subpatterns. The .NET syntax \k{name} and the Perl syntax \k<name> or \k'name' are supported, as is the Python syntax (?P=name). Perl 5.10's unified -back reference syntax, in which \g can be used for both numeric and named +backreference syntax, in which \g can be used for both numeric and named references, is also supported. We could rewrite the above example in any of the following ways:

    @@ -2209,30 +2209,30 @@ A subpattern that is referenced by name may appear in the pattern before or
     after the reference.
     

    -There may be more than one back reference to the same subpattern. If a -subpattern has not actually been used in a particular match, any back -references to it always fail by default. For example, the pattern +There may be more than one backreference to the same subpattern. If a +subpattern has not actually been used in a particular match, any backreferences +to it always fail by default. For example, the pattern

       (a|(bc))\2
     
    always fails if it starts to match "a" rather than "bc". However, if the -PCRE2_MATCH_UNSET_BACKREF option is set at compile time, a back reference to an +PCRE2_MATCH_UNSET_BACKREF option is set at compile time, a backreference to an unset value matches an empty string.

    Because there may be many capturing parentheses in a pattern, all digits -following a backslash are taken as part of a potential back reference number. +following a backslash are taken as part of a potential backreference number. If the pattern continues with a digit character, some delimiter must be used to -terminate the back reference. If the PCRE2_EXTENDED option is set, this can be +terminate the backreference. If the PCRE2_EXTENDED option is set, this can be white space. Otherwise, the \g{ syntax or an empty comment (see "Comments" below) can be used.


    -Recursive back references +Recursive backreferences

    -A back reference that occurs inside the parentheses to which it refers fails +A backreference that occurs inside the parentheses to which it refers fails when the subpattern is first used, so, for example, (a\1) never matches. However, such references can be useful inside repeated subpatterns. For example, the pattern @@ -2240,14 +2240,14 @@ example, the pattern (a|b\1)+

    matches any number of "a"s and also "aba", "ababbaa" etc. At each iteration of -the subpattern, the back reference matches the character string corresponding +the subpattern, the backreference matches the character string corresponding to the previous iteration. In order for this to work, the pattern must be such -that the first iteration does not need to match the back reference. This can be +that the first iteration does not need to match the backreference. This can be done using alternation, as in the example above, or by a quantifier with a minimum of zero.

    -Back references of this type cause the group that they reference to be treated +backreferences of this type cause the group that they reference to be treated as an atomic group. Once the whole group has been matched, a subsequent matching failure cannot @@ -2397,10 +2397,10 @@ that is, a "subroutine" call into a group that is already active, is not supported.

    -Perl does not support back references in lookbehinds. PCRE2 does support them, +Perl does not support backreferences in lookbehinds. PCRE2 does support them, but only if certain conditions are met. The PCRE2_MATCH_UNSET_BACKREF option must not be set, there must be no use of (?| in the pattern (it creates -duplicate subpattern numbers), and if the back reference is by name, the name +duplicate subpattern numbers), and if the backreference is by name, the name must be unique. Of course, the referenced subpattern must itself be of fixed length. The following pattern matches words containing at least two characters that begin and end with the same character: @@ -2882,7 +2882,7 @@ in PCRE2 these values can be referenced. Consider this pattern: ^(.)(\1|a(?2)) This pattern matches "bab". The first capturing parentheses match "b", then in -the second group, when the back reference \1 fails to match "b", the second +the second group, when the backreference \1 fails to match "b", the second alternative matches "a" and then recurses. In the recursion, \1 does now match "b" and so the whole match succeeds. This match used to fail in Perl, but in later versions (I tried 5.024) it now works. @@ -2943,7 +2943,7 @@ plus or a minus sign it is taken as a relative reference. For example: (abc)(?i:\g<-1>) Note that \g{...} (Perl syntax) and \g<...> (Oniguruma syntax) are not -synonymous. The former is a back reference; the latter is a subroutine call. +synonymous. The former is a backreference; the latter is a subroutine call.


    CALLOUTS

    diff --git a/doc/html/pcre2posix.html b/doc/html/pcre2posix.html index 8a4431c..1da2460 100644 --- a/doc/html/pcre2posix.html +++ b/doc/html/pcre2posix.html @@ -132,14 +132,14 @@ When a pattern that is compiled with this flag is passed to regexec() for matching, the nmatch and pmatch arguments are ignored, and no captured strings are returned. Versions of the PCRE library prior to 10.22 used to set the PCRE2_NO_AUTO_CAPTURE compile option, but this no longer happens -because it disables the use of back references. +because it disables the use of backreferences.

       REG_PEND
     
    If this option is set, the reg_endp field in the preg structure (which has the type const char *) must be set to point to the character beyond the end of the pattern before calling regcomp(). The pattern itself may -now contain binary zeroes, which are treated as data characters. Without +now contain binary zeros, which are treated as data characters. Without REG_PEND, a binary zero terminates the pattern and the re_endp field is ignored. This is a GNU extension to the POSIX standard and should be used with caution in software intended to be portable to other systems. @@ -248,10 +248,10 @@ function.
       REG_STARTEND
     
    -When this option is set, the subject string is starts at string + +When this option is set, the subject string starts at string + pmatch[0].rm_so and ends at string + pmatch[0].rm_eo, which should point to the first character beyond the string. There may be binary -zeroes within the subject string, and indeed, using REG_STARTEND is the only +zeros within the subject string, and indeed, using REG_STARTEND is the only way to pass a subject string that contains a binary zero.

    diff --git a/doc/html/pcre2syntax.html b/doc/html/pcre2syntax.html index 9098f47..409bf7c 100644 --- a/doc/html/pcre2syntax.html +++ b/doc/html/pcre2syntax.html @@ -442,7 +442,7 @@ of the newline or \R options with similar syntax. More than one of them may appear. For the first three, d is a decimal number.

       (*LIMIT_DEPTH=d) set the backtracking limit to d
    -  (*LIMIT_HEAP=d)  set the heap size limit to d kilobytes
    +  (*LIMIT_HEAP=d)  set the heap size limit to d * 1024 bytes
       (*LIMIT_MATCH=d) set the match limit to d
       (*NOTEMPTY)      set PCRE2_NOTEMPTY when matching
       (*NOTEMPTY_ATSTART) set PCRE2_NOTEMPTY_ATSTART when matching
    diff --git a/doc/html/pcre2test.html b/doc/html/pcre2test.html
    index d6e5345..33a07ea 100644
    --- a/doc/html/pcre2test.html
    +++ b/doc/html/pcre2test.html
    @@ -129,7 +129,7 @@ to occur).
     UTF-8 (in its original definition) is not capable of encoding values greater
     than 0x7fffffff, but such values can be handled by the 32-bit library. When
     testing this library in non-UTF mode with utf8_input set, if any
    -character is preceded by the byte 0xff (which is an illegal byte in UTF-8)
    +character is preceded by the byte 0xff (which is an invalid byte in UTF-8)
     0x80000000 is added to the character's value. This is the only way of passing
     such code points in a pattern string. For subject strings, using an escape
     sequence is preferable.
    @@ -264,7 +264,7 @@ Do not output the version number of pcre2test at the start of execution.
     

    -S size On Unix-like systems, set the size of the run-time stack to size -megabytes. +mebibytes (units of 1024*1024 bytes).

    -subject modifier-list @@ -679,8 +679,8 @@ Newline and \R handling

    The bsr modifier specifies what \R in a pattern should match. If it is set to "anycrlf", \R matches CR, LF, or CRLF only. If it is set to "unicode", -\R matches any Unicode newline sequence. The default is specified when PCRE2 -is built, with the default default being Unicode. +\R matches any Unicode newline sequence. The default can be specified when +PCRE2 is built; if it is not, the default is set to Unicode.

    The newline modifier specifies which characters are to be interpreted as @@ -1418,11 +1418,11 @@ Setting the JIT stack size

    The jitstack modifier provides a way of setting the maximum stack size that is used by the just-in-time optimization code. It is ignored if JIT -optimization is not being used. The value is a number of kilobytes. Setting -zero reverts to the default of 32K. Providing a stack that is larger than the -default is necessary only for very complicated patterns. If jitstack is -set non-zero on a subject line it overrides any value that was set on the -pattern. +optimization is not being used. The value is a number of kibibytes (units of +1024 bytes). Setting zero reverts to the default of 32KiB. Providing a stack +that is larger than the default is necessary only for very complicated +patterns. If jitstack is set non-zero on a subject line it overrides any +value that was set on the pattern.


    Setting heap, match, and depth limits @@ -1468,10 +1468,10 @@ and non-recursive, to the internal matching function, thus controlling the overall amount of computing resource that is used.

    -For both kinds of matching, the heap_limit number (which is in kilobytes) -limits the amount of heap memory used for matching. A value of zero disables -the use of any heap memory; many simple pattern matches can be done without -using the heap, so this is not an unreasonable setting. +For both kinds of matching, the heap_limit number, which is in kibibytes +(units of 1024 bytes), limits the amount of heap memory used for matching. A +value of zero disables the use of any heap memory; many simple pattern matches +can be done without using the heap, so zero is not an unreasonable setting.


    Showing MARK names diff --git a/doc/html/pcre2unicode.html b/doc/html/pcre2unicode.html index 448a221..78750d1 100644 --- a/doc/html/pcre2unicode.html +++ b/doc/html/pcre2unicode.html @@ -53,7 +53,7 @@ compatibility with Perl 5.6. PCRE2 does not support this. WIDE CHARACTERS AND UTF MODES

    -Codepoints less than 256 can be specified in patterns by either braced or +Code points less than 256 can be specified in patterns by either braced or unbraced hexadecimal escape sequences (for example, \x{b3} or \xb3). Larger values have to use braced sequences. Unbraced octal code points up to \777 are also recognized; larger ones can be coded using \o{...}. @@ -116,7 +116,7 @@ CASE-EQUIVALENCE IN UTF MODES Case-insensitive matching in a UTF mode makes use of Unicode properties except for characters whose code points are less than 128 and that have at most two case-equivalent values. For these, a direct table lookup is used for speed. A -few Unicode characters such as Greek sigma have more than two codepoints that +few Unicode characters such as Greek sigma have more than two code points that are case-equivalent, and these are treated as such.


    diff --git a/doc/pcre2.txt b/doc/pcre2.txt index 9c70f06..51a1a52 100644 --- a/doc/pcre2.txt +++ b/doc/pcre2.txt @@ -619,32 +619,33 @@ NEWLINES Each of the first three conventions is used by at least one operating system as its standard newline sequence. When PCRE2 is built, a default - can be specified. The default default is LF, which is the Unix stan- - dard. However, the newline convention can be changed by an application - when calling pcre2_compile(), or it can be specified by special text at - the start of the pattern itself; this overrides any other settings. See - the pcre2pattern page for details of the special character sequences. + can be specified. If it is not, the default is set to LF, which is the + Unix standard. However, the newline convention can be changed by an + application when calling pcre2_compile(), or it can be specified by + special text at the start of the pattern itself; this overrides any + other settings. See the pcre2pattern page for details of the special + character sequences. - In the PCRE2 documentation the word "newline" is used to mean "the + In the PCRE2 documentation the word "newline" is used to mean "the character or pair of characters that indicate a line break". The choice - of newline convention affects the handling of the dot, circumflex, and + of newline convention affects the handling of the dot, circumflex, and dollar metacharacters, the handling of #-comments in /x mode, and, when - CRLF is a recognized line ending sequence, the match position advance- + CRLF is a recognized line ending sequence, the match position advance- ment for a non-anchored pattern. There is more detail about this in the section on pcre2_match() options below. - The choice of newline convention does not affect the interpretation of + The choice of newline convention does not affect the interpretation of the \n or \r escape sequences, nor does it affect what \R matches; this has its own separate convention. MULTITHREADING - In a multithreaded application it is important to keep thread-specific - data separate from data that can be shared between threads. The PCRE2 - library code itself is thread-safe: it contains no static or global - variables. The API is designed to be fairly simple for non-threaded - applications while at the same time ensuring that multithreaded appli- + In a multithreaded application it is important to keep thread-specific + data separate from data that can be shared between threads. The PCRE2 + library code itself is thread-safe: it contains no static or global + variables. The API is designed to be fairly simple for non-threaded + applications while at the same time ensuring that multithreaded appli- cations can use it. There are several different blocks of data that are used to pass infor- @@ -652,19 +653,19 @@ MULTITHREADING The compiled pattern - A pointer to the compiled form of a pattern is returned to the user + A pointer to the compiled form of a pattern is returned to the user when pcre2_compile() is successful. The data in the compiled pattern is - fixed, and does not change when the pattern is matched. Therefore, it - is thread-safe, that is, the same compiled pattern can be used by more + fixed, and does not change when the pattern is matched. Therefore, it + is thread-safe, that is, the same compiled pattern can be used by more than one thread simultaneously. For example, an application can compile all its patterns at the start, before forking off multiple threads that - use them. However, if the just-in-time (JIT) optimization feature is - being used, it needs separate memory stack areas for each thread. See + use them. However, if the just-in-time (JIT) optimization feature is + being used, it needs separate memory stack areas for each thread. See the pcre2jit documentation for more details. - In a more complicated situation, where patterns are compiled only when - they are first needed, but are still shared between threads, pointers - to compiled patterns must be protected from simultaneous writing by + In a more complicated situation, where patterns are compiled only when + they are first needed, but are still shared between threads, pointers + to compiled patterns must be protected from simultaneous writing by multiple threads, at least until a pattern has been compiled. The logic can be something like this: @@ -677,72 +678,72 @@ MULTITHREADING Release the lock Use pointer in pcre2_match() - Of course, testing for compilation errors should also be included in + Of course, testing for compilation errors should also be included in the code. If JIT is being used, but the JIT compilation is not being done immedi- - ately, (perhaps waiting to see if the pattern is used often enough) + ately, (perhaps waiting to see if the pattern is used often enough) similar logic is required. JIT compilation updates a pointer within the - compiled code block, so a thread must gain unique write access to the - pointer before calling pcre2_jit_compile(). Alternatively, + compiled code block, so a thread must gain unique write access to the + pointer before calling pcre2_jit_compile(). Alternatively, pcre2_code_copy() or pcre2_code_copy_with_tables() can be used to - obtain a private copy of the compiled code before calling the JIT com- + obtain a private copy of the compiled code before calling the JIT com- piler. Context blocks - The next main section below introduces the idea of "contexts" in which + The next main section below introduces the idea of "contexts" in which PCRE2 functions are called. A context is nothing more than a collection of parameters that control the way PCRE2 operates. Grouping a number of parameters together in a context is a convenient way of passing them to - a PCRE2 function without using lots of arguments. The parameters that - are stored in contexts are in some sense "advanced features" of the + a PCRE2 function without using lots of arguments. The parameters that + are stored in contexts are in some sense "advanced features" of the API. Many straightforward applications will not need to use contexts. In a multithreaded application, if the parameters in a context are val- - ues that are never changed, the same context can be used by all the + ues that are never changed, the same context can be used by all the threads. However, if any thread needs to change any value in a context, it must make its own thread-specific copy. Match blocks - The matching functions need a block of memory for storing the results + The matching functions need a block of memory for storing the results of a match. This includes details of what was matched, as well as addi- - tional information such as the name of a (*MARK) setting. Each thread + tional information such as the name of a (*MARK) setting. Each thread must provide its own copy of this memory. PCRE2 CONTEXTS - Some PCRE2 functions have a lot of parameters, many of which are used - only by specialist applications, for example, those that use custom - memory management or non-standard character tables. To keep function - argument lists at a reasonable size, and at the same time to keep the - API extensible, "uncommon" parameters are passed to certain functions - in a context instead of directly. A context is just a block of memory - that holds the parameter values. Applications that do not need to - adjust any of the context parameters can pass NULL when a context + Some PCRE2 functions have a lot of parameters, many of which are used + only by specialist applications, for example, those that use custom + memory management or non-standard character tables. To keep function + argument lists at a reasonable size, and at the same time to keep the + API extensible, "uncommon" parameters are passed to certain functions + in a context instead of directly. A context is just a block of memory + that holds the parameter values. Applications that do not need to + adjust any of the context parameters can pass NULL when a context pointer is required. - There are three different types of context: a general context that is - relevant for several PCRE2 operations, a compile-time context, and a + There are three different types of context: a general context that is + relevant for several PCRE2 operations, a compile-time context, and a match-time context. The general context - At present, this context just contains pointers to (and data for) - external memory management functions that are called from several + At present, this context just contains pointers to (and data for) + external memory management functions that are called from several places in the PCRE2 library. The context is named `general' rather than - specifically `memory' because in future other fields may be added. If - you do not want to supply your own custom memory management functions, - you do not need to bother with a general context. A general context is + specifically `memory' because in future other fields may be added. If + you do not want to supply your own custom memory management functions, + you do not need to bother with a general context. A general context is created by: pcre2_general_context *pcre2_general_context_create( void *(*private_malloc)(PCRE2_SIZE, void *), void (*private_free)(void *, void *), void *memory_data); - The two function pointers specify custom memory management functions, + The two function pointers specify custom memory management functions, whose prototypes are: void *private_malloc(PCRE2_SIZE, void *); @@ -750,16 +751,16 @@ PCRE2 CONTEXTS Whenever code in PCRE2 calls these functions, the final argument is the value of memory_data. Either of the first two arguments of the creation - function may be NULL, in which case the system memory management func- - tions malloc() and free() are used. (This is not currently useful, as - there are no other fields in a general context, but in future there - might be.) The private_malloc() function is used (if supplied) to - obtain memory for storing the context, and all three values are saved + function may be NULL, in which case the system memory management func- + tions malloc() and free() are used. (This is not currently useful, as + there are no other fields in a general context, but in future there + might be.) The private_malloc() function is used (if supplied) to + obtain memory for storing the context, and all three values are saved as part of the context. - Whenever PCRE2 creates a data block of any kind, the block contains a - pointer to the free() function that matches the malloc() function that - was used. When the time comes to free the block, this function is + Whenever PCRE2 creates a data block of any kind, the block contains a + pointer to the free() function that matches the malloc() function that + was used. When the time comes to free the block, this function is called. A general context can be copied by calling: @@ -774,8 +775,8 @@ PCRE2 CONTEXTS The compile context - A compile context is required if you want to provide an external func- - tion for stack checking during compilation or to change the default + A compile context is required if you want to provide an external func- + tion for stack checking during compilation or to change the default values of any of the following compile-time parameters: What \R matches (Unicode newlines or CR, LF, CRLF only) @@ -785,11 +786,11 @@ PCRE2 CONTEXTS The maximum length of the pattern string The extra options bits (none set by default) - A compile context is also required if you are using custom memory man- - agement. If none of these apply, just pass NULL as the context argu- + A compile context is also required if you are using custom memory man- + agement. If none of these apply, just pass NULL as the context argu- ment of pcre2_compile(). - A compile context is created, copied, and freed by the following func- + A compile context is created, copied, and freed by the following func- tions: pcre2_compile_context *pcre2_compile_context_create( @@ -800,91 +801,91 @@ PCRE2 CONTEXTS void pcre2_compile_context_free(pcre2_compile_context *ccontext); - A compile context is created with default values for its parameters. + A compile context is created with default values for its parameters. These can be changed by calling the following functions, which return 0 on success, or PCRE2_ERROR_BADDATA if invalid data is detected. int pcre2_set_bsr(pcre2_compile_context *ccontext, uint32_t value); - The value must be PCRE2_BSR_ANYCRLF, to specify that \R matches only - CR, LF, or CRLF, or PCRE2_BSR_UNICODE, to specify that \R matches any + The value must be PCRE2_BSR_ANYCRLF, to specify that \R matches only + CR, LF, or CRLF, or PCRE2_BSR_UNICODE, to specify that \R matches any Unicode line ending sequence. The value is used by the JIT compiler and - by the two interpreted matching functions, pcre2_match() and + by the two interpreted matching functions, pcre2_match() and pcre2_dfa_match(). int pcre2_set_character_tables(pcre2_compile_context *ccontext, const unsigned char *tables); - The value must be the result of a call to pcre2_maketables(), whose + The value must be the result of a call to pcre2_maketables(), whose only argument is a general context. This function builds a set of char- acter tables in the current locale. int pcre2_set_compile_extra_options(pcre2_compile_context *ccontext, uint32_t extra_options); - As PCRE2 has developed, almost all the 32 option bits that are avail- - able in the options argument of pcre2_compile() have been used up. To - avoid running out, the compile context contains a set of extra option - bits which are used for some newer, assumed rarer, options. This func- - tion sets those bits. It always sets all the bits (either on or off). - It does not modify any existing setting. The available options are + As PCRE2 has developed, almost all the 32 option bits that are avail- + able in the options argument of pcre2_compile() have been used up. To + avoid running out, the compile context contains a set of extra option + bits which are used for some newer, assumed rarer, options. This func- + tion sets those bits. It always sets all the bits (either on or off). + It does not modify any existing setting. The available options are defined in the section entitled "Extra compile options" below. int pcre2_set_max_pattern_length(pcre2_compile_context *ccontext, PCRE2_SIZE value); - This sets a maximum length, in code units, for any pattern string that - is compiled with this context. If the pattern is longer, an error is - generated. This facility is provided so that applications that accept + This sets a maximum length, in code units, for any pattern string that + is compiled with this context. If the pattern is longer, an error is + generated. This facility is provided so that applications that accept patterns from external sources can limit their size. The default is the - largest number that a PCRE2_SIZE variable can hold, which is effec- + largest number that a PCRE2_SIZE variable can hold, which is effec- tively unlimited. int pcre2_set_newline(pcre2_compile_context *ccontext, uint32_t value); This specifies which characters or character sequences are to be recog- - nized as newlines. The value must be one of PCRE2_NEWLINE_CR (carriage + nized as newlines. The value must be one of PCRE2_NEWLINE_CR (carriage return only), PCRE2_NEWLINE_LF (linefeed only), PCRE2_NEWLINE_CRLF (the - two-character sequence CR followed by LF), PCRE2_NEWLINE_ANYCRLF (any - of the above), PCRE2_NEWLINE_ANY (any Unicode newline sequence), or + two-character sequence CR followed by LF), PCRE2_NEWLINE_ANYCRLF (any + of the above), PCRE2_NEWLINE_ANY (any Unicode newline sequence), or PCRE2_NEWLINE_NUL (the NUL character, that is a binary zero). A pattern can override the value set in the compile context by starting with a sequence such as (*CRLF). See the pcre2pattern page for details. - When a pattern is compiled with the PCRE2_EXTENDED or + When a pattern is compiled with the PCRE2_EXTENDED or PCRE2_EXTENDED_MORE option, the newline convention affects the recogni- - tion of white space and the end of internal comments starting with #. - The value is saved with the compiled pattern for subsequent use by the - JIT compiler and by the two interpreted matching functions, + tion of white space and the end of internal comments starting with #. + The value is saved with the compiled pattern for subsequent use by the + JIT compiler and by the two interpreted matching functions, pcre2_match() and pcre2_dfa_match(). int pcre2_set_parens_nest_limit(pcre2_compile_context *ccontext, uint32_t value); This parameter ajusts the limit, set when PCRE2 is built (default 250), - on the depth of parenthesis nesting in a pattern. This limit stops - rogue patterns using up too much system stack when being compiled. The + on the depth of parenthesis nesting in a pattern. This limit stops + rogue patterns using up too much system stack when being compiled. The limit applies to parentheses of all kinds, not just capturing parenthe- ses. int pcre2_set_compile_recursion_guard(pcre2_compile_context *ccontext, int (*guard_function)(uint32_t, void *), void *user_data); - There is at least one application that runs PCRE2 in threads with very - limited system stack, where running out of stack is to be avoided at - all costs. The parenthesis limit above cannot take account of how much - stack is actually available during compilation. For a finer control, - you can supply a function that is called whenever pcre2_compile() - starts to compile a parenthesized part of a pattern. This function can - check the actual stack size (or anything else that it wants to, of + There is at least one application that runs PCRE2 in threads with very + limited system stack, where running out of stack is to be avoided at + all costs. The parenthesis limit above cannot take account of how much + stack is actually available during compilation. For a finer control, + you can supply a function that is called whenever pcre2_compile() + starts to compile a parenthesized part of a pattern. This function can + check the actual stack size (or anything else that it wants to, of course). - The first argument to the callout function gives the current depth of - nesting, and the second is user data that is set up by the last argu- - ment of pcre2_set_compile_recursion_guard(). The callout function + The first argument to the callout function gives the current depth of + nesting, and the second is user data that is set up by the last argu- + ment of pcre2_set_compile_recursion_guard(). The callout function should return zero if all is well, or non-zero to force an error. The match context @@ -898,10 +899,10 @@ PCRE2 CONTEXTS Change the backtracking depth limit Set custom memory management specifically for the match - If none of these apply, just pass NULL as the context argument of + If none of these apply, just pass NULL as the context argument of pcre2_match(), pcre2_dfa_match(), or pcre2_jit_match(). - A match context is created, copied, and freed by the following func- + A match context is created, copied, and freed by the following func- tions: pcre2_match_context *pcre2_match_context_create( @@ -912,7 +913,7 @@ PCRE2 CONTEXTS void pcre2_match_context_free(pcre2_match_context *mcontext); - A match context is created with default values for its parameters. + A match context is created with default values for its parameters. These can be changed by calling the following functions, which return 0 on success, or PCRE2_ERROR_BADDATA if invalid data is detected. @@ -927,29 +928,29 @@ PCRE2 CONTEXTS int pcre2_set_offset_limit(pcre2_match_context *mcontext, PCRE2_SIZE value); - The offset_limit parameter limits how far an unanchored search can - advance in the subject string. The default value is PCRE2_UNSET. The - pcre2_match() and pcre2_dfa_match() functions return - PCRE2_ERROR_NOMATCH if a match with a starting point before or at the - given offset is not found. The pcre2_substitute() function makes no + The offset_limit parameter limits how far an unanchored search can + advance in the subject string. The default value is PCRE2_UNSET. The + pcre2_match() and pcre2_dfa_match() functions return + PCRE2_ERROR_NOMATCH if a match with a starting point before or at the + given offset is not found. The pcre2_substitute() function makes no more substitutions. - For example, if the pattern /abc/ is matched against "123abc" with an - offset limit less than 3, the result is PCRE2_ERROR_NO_MATCH. A match - can never be found if the startoffset argument of pcre2_match(), - pcre2_dfa_match(), or pcre2_substitute() is greater than the offset + For example, if the pattern /abc/ is matched against "123abc" with an + offset limit less than 3, the result is PCRE2_ERROR_NO_MATCH. A match + can never be found if the startoffset argument of pcre2_match(), + pcre2_dfa_match(), or pcre2_substitute() is greater than the offset limit set in the match context. - When using this facility, you must set the PCRE2_USE_OFFSET_LIMIT + When using this facility, you must set the PCRE2_USE_OFFSET_LIMIT option when calling pcre2_compile() so that when JIT is in use, differ- - ent code can be compiled. If a match is started with a non-default - match limit when PCRE2_USE_OFFSET_LIMIT is not set, an error is gener- + ent code can be compiled. If a match is started with a non-default + match limit when PCRE2_USE_OFFSET_LIMIT is not set, an error is gener- ated. - The offset limit facility can be used to track progress when searching - large subject strings or to limit the extent of global substitutions. - See also the PCRE2_FIRSTLINE option, which requires a match to start - before or at the first newline that follows the start of matching in + The offset limit facility can be used to track progress when searching + large subject strings or to limit the extent of global substitutions. + See also the PCRE2_FIRSTLINE option, which requires a match to start + before or at the first newline that follows the start of matching in the subject. If this is set with an offset limit, a match must occur in the first line and also within the offset limit. In other words, which- ever limit comes first is used. @@ -957,111 +958,112 @@ PCRE2 CONTEXTS int pcre2_set_heap_limit(pcre2_match_context *mcontext, uint32_t value); - The heap_limit parameter specifies, in units of kilobytes, the maximum - amount of heap memory that pcre2_match() may use to hold backtracking - information when running an interpretive match. This limit also applies - to pcre2_dfa_match(), which may use the heap when processing patterns - with a lot of nested pattern recursion or lookarounds or atomic groups. - This limit does not apply to matching with the JIT optimization, which - has its own memory control arrangements (see the pcre2jit documentation - for more details). If the limit is reached, the negative error code - PCRE2_ERROR_HEAPLIMIT is returned. The default limit is set when PCRE2 - is built; the default default is very large and is essentially "unlim- - ited". + The heap_limit parameter specifies, in units of kibibytes (1024 bytes), + the maximum amount of heap memory that pcre2_match() may use to hold + backtracking information when running an interpretive match. This limit + also applies to pcre2_dfa_match(), which may use the heap when process- + ing patterns with a lot of nested pattern recursion or lookarounds or + atomic groups. This limit does not apply to matching with the JIT opti- + mization, which has its own memory control arrangements (see the + pcre2jit documentation for more details). If the limit is reached, the + negative error code PCRE2_ERROR_HEAPLIMIT is returned. The default + limit can be set when PCRE2 is built; if it is not, the default is set + very large and is essentially "unlimited". A value for the heap limit may also be supplied by an item at the start of a pattern of the form (*LIMIT_HEAP=ddd) - where ddd is a decimal number. However, such a setting is ignored - unless ddd is less than the limit set by the caller of pcre2_match() + where ddd is a decimal number. However, such a setting is ignored + unless ddd is less than the limit set by the caller of pcre2_match() or, if no such limit is set, less than the default. - The pcre2_match() function starts out using a 20K vector on the system - stack for recording backtracking points. The more nested backtracking + The pcre2_match() function starts out using a 20K vector on the system + stack for recording backtracking points. The more nested backtracking points there are (that is, the deeper the search tree), the more memory - is needed. Heap memory is used only if the initial vector is too + is needed. Heap memory is used only if the initial vector is too small. If the heap limit is set to a value less than 21 (in particular, - zero) no heap memory will be used. In this case, only patterns that do + zero) no heap memory will be used. In this case, only patterns that do not have a lot of nested backtracking can be successfully processed. - Similarly, for pcre2_dfa_match(), a vector on the system stack is used - when processing pattern recursions, lookarounds, or atomic groups, and - only if this is not big enough is heap memory used. In this case, too, + Similarly, for pcre2_dfa_match(), a vector on the system stack is used + when processing pattern recursions, lookarounds, or atomic groups, and + only if this is not big enough is heap memory used. In this case, too, setting a value of zero disables the use of the heap. int pcre2_set_match_limit(pcre2_match_context *mcontext, uint32_t value); - The match_limit parameter provides a means of preventing PCRE2 from + The match_limit parameter provides a means of preventing PCRE2 from using up too many computing resources when processing patterns that are not going to match, but which have a very large number of possibilities - in their search trees. The classic example is a pattern that uses + in their search trees. The classic example is a pattern that uses nested unlimited repeats. - There is an internal counter in pcre2_match() that is incremented each - time round its main matching loop. If this value reaches the match + There is an internal counter in pcre2_match() that is incremented each + time round its main matching loop. If this value reaches the match limit, pcre2_match() returns the negative value PCRE2_ERROR_MATCHLIMIT. - This has the effect of limiting the amount of backtracking that can + This has the effect of limiting the amount of backtracking that can take place. For patterns that are not anchored, the count restarts from - zero for each position in the subject string. This limit also applies + zero for each position in the subject string. This limit also applies to pcre2_dfa_match(), though the counting is done in a different way. - When pcre2_match() is called with a pattern that was successfully pro- + When pcre2_match() is called with a pattern that was successfully pro- cessed by pcre2_jit_compile(), the way in which matching is executed is - entirely different. However, there is still the possibility of runaway - matching that goes on for a very long time, and so the match_limit - value is also used in this case (but in a different way) to limit how + entirely different. However, there is still the possibility of runaway + matching that goes on for a very long time, and so the match_limit + value is also used in this case (but in a different way) to limit how long the matching can continue. - The default value for the limit can be set when PCRE2 is built; the - default default is 10 million, which handles all but the most extreme - cases. A value for the match limit may also be supplied by an item at + The default value for the limit can be set when PCRE2 is built; the + default default is 10 million, which handles all but the most extreme + cases. A value for the match limit may also be supplied by an item at the start of a pattern of the form (*LIMIT_MATCH=ddd) - where ddd is a decimal number. However, such a setting is ignored + where ddd is a decimal number. However, such a setting is ignored unless ddd is less than the limit set by the caller of pcre2_match() or pcre2_dfa_match() or, if no such limit is set, less than the default. int pcre2_set_depth_limit(pcre2_match_context *mcontext, uint32_t value); - This parameter limits the depth of nested backtracking in - pcre2_match(). Each time a nested backtracking point is passed, a new + This parameter limits the depth of nested backtracking in + pcre2_match(). Each time a nested backtracking point is passed, a new memory "frame" is used to remember the state of matching at that point. - Thus, this parameter indirectly limits the amount of memory that is - used in a match. However, because the size of each memory "frame" + Thus, this parameter indirectly limits the amount of memory that is + used in a match. However, because the size of each memory "frame" depends on the number of capturing parentheses, the actual memory limit - varies from pattern to pattern. This limit was more useful in versions + varies from pattern to pattern. This limit was more useful in versions before 10.30, where function recursion was used for backtracking. - The depth limit is not relevant, and is ignored, when matching is done + The depth limit is not relevant, and is ignored, when matching is done using JIT compiled code. However, it is supported by pcre2_dfa_match(), - which uses it to limit the depth of nested internal recursive function - calls that implement atomic groups, lookaround assertions, and pattern - recursions. This limits, indirectly, the amount of system stack this is - used. It was more useful in versions before 10.32, when stack memory + which uses it to limit the depth of nested internal recursive function + calls that implement atomic groups, lookaround assertions, and pattern + recursions. This limits, indirectly, the amount of system stack that is + used. It was more useful in versions before 10.32, when stack memory was used for local workspace vectors for recursive function calls. From - version 10.32, only local variables are allocated on the stack and as + version 10.32, only local variables are allocated on the stack and as each call uses only a few hundred bytes, even a small stack can support quite a lot of recursion. - If the depth of internal recursive function calls is great enough, - local workspace vectors are allocated on the heap from version 10.32 - onwards, so the depth limit also indirectly limits the amount of heap + If the depth of internal recursive function calls is great enough, + local workspace vectors are allocated on the heap from version 10.32 + onwards, so the depth limit also indirectly limits the amount of heap memory that is used. A recursive pattern such as /(.(?2))((?1)|)/, when - matched to a very long string using pcre2_dfa_match(), can use a great - deal of memory. However, it is probably better to limit heap usage + matched to a very long string using pcre2_dfa_match(), can use a great + deal of memory. However, it is probably better to limit heap usage directly by calling pcre2_set_heap_limit(). - The default value for the depth limit can be set when PCRE2 is built; - the default default is the same value as the default for the match - limit. If the limit is exceeded, pcre2_match() or pcre2_dfa_match() - returns PCRE2_ERROR_DEPTHLIMIT. A value for the depth limit may also be - supplied by an item at the start of a pattern of the form + The default value for the depth limit can be set when PCRE2 is built; + if it is not, the default is set to the same value as the default for + the match limit. If the limit is exceeded, pcre2_match() or + pcre2_dfa_match() returns PCRE2_ERROR_DEPTHLIMIT. A value for the depth + limit may also be supplied by an item at the start of a pattern of the + form (*LIMIT_DEPTH=ddd) @@ -1117,7 +1119,7 @@ CHECKING BUILD-TIME OPTIONS PCRE2_CONFIG_HEAPLIMIT - The output is a uint32_t integer that gives, in kilobytes, the default + The output is a uint32_t integer that gives, in kibibytes, the default limit for the amount of heap memory used by pcre2_match() or pcre2_dfa_match(). Further details are given with pcre2_set_heap_limit() above. @@ -1413,7 +1415,7 @@ COMPILING A PATTERN it can be changed within a pattern by a (?i) option setting. If PCRE2_UTF is set, Unicode properties are used for all characters with more than one other case, and for all characters whose code points are - greater than U+007f. For lower valued characters with only one other + greater than U+007F. For lower valued characters with only one other case, a lookup table is used for speed. When PCRE2_UTF is not set, a lookup table is used for all code points less than 256, and higher code points (available only in 16-bit or 32-bit mode) are treated as not @@ -1533,7 +1535,7 @@ COMPILING A PATTERN PCRE2_MATCH_UNSET_BACKREF - If this option is set, a back reference to an unset subpattern group + If this option is set, a backreference to an unset subpattern group matches an empty string (by default this causes the current matching alternative to fail). A pattern such as (\1)(a) succeeds when this option is set (assuming it can find an "a" in the subject), whereas it @@ -1599,7 +1601,7 @@ COMPILING A PATTERN ? behaves as if it were followed by ?: but named parentheses can still be used for capturing (and they acquire numbers in the usual way). This is the same as Perl's /n option. Note that, when this option is set, - references to capturing groups (back references or recursion/subroutine + references to capturing groups (backreferences or recursion/subroutine calls) may only refer to named groups, though the reference can be by name or by number. @@ -1619,7 +1621,7 @@ COMPILING A PATTERN .* is the first significant item in a top-level branch of a pattern, and all the other branches also start with .* or with \A or \G or ^. The optimization is automatically disabled for .* if it is inside an - atomic group or a capturing group that is the subject of a back refer- + atomic group or a capturing group that is the subject of a backrefer- ence, or if the pattern contains (*PRUNE) or (*SKIP). When the opti- mization is not disabled, such a pattern is automatically anchored if PCRE2_DOTALL is set for all the .* items and PCRE2_MULTILINE is not set @@ -1970,7 +1972,7 @@ INFORMATION ABOUT A COMPILED PATTERN .* is not in an atomic group .* is not in a capturing group that is the subject - of a back reference + of a backreference PCRE2_DOTALL is in force for .* Neither (*PRUNE) nor (*SKIP) appears in the pattern PCRE2_NO_DOTSTAR_ANCHOR is not set @@ -1980,101 +1982,99 @@ INFORMATION ABOUT A COMPILED PATTERN PCRE2_INFO_BACKREFMAX - Return the number of the highest back reference in the pattern. The + Return the number of the highest backreference in the pattern. The third argument should point to an uint32_t variable. Named subpatterns acquire numbers as well as names, and these count towards the highest - back reference. Back references such as \4 or \g{12} match the cap- - tured characters of the given group, but in addition, the check that a - capturing group is set in a conditional subpattern such as (?(3)a|b) is - also a back reference. Zero is returned if there are no back refer- - ences. + backreference. Backreferences such as \4 or \g{12} match the captured + characters of the given group, but in addition, the check that a cap- + turing group is set in a conditional subpattern such as (?(3)a|b) is + also a backreference. Zero is returned if there are no backreferences. PCRE2_INFO_BSR - The output is a uint32_t whose value indicates what character sequences - the \R escape sequence matches. A value of PCRE2_BSR_UNICODE means that - \R matches any Unicode line ending sequence; a value of PCRE2_BSR_ANY- - CRLF means that \R matches only CR, LF, or CRLF. + The output is a uint32_t integer whose value indicates what character + sequences the \R escape sequence matches. A value of PCRE2_BSR_UNICODE + means that \R matches any Unicode line ending sequence; a value of + PCRE2_BSR_ANYCRLF means that \R matches only CR, LF, or CRLF. PCRE2_INFO_CAPTURECOUNT - Return the highest capturing subpattern number in the pattern. In pat- + Return the highest capturing subpattern number in the pattern. In pat- terns where (?| is not used, this is also the total number of capturing subpatterns. The third argument should point to an uint32_t variable. PCRE2_INFO_DEPTHLIMIT - If the pattern set a backtracking depth limit by including an item of - the form (*LIMIT_DEPTH=nnnn) at the start, the value is returned. The - third argument should point to an unsigned 32-bit integer. If no such - value has been set, the call to pcre2_pattern_info() returns the error + If the pattern set a backtracking depth limit by including an item of + the form (*LIMIT_DEPTH=nnnn) at the start, the value is returned. The + third argument should point to a uint32_t integer. If no such value has + been set, the call to pcre2_pattern_info() returns the error PCRE2_ERROR_UNSET. Note that this limit will only be used during match- - ing if it is less than the limit set or defaulted by the caller of the + ing if it is less than the limit set or defaulted by the caller of the match function. PCRE2_INFO_FIRSTBITMAP - In the absence of a single first code unit for a non-anchored pattern, - pcre2_compile() may construct a 256-bit table that defines a fixed set - of values for the first code unit in any match. For example, a pattern - that starts with [abc] results in a table with three bits set. When - code unit values greater than 255 are supported, the flag bit for 255 - means "any code unit of value 255 or above". If such a table was con- - structed, a pointer to it is returned. Otherwise NULL is returned. The - third argument should point to an const uint8_t * variable. + In the absence of a single first code unit for a non-anchored pattern, + pcre2_compile() may construct a 256-bit table that defines a fixed set + of values for the first code unit in any match. For example, a pattern + that starts with [abc] results in a table with three bits set. When + code unit values greater than 255 are supported, the flag bit for 255 + means "any code unit of value 255 or above". If such a table was con- + structed, a pointer to it is returned. Otherwise NULL is returned. The + third argument should point to a const uint8_t * variable. PCRE2_INFO_FIRSTCODETYPE Return information about the first code unit of any matched string, for - a non-anchored pattern. The third argument should point to an uint32_t - variable. If there is a fixed first value, for example, the letter "c" - from a pattern such as (cat|cow|coyote), 1 is returned, and the value - can be retrieved using PCRE2_INFO_FIRSTCODEUNIT. If there is no fixed - first value, but it is known that a match can occur only at the start - of the subject or following a newline in the subject, 2 is returned. + a non-anchored pattern. The third argument should point to an uint32_t + variable. If there is a fixed first value, for example, the letter "c" + from a pattern such as (cat|cow|coyote), 1 is returned, and the value + can be retrieved using PCRE2_INFO_FIRSTCODEUNIT. If there is no fixed + first value, but it is known that a match can occur only at the start + of the subject or following a newline in the subject, 2 is returned. Otherwise, and for anchored patterns, 0 is returned. PCRE2_INFO_FIRSTCODEUNIT - Return the value of the first code unit of any matched string for a - pattern where PCRE2_INFO_FIRSTCODETYPE returns 1; otherwise return 0. - The third argument should point to an uint32_t variable. In the 8-bit - library, the value is always less than 256. In the 16-bit library the - value can be up to 0xffff. In the 32-bit library in UTF-32 mode the + Return the value of the first code unit of any matched string for a + pattern where PCRE2_INFO_FIRSTCODETYPE returns 1; otherwise return 0. + The third argument should point to an uint32_t variable. In the 8-bit + library, the value is always less than 256. In the 16-bit library the + value can be up to 0xffff. In the 32-bit library in UTF-32 mode the value can be up to 0x10ffff, and up to 0xffffffff when not using UTF-32 mode. PCRE2_INFO_FRAMESIZE Return the size (in bytes) of the data frames that are used to remember - backtracking positions when the pattern is processed by pcre2_match() - without the use of JIT. The third argument should point to an size_t + backtracking positions when the pattern is processed by pcre2_match() + without the use of JIT. The third argument should point to a size_t variable. The frame size depends on the number of capturing parentheses - in the pattern. Each additional capturing group adds two PCRE2_SIZE + in the pattern. Each additional capturing group adds two PCRE2_SIZE variables. PCRE2_INFO_HASBACKSLASHC - Return 1 if the pattern contains any instances of \C, otherwise 0. The + Return 1 if the pattern contains any instances of \C, otherwise 0. The third argument should point to an uint32_t variable. PCRE2_INFO_HASCRORLF - Return 1 if the pattern contains any explicit matches for CR or LF + Return 1 if the pattern contains any explicit matches for CR or LF characters, otherwise 0. The third argument should point to an uint32_t - variable. An explicit match is either a literal CR or LF character, or - \r or \n or one of the equivalent hexadecimal or octal escape + variable. An explicit match is either a literal CR or LF character, or + \r or \n or one of the equivalent hexadecimal or octal escape sequences. PCRE2_INFO_HEAPLIMIT If the pattern set a heap memory limit by including an item of the form (*LIMIT_HEAP=nnnn) at the start, the value is returned. The third argu- - ment should point to an unsigned 32-bit integer. If no such value has - been set, the call to pcre2_pattern_info() returns the error - PCRE2_ERROR_UNSET. Note that this limit will only be used during match- - ing if it is less than the limit set or defaulted by the caller of the - match function. + ment should point to a uint32_t integer. If no such value has been set, + the call to pcre2_pattern_info() returns the error PCRE2_ERROR_UNSET. + Note that this limit will only be used during matching if it is less + than the limit set or defaulted by the caller of the match function. PCRE2_INFO_JCHANGED @@ -2120,8 +2120,8 @@ INFORMATION ABOUT A COMPILED PATTERN If the pattern set a match limit by including an item of the form (*LIMIT_MATCH=nnnn) at the start, the value is returned. The third - argument should point to an unsigned 32-bit integer. If no such value - has been set, the call to pcre2_pattern_info() returns the error + argument should point to a uint32_t integer. If no such value has been + set, the call to pcre2_pattern_info() returns the error PCRE2_ERROR_UNSET. Note that this limit will only be used during match- ing if it is less than the limit set or defaulted by the caller of the match function. @@ -2129,15 +2129,15 @@ INFORMATION ABOUT A COMPILED PATTERN PCRE2_INFO_MAXLOOKBEHIND Return the number of characters (not code units) in the longest lookbe- - hind assertion in the pattern. The third argument should point to an - unsigned 32-bit integer. This information is useful when doing multi- - segment matching using the partial matching facilities. Note that the - simple assertions \b and \B require a one-character lookbehind. \A also - registers a one-character lookbehind, though it does not actually - inspect the previous character. This is to ensure that at least one - character from the old segment is retained when a new segment is pro- - cessed. Otherwise, if there are no lookbehinds in the pattern, \A might - match incorrectly at the start of a second or subsequent segment. + hind assertion in the pattern. The third argument should point to a + uint32_t integer. This information is useful when doing multi-segment + matching using the partial matching facilities. Note that the simple + assertions \b and \B require a one-character lookbehind. \A also regis- + ters a one-character lookbehind, though it does not actually inspect + the previous character. This is to ensure that at least one character + from the old segment is retained when a new segment is processed. Oth- + erwise, if there are no lookbehinds in the pattern, \A might match + incorrectly at the start of a second or subsequent segment. PCRE2_INFO_MINLENGTH @@ -2378,7 +2378,7 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION set must point to the start of a character, or to the end of the sub- ject (in UTF-32 mode, one code unit equals one character, so all off- sets are valid). Like the pattern string, the subject may contain - binary zeroes. + binary zeros. A non-zero starting offset is useful when searching for another match in the same subject by calling pcre2_match() again after a previous @@ -3440,13 +3440,13 @@ MATCHING A PATTERN: THE ALTERNATIVE FUNCTION This return is given if pcre2_dfa_match() encounters an item in the pattern that it does not support, for instance, the use of \C in a UTF - mode or a back reference. + mode or a backreference. PCRE2_ERROR_DFA_UCOND This return is given if pcre2_dfa_match() encounters a condition item - that uses a back reference for the condition, or a test for recursion - in a specific group. These are not supported. + that uses a backreference for the condition, or a test for recursion in + a specific group. These are not supported. PCRE2_ERROR_DFA_WSSIZE @@ -3683,8 +3683,8 @@ NEWLINE RECOGNITION --enable-newline-is-nul - which causes NUL (binary zero) is set as the default line-ending char- - acter. + which causes NUL (binary zero) to be set as the default line-ending + character. Whatever default line ending convention is selected when PCRE2 is built can be overridden by applications that use the library. At build time @@ -3745,18 +3745,18 @@ LIMITING PCRE2 RESOURCE USAGE stack to record backtracking points. The more nested backtracking points there are (that is, the deeper the search tree), the more memory is needed. If the initial vector is not large enough, heap memory is - used, up to a certain limit, which is specified in kilobytes. The limit - can be changed at run time, as described in the pcre2api documentation. - The default limit (in effect unlimited) is 20 million. You can change - this by a setting such as + used, up to a certain limit, which is specified in kibibytes (units of + 1024 bytes). The limit can be changed at run time, as described in the + pcre2api documentation. The default limit (in effect unlimited) is 20 + million. You can change this by a setting such as --with-heap-limit=500 - which limits the amount of heap to 500 kilobytes. This limit applies - only to interpretive matching in pcre2_match() and pcre2_dfa_match(), - which may also use the heap for internal workspace when processing com- - plicated patterns. This limit does not apply when JIT (which has its - own memory arrangements) is used. + which limits the amount of heap to 500 KiB. This limit applies only to + interpretive matching in pcre2_match() and pcre2_dfa_match(), which may + also use the heap for internal workspace when processing complicated + patterns. This limit does not apply when JIT (which has its own memory + arrangements) is used. You can also explicitly limit the depth of nested backtracking in the pcre2_match() interpreter. This limit defaults to the value that is set @@ -4005,10 +4005,10 @@ SUPPORT FOR FUZZERS Setting --enable-fuzz-support also causes a binary called pcre2fuz- zcheck to be created. This is normally run under valgrind or used when PCRE2 is compiled with address sanitizing enabled. It calls the fuzzing - function and outputs information about it is doing. The input strings - are specified by arguments: if an argument starts with "=" the rest of - it is a literal input string. Otherwise, it is assumed to be a file - name, and the contents of the file are the test string. + function and outputs information about what it is doing. The input + strings are specified by arguments: if an argument starts with "=" the + rest of it is a literal input string. Otherwise, it is assumed to be a + file name, and the contents of the file are the test string. OBSOLETE OPTION @@ -4167,9 +4167,9 @@ MISSING CALLOUTS all branches are anchorable. This optimization is disabled, however, if .* is in an atomic group or - if there is a back reference to the capturing group in which it - appears. It is also disabled if the pattern contains (*PRUNE) or - (*SKIP). However, the presence of callouts does not affect it. + if there is a backreference to the capturing group in which it appears. + It is also disabled if the pattern contains (*PRUNE) or (*SKIP). How- + ever, the presence of callouts does not affect it. For example, if the pattern .*\d is compiled with PCRE2_AUTO_CALLOUT and applied to the string "aa", the pcre2test output is: @@ -4489,7 +4489,7 @@ DIFFERENCES BETWEEN PCRE2 AND PERL 2. Like Perl, PCRE2 allows repeat quantifiers on parenthesized asser- tions, but they do not mean what you might think. For example, (?!a){3} does not assert that the next three characters are not "a". It just - asserts that the next character is not "a" three times (in principle: + asserts that the next character is not "a" three times (in principle; PCRE2 optimizes this to run the assertion just once). Perl allows some repeat quantifiers on other assertions, for example, \b* (but not \b{3}), but these do not seem to have any use. @@ -4534,9 +4534,9 @@ DIFFERENCES BETWEEN PCRE2 AND PERL classes. 7. Fairly obviously, PCRE2 does not support the (?{code}) and - (??{code}) constructions. However, there is support PCRE2's "callout" - feature, which allows an external function to be called during pattern - matching. See the pcre2callout documentation for details. + (??{code}) constructions. However, PCRE2 does have a "callout" feature, + which allows an external function to be called during pattern matching. + See the pcre2callout documentation for details. 8. Subroutine calls (whether recursive or not) were treated as atomic groups up to PCRE2 release 10.23, but from release 10.30 this changed, @@ -4604,9 +4604,9 @@ DIFFERENCES BETWEEN PCRE2 AND PERL different length of string. Perl requires them all to have the same length. - (b) From PCRE2 10.23, back references to groups of fixed length are - supported in lookbehinds, provided that there is no possibility of ref- - erencing a non-unique number or name. Perl does not support backrefer- + (b) From PCRE2 10.23, backreferences to groups of fixed length are sup- + ported in lookbehinds, provided that there is no possibility of refer- + encing a non-unique number or name. Perl does not support backrefer- ences in lookbehinds. (c) If PCRE2_DOLLAR_ENDONLY is set and PCRE2_MULTILINE is not set, the @@ -5103,9 +5103,9 @@ SIZE AND OTHER LIMITATIONS limit to the depth of nesting of parenthesized subpatterns of all kinds. This is imposed in order to limit the amount of system stack used at compile time. The default limit can be specified when PCRE2 is - built; the default default is 250. An application can change this limit - by calling pcre2_set_parens_nest_limit() to set the limit in a compile - context. + built; if not, the default is set to 250. An application can change + this limit by calling pcre2_set_parens_nest_limit() to set the limit in + a compile context. The maximum length of name for a named subpattern is 32 code units, and the maximum number of named subpatterns is 10000. @@ -5204,7 +5204,7 @@ THE STANDARD MATCHING ALGORITHM Because it ends up with a single path through the tree, it is rela- tively straightforward for this algorithm to keep track of the sub- strings that are matched by portions of the pattern in parentheses. - This provides support for capturing parentheses and back references. + This provides support for capturing parentheses and backreferences. THE ALTERNATIVE MATCHING ALGORITHM @@ -5277,7 +5277,7 @@ THE ALTERNATIVE MATCHING ALGORITHM algorithm does not attempt to do this. This means that no captured sub- strings are available. - 3. Because no substrings are captured, back references within the pat- + 3. Because no substrings are captured, backreferences within the pat- tern are not supported, and cause errors if encountered. 4. For the same reason, conditional expressions that use a backrefer- @@ -5331,7 +5331,7 @@ DISADVANTAGES OF THE ALTERNATIVE ALGORITHM partly because it has to search for all possible matches, but is also because it is less susceptible to optimization. - 2. Capturing parentheses and back references are not supported. + 2. Capturing parentheses and backreferences are not supported. 3. Although atomic groups are supported, their use does not provide the performance advantage that it does for the standard algorithm. @@ -5929,30 +5929,31 @@ SPECIAL START-OF-PATTERN ITEMS pcre2_match() for it to have any effect. In other words, the pattern writer can lower the limits set by the programmer, but not raise them. If there is more than one setting of one of these limits, the lower - value is used. The heap limit is specified in kilobytes. + value is used. The heap limit is specified in kibibytes (units of 1024 + bytes). - Prior to release 10.30, LIMIT_DEPTH was called LIMIT_RECURSION. This + Prior to release 10.30, LIMIT_DEPTH was called LIMIT_RECURSION. This name is still recognized for backwards compatibility. The heap limit applies only when the pcre2_match() or pcre2_dfa_match() interpreters are used for matching. It does not apply to JIT. The match - limit is used (but in a different way) when JIT is being used, or when + limit is used (but in a different way) when JIT is being used, or when pcre2_dfa_match() is called, to limit computing resource usage by those - matching functions. The depth limit is ignored by JIT but is relevant - for DFA matching, which uses function recursion for recursions within - the pattern and for lookaround assertions and atomic groups. In this + matching functions. The depth limit is ignored by JIT but is relevant + for DFA matching, which uses function recursion for recursions within + the pattern and for lookaround assertions and atomic groups. In this case, the depth limit controls the depth of such recursion. Newline conventions - PCRE2 supports six different conventions for indicating line breaks in - strings: a single CR (carriage return) character, a single LF (line- + PCRE2 supports six different conventions for indicating line breaks in + strings: a single CR (carriage return) character, a single LF (line- feed) character, the two-character sequence CRLF, any of the three pre- - ceding, any Unicode newline sequence, or the NUL character (binary - zero). The pcre2api page has further discussion about newlines, and + ceding, any Unicode newline sequence, or the NUL character (binary + zero). The pcre2api page has further discussion about newlines, and shows how to set the newline convention when calling pcre2_compile(). - It is also possible to specify a newline convention by starting a pat- + It is also possible to specify a newline convention by starting a pat- tern string with one of the following sequences: (*CR) carriage return @@ -5963,7 +5964,7 @@ SPECIAL START-OF-PATTERN ITEMS (*NUL) the NUL character (binary zero) These override the default and the options given to the compiling func- - tion. For example, on a Unix system where LF is the default newline + tion. For example, on a Unix system where LF is the default newline sequence, the pattern (*CR)a.b @@ -5972,38 +5973,38 @@ SPECIAL START-OF-PATTERN ITEMS no longer a newline. If more than one of these settings is present, the last one is used. - The newline convention affects where the circumflex and dollar asser- + The newline convention affects where the circumflex and dollar asser- tions are true. It also affects the interpretation of the dot metachar- - acter when PCRE2_DOTALL is not set, and the behaviour of \N. However, - it does not affect what the \R escape sequence matches. By default, - this is any Unicode newline sequence, for Perl compatibility. However, - this can be changed; see the next section and the description of \R in - the section entitled "Newline sequences" below. A change of \R setting + acter when PCRE2_DOTALL is not set, and the behaviour of \N. However, + it does not affect what the \R escape sequence matches. By default, + this is any Unicode newline sequence, for Perl compatibility. However, + this can be changed; see the next section and the description of \R in + the section entitled "Newline sequences" below. A change of \R setting can be combined with a change of newline convention. Specifying what \R matches It is possible to restrict \R to match only CR, LF, or CRLF (instead of - the complete set of Unicode line endings) by setting the option - PCRE2_BSR_ANYCRLF at compile time. This effect can also be achieved by - starting a pattern with (*BSR_ANYCRLF). For completeness, (*BSR_UNI- + the complete set of Unicode line endings) by setting the option + PCRE2_BSR_ANYCRLF at compile time. This effect can also be achieved by + starting a pattern with (*BSR_ANYCRLF). For completeness, (*BSR_UNI- CODE) is also recognized, corresponding to PCRE2_BSR_UNICODE. EBCDIC CHARACTER CODES - PCRE2 can be compiled to run in an environment that uses EBCDIC as its - character code instead of ASCII or Unicode (typically a mainframe sys- - tem). In the sections below, character code values are ASCII or Uni- + PCRE2 can be compiled to run in an environment that uses EBCDIC as its + character code instead of ASCII or Unicode (typically a mainframe sys- + tem). In the sections below, character code values are ASCII or Uni- code; in an EBCDIC environment these characters may have different code values, and there are no code points greater than 255. CHARACTERS AND METACHARACTERS - A regular expression is a pattern that is matched against a subject - string from left to right. Most characters stand for themselves in a - pattern, and match the corresponding characters in the subject. As a + A regular expression is a pattern that is matched against a subject + string from left to right. Most characters stand for themselves in a + pattern, and match the corresponding characters in the subject. As a trivial example, the pattern The quick brown fox @@ -6012,14 +6013,14 @@ CHARACTERS AND METACHARACTERS caseless matching is specified (the PCRE2_CASELESS option), letters are matched independently of case. - The power of regular expressions comes from the ability to include - alternatives and repetitions in the pattern. These are encoded in the + The power of regular expressions comes from the ability to include + alternatives and repetitions in the pattern. These are encoded in the pattern by the use of metacharacters, which do not stand for themselves but instead are interpreted in some special way. - There are two different sets of metacharacters: those that are recog- - nized anywhere in the pattern except within square brackets, and those - that are recognized within square brackets. Outside square brackets, + There are two different sets of metacharacters: those that are recog- + nized anywhere in the pattern except within square brackets, and those + that are recognized within square brackets. Outside square brackets, the metacharacters are as follows: \ general escape character with several uses @@ -6038,7 +6039,7 @@ CHARACTERS AND METACHARACTERS also "possessive quantifier" { start min/max quantifier - Part of a pattern that is in square brackets is called a "character + Part of a pattern that is in square brackets is called a "character class". In a character class the only metacharacters are: \ general escape character @@ -6055,30 +6056,30 @@ BACKSLASH The backslash character has several uses. Firstly, if it is followed by a character that is not a number or a letter, it takes away any special - meaning that character may have. This use of backslash as an escape + meaning that character may have. This use of backslash as an escape character applies both inside and outside character classes. - For example, if you want to match a * character, you must write \* in - the pattern. This escaping action applies whether or not the following - character would otherwise be interpreted as a metacharacter, so it is - always safe to precede a non-alphanumeric with backslash to specify + For example, if you want to match a * character, you must write \* in + the pattern. This escaping action applies whether or not the following + character would otherwise be interpreted as a metacharacter, so it is + always safe to precede a non-alphanumeric with backslash to specify that it stands for itself. In particular, if you want to match a back- slash, you write \\. - In a UTF mode, only ASCII numbers and letters have any special meaning - after a backslash. All other characters (in particular, those whose - codepoints are greater than 127) are treated as literals. + In a UTF mode, only ASCII numbers and letters have any special meaning + after a backslash. All other characters (in particular, those whose + code points are greater than 127) are treated as literals. - If a pattern is compiled with the PCRE2_EXTENDED option, most white - space in the pattern (other than in a character class), and characters - between a # outside a character class and the next newline, inclusive, + If a pattern is compiled with the PCRE2_EXTENDED option, most white + space in the pattern (other than in a character class), and characters + between a # outside a character class and the next newline, inclusive, are ignored. An escaping backslash can be used to include a white space or # character as part of the pattern. - If you want to remove the special meaning from a sequence of charac- - ters, you can do so by putting them between \Q and \E. This is differ- - ent from Perl in that $ and @ are handled as literals in \Q...\E - sequences in PCRE2, whereas in Perl, $ and @ cause variable interpola- + If you want to remove the special meaning from a sequence of charac- + ters, you can do so by putting them between \Q and \E. This is differ- + ent from Perl in that $ and @ are handled as literals in \Q...\E + sequences in PCRE2, whereas in Perl, $ and @ cause variable interpola- tion. Note the following examples: Pattern PCRE2 matches Perl matches @@ -6088,21 +6089,21 @@ BACKSLASH \Qabc\$xyz\E abc\$xyz abc\$xyz \Qabc\E\$\Qxyz\E abc$xyz abc$xyz - The \Q...\E sequence is recognized both inside and outside character - classes. An isolated \E that is not preceded by \Q is ignored. If \Q - is not followed by \E later in the pattern, the literal interpretation - continues to the end of the pattern (that is, \E is assumed at the - end). If the isolated \Q is inside a character class, this causes an - error, because the character class is not terminated by a closing + The \Q...\E sequence is recognized both inside and outside character + classes. An isolated \E that is not preceded by \Q is ignored. If \Q + is not followed by \E later in the pattern, the literal interpretation + continues to the end of the pattern (that is, \E is assumed at the + end). If the isolated \Q is inside a character class, this causes an + error, because the character class is not terminated by a closing square bracket. Non-printing characters A second use of backslash provides a way of encoding non-printing char- - acters in patterns in a visible manner. There is no restriction on the - appearance of non-printing characters in a pattern, but when a pattern + acters in patterns in a visible manner. There is no restriction on the + appearance of non-printing characters in a pattern, but when a pattern is being prepared by text editing, it is often easier to use one of the - following escape sequences than the binary character it represents. In + following escape sequences than the binary character it represents. In an ASCII or Unicode environment, these escapes are as follows: \a alarm, that is, the BEL character (hex 07) @@ -6113,57 +6114,57 @@ BACKSLASH \r carriage return (hex 0D) \t tab (hex 09) \0dd character with octal code 0dd - \ddd character with octal code ddd, or back reference + \ddd character with octal code ddd, or backreference \o{ddd..} character with octal code ddd.. \xhh character with hex code hh \x{hhh..} character with hex code hhh.. (default mode) \uhhhh character with hex code hhhh (when PCRE2_ALT_BSUX is set) - The precise effect of \cx on ASCII characters is as follows: if x is a - lower case letter, it is converted to upper case. Then bit 6 of the + The precise effect of \cx on ASCII characters is as follows: if x is a + lower case letter, it is converted to upper case. Then bit 6 of the character (hex 40) is inverted. Thus \cA to \cZ become hex 01 to hex 1A - (A is 41, Z is 5A), but \c{ becomes hex 3B ({ is 7B), and \c; becomes - hex 7B (; is 3B). If the code unit following \c has a value less than + (A is 41, Z is 5A), but \c{ becomes hex 3B ({ is 7B), and \c; becomes + hex 7B (; is 3B). If the code unit following \c has a value less than 32 or greater than 126, a compile-time error occurs. - When PCRE2 is compiled in EBCDIC mode, \a, \e, \f, \n, \r, and \t gen- + When PCRE2 is compiled in EBCDIC mode, \a, \e, \f, \n, \r, and \t gen- erate the appropriate EBCDIC code values. The \c escape is processed as specified for Perl in the perlebcdic document. The only characters that - are allowed after \c are A-Z, a-z, or one of @, [, \, ], ^, _, or ?. - Any other character provokes a compile-time error. The sequence \c@ - encodes character code 0; after \c the letters (in either case) encode + are allowed after \c are A-Z, a-z, or one of @, [, \, ], ^, _, or ?. + Any other character provokes a compile-time error. The sequence \c@ + encodes character code 0; after \c the letters (in either case) encode characters 1-26 (hex 01 to hex 1A); [, \, ], ^, and _ encode characters - 27-31 (hex 1B to hex 1F), and \c? becomes either 255 (hex FF) or 95 + 27-31 (hex 1B to hex 1F), and \c? becomes either 255 (hex FF) or 95 (hex 5F). - Thus, apart from \c?, these escapes generate the same character code - values as they do in an ASCII environment, though the meanings of the - values mostly differ. For example, \cG always generates code value 7, + Thus, apart from \c?, these escapes generate the same character code + values as they do in an ASCII environment, though the meanings of the + values mostly differ. For example, \cG always generates code value 7, which is BEL in ASCII but DEL in EBCDIC. - The sequence \c? generates DEL (127, hex 7F) in an ASCII environment, - but because 127 is not a control character in EBCDIC, Perl makes it - generate the APC character. Unfortunately, there are several variants - of EBCDIC. In most of them the APC character has the value 255 (hex - FF), but in the one Perl calls POSIX-BC its value is 95 (hex 5F). If + The sequence \c? generates DEL (127, hex 7F) in an ASCII environment, + but because 127 is not a control character in EBCDIC, Perl makes it + generate the APC character. Unfortunately, there are several variants + of EBCDIC. In most of them the APC character has the value 255 (hex + FF), but in the one Perl calls POSIX-BC its value is 95 (hex 5F). If certain other characters have POSIX-BC values, PCRE2 makes \c? generate 95; otherwise it generates 255. - After \0 up to two further octal digits are read. If there are fewer - than two digits, just those that are present are used. Thus the + After \0 up to two further octal digits are read. If there are fewer + than two digits, just those that are present are used. Thus the sequence \0\x\015 specifies two binary zeros followed by a CR character (code value 13). Make sure you supply two digits after the initial zero if the pattern character that follows is itself an octal digit. - The escape \o must be followed by a sequence of octal digits, enclosed - in braces. An error occurs if this is not the case. This escape is a - recent addition to Perl; it provides way of specifying character code - points as octal numbers greater than 0777, and it also allows octal - numbers and back references to be unambiguously specified. + The escape \o must be followed by a sequence of octal digits, enclosed + in braces. An error occurs if this is not the case. This escape is a + recent addition to Perl; it provides way of specifying character code + points as octal numbers greater than 0777, and it also allows octal + numbers and backreferences to be unambiguously specified. For greater clarity and unambiguity, it is best to avoid following \ by a digit greater than zero. Instead, use \o{} or \x{} to specify charac- - ter numbers, and \g{} to specify back references. The following para- + ter numbers, and \g{} to specify backreferences. The following para- graphs describe the old, ambiguous syntax. The handling of a backslash followed by a digit other than 0 is compli- @@ -6171,103 +6172,103 @@ BACKSLASH Outside a character class, PCRE2 reads the digit and any following dig- its as a decimal number. If the number is less than 10, begins with the - digit 8 or 9, or if there are at least that many previous capturing - left parentheses in the expression, the entire sequence is taken as a - back reference. A description of how this works is given later, follow- - ing the discussion of parenthesized subpatterns. Otherwise, up to + digit 8 or 9, or if there are at least that many previous capturing + left parentheses in the expression, the entire sequence is taken as a + backreference. A description of how this works is given later, follow- + ing the discussion of parenthesized subpatterns. Otherwise, up to three octal digits are read to form a character code. - Inside a character class, PCRE2 handles \8 and \9 as the literal char- - acters "8" and "9", and otherwise reads up to three octal digits fol- + Inside a character class, PCRE2 handles \8 and \9 as the literal char- + acters "8" and "9", and otherwise reads up to three octal digits fol- lowing the backslash, using them to generate a data character. Any sub- - sequent digits stand for themselves. For example, outside a character + sequent digits stand for themselves. For example, outside a character class: \040 is another way of writing an ASCII space \40 is the same, provided there are fewer than 40 previous capturing subpatterns - \7 is always a back reference - \11 might be a back reference, or another way of + \7 is always a backreference + \11 might be a backreference, or another way of writing a tab \011 is always a tab \0113 is a tab followed by the character "3" - \113 might be a back reference, otherwise the + \113 might be a backreference, otherwise the character with octal code 113 - \377 might be a back reference, otherwise + \377 might be a backreference, otherwise the value 255 (decimal) - \81 is always a back reference + \81 is always a backreference - Note that octal values of 100 or greater that are specified using this - syntax must not be introduced by a leading zero, because no more than + Note that octal values of 100 or greater that are specified using this + syntax must not be introduced by a leading zero, because no more than three octal digits are ever read. - By default, after \x that is not followed by {, from zero to two hexa- - decimal digits are read (letters can be in upper or lower case). Any + By default, after \x that is not followed by {, from zero to two hexa- + decimal digits are read (letters can be in upper or lower case). Any number of hexadecimal digits may appear between \x{ and }. If a charac- - ter other than a hexadecimal digit appears between \x{ and }, or if + ter other than a hexadecimal digit appears between \x{ and }, or if there is no terminating }, an error occurs. - If the PCRE2_ALT_BSUX option is set, the interpretation of \x is as + If the PCRE2_ALT_BSUX option is set, the interpretation of \x is as just described only when it is followed by two hexadecimal digits. Oth- - erwise, it matches a literal "x" character. In this mode, support for - code points greater than 256 is provided by \u, which must be followed - by four hexadecimal digits; otherwise it matches a literal "u" charac- + erwise, it matches a literal "x" character. In this mode, support for + code points greater than 256 is provided by \u, which must be followed + by four hexadecimal digits; otherwise it matches a literal "u" charac- ter. Characters whose value is less than 256 can be defined by either of the two syntaxes for \x (or by \u in PCRE2_ALT_BSUX mode). There is no dif- - ference in the way they are handled. For example, \xdc is exactly the + ference in the way they are handled. For example, \xdc is exactly the same as \x{dc} (or \u00dc in PCRE2_ALT_BSUX mode). Constraints on character values - Characters that are specified using octal or hexadecimal numbers are + Characters that are specified using octal or hexadecimal numbers are limited to certain values, as follows: 8-bit non-UTF mode no greater than 0xff 16-bit non-UTF mode no greater than 0xffff 32-bit non-UTF mode no greater than 0xffffffff - All UTF modes no greater than 0x10ffff and a valid codepoint + All UTF modes no greater than 0x10ffff and a valid code point - Invalid Unicode codepoints are all those in the range 0xd800 to 0xdfff - (the so-called "surrogate" codepoints). The check for these can be dis- - abled by the caller of pcre2_compile() by setting the option + Invalid Unicode code points are all those in the range 0xd800 to 0xdfff + (the so-called "surrogate" code points). The check for these can be + disabled by the caller of pcre2_compile() by setting the option PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES. Escape sequences in character classes All the sequences that define a single character value can be used both - inside and outside character classes. In addition, inside a character + inside and outside character classes. In addition, inside a character class, \b is interpreted as the backspace character (hex 08). - \N is not allowed in a character class. \B, \R, and \X are not special - inside a character class. Like other unrecognized alphabetic escape - sequences, they cause an error. Outside a character class, these + \N is not allowed in a character class. \B, \R, and \X are not special + inside a character class. Like other unrecognized alphabetic escape + sequences, they cause an error. Outside a character class, these sequences have different meanings. Unsupported escape sequences - In Perl, the sequences \l, \L, \u, and \U are recognized by its string - handler and used to modify the case of following characters. By + In Perl, the sequences \l, \L, \u, and \U are recognized by its string + handler and used to modify the case of following characters. By default, PCRE2 does not support these escape sequences. However, if the PCRE2_ALT_BSUX option is set, \U matches a "U" character, and \u can be used to define a character by code point, as described above. - Absolute and relative back references + Absolute and relative backreferences - The sequence \g followed by a signed or unsigned number, optionally - enclosed in braces, is an absolute or relative back reference. A named - back reference can be coded as \g{name}. Back references are discussed + The sequence \g followed by a signed or unsigned number, optionally + enclosed in braces, is an absolute or relative backreference. A named + backreference can be coded as \g{name}. backreferences are discussed later, following the discussion of parenthesized subpatterns. Absolute and relative subroutine calls - For compatibility with Oniguruma, the non-Perl syntax \g followed by a + For compatibility with Oniguruma, the non-Perl syntax \g followed by a name or a number enclosed either in angle brackets or single quotes, is - an alternative syntax for referencing a subpattern as a "subroutine". - Details are discussed later. Note that \g{...} (Perl syntax) and - \g<...> (Oniguruma syntax) are not synonymous. The former is a back - reference; the latter is a subroutine call. + an alternative syntax for referencing a subpattern as a "subroutine". + Details are discussed later. Note that \g{...} (Perl syntax) and + \g<...> (Oniguruma syntax) are not synonymous. The former is a backref- + erence; the latter is a subroutine call. Generic character types @@ -6285,55 +6286,55 @@ BACKSLASH \W any "non-word" character There is also the single sequence \N, which matches a non-newline char- - acter. This is the same as the "." metacharacter when PCRE2_DOTALL is - not set. Perl also uses \N to match characters by name; PCRE2 does not + acter. This is the same as the "." metacharacter when PCRE2_DOTALL is + not set. Perl also uses \N to match characters by name; PCRE2 does not support this. - Each pair of lower and upper case escape sequences partitions the com- - plete set of characters into two disjoint sets. Any given character - matches one, and only one, of each pair. The sequences can appear both - inside and outside character classes. They each match one character of - the appropriate type. If the current matching point is at the end of - the subject string, all of them fail, because there is no character to + Each pair of lower and upper case escape sequences partitions the com- + plete set of characters into two disjoint sets. Any given character + matches one, and only one, of each pair. The sequences can appear both + inside and outside character classes. They each match one character of + the appropriate type. If the current matching point is at the end of + the subject string, all of them fail, because there is no character to match. - The default \s characters are HT (9), LF (10), VT (11), FF (12), CR - (13), and space (32), which are defined as white space in the "C" + The default \s characters are HT (9), LF (10), VT (11), FF (12), CR + (13), and space (32), which are defined as white space in the "C" locale. This list may vary if locale-specific matching is taking place. - For example, in some locales the "non-breaking space" character (\xA0) + For example, in some locales the "non-breaking space" character (\xA0) is recognized as white space, and in others the VT character is not. - A "word" character is an underscore or any character that is a letter - or digit. By default, the definition of letters and digits is con- + A "word" character is an underscore or any character that is a letter + or digit. By default, the definition of letters and digits is con- trolled by PCRE2's low-valued character tables, and may vary if locale- specific matching is taking place (see "Locale support" in the pcre2api - page). For example, in a French locale such as "fr_FR" in Unix-like - systems, or "french" in Windows, some character codes greater than 127 - are used for accented letters, and these are then matched by \w. The + page). For example, in a French locale such as "fr_FR" in Unix-like + systems, or "french" in Windows, some character codes greater than 127 + are used for accented letters, and these are then matched by \w. The use of locales with Unicode is discouraged. - By default, characters whose code points are greater than 127 never + By default, characters whose code points are greater than 127 never match \d, \s, or \w, and always match \D, \S, and \W, although this may - be different for characters in the range 128-255 when locale-specific - matching is happening. These escape sequences retain their original - meanings from before Unicode support was available, mainly for effi- - ciency reasons. If the PCRE2_UCP option is set, the behaviour is - changed so that Unicode properties are used to determine character + be different for characters in the range 128-255 when locale-specific + matching is happening. These escape sequences retain their original + meanings from before Unicode support was available, mainly for effi- + ciency reasons. If the PCRE2_UCP option is set, the behaviour is + changed so that Unicode properties are used to determine character types, as follows: \d any character that matches \p{Nd} (decimal digit) \s any character that matches \p{Z} or \h or \v \w any character that matches \p{L} or \p{N}, plus underscore - The upper case escapes match the inverse sets of characters. Note that - \d matches only decimal digits, whereas \w matches any Unicode digit, + The upper case escapes match the inverse sets of characters. Note that + \d matches only decimal digits, whereas \w matches any Unicode digit, as well as any Unicode letter, and underscore. Note also that PCRE2_UCP - affects \b, and \B because they are defined in terms of \w and \W. + affects \b, and \B because they are defined in terms of \w and \W. Matching these sequences is noticeably slower when PCRE2_UCP is set. - The sequences \h, \H, \v, and \V, in contrast to the other sequences, - which match only ASCII characters by default, always match a specific - list of code points, whether or not PCRE2_UCP is set. The horizontal + The sequences \h, \H, \v, and \V, in contrast to the other sequences, + which match only ASCII characters by default, always match a specific + list of code points, whether or not PCRE2_UCP is set. The horizontal space characters are: U+0009 Horizontal tab (HT) @@ -6366,36 +6367,36 @@ BACKSLASH U+2028 Line separator U+2029 Paragraph separator - In 8-bit, non-UTF-8 mode, only the characters with code points less + In 8-bit, non-UTF-8 mode, only the characters with code points less than 256 are relevant. Newline sequences - Outside a character class, by default, the escape sequence \R matches - any Unicode newline sequence. In 8-bit non-UTF-8 mode \R is equivalent + Outside a character class, by default, the escape sequence \R matches + any Unicode newline sequence. In 8-bit non-UTF-8 mode \R is equivalent to the following: (?>\r\n|\n|\x0b|\f|\r|\x85) - This is an example of an "atomic group", details of which are given + This is an example of an "atomic group", details of which are given below. This particular group matches either the two-character sequence - CR followed by LF, or one of the single characters LF (linefeed, - U+000A), VT (vertical tab, U+000B), FF (form feed, U+000C), CR (car- - riage return, U+000D), or NEL (next line, U+0085). Because this is an - atomic group, the two-character sequence is treated as a single unit + CR followed by LF, or one of the single characters LF (linefeed, + U+000A), VT (vertical tab, U+000B), FF (form feed, U+000C), CR (car- + riage return, U+000D), or NEL (next line, U+0085). Because this is an + atomic group, the two-character sequence is treated as a single unit that cannot be split. - In other modes, two additional characters whose codepoints are greater + In other modes, two additional characters whose code points are greater than 255 are added: LS (line separator, U+2028) and PS (paragraph sepa- - rator, U+2029). Unicode support is not needed for these characters to + rator, U+2029). Unicode support is not needed for these characters to be recognized. It is possible to restrict \R to match only CR, LF, or CRLF (instead of - the complete set of Unicode line endings) by setting the option - PCRE2_BSR_ANYCRLF at compile time. (BSR is an abbrevation for "back- + the complete set of Unicode line endings) by setting the option + PCRE2_BSR_ANYCRLF at compile time. (BSR is an abbrevation for "back- slash R".) This can be made the default when PCRE2 is built; if this is - the case, the other behaviour can be requested via the PCRE2_BSR_UNI- - CODE option. It is also possible to specify these settings by starting + the case, the other behaviour can be requested via the PCRE2_BSR_UNI- + CODE option. It is also possible to specify these settings by starting a pattern string with one of the following sequences: (*BSR_ANYCRLF) CR, LF, or CRLF only @@ -6403,81 +6404,81 @@ BACKSLASH These override the default and the options given to the compiling func- tion. Note that these special settings, which are not Perl-compatible, - are recognized only at the very start of a pattern, and that they must - be in upper case. If more than one of them is present, the last one is - used. They can be combined with a change of newline convention; for + are recognized only at the very start of a pattern, and that they must + be in upper case. If more than one of them is present, the last one is + used. They can be combined with a change of newline convention; for example, a pattern can start with: (*ANY)(*BSR_ANYCRLF) - They can also be combined with the (*UTF) or (*UCP) special sequences. - Inside a character class, \R is treated as an unrecognized escape + They can also be combined with the (*UTF) or (*UCP) special sequences. + Inside a character class, \R is treated as an unrecognized escape sequence, and causes an error. Unicode character properties - When PCRE2 is built with Unicode support (the default), three addi- - tional escape sequences that match characters with specific properties - are available. In 8-bit non-UTF-8 mode, these sequences are of course - limited to testing characters whose codepoints are less than 256, but - they do work in this mode. In 32-bit non-UTF mode, codepoints greater - than 0x10ffff (the Unicode limit) may be encountered. These are all - treated as being in the Common script and with an unassigned type. The + When PCRE2 is built with Unicode support (the default), three addi- + tional escape sequences that match characters with specific properties + are available. In 8-bit non-UTF-8 mode, these sequences are of course + limited to testing characters whose code points are less than 256, but + they do work in this mode. In 32-bit non-UTF mode, code points greater + than 0x10ffff (the Unicode limit) may be encountered. These are all + treated as being in the Common script and with an unassigned type. The extra escape sequences are: \p{xx} a character with the xx property \P{xx} a character without the xx property \X a Unicode extended grapheme cluster - The property names represented by xx above are limited to the Unicode + The property names represented by xx above are limited to the Unicode script names, the general category properties, "Any", which matches any character (including newline), and some special PCRE2 properties - (described in the next section). Other Perl properties such as "InMu- - sicalSymbols" are not supported by PCRE2. Note that \P{Any} does not + (described in the next section). Other Perl properties such as "InMu- + sicalSymbols" are not supported by PCRE2. Note that \P{Any} does not match any characters, so always causes a match failure. Sets of Unicode characters are defined as belonging to certain scripts. - A character from one of these sets can be matched using a script name. + A character from one of these sets can be matched using a script name. For example: \p{Greek} \P{Han} - Those that are not part of an identified script are lumped together as + Those that are not part of an identified script are lumped together as "Common". The current list of scripts is: - Adlam, Ahom, Anatolian_Hieroglyphs, Arabic, Armenian, Avestan, Bali- - nese, Bamum, Bassa_Vah, Batak, Bengali, Bhaiksuki, Bopomofo, Brahmi, - Braille, Buginese, Buhid, Canadian_Aboriginal, Carian, Caucasian_Alba- - nian, Chakma, Cham, Cherokee, Common, Coptic, Cuneiform, Cypriot, + Adlam, Ahom, Anatolian_Hieroglyphs, Arabic, Armenian, Avestan, Bali- + nese, Bamum, Bassa_Vah, Batak, Bengali, Bhaiksuki, Bopomofo, Brahmi, + Braille, Buginese, Buhid, Canadian_Aboriginal, Carian, Caucasian_Alba- + nian, Chakma, Cham, Cherokee, Common, Coptic, Cuneiform, Cypriot, Cyrillic, Deseret, Devanagari, Duployan, Egyptian_Hieroglyphs, Elbasan, - Ethiopic, Georgian, Glagolitic, Gothic, Grantha, Greek, Gujarati, Gur- - mukhi, Han, Hangul, Hanunoo, Hatran, Hebrew, Hiragana, Imperial_Ara- - maic, Inherited, Inscriptional_Pahlavi, Inscriptional_Parthian, - Javanese, Kaithi, Kannada, Katakana, Kayah_Li, Kharoshthi, Khmer, Kho- - jki, Khudawadi, Lao, Latin, Lepcha, Limbu, Linear_A, Linear_B, Lisu, - Lycian, Lydian, Mahajani, Malayalam, Mandaic, Manichaean, Marchen, - Masaram_Gondi, Meetei_Mayek, Mende_Kikakui, Meroitic_Cursive, - Meroitic_Hieroglyphs, Miao, Modi, Mongolian, Mro, Multani, Myanmar, - Nabataean, New_Tai_Lue, Newa, Nko, Nushu, Ogham, Ol_Chiki, Old_Hungar- - ian, Old_Italic, Old_North_Arabian, Old_Permic, Old_Persian, - Old_South_Arabian, Old_Turkic, Oriya, Osage, Osmanya, Pahawh_Hmong, - Palmyrene, Pau_Cin_Hau, Phags_Pa, Phoenician, Psalter_Pahlavi, Rejang, - Runic, Samaritan, Saurashtra, Sharada, Shavian, Siddham, SignWriting, - Sinhala, Sora_Sompeng, Soyombo, Sundanese, Syloti_Nagri, Syriac, Taga- - log, Tagbanwa, Tai_Le, Tai_Tham, Tai_Viet, Takri, Tamil, Tangut, Tel- - ugu, Thaana, Thai, Tibetan, Tifinagh, Tirhuta, Ugaritic, Vai, + Ethiopic, Georgian, Glagolitic, Gothic, Grantha, Greek, Gujarati, Gur- + mukhi, Han, Hangul, Hanunoo, Hatran, Hebrew, Hiragana, Imperial_Ara- + maic, Inherited, Inscriptional_Pahlavi, Inscriptional_Parthian, + Javanese, Kaithi, Kannada, Katakana, Kayah_Li, Kharoshthi, Khmer, Kho- + jki, Khudawadi, Lao, Latin, Lepcha, Limbu, Linear_A, Linear_B, Lisu, + Lycian, Lydian, Mahajani, Malayalam, Mandaic, Manichaean, Marchen, + Masaram_Gondi, Meetei_Mayek, Mende_Kikakui, Meroitic_Cursive, + Meroitic_Hieroglyphs, Miao, Modi, Mongolian, Mro, Multani, Myanmar, + Nabataean, New_Tai_Lue, Newa, Nko, Nushu, Ogham, Ol_Chiki, Old_Hungar- + ian, Old_Italic, Old_North_Arabian, Old_Permic, Old_Persian, + Old_South_Arabian, Old_Turkic, Oriya, Osage, Osmanya, Pahawh_Hmong, + Palmyrene, Pau_Cin_Hau, Phags_Pa, Phoenician, Psalter_Pahlavi, Rejang, + Runic, Samaritan, Saurashtra, Sharada, Shavian, Siddham, SignWriting, + Sinhala, Sora_Sompeng, Soyombo, Sundanese, Syloti_Nagri, Syriac, Taga- + log, Tagbanwa, Tai_Le, Tai_Tham, Tai_Viet, Takri, Tamil, Tangut, Tel- + ugu, Thaana, Thai, Tibetan, Tifinagh, Tirhuta, Ugaritic, Vai, Warang_Citi, Yi, Zanabazar_Square. Each character has exactly one Unicode general category property, spec- - ified by a two-letter abbreviation. For compatibility with Perl, nega- - tion can be specified by including a circumflex between the opening - brace and the property name. For example, \p{^Lu} is the same as + ified by a two-letter abbreviation. For compatibility with Perl, nega- + tion can be specified by including a circumflex between the opening + brace and the property name. For example, \p{^Lu} is the same as \P{Lu}. If only one letter is specified with \p or \P, it includes all the gen- - eral category properties that start with that letter. In this case, in - the absence of negation, the curly brackets in the escape sequence are + eral category properties that start with that letter. In this case, in + the absence of negation, the curly brackets in the escape sequence are optional; these two examples have the same effect: \p{L} @@ -6529,85 +6530,85 @@ BACKSLASH Zp Paragraph separator Zs Space separator - The special property L& is also supported: it matches a character that - has the Lu, Ll, or Lt property, in other words, a letter that is not + The special property L& is also supported: it matches a character that + has the Lu, Ll, or Lt property, in other words, a letter that is not classified as a modifier or "other". - The Cs (Surrogate) property applies only to characters in the range - U+D800 to U+DFFF. Such characters are not valid in Unicode strings and - so cannot be tested by PCRE2, unless UTF validity checking has been - turned off (see the discussion of PCRE2_NO_UTF_CHECK in the pcre2api + The Cs (Surrogate) property applies only to characters in the range + U+D800 to U+DFFF. Such characters are not valid in Unicode strings and + so cannot be tested by PCRE2, unless UTF validity checking has been + turned off (see the discussion of PCRE2_NO_UTF_CHECK in the pcre2api page). Perl does not support the Cs property. - The long synonyms for property names that Perl supports (such as - \p{Letter}) are not supported by PCRE2, nor is it permitted to prefix + The long synonyms for property names that Perl supports (such as + \p{Letter}) are not supported by PCRE2, nor is it permitted to prefix any of these properties with "Is". No character that is in the Unicode table has the Cn (unassigned) prop- erty. Instead, this property is assumed for any code point that is not in the Unicode table. - Specifying caseless matching does not affect these escape sequences. - For example, \p{Lu} always matches only upper case letters. This is + Specifying caseless matching does not affect these escape sequences. + For example, \p{Lu} always matches only upper case letters. This is different from the behaviour of current versions of Perl. - Matching characters by Unicode property is not fast, because PCRE2 has - to do a multistage table lookup in order to find a character's prop- + Matching characters by Unicode property is not fast, because PCRE2 has + to do a multistage table lookup in order to find a character's prop- erty. That is why the traditional escape sequences such as \d and \w do - not use Unicode properties in PCRE2 by default, though you can make - them do so by setting the PCRE2_UCP option or by starting the pattern + not use Unicode properties in PCRE2 by default, though you can make + them do so by setting the PCRE2_UCP option or by starting the pattern with (*UCP). Extended grapheme clusters - The \X escape matches any number of Unicode characters that form an + The \X escape matches any number of Unicode characters that form an "extended grapheme cluster", and treats the sequence as an atomic group - (see below). Unicode supports various kinds of composite character by - giving each character a grapheme breaking property, and having rules + (see below). Unicode supports various kinds of composite character by + giving each character a grapheme breaking property, and having rules that use these properties to define the boundaries of extended grapheme - clusters. The rules are defined in Unicode Standard Annex 29, "Unicode + clusters. The rules are defined in Unicode Standard Annex 29, "Unicode Text Segmentation". - \X always matches at least one character. Then it decides whether to + \X always matches at least one character. Then it decides whether to add additional characters according to the following rules for ending a cluster: 1. End at the end of the subject string. - 2. Do not end between CR and LF; otherwise end after any control char- + 2. Do not end between CR and LF; otherwise end after any control char- acter. - 3. Do not break Hangul (a Korean script) syllable sequences. Hangul - characters are of five types: L, V, T, LV, and LVT. An L character may - be followed by an L, V, LV, or LVT character; an LV or V character may + 3. Do not break Hangul (a Korean script) syllable sequences. Hangul + characters are of five types: L, V, T, LV, and LVT. An L character may + be followed by an L, V, LV, or LVT character; an LV or V character may be followed by a V or T character; an LVT or T character may be follwed only by a T character. - 4. Do not end before extending characters or spacing marks or the - "zero-width joiner" characters. Characters with the "mark" property + 4. Do not end before extending characters or spacing marks or the + "zero-width joiner" characters. Characters with the "mark" property always have the "extend" grapheme breaking property. 5. Do not end after prepend characters. - 6. Do not break within emoji modifier sequences (a base character fol- + 6. Do not break within emoji modifier sequences (a base character fol- lowed by a modifier). Extending characters are allowed before the modi- fier. - 7. Do not break within emoji zwj sequences (zero-width jointer followed + 7. Do not break within emoji zwj sequences (zero-width joiner followed by "glue after ZWJ" or "base glue after ZWJ"). - 8. Do not break within emoji flag sequences. That is, do not break - between regional indicator (RI) characters if there are an odd number + 8. Do not break within emoji flag sequences. That is, do not break + between regional indicator (RI) characters if there are an odd number of RI characters before the break point. 6. Otherwise, end the cluster. PCRE2's additional properties - As well as the standard Unicode properties described above, PCRE2 sup- - ports four more that make it possible to convert traditional escape + As well as the standard Unicode properties described above, PCRE2 sup- + ports four more that make it possible to convert traditional escape sequences such as \w and \s to use Unicode properties. PCRE2 uses these - non-standard, non-Perl properties internally when PCRE2_UCP is set. + non-standard, non-Perl properties internally when PCRE2_UCP is set. However, they may also be used explicitly. These properties are: Xan Any alphanumeric character @@ -6615,53 +6616,53 @@ BACKSLASH Xsp Any Perl space character Xwd Any Perl "word" character - Xan matches characters that have either the L (letter) or the N (num- - ber) property. Xps matches the characters tab, linefeed, vertical tab, - form feed, or carriage return, and any other character that has the Z - (separator) property. Xsp is the same as Xps; in PCRE1 it used to - exclude vertical tab, for Perl compatibility, but Perl changed. Xwd + Xan matches characters that have either the L (letter) or the N (num- + ber) property. Xps matches the characters tab, linefeed, vertical tab, + form feed, or carriage return, and any other character that has the Z + (separator) property. Xsp is the same as Xps; in PCRE1 it used to + exclude vertical tab, for Perl compatibility, but Perl changed. Xwd matches the same characters as Xan, plus underscore. - There is another non-standard property, Xuc, which matches any charac- - ter that can be represented by a Universal Character Name in C++ and - other programming languages. These are the characters $, @, ` (grave - accent), and all characters with Unicode code points greater than or - equal to U+00A0, except for the surrogates U+D800 to U+DFFF. Note that - most base (ASCII) characters are excluded. (Universal Character Names - are of the form \uHHHH or \UHHHHHHHH where H is a hexadecimal digit. + There is another non-standard property, Xuc, which matches any charac- + ter that can be represented by a Universal Character Name in C++ and + other programming languages. These are the characters $, @, ` (grave + accent), and all characters with Unicode code points greater than or + equal to U+00A0, except for the surrogates U+D800 to U+DFFF. Note that + most base (ASCII) characters are excluded. (Universal Character Names + are of the form \uHHHH or \UHHHHHHHH where H is a hexadecimal digit. Note that the Xuc property does not match these sequences but the char- acters that they represent.) Resetting the match start - The escape sequence \K causes any previously matched characters not to + The escape sequence \K causes any previously matched characters not to be included in the final matched sequence. For example, the pattern: foo\Kbar - matches "foobar", but reports that it has matched "bar". This feature - is similar to a lookbehind assertion (described below). However, in - this case, the part of the subject before the real match does not have - to be of fixed length, as lookbehind assertions do. The use of \K does - not interfere with the setting of captured substrings. For example, + matches "foobar", but reports that it has matched "bar". This feature + is similar to a lookbehind assertion (described below). However, in + this case, the part of the subject before the real match does not have + to be of fixed length, as lookbehind assertions do. The use of \K does + not interfere with the setting of captured substrings. For example, when the pattern (foo)\Kbar matches "foobar", the first substring is still set to "foo". - Perl documents that the use of \K within assertions is "not well - defined". In PCRE2, \K is acted upon when it occurs inside positive - assertions, but is ignored in negative assertions. Note that when a - pattern such as (?=ab\K) matches, the reported start of the match can + Perl documents that the use of \K within assertions is "not well + defined". In PCRE2, \K is acted upon when it occurs inside positive + assertions, but is ignored in negative assertions. Note that when a + pattern such as (?=ab\K) matches, the reported start of the match can be greater than the end of the match. Simple assertions - The final use of backslash is for certain simple assertions. An asser- - tion specifies a condition that has to be met at a particular point in - a match, without consuming any characters from the subject string. The - use of subpatterns for more complicated assertions is described below. + The final use of backslash is for certain simple assertions. An asser- + tion specifies a condition that has to be met at a particular point in + a match, without consuming any characters from the subject string. The + use of subpatterns for more complicated assertions is described below. The backslashed assertions are: \b matches at a word boundary @@ -6672,184 +6673,184 @@ BACKSLASH \z matches only at the end of the subject \G matches at the first matching position in the subject - Inside a character class, \b has a different meaning; it matches the - backspace character. If any other of these assertions appears in a + Inside a character class, \b has a different meaning; it matches the + backspace character. If any other of these assertions appears in a character class, an "invalid escape sequence" error is generated. - A word boundary is a position in the subject string where the current - character and the previous character do not both match \w or \W (i.e. - one matches \w and the other matches \W), or the start or end of the - string if the first or last character matches \w, respectively. In a - UTF mode, the meanings of \w and \W can be changed by setting the + A word boundary is a position in the subject string where the current + character and the previous character do not both match \w or \W (i.e. + one matches \w and the other matches \W), or the start or end of the + string if the first or last character matches \w, respectively. In a + UTF mode, the meanings of \w and \W can be changed by setting the PCRE2_UCP option. When this is done, it also affects \b and \B. Neither - PCRE2 nor Perl has a separate "start of word" or "end of word" metase- - quence. However, whatever follows \b normally determines which it is. + PCRE2 nor Perl has a separate "start of word" or "end of word" metase- + quence. However, whatever follows \b normally determines which it is. For example, the fragment \ba matches "a" at the start of a word. - The \A, \Z, and \z assertions differ from the traditional circumflex + The \A, \Z, and \z assertions differ from the traditional circumflex and dollar (described in the next section) in that they only ever match - at the very start and end of the subject string, whatever options are - set. Thus, they are independent of multiline mode. These three asser- - tions are not affected by the PCRE2_NOTBOL or PCRE2_NOTEOL options, - which affect only the behaviour of the circumflex and dollar metachar- - acters. However, if the startoffset argument of pcre2_match() is non- - zero, indicating that matching is to start at a point other than the - beginning of the subject, \A can never match. The difference between - \Z and \z is that \Z matches before a newline at the end of the string + at the very start and end of the subject string, whatever options are + set. Thus, they are independent of multiline mode. These three asser- + tions are not affected by the PCRE2_NOTBOL or PCRE2_NOTEOL options, + which affect only the behaviour of the circumflex and dollar metachar- + acters. However, if the startoffset argument of pcre2_match() is non- + zero, indicating that matching is to start at a point other than the + beginning of the subject, \A can never match. The difference between + \Z and \z is that \Z matches before a newline at the end of the string as well as at the very end, whereas \z matches only at the end. - The \G assertion is true only when the current matching position is at - the start point of the match, as specified by the startoffset argument - of pcre2_match(). It differs from \A when the value of startoffset is - non-zero. By calling pcre2_match() multiple times with appropriate - arguments, you can mimic Perl's /g option, and it is in this kind of + The \G assertion is true only when the current matching position is at + the start point of the match, as specified by the startoffset argument + of pcre2_match(). It differs from \A when the value of startoffset is + non-zero. By calling pcre2_match() multiple times with appropriate + arguments, you can mimic Perl's /g option, and it is in this kind of implementation where \G can be useful. - Note, however, that PCRE2's interpretation of \G, as the start of the + Note, however, that PCRE2's interpretation of \G, as the start of the current match, is subtly different from Perl's, which defines it as the - end of the previous match. In Perl, these can be different when the - previously matched string was empty. Because PCRE2 does just one match + end of the previous match. In Perl, these can be different when the + previously matched string was empty. Because PCRE2 does just one match at a time, it cannot reproduce this behaviour. - If all the alternatives of a pattern begin with \G, the expression is + If all the alternatives of a pattern begin with \G, the expression is anchored to the starting match position, and the "anchored" flag is set in the compiled regular expression. CIRCUMFLEX AND DOLLAR - The circumflex and dollar metacharacters are zero-width assertions. - That is, they test for a particular condition being true without con- + The circumflex and dollar metacharacters are zero-width assertions. + That is, they test for a particular condition being true without con- suming any characters from the subject string. These two metacharacters - are concerned with matching the starts and ends of lines. If the new- - line convention is set so that only the two-character sequence CRLF is - recognized as a newline, isolated CR and LF characters are treated as + are concerned with matching the starts and ends of lines. If the new- + line convention is set so that only the two-character sequence CRLF is + recognized as a newline, isolated CR and LF characters are treated as ordinary data characters, and are not recognized as newlines. Outside a character class, in the default matching mode, the circumflex - character is an assertion that is true only if the current matching - point is at the start of the subject string. If the startoffset argu- - ment of pcre2_match() is non-zero, or if PCRE2_NOTBOL is set, circum- - flex can never match if the PCRE2_MULTILINE option is unset. Inside a - character class, circumflex has an entirely different meaning (see + character is an assertion that is true only if the current matching + point is at the start of the subject string. If the startoffset argu- + ment of pcre2_match() is non-zero, or if PCRE2_NOTBOL is set, circum- + flex can never match if the PCRE2_MULTILINE option is unset. Inside a + character class, circumflex has an entirely different meaning (see below). - Circumflex need not be the first character of the pattern if a number - of alternatives are involved, but it should be the first thing in each - alternative in which it appears if the pattern is ever to match that - branch. If all possible alternatives start with a circumflex, that is, - if the pattern is constrained to match only at the start of the sub- - ject, it is said to be an "anchored" pattern. (There are also other + Circumflex need not be the first character of the pattern if a number + of alternatives are involved, but it should be the first thing in each + alternative in which it appears if the pattern is ever to match that + branch. If all possible alternatives start with a circumflex, that is, + if the pattern is constrained to match only at the start of the sub- + ject, it is said to be an "anchored" pattern. (There are also other constructs that can cause a pattern to be anchored.) - The dollar character is an assertion that is true only if the current - matching point is at the end of the subject string, or immediately - before a newline at the end of the string (by default), unless + The dollar character is an assertion that is true only if the current + matching point is at the end of the subject string, or immediately + before a newline at the end of the string (by default), unless PCRE2_NOTEOL is set. Note, however, that it does not actually match the newline. Dollar need not be the last character of the pattern if a num- ber of alternatives are involved, but it should be the last item in any - branch in which it appears. Dollar has no special meaning in a charac- + branch in which it appears. Dollar has no special meaning in a charac- ter class. - The meaning of dollar can be changed so that it matches only at the - very end of the string, by setting the PCRE2_DOLLAR_ENDONLY option at + The meaning of dollar can be changed so that it matches only at the + very end of the string, by setting the PCRE2_DOLLAR_ENDONLY option at compile time. This does not affect the \Z assertion. The meanings of the circumflex and dollar metacharacters are changed if - the PCRE2_MULTILINE option is set. When this is the case, a dollar - character matches before any newlines in the string, as well as at the - very end, and a circumflex matches immediately after internal newlines - as well as at the start of the subject string. It does not match after - a newline that ends the string, for compatibility with Perl. However, + the PCRE2_MULTILINE option is set. When this is the case, a dollar + character matches before any newlines in the string, as well as at the + very end, and a circumflex matches immediately after internal newlines + as well as at the start of the subject string. It does not match after + a newline that ends the string, for compatibility with Perl. However, this can be changed by setting the PCRE2_ALT_CIRCUMFLEX option. - For example, the pattern /^abc$/ matches the subject string "def\nabc" - (where \n represents a newline) in multiline mode, but not otherwise. - Consequently, patterns that are anchored in single line mode because - all branches start with ^ are not anchored in multiline mode, and a - match for circumflex is possible when the startoffset argument of - pcre2_match() is non-zero. The PCRE2_DOLLAR_ENDONLY option is ignored + For example, the pattern /^abc$/ matches the subject string "def\nabc" + (where \n represents a newline) in multiline mode, but not otherwise. + Consequently, patterns that are anchored in single line mode because + all branches start with ^ are not anchored in multiline mode, and a + match for circumflex is possible when the startoffset argument of + pcre2_match() is non-zero. The PCRE2_DOLLAR_ENDONLY option is ignored if PCRE2_MULTILINE is set. - When the newline convention (see "Newline conventions" below) recog- - nizes the two-character sequence CRLF as a newline, this is preferred, - even if the single characters CR and LF are also recognized as new- - lines. For example, if the newline convention is "any", a multiline - mode circumflex matches before "xyz" in the string "abc\r\nxyz" rather - than after CR, even though CR on its own is a valid newline. (It also + When the newline convention (see "Newline conventions" below) recog- + nizes the two-character sequence CRLF as a newline, this is preferred, + even if the single characters CR and LF are also recognized as new- + lines. For example, if the newline convention is "any", a multiline + mode circumflex matches before "xyz" in the string "abc\r\nxyz" rather + than after CR, even though CR on its own is a valid newline. (It also matches at the very start of the string, of course.) - Note that the sequences \A, \Z, and \z can be used to match the start - and end of the subject in both modes, and if all branches of a pattern - start with \A it is always anchored, whether or not PCRE2_MULTILINE is + Note that the sequences \A, \Z, and \z can be used to match the start + and end of the subject in both modes, and if all branches of a pattern + start with \A it is always anchored, whether or not PCRE2_MULTILINE is set. FULL STOP (PERIOD, DOT) AND \N Outside a character class, a dot in the pattern matches any one charac- - ter in the subject string except (by default) a character that signi- + ter in the subject string except (by default) a character that signi- fies the end of a line. - When a line ending is defined as a single character, dot never matches - that character; when the two-character sequence CRLF is used, dot does - not match CR if it is immediately followed by LF, but otherwise it - matches all characters (including isolated CRs and LFs). When any Uni- - code line endings are being recognized, dot does not match CR or LF or + When a line ending is defined as a single character, dot never matches + that character; when the two-character sequence CRLF is used, dot does + not match CR if it is immediately followed by LF, but otherwise it + matches all characters (including isolated CRs and LFs). When any Uni- + code line endings are being recognized, dot does not match CR or LF or any of the other line ending characters. - The behaviour of dot with regard to newlines can be changed. If the - PCRE2_DOTALL option is set, a dot matches any one character, without - exception. If the two-character sequence CRLF is present in the sub- + The behaviour of dot with regard to newlines can be changed. If the + PCRE2_DOTALL option is set, a dot matches any one character, without + exception. If the two-character sequence CRLF is present in the sub- ject string, it takes two dots to match it. - The handling of dot is entirely independent of the handling of circum- - flex and dollar, the only relationship being that they both involve + The handling of dot is entirely independent of the handling of circum- + flex and dollar, the only relationship being that they both involve newlines. Dot has no special meaning in a character class. - The escape sequence \N behaves like a dot, except that it is not - affected by the PCRE2_DOTALL option. In other words, it matches any - character except one that signifies the end of a line. Perl also uses + The escape sequence \N behaves like a dot, except that it is not + affected by the PCRE2_DOTALL option. In other words, it matches any + character except one that signifies the end of a line. Perl also uses \N to match characters by name; PCRE2 does not support this. MATCHING A SINGLE CODE UNIT - Outside a character class, the escape sequence \C matches any one code - unit, whether or not a UTF mode is set. In the 8-bit library, one code - unit is one byte; in the 16-bit library it is a 16-bit unit; in the - 32-bit library it is a 32-bit unit. Unlike a dot, \C always matches - line-ending characters. The feature is provided in Perl in order to + Outside a character class, the escape sequence \C matches any one code + unit, whether or not a UTF mode is set. In the 8-bit library, one code + unit is one byte; in the 16-bit library it is a 16-bit unit; in the + 32-bit library it is a 32-bit unit. Unlike a dot, \C always matches + line-ending characters. The feature is provided in Perl in order to match individual bytes in UTF-8 mode, but it is unclear how it can use- fully be used. - Because \C breaks up characters into individual code units, matching - one unit with \C in UTF-8 or UTF-16 mode means that the rest of the - string may start with a malformed UTF character. This has undefined + Because \C breaks up characters into individual code units, matching + one unit with \C in UTF-8 or UTF-16 mode means that the rest of the + string may start with a malformed UTF character. This has undefined results, because PCRE2 assumes that it is matching character by charac- - ter in a valid UTF string (by default it checks the subject string's - validity at the start of processing unless the PCRE2_NO_UTF_CHECK + ter in a valid UTF string (by default it checks the subject string's + validity at the start of processing unless the PCRE2_NO_UTF_CHECK option is used). - An application can lock out the use of \C by setting the - PCRE2_NEVER_BACKSLASH_C option when compiling a pattern. It is also + An application can lock out the use of \C by setting the + PCRE2_NEVER_BACKSLASH_C option when compiling a pattern. It is also possible to build PCRE2 with the use of \C permanently disabled. - PCRE2 does not allow \C to appear in lookbehind assertions (described - below) in UTF-8 or UTF-16 modes, because this would make it impossible - to calculate the length of the lookbehind. Neither the alternative + PCRE2 does not allow \C to appear in lookbehind assertions (described + below) in UTF-8 or UTF-16 modes, because this would make it impossible + to calculate the length of the lookbehind. Neither the alternative matching function pcre2_dfa_match() nor the JIT optimizer support \C in these UTF modes. The former gives a match-time error; the latter fails to optimize and so the match is always run using the interpreter. - In the 32-bit library, however, \C is always supported (when not - explicitly locked out) because it always matches a single code unit, + In the 32-bit library, however, \C is always supported (when not + explicitly locked out) because it always matches a single code unit, whether or not UTF-32 is specified. In general, the \C escape sequence is best avoided. However, one way of - using it that avoids the problem of malformed UTF-8 or UTF-16 charac- - ters is to use a lookahead to check the length of the next character, - as in this pattern, which could be used with a UTF-8 string (ignore + using it that avoids the problem of malformed UTF-8 or UTF-16 charac- + ters is to use a lookahead to check the length of the next character, + as in this pattern, which could be used with a UTF-8 string (ignore white space and line breaks): (?| (?=[\x00-\x7f])(\C) | @@ -6857,10 +6858,10 @@ MATCHING A SINGLE CODE UNIT (?=[\x{800}-\x{ffff}])(\C)(\C)(\C) | (?=[\x{10000}-\x{1fffff}])(\C)(\C)(\C)(\C)) - In this example, a group that starts with (?| resets the capturing + In this example, a group that starts with (?| resets the capturing parentheses numbers in each alternative (see "Duplicate Subpattern Num- bers" below). The assertions at the start of each branch check the next - UTF-8 character for values whose encoding uses 1, 2, 3, or 4 bytes, + UTF-8 character for values whose encoding uses 1, 2, 3, or 4 bytes, respectively. The character's individual bytes are then captured by the appropriate number of \C groups. @@ -6869,112 +6870,112 @@ SQUARE BRACKETS AND CHARACTER CLASSES An opening square bracket introduces a character class, terminated by a closing square bracket. A closing square bracket on its own is not spe- - cial by default. If a closing square bracket is required as a member + cial by default. If a closing square bracket is required as a member of the class, it should be the first data character in the class (after - an initial circumflex, if present) or escaped with a backslash. This - means that, by default, an empty class cannot be defined. However, if - the PCRE2_ALLOW_EMPTY_CLASS option is set, a closing square bracket at + an initial circumflex, if present) or escaped with a backslash. This + means that, by default, an empty class cannot be defined. However, if + the PCRE2_ALLOW_EMPTY_CLASS option is set, a closing square bracket at the start does end the (empty) class. - A character class matches a single character in the subject. A matched + A character class matches a single character in the subject. A matched character must be in the set of characters defined by the class, unless - the first character in the class definition is a circumflex, in which + the first character in the class definition is a circumflex, in which case the subject character must not be in the set defined by the class. - If a circumflex is actually required as a member of the class, ensure + If a circumflex is actually required as a member of the class, ensure it is not the first character, or escape it with a backslash. - For example, the character class [aeiou] matches any lower case vowel, - while [^aeiou] matches any character that is not a lower case vowel. + For example, the character class [aeiou] matches any lower case vowel, + while [^aeiou] matches any character that is not a lower case vowel. Note that a circumflex is just a convenient notation for specifying the - characters that are in the class by enumerating those that are not. A - class that starts with a circumflex is not an assertion; it still con- - sumes a character from the subject string, and therefore it fails if + characters that are in the class by enumerating those that are not. A + class that starts with a circumflex is not an assertion; it still con- + sumes a character from the subject string, and therefore it fails if the current pointer is at the end of the string. - When caseless matching is set, any letters in a class represent both - their upper case and lower case versions, so for example, a caseless - [aeiou] matches "A" as well as "a", and a caseless [^aeiou] does not + When caseless matching is set, any letters in a class represent both + their upper case and lower case versions, so for example, a caseless + [aeiou] matches "A" as well as "a", and a caseless [^aeiou] does not match "A", whereas a caseful version would. - Characters that might indicate line breaks are never treated in any - special way when matching character classes, whatever line-ending - sequence is in use, and whatever setting of the PCRE2_DOTALL and - PCRE2_MULTILINE options is used. A class such as [^a] always matches + Characters that might indicate line breaks are never treated in any + special way when matching character classes, whatever line-ending + sequence is in use, and whatever setting of the PCRE2_DOTALL and + PCRE2_MULTILINE options is used. A class such as [^a] always matches one of these characters. - The character escape sequences \d, \D, \h, \H, \p, \P, \s, \S, \v, \V, + The character escape sequences \d, \D, \h, \H, \p, \P, \s, \S, \v, \V, \w, and \W may appear in a character class, and add the characters that - they match to the class. For example, [\dABCDEF] matches any hexadeci- - mal digit. In UTF modes, the PCRE2_UCP option affects the meanings of - \d, \s, \w and their upper case partners, just as it does when they - appear outside a character class, as described in the section entitled + they match to the class. For example, [\dABCDEF] matches any hexadeci- + mal digit. In UTF modes, the PCRE2_UCP option affects the meanings of + \d, \s, \w and their upper case partners, just as it does when they + appear outside a character class, as described in the section entitled "Generic character types" above. The escape sequence \b has a different - meaning inside a character class; it matches the backspace character. - The sequences \B, \N, \R, and \X are not special inside a character - class. Like any other unrecognized escape sequences, they cause an + meaning inside a character class; it matches the backspace character. + The sequences \B, \N, \R, and \X are not special inside a character + class. Like any other unrecognized escape sequences, they cause an error. - The minus (hyphen) character can be used to specify a range of charac- - ters in a character class. For example, [d-m] matches any letter - between d and m, inclusive. If a minus character is required in a - class, it must be escaped with a backslash or appear in a position - where it cannot be interpreted as indicating a range, typically as the + The minus (hyphen) character can be used to specify a range of charac- + ters in a character class. For example, [d-m] matches any letter + between d and m, inclusive. If a minus character is required in a + class, it must be escaped with a backslash or appear in a position + where it cannot be interpreted as indicating a range, typically as the first or last character in the class, or immediately after a range. For - example, [b-d-z] matches letters in the range b to d, a hyphen charac- + example, [b-d-z] matches letters in the range b to d, a hyphen charac- ter, or z. Perl treats a hyphen as a literal if it appears before or after a POSIX class (see below) or before or after a character type escape such as as - \d or \H. However, unless the hyphen is the last character in the - class, Perl outputs a warning in its warning mode, as this is most - likely a user error. As PCRE2 has no facility for warning, an error is + \d or \H. However, unless the hyphen is the last character in the + class, Perl outputs a warning in its warning mode, as this is most + likely a user error. As PCRE2 has no facility for warning, an error is given in these cases. It is not possible to have the literal character "]" as the end charac- - ter of a range. A pattern such as [W-]46] is interpreted as a class of - two characters ("W" and "-") followed by a literal string "46]", so it - would match "W46]" or "-46]". However, if the "]" is escaped with a - backslash it is interpreted as the end of range, so [W-\]46] is inter- - preted as a class containing a range followed by two other characters. - The octal or hexadecimal representation of "]" can also be used to end + ter of a range. A pattern such as [W-]46] is interpreted as a class of + two characters ("W" and "-") followed by a literal string "46]", so it + would match "W46]" or "-46]". However, if the "]" is escaped with a + backslash it is interpreted as the end of range, so [W-\]46] is inter- + preted as a class containing a range followed by two other characters. + The octal or hexadecimal representation of "]" can also be used to end a range. Ranges normally include all code points between the start and end char- - acters, inclusive. They can also be used for code points specified + acters, inclusive. They can also be used for code points specified numerically, for example [\000-\037]. Ranges can include any characters - that are valid for the current mode. In any UTF mode, the so-called - "surrogate" characters (those whose code points lie between 0xd800 and - 0xdfff inclusive) may not be specified explicitly by default (the - PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES option disables this check). How- + that are valid for the current mode. In any UTF mode, the so-called + "surrogate" characters (those whose code points lie between 0xd800 and + 0xdfff inclusive) may not be specified explicitly by default (the + PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES option disables this check). How- ever, ranges such as [\x{d7ff}-\x{e000}], which include the surrogates, are always permitted. - There is a special case in EBCDIC environments for ranges whose end + There is a special case in EBCDIC environments for ranges whose end points are both specified as literal letters in the same case. For com- - patibility with Perl, EBCDIC code points within the range that are not - letters are omitted. For example, [h-k] matches only four characters, + patibility with Perl, EBCDIC code points within the range that are not + letters are omitted. For example, [h-k] matches only four characters, even though the codes for h and k are 0x88 and 0x92, a range of 11 code - points. However, if the range is specified numerically, for example, + points. However, if the range is specified numerically, for example, [\x88-\x92] or [h-\x92], all code points are included. If a range that includes letters is used when caseless matching is set, it matches the letters in either case. For example, [W-c] is equivalent - to [][\\^_`wxyzabc], matched caselessly, and in a non-UTF mode, if - character tables for a French locale are in use, [\xc8-\xcb] matches + to [][\\^_`wxyzabc], matched caselessly, and in a non-UTF mode, if + character tables for a French locale are in use, [\xc8-\xcb] matches accented E characters in both cases. - A circumflex can conveniently be used with the upper case character - types to specify a more restricted set of characters than the matching - lower case type. For example, the class [^\W_] matches any letter or + A circumflex can conveniently be used with the upper case character + types to specify a more restricted set of characters than the matching + lower case type. For example, the class [^\W_] matches any letter or digit, but not underscore, whereas [\w] includes underscore. A positive character class should be read as "something OR something OR ..." and a negative class as "NOT something AND NOT something AND NOT ...". - The only metacharacters that are recognized in character classes are - backslash, hyphen (only where it can be interpreted as specifying a - range), circumflex (only at the start), opening square bracket (only - when it can be interpreted as introducing a POSIX class name, or for a - special compatibility feature - see the next two sections), and the + The only metacharacters that are recognized in character classes are + backslash, hyphen (only where it can be interpreted as specifying a + range), circumflex (only at the start), opening square bracket (only + when it can be interpreted as introducing a POSIX class name, or for a + special compatibility feature - see the next two sections), and the terminating closing square bracket. However, escaping other non- alphanumeric characters does no harm. @@ -6982,7 +6983,7 @@ SQUARE BRACKETS AND CHARACTER CLASSES POSIX CHARACTER CLASSES Perl supports the POSIX notation for character classes. This uses names - enclosed by [: and :] within the enclosing square brackets. PCRE2 also + enclosed by [: and :] within the enclosing square brackets. PCRE2 also supports this notation. For example, [01[:alpha:]%] @@ -7005,13 +7006,13 @@ POSIX CHARACTER CLASSES word "word" characters (same as \w) xdigit hexadecimal digits - The default "space" characters are HT (9), LF (10), VT (11), FF (12), - CR (13), and space (32). If locale-specific matching is taking place, - the list of space characters may be different; there may be fewer or + The default "space" characters are HT (9), LF (10), VT (11), FF (12), + CR (13), and space (32). If locale-specific matching is taking place, + the list of space characters may be different; there may be fewer or more of them. "Space" and \s match the same set of characters. - The name "word" is a Perl extension, and "blank" is a GNU extension - from Perl 5.8. Another Perl extension is negation, which is indicated + The name "word" is a Perl extension, and "blank" is a GNU extension + from Perl 5.8. Another Perl extension is negation, which is indicated by a ^ character after the colon. For example, [12[:^digit:]] @@ -7022,9 +7023,9 @@ POSIX CHARACTER CLASSES By default, characters with values greater than 127 do not match any of the POSIX character classes, although this may be different for charac- - ters in the range 128-255 when locale-specific matching is happening. - However, if the PCRE2_UCP option is passed to pcre2_compile(), some of - the classes are changed so that Unicode character properties are used. + ters in the range 128-255 when locale-specific matching is happening. + However, if the PCRE2_UCP option is passed to pcre2_compile(), some of + the classes are changed so that Unicode character properties are used. This is achieved by replacing certain POSIX classes with other sequences, as follows: @@ -7038,10 +7039,10 @@ POSIX CHARACTER CLASSES [:upper:] becomes \p{Lu} [:word:] becomes \p{Xwd} - Negated versions, such as [:^alpha:] use \P instead of \p. Three other + Negated versions, such as [:^alpha:] use \P instead of \p. Three other POSIX classes are handled specially in UCP mode: - [:graph:] This matches characters that have glyphs that mark the page + [:graph:] This matches characters that have glyphs that mark the page when printed. In Unicode property terms, it matches all char- acters with the L, M, N, P, S, or Cf properties, except for: @@ -7050,59 +7051,59 @@ POSIX CHARACTER CLASSES U+2066 - U+2069 Various "isolate"s - [:print:] This matches the same characters as [:graph:] plus space - characters that are not controls, that is, characters with + [:print:] This matches the same characters as [:graph:] plus space + characters that are not controls, that is, characters with the Zs property. [:punct:] This matches all characters that have the Unicode P (punctua- - tion) property, plus those characters with code points less + tion) property, plus those characters with code points less than 256 that have the S (Symbol) property. - The other POSIX classes are unchanged, and match only characters with + The other POSIX classes are unchanged, and match only characters with code points less than 256. COMPATIBILITY FEATURE FOR WORD BOUNDARIES - In the POSIX.2 compliant library that was included in 4.4BSD Unix, the - ugly syntax [[:<:]] and [[:>:]] is used for matching "start of word" + In the POSIX.2 compliant library that was included in 4.4BSD Unix, the + ugly syntax [[:<:]] and [[:>:]] is used for matching "start of word" and "end of word". PCRE2 treats these items as follows: [[:<:]] is converted to \b(?=\w) [[:>:]] is converted to \b(?<=\w) Only these exact character sequences are recognized. A sequence such as - [a[:<:]b] provokes error for an unrecognized POSIX class name. This - support is not compatible with Perl. It is provided to help migrations + [a[:<:]b] provokes error for an unrecognized POSIX class name. This + support is not compatible with Perl. It is provided to help migrations from other environments, and is best not used in any new patterns. Note - that \b matches at the start and the end of a word (see "Simple asser- - tions" above), and in a Perl-style pattern the preceding or following - character normally shows which is wanted, without the need for the - assertions that are used above in order to give exactly the POSIX be- + that \b matches at the start and the end of a word (see "Simple asser- + tions" above), and in a Perl-style pattern the preceding or following + character normally shows which is wanted, without the need for the + assertions that are used above in order to give exactly the POSIX be- haviour. VERTICAL BAR - Vertical bar characters are used to separate alternative patterns. For + Vertical bar characters are used to separate alternative patterns. For example, the pattern gilbert|sullivan - matches either "gilbert" or "sullivan". Any number of alternatives may - appear, and an empty alternative is permitted (matching the empty + matches either "gilbert" or "sullivan". Any number of alternatives may + appear, and an empty alternative is permitted (matching the empty string). The matching process tries each alternative in turn, from left - to right, and the first one that succeeds is used. If the alternatives - are within a subpattern (defined below), "succeeds" means matching the + to right, and the first one that succeeds is used. If the alternatives + are within a subpattern (defined below), "succeeds" means matching the rest of the main pattern as well as the alternative in the subpattern. INTERNAL OPTION SETTING - The settings of the PCRE2_CASELESS, PCRE2_MULTILINE, PCRE2_DOTALL, - PCRE2_EXTENDED, PCRE2_EXTENDED_MORE, and PCRE2_NO_AUTO_CAPTURE options + The settings of the PCRE2_CASELESS, PCRE2_MULTILINE, PCRE2_DOTALL, + PCRE2_EXTENDED, PCRE2_EXTENDED_MORE, and PCRE2_NO_AUTO_CAPTURE options (which are Perl-compatible) can be changed from within the pattern by a - sequence of Perl option letters enclosed between "(?" and ")". The + sequence of Perl option letters enclosed between "(?" and ")". The option letters are i for PCRE2_CASELESS @@ -7113,43 +7114,43 @@ INTERNAL OPTION SETTING xx for PCRE2_EXTENDED_MORE For example, (?im) sets caseless, multiline matching. It is also possi- - ble to unset these options by preceding the letter with a hyphen. The - two "extended" options are not independent; unsetting either one can- + ble to unset these options by preceding the letter with a hyphen. The + two "extended" options are not independent; unsetting either one can- cels the effects of both of them. - A combined setting and unsetting such as (?im-sx), which sets - PCRE2_CASELESS and PCRE2_MULTILINE while unsetting PCRE2_DOTALL and - PCRE2_EXTENDED, is also permitted. If a letter appears both before and - after the hyphen, the option is unset. An empty options setting "(?)" + A combined setting and unsetting such as (?im-sx), which sets + PCRE2_CASELESS and PCRE2_MULTILINE while unsetting PCRE2_DOTALL and + PCRE2_EXTENDED, is also permitted. If a letter appears both before and + after the hyphen, the option is unset. An empty options setting "(?)" is allowed. Needless to say, it has no effect. - The PCRE2-specific options PCRE2_DUPNAMES and PCRE2_UNGREEDY can be - changed in the same way as the Perl-compatible options by using the + The PCRE2-specific options PCRE2_DUPNAMES and PCRE2_UNGREEDY can be + changed in the same way as the Perl-compatible options by using the characters J and U respectively. - When one of these option changes occurs at top level (that is, not - inside subpattern parentheses), the change applies to the remainder of - the pattern that follows. An option change within a subpattern (see - below for a description of subpatterns) affects only that part of the + When one of these option changes occurs at top level (that is, not + inside subpattern parentheses), the change applies to the remainder of + the pattern that follows. An option change within a subpattern (see + below for a description of subpatterns) affects only that part of the subpattern that follows it, so (a(?i)b)c - matches abc and aBc and no other strings (assuming PCRE2_CASELESS is - not used). By this means, options can be made to have different set- + matches abc and aBc and no other strings (assuming PCRE2_CASELESS is + not used). By this means, options can be made to have different set- tings in different parts of the pattern. Any changes made in one alter- native do carry on into subsequent branches within the same subpattern. For example, (a(?i)b|c) - matches "ab", "aB", "c", and "C", even though when matching "C" the - first branch is abandoned before the option setting. This is because - the effects of option settings happen at compile time. There would be + matches "ab", "aB", "c", and "C", even though when matching "C" the + first branch is abandoned before the option setting. This is because + the effects of option settings happen at compile time. There would be some very weird behaviour otherwise. - As a convenient shorthand, if any option settings are required at the - start of a non-capturing subpattern (see the next section), the option + As a convenient shorthand, if any option settings are required at the + start of a non-capturing subpattern (see the next section), the option letters may appear between the "?" and the ":". Thus the two patterns (?i:saturday|sunday) @@ -7157,14 +7158,14 @@ INTERNAL OPTION SETTING match exactly the same set of strings. - Note: There are other PCRE2-specific options that can be set by the + Note: There are other PCRE2-specific options that can be set by the application when the compiling function is called. The pattern can con- - tain special leading sequences such as (*CRLF) to override what the - application has set or what has been defaulted. Details are given in - the section entitled "Newline sequences" above. There are also the - (*UTF) and (*UCP) leading sequences that can be used to set UTF and - Unicode property modes; they are equivalent to setting the PCRE2_UTF - and PCRE2_UCP options, respectively. However, the application can set + tain special leading sequences such as (*CRLF) to override what the + application has set or what has been defaulted. Details are given in + the section entitled "Newline sequences" above. There are also the + (*UTF) and (*UCP) leading sequences that can be used to set UTF and + Unicode property modes; they are equivalent to setting the PCRE2_UTF + and PCRE2_UCP options, respectively. However, the application can set the PCRE2_NEVER_UTF and PCRE2_NEVER_UCP options, which lock out the use of the (*UTF) and (*UCP) sequences. @@ -7178,18 +7179,18 @@ SUBPATTERNS cat(aract|erpillar|) - matches "cataract", "caterpillar", or "cat". Without the parentheses, + matches "cataract", "caterpillar", or "cat". Without the parentheses, it would match "cataract", "erpillar" or an empty string. - 2. It sets up the subpattern as a capturing subpattern. This means + 2. It sets up the subpattern as a capturing subpattern. This means that, when the whole pattern matches, the portion of the subject string - that matched the subpattern is passed back to the caller, separately - from the portion that matched the whole pattern. (This applies only to - the traditional matching function; the DFA matching function does not + that matched the subpattern is passed back to the caller, separately + from the portion that matched the whole pattern. (This applies only to + the traditional matching function; the DFA matching function does not support capturing.) Opening parentheses are counted from left to right (starting from 1) to - obtain numbers for the capturing subpatterns. For example, if the + obtain numbers for the capturing subpatterns. For example, if the string "the red king" is matched against the pattern the ((red|white) (king|queen)) @@ -7197,12 +7198,12 @@ SUBPATTERNS the captured substrings are "red king", "red", and "king", and are num- bered 1, 2, and 3, respectively. - The fact that plain parentheses fulfil two functions is not always - helpful. There are often times when a grouping subpattern is required - without a capturing requirement. If an opening parenthesis is followed - by a question mark and a colon, the subpattern does not do any captur- - ing, and is not counted when computing the number of any subsequent - capturing subpatterns. For example, if the string "the white queen" is + The fact that plain parentheses fulfil two functions is not always + helpful. There are often times when a grouping subpattern is required + without a capturing requirement. If an opening parenthesis is followed + by a question mark and a colon, the subpattern does not do any captur- + ing, and is not counted when computing the number of any subsequent + capturing subpatterns. For example, if the string "the white queen" is matched against the pattern the ((?:red|white) (king|queen)) @@ -7210,37 +7211,37 @@ SUBPATTERNS the captured substrings are "white queen" and "queen", and are numbered 1 and 2. The maximum number of capturing subpatterns is 65535. - As a convenient shorthand, if any option settings are required at the - start of a non-capturing subpattern, the option letters may appear + As a convenient shorthand, if any option settings are required at the + start of a non-capturing subpattern, the option letters may appear between the "?" and the ":". Thus the two patterns (?i:saturday|sunday) (?:(?i)saturday|sunday) match exactly the same set of strings. Because alternative branches are - tried from left to right, and options are not reset until the end of - the subpattern is reached, an option setting in one branch does affect - subsequent branches, so the above patterns match "SUNDAY" as well as + tried from left to right, and options are not reset until the end of + the subpattern is reached, an option setting in one branch does affect + subsequent branches, so the above patterns match "SUNDAY" as well as "Saturday". DUPLICATE SUBPATTERN NUMBERS Perl 5.10 introduced a feature whereby each alternative in a subpattern - uses the same numbers for its capturing parentheses. Such a subpattern - starts with (?| and is itself a non-capturing subpattern. For example, + uses the same numbers for its capturing parentheses. Such a subpattern + starts with (?| and is itself a non-capturing subpattern. For example, consider this pattern: (?|(Sat)ur|(Sun))day - Because the two alternatives are inside a (?| group, both sets of cap- - turing parentheses are numbered one. Thus, when the pattern matches, - you can look at captured substring number one, whichever alternative - matched. This construct is useful when you want to capture part, but + Because the two alternatives are inside a (?| group, both sets of cap- + turing parentheses are numbered one. Thus, when the pattern matches, + you can look at captured substring number one, whichever alternative + matched. This construct is useful when you want to capture part, but not all, of one of a number of alternatives. Inside a (?| group, paren- - theses are numbered as usual, but the number is reset at the start of - each branch. The numbers of any capturing parentheses that follow the - subpattern start after the highest number used in any branch. The fol- + theses are numbered as usual, but the number is reset at the start of + each branch. The numbers of any capturing parentheses that follow the + subpattern start after the highest number used in any branch. The fol- lowing example is taken from the Perl documentation. The numbers under- neath show in which buffer the captured content will be stored. @@ -7248,14 +7249,14 @@ DUPLICATE SUBPATTERN NUMBERS / ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x # 1 2 2 3 2 3 4 - A back reference to a numbered subpattern uses the most recent value - that is set for that number by any subpattern. The following pattern + A backreference to a numbered subpattern uses the most recent value + that is set for that number by any subpattern. The following pattern matches "abcabc" or "defdef": /(?|(abc)|(def))\1/ - In contrast, a subroutine call to a numbered subpattern always refers - to the first one in the pattern with the given number. The following + In contrast, a subroutine call to a numbered subpattern always refers + to the first one in the pattern with the given number. The following pattern matches "abcabc" or "defabc": /(?|(abc)|(def))(?1)/ @@ -7263,47 +7264,47 @@ DUPLICATE SUBPATTERN NUMBERS A relative reference such as (?-1) is no different: it is just a conve- nient way of computing an absolute group number. - If a condition test for a subpattern's having matched refers to a non- - unique number, the test is true if any of the subpatterns of that num- + If a condition test for a subpattern's having matched refers to a non- + unique number, the test is true if any of the subpatterns of that num- ber have matched. - An alternative approach to using this "branch reset" feature is to use + An alternative approach to using this "branch reset" feature is to use duplicate named subpatterns, as described in the next section. NAMED SUBPATTERNS - Identifying capturing parentheses by number is simple, but it can be - very hard to keep track of the numbers in complicated regular expres- - sions. Furthermore, if an expression is modified, the numbers may + Identifying capturing parentheses by number is simple, but it can be + very hard to keep track of the numbers in complicated regular expres- + sions. Furthermore, if an expression is modified, the numbers may change. To help with this difficulty, PCRE2 supports the naming of sub- patterns. This feature was not added to Perl until release 5.10. Python - had the feature earlier, and PCRE1 introduced it at release 4.0, using - the Python syntax. PCRE2 supports both the Perl and the Python syntax. - Perl allows identically numbered subpatterns to have different names, + had the feature earlier, and PCRE1 introduced it at release 4.0, using + the Python syntax. PCRE2 supports both the Perl and the Python syntax. + Perl allows identically numbered subpatterns to have different names, but PCRE2 does not. - In PCRE2, a subpattern can be named in one of three ways: (?...) - or (?'name'...) as in Perl, or (?P...) as in Python. References - to capturing parentheses from other parts of the pattern, such as back - references, recursion, and conditions, can be made by name as well as + In PCRE2, a subpattern can be named in one of three ways: (?...) + or (?'name'...) as in Perl, or (?P...) as in Python. References + to capturing parentheses from other parts of the pattern, such as back- + references, recursion, and conditions, can be made by name as well as by number. - Names consist of up to 32 alphanumeric characters and underscores, but - must start with a non-digit. Named capturing parentheses are still - allocated numbers as well as names, exactly as if the names were not + Names consist of up to 32 alphanumeric characters and underscores, but + must start with a non-digit. Named capturing parentheses are still + allocated numbers as well as names, exactly as if the names were not present. The PCRE2 API provides function calls for extracting the name- - to-number translation table from a compiled pattern. There are also + to-number translation table from a compiled pattern. There are also convenience functions for extracting a captured substring by name. - By default, a name must be unique within a pattern, but it is possible - to relax this constraint by setting the PCRE2_DUPNAMES option at com- - pile time. (Duplicate names are also always permitted for subpatterns - with the same number, set up as described in the previous section.) - Duplicate names can be useful for patterns where only one instance of + By default, a name must be unique within a pattern, but it is possible + to relax this constraint by setting the PCRE2_DUPNAMES option at com- + pile time. (Duplicate names are also always permitted for subpatterns + with the same number, set up as described in the previous section.) + Duplicate names can be useful for patterns where only one instance of the named parentheses can match. Suppose you want to match the name of - a weekday, either as a 3-letter abbreviation or as the full name, and - in both cases you want to extract the abbreviation. This pattern + a weekday, either as a 3-letter abbreviation or as the full name, and + in both cases you want to extract the abbreviation. This pattern (ignoring the line breaks) does the job: (?Mon|Fri|Sun)(?:day)?| @@ -7312,18 +7313,18 @@ NAMED SUBPATTERNS (?Thu)(?:rsday)?| (?Sat)(?:urday)? - There are five capturing substrings, but only one is ever set after a + There are five capturing substrings, but only one is ever set after a match. (An alternative way of solving this problem is to use a "branch reset" subpattern, as described in the previous section.) - The convenience functions for extracting the data by name returns the - substring for the first (and in this example, the only) subpattern of - that name that matched. This saves searching to find which numbered + The convenience functions for extracting the data by name returns the + substring for the first (and in this example, the only) subpattern of + that name that matched. This saves searching to find which numbered subpattern it was. - If you make a back reference to a non-unique named subpattern from - elsewhere in the pattern, the subpatterns to which the name refers are - checked in the order in which they appear in the overall pattern. The + If you make a backreference to a non-unique named subpattern from else- + where in the pattern, the subpatterns to which the name refers are + checked in the order in which they appear in the overall pattern. The first one that is set is used for the reference. For example, this pat- tern matches both "foofoo" and "barbar" but not "foobar" or "barfoo": @@ -7331,29 +7332,29 @@ NAMED SUBPATTERNS If you make a subroutine call to a non-unique named subpattern, the one - that corresponds to the first occurrence of the name is used. In the + that corresponds to the first occurrence of the name is used. In the absence of duplicate numbers (see the previous section) this is the one with the lowest number. If you use a named reference in a condition test (see the section about conditions below), either to check whether a subpattern has matched, or - to check for recursion, all subpatterns with the same name are tested. - If the condition is true for any one of them, the overall condition is - true. This is the same behaviour as testing by number. For further - details of the interfaces for handling named subpatterns, see the + to check for recursion, all subpatterns with the same name are tested. + If the condition is true for any one of them, the overall condition is + true. This is the same behaviour as testing by number. For further + details of the interfaces for handling named subpatterns, see the pcre2api documentation. Warning: You cannot use different names to distinguish between two sub- - patterns with the same number because PCRE2 uses only the numbers when + patterns with the same number because PCRE2 uses only the numbers when matching. For this reason, an error is given at compile time if differ- - ent names are given to subpatterns with the same number. However, you + ent names are given to subpatterns with the same number. However, you can always give the same name to subpatterns with the same number, even when PCRE2_DUPNAMES is not set. REPETITION - Repetition is specified by quantifiers, which can follow any of the + Repetition is specified by quantifiers, which can follow any of the following items: a literal data character @@ -7363,21 +7364,21 @@ REPETITION the \R escape sequence an escape such as \d or \pL that matches a single character a character class - a back reference + a backreference a parenthesized subpattern (including most assertions) a subroutine call to a subpattern (recursive or otherwise) - The general repetition quantifier specifies a minimum and maximum num- - ber of permitted matches, by giving the two numbers in curly brackets - (braces), separated by a comma. The numbers must be less than 65536, + The general repetition quantifier specifies a minimum and maximum num- + ber of permitted matches, by giving the two numbers in curly brackets + (braces), separated by a comma. The numbers must be less than 65536, and the first must be less than or equal to the second. For example: z{2,4} - matches "zz", "zzz", or "zzzz". A closing brace on its own is not a - special character. If the second number is omitted, but the comma is - present, there is no upper limit; if the second number and the comma - are both omitted, the quantifier specifies an exact number of required + matches "zz", "zzz", or "zzzz". A closing brace on its own is not a + special character. If the second number is omitted, but the comma is + present, there is no upper limit; if the second number and the comma + are both omitted, the quantifier specifies an exact number of required matches. Thus [aeiou]{3,} @@ -7386,50 +7387,50 @@ REPETITION \d{8} - matches exactly 8 digits. An opening curly bracket that appears in a - position where a quantifier is not allowed, or one that does not match - the syntax of a quantifier, is taken as a literal character. For exam- + matches exactly 8 digits. An opening curly bracket that appears in a + position where a quantifier is not allowed, or one that does not match + the syntax of a quantifier, is taken as a literal character. For exam- ple, {,6} is not a quantifier, but a literal string of four characters. In UTF modes, quantifiers apply to characters rather than to individual - code units. Thus, for example, \x{100}{2} matches two characters, each + code units. Thus, for example, \x{100}{2} matches two characters, each of which is represented by a two-byte sequence in a UTF-8 string. Simi- - larly, \X{3} matches three Unicode extended grapheme clusters, each of - which may be several code units long (and they may be of different + larly, \X{3} matches three Unicode extended grapheme clusters, each of + which may be several code units long (and they may be of different lengths). The quantifier {0} is permitted, causing the expression to behave as if the previous item and the quantifier were not present. This may be use- - ful for subpatterns that are referenced as subroutines from elsewhere + ful for subpatterns that are referenced as subroutines from elsewhere in the pattern (but see also the section entitled "Defining subpatterns - for use by reference only" below). Items other than subpatterns that + for use by reference only" below). Items other than subpatterns that have a {0} quantifier are omitted from the compiled pattern. - For convenience, the three most common quantifiers have single-charac- + For convenience, the three most common quantifiers have single-charac- ter abbreviations: * is equivalent to {0,} + is equivalent to {1,} ? is equivalent to {0,1} - It is possible to construct infinite loops by following a subpattern + It is possible to construct infinite loops by following a subpattern that can match no characters with a quantifier that has no upper limit, for example: (a?)* - Earlier versions of Perl and PCRE1 used to give an error at compile + Earlier versions of Perl and PCRE1 used to give an error at compile time for such patterns. However, because there are cases where this can be useful, such patterns are now accepted, but if any repetition of the - subpattern does in fact match no characters, the loop is forcibly bro- + subpattern does in fact match no characters, the loop is forcibly bro- ken. - By default, the quantifiers are "greedy", that is, they match as much - as possible (up to the maximum number of permitted times), without - causing the rest of the pattern to fail. The classic example of where + By default, the quantifiers are "greedy", that is, they match as much + as possible (up to the maximum number of permitted times), without + causing the rest of the pattern to fail. The classic example of where this gives problems is in trying to match comments in C programs. These - appear between /* and */ and within the comment, individual * and / - characters may appear. An attempt to match C comments by applying the + appear between /* and */ and within the comment, individual * and / + characters may appear. An attempt to match C comments by applying the pattern /\*.*\*/ @@ -7438,19 +7439,19 @@ REPETITION /* first comment */ not comment /* second comment */ - fails, because it matches the entire string owing to the greediness of + fails, because it matches the entire string owing to the greediness of the .* item. If a quantifier is followed by a question mark, it ceases to be greedy, - and instead matches the minimum number of times possible, so the pat- + and instead matches the minimum number of times possible, so the pat- tern /\*.*?\*/ - does the right thing with the C comments. The meaning of the various - quantifiers is not otherwise changed, just the preferred number of - matches. Do not confuse this use of question mark with its use as a - quantifier in its own right. Because it has two uses, it can sometimes + does the right thing with the C comments. The meaning of the various + quantifiers is not otherwise changed, just the preferred number of + matches. Do not confuse this use of question mark with its use as a + quantifier in its own right. Because it has two uses, it can sometimes appear doubled, as in \d??\d @@ -7459,45 +7460,45 @@ REPETITION only way the rest of the pattern matches. If the PCRE2_UNGREEDY option is set (an option that is not available in - Perl), the quantifiers are not greedy by default, but individual ones - can be made greedy by following them with a question mark. In other + Perl), the quantifiers are not greedy by default, but individual ones + can be made greedy by following them with a question mark. In other words, it inverts the default behaviour. - When a parenthesized subpattern is quantified with a minimum repeat - count that is greater than 1 or with a limited maximum, more memory is - required for the compiled pattern, in proportion to the size of the + When a parenthesized subpattern is quantified with a minimum repeat + count that is greater than 1 or with a limited maximum, more memory is + required for the compiled pattern, in proportion to the size of the minimum or maximum. - If a pattern starts with .* or .{0,} and the PCRE2_DOTALL option - (equivalent to Perl's /s) is set, thus allowing the dot to match new- - lines, the pattern is implicitly anchored, because whatever follows - will be tried against every character position in the subject string, - so there is no point in retrying the overall match at any position + If a pattern starts with .* or .{0,} and the PCRE2_DOTALL option + (equivalent to Perl's /s) is set, thus allowing the dot to match new- + lines, the pattern is implicitly anchored, because whatever follows + will be tried against every character position in the subject string, + so there is no point in retrying the overall match at any position after the first. PCRE2 normally treats such a pattern as though it were preceded by \A. - In cases where it is known that the subject string contains no new- - lines, it is worth setting PCRE2_DOTALL in order to obtain this opti- + In cases where it is known that the subject string contains no new- + lines, it is worth setting PCRE2_DOTALL in order to obtain this opti- mization, or alternatively, using ^ to indicate anchoring explicitly. - However, there are some cases where the optimization cannot be used. - When .* is inside capturing parentheses that are the subject of a back - reference elsewhere in the pattern, a match at the start may fail where - a later one succeeds. Consider, for example: + However, there are some cases where the optimization cannot be used. + When .* is inside capturing parentheses that are the subject of a + backreference elsewhere in the pattern, a match at the start may fail + where a later one succeeds. Consider, for example: (.*)abc\1 - If the subject is "xyz123abc123" the match point is the fourth charac- + If the subject is "xyz123abc123" the match point is the fourth charac- ter. For this reason, such a pattern is not implicitly anchored. - Another case where implicit anchoring is not applied is when the lead- - ing .* is inside an atomic group. Once again, a match at the start may + Another case where implicit anchoring is not applied is when the lead- + ing .* is inside an atomic group. Once again, a match at the start may fail where a later one succeeds. Consider this pattern: (?>.*?a)b - It matches "ab" in the subject "aab". The use of the backtracking con- - trol verbs (*PRUNE) and (*SKIP) also disable this optimization, and + It matches "ab" in the subject "aab". The use of the backtracking con- + trol verbs (*PRUNE) and (*SKIP) also disable this optimization, and there is an option, PCRE2_NO_DOTSTAR_ANCHOR, to do so explicitly. When a capturing subpattern is repeated, the value captured is the sub- @@ -7506,8 +7507,8 @@ REPETITION (tweedle[dume]{3}\s*)+ has matched "tweedledum tweedledee" the value of the captured substring - is "tweedledee". However, if there are nested capturing subpatterns, - the corresponding captured values may have been set in previous itera- + is "tweedledee". However, if there are nested capturing subpatterns, + the corresponding captured values may have been set in previous itera- tions. For example, after (a|(b))+ @@ -7517,53 +7518,53 @@ REPETITION ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS - With both maximizing ("greedy") and minimizing ("ungreedy" or "lazy") - repetition, failure of what follows normally causes the repeated item - to be re-evaluated to see if a different number of repeats allows the - rest of the pattern to match. Sometimes it is useful to prevent this, - either to change the nature of the match, or to cause it fail earlier - than it otherwise might, when the author of the pattern knows there is + With both maximizing ("greedy") and minimizing ("ungreedy" or "lazy") + repetition, failure of what follows normally causes the repeated item + to be re-evaluated to see if a different number of repeats allows the + rest of the pattern to match. Sometimes it is useful to prevent this, + either to change the nature of the match, or to cause it fail earlier + than it otherwise might, when the author of the pattern knows there is no point in carrying on. - Consider, for example, the pattern \d+foo when applied to the subject + Consider, for example, the pattern \d+foo when applied to the subject line 123456bar After matching all 6 digits and then failing to match "foo", the normal - action of the matcher is to try again with only 5 digits matching the - \d+ item, and then with 4, and so on, before ultimately failing. - "Atomic grouping" (a term taken from Jeffrey Friedl's book) provides - the means for specifying that once a subpattern has matched, it is not + action of the matcher is to try again with only 5 digits matching the + \d+ item, and then with 4, and so on, before ultimately failing. + "Atomic grouping" (a term taken from Jeffrey Friedl's book) provides + the means for specifying that once a subpattern has matched, it is not to be re-evaluated in this way. - If we use atomic grouping for the previous example, the matcher gives - up immediately on failing to match "foo" the first time. The notation + If we use atomic grouping for the previous example, the matcher gives + up immediately on failing to match "foo" the first time. The notation is a kind of special parenthesis, starting with (?> as in this example: (?>\d+)foo - This kind of parenthesis "locks up" the part of the pattern it con- - tains once it has matched, and a failure further into the pattern is - prevented from backtracking into it. Backtracking past it to previous + This kind of parenthesis "locks up" the part of the pattern it con- + tains once it has matched, and a failure further into the pattern is + prevented from backtracking into it. Backtracking past it to previous items, however, works as normal. - An alternative description is that a subpattern of this type matches - exactly the string of characters that an identical standalone pattern + An alternative description is that a subpattern of this type matches + exactly the string of characters that an identical standalone pattern would match, if anchored at the current point in the subject string. Atomic grouping subpatterns are not capturing subpatterns. Simple cases such as the above example can be thought of as a maximizing repeat that - must swallow everything it can. So, while both \d+ and \d+? are pre- - pared to adjust the number of digits they match in order to make the + must swallow everything it can. So, while both \d+ and \d+? are pre- + pared to adjust the number of digits they match in order to make the rest of the pattern match, (?>\d+) can only match an entire sequence of digits. - Atomic groups in general can of course contain arbitrarily complicated - subpatterns, and can be nested. However, when the subpattern for an + Atomic groups in general can of course contain arbitrarily complicated + subpatterns, and can be nested. However, when the subpattern for an atomic group is just a single repeated item, as in the example above, a - simpler notation, called a "possessive quantifier" can be used. This - consists of an additional + character following a quantifier. Using + simpler notation, called a "possessive quantifier" can be used. This + consists of an additional + character following a quantifier. Using this notation, the previous example can be rewritten as \d++foo @@ -7573,46 +7574,46 @@ ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS (abc|xyz){2,3}+ - Possessive quantifiers are always greedy; the setting of the - PCRE2_UNGREEDY option is ignored. They are a convenient notation for - the simpler forms of atomic group. However, there is no difference in + Possessive quantifiers are always greedy; the setting of the + PCRE2_UNGREEDY option is ignored. They are a convenient notation for + the simpler forms of atomic group. However, there is no difference in the meaning of a possessive quantifier and the equivalent atomic group, - though there may be a performance difference; possessive quantifiers + though there may be a performance difference; possessive quantifiers should be slightly faster. - The possessive quantifier syntax is an extension to the Perl 5.8 syn- - tax. Jeffrey Friedl originated the idea (and the name) in the first + The possessive quantifier syntax is an extension to the Perl 5.8 syn- + tax. Jeffrey Friedl originated the idea (and the name) in the first edition of his book. Mike McCloskey liked it, so implemented it when he built Sun's Java package, and PCRE1 copied it from there. It ultimately found its way into Perl at release 5.10. - PCRE2 has an optimization that automatically "possessifies" certain - simple pattern constructs. For example, the sequence A+B is treated as - A++B because there is no point in backtracking into a sequence of A's + PCRE2 has an optimization that automatically "possessifies" certain + simple pattern constructs. For example, the sequence A+B is treated as + A++B because there is no point in backtracking into a sequence of A's when B must follow. This feature can be disabled by the PCRE2_NO_AUTO- POSSESS option, or starting the pattern with (*NO_AUTO_POSSESS). - When a pattern contains an unlimited repeat inside a subpattern that - can itself be repeated an unlimited number of times, the use of an - atomic group is the only way to avoid some failing matches taking a + When a pattern contains an unlimited repeat inside a subpattern that + can itself be repeated an unlimited number of times, the use of an + atomic group is the only way to avoid some failing matches taking a very long time indeed. The pattern (\D+|<\d+>)*[!?] - matches an unlimited number of substrings that either consist of non- - digits, or digits enclosed in <>, followed by either ! or ?. When it + matches an unlimited number of substrings that either consist of non- + digits, or digits enclosed in <>, followed by either ! or ?. When it matches, it runs quickly. However, if it is applied to aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - it takes a long time before reporting failure. This is because the - string can be divided between the internal \D+ repeat and the external - * repeat in a large number of ways, and all have to be tried. (The - example uses [!?] rather than a single character at the end, because - both PCRE2 and Perl have an optimization that allows for fast failure - when a single character is used. They remember the last single charac- - ter that is required for a match, and fail early if it is not present - in the string.) If the pattern is changed so that it uses an atomic + it takes a long time before reporting failure. This is because the + string can be divided between the internal \D+ repeat and the external + * repeat in a large number of ways, and all have to be tried. (The + example uses [!?] rather than a single character at the end, because + both PCRE2 and Perl have an optimization that allows for fast failure + when a single character is used. They remember the last single charac- + ter that is required for a match, and fail early if it is not present + in the string.) If the pattern is changed so that it uses an atomic group, like this: ((?>\D+)|<\d+>)*[!?] @@ -7620,32 +7621,32 @@ ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS sequences of non-digits cannot be broken, and failure happens quickly. -BACK REFERENCES +BACKREFERENCES Outside a character class, a backslash followed by a digit greater than - 0 (and possibly further digits) is a back reference to a capturing sub- - pattern earlier (that is, to its left) in the pattern, provided there + 0 (and possibly further digits) is a backreference to a capturing sub- + pattern earlier (that is, to its left) in the pattern, provided there have been that many previous capturing left parentheses. - However, if the decimal number following the backslash is less than 8, - it is always taken as a back reference, and causes an error only if - there are not that many capturing left parentheses in the entire pat- - tern. In other words, the parentheses that are referenced need not be - to the left of the reference for numbers less than 8. A "forward back - reference" of this type can make sense when a repetition is involved - and the subpattern to the right has participated in an earlier itera- + However, if the decimal number following the backslash is less than 8, + it is always taken as a backreference, and causes an error only if + there are not that many capturing left parentheses in the entire pat- + tern. In other words, the parentheses that are referenced need not be + to the left of the reference for numbers less than 8. A "forward back- + reference" of this type can make sense when a repetition is involved + and the subpattern to the right has participated in an earlier itera- tion. - It is not possible to have a numerical "forward back reference" to a - subpattern whose number is 8 or more using this syntax because a - sequence such as \50 is interpreted as a character defined in octal. + It is not possible to have a numerical "forward backreference" to a + subpattern whose number is 8 or more using this syntax because a + sequence such as \50 is interpreted as a character defined in octal. See the subsection entitled "Non-printing characters" above for further - details of the handling of digits following a backslash. There is no - such problem when named parentheses are used. A back reference to any + details of the handling of digits following a backslash. There is no + such problem when named parentheses are used. A backreference to any subpattern is possible using named parentheses (see below). - Another way of avoiding the ambiguity inherent in the use of digits - following a backslash is to use the \g escape sequence. This escape + Another way of avoiding the ambiguity inherent in the use of digits + following a backslash is to use the \g escape sequence. This escape must be followed by a signed or unsigned number, optionally enclosed in braces. These examples are all identical: @@ -7653,46 +7654,46 @@ BACK REFERENCES (ring), \g1 (ring), \g{1} - An unsigned number specifies an absolute reference without the ambigu- + An unsigned number specifies an absolute reference without the ambigu- ity that is present in the older syntax. It is also useful when literal - digits follow the reference. A signed number is a relative reference. + digits follow the reference. A signed number is a relative reference. Consider this example: (abc(def)ghi)\g{-1} The sequence \g{-1} is a reference to the most recently started captur- ing subpattern before \g, that is, is it equivalent to \2 in this exam- - ple. Similarly, \g{-2} would be equivalent to \1. The use of relative - references can be helpful in long patterns, and also in patterns that - are created by joining together fragments that contain references + ple. Similarly, \g{-2} would be equivalent to \1. The use of relative + references can be helpful in long patterns, and also in patterns that + are created by joining together fragments that contain references within themselves. - The sequence \g{+1} is a reference to the next capturing subpattern. - This kind of forward reference can be useful it patterns that repeat. + The sequence \g{+1} is a reference to the next capturing subpattern. + This kind of forward reference can be useful it patterns that repeat. Perl does not support the use of + in this way. - A back reference matches whatever actually matched the capturing sub- - pattern in the current subject string, rather than anything matching - the subpattern itself (see "Subpatterns as subroutines" below for a way - of doing that). So the pattern + A backreference matches whatever actually matched the capturing subpat- + tern in the current subject string, rather than anything matching the + subpattern itself (see "Subpatterns as subroutines" below for a way of + doing that). So the pattern (sens|respons)e and \1ibility - matches "sense and sensibility" and "response and responsibility", but - not "sense and responsibility". If caseful matching is in force at the - time of the back reference, the case of letters is relevant. For exam- + matches "sense and sensibility" and "response and responsibility", but + not "sense and responsibility". If caseful matching is in force at the + time of the backreference, the case of letters is relevant. For exam- ple, ((?i)rah)\s+\1 - matches "rah rah" and "RAH RAH", but not "RAH rah", even though the + matches "rah rah" and "RAH RAH", but not "RAH rah", even though the original capturing subpattern is matched caselessly. - There are several different ways of writing back references to named - subpatterns. The .NET syntax \k{name} and the Perl syntax \k or - \k'name' are supported, as is the Python syntax (?P=name). Perl 5.10's - unified back reference syntax, in which \g can be used for both numeric - and named references, is also supported. We could rewrite the above + There are several different ways of writing backreferences to named + subpatterns. The .NET syntax \k{name} and the Perl syntax \k or + \k'name' are supported, as is the Python syntax (?P=name). Perl 5.10's + unified backreference syntax, in which \g can be used for both numeric + and named references, is also supported. We could rewrite the above example in any of the following ways: (?(?i)rah)\s+\k @@ -7700,96 +7701,96 @@ BACK REFERENCES (?P(?i)rah)\s+(?P=p1) (?(?i)rah)\s+\g{p1} - A subpattern that is referenced by name may appear in the pattern + A subpattern that is referenced by name may appear in the pattern before or after the reference. - There may be more than one back reference to the same subpattern. If a - subpattern has not actually been used in a particular match, any back + There may be more than one backreference to the same subpattern. If a + subpattern has not actually been used in a particular match, any back- references to it always fail by default. For example, the pattern (a|(bc))\2 - always fails if it starts to match "a" rather than "bc". However, if - the PCRE2_MATCH_UNSET_BACKREF option is set at compile time, a back - reference to an unset value matches an empty string. + always fails if it starts to match "a" rather than "bc". However, if + the PCRE2_MATCH_UNSET_BACKREF option is set at compile time, a backref- + erence to an unset value matches an empty string. - Because there may be many capturing parentheses in a pattern, all dig- - its following a backslash are taken as part of a potential back refer- - ence number. If the pattern continues with a digit character, some - delimiter must be used to terminate the back reference. If the - PCRE2_EXTENDED option is set, this can be white space. Otherwise, the + Because there may be many capturing parentheses in a pattern, all dig- + its following a backslash are taken as part of a potential backrefer- + ence number. If the pattern continues with a digit character, some + delimiter must be used to terminate the backreference. If the + PCRE2_EXTENDED option is set, this can be white space. Otherwise, the \g{ syntax or an empty comment (see "Comments" below) can be used. - Recursive back references + Recursive backreferences - A back reference that occurs inside the parentheses to which it refers - fails when the subpattern is first used, so, for example, (a\1) never - matches. However, such references can be useful inside repeated sub- + A backreference that occurs inside the parentheses to which it refers + fails when the subpattern is first used, so, for example, (a\1) never + matches. However, such references can be useful inside repeated sub- patterns. For example, the pattern (a|b\1)+ matches any number of "a"s and also "aba", "ababbaa" etc. At each iter- - ation of the subpattern, the back reference matches the character - string corresponding to the previous iteration. In order for this to - work, the pattern must be such that the first iteration does not need - to match the back reference. This can be done using alternation, as in - the example above, or by a quantifier with a minimum of zero. + ation of the subpattern, the backreference matches the character string + corresponding to the previous iteration. In order for this to work, the + pattern must be such that the first iteration does not need to match + the backreference. This can be done using alternation, as in the exam- + ple above, or by a quantifier with a minimum of zero. - Back references of this type cause the group that they reference to be - treated as an atomic group. Once the whole group has been matched, a - subsequent matching failure cannot cause backtracking into the middle + backreferences of this type cause the group that they reference to be + treated as an atomic group. Once the whole group has been matched, a + subsequent matching failure cannot cause backtracking into the middle of the group. ASSERTIONS - An assertion is a test on the characters following or preceding the + An assertion is a test on the characters following or preceding the current matching point that does not consume any characters. The simple - assertions coded as \b, \B, \A, \G, \Z, \z, ^ and $ are described + assertions coded as \b, \B, \A, \G, \Z, \z, ^ and $ are described above. - More complicated assertions are coded as subpatterns. There are two - kinds: those that look ahead of the current position in the subject - string, and those that look behind it, and in each case an assertion - may be positive (must succeed for matching to continue) or negative + More complicated assertions are coded as subpatterns. There are two + kinds: those that look ahead of the current position in the subject + string, and those that look behind it, and in each case an assertion + may be positive (must succeed for matching to continue) or negative (must not succeed for matching to continue). An assertion subpattern is - matched in the normal way, except that, when matching continues after- - wards, the matching position in the subject string is as it was at the + matched in the normal way, except that, when matching continues after- + wards, the matching position in the subject string is as it was at the start of the assertion. - Assertion subpatterns are not capturing subpatterns. If an assertion - contains capturing subpatterns within it, these are counted for the - purposes of numbering the capturing subpatterns in the whole pattern. - However, substring capturing is carried out only for positive asser- + Assertion subpatterns are not capturing subpatterns. If an assertion + contains capturing subpatterns within it, these are counted for the + purposes of numbering the capturing subpatterns in the whole pattern. + However, substring capturing is carried out only for positive asser- tions that succeed, that is, one of their branches matches, so matching - continues after the assertion. If all branches of a positive assertion + continues after the assertion. If all branches of a positive assertion fail to match, nothing is captured, and control is passed to the previ- ous backtracking point. - No capturing is done for a negative assertion unless it is being used - as a condition in a conditional subpattern (see the discussion below). - Matching continues after a non-conditional negative assertion only if + No capturing is done for a negative assertion unless it is being used + as a condition in a conditional subpattern (see the discussion below). + Matching continues after a non-conditional negative assertion only if all its branches fail to match. - For compatibility with Perl, most assertion subpatterns may be - repeated; though it makes no sense to assert the same thing several - times, the side effect of capturing parentheses may occasionally be - useful. However, an assertion that forms the condition for a condi- - tional subpattern may not be quantified. In practice, for other asser- + For compatibility with Perl, most assertion subpatterns may be + repeated; though it makes no sense to assert the same thing several + times, the side effect of capturing parentheses may occasionally be + useful. However, an assertion that forms the condition for a condi- + tional subpattern may not be quantified. In practice, for other asser- tions, there only three cases: - (1) If the quantifier is {0}, the assertion is never obeyed during - matching. However, it may contain internal capturing parenthesized + (1) If the quantifier is {0}, the assertion is never obeyed during + matching. However, it may contain internal capturing parenthesized groups that are called from elsewhere via the subroutine mechanism. - (2) If quantifier is {0,n} where n is greater than zero, it is treated - as if it were {0,1}. At run time, the rest of the pattern match is + (2) If quantifier is {0,n} where n is greater than zero, it is treated + as if it were {0,1}. At run time, the rest of the pattern match is tried with and without the assertion, the order depending on the greed- iness of the quantifier. - (3) If the minimum repetition is greater than zero, the quantifier is - ignored. The assertion is obeyed just once when encountered during + (3) If the minimum repetition is greater than zero, the quantifier is + ignored. The assertion is obeyed just once when encountered during matching. Lookahead assertions @@ -7799,38 +7800,38 @@ ASSERTIONS \w+(?=;) - matches a word followed by a semicolon, but does not include the semi- + matches a word followed by a semicolon, but does not include the semi- colon in the match, and foo(?!bar) - matches any occurrence of "foo" that is not followed by "bar". Note + matches any occurrence of "foo" that is not followed by "bar". Note that the apparently similar pattern (?!foo)bar - does not find an occurrence of "bar" that is preceded by something - other than "foo"; it finds any occurrence of "bar" whatsoever, because + does not find an occurrence of "bar" that is preceded by something + other than "foo"; it finds any occurrence of "bar" whatsoever, because the assertion (?!foo) is always true when the next three characters are "bar". A lookbehind assertion is needed to achieve the other effect. If you want to force a matching failure at some point in a pattern, the - most convenient way to do it is with (?!) because an empty string - always matches, so an assertion that requires there not to be an empty + most convenient way to do it is with (?!) because an empty string + always matches, so an assertion that requires there not to be an empty string must always fail. The backtracking control verb (*FAIL) or (*F) is a synonym for (?!). Lookbehind assertions - Lookbehind assertions start with (?<= for positive assertions and (?)...) or (?('name')...) to test for a - used subpattern by name. For compatibility with earlier versions of - PCRE1, which had this facility before Perl, the syntax (?(name)...) is - also recognized. Note, however, that undelimited names consisting of - the letter R followed by digits are ambiguous (see the following sec- + Perl uses the syntax (?()...) or (?('name')...) to test for a + used subpattern by name. For compatibility with earlier versions of + PCRE1, which had this facility before Perl, the syntax (?(name)...) is + also recognized. Note, however, that undelimited names consisting of + the letter R followed by digits are ambiguous (see the following sec- tion). Rewriting the above example to use a named subpattern gives this: (? \( )? [^()]+ (?() \) ) - If the name used in a condition of this kind is a duplicate, the test - is applied to all subpatterns of the same name, and is true if any one + If the name used in a condition of this kind is a duplicate, the test + is applied to all subpatterns of the same name, and is true if any one of them has matched. Checking for pattern recursion - "Recursion" in this sense refers to any subroutine-like call from one - part of the pattern to another, whether or not it is actually recur- - sive. See the sections entitled "Recursive patterns" and "Subpatterns + "Recursion" in this sense refers to any subroutine-like call from one + part of the pattern to another, whether or not it is actually recur- + sive. See the sections entitled "Recursive patterns" and "Subpatterns as subroutines" below for details of recursion and subpattern calls. - If a condition is the string (R), and there is no subpattern with the - name R, the condition is true if matching is currently in a recursion - or subroutine call to the whole pattern or any subpattern. If digits - follow the letter R, and there is no subpattern with that name, the + If a condition is the string (R), and there is no subpattern with the + name R, the condition is true if matching is currently in a recursion + or subroutine call to the whole pattern or any subpattern. If digits + follow the letter R, and there is no subpattern with that name, the condition is true if the most recent call is into a subpattern with the - given number, which must exist somewhere in the overall pattern. This + given number, which must exist somewhere in the overall pattern. This is a contrived example that is equivalent to a+b: ((?(R1)a+|(?1)b)) - However, in both cases, if there is a subpattern with a matching name, - the condition tests for its being set, as described in the section - above, instead of testing for recursion. For example, creating a group - with the name R1 by adding (?) to the above pattern completely + However, in both cases, if there is a subpattern with a matching name, + the condition tests for its being set, as described in the section + above, instead of testing for recursion. For example, creating a group + with the name R1 by adding (?) to the above pattern completely changes its meaning. If a name preceded by ampersand follows the letter R, for example: @@ -8057,7 +8058,7 @@ CONDITIONAL SUBPATTERNS of that name (which must exist within the pattern). This condition does not check the entire recursion stack. It tests only - the current level. If the name used in a condition of this kind is a + the current level. If the name used in a condition of this kind is a duplicate, the test is applied to all subpatterns of the same name, and is true if any one of them is the most recent recursion. @@ -8066,10 +8067,10 @@ CONDITIONAL SUBPATTERNS Defining subpatterns for use by reference only If the condition is the string (DEFINE), the condition is always false, - even if there is a group with the name DEFINE. In this case, there may + even if there is a group with the name DEFINE. In this case, there may be only one alternative in the subpattern. It is always skipped if con- - trol reaches this point in the pattern; the idea of DEFINE is that it - can be used to define subroutines that can be referenced from else- + trol reaches this point in the pattern; the idea of DEFINE is that it + can be used to define subroutines that can be referenced from else- where. (The use of subroutines is described below.) For example, a pat- tern to match an IPv4 address such as "192.168.23.245" could be written like this (ignore white space and line breaks): @@ -8077,97 +8078,97 @@ CONDITIONAL SUBPATTERNS (?(DEFINE) (? 2[0-4]\d | 25[0-5] | 1\d\d | [1-9]?\d) ) \b (?&byte) (\.(?&byte)){3} \b - The first part of the pattern is a DEFINE group inside which a another - group named "byte" is defined. This matches an individual component of - an IPv4 address (a number less than 256). When matching takes place, - this part of the pattern is skipped because DEFINE acts like a false - condition. The rest of the pattern uses references to the named group - to match the four dot-separated components of an IPv4 address, insist- + The first part of the pattern is a DEFINE group inside which a another + group named "byte" is defined. This matches an individual component of + an IPv4 address (a number less than 256). When matching takes place, + this part of the pattern is skipped because DEFINE acts like a false + condition. The rest of the pattern uses references to the named group + to match the four dot-separated components of an IPv4 address, insist- ing on a word boundary at each end. Checking the PCRE2 version - Programs that link with a PCRE2 library can check the version by call- - ing pcre2_config() with appropriate arguments. Users of applications - that do not have access to the underlying code cannot do this. A spe- - cial "condition" called VERSION exists to allow such users to discover + Programs that link with a PCRE2 library can check the version by call- + ing pcre2_config() with appropriate arguments. Users of applications + that do not have access to the underlying code cannot do this. A spe- + cial "condition" called VERSION exists to allow such users to discover which version of PCRE2 they are dealing with by using this condition to - match a string such as "yesno". VERSION must be followed either by "=" + match a string such as "yesno". VERSION must be followed either by "=" or ">=" and a version number. For example: (?(VERSION>=10.4)yes|no) - This pattern matches "yes" if the PCRE2 version is greater or equal to - 10.4, or "no" otherwise. The fractional part of the version number may + This pattern matches "yes" if the PCRE2 version is greater or equal to + 10.4, or "no" otherwise. The fractional part of the version number may not contain more than two digits. Assertion conditions - If the condition is not in any of the above formats, it must be an - assertion. This may be a positive or negative lookahead or lookbehind - assertion. Consider this pattern, again containing non-significant + If the condition is not in any of the above formats, it must be an + assertion. This may be a positive or negative lookahead or lookbehind + assertion. Consider this pattern, again containing non-significant white space, and with the two alternatives on the second line: (?(?=[^a-z]*[a-z]) \d{2}-[a-z]{3}-\d{2} | \d{2}-\d{2}-\d{2} ) - The condition is a positive lookahead assertion that matches an - optional sequence of non-letters followed by a letter. In other words, - it tests for the presence of at least one letter in the subject. If a - letter is found, the subject is matched against the first alternative; - otherwise it is matched against the second. This pattern matches - strings in one of the two forms dd-aaa-dd or dd-dd-dd, where aaa are + The condition is a positive lookahead assertion that matches an + optional sequence of non-letters followed by a letter. In other words, + it tests for the presence of at least one letter in the subject. If a + letter is found, the subject is matched against the first alternative; + otherwise it is matched against the second. This pattern matches + strings in one of the two forms dd-aaa-dd or dd-dd-dd, where aaa are letters and dd are digits. - When an assertion that is a condition contains capturing subpatterns, - any capturing that occurs in a matching branch is retained afterwards, + When an assertion that is a condition contains capturing subpatterns, + any capturing that occurs in a matching branch is retained afterwards, for both positive and negative assertions, because matching always con- tinues after the assertion, whether it succeeds or fails. (Compare non- - conditional assertions, when captures are retained only for positive + conditional assertions, when captures are retained only for positive assertions that succeed.) COMMENTS There are two ways of including comments in patterns that are processed - by PCRE2. In both cases, the start of the comment must not be in a - character class, nor in the middle of any other sequence of related - characters such as (?: or a subpattern name or number. The characters + by PCRE2. In both cases, the start of the comment must not be in a + character class, nor in the middle of any other sequence of related + characters such as (?: or a subpattern name or number. The characters that make up a comment play no part in the pattern matching. - The sequence (?# marks the start of a comment that continues up to the - next closing parenthesis. Nested parentheses are not permitted. If the - PCRE2_EXTENDED option is set, an unescaped # character also introduces - a comment, which in this case continues to immediately after the next - newline character or character sequence in the pattern. Which charac- - ters are interpreted as newlines is controlled by an option passed to - the compiling function or by a special sequence at the start of the - pattern, as described in the section entitled "Newline conventions" - above. Note that the end of this type of comment is a literal newline - sequence in the pattern; escape sequences that happen to represent a - newline do not count. For example, consider this pattern when - PCRE2_EXTENDED is set, and the default newline convention (a single + The sequence (?# marks the start of a comment that continues up to the + next closing parenthesis. Nested parentheses are not permitted. If the + PCRE2_EXTENDED option is set, an unescaped # character also introduces + a comment, which in this case continues to immediately after the next + newline character or character sequence in the pattern. Which charac- + ters are interpreted as newlines is controlled by an option passed to + the compiling function or by a special sequence at the start of the + pattern, as described in the section entitled "Newline conventions" + above. Note that the end of this type of comment is a literal newline + sequence in the pattern; escape sequences that happen to represent a + newline do not count. For example, consider this pattern when + PCRE2_EXTENDED is set, and the default newline convention (a single linefeed character) is in force: abc #comment \n still comment - On encountering the # character, pcre2_compile() skips along, looking - for a newline in the pattern. The sequence \n is still literal at this - stage, so it does not terminate the comment. Only an actual character + On encountering the # character, pcre2_compile() skips along, looking + for a newline in the pattern. The sequence \n is still literal at this + stage, so it does not terminate the comment. Only an actual character with the code value 0x0a (the default newline) does so. RECURSIVE PATTERNS - Consider the problem of matching a string in parentheses, allowing for - unlimited nested parentheses. Without the use of recursion, the best - that can be done is to use a pattern that matches up to some fixed - depth of nesting. It is not possible to handle an arbitrary nesting + Consider the problem of matching a string in parentheses, allowing for + unlimited nested parentheses. Without the use of recursion, the best + that can be done is to use a pattern that matches up to some fixed + depth of nesting. It is not possible to handle an arbitrary nesting depth. For some time, Perl has provided a facility that allows regular expres- - sions to recurse (amongst other things). It does this by interpolating - Perl code in the expression at run time, and the code can refer to the + sions to recurse (amongst other things). It does this by interpolating + Perl code in the expression at run time, and the code can refer to the expression itself. A Perl pattern using code interpolation to solve the parentheses problem can be created like this: @@ -8177,166 +8178,165 @@ RECURSIVE PATTERNS refers recursively to the pattern in which it appears. Obviously, PCRE2 cannot support the interpolation of Perl code. - Instead, it supports special syntax for recursion of the entire pat- + Instead, it supports special syntax for recursion of the entire pat- tern, and also for individual subpattern recursion. After its introduc- - tion in PCRE1 and Python, this kind of recursion was subsequently + tion in PCRE1 and Python, this kind of recursion was subsequently introduced into Perl at release 5.10. - A special item that consists of (? followed by a number greater than - zero and a closing parenthesis is a recursive subroutine call of the - subpattern of the given number, provided that it occurs inside that - subpattern. (If not, it is a non-recursive subroutine call, which is - described in the next section.) The special item (?R) or (?0) is a + A special item that consists of (? followed by a number greater than + zero and a closing parenthesis is a recursive subroutine call of the + subpattern of the given number, provided that it occurs inside that + subpattern. (If not, it is a non-recursive subroutine call, which is + described in the next section.) The special item (?R) or (?0) is a recursive call of the entire regular expression. - This PCRE2 pattern solves the nested parentheses problem (assume the + This PCRE2 pattern solves the nested parentheses problem (assume the PCRE2_EXTENDED option is set so that white space is ignored): \( ( [^()]++ | (?R) )* \) - First it matches an opening parenthesis. Then it matches any number of - substrings which can either be a sequence of non-parentheses, or a - recursive match of the pattern itself (that is, a correctly parenthe- + First it matches an opening parenthesis. Then it matches any number of + substrings which can either be a sequence of non-parentheses, or a + recursive match of the pattern itself (that is, a correctly parenthe- sized substring). Finally there is a closing parenthesis. Note the use of a possessive quantifier to avoid backtracking into sequences of non- parentheses. - If this were part of a larger pattern, you would not want to recurse + If this were part of a larger pattern, you would not want to recurse the entire pattern, so instead you could use this: ( \( ( [^()]++ | (?1) )* \) ) - We have put the pattern into parentheses, and caused the recursion to + We have put the pattern into parentheses, and caused the recursion to refer to them instead of the whole pattern. - In a larger pattern, keeping track of parenthesis numbers can be - tricky. This is made easier by the use of relative references. Instead + In a larger pattern, keeping track of parenthesis numbers can be + tricky. This is made easier by the use of relative references. Instead of (?1) in the pattern above you can write (?-2) to refer to the second - most recently opened parentheses preceding the recursion. In other - words, a negative number counts capturing parentheses leftwards from + most recently opened parentheses preceding the recursion. In other + words, a negative number counts capturing parentheses leftwards from the point at which it is encountered. Be aware however, that if duplicate subpattern numbers are in use, rel- - ative references refer to the earliest subpattern with the appropriate + ative references refer to the earliest subpattern with the appropriate number. Consider, for example: (?|(a)|(b)) (c) (?-2) - The first two capturing groups (a) and (b) are both numbered 1, and - group (c) is number 2. When the reference (?-2) is encountered, the + The first two capturing groups (a) and (b) are both numbered 1, and + group (c) is number 2. When the reference (?-2) is encountered, the second most recently opened parentheses has the number 1, but it is the - first such group (the (a) group) to which the recursion refers. This - would be the same if an absolute reference (?1) was used. In other - words, relative references are just a shorthand for computing a group + first such group (the (a) group) to which the recursion refers. This + would be the same if an absolute reference (?1) was used. In other + words, relative references are just a shorthand for computing a group number. - It is also possible to refer to subsequently opened parentheses, by - writing references such as (?+2). However, these cannot be recursive - because the reference is not inside the parentheses that are refer- - enced. They are always non-recursive subroutine calls, as described in + It is also possible to refer to subsequently opened parentheses, by + writing references such as (?+2). However, these cannot be recursive + because the reference is not inside the parentheses that are refer- + enced. They are always non-recursive subroutine calls, as described in the next section. - An alternative approach is to use named parentheses. The Perl syntax - for this is (?&name); PCRE1's earlier syntax (?P>name) is also sup- + An alternative approach is to use named parentheses. The Perl syntax + for this is (?&name); PCRE1's earlier syntax (?P>name) is also sup- ported. We could rewrite the above example as follows: (? \( ( [^()]++ | (?&pn) )* \) ) - If there is more than one subpattern with the same name, the earliest + If there is more than one subpattern with the same name, the earliest one is used. The example pattern that we have been looking at contains nested unlim- - ited repeats, and so the use of a possessive quantifier for matching - strings of non-parentheses is important when applying the pattern to + ited repeats, and so the use of a possessive quantifier for matching + strings of non-parentheses is important when applying the pattern to strings that do not match. For example, when this pattern is applied to (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() - it yields "no match" quickly. However, if a possessive quantifier is - not used, the match runs for a very long time indeed because there are - so many different ways the + and * repeats can carve up the subject, + it yields "no match" quickly. However, if a possessive quantifier is + not used, the match runs for a very long time indeed because there are + so many different ways the + and * repeats can carve up the subject, and all have to be tested before failure can be reported. - At the end of a match, the values of capturing parentheses are those - from the outermost level. If you want to obtain intermediate values, a + At the end of a match, the values of capturing parentheses are those + from the outermost level. If you want to obtain intermediate values, a callout function can be used (see below and the pcre2callout documenta- tion). If the pattern above is matched against (ab(cd)ef) - the value for the inner capturing parentheses (numbered 2) is "ef", - which is the last value taken on at the top level. If a capturing sub- - pattern is not matched at the top level, its final captured value is - unset, even if it was (temporarily) set at a deeper level during the + the value for the inner capturing parentheses (numbered 2) is "ef", + which is the last value taken on at the top level. If a capturing sub- + pattern is not matched at the top level, its final captured value is + unset, even if it was (temporarily) set at a deeper level during the matching process. - Do not confuse the (?R) item with the condition (R), which tests for - recursion. Consider this pattern, which matches text in angle brack- - ets, allowing for arbitrary nesting. Only digits are allowed in nested - brackets (that is, when recursing), whereas any characters are permit- + Do not confuse the (?R) item with the condition (R), which tests for + recursion. Consider this pattern, which matches text in angle brack- + ets, allowing for arbitrary nesting. Only digits are allowed in nested + brackets (that is, when recursing), whereas any characters are permit- ted at the outer level. < (?: (?(R) \d++ | [^<>]*+) | (?R)) * > - In this pattern, (?(R) is the start of a conditional subpattern, with - two different alternatives for the recursive and non-recursive cases. + In this pattern, (?(R) is the start of a conditional subpattern, with + two different alternatives for the recursive and non-recursive cases. The (?R) item is the actual recursive call. Differences in recursion processing between PCRE2 and Perl Some former differences between PCRE2 and Perl no longer exist. - Before release 10.30, recursion processing in PCRE2 differed from Perl - in that a recursive subpattern call was always treated as an atomic - group. That is, once it had matched some of the subject string, it was - never re-entered, even if it contained untried alternatives and there - was a subsequent matching failure. (Historical note: PCRE implemented + Before release 10.30, recursion processing in PCRE2 differed from Perl + in that a recursive subpattern call was always treated as an atomic + group. That is, once it had matched some of the subject string, it was + never re-entered, even if it contained untried alternatives and there + was a subsequent matching failure. (Historical note: PCRE implemented recursion before Perl did.) - Starting with release 10.30, recursive subroutine calls are no longer + Starting with release 10.30, recursive subroutine calls are no longer treated as atomic. That is, they can be re-entered to try unused alter- - natives if there is a matching failure later in the pattern. This is - now compatible with the way Perl works. If you want a subroutine call + natives if there is a matching failure later in the pattern. This is + now compatible with the way Perl works. If you want a subroutine call to be atomic, you must explicitly enclose it in an atomic group. - Supporting backtracking into recursions simplifies certain types of + Supporting backtracking into recursions simplifies certain types of recursive pattern. For example, this pattern matches palindromic strings: ^((.)(?1)\2|.?)$ - The second branch in the group matches a single central character in - the palindrome when there are an odd number of characters, or nothing - when there are an even number of characters, but in order to work it - has to be able to try the second case when the rest of the pattern + The second branch in the group matches a single central character in + the palindrome when there are an odd number of characters, or nothing + when there are an even number of characters, but in order to work it + has to be able to try the second case when the rest of the pattern match fails. If you want to match typical palindromic phrases, the pat- - tern has to ignore all non-word characters, which can be done like + tern has to ignore all non-word characters, which can be done like this: ^\W*+((.)\W*+(?1)\W*+\2|\W*+.?)\W*+$ - If run with the PCRE2_CASELESS option, this pattern matches phrases - such as "A man, a plan, a canal: Panama!". Note the use of the posses- - sive quantifier *+ to avoid backtracking into sequences of non-word + If run with the PCRE2_CASELESS option, this pattern matches phrases + such as "A man, a plan, a canal: Panama!". Note the use of the posses- + sive quantifier *+ to avoid backtracking into sequences of non-word characters. Without this, PCRE2 takes a great deal longer (ten times or - more) to match typical phrases, and Perl takes so long that you think + more) to match typical phrases, and Perl takes so long that you think it has gone into a loop. - Another way in which PCRE2 and Perl used to differ in their recursion - processing is in the handling of captured values. Formerly in Perl, - when a subpattern was called recursively or as a subpattern (see the - next section), it had no access to any values that were captured out- - side the recursion, whereas in PCRE2 these values can be referenced. + Another way in which PCRE2 and Perl used to differ in their recursion + processing is in the handling of captured values. Formerly in Perl, + when a subpattern was called recursively or as a subpattern (see the + next section), it had no access to any values that were captured out- + side the recursion, whereas in PCRE2 these values can be referenced. Consider this pattern: ^(.)(\1|a(?2)) - This pattern matches "bab". The first capturing parentheses match "b", - then in the second group, when the back reference \1 fails to match - "b", the second alternative matches "a" and then recurses. In the - recursion, \1 does now match "b" and so the whole match succeeds. This - match used to fail in Perl, but in later versions (I tried 5.024) it - now works. + This pattern matches "bab". The first capturing parentheses match "b", + then in the second group, when the backreference \1 fails to match "b", + the second alternative matches "a" and then recurses. In the recursion, + \1 does now match "b" and so the whole match succeeds. This match used + to fail in Perl, but in later versions (I tried 5.024) it now works. SUBPATTERNS AS SUBROUTINES @@ -8396,7 +8396,7 @@ ONIGURUMA SUBROUTINE SYNTAX (abc)(?i:\g<-1>) Note that \g{...} (Perl syntax) and \g<...> (Oniguruma syntax) are not - synonymous. The former is a back reference; the latter is a subroutine + synonymous. The former is a backreference; the latter is a subroutine call. @@ -9246,54 +9246,53 @@ COMPILING A PATTERN for matching, the nmatch and pmatch arguments are ignored, and no cap- tured strings are returned. Versions of the PCRE library prior to 10.22 used to set the PCRE2_NO_AUTO_CAPTURE compile option, but this no - longer happens because it disables the use of back references. + longer happens because it disables the use of backreferences. REG_PEND If this option is set, the reg_endp field in the preg structure (which has the type const char *) must be set to point to the character beyond the end of the pattern before calling regcomp(). The pattern itself may - now contain binary zeroes, which are treated as data characters. With- - out REG_PEND, a binary zero terminates the pattern and the re_endp - field is ignored. This is a GNU extension to the POSIX standard and - should be used with caution in software intended to be portable to - other systems. + now contain binary zeros, which are treated as data characters. Without + REG_PEND, a binary zero terminates the pattern and the re_endp field is + ignored. This is a GNU extension to the POSIX standard and should be + used with caution in software intended to be portable to other systems. REG_UCP - The PCRE2_UCP option is set when the regular expression is passed for - compilation to the native function. This causes PCRE2 to use Unicode - properties when matchine \d, \w, etc., instead of just recognizing + The PCRE2_UCP option is set when the regular expression is passed for + compilation to the native function. This causes PCRE2 to use Unicode + properties when matchine \d, \w, etc., instead of just recognizing ASCII values. Note that REG_UCP is not part of the POSIX standard. REG_UNGREEDY - The PCRE2_UNGREEDY option is set when the regular expression is passed - for compilation to the native function. Note that REG_UNGREEDY is not + The PCRE2_UNGREEDY option is set when the regular expression is passed + for compilation to the native function. Note that REG_UNGREEDY is not part of the POSIX standard. REG_UTF - The PCRE2_UTF option is set when the regular expression is passed for - compilation to the native function. This causes the pattern itself and - all data strings used for matching it to be treated as UTF-8 strings. + The PCRE2_UTF option is set when the regular expression is passed for + compilation to the native function. This causes the pattern itself and + all data strings used for matching it to be treated as UTF-8 strings. Note that REG_UTF is not part of the POSIX standard. - In the absence of these flags, no options are passed to the native - function. This means the the regex is compiled with PCRE2 default - semantics. In particular, the way it handles newline characters in the - subject string is the Perl way, not the POSIX way. Note that setting + In the absence of these flags, no options are passed to the native + function. This means the the regex is compiled with PCRE2 default + semantics. In particular, the way it handles newline characters in the + subject string is the Perl way, not the POSIX way. Note that setting PCRE2_MULTILINE has only some of the effects specified for REG_NEWLINE. - It does not affect the way newlines are matched by the dot metacharac- + It does not affect the way newlines are matched by the dot metacharac- ter (they are not) or by a negative class such as [^a] (they are). - The yield of regcomp() is zero on success, and non-zero otherwise. The - preg structure is filled in on success, and one other member of the - structure (as well as re_endp) is public: re_nsub contains the number + The yield of regcomp() is zero on success, and non-zero otherwise. The + preg structure is filled in on success, and one other member of the + structure (as well as re_endp) is public: re_nsub contains the number of capturing subpatterns in the regular expression. Various error codes are defined in the header file. - NOTE: If the yield of regcomp() is non-zero, you must not attempt to + NOTE: If the yield of regcomp() is non-zero, you must not attempt to use the contents of the preg structure. If, for example, you pass it to regexec(), the result is undefined and your program is likely to crash. @@ -9301,9 +9300,9 @@ COMPILING A PATTERN MATCHING NEWLINE CHARACTERS This area is not simple, because POSIX and Perl take different views of - things. It is not possible to get PCRE2 to obey POSIX semantics, but + things. It is not possible to get PCRE2 to obey POSIX semantics, but then PCRE2 was never intended to be a POSIX engine. The following table - lists the different possibilities for matching newline characters in + lists the different possibilities for matching newline characters in Perl and PCRE2: Default Change with @@ -9324,25 +9323,25 @@ MATCHING NEWLINE CHARACTERS $ matches \n in middle no REG_NEWLINE ^ matches \n in middle no REG_NEWLINE - This behaviour is not what happens when PCRE2 is called via its POSIX - API. By default, PCRE2's behaviour is the same as Perl's, except that - there is no equivalent for PCRE2_DOLLAR_ENDONLY in Perl. In both PCRE2 + This behaviour is not what happens when PCRE2 is called via its POSIX + API. By default, PCRE2's behaviour is the same as Perl's, except that + there is no equivalent for PCRE2_DOLLAR_ENDONLY in Perl. In both PCRE2 and Perl, there is no way to stop newline from matching [^a]. - Default POSIX newline handling can be obtained by setting PCRE2_DOTALL - and PCRE2_DOLLAR_ENDONLY when calling pcre2_compile() directly, but - there is no way to make PCRE2 behave exactly as for the REG_NEWLINE - action. When using the POSIX API, passing REG_NEWLINE to PCRE2's reg- + Default POSIX newline handling can be obtained by setting PCRE2_DOTALL + and PCRE2_DOLLAR_ENDONLY when calling pcre2_compile() directly, but + there is no way to make PCRE2 behave exactly as for the REG_NEWLINE + action. When using the POSIX API, passing REG_NEWLINE to PCRE2's reg- comp() function causes PCRE2_MULTILINE to be passed to pcre2_compile(), - and REG_DOTALL passes PCRE2_DOTALL. There is no way to pass PCRE2_DOL- + and REG_DOTALL passes PCRE2_DOTALL. There is no way to pass PCRE2_DOL- LAR_ENDONLY. MATCHING A PATTERN - The function regexec() is called to match a compiled pattern preg - against a given string, which is by default terminated by a zero byte - (but see REG_STARTEND below), subject to the options in eflags. These + The function regexec() is called to match a compiled pattern preg + against a given string, which is by default terminated by a zero byte + (but see REG_STARTEND below), subject to the options in eflags. These can be: REG_NOTBOL @@ -9352,9 +9351,9 @@ MATCHING A PATTERN REG_NOTEMPTY - The PCRE2_NOTEMPTY option is set when calling the underlying PCRE2 - matching function. Note that REG_NOTEMPTY is not part of the POSIX - standard. However, setting this option can give more POSIX-like behav- + The PCRE2_NOTEMPTY option is set when calling the underlying PCRE2 + matching function. Note that REG_NOTEMPTY is not part of the POSIX + standard. However, setting this option can give more POSIX-like behav- iour in some situations. REG_NOTEOL @@ -9364,66 +9363,66 @@ MATCHING A PATTERN REG_STARTEND - When this option is set, the subject string is starts at string + - pmatch[0].rm_so and ends at string + pmatch[0].rm_eo, which should - point to the first character beyond the string. There may be binary - zeroes within the subject string, and indeed, using REG_STARTEND is the + When this option is set, the subject string starts at string + + pmatch[0].rm_so and ends at string + pmatch[0].rm_eo, which should + point to the first character beyond the string. There may be binary + zeros within the subject string, and indeed, using REG_STARTEND is the only way to pass a subject string that contains a binary zero. - Whatever the value of pmatch[0].rm_so, the offsets of the matched - string and any captured substrings are still given relative to the - start of string itself. (Before PCRE2 release 10.30 these were given - relative to string + pmatch[0].rm_so, but this differs from other + Whatever the value of pmatch[0].rm_so, the offsets of the matched + string and any captured substrings are still given relative to the + start of string itself. (Before PCRE2 release 10.30 these were given + relative to string + pmatch[0].rm_so, but this differs from other implementations.) - This is a BSD extension, compatible with but not specified by IEEE - Standard 1003.2 (POSIX.2), and should be used with caution in software - intended to be portable to other systems. Note that a non-zero rm_so - does not imply REG_NOTBOL; REG_STARTEND affects only the location and - length of the string, not how it is matched. Setting REG_STARTEND and - passing pmatch as NULL are mutually exclusive; the error REG_INVARG is + This is a BSD extension, compatible with but not specified by IEEE + Standard 1003.2 (POSIX.2), and should be used with caution in software + intended to be portable to other systems. Note that a non-zero rm_so + does not imply REG_NOTBOL; REG_STARTEND affects only the location and + length of the string, not how it is matched. Setting REG_STARTEND and + passing pmatch as NULL are mutually exclusive; the error REG_INVARG is returned. - If the pattern was compiled with the REG_NOSUB flag, no data about any - matched strings is returned. The nmatch and pmatch arguments of + If the pattern was compiled with the REG_NOSUB flag, no data about any + matched strings is returned. The nmatch and pmatch arguments of regexec() are ignored (except possibly as input for REG_STARTEND). - The value of nmatch may be zero, and the value pmatch may be NULL - (unless REG_STARTEND is set); in both these cases no data about any + The value of nmatch may be zero, and the value pmatch may be NULL + (unless REG_STARTEND is set); in both these cases no data about any matched strings is returned. - Otherwise, the portion of the string that was matched, and also any + Otherwise, the portion of the string that was matched, and also any captured substrings, are returned via the pmatch argument, which points - to an array of nmatch structures of type regmatch_t, containing the - members rm_so and rm_eo. These contain the byte offset to the first + to an array of nmatch structures of type regmatch_t, containing the + members rm_so and rm_eo. These contain the byte offset to the first character of each substring and the offset to the first character after - the end of each substring, respectively. The 0th element of the vector - relates to the entire portion of string that was matched; subsequent + the end of each substring, respectively. The 0th element of the vector + relates to the entire portion of string that was matched; subsequent elements relate to the capturing subpatterns of the regular expression. Unused entries in the array have both structure members set to -1. - A successful match yields a zero return; various error codes are - defined in the header file, of which REG_NOMATCH is the "expected" + A successful match yields a zero return; various error codes are + defined in the header file, of which REG_NOMATCH is the "expected" failure code. ERROR MESSAGES The regerror() function maps a non-zero errorcode from either regcomp() - or regexec() to a printable message. If preg is not NULL, the error + or regexec() to a printable message. If preg is not NULL, the error should have arisen from the use of that structure. A message terminated - by a binary zero is placed in errbuf. If the buffer is too short, only + by a binary zero is placed in errbuf. If the buffer is too short, only the first errbuf_size - 1 characters of the error message are used. The - yield of the function is the size of buffer needed to hold the whole - message, including the terminating zero. This value is greater than + yield of the function is the size of buffer needed to hold the whole + message, including the terminating zero. This value is greater than errbuf_size if the message was truncated. MEMORY USAGE - Compiling a regular expression causes memory to be allocated and asso- - ciated with the preg structure. The function regfree() frees all such - memory, after which preg may no longer be used as a compiled expres- + Compiling a regular expression causes memory to be allocated and asso- + ciated with the preg structure. The function regfree() frees all such + memory, after which preg may no longer be used as a compiled expres- sion. @@ -9995,7 +9994,7 @@ OPTION SETTING one of them may appear. For the first three, d is a decimal number. (*LIMIT_DEPTH=d) set the backtracking limit to d - (*LIMIT_HEAP=d) set the heap size limit to d kilobytes + (*LIMIT_HEAP=d) set the heap size limit to d * 1024 bytes (*LIMIT_MATCH=d) set the match limit to d (*NOTEMPTY) set PCRE2_NOTEMPTY when matching (*NOTEMPTY_ATSTART) set PCRE2_NOTEMPTY_ATSTART when matching @@ -10198,7 +10197,7 @@ UNICODE PROPERTY SUPPORT WIDE CHARACTERS AND UTF MODES - Codepoints less than 256 can be specified in patterns by either braced + Code points less than 256 can be specified in patterns by either braced or unbraced hexadecimal escape sequences (for example, \x{b3} or \xb3). Larger values have to use braced sequences. Unbraced octal code points up to \777 are also recognized; larger ones can be coded using \o{...}. @@ -10251,7 +10250,7 @@ CASE-EQUIVALENCE IN UTF MODES except for characters whose code points are less than 128 and that have at most two case-equivalent values. For these, a direct table lookup is used for speed. A few Unicode characters such as Greek sigma have more - than two codepoints that are case-equivalent, and these are treated as + than two code points that are case-equivalent, and these are treated as such. diff --git a/doc/pcre2_compile.3 b/doc/pcre2_compile.3 index 19f35c3..a5e8269 100644 --- a/doc/pcre2_compile.3 +++ b/doc/pcre2_compile.3 @@ -53,7 +53,7 @@ The option bits are: PCRE2_EXTENDED Ignore white space and # comments PCRE2_FIRSTLINE Force matching to be before newline PCRE2_LITERAL Pattern characters are all literal - PCRE2_MATCH_UNSET_BACKREF Match unset back references + PCRE2_MATCH_UNSET_BACKREF Match unset backreferences PCRE2_MULTILINE ^ and $ match newlines within data PCRE2_NEVER_BACKSLASH_C Lock out the use of \eC in patterns PCRE2_NEVER_UCP Lock out PCRE2_UCP, e.g. via (*UCP) diff --git a/doc/pcre2_match.3 b/doc/pcre2_match.3 index 6f7aefb..9d15ec9 100644 --- a/doc/pcre2_match.3 +++ b/doc/pcre2_match.3 @@ -65,7 +65,7 @@ subject that is terminated by a binary zero code unit. The options are: match even if there is a full match .\" JOIN PCRE2_PARTIAL_SOFT Return PCRE2_ERROR_PARTIAL for a partial - match if no full matches are found + match if no full matches are found .sp For details of partial matching, see the .\" HREF diff --git a/doc/pcre2_pattern_info.3 b/doc/pcre2_pattern_info.3 index 64bfc45..01b74a2 100644 --- a/doc/pcre2_pattern_info.3 +++ b/doc/pcre2_pattern_info.3 @@ -24,7 +24,7 @@ request are as follows: .sp PCRE2_INFO_ALLOPTIONS Final options after compiling PCRE2_INFO_ARGOPTIONS Options passed to \fBpcre2_compile()\fP - PCRE2_INFO_BACKREFMAX Number of highest back reference + PCRE2_INFO_BACKREFMAX Number of highest backreference PCRE2_INFO_BSR What \eR matches: PCRE2_BSR_UNICODE: Unicode line endings PCRE2_BSR_ANYCRLF: CR, LF, or CRLF only diff --git a/doc/pcre2_set_compile_extra_options.3 b/doc/pcre2_set_compile_extra_options.3 index 1d73a8f..79f71ce 100644 --- a/doc/pcre2_set_compile_extra_options.3 +++ b/doc/pcre2_set_compile_extra_options.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_MAX_PATTERN_LENGTH 3 "16 June 2017" "PCRE2 10.30" +.TH PCRE2_SET_COMPILE_EXTRA_OPTIONS 3 "16 June 2017" "PCRE2 10.30" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_glob_separator.3 b/doc/pcre2_set_glob_separator.3 index 273b515..5d78c09 100644 --- a/doc/pcre2_set_glob_separator.3 +++ b/doc/pcre2_set_glob_separator.3 @@ -16,7 +16,7 @@ PCRE2 - Perl-compatible regular expressions (revised API) .sp This function is part of an experimental set of pattern conversion functions. It sets the component separator character that is used when converting globs. -The second argument must one of the characters forward slash, backslash, or +The second argument must be one of the characters forward slash, backslash, or dot. The default is backslash when running under Windows, otherwise forward slash. The result of the function is zero for success or PCRE2_ERROR_BADDATA if the second argument is invalid. diff --git a/doc/pcre2_set_heap_limit.3 b/doc/pcre2_set_heap_limit.3 index a99b4ab..7c155a2 100644 --- a/doc/pcre2_set_heap_limit.3 +++ b/doc/pcre2_set_heap_limit.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_DEPTH_LIMIT 3 "11 April 2017" "PCRE2 10.30" +.TH PCRE2_SET_HEAP_LIMIT 3 "11 April 2017" "PCRE2 10.30" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2api.3 b/doc/pcre2api.3 index ed4b3a0..692945e 100644 --- a/doc/pcre2api.3 +++ b/doc/pcre2api.3 @@ -497,10 +497,10 @@ U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS .P Each of the first three conventions is used by at least one operating system as its standard newline sequence. When PCRE2 is built, a default can be specified. -The default default is LF, which is the Unix standard. However, the newline -convention can be changed by an application when calling \fBpcre2_compile()\fP, -or it can be specified by special text at the start of the pattern itself; this -overrides any other settings. See the +If it is not, the default is set to LF, which is the Unix standard. However, +the newline convention can be changed by an application when calling +\fBpcre2_compile()\fP, or it can be specified by special text at the start of +the pattern itself; this overrides any other settings. See the .\" HREF \fBpcre2pattern\fP .\" @@ -885,19 +885,20 @@ offset limit. In other words, whichever limit comes first is used. .B " uint32_t \fIvalue\fP);" .fi .sp -The \fIheap_limit\fP parameter specifies, in units of kilobytes, the maximum -amount of heap memory that \fBpcre2_match()\fP may use to hold backtracking -information when running an interpretive match. This limit also applies to -\fBpcre2_dfa_match()\fP, which may use the heap when processing patterns with a -lot of nested pattern recursion or lookarounds or atomic groups. This limit -does not apply to matching with the JIT optimization, which has its own memory -control arrangements (see the +The \fIheap_limit\fP parameter specifies, in units of kibibytes (1024 bytes), +the maximum amount of heap memory that \fBpcre2_match()\fP may use to hold +backtracking information when running an interpretive match. This limit also +applies to \fBpcre2_dfa_match()\fP, which may use the heap when processing +patterns with a lot of nested pattern recursion or lookarounds or atomic +groups. This limit does not apply to matching with the JIT optimization, which +has its own memory control arrangements (see the .\" HREF \fBpcre2jit\fP .\" documentation for more details). If the limit is reached, the negative error -code PCRE2_ERROR_HEAPLIMIT is returned. The default limit is set when PCRE2 is -built; the default default is very large and is essentially "unlimited". +code PCRE2_ERROR_HEAPLIMIT is returned. The default limit can be set when PCRE2 +is built; if it is not, the default is set very large and is essentially +"unlimited". .P A value for the heap limit may also be supplied by an item at the start of a pattern of the form @@ -975,7 +976,7 @@ The depth limit is not relevant, and is ignored, when matching is done using JIT compiled code. However, it is supported by \fBpcre2_dfa_match()\fP, which uses it to limit the depth of nested internal recursive function calls that implement atomic groups, lookaround assertions, and pattern recursions. This -limits, indirectly, the amount of system stack this is used. It was more useful +limits, indirectly, the amount of system stack that is used. It was more useful in versions before 10.32, when stack memory was used for local workspace vectors for recursive function calls. From version 10.32, only local variables are allocated on the stack and as each call uses only a few hundred bytes, even @@ -989,11 +990,11 @@ using \fBpcre2_dfa_match()\fP, can use a great deal of memory. However, it is probably better to limit heap usage directly by calling \fBpcre2_set_heap_limit()\fP. .P -The default value for the depth limit can be set when PCRE2 is built; the -default default is the same value as the default for the match limit. If the -limit is exceeded, \fBpcre2_match()\fP or \fBpcre2_dfa_match()\fP returns -PCRE2_ERROR_DEPTHLIMIT. A value for the depth limit may also be supplied by an -item at the start of a pattern of the form +The default value for the depth limit can be set when PCRE2 is built; if it is +not, the default is set to the same value as the default for the match limit. +If the limit is exceeded, \fBpcre2_match()\fP or \fBpcre2_dfa_match()\fP +returns PCRE2_ERROR_DEPTHLIMIT. A value for the depth limit may also be +supplied by an item at the start of a pattern of the form .sp (*LIMIT_DEPTH=ddd) .sp @@ -1050,7 +1051,7 @@ given with \fBpcre2_set_depth_limit()\fP above. .sp PCRE2_CONFIG_HEAPLIMIT .sp -The output is a uint32_t integer that gives, in kilobytes, the default limit +The output is a uint32_t integer that gives, in kibibytes, the default limit for the amount of heap memory used by \fBpcre2_match()\fP or \fBpcre2_dfa_match()\fP. Further details are given with \fBpcre2_set_heap_limit()\fP above. @@ -1367,7 +1368,7 @@ If this bit is set, letters in the pattern match both upper and lower case letters in the subject. It is equivalent to Perl's /i option, and it can be changed within a pattern by a (?i) option setting. If PCRE2_UTF is set, Unicode properties are used for all characters with more than one other case, and for -all characters whose code points are greater than U+007f. For lower valued +all characters whose code points are greater than U+007F. For lower valued characters with only one other case, a lookup table is used for speed. When PCRE2_UTF is not set, a lookup table is used for all code points less than 256, and higher code points (available only in 16-bit or 32-bit mode) are treated as @@ -1489,7 +1490,7 @@ error. .sp PCRE2_MATCH_UNSET_BACKREF .sp -If this option is set, a back reference to an unset subpattern group matches an +If this option is set, a backreference to an unset subpattern group matches an empty string (by default this causes the current matching alternative to fail). A pattern such as (\e1)(a) succeeds when this option is set (assuming it can find an "a" in the subject), whereas it fails by default, for Perl @@ -1550,8 +1551,8 @@ If this option is set, it disables the use of numbered capturing parentheses in the pattern. Any opening parenthesis that is not followed by ? behaves as if it were followed by ?: but named parentheses can still be used for capturing (and they acquire numbers in the usual way). This is the same as Perl's /n option. -Note that, when this option is set, references to capturing groups (back -references or recursion/subroutine calls) may only refer to named groups, +Note that, when this option is set, references to capturing groups +(backreferences or recursion/subroutine calls) may only refer to named groups, though the reference can be by name or by number. .sp PCRE2_NO_AUTO_POSSESS @@ -1570,7 +1571,7 @@ If this option is set, it disables an optimization that is applied when .* is the first significant item in a top-level branch of a pattern, and all the other branches also start with .* or with \eA or \eG or ^. The optimization is automatically disabled for .* if it is inside an atomic group or a capturing -group that is the subject of a back reference, or if the pattern contains +group that is the subject of a backreference, or if the pattern contains (*PRUNE) or (*SKIP). When the optimization is not disabled, such a pattern is automatically anchored if PCRE2_DOTALL is set for all the .* items and PCRE2_MULTILINE is not set for any ^ items. Otherwise, the fact that any match @@ -1956,7 +1957,7 @@ following are true: .* is not in an atomic group .\" JOIN .* is not in a capturing group that is the subject - of a back reference + of a backreference PCRE2_DOTALL is in force for .* Neither (*PRUNE) nor (*SKIP) appears in the pattern PCRE2_NO_DOTSTAR_ANCHOR is not set @@ -1966,20 +1967,20 @@ options returned for PCRE2_INFO_ALLOPTIONS. .sp PCRE2_INFO_BACKREFMAX .sp -Return the number of the highest back reference in the pattern. The third +Return the number of the highest backreference in the pattern. The third argument should point to an \fBuint32_t\fP variable. Named subpatterns acquire -numbers as well as names, and these count towards the highest back reference. -Back references such as \e4 or \eg{12} match the captured characters of the +numbers as well as names, and these count towards the highest backreference. +Backreferences such as \e4 or \eg{12} match the captured characters of the given group, but in addition, the check that a capturing group is set in a -conditional subpattern such as (?(3)a|b) is also a back reference. Zero is -returned if there are no back references. +conditional subpattern such as (?(3)a|b) is also a backreference. Zero is +returned if there are no backreferences. .sp PCRE2_INFO_BSR .sp -The output is a uint32_t whose value indicates what character sequences the \eR -escape sequence matches. A value of PCRE2_BSR_UNICODE means that \eR matches -any Unicode line ending sequence; a value of PCRE2_BSR_ANYCRLF means that \eR -matches only CR, LF, or CRLF. +The output is a uint32_t integer whose value indicates what character sequences +the \eR escape sequence matches. A value of PCRE2_BSR_UNICODE means that \eR +matches any Unicode line ending sequence; a value of PCRE2_BSR_ANYCRLF means +that \eR matches only CR, LF, or CRLF. .sp PCRE2_INFO_CAPTURECOUNT .sp @@ -1991,10 +1992,10 @@ The third argument should point to an \fBuint32_t\fP variable. .sp If the pattern set a backtracking depth limit by including an item of the form (*LIMIT_DEPTH=nnnn) at the start, the value is returned. The third argument -should point to an unsigned 32-bit integer. If no such value has been set, the -call to \fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note -that this limit will only be used during matching if it is less than the limit -set or defaulted by the caller of the match function. +should point to a uint32_t integer. If no such value has been set, the call to +\fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note that this +limit will only be used during matching if it is less than the limit set or +defaulted by the caller of the match function. .sp PCRE2_INFO_FIRSTBITMAP .sp @@ -2004,7 +2005,7 @@ values for the first code unit in any match. For example, a pattern that starts with [abc] results in a table with three bits set. When code unit values greater than 255 are supported, the flag bit for 255 means "any code unit of value 255 or above". If such a table was constructed, a pointer to it is -returned. Otherwise NULL is returned. The third argument should point to an +returned. Otherwise NULL is returned. The third argument should point to a \fBconst uint8_t *\fP variable. .sp PCRE2_INFO_FIRSTCODETYPE @@ -2031,7 +2032,7 @@ and up to 0xffffffff when not using UTF-32 mode. .sp Return the size (in bytes) of the data frames that are used to remember backtracking positions when the pattern is processed by \fBpcre2_match()\fP -without the use of JIT. The third argument should point to an \fBsize_t\fP +without the use of JIT. The third argument should point to a \fBsize_t\fP variable. The frame size depends on the number of capturing parentheses in the pattern. Each additional capturing group adds two PCRE2_SIZE variables. .sp @@ -2051,10 +2052,10 @@ the equivalent hexadecimal or octal escape sequences. .sp If the pattern set a heap memory limit by including an item of the form (*LIMIT_HEAP=nnnn) at the start, the value is returned. The third argument -should point to an unsigned 32-bit integer. If no such value has been set, the -call to \fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note -that this limit will only be used during matching if it is less than the limit -set or defaulted by the caller of the match function. +should point to a uint32_t integer. If no such value has been set, the call to +\fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note that this +limit will only be used during matching if it is less than the limit set or +defaulted by the caller of the match function. .sp PCRE2_INFO_JCHANGED .sp @@ -2098,15 +2099,15 @@ in such cases. .sp If the pattern set a match limit by including an item of the form (*LIMIT_MATCH=nnnn) at the start, the value is returned. The third argument -should point to an unsigned 32-bit integer. If no such value has been set, the -call to \fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note -that this limit will only be used during matching if it is less than the limit -set or defaulted by the caller of the match function. +should point to a uint32_t integer. If no such value has been set, the call to +\fBpcre2_pattern_info()\fP returns the error PCRE2_ERROR_UNSET. Note that this +limit will only be used during matching if it is less than the limit set or +defaulted by the caller of the match function. .sp PCRE2_INFO_MAXLOOKBEHIND .sp Return the number of characters (not code units) in the longest lookbehind -assertion in the pattern. The third argument should point to an unsigned 32-bit +assertion in the pattern. The third argument should point to a uint32_t integer. This information is useful when doing multi-segment matching using the partial matching facilities. Note that the simple assertions \eb and \eB require a one-character lookbehind. \eA also registers a one-character @@ -2393,7 +2394,7 @@ zero, the search for a match starts at the beginning of the subject, and this is by far the most common case. In UTF-8 or UTF-16 mode, the starting offset must point to the start of a character, or to the end of the subject (in UTF-32 mode, one code unit equals one character, so all offsets are valid). Like the -pattern string, the subject may contain binary zeroes. +pattern string, the subject may contain binary zeros. .P A non-zero starting offset is useful when searching for another match in the same subject by calling \fBpcre2_match()\fP again after a previous success. @@ -3562,12 +3563,12 @@ There are in addition the following errors that are specific to .sp This return is given if \fBpcre2_dfa_match()\fP encounters an item in the pattern that it does not support, for instance, the use of \eC in a UTF mode or -a back reference. +a backreference. .sp PCRE2_ERROR_DFA_UCOND .sp This return is given if \fBpcre2_dfa_match()\fP encounters a condition item -that uses a back reference for the condition, or a test for recursion in a +that uses a backreference for the condition, or a test for recursion in a specific group. These are not supported. .sp PCRE2_ERROR_DFA_WSSIZE diff --git a/doc/pcre2build.3 b/doc/pcre2build.3 index 3b8a956..9442c3f 100644 --- a/doc/pcre2build.3 +++ b/doc/pcre2build.3 @@ -216,7 +216,7 @@ separator, U+2028), and PS (paragraph separator, U+2029). The final option is .sp --enable-newline-is-nul .sp -which causes NUL (binary zero) is set as the default line-ending character. +which causes NUL (binary zero) to be set as the default line-ending character. .P Whatever default line ending convention is selected when PCRE2 is built can be overridden by applications that use the library. At build time it is @@ -281,8 +281,8 @@ The \fBpcre2_match()\fP function starts out using a 20K vector on the system stack to record backtracking points. The more nested backtracking points there are (that is, the deeper the search tree), the more memory is needed. If the initial vector is not large enough, heap memory is used, up to a certain limit, -which is specified in kilobytes. The limit can be changed at run time, as -described in the +which is specified in kibibytes (units of 1024 bytes). The limit can be changed +at run time, as described in the .\" HREF \fBpcre2api\fP .\" @@ -291,7 +291,7 @@ change this by a setting such as .sp --with-heap-limit=500 .sp -which limits the amount of heap to 500 kilobytes. This limit applies only to +which limits the amount of heap to 500 KiB. This limit applies only to interpretive matching in \fBpcre2_match()\fP and \fBpcre2_dfa_match()\fP, which may also use the heap for internal workspace when processing complicated patterns. This limit does not apply when JIT (which has its own memory @@ -552,7 +552,7 @@ generated from the string. Setting --enable-fuzz-support also causes a binary called \fBpcre2fuzzcheck\fP to be created. This is normally run under valgrind or used when PCRE2 is compiled with address sanitizing enabled. It calls the fuzzing function and -outputs information about it is doing. The input strings are specified by +outputs information about what it is doing. The input strings are specified by arguments: if an argument starts with "=" the rest of it is a literal input string. Otherwise, it is assumed to be a file name, and the contents of the file are the test string. diff --git a/doc/pcre2callout.3 b/doc/pcre2callout.3 index 4be2e49..c815c72 100644 --- a/doc/pcre2callout.3 +++ b/doc/pcre2callout.3 @@ -128,7 +128,7 @@ start only after an internal newline or at the beginning of the subject, and branch, automatic anchoring occurs if all branches are anchorable. .P This optimization is disabled, however, if .* is in an atomic group or if there -is a back reference to the capturing group in which it appears. It is also +is a backreference to the capturing group in which it appears. It is also disabled if the pattern contains (*PRUNE) or (*SKIP). However, the presence of callouts does not affect it. .P diff --git a/doc/pcre2compat.3 b/doc/pcre2compat.3 index 8094ebd..313bbd7 100644 --- a/doc/pcre2compat.3 +++ b/doc/pcre2compat.3 @@ -19,7 +19,7 @@ page. 2. Like Perl, PCRE2 allows repeat quantifiers on parenthesized assertions, but they do not mean what you might think. For example, (?!a){3} does not assert that the next three characters are not "a". It just asserts that the next -character is not "a" three times (in principle: PCRE2 optimizes this to run the +character is not "a" three times (in principle; PCRE2 optimizes this to run the assertion just once). Perl allows some repeat quantifiers on other assertions, for example, \eb* (but not \eb{3}), but these do not seem to have any use. .P @@ -62,8 +62,8 @@ Note the following examples: The \eQ...\eE sequence is recognized both inside and outside character classes. .P 7. Fairly obviously, PCRE2 does not support the (?{code}) and (??{code}) -constructions. However, there is support PCRE2's "callout" feature, which -allows an external function to be called during pattern matching. See the +constructions. However, PCRE2 does have a "callout" feature, which allows an +external function to be called during pattern matching. See the .\" HREF \fBpcre2callout\fP .\" @@ -131,7 +131,7 @@ list is with respect to Perl 5.26: each alternative branch of a lookbehind assertion can match a different length of string. Perl requires them all to have the same length. .sp -(b) From PCRE2 10.23, back references to groups of fixed length are supported +(b) From PCRE2 10.23, backreferences to groups of fixed length are supported in lookbehinds, provided that there is no possibility of referencing a non-unique number or name. Perl does not support backreferences in lookbehinds. .sp diff --git a/doc/pcre2grep.1 b/doc/pcre2grep.1 index ba6aea6..f218052 100644 --- a/doc/pcre2grep.1 +++ b/doc/pcre2grep.1 @@ -57,9 +57,10 @@ controlled by parameters that can be set by the \fB--buffer-size\fP and that is obtained at the start of processing. If an input file contains very long lines, a larger buffer may be needed; this is handled by automatically extending the buffer, up to the limit specified by \fB--max-buffer-size\fP. The -default values for these parameters are specified when \fBpcre2grep\fP is -built, with the default defaults being 20K and 1M respectively. An error occurs -if a line is too long and the buffer can no longer be expanded. +default values for these parameters can be set when \fBpcre2grep\fP is +built; if nothing is specified, the defaults are set to 20K and 1M +respectively. An error occurs if a line is too long and the buffer can no +longer be expanded. .P The block of memory that is actually used is three times the "buffer size", to allow for buffering "before" and "after" lines. If the buffer size is too @@ -434,13 +435,13 @@ short form for this option. When this option is given, non-compressed input is read and processed line by line, and the output is flushed after each write. By default, input is read in large chunks, unless \fBpcre2grep\fP can determine that it is reading from a -terminal (which is currently possible only in Unix-like environments). Output -to terminal is normally automatically flushed by the operating system. This -option can be useful when the input or output is attached to a pipe and you do -not want \fBpcre2grep\fP to buffer up large amounts of data. However, its use -will affect performance, and the \fB-M\fP (multiline) option ceases to work. -When input is from a compressed .gz or .bz2 file, \fB--line-buffered\fP is -ignored. +terminal (which is currently possible only in Unix-like environments or +Windows). Output to terminal is normally automatically flushed by the operating +system. This option can be useful when the input or output is attached to a +pipe and you do not want \fBpcre2grep\fP to buffer up large amounts of data. +However, its use will affect performance, and the \fB-M\fP (multiline) option +ceases to work. When input is from a compressed .gz or .bz2 file, +\fB--line-buffered\fP is ignored. .TP \fB--line-offsets\fP Instead of showing lines or parts of lines that match, show each match as a @@ -470,11 +471,11 @@ is a pattern that uses nested unlimited repeats. Internally, PCRE2 has a counter that is incremented each time around its main processing loop. If the value set by \fB--match-limit\fP is reached, an error occurs. .sp -The \fB--heap-limit\fP option specifies, as a number of kilobytes, the amount -of heap memory that may be used for matching. Heap memory is needed only if -matching the pattern requires a significant number of nested backtracking -points to be remembered. This parameter can be set to zero to forbid the use of -heap memory altogether. +The \fB--heap-limit\fP option specifies, as a number of kibibytes (units of +1024 bytes), the amount of heap memory that may be used for matching. Heap +memory is needed only if matching the pattern requires a significant number of +nested backtracking points to be remembered. This parameter can be set to zero +to forbid the use of heap memory altogether. .sp The \fB--depth-limit\fP option limits the depth of nested backtracking points, which indirectly limits the amount of memory that is used. The amount of memory @@ -483,9 +484,9 @@ parentheses in the pattern, so the amount of memory that is used before this limit acts varies from pattern to pattern. This limit is of use only if it is set smaller than \fB--match-limit\fP. .sp -There are no short forms for these options. The default settings are specified -when the PCRE2 library is compiled, with the default defaults being very large -and so effectively unlimited. +There are no short forms for these options. The default limits can be set +when the PCRE2 library is compiled; if they are not specified, the defaults +are very large and so effectively unlimited. .TP \fB--max-buffer-size=\fInumber\fP This limits the expansion of the processing buffer, whose initial size can be diff --git a/doc/pcre2grep.txt b/doc/pcre2grep.txt index 6a84095..c0d1636 100644 --- a/doc/pcre2grep.txt +++ b/doc/pcre2grep.txt @@ -56,10 +56,10 @@ DESCRIPTION that is obtained at the start of processing. If an input file contains very long lines, a larger buffer may be needed; this is handled by automatically extending the buffer, up to the limit specified by --max- - buffer-size. The default values for these parameters are specified when - pcre2grep is built, with the default defaults being 20K and 1M respec- - tively. An error occurs if a line is too long and the buffer can no - longer be expanded. + buffer-size. The default values for these parameters can be set when + pcre2grep is built; if nothing is specified, the defaults are set to + 20K and 1M respectively. An error occurs if a line is too long and the + buffer can no longer be expanded. The block of memory that is actually used is three times the "buffer size", to allow for buffering "before" and "after" lines. If the buffer @@ -475,14 +475,14 @@ OPTIONS processed line by line, and the output is flushed after each write. By default, input is read in large chunks, unless pcre2grep can determine that it is reading from a terminal - (which is currently possible only in Unix-like environments). - Output to terminal is normally automatically flushed by the - operating system. This option can be useful when the input or - output is attached to a pipe and you do not want pcre2grep to - buffer up large amounts of data. However, its use will affect - performance, and the -M (multiline) option ceases to work. - When input is from a compressed .gz or .bz2 file, --line- - buffered is ignored. + (which is currently possible only in Unix-like environments + or Windows). Output to terminal is normally automatically + flushed by the operating system. This option can be useful + when the input or output is attached to a pipe and you do not + want pcre2grep to buffer up large amounts of data. However, + its use will affect performance, and the -M (multiline) + option ceases to work. When input is from a compressed .gz or + .bz2 file, --line-buffered is ignored. --line-offsets Instead of showing lines or parts of lines that match, show @@ -517,12 +517,12 @@ OPTIONS processing loop. If the value set by --match-limit is reached, an error occurs. - The --heap-limit option specifies, as a number of kilobytes, - the amount of heap memory that may be used for matching. Heap - memory is needed only if matching the pattern requires a sig- - nificant number of nested backtracking points to be remem- - bered. This parameter can be set to zero to forbid the use of - heap memory altogether. + The --heap-limit option specifies, as a number of kibibytes + (units of 1024 bytes), the amount of heap memory that may be + used for matching. Heap memory is needed only if matching the + pattern requires a significant number of nested backtracking + points to be remembered. This parameter can be set to zero to + forbid the use of heap memory altogether. The --depth-limit option limits the depth of nested back- tracking points, which indirectly limits the amount of memory @@ -532,10 +532,10 @@ OPTIONS limit acts varies from pattern to pattern. This limit is of use only if it is set smaller than --match-limit. - There are no short forms for these options. The default set- - tings are specified when the PCRE2 library is compiled, with - the default defaults being very large and so effectively - unlimited. + There are no short forms for these options. The default lim- + its can be set when the PCRE2 library is compiled; if they + are not specified, the defaults are very large and so effec- + tively unlimited. --max-buffer-size=number This limits the expansion of the processing buffer, whose diff --git a/doc/pcre2limits.3 b/doc/pcre2limits.3 index 88944db..9a7dc50 100644 --- a/doc/pcre2limits.3 +++ b/doc/pcre2limits.3 @@ -38,9 +38,9 @@ There is no limit to the number of parenthesized subpatterns, but there can be no more than 65535 capturing subpatterns. There is, however, a limit to the depth of nesting of parenthesized subpatterns of all kinds. This is imposed in order to limit the amount of system stack used at compile time. The default -limit can be specified when PCRE2 is built; the default default is 250. An -application can change this limit by calling pcre2_set_parens_nest_limit() to -set the limit in a compile context. +limit can be specified when PCRE2 is built; if not, the default is set to 250. +An application can change this limit by calling pcre2_set_parens_nest_limit() +to set the limit in a compile context. .P The maximum length of name for a named subpattern is 32 code units, and the maximum number of named subpatterns is 10000. diff --git a/doc/pcre2matching.3 b/doc/pcre2matching.3 index 3a885e5..81ce968 100644 --- a/doc/pcre2matching.3 +++ b/doc/pcre2matching.3 @@ -67,7 +67,7 @@ ungreedy repetition quantifiers are specified in the pattern. Because it ends up with a single path through the tree, it is relatively straightforward for this algorithm to keep track of the substrings that are matched by portions of the pattern in parentheses. This provides support for -capturing parentheses and back references. +capturing parentheses and backreferences. . . .SH "THE ALTERNATIVE MATCHING ALGORITHM" @@ -134,7 +134,7 @@ straightforward to keep track of captured substrings for the different matching possibilities, and PCRE2's implementation of this algorithm does not attempt to do this. This means that no captured substrings are available. .P -3. Because no substrings are captured, back references within the pattern are +3. Because no substrings are captured, backreferences within the pattern are not supported, and cause errors if encountered. .P 4. For the same reason, conditional expressions that use a backreference as the @@ -188,7 +188,7 @@ The alternative algorithm suffers from a number of disadvantages: because it has to search for all possible matches, but is also because it is less susceptible to optimization. .P -2. Capturing parentheses and back references are not supported. +2. Capturing parentheses and backreferences are not supported. .P 3. Although atomic groups are supported, their use does not provide the performance advantage that it does for the standard algorithm. diff --git a/doc/pcre2pattern.3 b/doc/pcre2pattern.3 index c33f27d..407d837 100644 --- a/doc/pcre2pattern.3 +++ b/doc/pcre2pattern.3 @@ -163,7 +163,7 @@ be less than the value set (or defaulted) by the caller of \fBpcre2_match()\fP for it to have any effect. In other words, the pattern writer can lower the limits set by the programmer, but not raise them. If there is more than one setting of one of these limits, the lower value is used. The heap limit is -specified in kilobytes. +specified in kibibytes (units of 1024 bytes). .P Prior to release 10.30, LIMIT_DEPTH was called LIMIT_RECURSION. This name is still recognized for backwards compatibility. @@ -318,7 +318,7 @@ precede a non-alphanumeric with backslash to specify that it stands for itself. In particular, if you want to match a backslash, you write \e\e. .P In a UTF mode, only ASCII numbers and letters have any special meaning after a -backslash. All other characters (in particular, those whose codepoints are +backslash. All other characters (in particular, those whose code points are greater than 127) are treated as literals. .P If a pattern is compiled with the PCRE2_EXTENDED option, most white space in @@ -367,7 +367,7 @@ these escapes are as follows: \er carriage return (hex 0D) \et tab (hex 09) \e0dd character with octal code 0dd - \eddd character with octal code ddd, or back reference + \eddd character with octal code ddd, or backreference \eo{ddd..} character with octal code ddd.. \exhh character with hex code hh \ex{hhh..} character with hex code hhh.. (default mode) @@ -410,12 +410,12 @@ follows is itself an octal digit. The escape \eo must be followed by a sequence of octal digits, enclosed in braces. An error occurs if this is not the case. This escape is a recent addition to Perl; it provides way of specifying character code points as octal -numbers greater than 0777, and it also allows octal numbers and back references +numbers greater than 0777, and it also allows octal numbers and backreferences to be unambiguously specified. .P For greater clarity and unambiguity, it is best to avoid following \e by a digit greater than zero. Instead, use \eo{} or \ex{} to specify character -numbers, and \eg{} to specify back references. The following paragraphs +numbers, and \eg{} to specify backreferences. The following paragraphs describe the old, ambiguous syntax. .P The handling of a backslash followed by a digit other than 0 is complicated, @@ -424,7 +424,7 @@ and Perl has changed over time, causing PCRE2 also to change. Outside a character class, PCRE2 reads the digit and any following digits as a decimal number. If the number is less than 10, begins with the digit 8 or 9, or if there are at least that many previous capturing left parentheses in the -expression, the entire sequence is taken as a \fIback reference\fP. A +expression, the entire sequence is taken as a \fIbackreference\fP. A description of how this works is given .\" HTML .\" @@ -446,20 +446,20 @@ for themselves. For example, outside a character class: .\" JOIN \e40 is the same, provided there are fewer than 40 previous capturing subpatterns - \e7 is always a back reference + \e7 is always a backreference .\" JOIN - \e11 might be a back reference, or another way of + \e11 might be a backreference, or another way of writing a tab \e011 is always a tab \e0113 is a tab followed by the character "3" .\" JOIN - \e113 might be a back reference, otherwise the + \e113 might be a backreference, otherwise the character with octal code 113 .\" JOIN - \e377 might be a back reference, otherwise + \e377 might be a backreference, otherwise the value 255 (decimal) .\" JOIN - \e81 is always a back reference + \e81 is always a backreference .sp Note that octal values of 100 or greater that are specified using this syntax must not be introduced by a leading zero, because no more than three octal @@ -492,10 +492,10 @@ limited to certain values, as follows: 8-bit non-UTF mode no greater than 0xff 16-bit non-UTF mode no greater than 0xffff 32-bit non-UTF mode no greater than 0xffffffff - All UTF modes no greater than 0x10ffff and a valid codepoint + All UTF modes no greater than 0x10ffff and a valid code point .sp -Invalid Unicode codepoints are all those in the range 0xd800 to 0xdfff (the -so-called "surrogate" codepoints). The check for these can be disabled by the +Invalid Unicode code points are all those in the range 0xd800 to 0xdfff (the +so-called "surrogate" code points). The check for these can be disabled by the caller of \fBpcre2_compile()\fP by setting the option PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES. . @@ -523,12 +523,12 @@ is set, \eU matches a "U" character, and \eu can be used to define a character by code point, as described above. . . -.SS "Absolute and relative back references" +.SS "Absolute and relative backreferences" .rs .sp The sequence \eg followed by a signed or unsigned number, optionally enclosed -in braces, is an absolute or relative back reference. A named back reference -can be coded as \eg{name}. Back references are discussed +in braces, is an absolute or relative backreference. A named backreference +can be coded as \eg{name}. backreferences are discussed .\" HTML .\" later, @@ -551,7 +551,7 @@ syntax for referencing a subpattern as a "subroutine". Details are discussed later. .\" Note that \eg{...} (Perl syntax) and \eg<...> (Oniguruma syntax) are \fInot\fP -synonymous. The former is a back reference; the latter is a +synonymous. The former is a backreference; the latter is a .\" HTML .\" subroutine @@ -692,7 +692,7 @@ U+000B), FF (form feed, U+000C), CR (carriage return, U+000D), or NEL (next line, U+0085). Because this is an atomic group, the two-character sequence is treated as a single unit that cannot be split. .P -In other modes, two additional characters whose codepoints are greater than 255 +In other modes, two additional characters whose code points are greater than 255 are added: LS (line separator, U+2028) and PS (paragraph separator, U+2029). Unicode support is not needed for these characters to be recognized. .P @@ -727,8 +727,8 @@ an error. When PCRE2 is built with Unicode support (the default), three additional escape sequences that match characters with specific properties are available. In 8-bit non-UTF-8 mode, these sequences are of course limited to testing -characters whose codepoints are less than 256, but they do work in this mode. -In 32-bit non-UTF mode, codepoints greater than 0x10ffff (the Unicode limit) +characters whose code points are less than 256, but they do work in this mode. +In 32-bit non-UTF mode, code points greater than 0x10ffff (the Unicode limit) may be encountered. These are all treated as being in the Common script and with an unassigned type. The extra escape sequences are: .sp @@ -1026,7 +1026,7 @@ joiner" characters. Characters with the "mark" property always have the 6. Do not break within emoji modifier sequences (a base character followed by a modifier). Extending characters are allowed before the modifier. .P -7. Do not break within emoji zwj sequences (zero-width jointer followed by +7. Do not break within emoji zwj sequences (zero-width joiner followed by "glue after ZWJ" or "base glue after ZWJ"). .P 8. Do not break within emoji flag sequences. That is, do not break between @@ -1724,7 +1724,7 @@ numbers underneath show in which buffer the captured content will be stored. / ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x # 1 2 2 3 2 3 4 .sp -A back reference to a numbered subpattern uses the most recent value that is +A backreference to a numbered subpattern uses the most recent value that is set for that number by any subpattern. The following pattern matches "abcabc" or "defdef": .sp @@ -1768,7 +1768,7 @@ In PCRE2, a subpattern can be named in one of three ways: (?...) or parentheses from other parts of the pattern, such as .\" HTML .\" -back references, +backreferences, .\" .\" HTML .\" @@ -1811,7 +1811,7 @@ The convenience functions for extracting the data by name returns the substring for the first (and in this example, the only) subpattern of that name that matched. This saves searching to find which numbered subpattern it was. .P -If you make a back reference to a non-unique named subpattern from elsewhere in +If you make a backreference to a non-unique named subpattern from elsewhere in the pattern, the subpatterns to which the name refers are checked in the order in which they appear in the overall pattern. The first one that is set is used for the reference. For example, this pattern matches both "foofoo" and @@ -1863,7 +1863,7 @@ items: the \eR escape sequence an escape such as \ed or \epL that matches a single character a character class - a back reference + a backreference a parenthesized subpattern (including most assertions) a subroutine call to a subpattern (recursive or otherwise) .sp @@ -1980,7 +1980,7 @@ worth setting PCRE2_DOTALL in order to obtain this optimization, or alternatively, using ^ to indicate anchoring explicitly. .P However, there are some cases where the optimization cannot be used. When .* -is inside capturing parentheses that are the subject of a back reference +is inside capturing parentheses that are the subject of a backreference elsewhere in the pattern, a match at the start may fail where a later one succeeds. Consider, for example: .sp @@ -2116,23 +2116,23 @@ sequences of non-digits cannot be broken, and failure happens quickly. . . .\" HTML -.SH "BACK REFERENCES" +.SH "BACKREFERENCES" .rs .sp Outside a character class, a backslash followed by a digit greater than 0 (and -possibly further digits) is a back reference to a capturing subpattern earlier +possibly further digits) is a backreference to a capturing subpattern earlier (that is, to its left) in the pattern, provided there have been that many previous capturing left parentheses. .P However, if the decimal number following the backslash is less than 8, it is -always taken as a back reference, and causes an error only if there are not +always taken as a backreference, and causes an error only if there are not that many capturing left parentheses in the entire pattern. In other words, the parentheses that are referenced need not be to the left of the reference for -numbers less than 8. A "forward back reference" of this type can make sense +numbers less than 8. A "forward backreference" of this type can make sense when a repetition is involved and the subpattern to the right has participated in an earlier iteration. .P -It is not possible to have a numerical "forward back reference" to a subpattern +It is not possible to have a numerical "forward backreference" to a subpattern whose number is 8 or more using this syntax because a sequence such as \e50 is interpreted as a character defined in octal. See the subsection entitled "Non-printing characters" @@ -2141,7 +2141,7 @@ interpreted as a character defined in octal. See the subsection entitled above .\" for further details of the handling of digits following a backslash. There is -no such problem when named parentheses are used. A back reference to any +no such problem when named parentheses are used. A backreference to any subpattern is possible using named parentheses (see below). .P Another way of avoiding the ambiguity inherent in the use of digits following a @@ -2169,7 +2169,7 @@ The sequence \eg{+1} is a reference to the next capturing subpattern. This kind of forward reference can be useful it patterns that repeat. Perl does not support the use of + in this way. .P -A back reference matches whatever actually matched the capturing subpattern in +A backreference matches whatever actually matched the capturing subpattern in the current subject string, rather than anything matching the subpattern itself (see .\" HTML @@ -2182,17 +2182,17 @@ below for a way of doing that). So the pattern .sp matches "sense and sensibility" and "response and responsibility", but not "sense and responsibility". If caseful matching is in force at the time of the -back reference, the case of letters is relevant. For example, +backreference, the case of letters is relevant. For example, .sp ((?i)rah)\es+\e1 .sp matches "rah rah" and "RAH RAH", but not "RAH rah", even though the original capturing subpattern is matched caselessly. .P -There are several different ways of writing back references to named +There are several different ways of writing backreferences to named subpatterns. The .NET syntax \ek{name} and the Perl syntax \ek or \ek'name' are supported, as is the Python syntax (?P=name). Perl 5.10's unified -back reference syntax, in which \eg can be used for both numeric and named +backreference syntax, in which \eg can be used for both numeric and named references, is also supported. We could rewrite the above example in any of the following ways: .sp @@ -2204,20 +2204,20 @@ the following ways: A subpattern that is referenced by name may appear in the pattern before or after the reference. .P -There may be more than one back reference to the same subpattern. If a -subpattern has not actually been used in a particular match, any back -references to it always fail by default. For example, the pattern +There may be more than one backreference to the same subpattern. If a +subpattern has not actually been used in a particular match, any backreferences +to it always fail by default. For example, the pattern .sp (a|(bc))\e2 .sp always fails if it starts to match "a" rather than "bc". However, if the -PCRE2_MATCH_UNSET_BACKREF option is set at compile time, a back reference to an +PCRE2_MATCH_UNSET_BACKREF option is set at compile time, a backreference to an unset value matches an empty string. .P Because there may be many capturing parentheses in a pattern, all digits -following a backslash are taken as part of a potential back reference number. +following a backslash are taken as part of a potential backreference number. If the pattern continues with a digit character, some delimiter must be used to -terminate the back reference. If the PCRE2_EXTENDED option is set, this can be +terminate the backreference. If the PCRE2_EXTENDED option is set, this can be white space. Otherwise, the \eg{ syntax or an empty comment (see .\" HTML .\" @@ -2226,10 +2226,10 @@ white space. Otherwise, the \eg{ syntax or an empty comment (see below) can be used. . . -.SS "Recursive back references" +.SS "Recursive backreferences" .rs .sp -A back reference that occurs inside the parentheses to which it refers fails +A backreference that occurs inside the parentheses to which it refers fails when the subpattern is first used, so, for example, (a\e1) never matches. However, such references can be useful inside repeated subpatterns. For example, the pattern @@ -2237,13 +2237,13 @@ example, the pattern (a|b\e1)+ .sp matches any number of "a"s and also "aba", "ababbaa" etc. At each iteration of -the subpattern, the back reference matches the character string corresponding +the subpattern, the backreference matches the character string corresponding to the previous iteration. In order for this to work, the pattern must be such -that the first iteration does not need to match the back reference. This can be +that the first iteration does not need to match the backreference. This can be done using alternation, as in the example above, or by a quantifier with a minimum of zero. .P -Back references of this type cause the group that they reference to be treated +backreferences of this type cause the group that they reference to be treated as an .\" HTML .\" @@ -2406,10 +2406,10 @@ recursion, that is, a "subroutine" call into a group that is already active, is not supported. .P -Perl does not support back references in lookbehinds. PCRE2 does support them, +Perl does not support backreferences in lookbehinds. PCRE2 does support them, but only if certain conditions are met. The PCRE2_MATCH_UNSET_BACKREF option must not be set, there must be no use of (?| in the pattern (it creates -duplicate subpattern numbers), and if the back reference is by name, the name +duplicate subpattern numbers), and if the backreference is by name, the name must be unique. Of course, the referenced subpattern must itself be of fixed length. The following pattern matches words containing at least two characters that begin and end with the same character: @@ -2899,7 +2899,7 @@ in PCRE2 these values can be referenced. Consider this pattern: ^(.)(\e1|a(?2)) .sp This pattern matches "bab". The first capturing parentheses match "b", then in -the second group, when the back reference \e1 fails to match "b", the second +the second group, when the backreference \e1 fails to match "b", the second alternative matches "a" and then recurses. In the recursion, \e1 does now match "b" and so the whole match succeeds. This match used to fail in Perl, but in later versions (I tried 5.024) it now works. @@ -2964,7 +2964,7 @@ plus or a minus sign it is taken as a relative reference. For example: (abc)(?i:\eg<-1>) .sp Note that \eg{...} (Perl syntax) and \eg<...> (Oniguruma syntax) are \fInot\fP -synonymous. The former is a back reference; the latter is a subroutine call. +synonymous. The former is a backreference; the latter is a subroutine call. . . .SH CALLOUTS diff --git a/doc/pcre2posix.3 b/doc/pcre2posix.3 index 399e2a8..0d8b2c2 100644 --- a/doc/pcre2posix.3 +++ b/doc/pcre2posix.3 @@ -108,14 +108,14 @@ When a pattern that is compiled with this flag is passed to \fBregexec()\fP for matching, the \fInmatch\fP and \fIpmatch\fP arguments are ignored, and no captured strings are returned. Versions of the PCRE library prior to 10.22 used to set the PCRE2_NO_AUTO_CAPTURE compile option, but this no longer happens -because it disables the use of back references. +because it disables the use of backreferences. .sp REG_PEND .sp If this option is set, the \fBreg_endp\fP field in the \fIpreg\fP structure (which has the type const char *) must be set to point to the character beyond the end of the pattern before calling \fBregcomp()\fP. The pattern itself may -now contain binary zeroes, which are treated as data characters. Without +now contain binary zeros, which are treated as data characters. Without REG_PEND, a binary zero terminates the pattern and the \fBre_endp\fP field is ignored. This is a GNU extension to the POSIX standard and should be used with caution in software intended to be portable to other systems. @@ -224,10 +224,10 @@ function. .sp REG_STARTEND .sp -When this option is set, the subject string is starts at \fIstring\fP + +When this option is set, the subject string starts at \fIstring\fP + \fIpmatch[0].rm_so\fP and ends at \fIstring\fP + \fIpmatch[0].rm_eo\fP, which should point to the first character beyond the string. There may be binary -zeroes within the subject string, and indeed, using REG_STARTEND is the only +zeros within the subject string, and indeed, using REG_STARTEND is the only way to pass a subject string that contains a binary zero. .P Whatever the value of \fIpmatch[0].rm_so\fP, the offsets of the matched string diff --git a/doc/pcre2syntax.3 b/doc/pcre2syntax.3 index 6eb0235..bc2f32b 100644 --- a/doc/pcre2syntax.3 +++ b/doc/pcre2syntax.3 @@ -419,7 +419,7 @@ of the newline or \eR options with similar syntax. More than one of them may appear. For the first three, d is a decimal number. .sp (*LIMIT_DEPTH=d) set the backtracking limit to d - (*LIMIT_HEAP=d) set the heap size limit to d kilobytes + (*LIMIT_HEAP=d) set the heap size limit to d * 1024 bytes (*LIMIT_MATCH=d) set the match limit to d (*NOTEMPTY) set PCRE2_NOTEMPTY when matching (*NOTEMPTY_ATSTART) set PCRE2_NOTEMPTY_ATSTART when matching diff --git a/doc/pcre2test.1 b/doc/pcre2test.1 index a14eab2..0303654 100644 --- a/doc/pcre2test.1 +++ b/doc/pcre2test.1 @@ -101,7 +101,7 @@ to occur). UTF-8 (in its original definition) is not capable of encoding values greater than 0x7fffffff, but such values can be handled by the 32-bit library. When testing this library in non-UTF mode with \fButf8_input\fP set, if any -character is preceded by the byte 0xff (which is an illegal byte in UTF-8) +character is preceded by the byte 0xff (which is an invalid byte in UTF-8) 0x80000000 is added to the character's value. This is the only way of passing such code points in a pattern string. For subject strings, using an escape sequence is preferable. @@ -220,7 +220,7 @@ Do not output the version number of \fBpcre2test\fP at the start of execution. .TP 10 \fB-S\fP \fIsize\fP On Unix-like systems, set the size of the run-time stack to \fIsize\fP -megabytes. +mebibytes (units of 1024*1024 bytes). .TP 10 \fB-subject\fP \fImodifier-list\fP Behave as if each subject line contains the given modifiers. @@ -639,8 +639,8 @@ The effects of these modifiers are described in the following sections. .sp The \fBbsr\fP modifier specifies what \eR in a pattern should match. If it is set to "anycrlf", \eR matches CR, LF, or CRLF only. If it is set to "unicode", -\eR matches any Unicode newline sequence. The default is specified when PCRE2 -is built, with the default default being Unicode. +\eR matches any Unicode newline sequence. The default can be specified when +PCRE2 is built; if it is not, the default is set to Unicode. .P The \fBnewline\fP modifier specifies which characters are to be interpreted as newlines, both in the pattern and in subject lines. The type must be one of CR, @@ -1381,11 +1381,11 @@ matching provokes an error return ("bad option value") from .sp The \fBjitstack\fP modifier provides a way of setting the maximum stack size that is used by the just-in-time optimization code. It is ignored if JIT -optimization is not being used. The value is a number of kilobytes. Setting -zero reverts to the default of 32K. Providing a stack that is larger than the -default is necessary only for very complicated patterns. If \fBjitstack\fP is -set non-zero on a subject line it overrides any value that was set on the -pattern. +optimization is not being used. The value is a number of kibibytes (units of +1024 bytes). Setting zero reverts to the default of 32KiB. Providing a stack +that is larger than the default is necessary only for very complicated +patterns. If \fBjitstack\fP is set non-zero on a subject line it overrides any +value that was set on the pattern. . . .SS "Setting heap, match, and depth limits" @@ -1427,10 +1427,10 @@ matching, \fImatch_limit\fP controls the total number of calls, both recursive and non-recursive, to the internal matching function, thus controlling the overall amount of computing resource that is used. .P -For both kinds of matching, the \fIheap_limit\fP number (which is in kilobytes) -limits the amount of heap memory used for matching. A value of zero disables -the use of any heap memory; many simple pattern matches can be done without -using the heap, so this is not an unreasonable setting. +For both kinds of matching, the \fIheap_limit\fP number, which is in kibibytes +(units of 1024 bytes), limits the amount of heap memory used for matching. A +value of zero disables the use of any heap memory; many simple pattern matches +can be done without using the heap, so zero is not an unreasonable setting. . . .SS "Showing MARK names" diff --git a/doc/pcre2test.txt b/doc/pcre2test.txt index ef00ef7..d831deb 100644 --- a/doc/pcre2test.txt +++ b/doc/pcre2test.txt @@ -94,7 +94,7 @@ INPUT ENCODING UTF-8 (in its original definition) is not capable of encoding values greater than 0x7fffffff, but such values can be handled by the 32-bit library. When testing this library in non-UTF mode with utf8_input set, - if any character is preceded by the byte 0xff (which is an illegal byte + if any character is preceded by the byte 0xff (which is an invalid byte in UTF-8) 0x80000000 is added to the character's value. This is the only way of passing such code points in a pattern string. For subject strings, using an escape sequence is preferable. @@ -208,7 +208,7 @@ COMMAND LINE OPTIONS execution. -S size On Unix-like systems, set the size of the run-time stack to - size megabytes. + size mebibytes (units of 1024*1024 bytes). -subject modifier-list Behave as if each subject line contains the given modifiers. @@ -614,32 +614,33 @@ PATTERN MODIFIERS The bsr modifier specifies what \R in a pattern should match. If it is set to "anycrlf", \R matches CR, LF, or CRLF only. If it is set to - "unicode", \R matches any Unicode newline sequence. The default is - specified when PCRE2 is built, with the default default being Unicode. + "unicode", \R matches any Unicode newline sequence. The default can be + specified when PCRE2 is built; if it is not, the default is set to Uni- + code. - The newline modifier specifies which characters are to be interpreted + The newline modifier specifies which characters are to be interpreted as newlines, both in the pattern and in subject lines. The type must be one of CR, LF, CRLF, ANYCRLF, ANY, or NUL (in upper or lower case). Information about a pattern - The debug modifier is a shorthand for info,fullbincode, requesting all + The debug modifier is a shorthand for info,fullbincode, requesting all available information. The bincode modifier causes a representation of the compiled code to be - output after compilation. This information does not contain length and + output after compilation. This information does not contain length and offset values, which ensures that the same output is generated for dif- - ferent internal link sizes and different code unit widths. By using - bincode, the same regression tests can be used in different environ- + ferent internal link sizes and different code unit widths. By using + bincode, the same regression tests can be used in different environ- ments. - The fullbincode modifier, by contrast, does include length and offset - values. This is used in a few special tests that run only for specific + The fullbincode modifier, by contrast, does include length and offset + values. This is used in a few special tests that run only for specific code unit widths and link sizes, and is also useful for one-off tests. - The info modifier requests information about the compiled pattern - (whether it is anchored, has a fixed first character, and so on). The - information is obtained from the pcre2_pattern_info() function. Here + The info modifier requests information about the compiled pattern + (whether it is anchored, has a fixed first character, and so on). The + information is obtained from the pcre2_pattern_info() function. Here are some typical examples: re> /(?i)(^a|^b)/m,info @@ -657,115 +658,115 @@ PATTERN MODIFIERS Last code unit = 'c' (caseless) Subject length lower bound = 3 - "Compile options" are those specified by modifiers; "overall options" - have added options that are taken or deduced from the pattern. If both - sets of options are the same, just a single "options" line is output; - if there are no options, the line is omitted. "First code unit" is - where any match must start; if there is more than one they are listed - as "starting code units". "Last code unit" is the last literal code - unit that must be present in any match. This is not necessarily the - last character. These lines are omitted if no starting or ending code + "Compile options" are those specified by modifiers; "overall options" + have added options that are taken or deduced from the pattern. If both + sets of options are the same, just a single "options" line is output; + if there are no options, the line is omitted. "First code unit" is + where any match must start; if there is more than one they are listed + as "starting code units". "Last code unit" is the last literal code + unit that must be present in any match. This is not necessarily the + last character. These lines are omitted if no starting or ending code units are recorded. - The framesize modifier shows the size, in bytes, of the storage frames - used by pcre2_match() for handling backtracking. The size depends on + The framesize modifier shows the size, in bytes, of the storage frames + used by pcre2_match() for handling backtracking. The size depends on the number of capturing parentheses in the pattern. - The callout_info modifier requests information about all the callouts + The callout_info modifier requests information about all the callouts in the pattern. A list of them is output at the end of any other infor- mation that is requested. For each callout, either its number or string is given, followed by the item that follows it in the pattern. Passing a NULL context - Normally, pcre2test passes a context block to pcre2_compile(). If the - null_context modifier is set, however, NULL is passed. This is for - testing that pcre2_compile() behaves correctly in this case (it uses + Normally, pcre2test passes a context block to pcre2_compile(). If the + null_context modifier is set, however, NULL is passed. This is for + testing that pcre2_compile() behaves correctly in this case (it uses default values). Specifying pattern characters in hexadecimal - The hex modifier specifies that the characters of the pattern, except - for substrings enclosed in single or double quotes, are to be inter- - preted as pairs of hexadecimal digits. This feature is provided as a + The hex modifier specifies that the characters of the pattern, except + for substrings enclosed in single or double quotes, are to be inter- + preted as pairs of hexadecimal digits. This feature is provided as a way of creating patterns that contain binary zeros and other non-print- - ing characters. White space is permitted between pairs of digits. For + ing characters. White space is permitted between pairs of digits. For example, this pattern contains three characters: /ab 32 59/hex - Parts of such a pattern are taken literally if quoted. This pattern - contains nine characters, only two of which are specified in hexadeci- + Parts of such a pattern are taken literally if quoted. This pattern + contains nine characters, only two of which are specified in hexadeci- mal: /ab "literal" 32/hex - Either single or double quotes may be used. There is no way of includ- - ing the delimiter within a substring. The hex and expand modifiers are + Either single or double quotes may be used. There is no way of includ- + ing the delimiter within a substring. The hex and expand modifiers are mutually exclusive. Specifying the pattern's length By default, patterns are passed to the compiling functions as zero-ter- - minated strings but can be passed by length instead of being zero-ter- - minated. The use_length modifier causes this to happen. Using a length - happens automatically (whether or not use_length is set) when hex is - set, because patterns specified in hexadecimal may contain binary + minated strings but can be passed by length instead of being zero-ter- + minated. The use_length modifier causes this to happen. Using a length + happens automatically (whether or not use_length is set) when hex is + set, because patterns specified in hexadecimal may contain binary zeros. If hex or use_length is used with the POSIX wrapper API (see "Using the - POSIX wrapper API" below), the REG_PEND extension is used to pass the + POSIX wrapper API" below), the REG_PEND extension is used to pass the pattern's length. Specifying wide characters in 16-bit and 32-bit modes In 16-bit and 32-bit modes, all input is automatically treated as UTF-8 - and translated to UTF-16 or UTF-32 when the utf modifier is set. For + and translated to UTF-16 or UTF-32 when the utf modifier is set. For testing the 16-bit and 32-bit libraries in non-UTF mode, the utf8_input - modifier can be used. It is mutually exclusive with utf. Input lines + modifier can be used. It is mutually exclusive with utf. Input lines are interpreted as UTF-8 as a means of specifying wide characters. More details are given in "Input encoding" above. Generating long repetitive patterns - Some tests use long patterns that are very repetitive. Instead of cre- - ating a very long input line for such a pattern, you can use a special - repetition feature, similar to the one described for subject lines - above. If the expand modifier is present on a pattern, parts of the + Some tests use long patterns that are very repetitive. Instead of cre- + ating a very long input line for such a pattern, you can use a special + repetition feature, similar to the one described for subject lines + above. If the expand modifier is present on a pattern, parts of the pattern that have the form \[]{} are expanded before the pattern is passed to pcre2_compile(). For exam- ple, \[AB]{6000} is expanded to "ABAB..." 6000 times. This construction - cannot be nested. An initial "\[" sequence is recognized only if "]{" - followed by decimal digits and "}" is found later in the pattern. If + cannot be nested. An initial "\[" sequence is recognized only if "]{" + followed by decimal digits and "}" is found later in the pattern. If not, the characters remain in the pattern unaltered. The expand and hex modifiers are mutually exclusive. - If part of an expanded pattern looks like an expansion, but is really + If part of an expanded pattern looks like an expansion, but is really part of the actual pattern, unwanted expansion can be avoided by giving two values in the quantifier. For example, \[AB]{6000,6000} is not rec- ognized as an expansion item. - If the info modifier is set on an expanded pattern, the result of the + If the info modifier is set on an expanded pattern, the result of the expansion is included in the information that is output. JIT compilation - Just-in-time (JIT) compiling is a heavyweight optimization that can - greatly speed up pattern matching. See the pcre2jit documentation for - details. JIT compiling happens, optionally, after a pattern has been - successfully compiled into an internal form. The JIT compiler converts + Just-in-time (JIT) compiling is a heavyweight optimization that can + greatly speed up pattern matching. See the pcre2jit documentation for + details. JIT compiling happens, optionally, after a pattern has been + successfully compiled into an internal form. The JIT compiler converts this to optimized machine code. It needs to know whether the match-time options PCRE2_PARTIAL_HARD and PCRE2_PARTIAL_SOFT are going to be used, - because different code is generated for the different cases. See the - partial modifier in "Subject Modifiers" below for details of how these + because different code is generated for the different cases. See the + partial modifier in "Subject Modifiers" below for details of how these options are specified for each match attempt. - JIT compilation is requested by the jit pattern modifier, which may + JIT compilation is requested by the jit pattern modifier, which may optionally be followed by an equals sign and a number in the range 0 to - 7. The three bits that make up the number specify which of the three + 7. The three bits that make up the number specify which of the three JIT operating modes are to be compiled: 1 compile JIT code for non-partial matching @@ -782,31 +783,31 @@ PATTERN MODIFIERS 6 soft and hard partial matching only 7 all three modes - If no number is given, 7 is assumed. The phrase "partial matching" + If no number is given, 7 is assumed. The phrase "partial matching" means a call to pcre2_match() with either the PCRE2_PARTIAL_SOFT or the - PCRE2_PARTIAL_HARD option set. Note that such a call may return a com- + PCRE2_PARTIAL_HARD option set. Note that such a call may return a com- plete match; the options enable the possibility of a partial match, but - do not require it. Note also that if you request JIT compilation only - for partial matching (for example, jit=2) but do not set the partial - modifier on a subject line, that match will not use JIT code because + do not require it. Note also that if you request JIT compilation only + for partial matching (for example, jit=2) but do not set the partial + modifier on a subject line, that match will not use JIT code because none was compiled for non-partial matching. - If JIT compilation is successful, the compiled JIT code will automati- - cally be used when an appropriate type of match is run, except when - incompatible run-time options are specified. For more details, see the - pcre2jit documentation. See also the jitstack modifier below for a way + If JIT compilation is successful, the compiled JIT code will automati- + cally be used when an appropriate type of match is run, except when + incompatible run-time options are specified. For more details, see the + pcre2jit documentation. See also the jitstack modifier below for a way of setting the size of the JIT stack. - If the jitfast modifier is specified, matching is done using the JIT - "fast path" interface, pcre2_jit_match(), which skips some of the san- - ity checks that are done by pcre2_match(), and of course does not work - when JIT is not supported. If jitfast is specified without jit, jit=7 + If the jitfast modifier is specified, matching is done using the JIT + "fast path" interface, pcre2_jit_match(), which skips some of the san- + ity checks that are done by pcre2_match(), and of course does not work + when JIT is not supported. If jitfast is specified without jit, jit=7 is assumed. - If the jitverify modifier is specified, information about the compiled - pattern shows whether JIT compilation was or was not successful. If - jitverify is specified without jit, jit=7 is assumed. If JIT compila- - tion is successful when jitverify is set, the text "(JIT)" is added to + If the jitverify modifier is specified, information about the compiled + pattern shows whether JIT compilation was or was not successful. If + jitverify is specified without jit, jit=7 is assumed. If JIT compila- + tion is successful when jitverify is set, the text "(JIT)" is added to the first output line after a match or non match when JIT-compiled code was actually used in the match. @@ -817,19 +818,19 @@ PATTERN MODIFIERS /pattern/locale=fr_FR The given locale is set, pcre2_maketables() is called to build a set of - character tables for the locale, and this is then passed to pcre2_com- - pile() when compiling the regular expression. The same tables are used - when matching the following subject lines. The locale modifier applies + character tables for the locale, and this is then passed to pcre2_com- + pile() when compiling the regular expression. The same tables are used + when matching the following subject lines. The locale modifier applies only to the pattern on which it appears, but can be given in a #pattern - command if a default is needed. Setting a locale and alternate charac- + command if a default is needed. Setting a locale and alternate charac- ter tables are mutually exclusive. Showing pattern memory The memory modifier causes the size in bytes of the memory used to hold - the compiled pattern to be output. This does not include the size of - the pcre2_code block; it is just the actual compiled data. If the pat- - tern is subsequently passed to the JIT compiler, the size of the JIT + the compiled pattern to be output. This does not include the size of + the pcre2_code block; it is just the actual compiled data. If the pat- + tern is subsequently passed to the JIT compiler, the size of the JIT compiled code is also output. Here is an example: re> /a(b)c/jit,memory @@ -839,27 +840,27 @@ PATTERN MODIFIERS Limiting nested parentheses - The parens_nest_limit modifier sets a limit on the depth of nested - parentheses in a pattern. Breaching the limit causes a compilation - error. The default for the library is set when PCRE2 is built, but - pcre2test sets its own default of 220, which is required for running + The parens_nest_limit modifier sets a limit on the depth of nested + parentheses in a pattern. Breaching the limit causes a compilation + error. The default for the library is set when PCRE2 is built, but + pcre2test sets its own default of 220, which is required for running the standard test suite. Limiting the pattern length - The max_pattern_length modifier sets a limit, in code units, to the + The max_pattern_length modifier sets a limit, in code units, to the length of pattern that pcre2_compile() will accept. Breaching the limit - causes a compilation error. The default is the largest number a + causes a compilation error. The default is the largest number a PCRE2_SIZE variable can hold (essentially unlimited). Using the POSIX wrapper API - The posix and posix_nosub modifiers cause pcre2test to call PCRE2 via - the POSIX wrapper API rather than its native API. When posix_nosub is - used, the POSIX option REG_NOSUB is passed to regcomp(). The POSIX - wrapper supports only the 8-bit library. Note that it does not imply + The posix and posix_nosub modifiers cause pcre2test to call PCRE2 via + the POSIX wrapper API rather than its native API. When posix_nosub is + used, the POSIX option REG_NOSUB is passed to regcomp(). The POSIX + wrapper supports only the 8-bit library. Note that it does not imply POSIX matching semantics; for more detail see the pcre2posix documenta- - tion. The following pattern modifiers set options for the regcomp() + tion. The following pattern modifiers set options for the regcomp() function: caseless REG_ICASE @@ -869,39 +870,39 @@ PATTERN MODIFIERS ucp REG_UCP ) the POSIX standard utf REG_UTF8 ) - The regerror_buffsize modifier specifies a size for the error buffer - that is passed to regerror() in the event of a compilation error. For + The regerror_buffsize modifier specifies a size for the error buffer + that is passed to regerror() in the event of a compilation error. For example: /abc/posix,regerror_buffsize=20 - This provides a means of testing the behaviour of regerror() when the - buffer is too small for the error message. If this modifier has not + This provides a means of testing the behaviour of regerror() when the + buffer is too small for the error message. If this modifier has not been set, a large buffer is used. - The aftertext and allaftertext subject modifiers work as described - below. All other modifiers are either ignored, with a warning message, + The aftertext and allaftertext subject modifiers work as described + below. All other modifiers are either ignored, with a warning message, or cause an error. - The pattern is passed to regcomp() as a zero-terminated string by - default, but if the use_length or hex modifiers are set, the REG_PEND + The pattern is passed to regcomp() as a zero-terminated string by + default, but if the use_length or hex modifiers are set, the REG_PEND extension is used to pass it by length. Testing the stack guard feature - The stackguard modifier is used to test the use of pcre2_set_com- - pile_recursion_guard(), a function that is provided to enable stack - availability to be checked during compilation (see the pcre2api docu- - mentation for details). If the number specified by the modifier is + The stackguard modifier is used to test the use of pcre2_set_com- + pile_recursion_guard(), a function that is provided to enable stack + availability to be checked during compilation (see the pcre2api docu- + mentation for details). If the number specified by the modifier is greater than zero, pcre2_set_compile_recursion_guard() is called to set - up callback from pcre2_compile() to a local function. The argument it - receives is the current nesting parenthesis depth; if this is greater + up callback from pcre2_compile() to a local function. The argument it + receives is the current nesting parenthesis depth; if this is greater than the value given by the modifier, non-zero is returned, causing the compilation to be aborted. Using alternative character tables - The value specified for the tables modifier must be one of the digits + The value specified for the tables modifier must be one of the digits 0, 1, or 2. It causes a specific set of built-in character tables to be passed to pcre2_compile(). This is used in the PCRE2 tests to check be- haviour with different character tables. The digit specifies the tables @@ -912,16 +913,16 @@ PATTERN MODIFIERS pcre2_chartables.c.dist 2 a set of tables defining ISO 8859 characters - In table 2, some characters whose codes are greater than 128 are iden- - tified as letters, digits, spaces, etc. Setting alternate character + In table 2, some characters whose codes are greater than 128 are iden- + tified as letters, digits, spaces, etc. Setting alternate character tables and a locale are mutually exclusive. Setting certain match controls The following modifiers are really subject modifiers, and are described - under "Subject Modifiers" below. However, they may be included in a - pattern's modifier list, in which case they are applied to every sub- - ject line that is processed with that pattern. These modifiers do not + under "Subject Modifiers" below. However, they may be included in a + pattern's modifier list, in which case they are applied to every sub- + ject line that is processed with that pattern. These modifiers do not affect the compilation process. aftertext show text after match @@ -939,39 +940,39 @@ PATTERN MODIFIERS substitute_unknown_unset use PCRE2_SUBSTITUTE_UNKNOWN_UNSET substitute_unset_empty use PCRE2_SUBSTITUTE_UNSET_EMPTY - These modifiers may not appear in a #pattern command. If you want them + These modifiers may not appear in a #pattern command. If you want them as defaults, set them in a #subject command. Specifying literal subject lines - If the subject_literal modifier is present on a pattern, all the sub- + If the subject_literal modifier is present on a pattern, all the sub- ject lines that it matches are taken as literal strings, with no inter- - pretation of backslashes. It is not possible to set subject modifiers - on such lines, but any that are set as defaults by a #subject command + pretation of backslashes. It is not possible to set subject modifiers + on such lines, but any that are set as defaults by a #subject command are recognized. Saving a compiled pattern - When a pattern with the push modifier is successfully compiled, it is - pushed onto a stack of compiled patterns, and pcre2test expects the - next line to contain a new pattern (or a command) instead of a subject + When a pattern with the push modifier is successfully compiled, it is + pushed onto a stack of compiled patterns, and pcre2test expects the + next line to contain a new pattern (or a command) instead of a subject line. This facility is used when saving compiled patterns to a file, as - described in the section entitled "Saving and restoring compiled pat- - terns" below. If pushcopy is used instead of push, a copy of the com- - piled pattern is stacked, leaving the original as current, ready to - match the following input lines. This provides a way of testing the - pcre2_code_copy() function. The push and pushcopy modifiers are - incompatible with compilation modifiers such as global that act at - match time. Any that are specified are ignored (for the stacked copy), + described in the section entitled "Saving and restoring compiled pat- + terns" below. If pushcopy is used instead of push, a copy of the com- + piled pattern is stacked, leaving the original as current, ready to + match the following input lines. This provides a way of testing the + pcre2_code_copy() function. The push and pushcopy modifiers are + incompatible with compilation modifiers such as global that act at + match time. Any that are specified are ignored (for the stacked copy), with a warning message, except for replace, which causes an error. Note - that jitverify, which is allowed, does not carry through to any subse- + that jitverify, which is allowed, does not carry through to any subse- quent matching that uses a stacked pattern. Testing foreign pattern conversion - The experimental foreign pattern conversion functions in PCRE2 can be - tested by setting the convert modifier. Its argument is a colon-sepa- - rated list of options, which set the equivalent option for the + The experimental foreign pattern conversion functions in PCRE2 can be + tested by setting the convert modifier. Its argument is a colon-sepa- + rated list of options, which set the equivalent option for the pcre2_pattern_convert() function: glob PCRE2_CONVERT_GLOB @@ -983,19 +984,19 @@ PATTERN MODIFIERS The "unset" value is useful for turning off a default that has been set by a #pattern command. When one of these options is set, the input pat- - tern is passed to pcre2_pattern_convert(). If the conversion is suc- - cessful, the result is reflected in the output and then passed to + tern is passed to pcre2_pattern_convert(). If the conversion is suc- + cessful, the result is reflected in the output and then passed to pcre2_compile(). The normal utf and no_utf_check options, if set, cause - the PCRE2_CONVERT_UTF and PCRE2_CONVERT_NO_UTF_CHECK options to be + the PCRE2_CONVERT_UTF and PCRE2_CONVERT_NO_UTF_CHECK options to be passed to pcre2_pattern_convert(). By default, the conversion function is allowed to allocate a buffer for - its output. However, if the convert_length modifier is set to a value - greater than zero, pcre2test passes a buffer of the given length. This + its output. However, if the convert_length modifier is set to a value + greater than zero, pcre2test passes a buffer of the given length. This makes it possible to test the length check. - The convert_glob_escape and convert_glob_separator modifiers can be - used to specify the escape and separator characters for glob process- + The convert_glob_escape and convert_glob_separator modifiers can be + used to specify the escape and separator characters for glob process- ing, overriding the defaults, which are operating-system dependent. @@ -1006,7 +1007,7 @@ SUBJECT MODIFIERS Setting match options - The following modifiers set options for pcre2_match() or + The following modifiers set options for pcre2_match() or pcre2_dfa_match(). See pcreapi for a description of their effects. anchored set PCRE2_ANCHORED @@ -1022,34 +1023,34 @@ SUBJECT MODIFIERS partial_hard (or ph) set PCRE2_PARTIAL_HARD partial_soft (or ps) set PCRE2_PARTIAL_SOFT - The partial matching modifiers are provided with abbreviations because + The partial matching modifiers are provided with abbreviations because they appear frequently in tests. - If the posix or posix_nosub modifier was present on the pattern, caus- + If the posix or posix_nosub modifier was present on the pattern, caus- ing the POSIX wrapper API to be used, the only option-setting modifiers that have any effect are notbol, notempty, and noteol, causing REG_NOT- - BOL, REG_NOTEMPTY, and REG_NOTEOL, respectively, to be passed to + BOL, REG_NOTEMPTY, and REG_NOTEOL, respectively, to be passed to regexec(). The other modifiers are ignored, with a warning message. - There is one additional modifier that can be used with the POSIX wrap- + There is one additional modifier that can be used with the POSIX wrap- per. It is ignored (with a warning) if used for non-POSIX matching. posix_startend=[:] - This causes the subject string to be passed to regexec() using the - REG_STARTEND option, which uses offsets to specify which part of the - string is searched. If only one number is given, the end offset is - passed as the end of the subject string. For more detail of REG_STAR- - TEND, see the pcre2posix documentation. If the subject string contains - binary zeros (coded as escapes such as \x{00} because pcre2test does + This causes the subject string to be passed to regexec() using the + REG_STARTEND option, which uses offsets to specify which part of the + string is searched. If only one number is given, the end offset is + passed as the end of the subject string. For more detail of REG_STAR- + TEND, see the pcre2posix documentation. If the subject string contains + binary zeros (coded as escapes such as \x{00} because pcre2test does not support actual binary zeros in its input), you must use posix_star- tend to specify its length. Setting match controls - The following modifiers affect the matching process or request addi- - tional information. Some of them may also be specified on a pattern - line (see above), in which case they apply to every subject line that + The following modifiers affect the matching process or request addi- + tional information. Some of them may also be specified on a pattern + line (see above), in which case they apply to every subject line that is matched against that pattern. aftertext show text after match @@ -1091,29 +1092,29 @@ SUBJECT MODIFIERS zero_terminate pass the subject as zero-terminated The effects of these modifiers are described in the following sections. - When matching via the POSIX wrapper API, the aftertext, allaftertext, - and ovector subject modifiers work as described below. All other modi- + When matching via the POSIX wrapper API, the aftertext, allaftertext, + and ovector subject modifiers work as described below. All other modi- fiers are either ignored, with a warning message, or cause an error. Showing more text - The aftertext modifier requests that as well as outputting the part of + The aftertext modifier requests that as well as outputting the part of the subject string that matched the entire pattern, pcre2test should in addition output the remainder of the subject string. This is useful for tests where the subject contains multiple copies of the same substring. - The allaftertext modifier requests the same action for captured sub- + The allaftertext modifier requests the same action for captured sub- strings as well as the main matched substring. In each case the remain- der is output on the following line with a plus character following the capture number. - The allusedtext modifier requests that all the text that was consulted - during a successful pattern match by the interpreter should be shown. - This feature is not supported for JIT matching, and if requested with - JIT it is ignored (with a warning message). Setting this modifier + The allusedtext modifier requests that all the text that was consulted + during a successful pattern match by the interpreter should be shown. + This feature is not supported for JIT matching, and if requested with + JIT it is ignored (with a warning message). Setting this modifier affects the output if there is a lookbehind at the start of a match, or - a lookahead at the end, or if \K is used in the pattern. Characters - that precede or follow the start and end of the actual match are indi- - cated in the output by '<' or '>' characters underneath them. Here is + a lookahead at the end, or if \K is used in the pattern. Characters + that precede or follow the start and end of the actual match are indi- + cated in the output by '<' or '>' characters underneath them. Here is an example: re> /(?<=pqr)abc(?=xyz)/ @@ -1121,16 +1122,16 @@ SUBJECT MODIFIERS 0: pqrabcxyz <<< >>> - This shows that the matched string is "abc", with the preceding and - following strings "pqr" and "xyz" having been consulted during the + This shows that the matched string is "abc", with the preceding and + following strings "pqr" and "xyz" having been consulted during the match (when processing the assertions). - The startchar modifier requests that the starting character for the - match be indicated, if it is different to the start of the matched + The startchar modifier requests that the starting character for the + match be indicated, if it is different to the start of the matched string. The only time when this occurs is when \K has been processed as part of the match. In this situation, the output for the matched string - is displayed from the starting character instead of from the match - point, with circumflex characters under the earlier characters. For + is displayed from the starting character instead of from the match + point, with circumflex characters under the earlier characters. For example: re> /abc\Kxyz/ @@ -1138,7 +1139,7 @@ SUBJECT MODIFIERS 0: abcxyz ^^^ - Unlike allusedtext, the startchar modifier can be used with JIT. How- + Unlike allusedtext, the startchar modifier can be used with JIT. How- ever, these two modifiers are mutually exclusive. Showing the value of all capture groups @@ -1146,78 +1147,78 @@ SUBJECT MODIFIERS The allcaptures modifier requests that the values of all potential cap- tured parentheses be output after a match. By default, only those up to the highest one actually used in the match are output (corresponding to - the return code from pcre2_match()). Groups that did not take part in - the match are output as "". This modifier is not relevant for - DFA matching (which does no capturing); it is ignored, with a warning + the return code from pcre2_match()). Groups that did not take part in + the match are output as "". This modifier is not relevant for + DFA matching (which does no capturing); it is ignored, with a warning message, if present. Testing callouts - A callout function is supplied when pcre2test calls the library match- - ing functions, unless callout_none is specified. Its behaviour can be - controlled by various modifiers listed above whose names begin with + A callout function is supplied when pcre2test calls the library match- + ing functions, unless callout_none is specified. Its behaviour can be + controlled by various modifiers listed above whose names begin with callout_. Details are given in the section entitled "Callouts" below. Finding all matches in a string Searching for all possible matches within a subject can be requested by - the global or altglobal modifier. After finding a match, the matching - function is called again to search the remainder of the subject. The - difference between global and altglobal is that the former uses the - start_offset argument to pcre2_match() or pcre2_dfa_match() to start - searching at a new point within the entire string (which is what Perl + the global or altglobal modifier. After finding a match, the matching + function is called again to search the remainder of the subject. The + difference between global and altglobal is that the former uses the + start_offset argument to pcre2_match() or pcre2_dfa_match() to start + searching at a new point within the entire string (which is what Perl does), whereas the latter passes over a shortened subject. This makes a difference to the matching process if the pattern begins with a lookbe- hind assertion (including \b or \B). - If an empty string is matched, the next match is done with the + If an empty string is matched, the next match is done with the PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED flags set, in order to search for another, non-empty, match at the same point in the subject. If this - match fails, the start offset is advanced, and the normal match is - retried. This imitates the way Perl handles such cases when using the - /g modifier or the split() function. Normally, the start offset is - advanced by one character, but if the newline convention recognizes - CRLF as a newline, and the current character is CR followed by LF, an + match fails, the start offset is advanced, and the normal match is + retried. This imitates the way Perl handles such cases when using the + /g modifier or the split() function. Normally, the start offset is + advanced by one character, but if the newline convention recognizes + CRLF as a newline, and the current character is CR followed by LF, an advance of two characters occurs. Testing substring extraction functions - The copy and get modifiers can be used to test the pcre2_sub- + The copy and get modifiers can be used to test the pcre2_sub- string_copy_xxx() and pcre2_substring_get_xxx() functions. They can be - given more than once, and each can specify a group name or number, for + given more than once, and each can specify a group name or number, for example: abcd\=copy=1,copy=3,get=G1 - If the #subject command is used to set default copy and/or get lists, - these can be unset by specifying a negative number to cancel all num- + If the #subject command is used to set default copy and/or get lists, + these can be unset by specifying a negative number to cancel all num- bered groups and an empty name to cancel all named groups. - The getall modifier tests pcre2_substring_list_get(), which extracts + The getall modifier tests pcre2_substring_list_get(), which extracts all captured substrings. - If the subject line is successfully matched, the substrings extracted - by the convenience functions are output with C, G, or L after the - string number instead of a colon. This is in addition to the normal - full list. The string length (that is, the return from the extraction + If the subject line is successfully matched, the substrings extracted + by the convenience functions are output with C, G, or L after the + string number instead of a colon. This is in addition to the normal + full list. The string length (that is, the return from the extraction function) is given in parentheses after each substring, followed by the name when the extraction was by name. Testing the substitution function - If the replace modifier is set, the pcre2_substitute() function is - called instead of one of the matching functions. Note that replacement - strings cannot contain commas, because a comma signifies the end of a + If the replace modifier is set, the pcre2_substitute() function is + called instead of one of the matching functions. Note that replacement + strings cannot contain commas, because a comma signifies the end of a modifier. This is not thought to be an issue in a test program. - Unlike subject strings, pcre2test does not process replacement strings - for escape sequences. In UTF mode, a replacement string is checked to - see if it is a valid UTF-8 string. If so, it is correctly converted to - a UTF string of the appropriate code unit width. If it is not a valid - UTF-8 string, the individual code units are copied directly. This pro- + Unlike subject strings, pcre2test does not process replacement strings + for escape sequences. In UTF mode, a replacement string is checked to + see if it is a valid UTF-8 string. If so, it is correctly converted to + a UTF string of the appropriate code unit width. If it is not a valid + UTF-8 string, the individual code units are copied directly. This pro- vides a means of passing an invalid UTF-8 string for testing purposes. - The following modifiers set options (in additional to the normal match + The following modifiers set options (in additional to the normal match options) for pcre2_substitute(): global PCRE2_SUBSTITUTE_GLOBAL @@ -1227,8 +1228,8 @@ SUBJECT MODIFIERS substitute_unset_empty PCRE2_SUBSTITUTE_UNSET_EMPTY - After a successful substitution, the modified string is output, pre- - ceded by the number of replacements. This may be zero if there were no + After a successful substitution, the modified string is output, pre- + ceded by the number of replacements. This may be zero if there were no matches. Here is a simple example of a substitution test: /abc/replace=xxx @@ -1237,12 +1238,12 @@ SUBJECT MODIFIERS =abc=abc=\=global 2: =xxx=xxx= - Subject and replacement strings should be kept relatively short (fewer - than 256 characters) for substitution tests, as fixed-size buffers are - used. To make it easy to test for buffer overflow, if the replacement - string starts with a number in square brackets, that number is passed - to pcre2_substitute() as the size of the output buffer, with the - replacement string starting at the next character. Here is an example + Subject and replacement strings should be kept relatively short (fewer + than 256 characters) for substitution tests, as fixed-size buffers are + used. To make it easy to test for buffer overflow, if the replacement + string starts with a number in square brackets, that number is passed + to pcre2_substitute() as the size of the output buffer, with the + replacement string starting at the next character. Here is an example that tests the edge case: /abc/ @@ -1251,11 +1252,11 @@ SUBJECT MODIFIERS 123abc123\=replace=[9]XYZ Failed: error -47: no more memory - The default action of pcre2_substitute() is to return - PCRE2_ERROR_NOMEMORY when the output buffer is too small. However, if - the PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option is set (by using the sub- - stitute_overflow_length modifier), pcre2_substitute() continues to go - through the motions of matching and substituting, in order to compute + The default action of pcre2_substitute() is to return + PCRE2_ERROR_NOMEMORY when the output buffer is too small. However, if + the PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option is set (by using the sub- + stitute_overflow_length modifier), pcre2_substitute() continues to go + through the motions of matching and substituting, in order to compute the size of buffer that is required. When this happens, pcre2test shows the required buffer length (which includes space for the trailing zero) as part of the error message. For example: @@ -1265,165 +1266,165 @@ SUBJECT MODIFIERS Failed: error -47: no more memory: 10 code units are needed A replacement string is ignored with POSIX and DFA matching. Specifying - partial matching provokes an error return ("bad option value") from + partial matching provokes an error return ("bad option value") from pcre2_substitute(). Setting the JIT stack size - The jitstack modifier provides a way of setting the maximum stack size - that is used by the just-in-time optimization code. It is ignored if - JIT optimization is not being used. The value is a number of kilobytes. - Setting zero reverts to the default of 32K. Providing a stack that is - larger than the default is necessary only for very complicated pat- - terns. If jitstack is set non-zero on a subject line it overrides any - value that was set on the pattern. + The jitstack modifier provides a way of setting the maximum stack size + that is used by the just-in-time optimization code. It is ignored if + JIT optimization is not being used. The value is a number of kibibytes + (units of 1024 bytes). Setting zero reverts to the default of 32KiB. + Providing a stack that is larger than the default is necessary only for + very complicated patterns. If jitstack is set non-zero on a subject + line it overrides any value that was set on the pattern. Setting heap, match, and depth limits - The heap_limit, match_limit, and depth_limit modifiers set the appro- - priate limits in the match context. These values are ignored when the + The heap_limit, match_limit, and depth_limit modifiers set the appro- + priate limits in the match context. These values are ignored when the find_limits modifier is specified. Finding minimum limits - If the find_limits modifier is present on a subject line, pcre2test - calls the relevant matching function several times, setting different - values in the match context via pcre2_set_heap_limit(), - pcre2_set_match_limit(), or pcre2_set_depth_limit() until it finds the - minimum values for each parameter that allows the match to complete + If the find_limits modifier is present on a subject line, pcre2test + calls the relevant matching function several times, setting different + values in the match context via pcre2_set_heap_limit(), + pcre2_set_match_limit(), or pcre2_set_depth_limit() until it finds the + minimum values for each parameter that allows the match to complete without error. If JIT is being used, only the match limit is relevant. When using this modifier, the pattern should not contain any limit set- - tings such as (*LIMIT_MATCH=...) within it. If such a setting is + tings such as (*LIMIT_MATCH=...) within it. If such a setting is present and is lower than the minimum matching value, the minimum value - cannot be found because pcre2_set_match_limit() etc. are only able to + cannot be found because pcre2_set_match_limit() etc. are only able to reduce the value of an in-pattern limit; they cannot increase it. - For non-DFA matching, the minimum depth_limit number is a measure of + For non-DFA matching, the minimum depth_limit number is a measure of how much nested backtracking happens (that is, how deeply the pattern's - tree is searched). In the case of DFA matching, depth_limit controls - the depth of recursive calls of the internal function that is used for + tree is searched). In the case of DFA matching, depth_limit controls + the depth of recursive calls of the internal function that is used for handling pattern recursion, lookaround assertions, and atomic groups. For non-DFA matching, the match_limit number is a measure of the amount of backtracking that takes place, and learning the minimum value can be - instructive. For most simple matches, the number is quite small, but - for patterns with very large numbers of matching possibilities, it can - become large very quickly with increasing length of subject string. In - the case of DFA matching, match_limit controls the total number of + instructive. For most simple matches, the number is quite small, but + for patterns with very large numbers of matching possibilities, it can + become large very quickly with increasing length of subject string. In + the case of DFA matching, match_limit controls the total number of calls, both recursive and non-recursive, to the internal matching func- tion, thus controlling the overall amount of computing resource that is used. - For both kinds of matching, the heap_limit number (which is in kilo- - bytes) limits the amount of heap memory used for matching. A value of - zero disables the use of any heap memory; many simple pattern matches - can be done without using the heap, so this is not an unreasonable set- - ting. + For both kinds of matching, the heap_limit number, which is in + kibibytes (units of 1024 bytes), limits the amount of heap memory used + for matching. A value of zero disables the use of any heap memory; many + simple pattern matches can be done without using the heap, so zero is + not an unreasonable setting. Showing MARK names The mark modifier causes the names from backtracking control verbs that - are returned from calls to pcre2_match() to be displayed. If a mark is - returned for a match, non-match, or partial match, pcre2test shows it. - For a match, it is on a line by itself, tagged with "MK:". Otherwise, + are returned from calls to pcre2_match() to be displayed. If a mark is + returned for a match, non-match, or partial match, pcre2test shows it. + For a match, it is on a line by itself, tagged with "MK:". Otherwise, it is added to the non-match message. Showing memory usage - The memory modifier causes pcre2test to log the sizes of all heap mem- - ory allocation and freeing calls that occur during a call to - pcre2_match() or pcre2_dfa_match(). These occur only when a match - requires a bigger vector than the default for remembering backtracking - points (pcre2_match()) or for internal workspace (pcre2_dfa_match()). - In many cases there will be no heap memory used and therefore no addi- + The memory modifier causes pcre2test to log the sizes of all heap mem- + ory allocation and freeing calls that occur during a call to + pcre2_match() or pcre2_dfa_match(). These occur only when a match + requires a bigger vector than the default for remembering backtracking + points (pcre2_match()) or for internal workspace (pcre2_dfa_match()). + In many cases there will be no heap memory used and therefore no addi- tional output. No heap memory is allocated during matching with JIT, so - in that case the memory modifier never has any effect. For this modi- - fier to work, the null_context modifier must not be set on both the + in that case the memory modifier never has any effect. For this modi- + fier to work, the null_context modifier must not be set on both the pattern and the subject, though it can be set on one or the other. Setting a starting offset - The offset modifier sets an offset in the subject string at which + The offset modifier sets an offset in the subject string at which matching starts. Its value is a number of code units, not characters. Setting an offset limit - The offset_limit modifier sets a limit for unanchored matches. If a + The offset_limit modifier sets a limit for unanchored matches. If a match cannot be found starting at or before this offset in the subject, a "no match" return is given. The data value is a number of code units, - not characters. When this modifier is used, the use_offset_limit modi- + not characters. When this modifier is used, the use_offset_limit modi- fier must have been set for the pattern; if not, an error is generated. Setting the size of the output vector - The ovector modifier applies only to the subject line in which it - appears, though of course it can also be used to set a default in a - #subject command. It specifies the number of pairs of offsets that are + The ovector modifier applies only to the subject line in which it + appears, though of course it can also be used to set a default in a + #subject command. It specifies the number of pairs of offsets that are available for storing matching information. The default is 15. - A value of zero is useful when testing the POSIX API because it causes + A value of zero is useful when testing the POSIX API because it causes regexec() to be called with a NULL capture vector. When not testing the - POSIX API, a value of zero is used to cause pcre2_match_data_cre- - ate_from_pattern() to be called, in order to create a match block of + POSIX API, a value of zero is used to cause pcre2_match_data_cre- + ate_from_pattern() to be called, in order to create a match block of exactly the right size for the pattern. (It is not possible to create a - match block with a zero-length ovector; there is always at least one + match block with a zero-length ovector; there is always at least one pair of offsets.) Passing the subject as zero-terminated By default, the subject string is passed to a native API matching func- tion with its correct length. In order to test the facility for passing - a zero-terminated string, the zero_terminate modifier is provided. It - causes the length to be passed as PCRE2_ZERO_TERMINATED. When matching + a zero-terminated string, the zero_terminate modifier is provided. It + causes the length to be passed as PCRE2_ZERO_TERMINATED. When matching via the POSIX interface, this modifier is ignored, with a warning. - When testing pcre2_substitute(), this modifier also has the effect of + When testing pcre2_substitute(), this modifier also has the effect of passing the replacement string as zero-terminated. Passing a NULL context - Normally, pcre2test passes a context block to pcre2_match(), + Normally, pcre2test passes a context block to pcre2_match(), pcre2_dfa_match() or pcre2_jit_match(). If the null_context modifier is - set, however, NULL is passed. This is for testing that the matching + set, however, NULL is passed. This is for testing that the matching functions behave correctly in this case (they use default values). This - modifier cannot be used with the find_limits modifier or when testing + modifier cannot be used with the find_limits modifier or when testing the substitution function. THE ALTERNATIVE MATCHING FUNCTION - By default, pcre2test uses the standard PCRE2 matching function, + By default, pcre2test uses the standard PCRE2 matching function, pcre2_match() to match each subject line. PCRE2 also supports an alter- - native matching function, pcre2_dfa_match(), which operates in a dif- - ferent way, and has some restrictions. The differences between the two + native matching function, pcre2_dfa_match(), which operates in a dif- + ferent way, and has some restrictions. The differences between the two functions are described in the pcre2matching documentation. - If the dfa modifier is set, the alternative matching function is used. - This function finds all possible matches at a given point in the sub- - ject. If, however, the dfa_shortest modifier is set, processing stops - after the first match is found. This is always the shortest possible + If the dfa modifier is set, the alternative matching function is used. + This function finds all possible matches at a given point in the sub- + ject. If, however, the dfa_shortest modifier is set, processing stops + after the first match is found. This is always the shortest possible match. DEFAULT OUTPUT FROM pcre2test - This section describes the output when the normal matching function, + This section describes the output when the normal matching function, pcre2_match(), is being used. - When a match succeeds, pcre2test outputs the list of captured sub- - strings, starting with number 0 for the string that matched the whole - pattern. Otherwise, it outputs "No match" when the return is - PCRE2_ERROR_NOMATCH, or "Partial match:" followed by the partially - matching substring when the return is PCRE2_ERROR_PARTIAL. (Note that - this is the entire substring that was inspected during the partial - match; it may include characters before the actual match start if a + When a match succeeds, pcre2test outputs the list of captured sub- + strings, starting with number 0 for the string that matched the whole + pattern. Otherwise, it outputs "No match" when the return is + PCRE2_ERROR_NOMATCH, or "Partial match:" followed by the partially + matching substring when the return is PCRE2_ERROR_PARTIAL. (Note that + this is the entire substring that was inspected during the partial + match; it may include characters before the actual match start if a lookbehind assertion, \K, \b, or \B was involved.) For any other return, pcre2test outputs the PCRE2 negative error number - and a short descriptive phrase. If the error is a failed UTF string - check, the code unit offset of the start of the failing character is + and a short descriptive phrase. If the error is a failed UTF string + check, the code unit offset of the start of the failing character is also output. Here is an example of an interactive pcre2test run. $ pcre2test @@ -1439,8 +1440,8 @@ DEFAULT OUTPUT FROM pcre2test Unset capturing substrings that are not followed by one that is set are not shown by pcre2test unless the allcaptures modifier is specified. In the following example, there are two capturing substrings, but when the - first data line is matched, the second, unset substring is not shown. - An "internal" unset substring is shown as "", as for the second + first data line is matched, the second, unset substring is not shown. + An "internal" unset substring is shown as "", as for the second data line. re> /(a)|(b)/ @@ -1452,11 +1453,11 @@ DEFAULT OUTPUT FROM pcre2test 1: 2: b - If the strings contain any non-printing characters, they are output as - \xhh escapes if the value is less than 256 and UTF mode is not set. + If the strings contain any non-printing characters, they are output as + \xhh escapes if the value is less than 256 and UTF mode is not set. Otherwise they are output as \x{hh...} escapes. See below for the defi- - nition of non-printing characters. If the aftertext modifier is set, - the output for substring 0 is followed by the the rest of the subject + nition of non-printing characters. If the aftertext modifier is set, + the output for substring 0 is followed by the the rest of the subject string, identified by "0+" like this: re> /cat/aftertext @@ -1464,7 +1465,7 @@ DEFAULT OUTPUT FROM pcre2test 0: cat 0+ aract - If global matching is requested, the results of successive matching + If global matching is requested, the results of successive matching attempts are output in sequence, like this: re> /\Bi(\w\w)/g @@ -1476,8 +1477,8 @@ DEFAULT OUTPUT FROM pcre2test 0: ipp 1: pp - "No match" is output only if the first match attempt fails. Here is an - example of a failure message (the offset 4 that is specified by the + "No match" is output only if the first match attempt fails. Here is an + example of a failure message (the offset 4 that is specified by the offset modifier is past the end of the subject string): re> /xyz/ @@ -1485,7 +1486,7 @@ DEFAULT OUTPUT FROM pcre2test Error -24 (bad offset value) Note that whereas patterns can be continued over several lines (a plain - ">" prompt is used for continuations), subject lines may not. However + ">" prompt is used for continuations), subject lines may not. However newlines can be included in a subject by means of the \n escape (or \r, \r\n, etc., depending on the newline sequence setting). @@ -1493,7 +1494,7 @@ DEFAULT OUTPUT FROM pcre2test OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION When the alternative matching function, pcre2_dfa_match(), is used, the - output consists of a list of all the matches that start at the first + output consists of a list of all the matches that start at the first point in the subject where there is at least one match. For example: re> /(tang|tangerine|tan)/ @@ -1502,11 +1503,11 @@ OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION 1: tang 2: tan - Using the normal matching function on this data finds only "tang". The - longest matching string is always given first (and numbered zero). - After a PCRE2_ERROR_PARTIAL return, the output is "Partial match:", - followed by the partially matching substring. Note that this is the - entire substring that was inspected during the partial match; it may + Using the normal matching function on this data finds only "tang". The + longest matching string is always given first (and numbered zero). + After a PCRE2_ERROR_PARTIAL return, the output is "Partial match:", + followed by the partially matching substring. Note that this is the + entire substring that was inspected during the partial match; it may include characters before the actual match start if a lookbehind asser- tion, \b, or \B was involved. (\K is not supported for DFA matching.) @@ -1522,16 +1523,16 @@ OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION 1: tan 0: tan - The alternative matching function does not support substring capture, - so the modifiers that are concerned with captured substrings are not + The alternative matching function does not support substring capture, + so the modifiers that are concerned with captured substrings are not relevant. RESTARTING AFTER A PARTIAL MATCH - When the alternative matching function has given the PCRE2_ERROR_PAR- + When the alternative matching function has given the PCRE2_ERROR_PAR- TIAL return, indicating that the subject partially matched the pattern, - you can restart the match with additional subject data by means of the + you can restart the match with additional subject data by means of the dfa_restart modifier. For example: re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/ @@ -1540,37 +1541,37 @@ RESTARTING AFTER A PARTIAL MATCH data> n05\=dfa,dfa_restart 0: n05 - For further information about partial matching, see the pcre2partial + For further information about partial matching, see the pcre2partial documentation. CALLOUTS If the pattern contains any callout requests, pcre2test's callout func- - tion is called during matching unless callout_none is specified. This + tion is called during matching unless callout_none is specified. This works with both matching functions, and with JIT, though there are some - differences in behaviour. The output for callouts with numerical argu- + differences in behaviour. The output for callouts with numerical argu- ments and those with string arguments is slightly different. Callouts with numerical arguments By default, the callout function displays the callout number, the start - and current positions in the subject text at the callout time, and the + and current positions in the subject text at the callout time, and the next pattern item to be tested. For example: --->pqrabcdef 0 ^ ^ \d - This output indicates that callout number 0 occurred for a match - attempt starting at the fourth character of the subject string, when - the pointer was at the seventh character, and when the next pattern - item was \d. Just one circumflex is output if the start and current - positions are the same, or if the current position precedes the start + This output indicates that callout number 0 occurred for a match + attempt starting at the fourth character of the subject string, when + the pointer was at the seventh character, and when the next pattern + item was \d. Just one circumflex is output if the start and current + positions are the same, or if the current position precedes the start position, which can happen if the callout is in a lookbehind assertion. Callouts numbered 255 are assumed to be automatic callouts, inserted as a result of the auto_callout pattern modifier. In this case, instead of - showing the callout number, the offset in the pattern, preceded by a + showing the callout number, the offset in the pattern, preceded by a plus, is output. For example: re> /\d?[A-E]\*/auto_callout @@ -1583,7 +1584,7 @@ CALLOUTS 0: E* If a pattern contains (*MARK) items, an additional line is output when- - ever a change of latest mark is passed to the callout function. For + ever a change of latest mark is passed to the callout function. For example: re> /a(*MARK:X)bc/auto_callout @@ -1597,17 +1598,17 @@ CALLOUTS +12 ^ ^ 0: abc - The mark changes between matching "a" and "b", but stays the same for - the rest of the match, so nothing more is output. If, as a result of - backtracking, the mark reverts to being unset, the text "" is + The mark changes between matching "a" and "b", but stays the same for + the rest of the match, so nothing more is output. If, as a result of + backtracking, the mark reverts to being unset, the text "" is output. Callouts with string arguments The output for a callout with a string argument is similar, except that - instead of outputting a callout number before the position indicators, - the callout string and its offset in the pattern string are output - before the reflection of the subject string, and the subject string is + instead of outputting a callout number before the position indicators, + the callout string and its offset in the pattern string are output + before the reflection of the subject string, and the subject string is reflected for each callout. For example: re> /^ab(?C'first')cd(?C"second")ef/ @@ -1623,26 +1624,26 @@ CALLOUTS Callout modifiers - The callout function in pcre2test returns zero (carry on matching) by - default, but you can use a callout_fail modifier in a subject line to + The callout function in pcre2test returns zero (carry on matching) by + default, but you can use a callout_fail modifier in a subject line to change this and other parameters of the callout (see below). If the callout_capture modifier is set, the current captured groups are output when a callout occurs. This is useful only for non-DFA matching, - as pcre2_dfa_match() does not support capturing, so no captures are + as pcre2_dfa_match() does not support capturing, so no captures are ever shown. The normal callout output, showing the callout number or pattern offset - (as described above) is suppressed if the callout_no_where modifier is + (as described above) is suppressed if the callout_no_where modifier is set. - When using the interpretive matching function pcre2_match() without - JIT, setting the callout_extra modifier causes additional output from - pcre2test's callout function to be generated. For the first callout in - a match attempt at a new starting position in the subject, "New match - attempt" is output. If there has been a backtrack since the last call- + When using the interpretive matching function pcre2_match() without + JIT, setting the callout_extra modifier causes additional output from + pcre2test's callout function to be generated. For the first callout in + a match attempt at a new starting position in the subject, "New match + attempt" is output. If there has been a backtrack since the last call- out (or start of matching if this is the first callout), "Backtrack" is - output, followed by "No other matching paths" if the backtrack ended + output, followed by "No other matching paths" if the backtrack ended the previous match attempt. For example: re> /(a+)b/auto_callout,no_start_optimize,no_auto_possess @@ -1679,82 +1680,82 @@ CALLOUTS +1 ^ a+ No match - Notice that various optimizations must be turned off if you want all - possible matching paths to be scanned. If no_start_optimize is not - used, there is an immediate "no match", without any callouts, because - the starting optimization fails to find "b" in the subject, which it - knows must be present for any match. If no_auto_possess is not used, - the "a+" item is turned into "a++", which reduces the number of back- + Notice that various optimizations must be turned off if you want all + possible matching paths to be scanned. If no_start_optimize is not + used, there is an immediate "no match", without any callouts, because + the starting optimization fails to find "b" in the subject, which it + knows must be present for any match. If no_auto_possess is not used, + the "a+" item is turned into "a++", which reduces the number of back- tracks. - The callout_extra modifier has no effect if used with the DFA matching + The callout_extra modifier has no effect if used with the DFA matching function, or with JIT. Return values from callouts - The default return from the callout function is zero, which allows + The default return from the callout function is zero, which allows matching to continue. The callout_fail modifier can be given one or two numbers. If there is only one number, 1 is returned instead of 0 (caus- ing matching to backtrack) when a callout of that number is reached. If - two numbers (:) are given, 1 is returned when callout is - reached and there have been at least callouts. The callout_error + two numbers (:) are given, 1 is returned when callout is + reached and there have been at least callouts. The callout_error modifier is similar, except that PCRE2_ERROR_CALLOUT is returned, caus- - ing the entire matching process to be aborted. If both these modifiers - are set for the same callout number, callout_error takes precedence. - Note that callouts with string arguments are always given the number + ing the entire matching process to be aborted. If both these modifiers + are set for the same callout number, callout_error takes precedence. + Note that callouts with string arguments are always given the number zero. - The callout_data modifier can be given an unsigned or a negative num- - ber. This is set as the "user data" that is passed to the matching - function, and passed back when the callout function is invoked. Any - value other than zero is used as a return from pcre2test's callout + The callout_data modifier can be given an unsigned or a negative num- + ber. This is set as the "user data" that is passed to the matching + function, and passed back when the callout function is invoked. Any + value other than zero is used as a return from pcre2test's callout function. Inserting callouts can be helpful when using pcre2test to check compli- - cated regular expressions. For further information about callouts, see + cated regular expressions. For further information about callouts, see the pcre2callout documentation. NON-PRINTING CHARACTERS When pcre2test is outputting text in the compiled version of a pattern, - bytes other than 32-126 are always treated as non-printing characters + bytes other than 32-126 are always treated as non-printing characters and are therefore shown as hex escapes. - When pcre2test is outputting text that is a matched part of a subject - string, it behaves in the same way, unless a different locale has been - set for the pattern (using the locale modifier). In this case, the - isprint() function is used to distinguish printing and non-printing + When pcre2test is outputting text that is a matched part of a subject + string, it behaves in the same way, unless a different locale has been + set for the pattern (using the locale modifier). In this case, the + isprint() function is used to distinguish printing and non-printing characters. SAVING AND RESTORING COMPILED PATTERNS - It is possible to save compiled patterns on disc or elsewhere, and + It is possible to save compiled patterns on disc or elsewhere, and reload them later, subject to a number of restrictions. JIT data cannot - be saved. The host on which the patterns are reloaded must be running + be saved. The host on which the patterns are reloaded must be running the same version of PCRE2, with the same code unit width, and must also - have the same endianness, pointer width and PCRE2_SIZE type. Before - compiled patterns can be saved they must be serialized, that is, con- - verted to a stream of bytes. A single byte stream may contain any num- - ber of compiled patterns, but they must all use the same character + have the same endianness, pointer width and PCRE2_SIZE type. Before + compiled patterns can be saved they must be serialized, that is, con- + verted to a stream of bytes. A single byte stream may contain any num- + ber of compiled patterns, but they must all use the same character tables. A single copy of the tables is included in the byte stream (its size is 1088 bytes). - The functions whose names begin with pcre2_serialize_ are used for - serializing and de-serializing. They are described in the pcre2serial- + The functions whose names begin with pcre2_serialize_ are used for + serializing and de-serializing. They are described in the pcre2serial- ize documentation. In this section we describe the features of pcre2test that can be used to test these functions. - When a pattern with push modifier is successfully compiled, it is - pushed onto a stack of compiled patterns, and pcre2test expects the - next line to contain a new pattern (or command) instead of a subject - line. By contrast, the pushcopy modifier causes a copy of the compiled - pattern to be stacked, leaving the original available for immediate - matching. By using push and/or pushcopy, a number of patterns can be + When a pattern with push modifier is successfully compiled, it is + pushed onto a stack of compiled patterns, and pcre2test expects the + next line to contain a new pattern (or command) instead of a subject + line. By contrast, the pushcopy modifier causes a copy of the compiled + pattern to be stacked, leaving the original available for immediate + matching. By using push and/or pushcopy, a number of patterns can be compiled and retained. These modifiers are incompatible with posix, and - control modifiers that act at match time are ignored (with a message) - for the stacked patterns. The jitverify modifier applies only at com- + control modifiers that act at match time are ignored (with a message) + for the stacked patterns. The jitverify modifier applies only at com- pile time. The command @@ -1762,21 +1763,21 @@ SAVING AND RESTORING COMPILED PATTERNS #save causes all the stacked patterns to be serialized and the result written - to the named file. Afterwards, all the stacked patterns are freed. The + to the named file. Afterwards, all the stacked patterns are freed. The command #load - reads the data in the file, and then arranges for it to be de-serial- - ized, with the resulting compiled patterns added to the pattern stack. - The pattern on the top of the stack can be retrieved by the #pop com- - mand, which must be followed by lines of subjects that are to be - matched with the pattern, terminated as usual by an empty line or end - of file. This command may be followed by a modifier list containing - only control modifiers that act after a pattern has been compiled. In + reads the data in the file, and then arranges for it to be de-serial- + ized, with the resulting compiled patterns added to the pattern stack. + The pattern on the top of the stack can be retrieved by the #pop com- + mand, which must be followed by lines of subjects that are to be + matched with the pattern, terminated as usual by an empty line or end + of file. This command may be followed by a modifier list containing + only control modifiers that act after a pattern has been compiled. In particular, hex, posix, posix_nosub, push, and pushcopy are not - allowed, nor are any option-setting modifiers. The JIT modifiers are, - however permitted. Here is an example that saves and reloads two pat- + allowed, nor are any option-setting modifiers. The JIT modifiers are, + however permitted. Here is an example that saves and reloads two pat- terns. /abc/push @@ -1789,10 +1790,10 @@ SAVING AND RESTORING COMPILED PATTERNS #pop jit,bincode abc - If jitverify is used with #pop, it does not automatically imply jit, + If jitverify is used with #pop, it does not automatically imply jit, which is different behaviour from when it is used on a pattern. - The #popcopy command is analagous to the pushcopy modifier in that it + The #popcopy command is analagous to the pushcopy modifier in that it makes current a copy of the topmost stack pattern, leaving the original still on the stack. diff --git a/doc/pcre2unicode.3 b/doc/pcre2unicode.3 index 813fadf..fdaddc4 100644 --- a/doc/pcre2unicode.3 +++ b/doc/pcre2unicode.3 @@ -46,7 +46,7 @@ compatibility with Perl 5.6. PCRE2 does not support this. .SH "WIDE CHARACTERS AND UTF MODES" .rs .sp -Codepoints less than 256 can be specified in patterns by either braced or +Code points less than 256 can be specified in patterns by either braced or unbraced hexadecimal escape sequences (for example, \ex{b3} or \exb3). Larger values have to use braced sequences. Unbraced octal code points up to \e777 are also recognized; larger ones can be coded using \eo{...}. @@ -109,7 +109,7 @@ not PCRE2_UCP is set. Case-insensitive matching in a UTF mode makes use of Unicode properties except for characters whose code points are less than 128 and that have at most two case-equivalent values. For these, a direct table lookup is used for speed. A -few Unicode characters such as Greek sigma have more than two codepoints that +few Unicode characters such as Greek sigma have more than two code points that are case-equivalent, and these are treated as such. . . diff --git a/perltest.sh b/perltest.sh index 1a7679a..6e4f44a 100755 --- a/perltest.sh +++ b/perltest.sh @@ -51,7 +51,7 @@ fi # utf invoke UTF-8 functionality # # The data lines must not have any pcre2test modifiers. Unless -# "subject_litersl" is on the pattern, data lines are processed as +# "subject_literal" is on the pattern, data lines are processed as # Perl double-quoted strings, so if they contain " $ or @ characters, these # have to be escaped. For this reason, all such characters in the # Perl-compatible testinput1 and testinput4 files are escaped so that they can diff --git a/src/config.h.generic b/src/config.h.generic index f738616..97e63f7 100644 --- a/src/config.h.generic +++ b/src/config.h.generic @@ -132,8 +132,9 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define to 1 if you have the header file. */ /* #undef HAVE_ZLIB_H */ -/* This limits the amount of memory that pcre2_match() may use while matching - a pattern. The value is in kilobytes. */ +/* This limits the amount of memory that may be used while matching a pattern. + It applies to both pcre2_match() and pcre2_dfa_match(). It does not apply + to JIT matching. The value is in kilobytes. */ #ifndef HEAP_LIMIT #define HEAP_LIMIT 20000000 #endif @@ -155,7 +156,8 @@ sure both macros are undefined; an emulation function will then be used. */ /* The value of MATCH_LIMIT determines the default number of times the pcre2_match() function can record a backtrack position during a single - matching attempt. There is a runtime interface for setting a different + matching attempt. The value is also used to limit a loop counter in + pcre2_dfa_match(). There is a runtime interface for setting a different limit. The limit exists in order to catch runaway regular expressions that take for ever to determine that they do not match. The default is set very large so that it does not accidentally catch legitimate cases. */ @@ -170,7 +172,9 @@ sure both macros are undefined; an emulation function will then be used. */ MATCH_LIMIT_DEPTH provides this facility. To have any useful effect, it must be less than the value of MATCH_LIMIT. The default is to use the same value as MATCH_LIMIT. There is a runtime method for setting a different - limit. */ + limit. In the case of pcre2_dfa_match(), this limit controls the depth of + the internal nested function calls that are used for pattern recursions, + lookarounds, and atomic groups. */ #ifndef MATCH_LIMIT_DEPTH #define MATCH_LIMIT_DEPTH MATCH_LIMIT #endif @@ -210,7 +214,7 @@ sure both macros are undefined; an emulation function will then be used. */ #define PACKAGE_NAME "PCRE2" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "PCRE2 10.31" +#define PACKAGE_STRING "PCRE2 10.32-RC1" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "pcre2" @@ -219,7 +223,7 @@ sure both macros are undefined; an emulation function will then be used. */ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "10.31" +#define PACKAGE_VERSION "10.32-RC1" /* The value of PARENS_NEST_LIMIT specifies the maximum depth of nested parentheses (of any kind) in a pattern. This limits the amount of system @@ -339,7 +343,7 @@ sure both macros are undefined; an emulation function will then be used. */ #endif /* Version number of package */ -#define VERSION "10.31" +#define VERSION "10.32-RC1" /* Define to 1 if on MINIX. */ /* #undef _MINIX */ diff --git a/src/config.h.in b/src/config.h.in index 14b48e9..56d15fa 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -134,7 +134,7 @@ sure both macros are undefined; an emulation function will then be used. */ /* This limits the amount of memory that may be used while matching a pattern. It applies to both pcre2_match() and pcre2_dfa_match(). It does not apply - to JIT matching. The value is in kilobytes. */ + to JIT matching. The value is in kibibytes (units of 1024 bytes). */ #undef HEAP_LIMIT /* The value of LINK_SIZE determines the number of bytes used to store links diff --git a/src/pcre2.h.generic b/src/pcre2.h.generic index fffcc30..6ed08ef 100644 --- a/src/pcre2.h.generic +++ b/src/pcre2.h.generic @@ -42,9 +42,9 @@ POSSIBILITY OF SUCH DAMAGE. /* The current PCRE version information. */ #define PCRE2_MAJOR 10 -#define PCRE2_MINOR 31 -#define PCRE2_PRERELEASE -#define PCRE2_DATE 2018-02-12 +#define PCRE2_MINOR 32 +#define PCRE2_PRERELEASE -RC1 +#define PCRE2_DATE 2018-02-19 /* When an application links to a PCRE DLL in Windows, the symbols that are imported have to be identified as such. When building PCRE2, the appropriate diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index 87530fb..5fc60f0 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -4261,11 +4261,11 @@ goto FAILED; /************************************************* -* Find first significant op code * +* Find first significant opcode * *************************************************/ /* This is called by several functions that scan a compiled expression looking -for a fixed first character, or an anchoring op code etc. It skips over things +for a fixed first character, or an anchoring opcode etc. It skips over things that do not influence this. For some calls, it makes sense to skip negative forward and all backward assertions, and also the \b assertion; for others it does not. @@ -5472,7 +5472,7 @@ for (;; pptr++) set xclass = TRUE. Then, in the pre-compile phase, accumulate the length of the extra data and reset the pointer. This is so that very large classes that contain a zillion wide characters or Unicode property tests - do not overwrite the work space (which is on the stack). */ + do not overwrite the workspace (which is on the stack). */ if (class_uchardata > class_uchardata_base) { @@ -7460,7 +7460,7 @@ length of the BRA and KET and any extra code units that are required at the beginning. We accumulate in a local variable to save frequent testing of lengthptr for NULL. We cannot do this by looking at the value of 'code' at the start and end of each alternative, because compiled items are discarded during -the pre-compile phase so that the work space is not exceeded. */ +the pre-compile phase so that the workspace is not exceeded. */ length = 2 + 2*LINK_SIZE + skipunits; diff --git a/src/pcre2_dfa_match.c b/src/pcre2_dfa_match.c index bc62e6b..5fc8c24 100644 --- a/src/pcre2_dfa_match.c +++ b/src/pcre2_dfa_match.c @@ -387,8 +387,8 @@ return (mb->callout)(cb, mb->callout_data); *************************************************/ /* This function is called when internal_dfa_match() is about to be called -recursively and there is insufficient workingspace left in the current work -space block. If there's an existing next block, use it; otherwise get a new +recursively and there is insufficient working space left in the current +workspace block. If there's an existing next block, use it; otherwise get a new block unless the heap limit is reached. Arguments: @@ -2800,7 +2800,7 @@ for (;;) local_workspace, /* workspace vector */ RWS_RSIZE, /* size of same */ rlevel, /* function recursion level */ - RWS); /* recursion work space */ + RWS); /* recursion workspace */ rws->free += RWS_RSIZE + RWS_OVEC_OSIZE; diff --git a/src/pcre2_match.c b/src/pcre2_match.c index ce96016..ea1cc9b 100644 --- a/src/pcre2_match.c +++ b/src/pcre2_match.c @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "config.h" #endif -/* These defines enables debugging code */ +/* These defines enable debugging code */ //#define DEBUG_FRAMES_DISPLAY //#define DEBUG_SHOW_OPS @@ -1776,7 +1776,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode); /* ===================================================================== */ - /* Match a bit-mapped character class, possibly repeatedly. These op codes + /* Match a bit-mapped character class, possibly repeatedly. These opcodes are used when all the characters in the class have values in the range 0-255, and either the matching is caseful, or the characters are in the range 0-127 when UTF processing is enabled. The only difference between @@ -2464,7 +2464,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode); /* ===================================================================== */ /* Match a single character type repeatedly. Note that the property type - does not need to be in a stack frame as it not used within an RMATCH() + does not need to be in a stack frame as it is not used within an RMATCH() loop. */ #define Lstart_eptr F->temp_sptr[0] @@ -4143,7 +4143,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode); } break; - /* The "byte" (i.e. "code unit") case is the same as non-UTF */ + /* The "byte" (i.e. "code unit") case is the same as non-UTF */ case OP_ANYBYTE: fc = Lmax - Lmin; @@ -5424,7 +5424,7 @@ fprintf(stderr, "++ op=%d\n", *Fecode); Feptr -= number; } - /* Save the earliest consulted character, then skip to next op code */ + /* Save the earliest consulted character, then skip to next opcode */ if (Feptr < mb->start_used_ptr) mb->start_used_ptr = Feptr; Fecode += 1 + LINK_SIZE; @@ -5929,7 +5929,7 @@ in rrc. */ RETURN_SWITCH: if (Frdepth == 0) return rrc; /* Exit from the top level */ -F = (heapframe *)((char *)F - Fback_frame); /* Back track */ +F = (heapframe *)((char *)F - Fback_frame); /* Backtrack */ mb->cb->callout_flags |= PCRE2_CALLOUT_BACKTRACK; /* Note for callouts */ #ifdef DEBUG_SHOW_RMATCH diff --git a/src/pcre2_study.c b/src/pcre2_study.c index b926867..087012d 100644 --- a/src/pcre2_study.c +++ b/src/pcre2_study.c @@ -1274,7 +1274,7 @@ do break; /* Single character types set the bits and stop. Note that if PCRE2_UCP - is set, we do not see these op codes because \d etc are converted to + is set, we do not see these opcodes because \d etc are converted to properties. Therefore, these apply in the case when only characters less than 256 are recognized to match the types. */ diff --git a/src/pcre2_tables.c b/src/pcre2_tables.c index 9f8dc29..934692b 100644 --- a/src/pcre2_tables.c +++ b/src/pcre2_tables.c @@ -170,7 +170,7 @@ are implementing). by E_Modifier). Extend characters are allowed before the modifier; this cannot be represented in this table, the code has to deal with it. -8. Do not break within emoji zwj sequences (ZWJ followed by Glue_After_Zwj or +8. Do not break within emoji zwj sequences (ZWJ followed by Glue_After_Zwj or E_Base_GAZ). 9. Do not break within emoji flag sequences. That is, do not break between diff --git a/src/pcre2test.c b/src/pcre2test.c index fe6ef79..fde4f6a 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -492,7 +492,7 @@ so many of them that they are split into two fields. */ /* These are the matching controls that may be set either on a pattern or on a data line. They are copied from the pattern controls as initial settings for -data line controls Note that CTL_MEMORY is not included here, because it does +data line controls. Note that CTL_MEMORY is not included here, because it does different things in the two cases. */ #define CTL_ALLPD (CTL_AFTERTEXT|\ @@ -5411,7 +5411,7 @@ switch(errorcode) /* The pattern is now in pbuffer[8|16|32], with the length in code units in patlen. If it is to be converted, copy the result back afterwards so that it -it ends up back in the usual place. */ +ends up back in the usual place. */ if (pat_patctl.convert_type != CONVERT_UNSET) { @@ -5735,7 +5735,7 @@ return PR_OK; *************************************************/ /* This is used for DFA, normal, and JIT fast matching. For DFA matching it -should only called with the third argument set to PCRE2_ERROR_DEPTHLIMIT. +should only be called with the third argument set to PCRE2_ERROR_DEPTHLIMIT. Arguments: pp the subject string @@ -7766,7 +7766,7 @@ printf(" -LM list pattern and subject modifiers, then exit\n"); printf(" -q quiet: do not output PCRE2 version number at start\n"); printf(" -pattern set default pattern modifier fields\n"); printf(" -subject set default subject modifier fields\n"); -printf(" -S set stack size to megabytes\n"); +printf(" -S set stack size to mebibytes\n"); printf(" -t [] time compilation and execution, repeating times\n"); printf(" -tm [] time execution (matching) only, repeating times\n"); printf(" -T same as -t, but show total times at the end\n");