diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2020-04-30 21:27:32 +0200 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2020-04-30 21:27:32 +0200 |
commit | d233fd14a39f9c583b85ffb03e42b5ea52e2f4c2 (patch) | |
tree | ca6969834952f03fd0f1c2bc5874c755b0dd2512 /pcre/doc | |
parent | 4fc8961d491f63b869a6fdc8a9865b0a695f0a02 (diff) | |
parent | c1291d7a6b59bfa84dbeb499aca64ea877239d9b (diff) | |
download | mariadb-git-d233fd14a39f9c583b85ffb03e42b5ea52e2f4c2.tar.gz |
Merge branch 'merge-pcre' into 10.1
Diffstat (limited to 'pcre/doc')
-rw-r--r-- | pcre/doc/html/README.txt | 9 | ||||
-rw-r--r-- | pcre/doc/html/pcre.html | 2 | ||||
-rw-r--r-- | pcre/doc/html/pcreapi.html | 6 | ||||
-rw-r--r-- | pcre/doc/html/pcretest.html | 24 | ||||
-rw-r--r-- | pcre/doc/pcre-config.txt | 42 | ||||
-rw-r--r-- | pcre/doc/pcre.3 | 2 | ||||
-rw-r--r-- | pcre/doc/pcre.txt | 3927 | ||||
-rw-r--r-- | pcre/doc/pcreapi.3 | 6 | ||||
-rw-r--r-- | pcre/doc/pcregrep.txt | 232 | ||||
-rw-r--r-- | pcre/doc/pcretest.1 | 26 | ||||
-rw-r--r-- | pcre/doc/pcretest.txt | 650 |
11 files changed, 2456 insertions, 2470 deletions
diff --git a/pcre/doc/html/README.txt b/pcre/doc/html/README.txt index 4887ebf350e..334362b3e53 100644 --- a/pcre/doc/html/README.txt +++ b/pcre/doc/html/README.txt @@ -13,9 +13,10 @@ libraries. The latest release of PCRE1 is always available in three alternative formats from: - ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-xxx.tar.gz - ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-xxx.tar.bz2 - ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-xxx.zip + https://ftp.pcre.org/pub/pcre/pcre-x.xx.tar.gz + https://ftp.pcre.org/pub/pcre/pcre-x.xx.tar.bz2 + https://ftp.pcre.org/pub/pcre/pcre-x.xx.tar.zip + There is a mailing list for discussion about the development of PCRE at pcre-dev@exim.org. You can access the archives and subscribe or manage your @@ -999,4 +1000,4 @@ pcre_xxx, one with the name pcre16_xx, and a third with the name pcre32_xxx. Philip Hazel Email local part: ph10 Email domain: cam.ac.uk -Last updated: 10 February 2015 +Last updated: 12 February 2020 diff --git a/pcre/doc/html/pcre.html b/pcre/doc/html/pcre.html index c87b1066427..0db75e44892 100644 --- a/pcre/doc/html/pcre.html +++ b/pcre/doc/html/pcre.html @@ -143,7 +143,7 @@ performance. One way of guarding against this possibility is to use the <b>pcre_fullinfo()</b> function to check the compiled pattern's options for UTF. Alternatively, from release 8.33, you can set the PCRE_NEVER_UTF option at -compile time. This causes an compile time error if a pattern contains a +compile time. This causes a compile time error if a pattern contains a UTF-setting sequence. </P> <P> diff --git a/pcre/doc/html/pcreapi.html b/pcre/doc/html/pcreapi.html index 2d7adf185a6..2fdfbff5ccf 100644 --- a/pcre/doc/html/pcreapi.html +++ b/pcre/doc/html/pcreapi.html @@ -1246,7 +1246,7 @@ the following negative numbers: PCRE_ERROR_BADOPTION the value of <i>what</i> was invalid PCRE_ERROR_UNSET the requested field is not set </pre> -The "magic number" is placed at the start of each compiled pattern as an simple +The "magic number" is placed at the start of each compiled pattern as a simple check against passing an arbitrary memory pointer. The endianness error can occur if a compiled pattern is saved and reloaded on a different host. Here is a typical call of <b>pcre_fullinfo()</b>, to obtain the length of the compiled @@ -1318,7 +1318,7 @@ returned. For anchored patterns, -2 is returned. </pre> Return the value of the first data unit (non-UTF character) of any matched string in the situation where PCRE_INFO_FIRSTCHARACTERFLAGS returns 1; -otherwise return 0. The fourth argument should point to an <b>uint_t</b> +otherwise return 0. The fourth argument should point to a <b>uint_t</b> variable. </P> <P> @@ -1577,7 +1577,7 @@ returned value 1 (with "z" returned from PCRE_INFO_REQUIREDCHAR), but for </pre> Return the value of the rightmost literal data unit that must exist in any matched string, other than at its start, if such a value has been recorded. The -fourth argument should point to an <b>uint32_t</b> variable. If there is no such +fourth argument should point to a <b>uint32_t</b> variable. If there is no such value, 0 is returned. </P> <br><a name="SEC16" href="#TOC1">REFERENCE COUNTS</a><br> diff --git a/pcre/doc/html/pcretest.html b/pcre/doc/html/pcretest.html index ba540d3c385..842ff3cbe53 100644 --- a/pcre/doc/html/pcretest.html +++ b/pcre/doc/html/pcretest.html @@ -99,23 +99,21 @@ the 16-bit library, or <b>pcre32_xx</b> when using the 32-bit library". <br><a name="SEC4" href="#TOC1">COMMAND LINE OPTIONS</a><br> <P> <b>-8</b> -If both the 8-bit library has been built, this option causes the 8-bit library -to be used (which is the default); if the 8-bit library has not been built, -this option causes an error. +If the 8-bit library has been built, this option causes it to be used (this is +the default). If the 8-bit library has not been built, this option causes an +error. </P> <P> <b>-16</b> -If both the 8-bit or the 32-bit, and the 16-bit libraries have been built, this -option causes the 16-bit library to be used. If only the 16-bit library has been -built, this is the default (so has no effect). If only the 8-bit or the 32-bit -library has been built, this option causes an error. +If the 16-bit library has been built, this option causes it to be used. If only +the 16-bit library has been built, this is the default. If the 16-bit library +has not been built, this option causes an error. </P> <P> <b>-32</b> -If both the 8-bit or the 16-bit, and the 32-bit libraries have been built, this -option causes the 32-bit library to be used. If only the 32-bit library has been -built, this is the default (so has no effect). If only the 8-bit or the 16-bit -library has been built, this option causes an error. +If the 32-bit library has been built, this option causes it to be used. If only +the 32-bit library has been built, this is the default. If the 32-bit library +has not been built, this option causes an error. </P> <P> <b>-b</b> @@ -1154,9 +1152,9 @@ Cambridge CB2 3QH, England. </P> <br><a name="SEC17" href="#TOC1">REVISION</a><br> <P> -Last updated: 23 February 2017 +Last updated: 10 February 2020 <br> -Copyright © 1997-2017 University of Cambridge. +Copyright © 1997-2020 University of Cambridge. <br> <p> Return to the <a href="index.html">PCRE index page</a>. diff --git a/pcre/doc/pcre-config.txt b/pcre/doc/pcre-config.txt index 8503ab0ef0c..977e46868a8 100644 --- a/pcre/doc/pcre-config.txt +++ b/pcre/doc/pcre-config.txt @@ -16,8 +16,8 @@ DESCRIPTION pcre-config returns the configuration of the installed PCRE libraries and the options required to compile a program to use them. Some of the - options apply only to the 8-bit, or 16-bit, or 32-bit libraries, - respectively, and are not available if only one of those libraries has + options apply only to the 8-bit, or 16-bit, or 32-bit libraries, re- + spectively, and are not available if only one of those libraries has been built. If an unavailable option is encountered, the "usage" infor- mation is output. @@ -36,37 +36,37 @@ OPTIONS --version Writes the version number of the installed PCRE libraries to the standard output. - --libs Writes to the standard output the command line options - required to link with the 8-bit PCRE library (-lpcre on many + --libs Writes to the standard output the command line options re- + quired to link with the 8-bit PCRE library (-lpcre on many systems). - --libs16 Writes to the standard output the command line options - required to link with the 16-bit PCRE library (-lpcre16 on - many systems). + --libs16 Writes to the standard output the command line options re- + quired to link with the 16-bit PCRE library (-lpcre16 on many + systems). - --libs32 Writes to the standard output the command line options - required to link with the 32-bit PCRE library (-lpcre32 on - many systems). + --libs32 Writes to the standard output the command line options re- + quired to link with the 32-bit PCRE library (-lpcre32 on many + systems). --libs-cpp - Writes to the standard output the command line options - required to link with PCRE's C++ wrapper library (-lpcrecpp + Writes to the standard output the command line options re- + quired to link with PCRE's C++ wrapper library (-lpcrecpp -lpcre on many systems). --libs-posix - Writes to the standard output the command line options - required to link with PCRE's POSIX API wrapper library + Writes to the standard output the command line options re- + quired to link with PCRE's POSIX API wrapper library (-lpcreposix -lpcre on many systems). - --cflags Writes to the standard output the command line options - required to compile files that use PCRE (this may include - some -I options, but is blank on many systems). + --cflags Writes to the standard output the command line options re- + quired to compile files that use PCRE (this may include some + -I options, but is blank on many systems). --cflags-posix - Writes to the standard output the command line options - required to compile files that use PCRE's POSIX API wrapper - library (this may include some -I options, but is blank on - many systems). + Writes to the standard output the command line options re- + quired to compile files that use PCRE's POSIX API wrapper li- + brary (this may include some -I options, but is blank on many + systems). SEE ALSO diff --git a/pcre/doc/pcre.3 b/pcre/doc/pcre.3 index 0f2837e7c06..716d58044c7 100644 --- a/pcre/doc/pcre.3 +++ b/pcre/doc/pcre.3 @@ -146,7 +146,7 @@ performance. One way of guarding against this possibility is to use the \fBpcre_fullinfo()\fP function to check the compiled pattern's options for UTF. Alternatively, from release 8.33, you can set the PCRE_NEVER_UTF option at -compile time. This causes an compile time error if a pattern contains a +compile time. This causes a compile time error if a pattern contains a UTF-setting sequence. .P If your application is one that supports UTF, be aware that validity checking diff --git a/pcre/doc/pcre.txt b/pcre/doc/pcre.txt index c027538f500..8ffc90234ac 100644 --- a/pcre/doc/pcre.txt +++ b/pcre/doc/pcre.txt @@ -37,10 +37,10 @@ INTRODUCTION give better JavaScript compatibility. Starting with release 8.30, it is possible to compile two separate PCRE - libraries: the original, which supports 8-bit character strings - (including UTF-8 strings), and a second library that supports 16-bit - character strings (including UTF-16 strings). The build process allows - either one or both to be built. The majority of the work to make this + libraries: the original, which supports 8-bit character strings (in- + cluding UTF-8 strings), and a second library that supports 16-bit char- + acter strings (including UTF-16 strings). The build process allows ei- + ther one or both to be built. The majority of the work to make this possible was done by Zoltan Herczeg. Starting with release 8.32 it is possible to compile a third separate @@ -121,7 +121,7 @@ SECURITY CONSIDERATIONS One way of guarding against this possibility is to use the pcre_fullinfo() function to check the compiled pattern's options for UTF. Alternatively, from release 8.33, you can set the PCRE_NEVER_UTF - option at compile time. This causes an compile time error if a pattern + option at compile time. This causes a compile time error if a pattern contains a UTF-setting sequence. If your application is one that supports UTF, be aware that validity @@ -314,12 +314,12 @@ THE PCRE 16-BIT LIBRARY Starting with release 8.30, it is possible to compile a PCRE library that supports 16-bit character strings, including UTF-16 strings, as well as or instead of the original 8-bit library. The majority of the - work to make this possible was done by Zoltan Herczeg. The two - libraries contain identical sets of functions, used in exactly the same + work to make this possible was done by Zoltan Herczeg. The two li- + braries contain identical sets of functions, used in exactly the same way. Only the names of the functions and the data types of their argu- ments and results are different. To avoid over-complication and reduce - the documentation maintenance load, most of the PCRE documentation - describes the 8-bit library, with only occasional references to the + the documentation maintenance load, most of the PCRE documentation de- + scribes the 8-bit library, with only occasional references to the 16-bit library. This page describes what is different when you use the 16-bit library. @@ -350,12 +350,12 @@ STRING TYPES In the 8-bit library, strings are passed to PCRE library functions as vectors of bytes with the C type "char *". In the 16-bit library, strings are passed as vectors of unsigned 16-bit quantities. The macro - PCRE_UCHAR16 specifies an appropriate data type, and PCRE_SPTR16 is - defined as "const PCRE_UCHAR16 *". In very many environments, "short - int" is a 16-bit data type. When PCRE is built, it defines PCRE_UCHAR16 - as "unsigned short int", but checks that it really is a 16-bit data - type. If it is not, the build fails with an error message telling the - maintainer to modify the definition appropriately. + PCRE_UCHAR16 specifies an appropriate data type, and PCRE_SPTR16 is de- + fined as "const PCRE_UCHAR16 *". In very many environments, "short int" + is a 16-bit data type. When PCRE is built, it defines PCRE_UCHAR16 as + "unsigned short int", but checks that it really is a 16-bit data type. + If it is not, the build fails with an error message telling the main- + tainer to modify the definition appropriately. STRUCTURE TYPES @@ -424,9 +424,9 @@ OPTION NAMES There are two new general option names, PCRE_UTF16 and PCRE_NO_UTF16_CHECK, which correspond to PCRE_UTF8 and - PCRE_NO_UTF8_CHECK in the 8-bit library. In fact, these new options - define the same bits in the options word. There is a discussion about - the validity of UTF-16 strings in the pcreunicode page. + PCRE_NO_UTF8_CHECK in the 8-bit library. In fact, these new options de- + fine the same bits in the options word. There is a discussion about the + validity of UTF-16 strings in the pcreunicode page. For the pcre16_config() function there is an option PCRE_CONFIG_UTF16 that returns 1 if UTF-16 support is configured, otherwise 0. If this @@ -464,8 +464,8 @@ ERROR NAMES patterns in the other mode, for example, if a pattern compiled with pcre_compile() is passed to pcre16_exec(). - There are new error codes whose names begin with PCRE_UTF16_ERR for - invalid UTF-16 strings, corresponding to the PCRE_UTF8_ERR codes for + There are new error codes whose names begin with PCRE_UTF16_ERR for in- + valid UTF-16 strings, corresponding to the PCRE_UTF8_ERR codes for UTF-8 strings that are described in the section entitled "Reason codes for invalid UTF-8 strings" in the main pcreapi page. The UTF-16 errors are: @@ -509,8 +509,8 @@ TESTING NOT SUPPORTED IN 16-BIT MODE Not all the features of the 8-bit library are available with the 16-bit - library. The C++ and POSIX wrapper functions support only the 8-bit - library, and the pcregrep program is at present 8-bit only. + library. The C++ and POSIX wrapper functions support only the 8-bit li- + brary, and the pcregrep program is at present 8-bit only. AUTHOR @@ -651,8 +651,8 @@ THE PCRE 32-BIT LIBRARY and the data types of their arguments and results are different. To avoid over-complication and reduce the documentation maintenance load, most of the PCRE documentation describes the 8-bit library, with only - occasional references to the 16-bit and 32-bit libraries. This page - describes what is different when you use the 32-bit library. + occasional references to the 16-bit and 32-bit libraries. This page de- + scribes what is different when you use the 32-bit library. WARNING: A single application can be linked with all or any of the three libraries, but you must take care when processing any particular @@ -681,8 +681,8 @@ STRING TYPES In the 8-bit library, strings are passed to PCRE library functions as vectors of bytes with the C type "char *". In the 32-bit library, strings are passed as vectors of unsigned 32-bit quantities. The macro - PCRE_UCHAR32 specifies an appropriate data type, and PCRE_SPTR32 is - defined as "const PCRE_UCHAR32 *". In very many environments, "unsigned + PCRE_UCHAR32 specifies an appropriate data type, and PCRE_SPTR32 is de- + fined as "const PCRE_UCHAR32 *". In very many environments, "unsigned int" is a 32-bit data type. When PCRE is built, it defines PCRE_UCHAR32 as "unsigned int", but checks that it really is a 32-bit data type. If it is not, the build fails with an error message telling the maintainer @@ -755,9 +755,9 @@ OPTION NAMES There are two new general option names, PCRE_UTF32 and PCRE_NO_UTF32_CHECK, which correspond to PCRE_UTF8 and - PCRE_NO_UTF8_CHECK in the 8-bit library. In fact, these new options - define the same bits in the options word. There is a discussion about - the validity of UTF-32 strings in the pcreunicode page. + PCRE_NO_UTF8_CHECK in the 8-bit library. In fact, these new options de- + fine the same bits in the options word. There is a discussion about the + validity of UTF-32 strings in the pcreunicode page. For the pcre32_config() function there is an option PCRE_CONFIG_UTF32 that returns 1 if UTF-32 support is configured, otherwise 0. If this @@ -793,8 +793,8 @@ ERROR NAMES to a function that processes patterns in the other mode, for example, if a pattern compiled with pcre_compile() is passed to pcre32_exec(). - There are new error codes whose names begin with PCRE_UTF32_ERR for - invalid UTF-32 strings, corresponding to the PCRE_UTF8_ERR codes for + There are new error codes whose names begin with PCRE_UTF32_ERR for in- + valid UTF-32 strings, corresponding to the PCRE_UTF8_ERR codes for UTF-8 strings that are described in the section entitled "Reason codes for invalid UTF-8 strings" in the main pcreapi page. The UTF-32 errors are: @@ -837,8 +837,8 @@ TESTING NOT SUPPORTED IN 32-BIT MODE Not all the features of the 8-bit library are available with the 32-bit - library. The C++ and POSIX wrapper functions support only the 8-bit - library, and the pcregrep program is at present 8-bit only. + library. The C++ and POSIX wrapper functions support only the 8-bit li- + brary, and the pcregrep program is at present 8-bit only. AUTHOR @@ -866,8 +866,8 @@ BUILDING PCRE PCRE is distributed with a configure script that can be used to build the library in Unix-like environments using the applications known as - Autotools. Also in the distribution are files to support building - using CMake instead of configure. The text file README contains general + Autotools. Also in the distribution are files to support building us- + ing CMake instead of configure. The text file README contains general information about building with Autotools (some of which is repeated below), and also has some comments about building on various operating systems. There is a lot more information about building PCRE without @@ -892,13 +892,13 @@ PCRE BUILD-TIME OPTIONS compiler, as described in NON-AUTOTOOLS-BUILD. The complete list of options for configure (which includes the standard - ones such as the selection of the installation directory) can be - obtained by running + ones such as the selection of the installation directory) can be ob- + tained by running ./configure --help - The following sections include descriptions of options whose names - begin with --enable or --disable. These settings specify changes to the + The following sections include descriptions of options whose names be- + gin with --enable or --disable. These settings specify changes to the defaults for the configure command. Because of the way that configure works, --enable and --disable always come in pairs, so the complemen- tary option always exists as well, but as it specifies the default, it @@ -916,8 +916,8 @@ BUILDING 8-BIT, 16-BIT AND 32-BIT LIBRARIES --enable-pcre16 - to the configure command. You can also build yet another separate - library, called libpcre32, in which strings are contained in vectors of + to the configure command. You can also build yet another separate li- + brary, called libpcre32, in which strings are contained in vectors of 32-bit data units and interpreted either as single-unit characters or UTF-32 strings, by adding @@ -965,8 +965,8 @@ UTF-8, UTF-16 AND UTF-32 SUPPORT to the configure command. This setting applies to all three libraries, adding support for UTF-8 to the 8-bit library, support for UTF-16 to - the 16-bit library, and support for UTF-32 to the to the 32-bit - library. There are no separate options for enabling UTF-8, UTF-16 and + the 16-bit library, and support for UTF-32 to the to the 32-bit li- + brary. There are no separate options for enabling UTF-8, UTF-16 and UTF-32 independently because that would allow ridiculous settings such as requesting UTF-16 support while building only the 8-bit library. It is not possible to build one library with UTF support and another with- @@ -975,8 +975,8 @@ UTF-8, UTF-16 AND UTF-32 SUPPORT Of itself, this setting does not make PCRE treat strings as UTF-8, UTF-16 or UTF-32. As well as compiling PCRE with this option, you also - have have to set the PCRE_UTF8, PCRE_UTF16 or PCRE_UTF32 option (as - appropriate) when you call one of the pattern compiling functions. + have have to set the PCRE_UTF8, PCRE_UTF16 or PCRE_UTF32 option (as ap- + propriate) when you call one of the pattern compiling functions. If you set --enable-utf when compiling in an EBCDIC environment, PCRE expects its input to be either ASCII or UTF-8 (depending on the run- @@ -1010,9 +1010,9 @@ JUST-IN-TIME COMPILER SUPPORT --enable-jit This support is available only for certain hardware architectures. If - this option is set for an unsupported architecture, a compile time - error occurs. See the pcrejit documentation for a discussion of JIT - usage. When JIT support is enabled, pcregrep automatically makes use of + this option is set for an unsupported architecture, a compile time er- + ror occurs. See the pcrejit documentation for a discussion of JIT us- + age. When JIT support is enabled, pcregrep automatically makes use of it, unless you add --disable-pcregrep-jit @@ -1029,8 +1029,8 @@ CODE VALUE OF NEWLINE --enable-newline-is-cr - to the configure command. There is also a --enable-newline-is-lf - option, which explicitly specifies linefeed as the newline character. + to the configure command. There is also a --enable-newline-is-lf op- + tion, which explicitly specifies linefeed as the newline character. Alternatively, you can specify that line endings are to be indicated by the two character sequence CRLF. If you want this, add @@ -1124,12 +1124,12 @@ AVOIDING EXCESSIVE STACK USAGE can replace the pointers so that your own functions are used instead. Separate functions are provided rather than using pcre_malloc and - pcre_free because the usage is very predictable: the block sizes - requested are always the same, and the blocks are always freed in - reverse order. A calling program might be able to implement optimized - functions that perform better than malloc() and free(). PCRE runs - noticeably more slowly when built in this way. This option affects only - the pcre_exec() function; it is not relevant for pcre_dfa_exec(). + pcre_free because the usage is very predictable: the block sizes re- + quested are always the same, and the blocks are always freed in reverse + order. A calling program might be able to implement optimized functions + that perform better than malloc() and free(). PCRE runs noticeably more + slowly when built in this way. This option affects only the pcre_exec() + function; it is not relevant for pcre_dfa_exec(). LIMITING PCRE RESOURCE USAGE @@ -1152,9 +1152,9 @@ LIMITING PCRE RESOURCE USAGE calls of match() more strictly than the total number of calls, in order to restrict the maximum amount of stack (or heap, if --disable-stack- for-recursion is specified) that is used. A second limit controls this; - it defaults to the value that is set for --with-match-limit, which - imposes no additional constraints. However, you can set a lower limit - by adding, for example, + it defaults to the value that is set for --with-match-limit, which im- + poses no additional constraints. However, you can set a lower limit by + adding, for example, --with-match-limit-recursion=10000 @@ -1190,9 +1190,9 @@ USING EBCDIC CODE --enable-ebcdic to the configure command. This setting implies --enable-rebuild-charta- - bles. You should only use it if you know that you are in an EBCDIC - environment (for example, an IBM mainframe operating system). The - --enable-ebcdic option is incompatible with --enable-utf. + bles. You should only use it if you know that you are in an EBCDIC en- + vironment (for example, an IBM mainframe operating system). The --en- + able-ebcdic option is incompatible with --enable-utf. The EBCDIC character that corresponds to an ASCII LF is assumed to have the value 0x15 by default. However, in some EBCDIC environments, 0x25 @@ -1246,8 +1246,8 @@ PCRETEST OPTION FOR LIBREADLINE SUPPORT --enable-pcretest-libreadline - to the configure command, pcretest is linked with the libreadline - library, and when its input is from a terminal, it reads it using the + to the configure command, pcretest is linked with the libreadline li- + brary, and when its input is from a terminal, it reads it using the readline() function. This provides line-editing and history facilities. Note that libreadline is GPL-licensed, so if you distribute a binary of pcretest linked in this way, there may be licensing issues. @@ -1278,8 +1278,8 @@ DEBUGGING WITH VALGRIND SUPPORT --enable-valgrind option to to the configure command, PCRE will use valgrind annotations - to mark certain memory regions as unaddressable. This allows it to - detect invalid memory accesses, and is mostly useful for debugging PCRE + to mark certain memory regions as unaddressable. This allows it to de- + tect invalid memory accesses, and is mostly useful for debugging PCRE itself. @@ -1372,8 +1372,8 @@ PCRE MATCHING ALGORITHMS ject string. The "standard" algorithm is the one provided by the pcre_exec(), pcre16_exec() and pcre32_exec() functions. These work in the same as as Perl's matching function, and provide a Perl-compatible - matching operation. The just-in-time (JIT) optimization that is - described in the pcrejit documentation is compatible with these func- + matching operation. The just-in-time (JIT) optimization that is de- + scribed in the pcrejit documentation is compatible with these func- tions. An alternative algorithm is provided by the pcre_dfa_exec(), @@ -1448,8 +1448,8 @@ THE ALTERNATIVE MATCHING ALGORITHM Although the general principle of this matching algorithm is that it scans the subject string only once, without backtracking, there is one exception: when a lookaround assertion is encountered, the characters - following or preceding the current point have to be independently - inspected. + following or preceding the current point have to be independently in- + spected. The scan continues until either the end of the subject is reached, or there are no more unterminated paths. At this point, terminated paths @@ -1482,9 +1482,9 @@ THE ALTERNATIVE MATCHING ALGORITHM There are a number of features of PCRE regular expressions that are not supported by the alternative matching algorithm. They are as follows: - 1. Because the algorithm finds all possible matches, the greedy or - ungreedy nature of repetition quantifiers is not relevant. Greedy and - ungreedy quantifiers are treated in exactly the same way. However, pos- + 1. Because the algorithm finds all possible matches, the greedy or un- + greedy nature of repetition quantifiers is not relevant. Greedy and un- + greedy quantifiers are treated in exactly the same way. However, pos- sessive quantifiers can make a difference when what follows could also match what is quantified, for example in a pattern like this: @@ -1498,8 +1498,8 @@ THE ALTERNATIVE MATCHING ALGORITHM 2. When dealing with multiple paths through the tree simultaneously, it is not straightforward to keep track of captured substrings for the - different matching possibilities, and PCRE's implementation of this - algorithm does not attempt to do this. This means that no captured sub- + different matching possibilities, and PCRE's implementation of this al- + gorithm 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- @@ -1509,10 +1509,10 @@ THE ALTERNATIVE MATCHING ALGORITHM ence as the condition or test for a specific group recursion are not supported. - 5. Because many paths through the tree may be active, the \K escape - sequence, which resets the start of the match when encountered (but may - be on some paths and not on others), is not supported. It causes an - error if encountered. + 5. Because many paths through the tree may be active, the \K escape se- + quence, which resets the start of the match when encountered (but may + be on some paths and not on others), is not supported. It causes an er- + ror if encountered. 6. Callouts are supported, but the value of the capture_top field is always 1, and the value of the capture_last field is always -1. @@ -1719,10 +1719,10 @@ PCRE API OVERVIEW PCRE has its own native API, which is described in this document. There are also some wrapper functions (for the 8-bit library only) that cor- - respond to the POSIX regular expression API, but they do not give - access to all the functionality. They are described in the pcreposix - documentation. Both of these APIs define a set of C function calls. A - C++ wrapper (again for the 8-bit library only) is also distributed with + respond to the POSIX regular expression API, but they do not give ac- + cess to all the functionality. They are described in the pcreposix doc- + umentation. Both of these APIs define a set of C function calls. A C++ + wrapper (again for the 8-bit library only) is also distributed with PCRE. It is documented in the pcrecpp page. The native API C function prototypes are defined in the header file @@ -1734,10 +1734,10 @@ PCRE API OVERVIEW for different releases of PCRE. In a Windows environment, if you want to statically link an application - program against a non-dll pcre.a file, you must define PCRE_STATIC - before including pcre.h or pcrecpp.h, because otherwise the pcre_mal- - loc() and pcre_free() exported functions will be declared - __declspec(dllimport), with unwanted results. + program against a non-dll pcre.a file, you must define PCRE_STATIC be- + fore including pcre.h or pcrecpp.h, because otherwise the pcre_malloc() + and pcre_free() exported functions will be declared __declspec(dl- + limport), with unwanted results. The functions pcre_compile(), pcre_compile2(), pcre_study(), and pcre_exec() are used for compiling and matching regular expressions in @@ -1749,10 +1749,10 @@ PCRE API OVERVIEW Just-in-time compiler support is an optional feature of PCRE that can be built in appropriate hardware environments. It greatly speeds up the - matching performance of many patterns. Simple programs can easily - request that it be used if available, by setting an option that is - ignored when it is not relevant. More complicated programs might need - to make use of the functions pcre_jit_stack_alloc(), + matching performance of many patterns. Simple programs can easily re- + quest that it be used if available, by setting an option that is ig- + nored when it is not relevant. More complicated programs might need to + make use of the functions pcre_jit_stack_alloc(), pcre_jit_stack_free(), and pcre_assign_jit_stack() in order to control the JIT code's memory usage. @@ -1784,39 +1784,37 @@ PCRE API OVERVIEW pcre_free_substring() and pcre_free_substring_list() are also provided, to free the memory used for extracted strings. - The function pcre_maketables() is used to build a set of character - tables in the current locale for passing to pcre_compile(), - pcre_exec(), or pcre_dfa_exec(). This is an optional facility that is - provided for specialist use. Most commonly, no special tables are - passed, in which case internal tables that are generated when PCRE is - built are used. + The function pcre_maketables() is used to build a set of character ta- + bles in the current locale for passing to pcre_compile(), pcre_exec(), + or pcre_dfa_exec(). This is an optional facility that is provided for + specialist use. Most commonly, no special tables are passed, in which + case internal tables that are generated when PCRE is built are used. - The function pcre_fullinfo() is used to find out information about a - compiled pattern. The function pcre_version() returns a pointer to a + The function pcre_fullinfo() is used to find out information about a + compiled pattern. The function pcre_version() returns a pointer to a string containing the version of PCRE and its date of release. - The function pcre_refcount() maintains a reference count in a data - block containing a compiled pattern. This is provided for the benefit + The function pcre_refcount() maintains a reference count in a data + block containing a compiled pattern. This is provided for the benefit of object-oriented applications. - The global variables pcre_malloc and pcre_free initially contain the - entry points of the standard malloc() and free() functions, respec- + The global variables pcre_malloc and pcre_free initially contain the + entry points of the standard malloc() and free() functions, respec- tively. PCRE calls the memory management functions via these variables, - so a calling program can replace them if it wishes to intercept the + so a calling program can replace them if it wishes to intercept the calls. This should be done before calling any PCRE functions. - The global variables pcre_stack_malloc and pcre_stack_free are also - indirections to memory management functions. These special functions - are used only when PCRE is compiled to use the heap for remembering - data, instead of recursive function calls, when running the pcre_exec() - function. See the pcrebuild documentation for details of how to do - this. It is a non-standard way of building PCRE, for use in environ- - ments that have limited stacks. Because of the greater use of memory - management, it runs more slowly. Separate functions are provided so - that special-purpose external code can be used for this case. When - used, these functions always allocate memory blocks of the same size. - There is a discussion about PCRE's stack usage in the pcrestack docu- - mentation. + The global variables pcre_stack_malloc and pcre_stack_free are also in- + directions to memory management functions. These special functions are + used only when PCRE is compiled to use the heap for remembering data, + instead of recursive function calls, when running the pcre_exec() func- + tion. See the pcrebuild documentation for details of how to do this. It + is a non-standard way of building PCRE, for use in environments that + have limited stacks. Because of the greater use of memory management, + it runs more slowly. Separate functions are provided so that special- + purpose external code can be used for this case. When used, these func- + tions always allocate memory blocks of the same size. There is a dis- + cussion about PCRE's stack usage in the pcrestack documentation. The global variable pcre_callout initially contains NULL. It can be set by the caller to a "callout" function, which PCRE will then call at @@ -1915,24 +1913,24 @@ CHECKING BUILD-TIME OPTIONS The output is an integer that is set to one if UTF-8 support is avail- able; otherwise it is set to zero. This value should normally be given to the 8-bit version of this function, pcre_config(). If it is given to - the 16-bit or 32-bit version of this function, the result is - PCRE_ERROR_BADOPTION. + the 16-bit or 32-bit version of this function, the result is PCRE_ER- + ROR_BADOPTION. PCRE_CONFIG_UTF16 The output is an integer that is set to one if UTF-16 support is avail- able; otherwise it is set to zero. This value should normally be given to the 16-bit version of this function, pcre16_config(). If it is given - to the 8-bit or 32-bit version of this function, the result is - PCRE_ERROR_BADOPTION. + to the 8-bit or 32-bit version of this function, the result is PCRE_ER- + ROR_BADOPTION. PCRE_CONFIG_UTF32 The output is an integer that is set to one if UTF-32 support is avail- able; otherwise it is set to zero. This value should normally be given to the 32-bit version of this function, pcre32_config(). If it is given - to the 8-bit or 16-bit version of this function, the result is - PCRE_ERROR_BADOPTION. + to the 8-bit or 16-bit version of this function, the result is PCRE_ER- + ROR_BADOPTION. PCRE_CONFIG_UNICODE_PROPERTIES @@ -1949,8 +1947,8 @@ CHECKING BUILD-TIME OPTIONS The output is a pointer to a zero-terminated "const char *" string. If JIT support is available, the string contains the name of the architec- ture for which the JIT compiler is configured, for example "x86 32bit - (little endian + unaligned)". If JIT support is not available, the - result is NULL. + (little endian + unaligned)". If JIT support is not available, the re- + sult is NULL. PCRE_CONFIG_NEWLINE @@ -1973,15 +1971,15 @@ CHECKING BUILD-TIME OPTIONS PCRE_CONFIG_LINK_SIZE - The output is an integer that contains the number of bytes used for - internal linkage in compiled regular expressions. For the 8-bit - library, the value can be 2, 3, or 4. For the 16-bit library, the value - is either 2 or 4 and is still a number of bytes. For the 32-bit - library, the value is either 2 or 4 and is still a number of bytes. The - default value of 2 is sufficient for all but the most massive patterns, - since it allows the compiled pattern to be up to 64K in size. Larger - values allow larger regular expressions to be compiled, at the expense - of slower matching. + The output is an integer that contains the number of bytes used for in- + ternal linkage in compiled regular expressions. For the 8-bit library, + the value can be 2, 3, or 4. For the 16-bit library, the value is ei- + ther 2 or 4 and is still a number of bytes. For the 32-bit library, the + value is either 2 or 4 and is still a number of bytes. The default + value of 2 is sufficient for all but the most massive patterns, since + it allows the compiled pattern to be up to 64K in size. Larger values + allow larger regular expressions to be compiled, at the expense of + slower matching. PCRE_CONFIG_POSIX_MALLOC_THRESHOLD @@ -2009,8 +2007,8 @@ CHECKING BUILD-TIME OPTIONS The output is a long integer that gives the default limit for the depth of recursion when calling the internal matching function in a - pcre_exec() execution. Further details are given with pcre_exec() - below. + pcre_exec() execution. Further details are given with pcre_exec() be- + low. PCRE_CONFIG_STACKRECURSE @@ -2042,11 +2040,11 @@ COMPILING A PATTERN the information applies equally to pcre_compile2(). The pattern is a C string terminated by a binary zero, and is passed in - the pattern argument. A pointer to a single block of memory that is - obtained via pcre_malloc is returned. This contains the compiled code - and related data. The pcre type is defined for the returned block; this - is a typedef for a structure whose contents are not externally defined. - It is up to the caller to free the memory (via pcre_free) when it is no + the pattern argument. A pointer to a single block of memory that is ob- + tained via pcre_malloc is returned. This contains the compiled code and + related data. The pcre type is defined for the returned block; this is + a typedef for a structure whose contents are not externally defined. It + is up to the caller to free the memory (via pcre_free) when it is no longer required. Although the compiled code of a PCRE regex is relocatable, that is, it @@ -2089,12 +2087,12 @@ COMPILING A PATTERN textual error message. Error codes and messages are listed below. If the final argument, tableptr, is NULL, PCRE uses a default set of - character tables that are built when PCRE is compiled, using the - default C locale. Otherwise, tableptr must be an address that is the - result of a call to pcre_maketables(). This value is stored with the - compiled pattern, and used again by pcre_exec() and pcre_dfa_exec() - when the pattern is matched. For more discussion, see the section on - locale support below. + character tables that are built when PCRE is compiled, using the de- + fault C locale. Otherwise, tableptr must be an address that is the re- + sult of a call to pcre_maketables(). This value is stored with the com- + piled pattern, and used again by pcre_exec() and pcre_dfa_exec() when + the pattern is matched. For more discussion, see the section on locale + support below. This code fragment shows a typical straightforward call to pcre_com- pile(): @@ -2178,13 +2176,13 @@ COMPILING A PATTERN PCRE_EXTENDED - If this bit is set, most white space characters in the pattern are - totally ignored except when escaped or inside a character class. How- - ever, white space is not allowed within sequences such as (?> that - introduce various parenthesized subpatterns, nor within a numerical - quantifier such as {1,3}. However, ignorable white space is permitted - between an item and a following quantifier and between a quantifier and - a following + that indicates possessiveness. + If this bit is set, most white space characters in the pattern are to- + tally ignored except when escaped or inside a character class. However, + white space is not allowed within sequences such as (?> that introduce + various parenthesized subpatterns, nor within a numerical quantifier + such as {1,3}. However, ignorable white space is permitted between an + item and a following quantifier and between a quantifier and a follow- + ing + that indicates possessiveness. White space did not used to include the VT character (code 11), because Perl did not treat this character as white space. However, Perl changed @@ -2196,17 +2194,17 @@ COMPILING A PATTERN PCRE_EXTENDED is equivalent to Perl's /x option, and it can be changed within a pattern by a (?x) option setting. - Which characters are interpreted as newlines is controlled by the - options passed to pcre_compile() or by a special sequence at the start - of the pattern, as described in the section entitled "Newline conven- - tions" in the pcrepattern documentation. 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. + Which characters are interpreted as newlines is controlled by the op- + tions passed to pcre_compile() or by a special sequence at the start of + the pattern, as described in the section entitled "Newline conventions" + in the pcrepattern documentation. 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. This option makes it possible to include comments inside complicated patterns. Note, however, that this applies only to data characters. - White space characters may never appear within special character - sequences in a pattern, for example within the sequence (?( that intro- + White space characters may never appear within special character se- + quences in a pattern, for example within the sequence (?( that intro- duces a conditional subpattern. PCRE_EXTRA @@ -2224,9 +2222,9 @@ COMPILING A PATTERN PCRE_FIRSTLINE - If this option is set, an unanchored pattern is required to match - before or at the first newline in the subject string, though the - matched text may continue over the newline. + If this option is set, an unanchored pattern is required to match be- + fore or at the first newline in the subject string, though the matched + text may continue over the newline. PCRE_JAVASCRIPT_COMPAT @@ -2529,8 +2527,8 @@ STUDYING A PATTERN pcre_study() returns NULL by default. In that circumstance, if the calling program wants to pass any of the other fields to pcre_exec() or pcre_dfa_exec(), it must set up its own pcre_extra block. However, if - pcre_study() is called with the PCRE_STUDY_EXTRA_NEEDED option, it - returns a pcre_extra block even if studying did not find any additional + pcre_study() is called with the PCRE_STUDY_EXTRA_NEEDED option, it re- + turns a pcre_extra block even if studying did not find any additional information. It may still return NULL, however, if an error occurs in pcre_study(). @@ -2557,10 +2555,10 @@ STUDYING A PATTERN The third argument for pcre_study() is a pointer for an error message. If studying succeeds (even if no data is returned), the variable it - points to is set to NULL. Otherwise it is set to point to a textual - error message. This is a static string that is part of the library. You - must not try to free it. You should test the error pointer for NULL - after calling pcre_study(), to be sure that it has run successfully. + points to is set to NULL. Otherwise it is set to point to a textual er- + ror message. This is a static string that is part of the library. You + must not try to free it. You should test the error pointer for NULL af- + ter calling pcre_study(), to be sure that it has run successfully. When you are finished with a pattern, you can free the memory used for the study data by calling pcre_free_study(). This function was added to @@ -2635,10 +2633,10 @@ LOCALE SUPPORT Unicode support, or use locales, but not try to mix the two. PCRE contains an internal set of tables that are used when the final - argument of pcre_compile() is NULL. These are sufficient for many - applications. Normally, the internal tables recognize only ASCII char- - acters. However, when PCRE is built, it is possible to cause the inter- - nal tables to be rebuilt in the default "C" locale of the local system, + argument of pcre_compile() is NULL. These are sufficient for many ap- + plications. Normally, the internal tables recognize only ASCII charac- + ters. However, when PCRE is built, it is possible to cause the internal + tables to be rebuilt in the default "C" locale of the local system, which may cause them to be different. The internal tables can always be overridden by tables supplied by the @@ -2649,9 +2647,9 @@ LOCALE SUPPORT External tables are built by calling the pcre_maketables() function, which has no arguments, in the relevant locale. The result can then be passed to pcre_compile() as often as necessary. For example, to build - and use tables that are appropriate for the French locale (where - accented characters with values greater than 128 are treated as let- - ters), the following code could be used: + and use tables that are appropriate for the French locale (where ac- + cented characters with values greater than 128 are treated as letters), + the following code could be used: setlocale(LC_CTYPE, "fr_FR"); tables = pcre_maketables(); @@ -2660,8 +2658,8 @@ LOCALE SUPPORT The locale name "fr_FR" is used on Linux and other Unix-like systems; if you are using Windows, the name for the French locale is "french". - When pcre_maketables() runs, the tables are built in memory that is - obtained via pcre_malloc. It is the caller's responsibility to ensure + When pcre_maketables() runs, the tables are built in memory that is ob- + tained via pcre_malloc. It is the caller's responsibility to ensure that the memory containing the tables remains available for as long as it is needed. @@ -2706,9 +2704,9 @@ INFORMATION ABOUT A PATTERN PCRE_ERROR_BADOPTION the value of what was invalid PCRE_ERROR_UNSET the requested field is not set - The "magic number" is placed at the start of each compiled pattern as - an simple check against passing an arbitrary memory pointer. The endi- - anness error can occur if a compiled pattern is saved and reloaded on a + The "magic number" is placed at the start of each compiled pattern as a + simple check against passing an arbitrary memory pointer. The endian- + ness error can occur if a compiled pattern is saved and reloaded on a different host. Here is a typical call of pcre_fullinfo(), to obtain the length of the compiled pattern: @@ -2745,12 +2743,12 @@ INFORMATION ABOUT A PATTERN PCRE_INFO_FIRSTBYTE (deprecated) Return information about the first data unit of any matched string, for - a non-anchored pattern. The name of this option refers to the 8-bit - library, where data units are bytes. The fourth argument should point - to an int variable. Negative values are used for special cases. How- - ever, this means that when the 32-bit library is in non-UTF-32 mode, - the full 32-bit range of characters cannot be returned. For this rea- - son, this value is deprecated; use PCRE_INFO_FIRSTCHARACTERFLAGS and + a non-anchored pattern. The name of this option refers to the 8-bit li- + brary, where data units are bytes. The fourth argument should point to + an int variable. Negative values are used for special cases. However, + this means that when the 32-bit library is in non-UTF-32 mode, the full + 32-bit range of characters cannot be returned. For this reason, this + value is deprecated; use PCRE_INFO_FIRSTCHARACTERFLAGS and PCRE_INFO_FIRSTCHARACTER instead. If there is a fixed first value, for example, the letter "c" from a @@ -2774,14 +2772,14 @@ INFORMATION ABOUT A PATTERN PCRE_INFO_FIRSTCHARACTER Return the value of the first data unit (non-UTF character) of any - matched string in the situation where PCRE_INFO_FIRSTCHARACTERFLAGS - returns 1; otherwise return 0. The fourth argument should point to an + matched string in the situation where PCRE_INFO_FIRSTCHARACTERFLAGS re- + turns 1; otherwise return 0. The fourth argument should point to a uint_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. + mode the value can be up to 0x10ffff, and up to 0xffffffff when not us- + ing UTF-32 mode. PCRE_INFO_FIRSTCHARACTERFLAGS @@ -2853,8 +2851,8 @@ INFORMATION ABOUT A PATTERN Since for the 32-bit library using the non-UTF-32 mode, this function is unable to return the full 32-bit range of characters, this value is - deprecated; instead the PCRE_INFO_REQUIREDCHARFLAGS and - PCRE_INFO_REQUIREDCHAR values should be used. + deprecated; instead the PCRE_INFO_REQUIREDCHARFLAGS and PCRE_INFO_RE- + QUIREDCHAR values should be used. PCRE_INFO_MATCH_EMPTY @@ -2864,10 +2862,10 @@ INFORMATION ABOUT A PATTERN PCRE_INFO_MATCHLIMIT 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 fourth - argument should point to an unsigned 32-bit integer. If no such value - has been set, the call to pcre_fullinfo() returns the error - PCRE_ERROR_UNSET. + (*LIMIT_MATCH=nnnn) at the start, the value is returned. The fourth ar- + gument should point to an unsigned 32-bit integer. If no such value has + been set, the call to pcre_fullinfo() returns the error PCRE_ERROR_UN- + SET. PCRE_INFO_MAXLOOKBEHIND @@ -2903,14 +2901,14 @@ INFORMATION ABOUT A PATTERN strings by name. It is also possible to extract the data directly, by first converting the name to a number in order to access the correct pointers in the output vector (described with pcre_exec() below). To do - the conversion, you need to use the name-to-number map, which is - described by these three values. + the conversion, you need to use the name-to-number map, which is de- + scribed by these three values. The map consists of a number of fixed-size entries. PCRE_INFO_NAMECOUNT gives the number of entries, and PCRE_INFO_NAMEENTRYSIZE gives the size - of each entry; both of these return an int value. The entry size - depends on the length of the longest name. PCRE_INFO_NAMETABLE returns - a pointer to the first entry of the table. This is a pointer to char in + of each entry; both of these return an int value. The entry size de- + pends on the length of the longest name. PCRE_INFO_NAMETABLE returns a + pointer to the first entry of the table. This is a pointer to char in the 8-bit library, where the first two bytes of each entry are the num- ber of the capturing parenthesis, most significant byte first. In the 16-bit library, the pointer points to 16-bit data units, the first of @@ -2926,9 +2924,9 @@ INFORMATION ABOUT A PATTERN for groups of the same number are not permitted. Duplicate names for subpatterns with different numbers are permitted, but only if PCRE_DUP- NAMES is set. They appear in the table in the order in which they were - found in the pattern. In the absence of (?| this is the order of - increasing number; when (?| is used this is not necessarily the case - because later subpatterns may have lower numbers. + found in the pattern. In the absence of (?| this is the order of in- + creasing number; when (?| is used this is not necessarily the case be- + cause later subpatterns may have lower numbers. As a simple example of the name/number table, consider the following pattern after compilation by the 8-bit library (assume PCRE_EXTENDED is @@ -2955,8 +2953,8 @@ INFORMATION ABOUT A PATTERN Return 1 if the pattern can be used for partial matching with pcre_exec(), otherwise 0. The fourth argument should point to an int - variable. From release 8.00, this always returns 1, because the - restrictions that previously applied to partial matching have been + variable. From release 8.00, this always returns 1, because the re- + strictions that previously applied to partial matching have been lifted. The pcrepartial documentation gives details of partial match- ing. @@ -2971,8 +2969,8 @@ INFORMATION ABOUT A PATTERN the PCRE_EXTENDED option, the result is PCRE_CASELESS, PCRE_MULTILINE, and PCRE_EXTENDED. - A pattern is automatically anchored by PCRE if all of its top-level - alternatives begin with one of the following: + A pattern is automatically anchored by PCRE if all of its top-level al- + ternatives begin with one of the following: ^ unless PCRE_MULTILINE is set \A always @@ -2988,13 +2986,13 @@ INFORMATION ABOUT A PATTERN If the pattern set a recursion limit by including an item of the form (*LIMIT_RECURSION=nnnn) at the start, the value is returned. The fourth argument should point to an unsigned 32-bit integer. If no such value - has been set, the call to pcre_fullinfo() returns the error - PCRE_ERROR_UNSET. + has been set, the call to pcre_fullinfo() returns the error PCRE_ER- + ROR_UNSET. PCRE_INFO_SIZE - Return the size of the compiled pattern in bytes (for all three - libraries). The fourth argument should point to a size_t variable. This + Return the size of the compiled pattern in bytes (for all three li- + braries). The fourth argument should point to a size_t variable. This value does not include the size of the pcre structure that is returned by pcre_compile(). The value that is passed as the argument to pcre_malloc() when pcre_compile() is getting memory in which to place @@ -3024,14 +3022,14 @@ INFORMATION ABOUT A PATTERN For anchored patterns, a last literal value is recorded only if it fol- lows something of variable length. For example, for the pattern - /^a\d+z\d+/ the returned value 1 (with "z" returned from - PCRE_INFO_REQUIREDCHAR), but for /^a\dz\d/ the returned value is 0. + /^a\d+z\d+/ the returned value 1 (with "z" returned from PCRE_INFO_RE- + QUIREDCHAR), but for /^a\dz\d/ the returned value is 0. PCRE_INFO_REQUIREDCHAR Return the value of the rightmost literal data unit that must exist in any matched string, other than at its start, if such a value has been - recorded. The fourth argument should point to an uint32_t variable. If + recorded. The fourth argument should point to a uint32_t variable. If there is no such value, 0 is returned. @@ -3065,14 +3063,14 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION The function pcre_exec() is called to match a subject string against a compiled pattern, which is passed in the code argument. If the pattern - was studied, the result of the study should be passed in the extra - argument. You can call pcre_exec() with the same code and extra argu- - ments as many times as you like, in order to match different subject - strings with the same pattern. - - This function is the main matching facility of the library, and it - operates in a Perl-like manner. For specialist use there is also an - alternative matching function, which is described below in the section + was studied, the result of the study should be passed in the extra ar- + gument. You can call pcre_exec() with the same code and extra arguments + as many times as you like, in order to match different subject strings + with the same pattern. + + This function is the main matching facility of the library, and it op- + erates in a Perl-like manner. For specialist use there is also an al- + ternative matching function, which is described below in the section about the pcre_dfa_exec() function. In most applications, the pattern will have been compiled (and option- @@ -3142,8 +3140,8 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION ited repeats. Internally, pcre_exec() uses a function called match(), which it calls - repeatedly (sometimes recursively). The limit set by match_limit is - imposed on the number of times this function is called during a match, + repeatedly (sometimes recursively). The limit set by match_limit is im- + posed on the number of times this function is called during a match, which 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. @@ -3155,12 +3153,12 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION used in this case (but in a different way) to limit how long the match- ing can continue. - The default value for the limit can be set when PCRE is built; the - default default is 10 million, which handles all but the most extreme + The default value for the limit can be set when PCRE is built; the de- + fault default is 10 million, which handles all but the most extreme cases. You can override the default by suppling pcre_exec() with a - pcre_extra block in which match_limit is set, and - PCRE_EXTRA_MATCH_LIMIT is set in the flags field. If the limit is - exceeded, pcre_exec() returns PCRE_ERROR_MATCHLIMIT. + pcre_extra block in which match_limit is set, and PCRE_EX- + TRA_MATCH_LIMIT is set in the flags field. If the limit is exceeded, + pcre_exec() returns PCRE_ERROR_MATCHLIMIT. A value for the match limit may also be supplied by an item at the start of a pattern of the form @@ -3186,9 +3184,9 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION The default value for match_limit_recursion can be set when PCRE is built; the default default is the same value as the default for match_limit. You can override the default by suppling pcre_exec() with - a pcre_extra block in which match_limit_recursion is set, and - PCRE_EXTRA_MATCH_LIMIT_RECURSION is set in the flags field. If the - limit is exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT. + a pcre_extra block in which match_limit_recursion is set, and PCRE_EX- + TRA_MATCH_LIMIT_RECURSION is set in the flags field. If the limit is + exceeded, pcre_exec() returns PCRE_ERROR_RECURSIONLIMIT. A value for the recursion limit may also be supplied by an item at the start of a pattern of the form @@ -3265,345 +3263,344 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION PCRE_NEWLINE_ANYCRLF PCRE_NEWLINE_ANY - These options override the newline definition that was chosen or - defaulted when the pattern was compiled. For details, see the descrip- - tion of pcre_compile() above. During matching, the newline choice - affects the behaviour of the dot, circumflex, and dollar metacharac- - ters. It may also alter the way the match position is advanced after a - match failure for an unanchored pattern. + These options override the newline definition that was chosen or de- + faulted when the pattern was compiled. For details, see the description + of pcre_compile() above. During matching, the newline choice affects + the behaviour of the dot, circumflex, and dollar metacharacters. It may + also alter the way the match position is advanced after a match failure + for an unanchored pattern. When PCRE_NEWLINE_CRLF, PCRE_NEWLINE_ANYCRLF, or PCRE_NEWLINE_ANY is set, and a match attempt for an unanchored pattern fails when the cur- - rent position is at a CRLF sequence, and the pattern contains no - explicit matches for CR or LF characters, the match position is - advanced by two characters instead of one, in other words, to after the - CRLF. + rent position is at a CRLF sequence, and the pattern contains no ex- + plicit matches for CR or LF characters, the match position is advanced + by two characters instead of one, in other words, to after the CRLF. The above rule is a compromise that makes the most common cases work as - expected. For example, if the pattern is .+A (and the PCRE_DOTALL - option is not set), it does not match the string "\r\nA" because, after - failing at the start, it skips both the CR and the LF before retrying. - However, the pattern [\r\n]A does match that string, because it con- + expected. For example, if the pattern is .+A (and the PCRE_DOTALL op- + tion is not set), it does not match the string "\r\nA" because, after + failing at the start, it skips both the CR and the LF before retrying. + However, the pattern [\r\n]A does match that string, because it con- tains an explicit CR or LF reference, and so advances only by one char- acter after the first failure. An explicit match for CR of LF is either a literal appearance of one of - those characters, or one of the \r or \n escape sequences. Implicit - matches such as [^X] do not count, nor does \s (which includes CR and + those characters, or one of the \r or \n escape sequences. Implicit + matches such as [^X] do not count, nor does \s (which includes CR and LF in the characters that it matches). - Notwithstanding the above, anomalous effects may still occur when CRLF + Notwithstanding the above, anomalous effects may still occur when CRLF is a valid newline sequence and explicit \r or \n escapes appear in the pattern. PCRE_NOTBOL This option specifies that first character of the subject string is not - the beginning of a line, so the circumflex metacharacter should not - match before it. Setting this without PCRE_MULTILINE (at compile time) - causes circumflex never to match. This option affects only the behav- + the beginning of a line, so the circumflex metacharacter should not + match before it. Setting this without PCRE_MULTILINE (at compile time) + causes circumflex never to match. This option affects only the behav- iour of the circumflex metacharacter. It does not affect \A. PCRE_NOTEOL This option specifies that the end of the subject string is not the end - of a line, so the dollar metacharacter should not match it nor (except - in multiline mode) a newline immediately before it. Setting this with- + of a line, so the dollar metacharacter should not match it nor (except + in multiline mode) a newline immediately before it. Setting this with- out PCRE_MULTILINE (at compile time) causes dollar never to match. This - option affects only the behaviour of the dollar metacharacter. It does + option affects only the behaviour of the dollar metacharacter. It does not affect \Z or \z. PCRE_NOTEMPTY An empty string is not considered to be a valid match if this option is - set. If there are alternatives in the pattern, they are tried. If all - the alternatives match the empty string, the entire match fails. For + set. If there are alternatives in the pattern, they are tried. If all + the alternatives match the empty string, the entire match fails. For example, if the pattern a?b? - is applied to a string not beginning with "a" or "b", it matches an - empty string at the start of the subject. With PCRE_NOTEMPTY set, this + is applied to a string not beginning with "a" or "b", it matches an + empty string at the start of the subject. With PCRE_NOTEMPTY set, this match is not valid, so PCRE searches further into the string for occur- rences of "a" or "b". PCRE_NOTEMPTY_ATSTART - This is like PCRE_NOTEMPTY, except that an empty string match that is - not at the start of the subject is permitted. If the pattern is - anchored, such a match can occur only if the pattern contains \K. - - Perl has no direct equivalent of PCRE_NOTEMPTY or - PCRE_NOTEMPTY_ATSTART, but it does make a special case of a pattern - match of the empty string within its split() function, and when using - the /g modifier. It is possible to emulate Perl's behaviour after - matching a null string by first trying the match again at the same off- - set with PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED, and then if that - fails, by advancing the starting offset (see below) and trying an ordi- - nary match again. There is some code that demonstrates how to do this - in the pcredemo sample program. In the most general case, you have to - check to see if the newline convention recognizes CRLF as a newline, - and if so, and the current character is CR followed by LF, advance the - starting offset by two characters instead of one. + This is like PCRE_NOTEMPTY, except that an empty string match that is + not at the start of the subject is permitted. If the pattern is an- + chored, such a match can occur only if the pattern contains \K. + + Perl has no direct equivalent of PCRE_NOTEMPTY or PCRE_NOTEMPTY_AT- + START, but it does make a special case of a pattern match of the empty + string within its split() function, and when using the /g modifier. It + is possible to emulate Perl's behaviour after matching a null string by + first trying the match again at the same offset with PCRE_NOTEMPTY_AT- + START and PCRE_ANCHORED, and then if that fails, by advancing the + starting offset (see below) and trying an ordinary match again. There + is some code that demonstrates how to do this in the pcredemo sample + program. In the most general case, you have to check to see if the new- + line convention recognizes CRLF as a newline, and if so, and the cur- + rent character is CR followed by LF, advance the starting offset by two + characters instead of one. PCRE_NO_START_OPTIMIZE - There are a number of optimizations that pcre_exec() uses at the start - of a match, in order to speed up the process. For example, if it is + There are a number of optimizations that pcre_exec() uses at the start + of a match, in order to speed up the process. For example, if it is known that an unanchored match must start with a specific character, it - searches the subject for that character, and fails immediately if it - cannot find it, without actually running the main matching function. + searches the subject for that character, and fails immediately if it + cannot find it, without actually running the main matching function. This means that a special item such as (*COMMIT) at the start of a pat- - tern is not considered until after a suitable starting point for the - match has been found. Also, when callouts or (*MARK) items are in use, + tern is not considered until after a suitable starting point for the + match has been found. Also, when callouts or (*MARK) items are in use, these "start-up" optimizations can cause them to be skipped if the pat- tern is never actually used. The start-up optimizations are in effect a pre-scan of the subject that takes place before the pattern is run. - The PCRE_NO_START_OPTIMIZE option disables the start-up optimizations, - possibly causing performance to suffer, but ensuring that in cases - where the result is "no match", the callouts do occur, and that items + The PCRE_NO_START_OPTIMIZE option disables the start-up optimizations, + possibly causing performance to suffer, but ensuring that in cases + where the result is "no match", the callouts do occur, and that items such as (*COMMIT) and (*MARK) are considered at every possible starting - position in the subject string. If PCRE_NO_START_OPTIMIZE is set at - compile time, it cannot be unset at matching time. The use of + position in the subject string. If PCRE_NO_START_OPTIMIZE is set at + compile time, it cannot be unset at matching time. The use of PCRE_NO_START_OPTIMIZE at matching time (that is, passing it to - pcre_exec()) disables JIT execution; in this situation, matching is - always done using interpretively. + pcre_exec()) disables JIT execution; in this situation, matching is al- + ways done using interpretively. - Setting PCRE_NO_START_OPTIMIZE can change the outcome of a matching - operation. Consider the pattern + Setting PCRE_NO_START_OPTIMIZE can change the outcome of a matching op- + eration. Consider the pattern (*COMMIT)ABC - When this is compiled, PCRE records the fact that a match must start - with the character "A". Suppose the subject string is "DEFABC". The - start-up optimization scans along the subject, finds "A" and runs the - first match attempt from there. The (*COMMIT) item means that the pat- - tern must match the current starting position, which in this case, it - does. However, if the same match is run with PCRE_NO_START_OPTIMIZE - set, the initial scan along the subject string does not happen. The - first match attempt is run starting from "D" and when this fails, - (*COMMIT) prevents any further matches being tried, so the overall - result is "no match". If the pattern is studied, more start-up opti- - mizations may be used. For example, a minimum length for the subject - may be recorded. Consider the pattern + When this is compiled, PCRE records the fact that a match must start + with the character "A". Suppose the subject string is "DEFABC". The + start-up optimization scans along the subject, finds "A" and runs the + first match attempt from there. The (*COMMIT) item means that the pat- + tern must match the current starting position, which in this case, it + does. However, if the same match is run with PCRE_NO_START_OPTIMIZE + set, the initial scan along the subject string does not happen. The + first match attempt is run starting from "D" and when this fails, + (*COMMIT) prevents any further matches being tried, so the overall re- + sult is "no match". If the pattern is studied, more start-up optimiza- + tions may be used. For example, a minimum length for the subject may be + recorded. Consider the pattern (*MARK:A)(X|Y) - The minimum length for a match is one character. If the subject is - "ABC", there will be attempts to match "ABC", "BC", "C", and then - finally an empty string. If the pattern is studied, the final attempt - does not take place, because PCRE knows that the subject is too short, - and so the (*MARK) is never encountered. In this case, studying the - pattern does not affect the overall match result, which is still "no + The minimum length for a match is one character. If the subject is + "ABC", there will be attempts to match "ABC", "BC", "C", and then fi- + nally an empty string. If the pattern is studied, the final attempt + does not take place, because PCRE knows that the subject is too short, + and so the (*MARK) is never encountered. In this case, studying the + pattern does not affect the overall match result, which is still "no match", but it does affect the auxiliary information that is returned. PCRE_NO_UTF8_CHECK When PCRE_UTF8 is set at compile time, the validity of the subject as a - UTF-8 string is automatically checked when pcre_exec() is subsequently + UTF-8 string is automatically checked when pcre_exec() is subsequently called. The entire string is checked before any other processing takes - place. The value of startoffset is also checked to ensure that it - points to the start of a UTF-8 character. There is a discussion about - the validity of UTF-8 strings in the pcreunicode page. If an invalid - sequence of bytes is found, pcre_exec() returns the error - PCRE_ERROR_BADUTF8 or, if PCRE_PARTIAL_HARD is set and the problem is a - truncated character at the end of the subject, PCRE_ERROR_SHORTUTF8. In - both cases, information about the precise nature of the error may also - be returned (see the descriptions of these errors in the section enti- - tled Error return values from pcre_exec() below). If startoffset con- + place. The value of startoffset is also checked to ensure that it + points to the start of a UTF-8 character. There is a discussion about + the validity of UTF-8 strings in the pcreunicode page. If an invalid + sequence of bytes is found, pcre_exec() returns the error PCRE_ER- + ROR_BADUTF8 or, if PCRE_PARTIAL_HARD is set and the problem is a trun- + cated character at the end of the subject, PCRE_ERROR_SHORTUTF8. In + both cases, information about the precise nature of the error may also + be returned (see the descriptions of these errors in the section enti- + tled Error return values from pcre_exec() below). If startoffset con- tains a value that does not point to the start of a UTF-8 character (or to the end of the subject), PCRE_ERROR_BADUTF8_OFFSET is returned. - If you already know that your subject is valid, and you want to skip - these checks for performance reasons, you can set the - PCRE_NO_UTF8_CHECK option when calling pcre_exec(). You might want to - do this for the second and subsequent calls to pcre_exec() if you are - making repeated calls to find all the matches in a single subject - string. However, you should be sure that the value of startoffset - points to the start of a character (or the end of the subject). When + If you already know that your subject is valid, and you want to skip + these checks for performance reasons, you can set the + PCRE_NO_UTF8_CHECK option when calling pcre_exec(). You might want to + do this for the second and subsequent calls to pcre_exec() if you are + making repeated calls to find all the matches in a single subject + string. However, you should be sure that the value of startoffset + points to the start of a character (or the end of the subject). When PCRE_NO_UTF8_CHECK is set, the effect of passing an invalid string as a - subject or an invalid value of startoffset is undefined. Your program + subject or an invalid value of startoffset is undefined. Your program may crash or loop. PCRE_PARTIAL_HARD PCRE_PARTIAL_SOFT - These options turn on the partial matching feature. For backwards com- - patibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial - match occurs if the end of the subject string is reached successfully, - but there are not enough subject characters to complete the match. If + These options turn on the partial matching feature. For backwards com- + patibility, PCRE_PARTIAL is a synonym for PCRE_PARTIAL_SOFT. A partial + match occurs if the end of the subject string is reached successfully, + but there are not enough subject characters to complete the match. If this happens when PCRE_PARTIAL_SOFT (but not PCRE_PARTIAL_HARD) is set, - matching continues by testing any remaining alternatives. Only if no - complete match can be found is PCRE_ERROR_PARTIAL returned instead of - PCRE_ERROR_NOMATCH. In other words, PCRE_PARTIAL_SOFT says that the - caller is prepared to handle a partial match, but only if no complete + matching continues by testing any remaining alternatives. Only if no + complete match can be found is PCRE_ERROR_PARTIAL returned instead of + PCRE_ERROR_NOMATCH. In other words, PCRE_PARTIAL_SOFT says that the + caller is prepared to handle a partial match, but only if no complete match can be found. - If PCRE_PARTIAL_HARD is set, it overrides PCRE_PARTIAL_SOFT. In this - case, if a partial match is found, pcre_exec() immediately returns - PCRE_ERROR_PARTIAL, without considering any other alternatives. In - other words, when PCRE_PARTIAL_HARD is set, a partial match is consid- + If PCRE_PARTIAL_HARD is set, it overrides PCRE_PARTIAL_SOFT. In this + case, if a partial match is found, pcre_exec() immediately returns + PCRE_ERROR_PARTIAL, without considering any other alternatives. In + other words, when PCRE_PARTIAL_HARD is set, a partial match is consid- ered to be more important that an alternative complete match. - In both cases, the portion of the string that was inspected when the + In both cases, the portion of the string that was inspected when the partial match was found is set as the first matching string. There is a - more detailed discussion of partial and multi-segment matching, with + more detailed discussion of partial and multi-segment matching, with examples, in the pcrepartial documentation. The string to be matched by pcre_exec() - The subject string is passed to pcre_exec() as a pointer in subject, a - length in length, and a starting offset in startoffset. The units for - length and startoffset are bytes for the 8-bit library, 16-bit data - items for the 16-bit library, and 32-bit data items for the 32-bit - library. - - If startoffset is negative or greater than the length of the subject, - pcre_exec() returns PCRE_ERROR_BADOFFSET. When the starting offset is - 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 - offset must point to the start of a character, or the end of the sub- - ject (in UTF-32 mode, one data unit equals one character, so all off- - sets are valid). Unlike the pattern string, the subject may contain - binary zeroes. - - A non-zero starting offset is useful when searching for another match - in the same subject by calling pcre_exec() again after a previous suc- - cess. Setting startoffset differs from just passing over a shortened - string and setting PCRE_NOTBOL in the case of a pattern that begins + The subject string is passed to pcre_exec() as a pointer in subject, a + length in length, and a starting offset in startoffset. The units for + length and startoffset are bytes for the 8-bit library, 16-bit data + items for the 16-bit library, and 32-bit data items for the 32-bit li- + brary. + + If startoffset is negative or greater than the length of the subject, + pcre_exec() returns PCRE_ERROR_BADOFFSET. When the starting offset is + 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 + offset must point to the start of a character, or the end of the sub- + ject (in UTF-32 mode, one data unit equals one character, so all off- + sets are valid). Unlike the pattern string, the subject may contain bi- + nary zeroes. + + A non-zero starting offset is useful when searching for another match + in the same subject by calling pcre_exec() again after a previous suc- + cess. Setting startoffset differs from just passing over a shortened + string and setting PCRE_NOTBOL in the case of a pattern that begins with any kind of lookbehind. For example, consider the pattern \Biss\B - which finds occurrences of "iss" in the middle of words. (\B matches - only if the current position in the subject is not a word boundary.) - When applied to the string "Mississipi" the first call to pcre_exec() - finds the first occurrence. If pcre_exec() is called again with just - the remainder of the subject, namely "issipi", it does not match, - because \B is always false at the start of the subject, which is deemed - to be a word boundary. However, if pcre_exec() is passed the entire + which finds occurrences of "iss" in the middle of words. (\B matches + only if the current position in the subject is not a word boundary.) + When applied to the string "Mississipi" the first call to pcre_exec() + finds the first occurrence. If pcre_exec() is called again with just + the remainder of the subject, namely "issipi", it does not match, be- + cause \B is always false at the start of the subject, which is deemed + to be a word boundary. However, if pcre_exec() is passed the entire string again, but with startoffset set to 4, it finds the second occur- - rence of "iss" because it is able to look behind the starting point to + rence of "iss" because it is able to look behind the starting point to discover that it is preceded by a letter. - Finding all the matches in a subject is tricky when the pattern can + Finding all the matches in a subject is tricky when the pattern can match an empty string. It is possible to emulate Perl's /g behaviour by - first trying the match again at the same offset, with the - PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED options, and then if that - fails, advancing the starting offset and trying an ordinary match + first trying the match again at the same offset, with the + PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED options, and then if that + fails, advancing the starting offset and trying an ordinary match again. There is some code that demonstrates how to do this in the pcre- demo sample program. In the most general case, you have to check to see - if the newline convention recognizes CRLF as a newline, and if so, and + if the newline convention recognizes CRLF as a newline, and if so, and the current character is CR followed by LF, advance the starting offset by two characters instead of one. - If a non-zero starting offset is passed when the pattern is anchored, + If a non-zero starting offset is passed when the pattern is anchored, one attempt to match at the given offset is made. This can only succeed - if the pattern does not require the match to be at the start of the + if the pattern does not require the match to be at the start of the subject. How pcre_exec() returns captured substrings - In general, a pattern matches a certain portion of the subject, and in - addition, further substrings from the subject may be picked out by - parts of the pattern. Following the usage in Jeffrey Friedl's book, - this is called "capturing" in what follows, and the phrase "capturing - subpattern" is used for a fragment of a pattern that picks out a sub- - string. PCRE supports several other kinds of parenthesized subpattern + In general, a pattern matches a certain portion of the subject, and in + addition, further substrings from the subject may be picked out by + parts of the pattern. Following the usage in Jeffrey Friedl's book, + this is called "capturing" in what follows, and the phrase "capturing + subpattern" is used for a fragment of a pattern that picks out a sub- + string. PCRE supports several other kinds of parenthesized subpattern that do not cause substrings to be captured. Captured substrings are returned to the caller via a vector of integers - whose address is passed in ovector. The number of elements in the vec- - tor is passed in ovecsize, which must be a non-negative number. Note: + whose address is passed in ovector. The number of elements in the vec- + tor is passed in ovecsize, which must be a non-negative number. Note: this argument is NOT the size of ovector in bytes. - The first two-thirds of the vector is used to pass back captured sub- - strings, each substring using a pair of integers. The remaining third - of the vector is used as workspace by pcre_exec() while matching cap- - turing subpatterns, and is not available for passing back information. - The number passed in ovecsize should always be a multiple of three. If + The first two-thirds of the vector is used to pass back captured sub- + strings, each substring using a pair of integers. The remaining third + of the vector is used as workspace by pcre_exec() while matching cap- + turing subpatterns, and is not available for passing back information. + The number passed in ovecsize should always be a multiple of three. If it is not, it is rounded down. - When a match is successful, information about captured substrings is - returned in pairs of integers, starting at the beginning of ovector, - and continuing up to two-thirds of its length at the most. The first - element of each pair is set to the offset of the first character in a - substring, and the second is set to the offset of the first character - after the end of a substring. These values are always data unit off- - sets, even in UTF mode. They are byte offsets in the 8-bit library, - 16-bit data item offsets in the 16-bit library, and 32-bit data item + When a match is successful, information about captured substrings is + returned in pairs of integers, starting at the beginning of ovector, + and continuing up to two-thirds of its length at the most. The first + element of each pair is set to the offset of the first character in a + substring, and the second is set to the offset of the first character + after the end of a substring. These values are always data unit off- + sets, even in UTF mode. They are byte offsets in the 8-bit library, + 16-bit data item offsets in the 16-bit library, and 32-bit data item offsets in the 32-bit library. Note: they are not character counts. - The first pair of integers, ovector[0] and ovector[1], identify the - portion of the subject string matched by the entire pattern. The next - pair is used for the first capturing subpattern, and so on. The value + The first pair of integers, ovector[0] and ovector[1], identify the + portion of the subject string matched by the entire pattern. The next + pair is used for the first capturing subpattern, and so on. The value returned by pcre_exec() is one more than the highest numbered pair that - has been set. For example, if two substrings have been captured, the - returned value is 3. If there are no capturing subpatterns, the return + has been set. For example, if two substrings have been captured, the + returned value is 3. If there are no capturing subpatterns, the return value from a successful match is 1, indicating that just the first pair of offsets has been set. If a capturing subpattern is matched repeatedly, it is the last portion of the string that it matched that is returned. - If the vector is too small to hold all the captured substring offsets, + If the vector is too small to hold all the captured substring offsets, it is used as far as possible (up to two-thirds of its length), and the - function returns a value of zero. If neither the actual string matched - nor any captured substrings are of interest, pcre_exec() may be called - with ovector passed as NULL and ovecsize as zero. However, if the pat- - tern contains back references and the ovector is not big enough to - remember the related substrings, PCRE has to get additional memory for - use during matching. Thus it is usually advisable to supply an ovector + function returns a value of zero. If neither the actual string matched + nor any captured substrings are of interest, pcre_exec() may be called + with ovector passed as NULL and ovecsize as zero. However, if the pat- + tern contains back references and the ovector is not big enough to re- + member the related substrings, PCRE has to get additional memory for + use during matching. Thus it is usually advisable to supply an ovector of reasonable size. - There are some cases where zero is returned (indicating vector over- - flow) when in fact the vector is exactly the right size for the final + There are some cases where zero is returned (indicating vector over- + flow) when in fact the vector is exactly the right size for the final match. For example, consider the pattern (a)(?:(b)c|bd) - If a vector of 6 elements (allowing for only 1 captured substring) is + If a vector of 6 elements (allowing for only 1 captured substring) is given with subject string "abd", pcre_exec() will try to set the second captured string, thereby recording a vector overflow, before failing to - match "c" and backing up to try the second alternative. The zero - return, however, does correctly indicate that the maximum number of - slots (namely 2) have been filled. In similar cases where there is tem- - porary overflow, but the final number of used slots is actually less - than the maximum, a non-zero value is returned. + match "c" and backing up to try the second alternative. The zero re- + turn, however, does correctly indicate that the maximum number of slots + (namely 2) have been filled. In similar cases where there is temporary + overflow, but the final number of used slots is actually less than the + maximum, a non-zero value is returned. The pcre_fullinfo() function can be used to find out how many capturing - subpatterns there are in a compiled pattern. The smallest size for - ovector that will allow for n captured substrings, in addition to the + subpatterns there are in a compiled pattern. The smallest size for + ovector that will allow for n captured substrings, in addition to the offsets of the substring matched by the whole pattern, is (n+1)*3. - It is possible for capturing subpattern number n+1 to match some part + It is possible for capturing subpattern number n+1 to match some part of the subject when subpattern n has not been used at all. For example, - if the string "abc" is matched against the pattern (a|(z))(bc) the - return from the function is 4, and subpatterns 1 and 3 are matched, but - 2 is not. When this happens, both values in the offset pairs corre- - sponding to unused subpatterns are set to -1. - - Offset values that correspond to unused subpatterns at the end of the - expression are also set to -1. For example, if the string "abc" is - matched against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not - matched. The return from the function is 2, because the highest used - capturing subpattern number is 1, and the offsets for for the second - and third capturing subpatterns (assuming the vector is large enough, + if the string "abc" is matched against the pattern (a|(z))(bc) the re- + turn from the function is 4, and subpatterns 1 and 3 are matched, but 2 + is not. When this happens, both values in the offset pairs correspond- + ing to unused subpatterns are set to -1. + + Offset values that correspond to unused subpatterns at the end of the + expression are also set to -1. For example, if the string "abc" is + matched against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not + matched. The return from the function is 2, because the highest used + capturing subpattern number is 1, and the offsets for for the second + and third capturing subpatterns (assuming the vector is large enough, of course) are set to -1. - Note: Elements in the first two-thirds of ovector that do not corre- - spond to capturing parentheses in the pattern are never changed. That - is, if a pattern contains n capturing parentheses, no more than ovec- - tor[0] to ovector[2n+1] are set by pcre_exec(). The other elements (in + Note: Elements in the first two-thirds of ovector that do not corre- + spond to capturing parentheses in the pattern are never changed. That + is, if a pattern contains n capturing parentheses, no more than ovec- + tor[0] to ovector[2n+1] are set by pcre_exec(). The other elements (in the first two-thirds) retain whatever values they previously had. - Some convenience functions are provided for extracting the captured + Some convenience functions are provided for extracting the captured substrings as separate strings. These are described below. Error return values from pcre_exec() - If pcre_exec() fails, it returns a negative number. The following are + If pcre_exec() fails, it returns a negative number. The following are defined in the header file: PCRE_ERROR_NOMATCH (-1) @@ -3612,7 +3609,7 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION PCRE_ERROR_NULL (-2) - Either code or subject was passed as NULL, or ovector was NULL and + Either code or subject was passed as NULL, or ovector was NULL and ovecsize was not zero. PCRE_ERROR_BADOPTION (-3) @@ -3621,82 +3618,82 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION PCRE_ERROR_BADMAGIC (-4) - PCRE stores a 4-byte "magic number" at the start of the compiled code, + PCRE stores a 4-byte "magic number" at the start of the compiled code, to catch the case when it is passed a junk pointer and to detect when a pattern that was compiled in an environment of one endianness is run in - an environment with the other endianness. This is the error that PCRE + an environment with the other endianness. This is the error that PCRE gives when the magic number is not present. PCRE_ERROR_UNKNOWN_OPCODE (-5) While running the pattern match, an unknown item was encountered in the - compiled pattern. This error could be caused by a bug in PCRE or by + compiled pattern. This error could be caused by a bug in PCRE or by overwriting of the compiled pattern. PCRE_ERROR_NOMEMORY (-6) - If a pattern contains back references, but the ovector that is passed + If a pattern contains back references, but the ovector that is passed to pcre_exec() is not big enough to remember the referenced substrings, - PCRE gets a block of memory at the start of matching to use for this - purpose. If the call via pcre_malloc() fails, this error is given. The + PCRE gets a block of memory at the start of matching to use for this + purpose. If the call via pcre_malloc() fails, this error is given. The memory is automatically freed at the end of matching. - This error is also given if pcre_stack_malloc() fails in pcre_exec(). - This can happen only when PCRE has been compiled with --disable-stack- + This error is also given if pcre_stack_malloc() fails in pcre_exec(). + This can happen only when PCRE has been compiled with --disable-stack- for-recursion. PCRE_ERROR_NOSUBSTRING (-7) - This error is used by the pcre_copy_substring(), pcre_get_substring(), - and pcre_get_substring_list() functions (see below). It is never - returned by pcre_exec(). + This error is used by the pcre_copy_substring(), pcre_get_substring(), + and pcre_get_substring_list() functions (see below). It is never re- + turned by pcre_exec(). PCRE_ERROR_MATCHLIMIT (-8) - The backtracking limit, as specified by the match_limit field in a - pcre_extra structure (or defaulted) was reached. See the description + The backtracking limit, as specified by the match_limit field in a + pcre_extra structure (or defaulted) was reached. See the description above. PCRE_ERROR_CALLOUT (-9) This error is never generated by pcre_exec() itself. It is provided for - use by callout functions that want to yield a distinctive error code. + use by callout functions that want to yield a distinctive error code. See the pcrecallout documentation for details. PCRE_ERROR_BADUTF8 (-10) - A string that contains an invalid UTF-8 byte sequence was passed as a - subject, and the PCRE_NO_UTF8_CHECK option was not set. If the size of - the output vector (ovecsize) is at least 2, the byte offset to the - start of the the invalid UTF-8 character is placed in the first ele- - ment, and a reason code is placed in the second element. The reason + A string that contains an invalid UTF-8 byte sequence was passed as a + subject, and the PCRE_NO_UTF8_CHECK option was not set. If the size of + the output vector (ovecsize) is at least 2, the byte offset to the + start of the the invalid UTF-8 character is placed in the first ele- + ment, and a reason code is placed in the second element. The reason codes are listed in the following section. For backward compatibility, - if PCRE_PARTIAL_HARD is set and the problem is a truncated UTF-8 char- - acter at the end of the subject (reason codes 1 to 5), - PCRE_ERROR_SHORTUTF8 is returned instead of PCRE_ERROR_BADUTF8. + if PCRE_PARTIAL_HARD is set and the problem is a truncated UTF-8 char- + acter at the end of the subject (reason codes 1 to 5), PCRE_ER- + ROR_SHORTUTF8 is returned instead of PCRE_ERROR_BADUTF8. PCRE_ERROR_BADUTF8_OFFSET (-11) - The UTF-8 byte sequence that was passed as a subject was checked and - found to be valid (the PCRE_NO_UTF8_CHECK option was not set), but the - value of startoffset did not point to the beginning of a UTF-8 charac- + The UTF-8 byte sequence that was passed as a subject was checked and + found to be valid (the PCRE_NO_UTF8_CHECK option was not set), but the + value of startoffset did not point to the beginning of a UTF-8 charac- ter or the end of the subject. PCRE_ERROR_PARTIAL (-12) - The subject string did not match, but it did match partially. See the + The subject string did not match, but it did match partially. See the pcrepartial documentation for details of partial matching. PCRE_ERROR_BADPARTIAL (-13) - This code is no longer in use. It was formerly returned when the - PCRE_PARTIAL option was used with a compiled pattern containing items - that were not supported for partial matching. From release 8.00 - onwards, there are no restrictions on partial matching. + This code is no longer in use. It was formerly returned when the + PCRE_PARTIAL option was used with a compiled pattern containing items + that were not supported for partial matching. From release 8.00 on- + wards, there are no restrictions on partial matching. PCRE_ERROR_INTERNAL (-14) - An unexpected internal error has occurred. This error could be caused + An unexpected internal error has occurred. This error could be caused by a bug in PCRE or by overwriting of the compiled pattern. PCRE_ERROR_BADCOUNT (-15) @@ -3706,8 +3703,8 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION PCRE_ERROR_RECURSIONLIMIT (-21) The internal recursion limit, as specified by the match_limit_recursion - field in a pcre_extra structure (or defaulted) was reached. See the - description above. + field in a pcre_extra structure (or defaulted) was reached. See the de- + scription above. PCRE_ERROR_BADNEWLINE (-23) @@ -3720,30 +3717,30 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION PCRE_ERROR_SHORTUTF8 (-25) - This error is returned instead of PCRE_ERROR_BADUTF8 when the subject - string ends with a truncated UTF-8 character and the PCRE_PARTIAL_HARD - option is set. Information about the failure is returned as for - PCRE_ERROR_BADUTF8. It is in fact sufficient to detect this case, but - this special error code for PCRE_PARTIAL_HARD precedes the implementa- - tion of returned information; it is retained for backwards compatibil- + This error is returned instead of PCRE_ERROR_BADUTF8 when the subject + string ends with a truncated UTF-8 character and the PCRE_PARTIAL_HARD + option is set. Information about the failure is returned as for + PCRE_ERROR_BADUTF8. It is in fact sufficient to detect this case, but + this special error code for PCRE_PARTIAL_HARD precedes the implementa- + tion of returned information; it is retained for backwards compatibil- ity. PCRE_ERROR_RECURSELOOP (-26) This error is returned when pcre_exec() detects a recursion loop within - the pattern. Specifically, it means that either the whole pattern or a - subpattern has been called recursively for the second time at the same + the pattern. Specifically, it means that either the whole pattern or a + subpattern has been called recursively for the second time at the same position in the subject string. Some simple patterns that might do this - are detected and faulted at compile time, but more complicated cases, + are detected and faulted at compile time, but more complicated cases, in particular mutual recursions between two different subpatterns, can- not be detected until run time. PCRE_ERROR_JIT_STACKLIMIT (-27) - This error is returned when a pattern that was successfully studied - using a JIT compile option is being matched, but the memory available - for the just-in-time processing stack is not large enough. See the - pcrejit documentation for more details. + This error is returned when a pattern that was successfully studied us- + ing a JIT compile option is being matched, but the memory available for + the just-in-time processing stack is not large enough. See the pcrejit + documentation for more details. PCRE_ERROR_BADMODE (-28) @@ -3752,38 +3749,38 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION PCRE_ERROR_BADENDIANNESS (-29) - This error is given if a pattern that was compiled and saved is - reloaded on a host with different endianness. The utility function + This error is given if a pattern that was compiled and saved is + reloaded on a host with different endianness. The utility function pcre_pattern_to_host_byte_order() can be used to convert such a pattern so that it runs on the new host. PCRE_ERROR_JIT_BADOPTION - This error is returned when a pattern that was successfully studied - using a JIT compile option is being matched, but the matching mode - (partial or complete match) does not correspond to any JIT compilation - mode. When the JIT fast path function is used, this error may be also - given for invalid options. See the pcrejit documentation for more - details. + This error is returned when a pattern that was successfully studied us- + ing a JIT compile option is being matched, but the matching mode (par- + tial or complete match) does not correspond to any JIT compilation + mode. When the JIT fast path function is used, this error may be also + given for invalid options. See the pcrejit documentation for more de- + tails. PCRE_ERROR_BADLENGTH (-32) - This error is given if pcre_exec() is called with a negative value for + This error is given if pcre_exec() is called with a negative value for the length argument. Error numbers -16 to -20, -22, and 30 are not used by pcre_exec(). Reason codes for invalid UTF-8 strings - This section applies only to the 8-bit library. The corresponding - information for the 16-bit and 32-bit libraries is given in the pcre16 + This section applies only to the 8-bit library. The corresponding in- + formation for the 16-bit and 32-bit libraries is given in the pcre16 and pcre32 pages. When pcre_exec() returns either PCRE_ERROR_BADUTF8 or PCRE_ERROR_SHORT- - UTF8, and the size of the output vector (ovecsize) is at least 2, the - offset of the start of the invalid UTF-8 character is placed in the + UTF8, and the size of the output vector (ovecsize) is at least 2, the + offset of the start of the invalid UTF-8 character is placed in the first output vector element (ovector[0]) and a reason code is placed in - the second element (ovector[1]). The reason codes are given names in + the second element (ovector[1]). The reason codes are given names in the pcre.h header file: PCRE_UTF8_ERR1 @@ -3792,10 +3789,10 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION PCRE_UTF8_ERR4 PCRE_UTF8_ERR5 - The string ends with a truncated UTF-8 character; the code specifies - how many bytes are missing (1 to 5). Although RFC 3629 restricts UTF-8 - characters to be no longer than 4 bytes, the encoding scheme (origi- - nally defined by RFC 2279) allows for up to 6 bytes, and this is + The string ends with a truncated UTF-8 character; the code specifies + how many bytes are missing (1 to 5). Although RFC 3629 restricts UTF-8 + characters to be no longer than 4 bytes, the encoding scheme (origi- + nally defined by RFC 2279) allows for up to 6 bytes, and this is checked first; hence the possibility of 4 or 5 missing bytes. PCRE_UTF8_ERR6 @@ -3805,24 +3802,24 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION PCRE_UTF8_ERR10 The two most significant bits of the 2nd, 3rd, 4th, 5th, or 6th byte of - the character do not have the binary value 0b10 (that is, either the + the character do not have the binary value 0b10 (that is, either the most significant bit is 0, or the next bit is 1). PCRE_UTF8_ERR11 PCRE_UTF8_ERR12 - A character that is valid by the RFC 2279 rules is either 5 or 6 bytes + A character that is valid by the RFC 2279 rules is either 5 or 6 bytes long; these code points are excluded by RFC 3629. PCRE_UTF8_ERR13 - A 4-byte character has a value greater than 0x10fff; these code points + A 4-byte character has a value greater than 0x10fff; these code points are excluded by RFC 3629. PCRE_UTF8_ERR14 - A 3-byte character has a value in the range 0xd800 to 0xdfff; this - range of code points are reserved by RFC 3629 for use with UTF-16, and + A 3-byte character has a value in the range 0xd800 to 0xdfff; this + range of code points are reserved by RFC 3629 for use with UTF-16, and so are excluded from UTF-8. PCRE_UTF8_ERR15 @@ -3831,28 +3828,28 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION PCRE_UTF8_ERR18 PCRE_UTF8_ERR19 - A 2-, 3-, 4-, 5-, or 6-byte character is "overlong", that is, it codes - for a value that can be represented by fewer bytes, which is invalid. - For example, the two bytes 0xc0, 0xae give the value 0x2e, whose cor- + A 2-, 3-, 4-, 5-, or 6-byte character is "overlong", that is, it codes + for a value that can be represented by fewer bytes, which is invalid. + For example, the two bytes 0xc0, 0xae give the value 0x2e, whose cor- rect coding uses just one byte. PCRE_UTF8_ERR20 The two most significant bits of the first byte of a character have the - binary value 0b10 (that is, the most significant bit is 1 and the sec- - ond is 0). Such a byte can only validly occur as the second or subse- + binary value 0b10 (that is, the most significant bit is 1 and the sec- + ond is 0). Such a byte can only validly occur as the second or subse- quent byte of a multi-byte character. PCRE_UTF8_ERR21 - The first byte of a character has the value 0xfe or 0xff. These values + The first byte of a character has the value 0xfe or 0xff. These values can never occur in a valid UTF-8 string. PCRE_UTF8_ERR22 - This error code was formerly used when the presence of a so-called - "non-character" caused an error. Unicode corrigendum #9 makes it clear - that such characters should not cause a string to be rejected, and so + This error code was formerly used when the presence of a so-called + "non-character" caused an error. Unicode corrigendum #9 makes it clear + that such characters should not cause a string to be rejected, and so this code is no longer in use and is never returned. @@ -3869,78 +3866,78 @@ EXTRACTING CAPTURED SUBSTRINGS BY NUMBER int pcre_get_substring_list(const char *subject, int *ovector, int stringcount, const char ***listptr); - Captured substrings can be accessed directly by using the offsets - returned by pcre_exec() in ovector. For convenience, the functions + Captured substrings can be accessed directly by using the offsets re- + turned by pcre_exec() in ovector. For convenience, the functions pcre_copy_substring(), pcre_get_substring(), and pcre_get_sub- - string_list() are provided for extracting captured substrings as new, - separate, zero-terminated strings. These functions identify substrings - by number. The next section describes functions for extracting named + string_list() are provided for extracting captured substrings as new, + separate, zero-terminated strings. These functions identify substrings + by number. The next section describes functions for extracting named substrings. - A substring that contains a binary zero is correctly extracted and has - a further zero added on the end, but the result is not, of course, a C - string. However, you can process such a string by referring to the - length that is returned by pcre_copy_substring() and pcre_get_sub- + A substring that contains a binary zero is correctly extracted and has + a further zero added on the end, but the result is not, of course, a C + string. However, you can process such a string by referring to the + length that is returned by pcre_copy_substring() and pcre_get_sub- string(). Unfortunately, the interface to pcre_get_substring_list() is - not adequate for handling strings containing binary zeros, because the + not adequate for handling strings containing binary zeros, because the end of the final string is not independently indicated. - The first three arguments are the same for all three of these func- - tions: subject is the subject string that has just been successfully + The first three arguments are the same for all three of these func- + tions: subject is the subject string that has just been successfully matched, ovector is a pointer to the vector of integer offsets that was passed to pcre_exec(), and stringcount is the number of substrings that - were captured by the match, including the substring that matched the + were captured by the match, including the substring that matched the entire regular expression. This is the value returned by pcre_exec() if - it is greater than zero. If pcre_exec() returned zero, indicating that - it ran out of space in ovector, the value passed as stringcount should + it is greater than zero. If pcre_exec() returned zero, indicating that + it ran out of space in ovector, the value passed as stringcount should be the number of elements in the vector divided by three. - The functions pcre_copy_substring() and pcre_get_substring() extract a - single substring, whose number is given as stringnumber. A value of - zero extracts the substring that matched the entire pattern, whereas - higher values extract the captured substrings. For pcre_copy_sub- - string(), the string is placed in buffer, whose length is given by - buffersize, while for pcre_get_substring() a new block of memory is - obtained via pcre_malloc, and its address is returned via stringptr. - The yield of the function is the length of the string, not including - the terminating zero, or one of these error codes: + The functions pcre_copy_substring() and pcre_get_substring() extract a + single substring, whose number is given as stringnumber. A value of + zero extracts the substring that matched the entire pattern, whereas + higher values extract the captured substrings. For pcre_copy_sub- + string(), the string is placed in buffer, whose length is given by + buffersize, while for pcre_get_substring() a new block of memory is ob- + tained via pcre_malloc, and its address is returned via stringptr. The + yield of the function is the length of the string, not including the + terminating zero, or one of these error codes: PCRE_ERROR_NOMEMORY (-6) - The buffer was too small for pcre_copy_substring(), or the attempt to + The buffer was too small for pcre_copy_substring(), or the attempt to get memory failed for pcre_get_substring(). PCRE_ERROR_NOSUBSTRING (-7) There is no substring whose number is stringnumber. - The pcre_get_substring_list() function extracts all available sub- - strings and builds a list of pointers to them. All this is done in a + The pcre_get_substring_list() function extracts all available sub- + strings and builds a list of pointers to them. All this is done in a single block of memory that is obtained via pcre_malloc. The address of - the memory block is returned via listptr, which is also the start of - the list of string pointers. The end of the list is marked by a NULL - pointer. The yield of the function is zero if all went well, or the - error code + the memory block is returned via listptr, which is also the start of + the list of string pointers. The end of the list is marked by a NULL + pointer. The yield of the function is zero if all went well, or the er- + ror code PCRE_ERROR_NOMEMORY (-6) if the attempt to get the memory block failed. - When any of these functions encounter a substring that is unset, which - can happen when capturing subpattern number n+1 matches some part of - the subject, but subpattern n has not been used at all, they return an + When any of these functions encounter a substring that is unset, which + can happen when capturing subpattern number n+1 matches some part of + the subject, but subpattern n has not been used at all, they return an empty string. This can be distinguished from a genuine zero-length sub- - string by inspecting the appropriate offset in ovector, which is nega- + string by inspecting the appropriate offset in ovector, which is nega- tive for unset substrings. - The two convenience functions pcre_free_substring() and pcre_free_sub- - string_list() can be used to free the memory returned by a previous + The two convenience functions pcre_free_substring() and pcre_free_sub- + string_list() can be used to free the memory returned by a previous call of pcre_get_substring() or pcre_get_substring_list(), respec- - tively. They do nothing more than call the function pointed to by - pcre_free, which of course could be called directly from a C program. - However, PCRE is used in some situations where it is linked via a spe- - cial interface to another programming language that cannot use - pcre_free directly; it is for these cases that the functions are pro- + tively. They do nothing more than call the function pointed to by + pcre_free, which of course could be called directly from a C program. + However, PCRE is used in some situations where it is linked via a spe- + cial interface to another programming language that cannot use + pcre_free directly; it is for these cases that the functions are pro- vided. @@ -3959,7 +3956,7 @@ EXTRACTING CAPTURED SUBSTRINGS BY NAME int stringcount, const char *stringname, const char **stringptr); - To extract a substring by name, you first have to find associated num- + To extract a substring by name, you first have to find associated num- ber. For example, for this pattern (a+)b(?<xxx>\d+)... @@ -3968,35 +3965,35 @@ EXTRACTING CAPTURED SUBSTRINGS BY NAME be unique (PCRE_DUPNAMES was not set), you can find the number from the name by calling pcre_get_stringnumber(). The first argument is the com- piled pattern, and the second is the name. The yield of the function is - the subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if there is no + the subpattern number, or PCRE_ERROR_NOSUBSTRING (-7) if there is no subpattern of that name. Given the number, you can extract the substring directly, or use one of the functions described in the previous section. For convenience, there are also two functions that do the whole job. - Most of the arguments of pcre_copy_named_substring() and - pcre_get_named_substring() are the same as those for the similarly - named functions that extract by number. As these are described in the - previous section, they are not re-described here. There are just two + Most of the arguments of pcre_copy_named_substring() and + pcre_get_named_substring() are the same as those for the similarly + named functions that extract by number. As these are described in the + previous section, they are not re-described here. There are just two differences: - First, instead of a substring number, a substring name is given. Sec- + First, instead of a substring number, a substring name is given. Sec- ond, there is an extra argument, given at the start, which is a pointer - to the compiled pattern. This is needed in order to gain access to the + to the compiled pattern. This is needed in order to gain access to the name-to-number translation table. - These functions call pcre_get_stringnumber(), and if it succeeds, they - then call pcre_copy_substring() or pcre_get_substring(), as appropri- - ate. NOTE: If PCRE_DUPNAMES is set and there are duplicate names, the + These functions call pcre_get_stringnumber(), and if it succeeds, they + then call pcre_copy_substring() or pcre_get_substring(), as appropri- + ate. NOTE: If PCRE_DUPNAMES is set and there are duplicate names, the behaviour may not be what you want (see the next section). Warning: If the pattern uses the (?| feature to set up multiple subpat- - terns with the same number, as described in the section on duplicate - subpattern numbers in the pcrepattern page, you cannot use names to - distinguish the different subpatterns, because names are not included - in the compiled code. The matching process uses only numbers. For this - reason, the use of different names for subpatterns of the same number + terns with the same number, as described in the section on duplicate + subpattern numbers in the pcrepattern page, you cannot use names to + distinguish the different subpatterns, because names are not included + in the compiled code. The matching process uses only numbers. For this + reason, the use of different names for subpatterns of the same number causes an error at compile time. @@ -4005,77 +4002,77 @@ DUPLICATE SUBPATTERN NAMES int pcre_get_stringtable_entries(const pcre *code, const char *name, char **first, char **last); - When a pattern is compiled with the PCRE_DUPNAMES option, names for - subpatterns are not required to be unique. (Duplicate names are always - allowed for subpatterns with the same number, created by using the (?| - feature. Indeed, if such subpatterns are named, they are required to + When a pattern is compiled with the PCRE_DUPNAMES option, names for + subpatterns are not required to be unique. (Duplicate names are always + allowed for subpatterns with the same number, created by using the (?| + feature. Indeed, if such subpatterns are named, they are required to use the same names.) Normally, patterns with duplicate names are such that in any one match, - only one of the named subpatterns participates. An example is shown in + only one of the named subpatterns participates. An example is shown in the pcrepattern documentation. - When duplicates are present, pcre_copy_named_substring() and - pcre_get_named_substring() return the first substring corresponding to - the given name that is set. If none are set, PCRE_ERROR_NOSUBSTRING - (-7) is returned; no data is returned. The pcre_get_stringnumber() - function returns one of the numbers that are associated with the name, + When duplicates are present, pcre_copy_named_substring() and + pcre_get_named_substring() return the first substring corresponding to + the given name that is set. If none are set, PCRE_ERROR_NOSUBSTRING + (-7) is returned; no data is returned. The pcre_get_stringnumber() + function returns one of the numbers that are associated with the name, but it is not defined which it is. - If you want to get full details of all captured substrings for a given - name, you must use the pcre_get_stringtable_entries() function. The + If you want to get full details of all captured substrings for a given + name, you must use the pcre_get_stringtable_entries() function. The first argument is the compiled pattern, and the second is the name. The - third and fourth are pointers to variables which are updated by the + third and fourth are pointers to variables which are updated by the function. After it has run, they point to the first and last entries in - the name-to-number table for the given name. The function itself - returns the length of each entry, or PCRE_ERROR_NOSUBSTRING (-7) if - there are none. The format of the table is described above in the sec- - tion entitled Information about a pattern above. Given all the rele- - vant entries for the name, you can extract each of their numbers, and - hence the captured data, if any. + the name-to-number table for the given name. The function itself re- + turns the length of each entry, or PCRE_ERROR_NOSUBSTRING (-7) if there + are none. The format of the table is described above in the section en- + titled Information about a pattern above. Given all the relevant en- + tries for the name, you can extract each of their numbers, and hence + the captured data, if any. FINDING ALL POSSIBLE MATCHES - The traditional matching function uses a similar algorithm to Perl, + The traditional matching function uses a similar algorithm to Perl, which stops when it finds the first match, starting at a given point in - the subject. If you want to find all possible matches, or the longest - possible match, consider using the alternative matching function (see - below) instead. If you cannot use the alternative function, but still - need to find all possible matches, you can kludge it up by making use + the subject. If you want to find all possible matches, or the longest + possible match, consider using the alternative matching function (see + below) instead. If you cannot use the alternative function, but still + need to find all possible matches, you can kludge it up by making use of the callout facility, which is described in the pcrecallout documen- tation. What you have to do is to insert a callout right at the end of the pat- - tern. When your callout function is called, extract and save the cur- - rent matched substring. Then return 1, which forces pcre_exec() to - backtrack and try other alternatives. Ultimately, when it runs out of + tern. When your callout function is called, extract and save the cur- + rent matched substring. Then return 1, which forces pcre_exec() to + backtrack and try other alternatives. Ultimately, when it runs out of matches, pcre_exec() will yield PCRE_ERROR_NOMATCH. OBTAINING AN ESTIMATE OF STACK USAGE - Matching certain patterns using pcre_exec() can use a lot of process - stack, which in certain environments can be rather limited in size. - Some users find it helpful to have an estimate of the amount of stack - that is used by pcre_exec(), to help them set recursion limits, as - described in the pcrestack documentation. The estimate that is output - by pcretest when called with the -m and -C options is obtained by call- - ing pcre_exec with the values NULL, NULL, NULL, -999, and -999 for its + Matching certain patterns using pcre_exec() can use a lot of process + stack, which in certain environments can be rather limited in size. + Some users find it helpful to have an estimate of the amount of stack + that is used by pcre_exec(), to help them set recursion limits, as de- + scribed in the pcrestack documentation. The estimate that is output by + pcretest when called with the -m and -C options is obtained by calling + pcre_exec with the values NULL, NULL, NULL, -999, and -999 for its first five arguments. - Normally, if its first argument is NULL, pcre_exec() immediately - returns the negative error code PCRE_ERROR_NULL, but with this special - combination of arguments, it returns instead a negative number whose - absolute value is the approximate stack frame size in bytes. (A nega- - tive number is used so that it is clear that no match has happened.) - The value is approximate because in some cases, recursive calls to + Normally, if its first argument is NULL, pcre_exec() immediately re- + turns the negative error code PCRE_ERROR_NULL, but with this special + combination of arguments, it returns instead a negative number whose + absolute value is the approximate stack frame size in bytes. (A nega- + tive number is used so that it is clear that no match has happened.) + The value is approximate because in some cases, recursive calls to pcre_exec() occur when there are one or two additional variables on the stack. - If PCRE has been compiled to use the heap instead of the stack for - recursion, the value returned is the size of each block that is - obtained from the heap. + If PCRE has been compiled to use the heap instead of the stack for re- + cursion, the value returned is the size of each block that is obtained + from the heap. MATCHING A PATTERN: THE ALTERNATIVE FUNCTION @@ -4085,26 +4082,26 @@ MATCHING A PATTERN: THE ALTERNATIVE FUNCTION int options, int *ovector, int ovecsize, int *workspace, int wscount); - The function pcre_dfa_exec() is called to match a subject string - against a compiled pattern, using a matching algorithm that scans the - subject string just once, and does not backtrack. This has different - characteristics to the normal algorithm, and is not compatible with - Perl. Some of the features of PCRE patterns are not supported. Never- - theless, there are times when this kind of matching can be useful. For - a discussion of the two matching algorithms, and a list of features - that pcre_dfa_exec() does not support, see the pcrematching documenta- + The function pcre_dfa_exec() is called to match a subject string + against a compiled pattern, using a matching algorithm that scans the + subject string just once, and does not backtrack. This has different + characteristics to the normal algorithm, and is not compatible with + Perl. Some of the features of PCRE patterns are not supported. Never- + theless, there are times when this kind of matching can be useful. For + a discussion of the two matching algorithms, and a list of features + that pcre_dfa_exec() does not support, see the pcrematching documenta- tion. - The arguments for the pcre_dfa_exec() function are the same as for + The arguments for the pcre_dfa_exec() function are the same as for pcre_exec(), plus two extras. The ovector argument is used in a differ- - ent way, and this is described below. The other common arguments are - used in the same way as for pcre_exec(), so their description is not + ent way, and this is described below. The other common arguments are + used in the same way as for pcre_exec(), so their description is not repeated here. - The two additional arguments provide workspace for the function. The - workspace vector should contain at least 20 elements. It is used for + The two additional arguments provide workspace for the function. The + workspace vector should contain at least 20 elements. It is used for keeping track of multiple paths through the pattern tree. More - workspace will be needed for patterns and subjects where there are a + workspace will be needed for patterns and subjects where there are a lot of potential matches. Here is an example of a simple call to pcre_dfa_exec(): @@ -4126,55 +4123,55 @@ MATCHING A PATTERN: THE ALTERNATIVE FUNCTION Option bits for pcre_dfa_exec() - The unused bits of the options argument for pcre_dfa_exec() must be - zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEW- - LINE_xxx, PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, - PCRE_NOTEMPTY_ATSTART, PCRE_NO_UTF8_CHECK, PCRE_BSR_ANYCRLF, - PCRE_BSR_UNICODE, PCRE_NO_START_OPTIMIZE, PCRE_PARTIAL_HARD, PCRE_PAR- - TIAL_SOFT, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last - four of these are exactly the same as for pcre_exec(), so their - description is not repeated here. + The unused bits of the options argument for pcre_dfa_exec() must be + zero. The only bits that may be set are PCRE_ANCHORED, PCRE_NEW- + LINE_xxx, PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_AT- + START, PCRE_NO_UTF8_CHECK, PCRE_BSR_ANYCRLF, PCRE_BSR_UNICODE, + PCRE_NO_START_OPTIMIZE, PCRE_PARTIAL_HARD, PCRE_PARTIAL_SOFT, + PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last four of + these are exactly the same as for pcre_exec(), so their description is + not repeated here. PCRE_PARTIAL_HARD PCRE_PARTIAL_SOFT - These have the same general effect as they do for pcre_exec(), but the - details are slightly different. When PCRE_PARTIAL_HARD is set for - pcre_dfa_exec(), it returns PCRE_ERROR_PARTIAL if the end of the sub- - ject is reached and there is still at least one matching possibility + These have the same general effect as they do for pcre_exec(), but the + details are slightly different. When PCRE_PARTIAL_HARD is set for + pcre_dfa_exec(), it returns PCRE_ERROR_PARTIAL if the end of the sub- + ject is reached and there is still at least one matching possibility that requires additional characters. This happens even if some complete matches have also been found. When PCRE_PARTIAL_SOFT is set, the return code PCRE_ERROR_NOMATCH is converted into PCRE_ERROR_PARTIAL if the end - of the subject is reached, there have been no complete matches, but - there is still at least one matching possibility. The portion of the - string that was inspected when the longest partial match was found is - set as the first matching string in both cases. There is a more - detailed discussion of partial and multi-segment matching, with exam- - ples, in the pcrepartial documentation. + of the subject is reached, there have been no complete matches, but + there is still at least one matching possibility. The portion of the + string that was inspected when the longest partial match was found is + set as the first matching string in both cases. There is a more de- + tailed discussion of partial and multi-segment matching, with examples, + in the pcrepartial documentation. PCRE_DFA_SHORTEST - Setting the PCRE_DFA_SHORTEST option causes the matching algorithm to + Setting the PCRE_DFA_SHORTEST option causes the matching algorithm to stop as soon as it has found one match. Because of the way the alterna- - tive algorithm works, this is necessarily the shortest possible match + tive algorithm works, this is necessarily the shortest possible match at the first possible matching point in the subject string. PCRE_DFA_RESTART When pcre_dfa_exec() returns a partial match, it is possible to call it - again, with additional subject characters, and have it continue with - the same match. The PCRE_DFA_RESTART option requests this action; when - it is set, the workspace and wscount options must reference the same - vector as before because data about the match so far is left in them + again, with additional subject characters, and have it continue with + the same match. The PCRE_DFA_RESTART option requests this action; when + it is set, the workspace and wscount options must reference the same + vector as before because data about the match so far is left in them after a partial match. There is more discussion of this facility in the pcrepartial documentation. Successful returns from pcre_dfa_exec() - When pcre_dfa_exec() succeeds, it may have matched more than one sub- + When pcre_dfa_exec() succeeds, it may have matched more than one sub- string in the subject. Note, however, that all the matches from one run - of the function start at the same point in the subject. The shorter - matches are all initial substrings of the longer matches. For example, + of the function start at the same point in the subject. The shorter + matches are all initial substrings of the longer matches. For example, if the pattern <.*> @@ -4189,79 +4186,79 @@ MATCHING A PATTERN: THE ALTERNATIVE FUNCTION <something> <something else> <something> <something else> <something further> - On success, the yield of the function is a number greater than zero, - which is the number of matched substrings. The substrings themselves - are returned in ovector. Each string uses two elements; the first is - the offset to the start, and the second is the offset to the end. In - fact, all the strings have the same start offset. (Space could have - been saved by giving this only once, but it was decided to retain some - compatibility with the way pcre_exec() returns data, even though the + On success, the yield of the function is a number greater than zero, + which is the number of matched substrings. The substrings themselves + are returned in ovector. Each string uses two elements; the first is + the offset to the start, and the second is the offset to the end. In + fact, all the strings have the same start offset. (Space could have + been saved by giving this only once, but it was decided to retain some + compatibility with the way pcre_exec() returns data, even though the meaning of the strings is different.) The strings are returned in reverse order of length; that is, the long- - est matching string is given first. If there were too many matches to - fit into ovector, the yield of the function is zero, and the vector is - filled with the longest matches. Unlike pcre_exec(), pcre_dfa_exec() + est matching string is given first. If there were too many matches to + fit into ovector, the yield of the function is zero, and the vector is + filled with the longest matches. Unlike pcre_exec(), pcre_dfa_exec() can use the entire ovector for returning matched strings. - NOTE: PCRE's "auto-possessification" optimization usually applies to - character repeats at the end of a pattern (as well as internally). For - example, the pattern "a\d+" is compiled as if it were "a\d++" because + NOTE: PCRE's "auto-possessification" optimization usually applies to + character repeats at the end of a pattern (as well as internally). For + example, the pattern "a\d+" is compiled as if it were "a\d++" because there is no point even considering the possibility of backtracking into - the repeated digits. For DFA matching, this means that only one possi- - ble match is found. If you really do want multiple matches in such - cases, either use an ungreedy repeat ("a\d+?") or set the + the repeated digits. For DFA matching, this means that only one possi- + ble match is found. If you really do want multiple matches in such + cases, either use an ungreedy repeat ("a\d+?") or set the PCRE_NO_AUTO_POSSESS option when compiling. Error returns from pcre_dfa_exec() - The pcre_dfa_exec() function returns a negative number when it fails. - Many of the errors are the same as for pcre_exec(), and these are - described above. There are in addition the following errors that are + The pcre_dfa_exec() function returns a negative number when it fails. + Many of the errors are the same as for pcre_exec(), and these are de- + scribed above. There are in addition the following errors that are specific to pcre_dfa_exec(): PCRE_ERROR_DFA_UITEM (-16) - This return is given if pcre_dfa_exec() encounters an item in the pat- - tern that it does not support, for instance, the use of \C or a back + This return is given if pcre_dfa_exec() encounters an item in the pat- + tern that it does not support, for instance, the use of \C or a back reference. PCRE_ERROR_DFA_UCOND (-17) - This return is given if pcre_dfa_exec() encounters a condition item - that uses a back reference for the condition, or a test for recursion + This return is given if pcre_dfa_exec() 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. PCRE_ERROR_DFA_UMLIMIT (-18) - This return is given if pcre_dfa_exec() is called with an extra block - that contains a setting of the match_limit or match_limit_recursion - fields. This is not supported (these fields are meaningless for DFA + This return is given if pcre_dfa_exec() is called with an extra block + that contains a setting of the match_limit or match_limit_recursion + fields. This is not supported (these fields are meaningless for DFA matching). PCRE_ERROR_DFA_WSSIZE (-19) - This return is given if pcre_dfa_exec() runs out of space in the + This return is given if pcre_dfa_exec() runs out of space in the workspace vector. PCRE_ERROR_DFA_RECURSE (-20) - When a recursive subpattern is processed, the matching function calls - itself recursively, using private vectors for ovector and workspace. - This error is given if the output vector is not large enough. This + When a recursive subpattern is processed, the matching function calls + itself recursively, using private vectors for ovector and workspace. + This error is given if the output vector is not large enough. This should be extremely rare, as a vector of size 1000 is used. PCRE_ERROR_DFA_BADRESTART (-30) - When pcre_dfa_exec() is called with the PCRE_DFA_RESTART option, some - plausibility checks are made on the contents of the workspace, which - should contain data about the previous partial match. If any of these + When pcre_dfa_exec() is called with the PCRE_DFA_RESTART option, some + plausibility checks are made on the contents of the workspace, which + should contain data about the previous partial match. If any of these checks fail, this error is given. SEE ALSO - pcre16(3), pcre32(3), pcrebuild(3), pcrecallout(3), pcrecpp(3)(3), + pcre16(3), pcre32(3), pcrebuild(3), pcrecallout(3), pcrecpp(3)(3), pcrematching(3), pcrepartial(3), pcreposix(3), pcreprecompile(3), pcre- sample(3), pcrestack(3). @@ -4307,16 +4304,15 @@ DESCRIPTION the 16-bit library, pcre32_callout for the 32-bit library). By default, this variable contains NULL, which disables all calling out. - Within a regular expression, (?C) indicates the points at which the - external function is to be called. Different callout points can be - identified by putting a number less than 256 after the letter C. The - default value is zero. For example, this pattern has two callout - points: + Within a regular expression, (?C) indicates the points at which the ex- + ternal function is to be called. Different callout points can be iden- + tified by putting a number less than 256 after the letter C. The de- + fault value is zero. For example, this pattern has two callout points: (?C1)abc(?C2)def - If the PCRE_AUTO_CALLOUT option bit is set when a pattern is compiled, - PCRE automatically inserts callouts, all with number 255, before each + If the PCRE_AUTO_CALLOUT option bit is set when a pattern is compiled, + PCRE automatically inserts callouts, all with number 255, before each item in the pattern. For example, if PCRE_AUTO_CALLOUT is used with the pattern @@ -4326,21 +4322,21 @@ DESCRIPTION (?C255)A(?C255)((?C255)\d{2}(?C255)|(?C255)-(?C255)-(?C255))(?C255) - Notice that there is a callout before and after each parenthesis and + Notice that there is a callout before and after each parenthesis and alternation bar. If the pattern contains a conditional group whose con- - dition is an assertion, an automatic callout is inserted immediately - before the condition. Such a callout may also be inserted explicitly, + dition is an assertion, an automatic callout is inserted immediately + before the condition. Such a callout may also be inserted explicitly, for example: (?(?C9)(?=a)ab|de) - This applies only to assertion conditions (because they are themselves + This applies only to assertion conditions (because they are themselves independent groups). - Automatic callouts can be used for tracking the progress of pattern - matching. The pcretest program has a pattern qualifier (/C) that sets - automatic callouts; when it is used, the output indicates how the pat- - tern is being matched. This is useful information when you are trying + Automatic callouts can be used for tracking the progress of pattern + matching. The pcretest program has a pattern qualifier (/C) that sets + automatic callouts; when it is used, the output indicates how the pat- + tern is being matched. This is useful information when you are trying to optimize the performance of a particular pattern. @@ -4350,10 +4346,10 @@ MISSING CALLOUTS piles and matches patterns, callouts sometimes do not happen exactly as you might expect. - At compile time, PCRE "auto-possessifies" repeated items when it knows - that what follows cannot be part of the repeat. For example, a+[bc] is - compiled as if it were a++[bc]. The pcretest output when this pattern - is anchored and then applied with automatic callouts to the string + At compile time, PCRE "auto-possessifies" repeated items when it knows + that what follows cannot be part of the repeat. For example, a+[bc] is + compiled as if it were a++[bc]. The pcretest output when this pattern + is anchored and then applied with automatic callouts to the string "aaaa" is: --->aaaa @@ -4362,11 +4358,11 @@ MISSING CALLOUTS +3 ^ ^ [bc] No match - This indicates that when matching [bc] fails, there is no backtracking - into a+ and therefore the callouts that would be taken for the back- - tracks do not occur. You can disable the auto-possessify feature by + This indicates that when matching [bc] fails, there is no backtracking + into a+ and therefore the callouts that would be taken for the back- + tracks do not occur. You can disable the auto-possessify feature by passing PCRE_NO_AUTO_POSSESS to pcre_compile(), or starting the pattern - with (*NO_AUTO_POSSESS). If this is done in pcretest (using the /O + with (*NO_AUTO_POSSESS). If this is done in pcretest (using the /O qualifier), the output changes to this: --->aaaa @@ -4381,34 +4377,34 @@ MISSING CALLOUTS This time, when matching [bc] fails, the matcher backtracks into a+ and tries again, repeatedly, until a+ itself fails. - Other optimizations that provide fast "no match" results also affect + Other optimizations that provide fast "no match" results also affect callouts. For example, if the pattern is ab(?C4)cd PCRE knows that any matching string must contain the letter "d". If the - subject string is "abyz", the lack of "d" means that matching doesn't - ever start, and the callout is never reached. However, with "abyd", + subject string is "abyz", the lack of "d" means that matching doesn't + ever start, and the callout is never reached. However, with "abyd", though the result is still no match, the callout is obeyed. - If the pattern is studied, PCRE knows the minimum length of a matching - string, and will immediately give a "no match" return without actually - running a match if the subject is not long enough, or, for unanchored + If the pattern is studied, PCRE knows the minimum length of a matching + string, and will immediately give a "no match" return without actually + running a match if the subject is not long enough, or, for unanchored patterns, if it has been scanned far enough. - You can disable these optimizations by passing the PCRE_NO_START_OPTI- - MIZE option to the matching function, or by starting the pattern with - (*NO_START_OPT). This slows down the matching process, but does ensure + You can disable these optimizations by passing the PCRE_NO_START_OPTI- + MIZE option to the matching function, or by starting the pattern with + (*NO_START_OPT). This slows down the matching process, but does ensure that callouts such as the example above are obeyed. THE CALLOUT INTERFACE - During matching, when PCRE reaches a callout point, the external func- + During matching, when PCRE reaches a callout point, the external func- tion defined by pcre_callout or pcre[16|32]_callout is called (if it is - set). This applies to both normal and DFA matching. The only argument - to the callout function is a pointer to a pcre_callout or - pcre[16|32]_callout block. These structures contains the following + set). This applies to both normal and DFA matching. The only argument + to the callout function is a pointer to a pcre_callout or + pcre[16|32]_callout block. These structures contains the following fields: int version; @@ -4429,93 +4425,92 @@ THE CALLOUT INTERFACE const PCRE_UCHAR16 *mark; (16-bit version) const PCRE_UCHAR32 *mark; (32-bit version) - The version field is an integer containing the version number of the - block format. The initial version was 0; the current version is 2. The - version number will change again in future if additional fields are + The version field is an integer containing the version number of the + block format. The initial version was 0; the current version is 2. The + version number will change again in future if additional fields are added, but the intention is never to remove any of the existing fields. - The callout_number field contains the number of the callout, as com- - piled into the pattern (that is, the number after ?C for manual call- + The callout_number field contains the number of the callout, as com- + piled into the pattern (that is, the number after ?C for manual call- outs, and 255 for automatically generated callouts). - The offset_vector field is a pointer to the vector of offsets that was - passed by the caller to the matching function. When pcre_exec() or - pcre[16|32]_exec() is used, the contents can be inspected, in order to - extract substrings that have been matched so far, in the same way as - for extracting substrings after a match has completed. For the DFA + The offset_vector field is a pointer to the vector of offsets that was + passed by the caller to the matching function. When pcre_exec() or + pcre[16|32]_exec() is used, the contents can be inspected, in order to + extract substrings that have been matched so far, in the same way as + for extracting substrings after a match has completed. For the DFA matching functions, this field is not useful. The subject and subject_length fields contain copies of the values that were passed to the matching function. - The start_match field normally contains the offset within the subject - at which the current match attempt started. However, if the escape - sequence \K has been encountered, this value is changed to reflect the - modified starting point. If the pattern is not anchored, the callout + The start_match field normally contains the offset within the subject + at which the current match attempt started. However, if the escape se- + quence \K has been encountered, this value is changed to reflect the + modified starting point. If the pattern is not anchored, the callout function may be called several times from the same point in the pattern for different starting points in the subject. - The current_position field contains the offset within the subject of + The current_position field contains the offset within the subject of the current match pointer. - When the pcre_exec() or pcre[16|32]_exec() is used, the capture_top - field contains one more than the number of the highest numbered cap- - tured substring so far. If no substrings have been captured, the value - of capture_top is one. This is always the case when the DFA functions + When the pcre_exec() or pcre[16|32]_exec() is used, the capture_top + field contains one more than the number of the highest numbered cap- + tured substring so far. If no substrings have been captured, the value + of capture_top is one. This is always the case when the DFA functions are used, because they do not support captured substrings. - The capture_last field contains the number of the most recently cap- - tured substring. However, when a recursion exits, the value reverts to - what it was outside the recursion, as do the values of all captured - substrings. If no substrings have been captured, the value of cap- - ture_last is -1. This is always the case for the DFA matching func- + The capture_last field contains the number of the most recently cap- + tured substring. However, when a recursion exits, the value reverts to + what it was outside the recursion, as do the values of all captured + substrings. If no substrings have been captured, the value of cap- + ture_last is -1. This is always the case for the DFA matching func- tions. - The callout_data field contains a value that is passed to a matching - function specifically so that it can be passed back in callouts. It is - passed in the callout_data field of a pcre_extra or pcre[16|32]_extra - data structure. If no such data was passed, the value of callout_data - in a callout block is NULL. There is a description of the pcre_extra + The callout_data field contains a value that is passed to a matching + function specifically so that it can be passed back in callouts. It is + passed in the callout_data field of a pcre_extra or pcre[16|32]_extra + data structure. If no such data was passed, the value of callout_data + in a callout block is NULL. There is a description of the pcre_extra structure in the pcreapi documentation. - The pattern_position field is present from version 1 of the callout + The pattern_position field is present from version 1 of the callout structure. It contains the offset to the next item to be matched in the pattern string. - The next_item_length field is present from version 1 of the callout + The next_item_length field is present from version 1 of the callout structure. It contains the length of the next item to be matched in the - pattern string. When the callout immediately precedes an alternation - bar, a closing parenthesis, or the end of the pattern, the length is - zero. When the callout precedes an opening parenthesis, the length is + pattern string. When the callout immediately precedes an alternation + bar, a closing parenthesis, or the end of the pattern, the length is + zero. When the callout precedes an opening parenthesis, the length is that of the entire subpattern. - The pattern_position and next_item_length fields are intended to help - in distinguishing between different automatic callouts, which all have + The pattern_position and next_item_length fields are intended to help + in distinguishing between different automatic callouts, which all have the same callout number. However, they are set for all callouts. - The mark field is present from version 2 of the callout structure. In - callouts from pcre_exec() or pcre[16|32]_exec() it contains a pointer - to the zero-terminated name of the most recently passed (*MARK), - (*PRUNE), or (*THEN) item in the match, or NULL if no such items have - been passed. Instances of (*PRUNE) or (*THEN) without a name do not - obliterate a previous (*MARK). In callouts from the DFA matching func- + The mark field is present from version 2 of the callout structure. In + callouts from pcre_exec() or pcre[16|32]_exec() it contains a pointer + to the zero-terminated name of the most recently passed (*MARK), + (*PRUNE), or (*THEN) item in the match, or NULL if no such items have + been passed. Instances of (*PRUNE) or (*THEN) without a name do not + obliterate a previous (*MARK). In callouts from the DFA matching func- tions this field always contains NULL. RETURN VALUES - The external callout function returns an integer to PCRE. If the value - is zero, matching proceeds as normal. If the value is greater than - zero, matching fails at the current point, but the testing of other + The external callout function returns an integer to PCRE. If the value + is zero, matching proceeds as normal. If the value is greater than + zero, matching fails at the current point, but the testing of other matching possibilities goes ahead, just as if a lookahead assertion had - failed. If the value is less than zero, the match is abandoned, the + failed. If the value is less than zero, the match is abandoned, the matching function returns the negative value. - Negative values should normally be chosen from the set of - PCRE_ERROR_xxx values. In particular, PCRE_ERROR_NOMATCH forces a stan- - dard "no match" failure. The error number PCRE_ERROR_CALLOUT is - reserved for use by callout functions; it will never be used by PCRE - itself. + Negative values should normally be chosen from the set of PCRE_ER- + ROR_xxx values. In particular, PCRE_ERROR_NOMATCH forces a standard "no + match" failure. The error number PCRE_ERROR_CALLOUT is reserved for + use by callout functions; it will never be used by PCRE itself. AUTHOR @@ -4542,8 +4537,8 @@ NAME DIFFERENCES BETWEEN PCRE AND PERL This document describes the differences in the ways that PCRE and Perl - handle regular expressions. The differences described here are with - respect to Perl versions 5.10 and above. + handle regular expressions. The differences described here are with re- + spect to Perl versions 5.10 and above. 1. PCRE has only a subset of Perl's Unicode support. Details of what it does have are given in the pcreunicode page. @@ -4614,8 +4609,8 @@ DIFFERENCES BETWEEN PCRE AND PERL the section on recursion differences from Perl in the pcrepattern page. 10. If any of the backtracking control verbs are used in a subpattern - that is called as a subroutine (whether or not recursively), their - effect is confined to that subpattern; it does not extend to the sur- + that is called as a subroutine (whether or not recursively), their ef- + fect is confined to that subpattern; it does not extend to the sur- rounding pattern. This is not always the case in Perl. In particular, if (*THEN) is present in a group that is called as a subroutine, its action is limited to that group, even if the group does not contain any @@ -4633,8 +4628,8 @@ DIFFERENCES BETWEEN PCRE AND PERL 13. There are some differences that are concerned with the settings of captured strings when part of a pattern is repeated. For example, - matching "aba" against the pattern /^(a(b)?)+$/ in Perl leaves $2 - unset, but in PCRE it is set to "b". + matching "aba" against the pattern /^(a(b)?)+$/ in Perl leaves $2 un- + set, but in PCRE it is set to "b". 14. PCRE's handling of duplicate subpattern numbers and duplicate sub- pattern names is not as general as Perl's. This is a consequence of the @@ -4647,11 +4642,11 @@ DIFFERENCES BETWEEN PCRE AND PERL turing subpattern number 1. To avoid this confusing situation, an error is given at compile time. - 15. Perl recognizes comments in some places that PCRE does not, for - example, between the ( and ? at the start of a subpattern. If the /x - modifier is set, Perl allows white space between ( and ? (though cur- - rent Perls warn that this is deprecated) but PCRE never does, even if - the PCRE_EXTENDED option is set. + 15. Perl recognizes comments in some places that PCRE does not, for ex- + ample, between the ( and ? at the start of a subpattern. If the /x mod- + ifier is set, Perl allows white space between ( and ? (though current + Perls warn that this is deprecated) but PCRE never does, even if the + PCRE_EXTENDED option is set. 16. Perl, when in warning mode, gives warnings for character classes such as [A-\d] or [a-[:digit:]]. It then treats the hyphens as liter- @@ -4746,10 +4741,10 @@ PCRE REGULAR EXPRESSION DETAILS Perl's regular expressions are described in its own documentation, and regular expressions in general are covered in a number of books, some - of which have copious examples. Jeffrey Friedl's "Mastering Regular - Expressions", published by O'Reilly, covers regular expressions in - great detail. This description of PCRE's regular expressions is - intended as reference material. + of which have copious examples. Jeffrey Friedl's "Mastering Regular Ex- + pressions", published by O'Reilly, covers regular expressions in great + detail. This description of PCRE's regular expressions is intended as + reference material. This document discusses the patterns that are supported by PCRE when one its main matching functions, pcre_exec() (8-bit) or @@ -4768,8 +4763,8 @@ SPECIAL START-OF-PATTERN ITEMS set by special items at the start of a pattern. These are not Perl-com- patible, but are provided to make these options accessible to pattern writers who are not able to change the program that processes the pat- - tern. Any number of these items may appear, but they must all be - together right at the start of the pattern string, and the letters must + tern. Any number of these items may appear, but they must all be to- + gether right at the start of the pattern string, and the letters must be in upper case. UTF support @@ -4788,16 +4783,16 @@ SPECIAL START-OF-PATTERN ITEMS (*UTF32) (*UTF) - (*UTF) is a generic sequence that can be used with any of the - libraries. Starting a pattern with such a sequence is equivalent to - setting the relevant option. How setting a UTF mode affects pattern - matching is mentioned in several places below. There is also a summary - of features in the pcreunicode page. + (*UTF) is a generic sequence that can be used with any of the li- + braries. Starting a pattern with such a sequence is equivalent to set- + ting the relevant option. How setting a UTF mode affects pattern match- + ing is mentioned in several places below. There is also a summary of + features in the pcreunicode page. Some applications that allow their users to supply patterns may wish to restrict them to non-UTF data for security reasons. If the - PCRE_NEVER_UTF option is set at compile time, (*UTF) etc. are not - allowed, and their appearance causes an error. + PCRE_NEVER_UTF option is set at compile time, (*UTF) etc. are not al- + lowed, and their appearance causes an error. Unicode property support @@ -4841,8 +4836,8 @@ SPECIAL START-OF-PATTERN ITEMS (*ANY) all Unicode newline sequences 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 - sequence, the pattern + tion. For example, on a Unix system where LF is the default newline se- + quence, the pattern (*CR)a.b @@ -4909,8 +4904,8 @@ CHARACTERS AND METACHARACTERS matching for characters 128 and above, you must ensure that PCRE is compiled with Unicode property support as well as with UTF support. - 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 al- + ternatives 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. @@ -4974,9 +4969,9 @@ BACKSLASH 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 PCRE, whereas in Perl, $ and @ cause variable interpola- - tion. Note the following examples: + ent from Perl in that $ and @ are handled as literals in \Q...\E se- + quences in PCRE, whereas in Perl, $ and @ cause variable interpolation. + Note the following examples: Pattern PCRE matches Perl matches @@ -4998,8 +4993,8 @@ BACKSLASH acters in patterns in a visible manner. There is no restriction on the appearance of non-printing characters, apart from the binary zero that terminates 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 an ASCII or Uni- + editing, it is often easier to use one of the following escape se- + quences than the binary character it represents. In an ASCII or Uni- code environment, these escapes are as follows: \a alarm, that is, the BEL character (hex 07) @@ -5028,8 +5023,8 @@ BACKSLASH ate 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 + Any other character provokes a compile-time error. The sequence \c@ en- + codes 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 (hex 5F). @@ -5048,8 +5043,8 @@ BACKSLASH 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 - sequence \0\x\015 specifies two binary zeros followed by a CR character + than two digits, just those that are present are used. Thus the se- + quence \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. @@ -5140,15 +5135,15 @@ BACKSLASH \N is not allowed in a character class. \B, \R, and \X are not special inside a character class. Like other unrecognized escape sequences, - they are treated as the literal characters "B", "R", and "X" by - default, but cause an error if the PCRE_EXTRA option is set. Outside a + they are treated as the literal characters "B", "R", and "X" by de- + fault, but cause an error if the PCRE_EXTRA option is set. 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 - default, PCRE does not support these escape sequences. However, if the + handler and used to modify the case of following characters. By de- + fault, PCRE does not support these escape sequences. However, if the PCRE_JAVASCRIPT_COMPAT option is set, \U matches a "U" character, and \u can be used to define a character by code point, as described in the previous section. @@ -5199,13 +5194,13 @@ BACKSLASH For compatibility with Perl, \s did not used to match the VT character (code 11), which made it different from the the POSIX "space" class. - However, Perl added VT at release 5.18, and PCRE followed suit at - release 8.34. The default \s characters are now 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) is recognized as white space, and in others the VT - character is not. + However, Perl added VT at release 5.18, and PCRE followed suit at re- + lease 8.34. The default \s characters are now 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 tak- + ing place. For example, in some locales the "non-breaking space" char- + acter (\xA0) is recognized as white space, and in others the VT charac- + ter 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- @@ -5282,8 +5277,8 @@ BACKSLASH (?>\r\n|\n|\x0b|\f|\r|\x85) - This is an example of an "atomic group", details of which are given - below. This particular group matches either the two-character sequence + This is an example of an "atomic group", details of which are given be- + low. 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). The two-character @@ -5298,10 +5293,10 @@ BACKSLASH the complete set of Unicode line endings) by setting the option PCRE_BSR_ANYCRLF either at compile time or when the pattern is matched. (BSR is an abbrevation for "backslash R".) This can be made the default - when PCRE is built; if this is the case, the other behaviour can be - requested via the PCRE_BSR_UNICODE option. It is also possible to - specify these settings by starting a pattern string with one of the - following sequences: + when PCRE is built; if this is the case, the other behaviour can be re- + quested via the PCRE_BSR_UNICODE option. It is also possible to spec- + ify these settings by starting a pattern string with one of the follow- + ing sequences: (*BSR_ANYCRLF) CR, LF, or CRLF only (*BSR_UNICODE) any Unicode newline sequence @@ -5318,8 +5313,8 @@ BACKSLASH They can also be combined with the (*UTF8), (*UTF16), (*UTF32), (*UTF) or (*UCP) special sequences. Inside a character class, \R is treated as - an unrecognized escape sequence, and so matches the letter "R" by - default, but causes an error if PCRE_EXTRA is set. + an unrecognized escape sequence, and so matches the letter "R" by de- + fault, but causes an error if PCRE_EXTRA is set. Unicode character properties @@ -5335,10 +5330,10 @@ BACKSLASH 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 PCRE properties - (described in the next section). Other Perl properties such as "InMu- - sicalSymbols" are not currently supported by PCRE. Note that \P{Any} - does not match any characters, so always causes a match failure. + character (including newline), and some special PCRE properties (de- + scribed in the next section). Other Perl properties such as "InMusi- + calSymbols" are not currently supported by PCRE. 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. @@ -5355,16 +5350,16 @@ BACKSLASH ian, Caucasian_Albanian, Chakma, Cham, Cherokee, Common, Coptic, Cunei- form, Cypriot, Cyrillic, Deseret, Devanagari, Duployan, Egyptian_Hiero- glyphs, Elbasan, Ethiopic, Georgian, Glagolitic, Gothic, Grantha, - Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hiragana, - Imperial_Aramaic, Inherited, Inscriptional_Pahlavi, Inscrip- + Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hiragana, Im- + perial_Aramaic, Inherited, Inscriptional_Pahlavi, Inscrip- tional_Parthian, Javanese, Kaithi, Kannada, Katakana, Kayah_Li, Kharoshthi, Khmer, Khojki, Khudawadi, Lao, Latin, Lepcha, Limbu, Lin- ear_A, Linear_B, Lisu, Lycian, Lydian, Mahajani, Malayalam, Mandaic, - Manichaean, Meetei_Mayek, Mende_Kikakui, Meroitic_Cursive, - Meroitic_Hieroglyphs, Miao, Modi, Mongolian, Mro, Myanmar, Nabataean, - New_Tai_Lue, Nko, Ogham, Ol_Chiki, Old_Italic, Old_North_Arabian, - Old_Permic, Old_Persian, Old_South_Arabian, Old_Turkic, Oriya, Osmanya, - Pahawh_Hmong, Palmyrene, Pau_Cin_Hau, Phags_Pa, Phoenician, + Manichaean, Meetei_Mayek, Mende_Kikakui, Meroitic_Cursive, Meroitic_Hi- + eroglyphs, Miao, Modi, Mongolian, Mro, Myanmar, Nabataean, New_Tai_Lue, + Nko, Ogham, Ol_Chiki, Old_Italic, Old_North_Arabian, Old_Permic, + Old_Persian, Old_South_Arabian, Old_Turkic, Oriya, Osmanya, Pa- + hawh_Hmong, Palmyrene, Pau_Cin_Hau, Phags_Pa, Phoenician, Psalter_Pahlavi, Rejang, Runic, Samaritan, Saurashtra, Sharada, Sha- vian, Siddham, Sinhala, Sora_Sompeng, Sundanese, Syloti_Nagri, Syriac, Tagalog, Tagbanwa, Tai_Le, Tai_Tham, Tai_Viet, Takri, Tamil, Telugu, @@ -5477,9 +5472,9 @@ BACKSLASH This simple definition was extended in Unicode to include more compli- cated kinds of composite character by giving each character a grapheme - breaking property, and creating rules that use these properties to - define the boundaries of extended grapheme clusters. In releases of - PCRE later than 8.31, \X matches one of these clusters. + breaking property, and creating rules that use these properties to de- + fine the boundaries of extended grapheme clusters. In releases of PCRE + later than 8.31, \X matches one of these clusters. \X always matches at least one character. Then it decides whether to add additional characters according to the following rules for ending a @@ -5507,8 +5502,8 @@ BACKSLASH PCRE's additional properties As well as the standard Unicode properties described above, PCRE sup- - ports four more that make it possible to convert traditional escape - sequences such as \w and \s to use Unicode properties. PCRE uses these + ports four more that make it possible to convert traditional escape se- + quences such as \w and \s to use Unicode properties. PCRE uses these non-standard, non-Perl properties internally when PCRE_UCP is set. How- ever, they may also be used explicitly. These properties are: @@ -5522,8 +5517,8 @@ BACKSLASH form feed, or carriage return, and any other character that has the Z (separator) property. Xsp is the same as Xps; it used to exclude ver- tical tab, for Perl compatibility, but Perl changed, and so PCRE fol- - lowed at release 8.34. Xwd matches the same characters as Xan, plus - underscore. + lowed at release 8.34. Xwd matches the same characters as Xan, plus un- + derscore. There is another non-standard property, Xuc, which matches any charac- ter that can be represented by a Universal Character Name in C++ and @@ -5553,11 +5548,11 @@ BACKSLASH matches "foobar", the first substring is still set to "foo". - Perl documents that the use of \K within assertions is "not well - defined". In PCRE, \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. + Perl documents that the use of \K within assertions is "not well de- + fined". In PCRE, \K is acted upon when it occurs inside positive asser- + tions, 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 @@ -5578,9 +5573,9 @@ BACKSLASH 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, by default it matches the corresponding literal char- - acter (for example, \B matches the letter B). However, if the - PCRE_EXTRA option is set, an "invalid escape sequence" error is gener- - ated instead. + acter (for example, \B matches the letter B). However, if the PCRE_EX- + TRA option is set, an "invalid escape sequence" error is generated in- + stead. 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. @@ -5644,8 +5639,8 @@ CIRCUMFLEX AND DOLLAR 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). Note, however, + matching point is at the end of the subject string, or immediately be- + fore a newline at the end of the string (by default). Note, however, that it does not actually match the newline. Dollar need not be the last character of the pattern if a number of alternatives are involved, but it should be the last item in any branch in which it appears. Dol- @@ -5692,18 +5687,18 @@ FULL STOP (PERIOD, DOT) AND \N any of the other line ending characters. The behaviour of dot with regard to newlines can be changed. If the - PCRE_DOTALL option is set, a dot matches any one character, without - exception. If the two-character sequence CRLF is present in the subject + PCRE_DOTALL option is set, a dot matches any one character, without ex- + ception. If the two-character sequence CRLF is present in the subject 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 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 PCRE_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; PCRE does not support this. + The escape sequence \N behaves like a dot, except that it is not af- + fected by the PCRE_DOTALL option. In other words, it matches any char- + acter except one that signifies the end of a line. Perl also uses \N to + match characters by name; PCRE does not support this. MATCHING A SINGLE DATA UNIT @@ -5738,11 +5733,11 @@ MATCHING A SINGLE DATA UNIT (?=[\x{10000}-\x{1fffff}])(\C)(\C)(\C)(\C)) A group that starts with (?| resets the capturing parentheses numbers - in each alternative (see "Duplicate Subpattern Numbers" 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, respectively. The - character's individual bytes are then captured by the appropriate num- - ber of groups. + in each alternative (see "Duplicate Subpattern Numbers" below). The as- + sertions at the start of each branch check the next UTF-8 character for + values whose encoding uses 1, 2, 3, or 4 bytes, respectively. The char- + acter's individual bytes are then captured by the appropriate number of + groups. SQUARE BRACKETS AND CHARACTER CLASSES @@ -5788,80 +5783,79 @@ SQUARE BRACKETS AND CHARACTER CLASSES with UTF support. 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 PCRE_DOTALL and - PCRE_MULTILINE options is used. A class such as [^a] always matches one - of these characters. + special way when matching character classes, whatever line-ending se- + quence is in use, and whatever setting of the PCRE_DOTALL and PCRE_MUL- + TILINE options is used. A class such as [^a] always matches one of + these characters. 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- - ter, or z. + ters in a character class. For example, [d-m] matches any letter be- + tween 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 character, or z. 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. - An error is generated if a POSIX character class (see below) or an - escape sequence other than one that defines a single character appears - at a point where a range ending character is expected. For example, + An error is generated if a POSIX character class (see below) or an es- + cape sequence other than one that defines a single character appears at + a point where a range ending character is expected. For example, [z-\xff] is valid, but [A-\d] and [A-[:digit:]] are not. - Ranges operate in the collating sequence of character values. They can - also be used for characters specified numerically, for example - [\000-\037]. Ranges can include any characters that are valid for the + Ranges operate in the collating sequence of character values. They can + also be used for characters specified numerically, for example + [\000-\037]. Ranges can include any characters that are valid for the current mode. 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 - accented E characters in both cases. In UTF modes, PCRE supports the - concept of case for characters with values greater than 128 only when + 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. In UTF modes, PCRE supports the + concept of case for characters with values greater than 128 only when it is compiled with Unicode property support. - 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 PCRE_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 PCRE_UCP option affects the meanings of + \d, \s, \w and their upper case partners, just as it does when they ap- + pear 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 are treated - as the literal characters "B", "N", "R", and "X" by default, but cause + 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 are treated + as the literal characters "B", "N", "R", and "X" by default, but cause an error if the PCRE_EXTRA option is set. - 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 - terminating closing square bracket. However, escaping other non- - alphanumeric characters does no harm. + 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-al- + phanumeric characters does no harm. POSIX CHARACTER CLASSES Perl supports the POSIX notation for character classes. This uses names - enclosed by [: and :] within the enclosing square brackets. PCRE also + enclosed by [: and :] within the enclosing square brackets. PCRE also supports this notation. For example, [01[:alpha:]%] @@ -5884,28 +5878,28 @@ 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" used to be different to \s, which did not include VT, for Perl compatibility. However, Perl changed at release 5.18, and - PCRE followed at release 8.34. "Space" and \s now match the same set + PCRE followed at release 8.34. "Space" and \s now 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:]] - matches "1", "2", or any non-digit. PCRE (and Perl) also recognize the + matches "1", "2", or any non-digit. PCRE (and Perl) also recognize the POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but these are not supported, and an error is given if they are encountered. By default, characters with values greater than 128 do not match any of - the POSIX character classes. However, if the PCRE_UCP option is passed - to pcre_compile(), some of the classes are changed so that Unicode - character properties are used. This is achieved by replacing certain + the POSIX character classes. However, if the PCRE_UCP option is passed + to pcre_compile(), some of the classes are changed so that Unicode + character properties are used. This is achieved by replacing certain POSIX classes by other sequences, as follows: [:alnum:] becomes \p{Xan} @@ -5917,10 +5911,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: @@ -5929,59 +5923,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 whose code points are + tion) property, plus those characters whose code points are less than 128 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 128. 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". PCRE 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- - haviour. + 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 as- + sertions that are used above in order to give exactly the POSIX behav- + iour. 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 PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and - PCRE_EXTENDED options (which are Perl-compatible) can be changed from - within the pattern by a sequence of Perl option letters enclosed - between "(?" and ")". The option letters are + The settings of the PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and + PCRE_EXTENDED options (which are Perl-compatible) can be changed from + within the pattern by a sequence of Perl option letters enclosed be- + tween "(?" and ")". The option letters are i for PCRE_CASELESS m for PCRE_MULTILINE @@ -5990,48 +5984,48 @@ INTERNAL OPTION SETTING For example, (?im) sets caseless, multiline matching. It is also possi- ble to unset these options by preceding the letter with a hyphen, and a - combined setting and unsetting such as (?im-sx), which sets PCRE_CASE- - LESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED, - is also permitted. If a letter appears both before and after the - hyphen, the option is unset. + combined setting and unsetting such as (?im-sx), which sets PCRE_CASE- + LESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED, + is also permitted. If a letter appears both before and after the hy- + phen, the option is unset. - The PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA - can be changed in the same way as the Perl-compatible options by using + The PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA + can be changed in the same way as the Perl-compatible options by using the characters J, U and X 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 in- + side subpattern parentheses), the change applies to the remainder of + the pattern that follows. An option change within a subpattern (see be- + low 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 PCRE_CASELESS is not - used). By this means, options can be made to have different settings - in different parts of the pattern. Any changes made in one alternative - do carry on into subsequent branches within the same subpattern. For + used). By this means, options can be made to have different settings + in different parts of the pattern. Any changes made in one alternative + 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. - Note: There are other PCRE-specific options that can be set by the - application when the compiling or matching functions are called. In - some cases the pattern can contain 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 (*UTF8), (*UTF16),(*UTF32), and - (*UCP) leading sequences that can be used to set UTF and Unicode prop- - erty modes; they are equivalent to setting the PCRE_UTF8, PCRE_UTF16, - PCRE_UTF32 and the PCRE_UCP options, respectively. The (*UTF) sequence - is a generic version that can be used with any of the libraries. How- - ever, the application can set the PCRE_NEVER_UTF option, which locks - out the use of the (*UTF) sequences. + Note: There are other PCRE-specific options that can be set by the ap- + plication when the compiling or matching functions are called. In some + cases the pattern can contain 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 (*UTF8), (*UTF16),(*UTF32), and (*UCP) leading se- + quences that can be used to set UTF and Unicode property modes; they + are equivalent to setting the PCRE_UTF8, PCRE_UTF16, PCRE_UTF32 and the + PCRE_UCP options, respectively. The (*UTF) sequence is a generic ver- + sion that can be used with any of the libraries. However, the applica- + tion can set the PCRE_NEVER_UTF option, which locks out the use of the + (*UTF) sequences. SUBPATTERNS @@ -6043,18 +6037,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 - that, when the whole pattern matches, that portion of the subject + 2. It sets up the subpattern as a capturing subpattern. This means + that, when the whole pattern matches, that portion of the subject string that matched the subpattern is passed back to the caller via the - ovector argument of the matching function. (This applies only to the - traditional matching functions; the DFA matching functions do not sup- + ovector argument of the matching function. (This applies only to the + traditional matching functions; the DFA matching functions do not sup- port 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)) @@ -6062,12 +6056,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)) @@ -6075,37 +6069,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 - between the "?" and the ":". Thus the two patterns + As a convenient shorthand, if any option settings are required at the + start of a non-capturing subpattern, the option letters may appear be- + tween 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. @@ -6113,58 +6107,58 @@ 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 back reference 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)/ - 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 - change. To help with this difficulty, PCRE supports the naming of sub- + 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, PCRE supports the naming of sub- patterns. This feature was not added to Perl until release 5.10. Python - had the feature earlier, and PCRE introduced it at release 4.0, using - the Python syntax. PCRE now supports both the Perl and the Python syn- - tax. Perl allows identically numbered subpatterns to have different + had the feature earlier, and PCRE introduced it at release 4.0, using + the Python syntax. PCRE now supports both the Perl and the Python syn- + tax. Perl allows identically numbered subpatterns to have different names, but PCRE does not. - In PCRE, 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, recursion, and conditions, can be made by name as well as + In PCRE, 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, 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 - present. The PCRE API provides function calls for extracting the name- - to-number translation table from a compiled pattern. There is also a + Names consist of up to 32 alphanumeric characters and underscores, but + must start with a non-digit. Named capturing parentheses are still al- + located numbers as well as names, exactly as if the names were not + present. The PCRE API provides function calls for extracting the name- + to-number translation table from a compiled pattern. There is also a convenience function for extracting a captured substring by name. - By default, a name must be unique within a pattern, but it is possible + By default, a name must be unique within a pattern, but it is possible to relax this constraint by setting the PCRE_DUPNAMES option at compile - time. (Duplicate names are also always permitted for subpatterns with - the same number, set up as described in the previous section.) Dupli- - cate 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 + time. (Duplicate names are also always permitted for subpatterns with + the same number, set up as described in the previous section.) Dupli- + cate 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 (ignoring the line breaks) does the job: @@ -6174,18 +6168,18 @@ NAMED SUBPATTERNS (?<DN>Thu)(?:rsday)?| (?<DN>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 function 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 function 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 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 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": @@ -6193,29 +6187,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 - pcreapi documentation. + 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 de- + tails of the interfaces for handling named subpatterns, see the pcreapi + documentation. Warning: You cannot use different names to distinguish between two sub- - patterns with the same number because PCRE uses only the numbers when + patterns with the same number because PCRE 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 PCRE_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 @@ -6229,17 +6223,17 @@ REPETITION a parenthesized subpattern (including 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,} @@ -6248,50 +6242,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 - data units. Thus, for example, \x{100}{2} matches two characters, each + data 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 data units long (and they may be of different + larly, \X{3} matches three Unicode extended grapheme clusters, each of + which may be several data 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 PCRE 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- + 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- 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 /\*.*\*/ @@ -6300,19 +6294,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. - However, if a quantifier is followed by a question mark, it ceases to + However, 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 pattern /\*.*?\*/ - 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 @@ -6320,45 +6314,45 @@ REPETITION which matches one digit by preference, but can match two if that is the only way the rest of the pattern matches. - If the PCRE_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 + If the PCRE_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 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 PCRE_DOTALL option (equiv- - alent to Perl's /s) is set, thus allowing the dot to match newlines, - 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. PCRE normally treats such a pattern as though it were preceded + alent to Perl's /s) is set, thus allowing the dot to match newlines, + 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. PCRE 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 PCRE_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 PCRE_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. + 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: (.*)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- + It matches "ab" in the subject "aab". The use of the backtracking con- trol verbs (*PRUNE) and (*SKIP) also disable this optimization. When a capturing subpattern is repeated, the value captured is the sub- @@ -6367,8 +6361,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))+/ @@ -6378,53 +6372,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 - the string of characters that an identical standalone pattern would + An alternative description is that a subpattern of this type matches + 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 @@ -6434,46 +6428,46 @@ ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS (abc|xyz){2,3}+ - Possessive quantifiers are always greedy; the setting of the - PCRE_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 + Possessive quantifiers are always greedy; the setting of the PCRE_UN- + GREEDY option is ignored. They are a convenient notation for the sim- + pler 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 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 PCRE copied it from there. It ultimately + built Sun's Java package, and PCRE copied it from there. It ultimately found its way into Perl at release 5.10. PCRE has an optimization that automatically "possessifies" certain sim- - ple 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 + ple 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. - 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 PCRE 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: + 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 ex- + ample uses [!?] rather than a single character at the end, because both + PCRE and Perl have an optimization that allows for fast failure when a + single character is used. They remember the last single character 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+>)*[!?] @@ -6484,28 +6478,28 @@ BACK REFERENCES 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 + 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 10, - 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 10. 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- + 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 10. 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 10 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 - subpattern is possible using named parentheses (see below). + It is not possible to have a numerical "forward back reference" to a + subpattern whose number is 10 or more using this syntax because a se- + quence such as \50 is interpreted as a character defined in octal. See + the subsection entitled "Non-printing characters" above for further de- + tails of the handling of digits following a backslash. There is no such + problem when named parentheses are used. A back reference to any sub- + pattern 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 an unsigned number or a negative number, optionally enclosed in braces. These examples are all identical: @@ -6513,7 +6507,7 @@ 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 negative number is a relative reference. Consider this example: @@ -6522,126 +6516,126 @@ BACK REFERENCES 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. - A back reference matches whatever actually matched the capturing sub- - pattern in the current subject string, rather than anything matching + 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 (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 back reference, 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<name> or - \k'name' are supported, as is the Python syntax (?P=name). Perl 5.10's + There are several different ways of writing back references 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 references, is also supported. We could rewrite the above - example in any of the following ways: + and named references, is also supported. We could rewrite the above ex- + ample in any of the following ways: (?<p1>(?i)rah)\s+\k<p1> (?'p1'(?i)rah)\s+\k{p1} (?P<p1>(?i)rah)\s+(?P=p1) (?<p1>(?i)rah)\s+\g{p1} - A subpattern that is referenced by name may appear in the pattern - before or after the reference. + A subpattern that is referenced by name may appear in the pattern be- + fore 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 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 (a|(bc))\2 - always fails if it starts to match "a" rather than "bc". However, if + always fails if it starts to match "a" rather than "bc". However, if the PCRE_JAVASCRIPT_COMPAT option is set at compile time, a back refer- ence 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 - PCRE_EXTENDED option is set, this can be white space. Otherwise, the - \g{ syntax or an empty comment (see "Comments" below) can be used. + 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 de- + limiter must be used to terminate the back reference. If the PCRE_EX- + TENDED option is set, this can be white space. Otherwise, the \g{ syn- + tax or an empty comment (see "Comments" below) can be used. Recursive back references - 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 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- 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 + 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. - 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 + 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 of the group. ASSERTIONS - An assertion is a test on the characters following or preceding the - current matching point that does not actually consume any characters. - The simple assertions coded as \b, \B, \A, \G, \Z, \z, ^ and $ are - described above. + An assertion is a test on the characters following or preceding the + current matching point that does not actually consume any characters. + The simple assertions coded as \b, \B, \A, \G, \Z, \z, ^ and $ are de- + scribed 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. An assertion subpattern is - matched in the normal way, except that it does not cause the current + 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. An assertion subpattern is + matched in the normal way, except that it does not cause the current matching position to be changed. - Assertion subpatterns are not capturing subpatterns. If such an asser- - tion contains capturing subpatterns within it, these are counted for - the purposes of numbering the capturing subpatterns in the whole pat- - tern. However, substring capturing is carried out only for positive - assertions. (Perl sometimes, but not always, does do capturing in nega- + Assertion subpatterns are not capturing subpatterns. If such an asser- + tion contains capturing subpatterns within it, these are counted for + the purposes of numbering the capturing subpatterns in the whole pat- + tern. However, substring capturing is carried out only for positive as- + sertions. (Perl sometimes, but not always, does do capturing in nega- tive assertions.) - WARNING: If a positive assertion containing one or more capturing sub- - patterns succeeds, but failure to match later in the pattern causes + WARNING: If a positive assertion containing one or more capturing sub- + patterns succeeds, but failure to match later in the pattern causes backtracking over this assertion, the captures within the assertion are - reset only if no higher numbered captures are already set. This is, - unfortunately, a fundamental limitation of the current implementation, - and as PCRE1 is now in maintenance-only status, it is unlikely ever to + reset only if no higher numbered captures are already set. This is, un- + fortunately, a fundamental limitation of the current implementation, + and as PCRE1 is now in maintenance-only status, it is unlikely ever to change. - For compatibility with Perl, 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. In + For compatibility with Perl, 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. In practice, 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 @@ -6651,38 +6645,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 al- + ways 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 (?<! + Lookbehind assertions start with (?<= for positive assertions and (?<! for negative assertions. For example, (?<!foo)bar - does find an occurrence of "bar" that is not preceded by "foo". The - contents of a lookbehind assertion are restricted such that all the + does find an occurrence of "bar" that is not preceded by "foo". The + contents of a lookbehind assertion are restricted such that all the strings it matches must have a fixed length. However, if there are sev- - eral top-level alternatives, they do not all have to have the same + eral top-level alternatives, they do not all have to have the same fixed length. Thus (?<=bullock|donkey) @@ -6691,62 +6685,62 @@ ASSERTIONS (?<!dogs?|cats?) - causes an error at compile time. Branches that match different length - strings are permitted only at the top level of a lookbehind assertion. + causes an error at compile time. Branches that match different length + strings are permitted only at the top level of a lookbehind assertion. This is an extension compared with Perl, which requires all branches to match the same length of string. An assertion such as (?<=ab(c|de)) - is not permitted, because its single top-level branch can match two + is not permitted, because its single top-level branch can match two different lengths, but it is acceptable to PCRE if rewritten to use two top-level branches: (?<=abc|abde) - In some cases, the escape sequence \K (see above) can be used instead + In some cases, the escape sequence \K (see above) can be used instead of a lookbehind assertion to get round the fixed-length restriction. - The implementation of lookbehind assertions is, for each alternative, - to temporarily move the current position back by the fixed length and + The implementation of lookbehind assertions is, for each alternative, + to temporarily move the current position back by the fixed length and then try to match. If there are insufficient characters before the cur- rent position, the assertion fails. - In a UTF mode, PCRE does not allow the \C escape (which matches a sin- - gle data unit even in a UTF mode) to appear in lookbehind assertions, - because it makes it impossible to calculate the length of the lookbe- - hind. The \X and \R escapes, which can match different numbers of data + In a UTF mode, PCRE does not allow the \C escape (which matches a sin- + gle data unit even in a UTF mode) to appear in lookbehind assertions, + because it makes it impossible to calculate the length of the lookbe- + hind. The \X and \R escapes, which can match different numbers of data units, are also not permitted. - "Subroutine" calls (see below) such as (?2) or (?&X) are permitted in - lookbehinds, as long as the subpattern matches a fixed-length string. + "Subroutine" calls (see below) such as (?2) or (?&X) are permitted in + lookbehinds, as long as the subpattern matches a fixed-length string. Recursion, however, is not supported. - Possessive quantifiers can be used in conjunction with lookbehind - assertions to specify efficient matching of fixed-length strings at the + Possessive quantifiers can be used in conjunction with lookbehind as- + sertions to specify efficient matching of fixed-length strings at the end of subject strings. Consider a simple pattern such as abcd$ - when applied to a long string that does not match. Because matching + when applied to a long string that does not match. Because matching proceeds from left to right, PCRE will look for each "a" in the subject - and then see if what follows matches the rest of the pattern. If the + and then see if what follows matches the rest of the pattern. If the pattern is specified as ^.*abcd$ - the initial .* matches the entire string at first, but when this fails + the initial .* matches the entire string at first, but when this fails (because there is no following "a"), it backtracks to match all but the - last character, then all but the last two characters, and so on. Once - again the search for "a" covers the entire string, from right to left, + last character, then all but the last two characters, and so on. Once + again the search for "a" covers the entire string, from right to left, so we are no better off. However, if the pattern is written as ^.*+(?<=abcd) - there can be no backtracking for the .*+ item; it can match only the - entire string. The subsequent lookbehind assertion does a single test - on the last four characters. If it fails, the match fails immediately. - For long strings, this approach makes a significant difference to the + there can be no backtracking for the .*+ item; it can match only the + entire string. The subsequent lookbehind assertion does a single test + on the last four characters. If it fails, the match fails immediately. + For long strings, this approach makes a significant difference to the processing time. Using multiple assertions @@ -6755,18 +6749,18 @@ ASSERTIONS (?<=\d{3})(?<!999)foo - matches "foo" preceded by three digits that are not "999". Notice that - each of the assertions is applied independently at the same point in - the subject string. First there is a check that the previous three - characters are all digits, and then there is a check that the same + matches "foo" preceded by three digits that are not "999". Notice that + each of the assertions is applied independently at the same point in + the subject string. First there is a check that the previous three + characters are all digits, and then there is a check that the same three characters are not "999". This pattern does not match "foo" pre- - ceded by six characters, the first of which are digits and the last - three of which are not "999". For example, it doesn't match "123abc- + ceded by six characters, the first of which are digits and the last + three of which are not "999". For example, it doesn't match "123abc- foo". A pattern to do that is (?<=\d{3}...)(?<!999)foo - This time the first assertion looks at the preceding six characters, + This time the first assertion looks at the preceding six characters, checking that the first three are digits, and then the second assertion checks that the preceding three characters are not "999". @@ -6774,99 +6768,99 @@ ASSERTIONS (?<=(?<!foo)bar)baz - matches an occurrence of "baz" that is preceded by "bar" which in turn + matches an occurrence of "baz" that is preceded by "bar" which in turn is not preceded by "foo", while (?<=\d{3}(?!999)...)foo - is another pattern that matches "foo" preceded by three digits and any + is another pattern that matches "foo" preceded by three digits and any three characters that are not "999". CONDITIONAL SUBPATTERNS - It is possible to cause the matching process to obey a subpattern con- - ditionally or to choose between two alternative subpatterns, depending - on the result of an assertion, or whether a specific capturing subpat- - tern has already been matched. The two possible forms of conditional + It is possible to cause the matching process to obey a subpattern con- + ditionally or to choose between two alternative subpatterns, depending + on the result of an assertion, or whether a specific capturing subpat- + tern has already been matched. The two possible forms of conditional subpattern are: (?(condition)yes-pattern) (?(condition)yes-pattern|no-pattern) - If the condition is satisfied, the yes-pattern is used; otherwise the - no-pattern (if present) is used. If there are more than two alterna- - tives in the subpattern, a compile-time error occurs. Each of the two + If the condition is satisfied, the yes-pattern is used; otherwise the + no-pattern (if present) is used. If there are more than two alterna- + tives in the subpattern, a compile-time error occurs. Each of the two alternatives may itself contain nested subpatterns of any form, includ- - ing conditional subpatterns; the restriction to two alternatives - applies only at the level of the condition. This pattern fragment is an + ing conditional subpatterns; the restriction to two alternatives ap- + plies only at the level of the condition. This pattern fragment is an example where the alternatives are complex: (?(1) (A|B|C) | (D | (?(2)E|F) | E) ) - There are four kinds of condition: references to subpatterns, refer- + There are four kinds of condition: references to subpatterns, refer- ences to recursion, a pseudo-condition called DEFINE, and assertions. Checking for a used subpattern by number - If the text between the parentheses consists of a sequence of digits, + If the text between the parentheses consists of a sequence of digits, the condition is true if a capturing subpattern of that number has pre- - viously matched. If there is more than one capturing subpattern with - the same number (see the earlier section about duplicate subpattern - numbers), the condition is true if any of them have matched. An alter- - native notation is to precede the digits with a plus or minus sign. In - this case, the subpattern number is relative rather than absolute. The - most recently opened parentheses can be referenced by (?(-1), the next - most recent by (?(-2), and so on. Inside loops it can also make sense + viously matched. If there is more than one capturing subpattern with + the same number (see the earlier section about duplicate subpattern + numbers), the condition is true if any of them have matched. An alter- + native notation is to precede the digits with a plus or minus sign. In + this case, the subpattern number is relative rather than absolute. The + most recently opened parentheses can be referenced by (?(-1), the next + most recent by (?(-2), and so on. Inside loops it can also make sense to refer to subsequent groups. The next parentheses to be opened can be - referenced as (?(+1), and so on. (The value zero in any of these forms + referenced as (?(+1), and so on. (The value zero in any of these forms is not used; it provokes a compile-time error.) - Consider the following pattern, which contains non-significant white + Consider the following pattern, which contains non-significant white space to make it more readable (assume the PCRE_EXTENDED option) and to divide it into three parts for ease of discussion: ( \( )? [^()]+ (?(1) \) ) - The first part matches an optional opening parenthesis, and if that + The first part matches an optional opening parenthesis, and if that character is present, sets it as the first captured substring. The sec- - ond part matches one or more characters that are not parentheses. The - third part is a conditional subpattern that tests whether or not the - first set of parentheses matched. If they did, that is, if subject - started with an opening parenthesis, the condition is true, and so the - yes-pattern is executed and a closing parenthesis is required. Other- - wise, since no-pattern is not present, the subpattern matches nothing. - In other words, this pattern matches a sequence of non-parentheses, - optionally enclosed in parentheses. - - If you were embedding this pattern in a larger one, you could use a + ond part matches one or more characters that are not parentheses. The + third part is a conditional subpattern that tests whether or not the + first set of parentheses matched. If they did, that is, if subject + started with an opening parenthesis, the condition is true, and so the + yes-pattern is executed and a closing parenthesis is required. Other- + wise, since no-pattern is not present, the subpattern matches nothing. + In other words, this pattern matches a sequence of non-parentheses, op- + tionally enclosed in parentheses. + + If you were embedding this pattern in a larger one, you could use a relative reference: ...other stuff... ( \( )? [^()]+ (?(-1) \) ) ... - This makes the fragment independent of the parentheses in the larger + This makes the fragment independent of the parentheses in the larger pattern. Checking for a used subpattern by name - Perl uses the syntax (?(<name>)...) or (?('name')...) to test for a - used subpattern by name. For compatibility with earlier versions of - PCRE, which had this facility before Perl, the syntax (?(name)...) is + Perl uses the syntax (?(<name>)...) or (?('name')...) to test for a + used subpattern by name. For compatibility with earlier versions of + PCRE, which had this facility before Perl, the syntax (?(name)...) is also recognized. Rewriting the above example to use a named subpattern gives this: (?<OPEN> \( )? [^()]+ (?(<OPEN>) \) ) - 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 If the condition is the string (R), and there is no subpattern with the - name R, the condition is true if a recursive call to the whole pattern + name R, the condition is true if a recursive call to the whole pattern or any subpattern has been made. If digits or a name preceded by amper- sand follow the letter R, for example: @@ -6874,51 +6868,51 @@ CONDITIONAL SUBPATTERNS the condition is true if the most recent recursion is into a subpattern whose number or name is given. This condition does not check the entire - recursion stack. 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 + recursion stack. If the name used in a condition of this kind is a du- + plicate, the test is applied to all subpatterns of the same name, and is true if any one of them is the most recent recursion. - At "top level", all these recursion test conditions are false. The + At "top level", all these recursion test conditions are false. The syntax for recursive patterns is described below. Defining subpatterns for use by reference only - If the condition is the string (DEFINE), and there is no subpattern - with the name DEFINE, the condition is always false. In this case, - there may be only one alternative in the subpattern. It is always - skipped if control reaches this point in the pattern; the idea of - DEFINE is that it can be used to define subroutines that can be refer- - enced from elsewhere. (The use of subroutines is described below.) For - example, a pattern to match an IPv4 address such as "192.168.23.245" + If the condition is the string (DEFINE), and there is no subpattern + with the name DEFINE, the condition is always false. In this case, + there may be only one alternative in the subpattern. It is always + skipped if control reaches this point in the pattern; the idea of DE- + FINE is that it can be used to define subroutines that can be refer- + enced from elsewhere. (The use of subroutines is described below.) For + example, a pattern to match an IPv4 address such as "192.168.23.245" could be written like this (ignore white space and line breaks): (?(DEFINE) (?<byte> 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. 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 as- + sertion. 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 op- + tional 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 let- + ter 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. @@ -6927,41 +6921,41 @@ COMMENTS There are two ways of including comments in patterns that are processed by PCRE. In both cases, the start of the comment must not be in a char- acter class, nor in the middle of any other sequence of related charac- - ters such as (?: or a subpattern name or number. The characters that + ters 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 + The sequence (?# marks the start of a comment that continues up to the + next closing parenthesis. Nested parentheses are not permitted. If the PCRE_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- + 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 the options passed to - a compiling function or by a special sequence at the start of the pat- + a compiling function or by a special sequence at the start of the pat- tern, 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 PCRE_EXTENDED is + in the pattern; escape sequences that happen to represent a newline do + not count. For example, consider this pattern when PCRE_EXTENDED is set, and the default newline convention is in force: abc #comment \n still comment - On encountering the # character, pcre_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, pcre_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: @@ -6971,201 +6965,201 @@ RECURSIVE PATTERNS refers recursively to the pattern in which it appears. Obviously, PCRE cannot support the interpolation of Perl code. Instead, - it supports special syntax for recursion of the entire pattern, and - also for individual subpattern recursion. After its introduction in - PCRE and Python, this kind of recursion was subsequently introduced + it supports special syntax for recursion of the entire pattern, and + also for individual subpattern recursion. After its introduction in + PCRE 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 - recursive call of the entire regular expression. + 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 re- + cursive call of the entire regular expression. - This PCRE pattern solves the nested parentheses problem (assume the + This PCRE pattern solves the nested parentheses problem (assume the PCRE_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- - sized substring). Finally there is a closing parenthesis. Note the use - of a possessive quantifier to avoid backtracking into sequences of non- + First it matches an opening parenthesis. Then it matches any number of + substrings which can either be a sequence of non-parentheses, or a re- + cursive match of the pattern itself (that is, a correctly parenthesized + 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. - 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 instead. The Perl - syntax for this is (?&name); PCRE's earlier syntax (?P>name) is also + An alternative approach is to use named parentheses instead. The Perl + syntax for this is (?&name); PCRE's earlier syntax (?P>name) is also supported. We could rewrite the above example as follows: (?<pn> \( ( [^()]++ | (?&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. - This particular example pattern that we have been looking at contains + This particular example pattern that we have been looking at contains nested unlimited repeats, and so the use of a possessive quantifier for matching strings of non-parentheses is important when applying the pat- - tern to strings that do not match. For example, when this pattern is + tern 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 - callout function can be used (see below and the pcrecallout documenta- + 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 pcrecallout 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. - If there are more than 15 capturing parentheses in a pattern, PCRE has - to obtain extra memory to store data during a recursion, which it does + If there are more than 15 capturing parentheses in a pattern, PCRE has + to obtain extra memory to store data during a recursion, which it does by using pcre_malloc, freeing it via pcre_free afterwards. If no memory can be obtained, the match fails with the PCRE_ERROR_NOMEMORY error. - 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 PCRE and Perl - Recursion processing in PCRE differs from Perl in two important ways. - In PCRE (like Python, but unlike Perl), a recursive subpattern call is + Recursion processing in PCRE differs from Perl in two important ways. + In PCRE (like Python, but unlike Perl), a recursive subpattern call is always treated as an atomic group. That is, once it has matched some of the subject string, it is never re-entered, even if it contains untried - alternatives and there is a subsequent matching failure. This can be - illustrated by the following pattern, which purports to match a palin- - dromic string that contains an odd number of characters (for example, + alternatives and there is a subsequent matching failure. This can be + illustrated by the following pattern, which purports to match a palin- + dromic string that contains an odd number of characters (for example, "a", "aba", "abcba", "abcdcba"): ^(.|(.)(?1)\2)$ The idea is that it either matches a single character, or two identical - characters surrounding a sub-palindrome. In Perl, this pattern works; - in PCRE it does not if the pattern is longer than three characters. + characters surrounding a sub-palindrome. In Perl, this pattern works; + in PCRE it does not if the pattern is longer than three characters. Consider the subject string "abcba": - At the top level, the first character is matched, but as it is not at + At the top level, the first character is matched, but as it is not at the end of the string, the first alternative fails; the second alterna- tive is taken and the recursion kicks in. The recursive call to subpat- - tern 1 successfully matches the next character ("b"). (Note that the + tern 1 successfully matches the next character ("b"). (Note that the beginning and end of line tests are not part of the recursion). - Back at the top level, the next character ("c") is compared with what - subpattern 2 matched, which was "a". This fails. Because the recursion - is treated as an atomic group, there are now no backtracking points, - and so the entire match fails. (Perl is able, at this point, to re- - enter the recursion and try the second alternative.) However, if the - pattern is written with the alternatives in the other order, things are + Back at the top level, the next character ("c") is compared with what + subpattern 2 matched, which was "a". This fails. Because the recursion + is treated as an atomic group, there are now no backtracking points, + and so the entire match fails. (Perl is able, at this point, to re-en- + ter the recursion and try the second alternative.) However, if the pat- + tern is written with the alternatives in the other order, things are different: ^((.)(?1)\2|.)$ - This time, the recursing alternative is tried first, and continues to - recurse until it runs out of characters, at which point the recursion - fails. But this time we do have another alternative to try at the - higher level. That is the big difference: in the previous case the - remaining alternative is at a deeper recursion level, which PCRE cannot + This time, the recursing alternative is tried first, and continues to + recurse until it runs out of characters, at which point the recursion + fails. But this time we do have another alternative to try at the + higher level. That is the big difference: in the previous case the re- + maining alternative is at a deeper recursion level, which PCRE cannot use. - To change the pattern so that it matches all palindromic strings, not - just those with an odd number of characters, it is tempting to change + To change the pattern so that it matches all palindromic strings, not + just those with an odd number of characters, it is tempting to change the pattern to this: ^((.)(?1)\2|.?)$ - Again, this works in Perl, but not in PCRE, and for the same reason. - When a deeper recursion has matched a single character, it cannot be - entered again in order to match an empty string. The solution is to - separate the two cases, and write out the odd and even cases as alter- + Again, this works in Perl, but not in PCRE, and for the same reason. + When a deeper recursion has matched a single character, it cannot be + entered again in order to match an empty string. The solution is to + separate the two cases, and write out the odd and even cases as alter- natives at the higher level: ^(?:((.)(?1)\2|)|((.)(?3)\4|.)) - If you want to match typical palindromic phrases, the pattern has to + If you want to match typical palindromic phrases, the pattern has to ignore all non-word characters, which can be done like this: ^\W*+(?:((.)\W*+(?1)\W*+\2|)|((.)\W*+(?3)\W*+\4|\W*+.\W*+))\W*+$ If run with the PCRE_CASELESS option, this pattern matches phrases such as "A man, a plan, a canal: Panama!" and it works well in both PCRE and - Perl. Note the use of the possessive quantifier *+ to avoid backtrack- - ing into sequences of non-word characters. Without this, PCRE takes a - great deal longer (ten times or more) to match typical phrases, and + Perl. Note the use of the possessive quantifier *+ to avoid backtrack- + ing into sequences of non-word characters. Without this, PCRE takes a + great deal longer (ten times or more) to match typical phrases, and Perl takes so long that you think it has gone into a loop. - WARNING: The palindrome-matching patterns above work only if the sub- - ject string does not start with a palindrome that is shorter than the - entire string. For example, although "abcba" is correctly matched, if - the subject is "ababa", PCRE finds the palindrome "aba" at the start, - then fails at top level because the end of the string does not follow. - Once again, it cannot jump back into the recursion to try other alter- + WARNING: The palindrome-matching patterns above work only if the sub- + ject string does not start with a palindrome that is shorter than the + entire string. For example, although "abcba" is correctly matched, if + the subject is "ababa", PCRE finds the palindrome "aba" at the start, + then fails at top level because the end of the string does not follow. + Once again, it cannot jump back into the recursion to try other alter- natives, so the entire match fails. - The second way in which PCRE and Perl differ in their recursion pro- - cessing is in the handling of captured values. In Perl, when a subpat- - tern is called recursively or as a subpattern (see the next section), - it has no access to any values that were captured outside the recur- - sion, whereas in PCRE these values can be referenced. Consider this + The second way in which PCRE and Perl differ in their recursion pro- + cessing is in the handling of captured values. In Perl, when a subpat- + tern is called recursively or as a subpattern (see the next section), + it has no access to any values that were captured outside the recur- + sion, whereas in PCRE these values can be referenced. Consider this pattern: ^(.)(\1|a(?2)) - In PCRE, 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. - In Perl, the pattern fails to match because inside the recursive call + In PCRE, 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. + In Perl, the pattern fails to match because inside the recursive call \1 cannot access the externally set value. SUBPATTERNS AS SUBROUTINES - If the syntax for a recursive subpattern call (either by number or by - name) is used outside the parentheses to which it refers, it operates - like a subroutine in a programming language. The called subpattern may - be defined before or after the reference. A numbered reference can be + If the syntax for a recursive subpattern call (either by number or by + name) is used outside the parentheses to which it refers, it operates + like a subroutine in a programming language. The called subpattern may + be defined before or after the reference. A numbered reference can be absolute or relative, as in these examples: (...(absolute)...)...(?2)... @@ -7176,79 +7170,79 @@ SUBPATTERNS AS SUBROUTINES (sens|respons)e and \1ibility - matches "sense and sensibility" and "response and responsibility", but + matches "sense and sensibility" and "response and responsibility", but not "sense and responsibility". If instead the pattern (sens|respons)e and (?1)ibility - is used, it does match "sense and responsibility" as well as the other - two strings. Another example is given in the discussion of DEFINE + is used, it does match "sense and responsibility" as well as the other + two strings. Another example is given in the discussion of DEFINE above. - All subroutine calls, whether recursive or not, are always treated as - atomic groups. That is, once a subroutine has matched some of the sub- + All subroutine calls, whether recursive or not, are always treated as + atomic groups. That is, once a subroutine has matched some of the sub- ject string, it is never re-entered, even if it contains untried alter- - natives and there is a subsequent matching failure. Any capturing - parentheses that are set during the subroutine call revert to their + natives and there is a subsequent matching failure. Any capturing + parentheses that are set during the subroutine call revert to their previous values afterwards. - Processing options such as case-independence are fixed when a subpat- - tern is defined, so if it is used as a subroutine, such options cannot + Processing options such as case-independence are fixed when a subpat- + tern is defined, so if it is used as a subroutine, such options cannot be changed for different calls. For example, consider this pattern: (abc)(?i:(?-1)) - It matches "abcabc". It does not match "abcABC" because the change of + It matches "abcabc". It does not match "abcABC" because the change of processing option does not affect the called subpattern. ONIGURUMA SUBROUTINE SYNTAX - 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, - possibly recursively. Here are two of the examples used above, rewrit- + an alternative syntax for referencing a subpattern as a subroutine, + possibly recursively. Here are two of the examples used above, rewrit- ten using this syntax: (?<pn> \( ( (?>[^()]+) | \g<pn> )* \) ) (sens|respons)e and \g'1'ibility - PCRE supports an extension to Oniguruma: if a number is preceded by a + PCRE supports an extension to Oniguruma: if a number is preceded by a 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 + Note that \g{...} (Perl syntax) and \g<...> (Oniguruma syntax) are not + synonymous. The former is a back reference; the latter is a subroutine call. CALLOUTS Perl has a feature whereby using the sequence (?{...}) causes arbitrary - Perl code to be obeyed in the middle of matching a regular expression. + Perl code to be obeyed in the middle of matching a regular expression. This makes it possible, amongst other things, to extract different sub- strings that match the same pair of parentheses when there is a repeti- tion. PCRE provides a similar feature, but of course it cannot obey arbitrary Perl code. The feature is called "callout". The caller of PCRE provides - an external function by putting its entry point in the global variable - pcre_callout (8-bit library) or pcre[16|32]_callout (16-bit or 32-bit - library). By default, this variable contains NULL, which disables all + an external function by putting its entry point in the global variable + pcre_callout (8-bit library) or pcre[16|32]_callout (16-bit or 32-bit + library). By default, this variable contains NULL, which disables all calling out. - Within a regular expression, (?C) indicates the points at which the - external function is to be called. If you want to identify different - callout points, you can put a number less than 256 after the letter C. - The default value is zero. For example, this pattern has two callout + Within a regular expression, (?C) indicates the points at which the ex- + ternal function is to be called. If you want to identify different + callout points, you can put a number less than 256 after the letter C. + The default value is zero. For example, this pattern has two callout points: (?C1)abc(?C2)def - If the PCRE_AUTO_CALLOUT flag is passed to a compiling function, call- - outs are automatically installed before each item in the pattern. They - are all numbered 255. If there is a conditional group in the pattern + If the PCRE_AUTO_CALLOUT flag is passed to a compiling function, call- + outs are automatically installed before each item in the pattern. They + are all numbered 255. If there is a conditional group in the pattern whose condition is an assertion, an additional callout is inserted just before the condition. An explicit callout may also be set at this posi- tion, as in this example: @@ -7258,120 +7252,120 @@ CALLOUTS Note that this applies only to assertion conditions, not to other types of condition. - During matching, when PCRE reaches a callout point, the external func- - tion is called. It is provided with the number of the callout, the - position in the pattern, and, optionally, one item of data originally - supplied by the caller of the matching function. The callout function + During matching, when PCRE reaches a callout point, the external func- + tion is called. It is provided with the number of the callout, the po- + sition in the pattern, and, optionally, one item of data originally + supplied by the caller of the matching function. The callout function may cause matching to proceed, to backtrack, or to fail altogether. - By default, PCRE implements a number of optimizations at compile time - and matching time, and one side-effect is that sometimes callouts are - skipped. If you need all possible callouts to happen, you need to set - options that disable the relevant optimizations. More details, and a - complete description of the interface to the callout function, are + By default, PCRE implements a number of optimizations at compile time + and matching time, and one side-effect is that sometimes callouts are + skipped. If you need all possible callouts to happen, you need to set + options that disable the relevant optimizations. More details, and a + complete description of the interface to the callout function, are given in the pcrecallout documentation. BACKTRACKING CONTROL - Perl 5.10 introduced a number of "Special Backtracking Control Verbs", - which are still described in the Perl documentation as "experimental - and subject to change or removal in a future version of Perl". It goes - on to say: "Their usage in production code should be noted to avoid - problems during upgrades." The same remarks apply to the PCRE features + Perl 5.10 introduced a number of "Special Backtracking Control Verbs", + which are still described in the Perl documentation as "experimental + and subject to change or removal in a future version of Perl". It goes + on to say: "Their usage in production code should be noted to avoid + problems during upgrades." The same remarks apply to the PCRE features described in this section. - The new verbs make use of what was previously invalid syntax: an open- + The new verbs make use of what was previously invalid syntax: an open- ing parenthesis followed by an asterisk. They are generally of the form - (*VERB) or (*VERB:NAME). Some may take either form, possibly behaving - differently depending on whether or not a name is present. A name is + (*VERB) or (*VERB:NAME). Some may take either form, possibly behaving + differently depending on whether or not a name is present. A name is any sequence of characters that does not include a closing parenthesis. The maximum length of name is 255 in the 8-bit library and 65535 in the - 16-bit and 32-bit libraries. If the name is empty, that is, if the - closing parenthesis immediately follows the colon, the effect is as if - the colon were not there. Any number of these verbs may occur in a + 16-bit and 32-bit libraries. If the name is empty, that is, if the + closing parenthesis immediately follows the colon, the effect is as if + the colon were not there. Any number of these verbs may occur in a pattern. - Since these verbs are specifically related to backtracking, most of - them can be used only when the pattern is to be matched using one of - the traditional matching functions, because these use a backtracking - algorithm. With the exception of (*FAIL), which behaves like a failing - negative assertion, the backtracking control verbs cause an error if + Since these verbs are specifically related to backtracking, most of + them can be used only when the pattern is to be matched using one of + the traditional matching functions, because these use a backtracking + algorithm. With the exception of (*FAIL), which behaves like a failing + negative assertion, the backtracking control verbs cause an error if encountered by a DFA matching function. - The behaviour of these verbs in repeated groups, assertions, and in + The behaviour of these verbs in repeated groups, assertions, and in subpatterns called as subroutines (whether or not recursively) is docu- mented below. Optimizations that affect backtracking verbs - PCRE contains some optimizations that are used to speed up matching by + PCRE contains some optimizations that are used to speed up matching by running some checks at the start of each match attempt. For example, it - may know the minimum length of matching subject, or that a particular + may know the minimum length of matching subject, or that a particular character must be present. When one of these optimizations bypasses the - running of a match, any included backtracking verbs will not, of + running of a match, any included backtracking verbs will not, of course, be processed. You can suppress the start-of-match optimizations - by setting the PCRE_NO_START_OPTIMIZE option when calling pcre_com- + by setting the PCRE_NO_START_OPTIMIZE option when calling pcre_com- pile() or pcre_exec(), or by starting the pattern with (*NO_START_OPT). There is more discussion of this option in the section entitled "Option bits for pcre_exec()" in the pcreapi documentation. - Experiments with Perl suggest that it too has similar optimizations, + Experiments with Perl suggest that it too has similar optimizations, sometimes leading to anomalous results. Verbs that act immediately - The following verbs act as soon as they are encountered. They may not + The following verbs act as soon as they are encountered. They may not be followed by a name. (*ACCEPT) - This verb causes the match to end successfully, skipping the remainder - of the pattern. However, when it is inside a subpattern that is called - as a subroutine, only that subpattern is ended successfully. Matching + This verb causes the match to end successfully, skipping the remainder + of the pattern. However, when it is inside a subpattern that is called + as a subroutine, only that subpattern is ended successfully. Matching then continues at the outer level. If (*ACCEPT) in triggered in a posi- - tive assertion, the assertion succeeds; in a negative assertion, the + tive assertion, the assertion succeeds; in a negative assertion, the assertion fails. - If (*ACCEPT) is inside capturing parentheses, the data so far is cap- + If (*ACCEPT) is inside capturing parentheses, the data so far is cap- tured. For example: A((?:A|B(*ACCEPT)|C)D) - This matches "AB", "AAD", or "ACD"; when it matches "AB", "B" is cap- + This matches "AB", "AAD", or "ACD"; when it matches "AB", "B" is cap- tured by the outer parentheses. (*FAIL) or (*F) - This verb causes a matching failure, forcing backtracking to occur. It - is equivalent to (?!) but easier to read. The Perl documentation notes - that it is probably useful only when combined with (?{}) or (??{}). - Those are, of course, Perl features that are not present in PCRE. The - nearest equivalent is the callout feature, as for example in this pat- + This verb causes a matching failure, forcing backtracking to occur. It + is equivalent to (?!) but easier to read. The Perl documentation notes + that it is probably useful only when combined with (?{}) or (??{}). + Those are, of course, Perl features that are not present in PCRE. The + nearest equivalent is the callout feature, as for example in this pat- tern: a+(?C)(*FAIL) - A match with the string "aaaa" always fails, but the callout is taken + A match with the string "aaaa" always fails, but the callout is taken before each backtrack happens (in this example, 10 times). Recording which path was taken - There is one verb whose main purpose is to track how a match was - arrived at, though it also has a secondary use in conjunction with - advancing the match starting point (see (*SKIP) below). + There is one verb whose main purpose is to track how a match was ar- + rived at, though it also has a secondary use in conjunction with ad- + vancing the match starting point (see (*SKIP) below). (*MARK:NAME) or (*:NAME) - A name is always required with this verb. There may be as many - instances of (*MARK) as you like in a pattern, and their names do not + A name is always required with this verb. There may be as many in- + stances of (*MARK) as you like in a pattern, and their names do not have to be unique. - When a match succeeds, the name of the last-encountered (*MARK:NAME), - (*PRUNE:NAME), or (*THEN:NAME) on the matching path is passed back to - the caller as described in the section entitled "Extra data for - pcre_exec()" in the pcreapi documentation. Here is an example of - pcretest output, where the /K modifier requests the retrieval and out- + When a match succeeds, the name of the last-encountered (*MARK:NAME), + (*PRUNE:NAME), or (*THEN:NAME) on the matching path is passed back to + the caller as described in the section entitled "Extra data for + pcre_exec()" in the pcreapi documentation. Here is an example of + pcretest output, where the /K modifier requests the retrieval and out- putting of (*MARK) data: re> /X(*MARK:A)Y|X(*MARK:B)Z/K @@ -7383,73 +7377,73 @@ BACKTRACKING CONTROL MK: B The (*MARK) name is tagged with "MK:" in this output, and in this exam- - ple it indicates which of the two alternatives matched. This is a more - efficient way of obtaining this information than putting each alterna- + ple it indicates which of the two alternatives matched. This is a more + efficient way of obtaining this information than putting each alterna- tive in its own capturing parentheses. - If a verb with a name is encountered in a positive assertion that is - true, the name is recorded and passed back if it is the last-encoun- + If a verb with a name is encountered in a positive assertion that is + true, the name is recorded and passed back if it is the last-encoun- tered. This does not happen for negative assertions or failing positive assertions. - After a partial match or a failed match, the last encountered name in + After a partial match or a failed match, the last encountered name in the entire match process is returned. For example: re> /X(*MARK:A)Y|X(*MARK:B)Z/K data> XP No match, mark = B - Note that in this unanchored example the mark is retained from the + Note that in this unanchored example the mark is retained from the match attempt that started at the letter "X" in the subject. Subsequent match attempts starting at "P" and then with an empty string do not get as far as the (*MARK) item, but nevertheless do not reset it. - If you are interested in (*MARK) values after failed matches, you - should probably set the PCRE_NO_START_OPTIMIZE option (see above) to + If you are interested in (*MARK) values after failed matches, you + should probably set the PCRE_NO_START_OPTIMIZE option (see above) to ensure that the match is always attempted. Verbs that act after backtracking The following verbs do nothing when they are encountered. Matching con- - tinues with what follows, but if there is no subsequent match, causing - a backtrack to the verb, a failure is forced. That is, backtracking - cannot pass to the left of the verb. However, when one of these verbs + tinues with what follows, but if there is no subsequent match, causing + a backtrack to the verb, a failure is forced. That is, backtracking + cannot pass to the left of the verb. However, when one of these verbs appears inside an atomic group or an assertion that is true, its effect - is confined to that group, because once the group has been matched, - there is never any backtracking into it. In this situation, backtrack- - ing can "jump back" to the left of the entire atomic group or asser- - tion. (Remember also, as stated above, that this localization also - applies in subroutine calls.) - - These verbs differ in exactly what kind of failure occurs when back- - tracking reaches them. The behaviour described below is what happens - when the verb is not in a subroutine or an assertion. Subsequent sec- + is confined to that group, because once the group has been matched, + there is never any backtracking into it. In this situation, backtrack- + ing can "jump back" to the left of the entire atomic group or asser- + tion. (Remember also, as stated above, that this localization also ap- + plies in subroutine calls.) + + These verbs differ in exactly what kind of failure occurs when back- + tracking reaches them. The behaviour described below is what happens + when the verb is not in a subroutine or an assertion. Subsequent sec- tions cover these special cases. (*COMMIT) - This verb, which may not be followed by a name, causes the whole match + This verb, which may not be followed by a name, causes the whole match to fail outright if there is a later matching failure that causes back- - tracking to reach it. Even if the pattern is unanchored, no further - attempts to find a match by advancing the starting point take place. If - (*COMMIT) is the only backtracking verb that is encountered, once it + tracking to reach it. Even if the pattern is unanchored, no further at- + tempts to find a match by advancing the starting point take place. If + (*COMMIT) is the only backtracking verb that is encountered, once it has been passed pcre_exec() is committed to finding a match at the cur- rent starting point, or not at all. For example: a+(*COMMIT)b - This matches "xxaab" but not "aacaab". It can be thought of as a kind + This matches "xxaab" but not "aacaab". It can be thought of as a kind of dynamic anchor, or "I've started, so I must finish." The name of the - most recently passed (*MARK) in the path is passed back when (*COMMIT) + most recently passed (*MARK) in the path is passed back when (*COMMIT) forces a match failure. - If there is more than one backtracking verb in a pattern, a different - one that follows (*COMMIT) may be triggered first, so merely passing + If there is more than one backtracking verb in a pattern, a different + one that follows (*COMMIT) may be triggered first, so merely passing (*COMMIT) during a match does not always guarantee that a match must be at this starting point. - Note that (*COMMIT) at the start of a pattern is not the same as an - anchor, unless PCRE's start-of-match optimizations are turned off, as + Note that (*COMMIT) at the start of a pattern is not the same as an an- + chor, unless PCRE's start-of-match optimizations are turned off, as shown in this output from pcretest: re> /(*COMMIT)abc/ @@ -7460,207 +7454,207 @@ BACKTRACKING CONTROL For this pattern, PCRE knows that any match must start with "a", so the optimization skips along the subject to "a" before applying the pattern - to the first set of data. The match attempt then succeeds. In the sec- - ond set of data, the escape sequence \Y is interpreted by the pcretest - program. It causes the PCRE_NO_START_OPTIMIZE option to be set when + to the first set of data. The match attempt then succeeds. In the sec- + ond set of data, the escape sequence \Y is interpreted by the pcretest + program. It causes the PCRE_NO_START_OPTIMIZE option to be set when pcre_exec() is called. This disables the optimization that skips along to the first character. The pattern is now applied starting at "x", and - so the (*COMMIT) causes the match to fail without trying any other + so the (*COMMIT) causes the match to fail without trying any other starting points. (*PRUNE) or (*PRUNE:NAME) - This verb causes the match to fail at the current starting position in + This verb causes the match to fail at the current starting position in the subject if there is a later matching failure that causes backtrack- - ing to reach it. If the pattern is unanchored, the normal "bumpalong" - advance to the next starting character then happens. Backtracking can - occur as usual to the left of (*PRUNE), before it is reached, or when - matching to the right of (*PRUNE), but if there is no match to the - right, backtracking cannot cross (*PRUNE). In simple cases, the use of - (*PRUNE) is just an alternative to an atomic group or possessive quan- + ing to reach it. If the pattern is unanchored, the normal "bumpalong" + advance to the next starting character then happens. Backtracking can + occur as usual to the left of (*PRUNE), before it is reached, or when + matching to the right of (*PRUNE), but if there is no match to the + right, backtracking cannot cross (*PRUNE). In simple cases, the use of + (*PRUNE) is just an alternative to an atomic group or possessive quan- tifier, but there are some uses of (*PRUNE) that cannot be expressed in - any other way. In an anchored pattern (*PRUNE) has the same effect as + any other way. In an anchored pattern (*PRUNE) has the same effect as (*COMMIT). The behaviour of (*PRUNE:NAME) is the not the same as - (*MARK:NAME)(*PRUNE). It is like (*MARK:NAME) in that the name is - remembered for passing back to the caller. However, (*SKIP:NAME) - searches only for names set with (*MARK). + (*MARK:NAME)(*PRUNE). It is like (*MARK:NAME) in that the name is re- + membered for passing back to the caller. However, (*SKIP:NAME) searches + only for names set with (*MARK). (*SKIP) - This verb, when given without a name, is like (*PRUNE), except that if - the pattern is unanchored, the "bumpalong" advance is not to the next + This verb, when given without a name, is like (*PRUNE), except that if + the pattern is unanchored, the "bumpalong" advance is not to the next character, but to the position in the subject where (*SKIP) was encoun- - tered. (*SKIP) signifies that whatever text was matched leading up to + tered. (*SKIP) signifies that whatever text was matched leading up to it cannot be part of a successful match. Consider: a+(*SKIP)b - If the subject is "aaaac...", after the first match attempt fails - (starting at the first character in the string), the starting point + If the subject is "aaaac...", after the first match attempt fails + (starting at the first character in the string), the starting point skips on to start the next attempt at "c". Note that a possessive quan- - tifer does not have the same effect as this example; although it would - suppress backtracking during the first match attempt, the second - attempt would start at the second character instead of skipping on to + tifer does not have the same effect as this example; although it would + suppress backtracking during the first match attempt, the second at- + tempt would start at the second character instead of skipping on to "c". (*SKIP:NAME) When (*SKIP) has an associated name, its behaviour is modified. When it is triggered, the previous path through the pattern is searched for the - most recent (*MARK) that has the same name. If one is found, the + most recent (*MARK) that has the same name. If one is found, the "bumpalong" advance is to the subject position that corresponds to that (*MARK) instead of to where (*SKIP) was encountered. If no (*MARK) with a matching name is found, the (*SKIP) is ignored. - Note that (*SKIP:NAME) searches only for names set by (*MARK:NAME). It + Note that (*SKIP:NAME) searches only for names set by (*MARK:NAME). It ignores names that are set by (*PRUNE:NAME) or (*THEN:NAME). (*THEN) or (*THEN:NAME) - This verb causes a skip to the next innermost alternative when back- - tracking reaches it. That is, it cancels any further backtracking - within the current alternative. Its name comes from the observation + This verb causes a skip to the next innermost alternative when back- + tracking reaches it. That is, it cancels any further backtracking + within the current alternative. Its name comes from the observation that it can be used for a pattern-based if-then-else block: ( COND1 (*THEN) FOO | COND2 (*THEN) BAR | COND3 (*THEN) BAZ ) ... - If the COND1 pattern matches, FOO is tried (and possibly further items - after the end of the group if FOO succeeds); on failure, the matcher - skips to the second alternative and tries COND2, without backtracking - into COND1. If that succeeds and BAR fails, COND3 is tried. If subse- - quently BAZ fails, there are no more alternatives, so there is a back- - track to whatever came before the entire group. If (*THEN) is not - inside an alternation, it acts like (*PRUNE). - - The behaviour of (*THEN:NAME) is the not the same as - (*MARK:NAME)(*THEN). It is like (*MARK:NAME) in that the name is - remembered for passing back to the caller. However, (*SKIP:NAME) - searches only for names set with (*MARK). - - A subpattern that does not contain a | character is just a part of the - enclosing alternative; it is not a nested alternation with only one - alternative. The effect of (*THEN) extends beyond such a subpattern to - the enclosing alternative. Consider this pattern, where A, B, etc. are - complex pattern fragments that do not contain any | characters at this + If the COND1 pattern matches, FOO is tried (and possibly further items + after the end of the group if FOO succeeds); on failure, the matcher + skips to the second alternative and tries COND2, without backtracking + into COND1. If that succeeds and BAR fails, COND3 is tried. If subse- + quently BAZ fails, there are no more alternatives, so there is a back- + track to whatever came before the entire group. If (*THEN) is not in- + side an alternation, it acts like (*PRUNE). + + The behaviour of (*THEN:NAME) is the not the same as + (*MARK:NAME)(*THEN). It is like (*MARK:NAME) in that the name is re- + membered for passing back to the caller. However, (*SKIP:NAME) searches + only for names set with (*MARK). + + A subpattern that does not contain a | character is just a part of the + enclosing alternative; it is not a nested alternation with only one al- + ternative. The effect of (*THEN) extends beyond such a subpattern to + the enclosing alternative. Consider this pattern, where A, B, etc. are + complex pattern fragments that do not contain any | characters at this level: A (B(*THEN)C) | D - If A and B are matched, but there is a failure in C, matching does not + If A and B are matched, but there is a failure in C, matching does not backtrack into A; instead it moves to the next alternative, that is, D. - However, if the subpattern containing (*THEN) is given an alternative, + However, if the subpattern containing (*THEN) is given an alternative, it behaves differently: A (B(*THEN)C | (*FAIL)) | D - The effect of (*THEN) is now confined to the inner subpattern. After a + The effect of (*THEN) is now confined to the inner subpattern. After a failure in C, matching moves to (*FAIL), which causes the whole subpat- - tern to fail because there are no more alternatives to try. In this + tern to fail because there are no more alternatives to try. In this case, matching does now backtrack into A. - Note that a conditional subpattern is not considered as having two - alternatives, because only one is ever used. In other words, the | - character in a conditional subpattern has a different meaning. Ignoring + Note that a conditional subpattern is not considered as having two al- + ternatives, because only one is ever used. In other words, the | char- + acter in a conditional subpattern has a different meaning. Ignoring white space, consider: ^.*? (?(?=a) a | b(*THEN)c ) - If the subject is "ba", this pattern does not match. Because .*? is - ungreedy, it initially matches zero characters. The condition (?=a) - then fails, the character "b" is matched, but "c" is not. At this - point, matching does not backtrack to .*? as might perhaps be expected - from the presence of the | character. The conditional subpattern is - part of the single alternative that comprises the whole pattern, and so - the match fails. (If there was a backtrack into .*?, allowing it to - match "b", the match would succeed.) + If the subject is "ba", this pattern does not match. Because .*? is un- + greedy, it initially matches zero characters. The condition (?=a) then + fails, the character "b" is matched, but "c" is not. At this point, + matching does not backtrack to .*? as might perhaps be expected from + the presence of the | character. The conditional subpattern is part of + the single alternative that comprises the whole pattern, and so the + match fails. (If there was a backtrack into .*?, allowing it to match + "b", the match would succeed.) - The verbs just described provide four different "strengths" of control + The verbs just described provide four different "strengths" of control when subsequent matching fails. (*THEN) is the weakest, carrying on the - match at the next alternative. (*PRUNE) comes next, failing the match - at the current starting position, but allowing an advance to the next - character (for an unanchored pattern). (*SKIP) is similar, except that + match at the next alternative. (*PRUNE) comes next, failing the match + at the current starting position, but allowing an advance to the next + character (for an unanchored pattern). (*SKIP) is similar, except that the advance may be more than one character. (*COMMIT) is the strongest, causing the entire match to fail. More than one backtracking verb - If more than one backtracking verb is present in a pattern, the one - that is backtracked onto first acts. For example, consider this pat- + If more than one backtracking verb is present in a pattern, the one + that is backtracked onto first acts. For example, consider this pat- tern, where A, B, etc. are complex pattern fragments: (A(*COMMIT)B(*THEN)C|ABD) - If A matches but B fails, the backtrack to (*COMMIT) causes the entire + If A matches but B fails, the backtrack to (*COMMIT) causes the entire match to fail. However, if A and B match, but C fails, the backtrack to - (*THEN) causes the next alternative (ABD) to be tried. This behaviour - is consistent, but is not always the same as Perl's. It means that if - two or more backtracking verbs appear in succession, all the the last + (*THEN) causes the next alternative (ABD) to be tried. This behaviour + is consistent, but is not always the same as Perl's. It means that if + two or more backtracking verbs appear in succession, all the the last of them has no effect. Consider this example: ...(*COMMIT)(*PRUNE)... If there is a matching failure to the right, backtracking onto (*PRUNE) - causes it to be triggered, and its action is taken. There can never be + causes it to be triggered, and its action is taken. There can never be a backtrack onto (*COMMIT). Backtracking verbs in repeated groups - PCRE differs from Perl in its handling of backtracking verbs in - repeated groups. For example, consider: + PCRE differs from Perl in its handling of backtracking verbs in re- + peated groups. For example, consider: /(a(*COMMIT)b)+ac/ - If the subject is "abac", Perl matches, but PCRE fails because the + If the subject is "abac", Perl matches, but PCRE fails because the (*COMMIT) in the second repeat of the group acts. Backtracking verbs in assertions - (*FAIL) in an assertion has its normal effect: it forces an immediate + (*FAIL) in an assertion has its normal effect: it forces an immediate backtrack. (*ACCEPT) in a positive assertion causes the assertion to succeed with- - out any further processing. In a negative assertion, (*ACCEPT) causes + out any further processing. In a negative assertion, (*ACCEPT) causes the assertion to fail without any further processing. - The other backtracking verbs are not treated specially if they appear - in a positive assertion. In particular, (*THEN) skips to the next - alternative in the innermost enclosing group that has alternations, + The other backtracking verbs are not treated specially if they appear + in a positive assertion. In particular, (*THEN) skips to the next al- + ternative in the innermost enclosing group that has alternations, whether or not this is within the assertion. - Negative assertions are, however, different, in order to ensure that - changing a positive assertion into a negative assertion changes its - result. Backtracking into (*COMMIT), (*SKIP), or (*PRUNE) causes a neg- - ative assertion to be true, without considering any further alternative + Negative assertions are, however, different, in order to ensure that + changing a positive assertion into a negative assertion changes its re- + sult. Backtracking into (*COMMIT), (*SKIP), or (*PRUNE) causes a nega- + tive assertion to be true, without considering any further alternative branches in the assertion. Backtracking into (*THEN) causes it to skip - to the next enclosing alternative within the assertion (the normal be- - haviour), but if the assertion does not have such an alternative, + to the next enclosing alternative within the assertion (the normal be- + haviour), but if the assertion does not have such an alternative, (*THEN) behaves like (*PRUNE). Backtracking verbs in subroutines - These behaviours occur whether or not the subpattern is called recur- + These behaviours occur whether or not the subpattern is called recur- sively. Perl's treatment of subroutines is different in some cases. - (*FAIL) in a subpattern called as a subroutine has its normal effect: + (*FAIL) in a subpattern called as a subroutine has its normal effect: it forces an immediate backtrack. - (*ACCEPT) in a subpattern called as a subroutine causes the subroutine - match to succeed without any further processing. Matching then contin- + (*ACCEPT) in a subpattern called as a subroutine causes the subroutine + match to succeed without any further processing. Matching then contin- ues after the subroutine call. (*COMMIT), (*SKIP), and (*PRUNE) in a subpattern called as a subroutine cause the subroutine match to fail. - (*THEN) skips to the next alternative in the innermost enclosing group - within the subpattern that has alternatives. If there is no such group + (*THEN) skips to the next alternative in the innermost enclosing group + within the subpattern that has alternatives. If there is no such group within the subpattern, (*THEN) causes the subroutine match to fail. SEE ALSO - pcreapi(3), pcrecallout(3), pcrematching(3), pcresyntax(3), pcre(3), + pcreapi(3), pcrecallout(3), pcrematching(3), pcresyntax(3), pcre(3), pcre16(3), pcre32(3). @@ -7814,16 +7808,16 @@ SCRIPT NAMES FOR \p AND \P ian, Caucasian_Albanian, Chakma, Cham, Cherokee, Common, Coptic, Cunei- form, Cypriot, Cyrillic, Deseret, Devanagari, Duployan, Egyptian_Hiero- glyphs, Elbasan, Ethiopic, Georgian, Glagolitic, Gothic, Grantha, - Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hiragana, - Imperial_Aramaic, Inherited, Inscriptional_Pahlavi, Inscrip- + Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hiragana, Im- + perial_Aramaic, Inherited, Inscriptional_Pahlavi, Inscrip- tional_Parthian, Javanese, Kaithi, Kannada, Katakana, Kayah_Li, Kharoshthi, Khmer, Khojki, Khudawadi, Lao, Latin, Lepcha, Limbu, Lin- ear_A, Linear_B, Lisu, Lycian, Lydian, Mahajani, Malayalam, Mandaic, - Manichaean, Meetei_Mayek, Mende_Kikakui, Meroitic_Cursive, - Meroitic_Hieroglyphs, Miao, Modi, Mongolian, Mro, Myanmar, Nabataean, - New_Tai_Lue, Nko, Ogham, Ol_Chiki, Old_Italic, Old_North_Arabian, - Old_Permic, Old_Persian, Old_South_Arabian, Old_Turkic, Oriya, Osmanya, - Pahawh_Hmong, Palmyrene, Pau_Cin_Hau, Phags_Pa, Phoenician, + Manichaean, Meetei_Mayek, Mende_Kikakui, Meroitic_Cursive, Meroitic_Hi- + eroglyphs, Miao, Modi, Mongolian, Mro, Myanmar, Nabataean, New_Tai_Lue, + Nko, Ogham, Ol_Chiki, Old_Italic, Old_North_Arabian, Old_Permic, + Old_Persian, Old_South_Arabian, Old_Turkic, Oriya, Osmanya, Pa- + hawh_Hmong, Palmyrene, Pau_Cin_Hau, Phags_Pa, Phoenician, Psalter_Pahlavi, Rejang, Runic, Samaritan, Saurashtra, Sharada, Sha- vian, Siddham, Sinhala, Sora_Sompeng, Sundanese, Syloti_Nagri, Syriac, Tagalog, Tagbanwa, Tai_Le, Tai_Tham, Tai_Viet, Takri, Tamil, Telugu, @@ -7938,9 +7932,9 @@ OPTION SETTING (?x) extended (ignore white space) (?-...) unset option(s) - The following are recognized only at the very start of a pattern or - after one of the newline or \R options with similar syntax. More than - one of them may appear. + The following are recognized only at the very start of a pattern or af- + ter one of the newline or \R options with similar syntax. More than one + of them may appear. (*LIMIT_MATCH=d) set the match limit to d (decimal number) (*LIMIT_RECURSION=d) set the recursion limit to d (decimal number) @@ -7958,8 +7952,8 @@ OPTION SETTING NEWLINE CONVENTION - These are recognized only at the very start of the pattern or after - option settings with a similar syntax. + These are recognized only at the very start of the pattern or after op- + tion settings with a similar syntax. (*CR) carriage return only (*LF) linefeed only @@ -7970,8 +7964,8 @@ NEWLINE CONVENTION WHAT \R MATCHES - These are recognized only at the very start of the pattern or after - option setting with a similar syntax. + These are recognized only at the very start of the pattern or after op- + tion setting with a similar syntax. (*BSR_ANYCRLF) CR, LF, or CRLF (*BSR_UNICODE) any Unicode newline sequence @@ -8161,8 +8155,8 @@ UNICODE PROPERTY SUPPORT UTF-16, where they are used in pairs to encode codepoints with values greater than 0xFFFF. The code points that are encoded by UTF-16 pairs are available independently in the UTF-8 and UTF-32 encodings. (In - other words, the whole surrogate thing is a fudge for UTF-16 which - unfortunately messes up UTF-8 and UTF-32.) + other words, the whole surrogate thing is a fudge for UTF-16 which un- + fortunately messes up UTF-8 and UTF-32.) If an invalid UTF-8 string is passed to PCRE, an error return is given. At compile time, the only additional information is the offset to the @@ -8263,8 +8257,8 @@ UNICODE PROPERTY SUPPORT test characters of any code value, but, by default, the characters that PCRE recognizes as digits, spaces, or word characters remain the same set as in non-UTF mode, all with values less than 256. This remains - true even when PCRE is built to include Unicode property support, - because to do otherwise would slow down PCRE in many common cases. Note + true even when PCRE is built to include Unicode property support, be- + cause to do otherwise would slow down PCRE in many common cases. Note in particular that this applies to \b and \B, because they are defined in terms of \w and \W. If you really want to test for a wider sense of, say, "digit", you can use explicit Unicode property tests such as @@ -8354,27 +8348,26 @@ AVAILABILITY OF JIT SUPPORT If --enable-jit is set on an unsupported platform, compilation fails. A program that is linked with PCRE 8.20 or later can tell if JIT sup- - port is available by calling pcre_config() with the PCRE_CONFIG_JIT - option. The result is 1 when JIT is available, and 0 otherwise. How- - ever, a simple program does not need to check this in order to use JIT. - The normal API is implemented in a way that falls back to the interpre- - tive code if JIT is not available. For programs that need the best pos- - sible performance, there is also a "fast path" API that is JIT-spe- - cific. - - If your program may sometimes be linked with versions of PCRE that are - older than 8.20, but you want to use JIT when it is available, you can + port is available by calling pcre_config() with the PCRE_CONFIG_JIT op- + tion. The result is 1 when JIT is available, and 0 otherwise. However, + a simple program does not need to check this in order to use JIT. The + normal API is implemented in a way that falls back to the interpretive + code if JIT is not available. For programs that need the best possible + performance, there is also a "fast path" API that is JIT-specific. + + If your program may sometimes be linked with versions of PCRE that are + older than 8.20, but you want to use JIT when it is available, you can test the values of PCRE_MAJOR and PCRE_MINOR, or the existence of a JIT - macro such as PCRE_CONFIG_JIT, for compile-time control of your code. - Also beware that the pcre_jit_exec() function was not available at all - before 8.32, and may not be available at all if PCRE isn't compiled - with --enable-jit. See the "JIT FAST PATH API" section below for - details. + macro such as PCRE_CONFIG_JIT, for compile-time control of your code. + Also beware that the pcre_jit_exec() function was not available at all + before 8.32, and may not be available at all if PCRE isn't compiled + with --enable-jit. See the "JIT FAST PATH API" section below for de- + tails. SIMPLE USE OF JIT - You have to do two things to make use of the JIT support in the sim- + You have to do two things to make use of the JIT support in the sim- plest way: (1) Call pcre_study() with the PCRE_STUDY_JIT_COMPILE option for @@ -8382,18 +8375,18 @@ SIMPLE USE OF JIT pcre_exec(). (2) Use pcre_free_study() to free the pcre_extra block when it is - no longer needed, instead of just freeing it yourself. This - ensures that + no longer needed, instead of just freeing it yourself. This en- + sures that any JIT data is also freed. - For a program that may be linked with pre-8.20 versions of PCRE, you + For a program that may be linked with pre-8.20 versions of PCRE, you can insert #ifndef PCRE_STUDY_JIT_COMPILE #define PCRE_STUDY_JIT_COMPILE 0 #endif - so that no option is passed to pcre_study(), and then use something + so that no option is passed to pcre_study(), and then use something like this to free the study data: #ifdef PCRE_CONFIG_JIT @@ -8402,11 +8395,11 @@ SIMPLE USE OF JIT pcre_free(study_ptr); #endif - PCRE_STUDY_JIT_COMPILE requests the JIT compiler to generate code for - complete matches. If you want to run partial matches using the - PCRE_PARTIAL_HARD or PCRE_PARTIAL_SOFT options of pcre_exec(), you - should set one or both of the following options in addition to, or - instead of, PCRE_STUDY_JIT_COMPILE when you call pcre_study(): + PCRE_STUDY_JIT_COMPILE requests the JIT compiler to generate code for + complete matches. If you want to run partial matches using the + PCRE_PARTIAL_HARD or PCRE_PARTIAL_SOFT options of pcre_exec(), you + should set one or both of the following options in addition to, or in- + stead of, PCRE_STUDY_JIT_COMPILE when you call pcre_study(): PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE @@ -8420,44 +8413,44 @@ SIMPLE USE OF JIT pcre_exec(...) #endif - but as described in the "JIT FAST PATH API" section below this assumes + but as described in the "JIT FAST PATH API" section below this assumes version 8.32 and later are compiled with --enable-jit, which may break. - The JIT compiler generates different optimized code for each of the - three modes (normal, soft partial, hard partial). When pcre_exec() is - called, the appropriate code is run if it is available. Otherwise, the + The JIT compiler generates different optimized code for each of the + three modes (normal, soft partial, hard partial). When pcre_exec() is + called, the appropriate code is run if it is available. Otherwise, the pattern is matched using interpretive code. - In some circumstances you may need to call additional functions. These - are described in the section entitled "Controlling the JIT stack" - below. - - If JIT support is not available, PCRE_STUDY_JIT_COMPILE etc. are - ignored, and no JIT data is created. Otherwise, the compiled pattern is - passed to the JIT compiler, which turns it into machine code that exe- - cutes much faster than the normal interpretive code. When pcre_exec() - is passed a pcre_extra block containing a pointer to JIT code of the - appropriate mode (normal or hard/soft partial), it obeys that code - instead of running the interpreter. The result is identical, but the - compiled JIT code runs much faster. - - There are some pcre_exec() options that are not supported for JIT exe- - cution. There are also some pattern items that JIT cannot handle. - Details are given below. In both cases, execution automatically falls - back to the interpretive code. If you want to know whether JIT was - actually used for a particular match, you should arrange for a JIT - callback function to be set up as described in the section entitled - "Controlling the JIT stack" below, even if you do not need to supply a - non-default JIT stack. Such a callback function is called whenever JIT - code is about to be obeyed. If the execution options are not right for - JIT execution, the callback function is not obeyed. - - If the JIT compiler finds an unsupported item, no JIT data is gener- - ated. You can find out if JIT execution is available after studying a - pattern by calling pcre_fullinfo() with the PCRE_INFO_JIT option. A - result of 1 means that JIT compilation was successful. A result of 0 + In some circumstances you may need to call additional functions. These + are described in the section entitled "Controlling the JIT stack" be- + low. + + If JIT support is not available, PCRE_STUDY_JIT_COMPILE etc. are ig- + nored, and no JIT data is created. Otherwise, the compiled pattern is + passed to the JIT compiler, which turns it into machine code that exe- + cutes much faster than the normal interpretive code. When pcre_exec() + is passed a pcre_extra block containing a pointer to JIT code of the + appropriate mode (normal or hard/soft partial), it obeys that code in- + stead of running the interpreter. The result is identical, but the com- + piled JIT code runs much faster. + + There are some pcre_exec() options that are not supported for JIT exe- + cution. There are also some pattern items that JIT cannot handle. De- + tails are given below. In both cases, execution automatically falls + back to the interpretive code. If you want to know whether JIT was ac- + tually used for a particular match, you should arrange for a JIT call- + back function to be set up as described in the section entitled "Con- + trolling the JIT stack" below, even if you do not need to supply a non- + default JIT stack. Such a callback function is called whenever JIT code + is about to be obeyed. If the execution options are not right for JIT + execution, the callback function is not obeyed. + + If the JIT compiler finds an unsupported item, no JIT data is gener- + ated. You can find out if JIT execution is available after studying a + pattern by calling pcre_fullinfo() with the PCRE_INFO_JIT option. A re- + sult of 1 means that JIT compilation was successful. A result of 0 means that JIT support is not available, or the pattern was not studied - with PCRE_STUDY_JIT_COMPILE etc., or the JIT compiler was not able to + with PCRE_STUDY_JIT_COMPILE etc., or the JIT compiler was not able to handle the pattern. Once a pattern has been studied, with or without JIT, it can be used as @@ -8466,77 +8459,77 @@ SIMPLE USE OF JIT UNSUPPORTED OPTIONS AND PATTERN ITEMS - The only pcre_exec() options that are supported for JIT execution are + The only pcre_exec() options that are supported for JIT execution are PCRE_NO_UTF8_CHECK, PCRE_NO_UTF16_CHECK, PCRE_NO_UTF32_CHECK, PCRE_NOT- - BOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART, PCRE_PAR- + BOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NOTEMPTY_ATSTART, PCRE_PAR- TIAL_HARD, and PCRE_PARTIAL_SOFT. - The only unsupported pattern items are \C (match a single data unit) - when running in a UTF mode, and a callout immediately before an asser- + The only unsupported pattern items are \C (match a single data unit) + when running in a UTF mode, and a callout immediately before an asser- tion condition in a conditional group. RETURN VALUES FROM JIT EXECUTION - When a pattern is matched using JIT execution, the return values are - the same as those given by the interpretive pcre_exec() code, with the - addition of one new error code: PCRE_ERROR_JIT_STACKLIMIT. This means - that the memory used for the JIT stack was insufficient. See "Control- + When a pattern is matched using JIT execution, the return values are + the same as those given by the interpretive pcre_exec() code, with the + addition of one new error code: PCRE_ERROR_JIT_STACKLIMIT. This means + that the memory used for the JIT stack was insufficient. See "Control- ling the JIT stack" below for a discussion of JIT stack usage. For com- - patibility with the interpretive pcre_exec() code, no more than two- - thirds of the ovector argument is used for passing back captured sub- + patibility with the interpretive pcre_exec() code, no more than two- + thirds of the ovector argument is used for passing back captured sub- strings. - The error code PCRE_ERROR_MATCHLIMIT is returned by the JIT code if - searching a very large pattern tree goes on for too long, as it is in - the same circumstance when JIT is not used, but the details of exactly - what is counted are not the same. The PCRE_ERROR_RECURSIONLIMIT error + The error code PCRE_ERROR_MATCHLIMIT is returned by the JIT code if + searching a very large pattern tree goes on for too long, as it is in + the same circumstance when JIT is not used, but the details of exactly + what is counted are not the same. The PCRE_ERROR_RECURSIONLIMIT error code is never returned by JIT execution. SAVING AND RESTORING COMPILED PATTERNS - The code that is generated by the JIT compiler is architecture-spe- - cific, and is also position dependent. For those reasons it cannot be - saved (in a file or database) and restored later like the bytecode and - other data of a compiled pattern. Saving and restoring compiled pat- - terns is not something many people do. More detail about this facility - is given in the pcreprecompile documentation. It should be possible to - run pcre_study() on a saved and restored pattern, and thereby recreate - the JIT data, but because JIT compilation uses significant resources, - it is probably not worth doing this; you might as well recompile the + The code that is generated by the JIT compiler is architecture-spe- + cific, and is also position dependent. For those reasons it cannot be + saved (in a file or database) and restored later like the bytecode and + other data of a compiled pattern. Saving and restoring compiled pat- + terns is not something many people do. More detail about this facility + is given in the pcreprecompile documentation. It should be possible to + run pcre_study() on a saved and restored pattern, and thereby recreate + the JIT data, but because JIT compilation uses significant resources, + it is probably not worth doing this; you might as well recompile the original pattern. CONTROLLING THE JIT STACK When the compiled JIT code runs, it needs a block of memory to use as a - stack. By default, it uses 32K on the machine stack. However, some - large or complicated patterns need more than this. The error - PCRE_ERROR_JIT_STACKLIMIT is given when there is not enough stack. - Three functions are provided for managing blocks of memory for use as - JIT stacks. There is further discussion about the use of JIT stacks in - the section entitled "JIT stack FAQ" below. - - The pcre_jit_stack_alloc() function creates a JIT stack. Its arguments - are a starting size and a maximum size, and it returns a pointer to an - opaque structure of type pcre_jit_stack, or NULL if there is an error. - The pcre_jit_stack_free() function can be used to free a stack that is - no longer needed. (For the technically minded: the address space is - allocated by mmap or VirtualAlloc.) - - JIT uses far less memory for recursion than the interpretive code, and - a maximum stack size of 512K to 1M should be more than enough for any + stack. By default, it uses 32K on the machine stack. However, some + large or complicated patterns need more than this. The error PCRE_ER- + ROR_JIT_STACKLIMIT is given when there is not enough stack. Three func- + tions are provided for managing blocks of memory for use as JIT stacks. + There is further discussion about the use of JIT stacks in the section + entitled "JIT stack FAQ" below. + + The pcre_jit_stack_alloc() function creates a JIT stack. Its arguments + are a starting size and a maximum size, and it returns a pointer to an + opaque structure of type pcre_jit_stack, or NULL if there is an error. + The pcre_jit_stack_free() function can be used to free a stack that is + no longer needed. (For the technically minded: the address space is al- + located by mmap or VirtualAlloc.) + + JIT uses far less memory for recursion than the interpretive code, and + a maximum stack size of 512K to 1M should be more than enough for any pattern. - The pcre_assign_jit_stack() function specifies which stack JIT code + The pcre_assign_jit_stack() function specifies which stack JIT code should use. Its arguments are as follows: pcre_extra *extra pcre_jit_callback callback void *data - The extra argument must be the result of studying a pattern with + The extra argument must be the result of studying a pattern with PCRE_STUDY_JIT_COMPILE etc. There are three cases for the values of the other two options: @@ -8553,29 +8546,29 @@ CONTROLLING THE JIT STACK return value must be a valid JIT stack, the result of calling pcre_jit_stack_alloc(). - A callback function is obeyed whenever JIT code is about to be run; it - is not obeyed when pcre_exec() is called with options that are incom- + A callback function is obeyed whenever JIT code is about to be run; it + is not obeyed when pcre_exec() is called with options that are incom- patible for JIT execution. A callback function can therefore be used to - determine whether a match operation was executed by JIT or by the - interpreter. + determine whether a match operation was executed by JIT or by the in- + terpreter. You may safely use the same JIT stack for more than one pattern (either - by assigning directly or by callback), as long as the patterns are all - matched sequentially in the same thread. In a multithread application, - if you do not specify a JIT stack, or if you assign or pass back NULL - from a callback, that is thread-safe, because each thread has its own - machine stack. However, if you assign or pass back a non-NULL JIT - stack, this must be a different stack for each thread so that the - application is thread-safe. - - Strictly speaking, even more is allowed. You can assign the same non- - NULL stack to any number of patterns as long as they are not used for - matching by multiple threads at the same time. For example, you can - assign the same stack to all compiled patterns, and use a global mutex - in the callback to wait until the stack is available for use. However, + by assigning directly or by callback), as long as the patterns are all + matched sequentially in the same thread. In a multithread application, + if you do not specify a JIT stack, or if you assign or pass back NULL + from a callback, that is thread-safe, because each thread has its own + machine stack. However, if you assign or pass back a non-NULL JIT + stack, this must be a different stack for each thread so that the ap- + plication is thread-safe. + + Strictly speaking, even more is allowed. You can assign the same non- + NULL stack to any number of patterns as long as they are not used for + matching by multiple threads at the same time. For example, you can as- + sign the same stack to all compiled patterns, and use a global mutex in + the callback to wait until the stack is available for use. However, this is an inefficient solution, and not recommended. - This is a suggestion for how a multithreaded program that needs to set + This is a suggestion for how a multithreaded program that needs to set up non-default JIT stacks might operate: During thread initalization @@ -8587,83 +8580,83 @@ CONTROLLING THE JIT STACK Use a one-line callback function return thread_local_var - All the functions described in this section do nothing if JIT is not - available, and pcre_assign_jit_stack() does nothing unless the extra - argument is non-NULL and points to a pcre_extra block that is the - result of a successful study with PCRE_STUDY_JIT_COMPILE etc. + All the functions described in this section do nothing if JIT is not + available, and pcre_assign_jit_stack() does nothing unless the extra + argument is non-NULL and points to a pcre_extra block that is the re- + sult of a successful study with PCRE_STUDY_JIT_COMPILE etc. JIT STACK FAQ (1) Why do we need JIT stacks? - PCRE (and JIT) is a recursive, depth-first engine, so it needs a stack - where the local data of the current node is pushed before checking its + PCRE (and JIT) is a recursive, depth-first engine, so it needs a stack + where the local data of the current node is pushed before checking its child nodes. Allocating real machine stack on some platforms is diffi- cult. For example, the stack chain needs to be updated every time if we - extend the stack on PowerPC. Although it is possible, its updating + extend the stack on PowerPC. Although it is possible, its updating time overhead decreases performance. So we do the recursion in memory. (2) Why don't we simply allocate blocks of memory with malloc()? - Modern operating systems have a nice feature: they can reserve an - address space instead of allocating memory. We can safely allocate mem- - ory pages inside this address space, so the stack could grow without - moving memory data (this is important because of pointers). Thus we can - allocate 1M address space, and use only a single memory page (usually - 4K) if that is enough. However, we can still grow up to 1M anytime if + Modern operating systems have a nice feature: they can reserve an ad- + dress space instead of allocating memory. We can safely allocate memory + pages inside this address space, so the stack could grow without moving + memory data (this is important because of pointers). Thus we can allo- + cate 1M address space, and use only a single memory page (usually 4K) + if that is enough. However, we can still grow up to 1M anytime if needed. (3) Who "owns" a JIT stack? The owner of the stack is the user program, not the JIT studied pattern - or anything else. The user program must ensure that if a stack is used - by pcre_exec(), (that is, it is assigned to the pattern currently run- + or anything else. The user program must ensure that if a stack is used + by pcre_exec(), (that is, it is assigned to the pattern currently run- ning), that stack must not be used by any other threads (to avoid over- writing the same memory area). The best practice for multithreaded pro- - grams is to allocate a stack for each thread, and return this stack + grams is to allocate a stack for each thread, and return this stack through the JIT callback function. (4) When should a JIT stack be freed? You can free a JIT stack at any time, as long as it will not be used by - pcre_exec() again. When you assign the stack to a pattern, only a - pointer is set. There is no reference counting or any other magic. You - can free the patterns and stacks in any order, anytime. Just do not - call pcre_exec() with a pattern pointing to an already freed stack, as - that will cause SEGFAULT. (Also, do not free a stack currently used by - pcre_exec() in another thread). You can also replace the stack for a - pattern at any time. You can even free the previous stack before - assigning a replacement. - - (5) Should I allocate/free a stack every time before/after calling + pcre_exec() again. When you assign the stack to a pattern, only a + pointer is set. There is no reference counting or any other magic. You + can free the patterns and stacks in any order, anytime. Just do not + call pcre_exec() with a pattern pointing to an already freed stack, as + that will cause SEGFAULT. (Also, do not free a stack currently used by + pcre_exec() in another thread). You can also replace the stack for a + pattern at any time. You can even free the previous stack before as- + signing a replacement. + + (5) Should I allocate/free a stack every time before/after calling pcre_exec()? - No, because this is too costly in terms of resources. However, you - could implement some clever idea which release the stack if it is not - used in let's say two minutes. The JIT callback can help to achieve + No, because this is too costly in terms of resources. However, you + could implement some clever idea which release the stack if it is not + used in let's say two minutes. The JIT callback can help to achieve this without keeping a list of the currently JIT studied patterns. - (6) OK, the stack is for long term memory allocation. But what happens - if a pattern causes stack overflow with a stack of 1M? Is that 1M kept + (6) OK, the stack is for long term memory allocation. But what happens + if a pattern causes stack overflow with a stack of 1M? Is that 1M kept until the stack is freed? - Especially on embedded sytems, it might be a good idea to release mem- - ory sometimes without freeing the stack. There is no API for this at - the moment. Probably a function call which returns with the currently - allocated memory for any stack and another which allows releasing mem- + Especially on embedded sytems, it might be a good idea to release mem- + ory sometimes without freeing the stack. There is no API for this at + the moment. Probably a function call which returns with the currently + allocated memory for any stack and another which allows releasing mem- ory (shrinking the stack) would be a good idea if someone needs this. (7) This is too much of a headache. Isn't there any better solution for JIT stack handling? - No, thanks to Windows. If POSIX threads were used everywhere, we could + No, thanks to Windows. If POSIX threads were used everywhere, we could throw out this complicated API. EXAMPLE CODE - This is a single-threaded example that specifies a JIT stack without + This is a single-threaded example that specifies a JIT stack without using a callback. int rc; @@ -8687,56 +8680,56 @@ EXAMPLE CODE JIT FAST PATH API - Because the API described above falls back to interpreted execution + Because the API described above falls back to interpreted execution when JIT is not available, it is convenient for programs that are writ- - ten for general use in many environments. However, calling JIT via - pcre_exec() does have a performance impact. Programs that are written - for use where JIT is known to be available, and which need the best - possible performance, can instead use a "fast path" API to call JIT - execution directly instead of calling pcre_exec() (obviously only for + ten for general use in many environments. However, calling JIT via + pcre_exec() does have a performance impact. Programs that are written + for use where JIT is known to be available, and which need the best + possible performance, can instead use a "fast path" API to call JIT ex- + ecution directly instead of calling pcre_exec() (obviously only for patterns that have been successfully studied by JIT). - The fast path function is called pcre_jit_exec(), and it takes exactly - the same arguments as pcre_exec(), plus one additional argument that - must point to a JIT stack. The JIT stack arrangements described above + The fast path function is called pcre_jit_exec(), and it takes exactly + the same arguments as pcre_exec(), plus one additional argument that + must point to a JIT stack. The JIT stack arrangements described above do not apply. The return values are the same as for pcre_exec(). - When you call pcre_exec(), as well as testing for invalid options, a + When you call pcre_exec(), as well as testing for invalid options, a number of other sanity checks are performed on the arguments. For exam- - ple, if the subject pointer is NULL, or its length is negative, an - immediate error is given. Also, unless PCRE_NO_UTF[8|16|32] is set, a - UTF subject string is tested for validity. In the interests of speed, - these checks do not happen on the JIT fast path, and if invalid data is + ple, if the subject pointer is NULL, or its length is negative, an im- + mediate error is given. Also, unless PCRE_NO_UTF[8|16|32] is set, a UTF + subject string is tested for validity. In the interests of speed, these + checks do not happen on the JIT fast path, and if invalid data is passed, the result is undefined. - Bypassing the sanity checks and the pcre_exec() wrapping can give + Bypassing the sanity checks and the pcre_exec() wrapping can give speedups of more than 10%. - Note that the pcre_jit_exec() function is not available in versions of - PCRE before 8.32 (released in November 2012). If you need to support + Note that the pcre_jit_exec() function is not available in versions of + PCRE before 8.32 (released in November 2012). If you need to support versions that old you must either use the slower pcre_exec(), or switch - between the two codepaths by checking the values of PCRE_MAJOR and + between the two codepaths by checking the values of PCRE_MAJOR and PCRE_MINOR. - Due to an unfortunate implementation oversight, even in versions 8.32 - and later there will be no pcre_jit_exec() stub function defined when - PCRE is compiled with --disable-jit, which is the default, and there's - no way to detect whether PCRE was compiled with --enable-jit via a + Due to an unfortunate implementation oversight, even in versions 8.32 + and later there will be no pcre_jit_exec() stub function defined when + PCRE is compiled with --disable-jit, which is the default, and there's + no way to detect whether PCRE was compiled with --enable-jit via a macro. - If you need to support versions older than 8.32, or versions that may - not build with --enable-jit, you must either use the slower + If you need to support versions older than 8.32, or versions that may + not build with --enable-jit, you must either use the slower pcre_exec(), or switch between the two codepaths by checking the values of PCRE_MAJOR and PCRE_MINOR. - Switching between the two by checking the version assumes that all the - versions being targeted are built with --enable-jit. To also support + Switching between the two by checking the version assumes that all the + versions being targeted are built with --enable-jit. To also support builds that may use --disable-jit either pcre_exec() must be used, or a compile-time check for JIT via pcre_config() (which assumes the runtime - environment will be the same), or as the Git project decided to do, + environment will be the same), or as the Git project decided to do, simply assume that pcre_jit_exec() is present in 8.32 or later unless a - compile-time flag is provided, see the "grep: un-break building with - PCRE >= 8.32 without --enable-jit" commit in git.git for an example of + compile-time flag is provided, see the "grep: un-break building with + PCRE >= 8.32 without --enable-jit" commit in git.git for an example of that. @@ -8782,11 +8775,11 @@ PARTIAL MATCHING IN PCRE If the application sees the user's keystrokes one by one, and can check that what has been typed so far is potentially valid, it is able to - raise an error as soon as a mistake is made, by beeping and not - reflecting the character that has been typed, for example. This immedi- - ate feedback is likely to be a better user interface than a check that - is delayed until the entire string has been entered. Partial matching - can also be useful when the subject string is very long and is not all + raise an error as soon as a mistake is made, by beeping and not re- + flecting the character that has been typed, for example. This immediate + feedback is likely to be a better user interface than a check that is + delayed until the entire string has been entered. Partial matching can + also be useful when the subject string is very long and is not all available at once. PCRE supports partial matching by means of the PCRE_PARTIAL_SOFT and @@ -8862,8 +8855,8 @@ PARTIAL MATCHING USING pcre_exec() OR pcre[16|32]_exec() If PCRE_PARTIAL_SOFT is set when pcre_exec() or pcre[16|32]_exec() identifies a partial match, the partial match is remembered, but match- ing continues as normal, and other alternatives in the pattern are - tried. If no complete match can be found, PCRE_ERROR_PARTIAL is - returned instead of PCRE_ERROR_NOMATCH. + tried. If no complete match can be found, PCRE_ERROR_PARTIAL is re- + turned instead of PCRE_ERROR_NOMATCH. This option is "soft" because it prefers a complete match over a par- tial match. All the various matching items in a pattern behave as if @@ -8949,8 +8942,8 @@ PARTIAL MATCHING USING pcre_dfa_exec() OR pcre[16|32]_dfa_exec() Because the DFA functions always search for all possible matches, and there is no difference between greedy and ungreedy repetition, their behaviour is different from the standard functions when PCRE_PAR- - TIAL_HARD is set. Consider the string "dog" matched against the - ungreedy pattern shown above: + TIAL_HARD is set. Consider the string "dog" matched against the un- + greedy pattern shown above: /dog(sbody)??/ @@ -9029,9 +9022,9 @@ MULTI-SEGMENT MATCHING WITH pcre_dfa_exec() OR pcre[16|32]_dfa_exec() and calling the function again with the same compiled regular expres- sion, this time setting the PCRE_DFA_RESTART option. You must pass the same working space as before, because this is where details of the pre- - vious partial match are stored. Here is an example using pcretest, - using the \R escape sequence to set the PCRE_DFA_RESTART option (\D - specifies the use of the DFA matching function): + vious partial match are stored. Here is an example using pcretest, us- + ing the \R escape sequence to set the PCRE_DFA_RESTART option (\D spec- + ifies the use of the DFA matching function): re> /^\d?\d(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d\d$/ data> 23ja\P\D @@ -9047,11 +9040,11 @@ MULTI-SEGMENT MATCHING WITH pcre_dfa_exec() OR pcre[16|32]_dfa_exec() to. That means that, for an unanchored pattern, if a continued match fails, - it is not possible to try again at a new starting point. All this - facility is capable of doing is continuing with the previous match - attempt. In the previous example, if the second set of data is "ug23" - the result is no match, even though there would be a match for "aug23" - if the entire string were given at once. Depending on the application, + it is not possible to try again at a new starting point. All this fa- + cility is capable of doing is continuing with the previous match at- + tempt. In the previous example, if the second set of data is "ug23" the + result is no match, even though there would be a match for "aug23" if + the entire string were given at once. Depending on the application, this may or may not be what you want. The only way to allow for start- ing again at the next character is to retain the matched part of the subject and try a new complete match. @@ -9100,8 +9093,8 @@ ISSUES WITH MULTI-SEGMENT MATCHING 1. If the pattern contains a test for the beginning of a line, you need to pass the PCRE_NOTBOL option when the subject string for any call - does start at the beginning of a line. There is also a PCRE_NOTEOL - option, but in practice when doing multi-segment matching you should be + does start at the beginning of a line. There is also a PCRE_NOTEOL op- + tion, but in practice when doing multi-segment matching you should be using PCRE_PARTIAL_HARD, which includes the effect of PCRE_NOTEOL. 2. Lookbehind assertions that have already been obeyed are catered for @@ -9213,8 +9206,8 @@ ISSUES WITH MULTI-SEGMENT MATCHING 1234|ABCD where no string can be a partial match for both alternatives. This is - not a problem if a standard matching function is used, because the - entire match has to be rerun each time: + not a problem if a standard matching function is used, because the en- + tire match has to be rerun each time: re> /1234|3789/ data> ABC123\P\P @@ -9264,10 +9257,10 @@ SAVING AND RE-USING PRECOMPILED PCRE PATTERNS If you save compiled patterns to a file, you can copy them to a differ- ent host and run them there. If the two hosts have different endianness - (byte order), you should run the pcre[16|32]_pat- - tern_to_host_byte_order() function on the new host before trying to - match the pattern. The matching functions return PCRE_ERROR_BADENDIAN- - NESS if they detect a pattern with the wrong endianness. + (byte order), you should run the pcre[16|32]_pattern_to_host_byte_or- + der() function on the new host before trying to match the pattern. The + matching functions return PCRE_ERROR_BADENDIANNESS if they detect a + pattern with the wrong endianness. Compiling regular expressions with one version of PCRE for use with a different version is not guaranteed to work and may cause crashes, and @@ -9282,8 +9275,8 @@ SAVING A COMPILED PATTERN find the length of this block in bytes by calling pcre[16|32]_fullinfo() with an argument of PCRE_INFO_SIZE. You can then save the data in any appropriate manner. Here is sample code for the - 8-bit library that compiles a pattern and writes it to a file. It - assumes that the variable fd refers to a file that is open for output: + 8-bit library that compiles a pattern and writes it to a file. It as- + sumes that the variable fd refers to a file that is open for output: int erroroffset, rc, size; char *error; @@ -9298,14 +9291,14 @@ SAVING A COMPILED PATTERN In this example, the bytes that comprise the compiled pattern are copied exactly. Note that this is binary data that may contain any of - the 256 possible byte values. On systems that make a distinction - between binary and non-binary data, be sure that the file is opened for + the 256 possible byte values. On systems that make a distinction be- + tween binary and non-binary data, be sure that the file is opened for binary output. If you want to write more than one pattern to a file, you will have to devise a way of separating them. For binary data, preceding each pat- - tern with its length is probably the most straightforward approach. - Another possibility is to write out the data in hexadecimal instead of + tern with its length is probably the most straightforward approach. An- + other possibility is to write out the data in hexadecimal instead of binary, one pattern to a line. Saving compiled patterns in a file is only one possible way of storing @@ -9324,8 +9317,8 @@ SAVING A COMPILED PATTERN study data, and this is what you must save (not the pcre[16|32]_extra block itself). The length of the study data can be obtained by calling pcre[16|32]_fullinfo() with an argument of PCRE_INFO_STUDYSIZE. Remem- - ber to check that pcre[16|32]_study() did return a non-NULL value - before trying to save the study data. + ber to check that pcre[16|32]_study() did return a non-NULL value be- + fore trying to save the study data. RE-USING A PRECOMPILED PATTERN @@ -9354,18 +9347,18 @@ RE-USING A PRECOMPILED PATTERN If you saved study data with the compiled pattern, you need to create your own pcre[16|32]_extra data block and set the study_data field to - point to the reloaded study data. You must also set the - PCRE_EXTRA_STUDY_DATA bit in the flags field to indicate that study - data is present. Then pass the pcre[16|32]_extra block to the matching - function in the usual way. If the pattern was studied for just-in-time - optimization, that data cannot be saved, and so is lost by a - save/restore cycle. + point to the reloaded study data. You must also set the PCRE_EX- + TRA_STUDY_DATA bit in the flags field to indicate that study data is + present. Then pass the pcre[16|32]_extra block to the matching function + in the usual way. If the pattern was studied for just-in-time optimiza- + tion, that data cannot be saved, and so is lost by a save/restore cy- + cle. COMPATIBILITY WITH DIFFERENT PCRE RELEASES - In general, it is safest to recompile all saved patterns when you - update to a new PCRE release, though not all updates actually require + In general, it is safest to recompile all saved patterns when you up- + date to a new PCRE release, though not all updates actually require this. @@ -9454,8 +9447,8 @@ STACK USAGE AT RUN TIME stack. In some environments the default process stack is quite small, and if it runs out the result is often SIGSEGV. This issue is probably the most frequently raised problem with PCRE. Rewriting your pattern - can often help. The pcrestack documentation discusses this issue in - detail. + can often help. The pcrestack documentation discusses this issue in de- + tail. PROCESSING TIME @@ -9466,8 +9459,8 @@ PROCESSING TIME (a|e|i|o|u). In general, the simplest construction that provides the required behaviour is usually the most efficient. Jeffrey Friedl's book contains a lot of useful general discussion about optimizing regular - expressions for efficient performance. This document contains a few - observations about PCRE. + expressions for efficient performance. This document contains a few ob- + servations about PCRE. Using Unicode character properties (the \p, \P, and \X escapes) is slow, because PCRE has to use a multi-stage table lookup whenever it @@ -9516,8 +9509,8 @@ PROCESSING TIME 2, 3, or 4 times, and for each of those cases other than 0 or 4, the + repeats can match different numbers of times.) When the remainder of the pattern is such that the entire match is going to fail, PCRE has in - principle to try every possible variation, and this can take an - extremely long time, even for relatively short strings. + principle to try every possible variation, and this can take an ex- + tremely long time, even for relatively short strings. An optimization catches some of the more simple cases such as @@ -9580,8 +9573,8 @@ DESCRIPTION This set of functions provides a POSIX-style API for the PCRE regular expression 8-bit library. See the pcreapi documentation for a descrip- tion of PCRE's native API, which contains much additional functional- - ity. There is no POSIX-style wrapper for PCRE's 16-bit and 32-bit - library. + ity. There is no POSIX-style wrapper for PCRE's 16-bit and 32-bit li- + brary. The functions described here are just wrapper functions that ultimately call the PCRE native API. Their prototypes are defined in the @@ -9610,12 +9603,12 @@ DESCRIPTION even less compatible. The header for these functions is supplied as pcreposix.h to avoid any - potential clash with other POSIX libraries. It can, of course, be - renamed or aliased as regex.h, which is the "correct" name. It provides + potential clash with other POSIX libraries. It can, of course, be re- + named or aliased as regex.h, which is the "correct" name. It provides two structure types, regex_t for compiled internal forms, and reg- match_t for returning captured substrings. It also defines some con- - stants whose names start with "REG_"; these are used for setting - options and identifying error codes. + stants whose names start with "REG_"; these are used for setting op- + tions and identifying error codes. COMPILING A PATTERN @@ -9676,8 +9669,8 @@ COMPILING A PATTERN Note that REG_UTF8 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 PCRE default - semantics. In particular, the way it handles newline characters in the + function. This means the the regex is compiled with PCRE default se- + mantics. In particular, the way it handles newline characters in the subject string is the Perl way, not the POSIX way. Note that setting PCRE_MULTILINE has only some of the effects specified for REG_NEWLINE. It does not affect the way newlines are matched by . (they are not) or @@ -9780,9 +9773,9 @@ MATCHING A PATTERN 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" - failure code. + A successful match yields a zero return; various error codes are de- + fined in the header file, of which REG_NOMATCH is the "expected" fail- + ure code. ERROR MESSAGES @@ -9790,9 +9783,9 @@ 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 should have arisen from the use of that structure. A message terminated - by a binary zero is placed in errbuf. The length of the message, - including the zero, is limited to errbuf_size. The yield of the func- - tion is the size of buffer needed to hold the whole message. + by a binary zero is placed in errbuf. The length of the message, in- + cluding the zero, is limited to errbuf_size. The yield of the function + is the size of buffer needed to hold the whole message. MEMORY USAGE @@ -9909,15 +9902,15 @@ MATCHING INTERFACE ignored. CAVEAT: An optional sub-pattern that does not exist in the matched - string is assigned the empty string. Therefore, the following will - return false (because the empty string is not a valid number): + string is assigned the empty string. Therefore, the following will re- + turn false (because the empty string is not a valid number): int number; pcrecpp::RE::FullMatch("abc", "[a-z]+(\\d+)?", &number); The matching interface supports at most 16 arguments per call. If you - need more, consider using the more general interface - pcrecpp::RE::DoMatch. See pcrecpp.h for the signature for DoMatch. + need more, consider using the more general interface pcrecpp::RE::Do- + Match. See pcrecpp.h for the signature for DoMatch. NOTE: Do not use no_arg, which is used internally to mark the end of a list of optional arguments, as a placeholder for missing arguments, as @@ -9982,10 +9975,10 @@ UTF-8 AND THE MATCHING INTERFACE PASSING MODIFIERS TO THE REGULAR EXPRESSION ENGINE - PCRE defines some modifiers to change the behavior of the regular - expression engine. The C++ wrapper defines an auxiliary class, - RE_Options, as a vehicle to pass such modifiers to a RE class. Cur- - rently, the following modifiers are supported: + PCRE defines some modifiers to change the behavior of the regular ex- + pression engine. The C++ wrapper defines an auxiliary class, RE_Op- + tions, as a vehicle to pass such modifiers to a RE class. Currently, + the following modifiers are supported: modifier description Perl corresponding @@ -10007,8 +10000,8 @@ PASSING MODIFIERS TO THE REGULAR EXPRESSION ENGINE API reference page. For each modifier, there are two member functions whose name is made - out of the modifier in lowercase, without the "PCRE_" prefix. For - instance, PCRE_CASELESS is handled by + out of the modifier in lowercase, without the "PCRE_" prefix. For in- + stance, PCRE_CASELESS is handled by bool caseless() @@ -10089,12 +10082,12 @@ SCANNING TEXT INCREMENTALLY ...; } - Each successful call to "Consume" will set "var/value", and also - advance "input" so it points past the matched text. + Each successful call to "Consume" will set "var/value", and also ad- + vance "input" so it points past the matched text. - The "FindAndConsume" operation is similar to "Consume" but does not - anchor your match at the beginning of the string. For example, you - could extract all words from a string by repeatedly calling + The "FindAndConsume" operation is similar to "Consume" but does not an- + chor your match at the beginning of the string. For example, you could + extract all words from a string by repeatedly calling pcrecpp::RE("(\\w+)").FindAndConsume(&input, &word) @@ -10138,8 +10131,8 @@ REPLACING PARTS OF STRINGS string s = "yabba dabba doo"; pcrecpp::RE("b+").GlobalReplace("d", &s); - will leave "s" containing "yada dada doo". It returns the number of - replacements made. + will leave "s" containing "yada dada doo". It returns the number of re- + placements made. Extract is like Replace, except that if the pattern matches, "rewrite" is copied into "out" (an additional argument) with substitutions. The @@ -10196,8 +10189,8 @@ PCRE SAMPLE PROGRAM If PCRE is installed elsewhere, you may need to add additional options to the command line. For example, on a Unix-like system that has PCRE - installed in /usr/local, you can compile the demonstration program - using a command like this: + installed in /usr/local, you can compile the demonstration program us- + ing a command like this: gcc -o pcredemo -I/usr/local/include pcredemo.c \ -L/usr/local/lib -lpcre @@ -10205,8 +10198,8 @@ PCRE SAMPLE PROGRAM In a Windows environment, if you want to statically link the program against a non-dll pcre.a file, you must uncomment the line that defines PCRE_STATIC before including pcre.h, because otherwise the pcre_mal- - loc() and pcre_free() exported functions will be declared - __declspec(dllimport), with unwanted results. + loc() and pcre_free() exported functions will be declared __de- + clspec(dllimport), with unwanted results. Once you have compiled and linked the demonstration program, you can run simple tests like this: @@ -10215,16 +10208,16 @@ PCRE SAMPLE PROGRAM ./pcredemo -g 'cat|dog' 'the dog sat on the cat' Note that there is a much more comprehensive test program, called - pcretest, which supports many more facilities for testing regular - expressions and both PCRE libraries. The pcredemo program is provided - as a simple coding example. + pcretest, which supports many more facilities for testing regular ex- + pressions and both PCRE libraries. The pcredemo program is provided as + a simple coding example. If you try to run pcredemo when PCRE is not installed in the standard library directory, you may get an error like this on some operating systems (e.g. Solaris): - ld.so.1: a.out: fatal: libpcre.so.0: open failed: No such file or - directory + ld.so.1: a.out: fatal: libpcre.so.0: open failed: No such file or di- + rectory This is caused by the way shared library support works on those sys- tems. You need to add @@ -10259,8 +10252,8 @@ SIZE AND OTHER LIMITATIONS never in practice be relevant. The maximum length of a compiled pattern is approximately 64K data - units (bytes for the 8-bit library, 16-bit units for the 16-bit - library, and 32-bit units for the 32-bit library) if PCRE is compiled + units (bytes for the 8-bit library, 16-bit units for the 16-bit li- + brary, and 32-bit units for the 32-bit library) if PCRE is compiled with the default internal linkage size, which is 2 bytes for the 8-bit and 16-bit libraries, and 4 bytes for the 32-bit library. If you want to process regular expressions that are truly enormous, you can compile @@ -10280,10 +10273,10 @@ SIZE AND OTHER LIMITATIONS the default is 250. There is a limit to the number of forward references to subsequent sub- - patterns of around 200,000. Repeated forward references with fixed - upper limits, for example, (?2){0,100} when subpattern number 2 is to - the right, are included in the count. There is no limit to the number - of backward references. + patterns of around 200,000. Repeated forward references with fixed up- + per limits, for example, (?2){0,100} when subpattern number 2 is to the + right, are included in the count. There is no limit to the number of + backward references. The maximum length of name for a named subpattern is 32 characters, and the maximum number of named subpatterns is 10000. @@ -10329,8 +10322,8 @@ PCRE DISCUSSION OF STACK USAGE back up and try a different alternative if the first one fails. As matching proceeds deeper and deeper into the tree of possibilities, the recursion depth increases. The match() function is also called in other - circumstances, for example, whenever a parenthesized sub-pattern is - entered, and in certain cases of repetition. + circumstances, for example, whenever a parenthesized sub-pattern is en- + tered, and in certain cases of repetition. Not all calls of match() increase the recursion depth; for an item such as a* it may be called several times at the same level, after matching @@ -10344,8 +10337,8 @@ PCRE DISCUSSION OF STACK USAGE PCRE_STUDY_JIT_COMPILE option, and just-in-time compiling was success- ful, and the options passed to pcre[16|32]_exec() were not incompati- ble, the matching process uses the JIT-compiled code instead of the - match() function. In this case, the memory requirements are handled - entirely differently. See the pcrejit documentation for details. + match() function. In this case, the memory requirements are handled en- + tirely differently. See the pcrejit documentation for details. The pcre[16|32]_dfa_exec() function operates in an entirely different way, and uses recursion only when there is a regular expression recur- @@ -10376,8 +10369,8 @@ PCRE DISCUSSION OF STACK USAGE end of the data, and is the kind of pattern that might be used when processing an XML file. Each iteration of the outer parentheses matches either one character that is not "<" or a "<" that is not followed by - "inet". However, each time a parenthesis is processed, a recursion - occurs, so this formulation uses a stack frame for each matched charac- + "inet". However, each time a parenthesis is processed, a recursion oc- + curs, so this formulation uses a stack frame for each matched charac- ter. For a long string, a lot of stack is required. Consider now this rewritten pattern, which matches exactly the same strings: @@ -10434,11 +10427,11 @@ PCRE DISCUSSION OF STACK USAGE Obtaining an estimate of stack usage - The actual amount of stack used per recursion can vary quite a lot, - depending on the compiler that was used to build PCRE and the optimiza- + The actual amount of stack used per recursion can vary quite a lot, de- + pending on the compiler that was used to build PCRE and the optimiza- tion or debugging options that were set for it. The rule of thumb value - of 500 bytes mentioned above may be larger or smaller than what is - actually needed. A better approximation can be obtained by running this + of 500 bytes mentioned above may be larger or smaller than what is ac- + tually needed. A better approximation can be obtained by running this command: pcretest -m -C @@ -10452,9 +10445,9 @@ PCRE DISCUSSION OF STACK USAGE The value is approximate because some recursions need a bit more (up to perhaps 16 more bytes). - If the above command is given when PCRE is compiled to use the heap - instead of the stack for recursion, the value that is output is the - size of each block that is obtained from the heap. + If the above command is given when PCRE is compiled to use the heap in- + stead of the stack for recursion, the value that is output is the size + of each block that is obtained from the heap. Changing stack size in Unix-like systems @@ -10482,8 +10475,8 @@ PCRE DISCUSSION OF STACK USAGE Using setrlimit(), as described above, should also work on Mac OS X. It is also possible to set a stack size when linking a program. There is a - discussion about stack sizes in Mac OS X at this web site: - http://developer.apple.com/qa/qa2005/qa1419.html. + discussion about stack sizes in Mac OS X at this web site: http://de- + veloper.apple.com/qa/qa2005/qa1419.html. AUTHOR diff --git a/pcre/doc/pcreapi.3 b/pcre/doc/pcreapi.3 index 6e7c7c6e3ce..d79217818a6 100644 --- a/pcre/doc/pcreapi.3 +++ b/pcre/doc/pcreapi.3 @@ -1227,7 +1227,7 @@ the following negative numbers: PCRE_ERROR_BADOPTION the value of \fIwhat\fP was invalid PCRE_ERROR_UNSET the requested field is not set .sp -The "magic number" is placed at the start of each compiled pattern as an simple +The "magic number" is placed at the start of each compiled pattern as a simple check against passing an arbitrary memory pointer. The endianness error can occur if a compiled pattern is saved and reloaded on a different host. Here is a typical call of \fBpcre_fullinfo()\fP, to obtain the length of the compiled @@ -1294,7 +1294,7 @@ returned. For anchored patterns, -2 is returned. .sp Return the value of the first data unit (non-UTF character) of any matched string in the situation where PCRE_INFO_FIRSTCHARACTERFLAGS returns 1; -otherwise return 0. The fourth argument should point to an \fBuint_t\fP +otherwise return 0. The fourth argument should point to a \fBuint_t\fP variable. .P In the 8-bit library, the value is always less than 256. In the 16-bit library @@ -1560,7 +1560,7 @@ returned value 1 (with "z" returned from PCRE_INFO_REQUIREDCHAR), but for .sp Return the value of the rightmost literal data unit that must exist in any matched string, other than at its start, if such a value has been recorded. The -fourth argument should point to an \fBuint32_t\fP variable. If there is no such +fourth argument should point to a \fBuint32_t\fP variable. If there is no such value, 0 is returned. . . diff --git a/pcre/doc/pcregrep.txt b/pcre/doc/pcregrep.txt index 97d9a7bd379..0c873c7a863 100644 --- a/pcre/doc/pcregrep.txt +++ b/pcre/doc/pcregrep.txt @@ -26,8 +26,8 @@ DESCRIPTION If you attempt to use delimiters (for example, by surrounding a pattern with slashes, as is common in Perl scripts), they are interpreted as part of the pattern. Quotes can of course be used to delimit patterns - on the command line because they are interpreted by the shell, and - indeed quotes are required if a pattern contains white space or shell + on the command line because they are interpreted by the shell, and in- + deed quotes are required if a pattern contains white space or shell metacharacters. The first argument that follows any option settings is treated as the @@ -37,8 +37,8 @@ DESCRIPTION or an argument pattern must be provided. If no files are specified, pcregrep reads the standard input. The stan- - dard input can also be referenced by a name consisting of a single - hyphen. For example: + dard input can also be referenced by a name consisting of a single hy- + phen. For example: pcregrep some-pattern /file1 - /file3 @@ -47,8 +47,8 @@ DESCRIPTION the start of each line, followed by a colon. However, there are options that can change how pcregrep behaves. In particular, the -M option makes it possible to search for patterns that span line boundaries. - What defines a line boundary is controlled by the -N (--newline) - option. + What defines a line boundary is controlled by the -N (--newline) op- + tion. The amount of memory used for buffering files that are being scanned is controlled by a parameter that can be set by the --buffer-size option. @@ -66,12 +66,12 @@ DESCRIPTION By default, as soon as one pattern matches a line, no further patterns are considered. However, if --colour (or --color) is used to colour the matching substrings, or if --only-matching, --file-offsets, or --line- - offsets is used to output only the part of the line that matched - (either shown literally, or as an offset), scanning resumes immediately + offsets is used to output only the part of the line that matched (ei- + ther shown literally, or as an offset), scanning resumes immediately following the match, so that further matches on the same line can be - found. If there are multiple patterns, they are all tried on the - remainder of the line, but patterns that follow the one that matched - are not tried on the earlier part of the line. + found. If there are multiple patterns, they are all tried on the re- + mainder of the line, but patterns that follow the one that matched are + not tried on the earlier part of the line. This behaviour means that the order in which multiple patterns are specified can affect the output when one of the above options is used. @@ -80,11 +80,11 @@ DESCRIPTION overlap). Patterns that can match an empty string are accepted, but empty string - matches are never recognized. An example is the pattern - "(super)?(man)?", in which all components are optional. This pattern - finds all occurrences of both "super" and "man"; the output differs - from matching with "super|man" when only the matching substrings are - being shown. + matches are never recognized. An example is the pattern "(su- + per)?(man)?", in which all components are optional. This pattern finds + all occurrences of both "super" and "man"; the output differs from + matching with "super|man" when only the matching substrings are being + shown. If the LC_ALL or LC_CTYPE environment variable is set, pcregrep uses the value to set a locale when calling the PCRE library. The --locale @@ -105,9 +105,9 @@ BINARY FILES By default, a file that contains a binary zero byte within the first 1024 bytes is identified as a binary file, and is processed specially. - (GNU grep also identifies binary files in this manner.) See the - --binary-files option for a means of changing the way binary files are - handled. + (GNU grep also identifies binary files in this manner.) See the --bi- + nary-files option for a means of changing the way binary files are han- + dled. OPTIONS @@ -151,16 +151,16 @@ OPTIONS --binary-files=word Specify how binary files are to be processed. If the word is - "binary" (the default), pattern matching is performed on - binary files, but the only output is "Binary file <name> + "binary" (the default), pattern matching is performed on bi- + nary files, but the only output is "Binary file <name> matches" when a match succeeds. If the word is "text", which is equivalent to the -a or --text option, binary files are processed in the same way as any other file. In this case, when a match succeeds, the output may be binary garbage, which can have nasty effects if sent to a terminal. If the - word is "without-match", which is equivalent to the -I - option, binary files are not processed at all; they are - assumed not to be of interest. + word is "without-match", which is equivalent to the -I op- + tion, binary files are not processed at all; they are assumed + not to be of interest. --buffer-size=number Set the parameter that controls how much memory is used for @@ -201,15 +201,15 @@ OPTIONS ronment variable PCREGREP_COLOUR or PCREGREP_COLOR. The value of this variable should be a string of two numbers, separated by a semicolon. They are copied directly into the control - string for setting colour on a terminal, so it is your - responsibility to ensure that they make sense. If neither of + string for setting colour on a terminal, so it is your re- + sponsibility to ensure that they make sense. If neither of the environment variables is set, the default is "1;31", which gives red. -D action, --devices=action - If an input path is not a regular file or a directory, - "action" specifies how it is to be processed. Valid values - are "read" (the default) or "skip" (silently skip the path). + If an input path is not a regular file or a directory, "ac- + tion" specifies how it is to be processed. Valid values are + "read" (the default) or "skip" (silently skip the path). -d action, --directories=action If an input path is a directory, "action" specifies how it is @@ -218,8 +218,8 @@ OPTIONS "recurse" (equivalent to the -r option), or "skip" (silently skip the path, the default in Windows environments). In the "read" case, directories are read as if they were ordinary - files. In some operating systems the effect of reading a - directory like this is an immediate end-of-file; in others it + files. In some operating systems the effect of reading a di- + rectory like this is an immediate end-of-file; in others it may provoke an error. -e pattern, --regex=pattern, --regexp=pattern @@ -249,8 +249,8 @@ OPTIONS whether listed on the command line, obtained from --file- list, or by scanning a directory. The pattern is a PCRE regu- lar expression, and is matched against the final component of - the file name, not the entire path. The -F, -w, and -x - options do not apply to this pattern. The option may be given + the file name, not the entire path. The -F, -w, and -x op- + tions do not apply to this pattern. The option may be given any number of times in order to specify multiple patterns. If a file name matches both an --include and an --exclude pat- tern, it is excluded. There is no short form for this option. @@ -264,29 +264,29 @@ OPTIONS --exclude-dir=pattern Directories whose names match the pattern are skipped without - being processed, whatever the setting of the --recursive - option. This applies to all directories, whether listed on - the command line, obtained from --file-list, or by scanning a + being processed, whatever the setting of the --recursive op- + tion. This applies to all directories, whether listed on the + command line, obtained from --file-list, or by scanning a parent directory. The pattern is a PCRE regular expression, and is matched against the final component of the directory name, not the entire path. The -F, -w, and -x options do not apply to this pattern. The option may be given any number of times in order to specify more than one pattern. If a direc- - tory matches both --include-dir and --exclude-dir, it is - excluded. There is no short form for this option. + tory matches both --include-dir and --exclude-dir, it is ex- + cluded. There is no short form for this option. -F, --fixed-strings Interpret each data-matching pattern as a list of fixed - strings, separated by newlines, instead of as a regular - expression. What constitutes a newline for this purpose is - controlled by the --newline option. The -w (match as a word) - and -x (match whole line) options can be used with -F. They - apply to each of the fixed strings. A line is selected if any + strings, separated by newlines, instead of as a regular ex- + pression. What constitutes a newline for this purpose is con- + trolled by the --newline option. The -w (match as a word) and + -x (match whole line) options can be used with -F. They ap- + ply to each of the fixed strings. A line is selected if any of the fixed strings are found in it (subject to -w or -x, if present). This option applies only to the patterns that are matched against the contents of files; it does not apply to - patterns specified by any of the --include or --exclude - options. + patterns specified by any of the --include or --exclude op- + tions. -f filename, --file=filename Read patterns from the file, one per line, and match them @@ -358,16 +358,16 @@ OPTIONS --include=pattern If any --include patterns are specified, the only files that are processed are those that match one of the patterns (and - do not match an --exclude pattern). This option does not - affect directories, but it applies to all files, whether - listed on the command line, obtained from --file-list, or by - scanning a directory. The pattern is a PCRE regular expres- - sion, and is matched against the final component of the file - name, not the entire path. The -F, -w, and -x options do not - apply to this pattern. The option may be given any number of - times. If a file name matches both an --include and an - --exclude pattern, it is excluded. There is no short form - for this option. + do not match an --exclude pattern). This option does not af- + fect directories, but it applies to all files, whether listed + on the command line, obtained from --file-list, or by scan- + ning a directory. The pattern is a PCRE regular expression, + and is matched against the final component of the file name, + not the entire path. The -F, -w, and -x options do not apply + to this pattern. The option may be given any number of times. + If a file name matches both an --include and an --exclude + pattern, it is excluded. There is no short form for this op- + tion. --include-from=filename Treat each non-empty line of the file as the data for an @@ -381,8 +381,8 @@ OPTIONS tories that are processed are those that match one of the patterns (and do not match an --exclude-dir pattern). This applies to all directories, whether listed on the command - line, obtained from --file-list, or by scanning a parent - directory. The pattern is a PCRE regular expression, and is + line, obtained from --file-list, or by scanning a parent di- + rectory. The pattern is a PCRE regular expression, and is matched against the final component of the directory name, not the entire path. The -F, -w, and -x options do not apply to this pattern. The option may be given any number of times. @@ -413,9 +413,9 @@ OPTIONS --line-buffered When this option is given, 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 pcregrep can - determine that it is reading from a terminal (which is cur- + by line, and the output is flushed after each write. By de- + fault, input is read in large chunks, unless pcregrep can de- + termine that it is reading from a terminal (which is cur- rently 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 @@ -437,9 +437,9 @@ OPTIONS --locale=locale-name This option specifies a locale to be used for pattern match- ing. It overrides the value in the LC_ALL or LC_CTYPE envi- - ronment variables. If no locale is specified, the PCRE - library's default (usually the "C" locale) is used. There is - no short form for this option. + ronment variables. If no locale is specified, the PCRE li- + brary's default (usually the "C" locale) is used. There is no + short form for this option. --match-limit=number Processing some regular expression patterns can require a @@ -447,26 +447,26 @@ OPTIONS gram crash if not enough is available. Other patterns may take a very long time to search for all possible matching strings. The pcre_exec() function that is called by pcregrep - to do the matching has two parameters that can limit the - resources that it uses. + to do the matching has two parameters that can limit the re- + sources that it uses. - The --match-limit option provides a means of limiting - resource usage when processing patterns that are not going to + The --match-limit option provides a means of limiting re- + source usage 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 nested unlimited repeats. Internally, PCRE uses a func- - tion called match() which it calls repeatedly (sometimes - recursively). The limit set by --match-limit is imposed on - the number of times this function is called during a match, - which has the effect of limiting the amount of backtracking - that can take place. + tion called match() which it calls repeatedly (sometimes re- + cursively). The limit set by --match-limit is imposed on the + number of times this function is called during a match, which + has the effect of limiting the amount of backtracking that + can take place. The --recursion-limit option is similar to --match-limit, but instead of limiting the total number of times that match() is called, it limits the depth of recursive calls, which in turn limits the amount of memory that can be used. The recursion - depth is a smaller number than the total number of calls, - because not all calls to match() are recursive. This limit is + depth is a smaller number than the total number of calls, be- + cause not all calls to match() are recursive. 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- @@ -494,30 +494,30 @@ OPTIONS is read line by line (see --line-buffered.) -N newline-type, --newline=newline-type - The PCRE library supports five different conventions for - indicating the ends of lines. They are the single-character - sequences CR (carriage return) and LF (linefeed), the two- - character sequence CRLF, an "anycrlf" convention, which rec- - ognizes any of the preceding three types, and an "any" con- - vention, in which any Unicode line ending sequence is assumed - to end a line. The Unicode sequences are the three just men- + The PCRE library supports five different conventions for in- + dicating the ends of lines. They are the single-character se- + quences CR (carriage return) and LF (linefeed), the two-char- + acter sequence CRLF, an "anycrlf" convention, which recog- + nizes any of the preceding three types, and an "any" conven- + tion, in which any Unicode line ending sequence is assumed to + end a line. The Unicode sequences are the three just men- tioned, plus VT (vertical tab, U+000B), FF (form feed, U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS (paragraph separator, U+2029). - When the PCRE library is built, a default line-ending - sequence is specified. This is normally the standard - sequence for the operating system. Unless otherwise specified - by this option, pcregrep uses the library's default. The - possible values for this option are CR, LF, CRLF, ANYCRLF, or - ANY. This makes it possible to use pcregrep to scan files - that have come from other environments without having to mod- - ify their line endings. If the data that is being scanned - does not agree with the convention set by this option, pcre- - grep may behave in strange ways. Note that this option does - not apply to files specified by the -f, --exclude-from, or - --include-from options, which are expected to use the operat- - ing system's standard newline sequence. + When the PCRE library is built, a default line-ending se- + quence is specified. This is normally the standard sequence + for the operating system. Unless otherwise specified by this + option, pcregrep uses the library's default. The possible + values for this option are CR, LF, CRLF, ANYCRLF, or ANY. + This makes it possible to use pcregrep to scan files that + have come from other environments without having to modify + their line endings. If the data that is being scanned does + not agree with the convention set by this option, pcregrep + may behave in strange ways. Note that this option does not + apply to files specified by the -f, --exclude-from, or --in- + clude-from options, which are expected to use the operating + system's standard newline sequence. -n, --line-number Precede each output line by its line number in the file, fol- @@ -538,12 +538,12 @@ OPTIONS is, the -A, -B, and -C options are ignored. If there is more than one match in a line, each of them is shown separately. If -o is combined with -v (invert the sense of the match to - find non-matching lines), no output is generated, but the - return code is set appropriately. If the matched portion of - the line is empty, nothing is output unless the file name or - line number are being printed, in which case they are shown - on an otherwise empty line. This option is mutually exclusive - with --file-offsets and --line-offsets. + find non-matching lines), no output is generated, but the re- + turn code is set appropriately. If the matched portion of the + line is empty, nothing is output unless the file name or line + number are being printed, in which case they are shown on an + otherwise empty line. This option is mutually exclusive with + --file-offsets and --line-offsets. -onumber, --only-matching=number Show only the part of the line that matched the capturing @@ -579,8 +579,8 @@ OPTIONS it contains, taking note of any --include and --exclude set- tings. By default, a directory is read as a normal file; in some operating systems this gives an immediate end-of-file. - This option is a shorthand for setting the -d option to - "recurse". + This option is a shorthand for setting the -d option to "re- + curse". --recursion-limit=number See --match-limit above. @@ -626,10 +626,10 @@ OPTIONS ENVIRONMENT VARIABLES - The environment variables LC_ALL and LC_CTYPE are examined, in that - order, for a locale. The first one that is set is used. This can be - overridden by the --locale option. If no locale is set, the PCRE - library's default (usually the "C" locale) is used. + The environment variables LC_ALL and LC_CTYPE are examined, in that or- + der, for a locale. The first one that is set is used. This can be over- + ridden by the --locale option. If no locale is set, the PCRE library's + default (usually the "C" locale) is used. NEWLINES @@ -640,8 +640,8 @@ NEWLINES ever newline sequences they have in the input. However, the setting of this option does not affect the interpretation of files specified by the -f, --exclude-from, or --include-from options, which are assumed to - use the operating system's standard newline sequence, nor does it - affect the way in which pcregrep writes informational messages to the + use the operating system's standard newline sequence, nor does it af- + fect the way in which pcregrep writes informational messages to the standard error and output streams. For these it uses the string "\n" to indicate newlines, relying on the C I/O library to convert this to an appropriate sequence. @@ -687,13 +687,13 @@ OPTIONS WITH DATA --file /some/file Note, however, that if you want to supply a file name beginning with ~ - as data in a shell command, and have the shell expand ~ to a home - directory, you must separate the file name from the option, because the + as data in a shell command, and have the shell expand ~ to a home di- + rectory, you must separate the file name from the option, because the shell does not treat ~ specially unless it is at the start of an item. The exceptions to the above are the --colour (or --color) and --only- - matching options, for which the data is optional. If one of these - options does have data, it must be given in the first form, using an + matching options, for which the data is optional. If one of these op- + tions does have data, it must be given in the first form, using an equals character. Otherwise pcregrep will assume that it has no data. @@ -702,14 +702,14 @@ MATCHING ERRORS It is possible to supply a regular expression that takes a very long time to fail to match certain lines. Such patterns normally involve nested indefinite repeats, for example: (a+)*\d when matched against a - line of a's with no final digit. The PCRE matching function has a - resource limit that causes it to abort in these circumstances. If this + line of a's with no final digit. The PCRE matching function has a re- + source limit that causes it to abort in these circumstances. If this happens, pcregrep outputs an error message and the line that caused the problem to the standard error stream. If there are more than 20 such errors, pcregrep gives up. - The --match-limit option of pcregrep can be used to set the overall - resource limit; there is a second option called --recursion-limit that + The --match-limit option of pcregrep can be used to set the overall re- + source limit; there is a second option called --recursion-limit that sets a limit on the amount of memory (usually stack) that is used (see the discussion of these options above). diff --git a/pcre/doc/pcretest.1 b/pcre/doc/pcretest.1 index ea7457c03d0..fec964d782a 100644 --- a/pcre/doc/pcretest.1 +++ b/pcre/doc/pcretest.1 @@ -1,4 +1,4 @@ -.TH PCRETEST 1 "23 February 2017" "PCRE 8.41" +.TH PCRETEST 1 "10 February 2020" "PCRE 8.44" .SH NAME pcretest - a program for testing Perl-compatible regular expressions. .SH SYNOPSIS @@ -78,21 +78,19 @@ the 16-bit library, or \fBpcre32_xx\fP when using the 32-bit library". .rs .TP 10 \fB-8\fP -If both the 8-bit library has been built, this option causes the 8-bit library -to be used (which is the default); if the 8-bit library has not been built, -this option causes an error. +If the 8-bit library has been built, this option causes it to be used (this is +the default). If the 8-bit library has not been built, this option causes an +error. .TP 10 \fB-16\fP -If both the 8-bit or the 32-bit, and the 16-bit libraries have been built, this -option causes the 16-bit library to be used. If only the 16-bit library has been -built, this is the default (so has no effect). If only the 8-bit or the 32-bit -library has been built, this option causes an error. +If the 16-bit library has been built, this option causes it to be used. If only +the 16-bit library has been built, this is the default. If the 16-bit library +has not been built, this option causes an error. .TP 10 \fB-32\fP -If both the 8-bit or the 16-bit, and the 32-bit libraries have been built, this -option causes the 32-bit library to be used. If only the 32-bit library has been -built, this is the default (so has no effect). If only the 8-bit or the 16-bit -library has been built, this option causes an error. +If the 32-bit library has been built, this option causes it to be used. If only +the 32-bit library has been built, this is the default. If the 32-bit library +has not been built, this option causes an error. .TP 10 \fB-b\fP Behave as if each pattern has the \fB/B\fP (show byte code) modifier; the @@ -1155,6 +1153,6 @@ Cambridge CB2 3QH, England. .rs .sp .nf -Last updated: 23 February 2017 -Copyright (c) 1997-2017 University of Cambridge. +Last updated: 10 February 2020 +Copyright (c) 1997-2020 University of Cambridge. .fi diff --git a/pcre/doc/pcretest.txt b/pcre/doc/pcretest.txt index 6d7305cfe82..835ee58a46d 100644 --- a/pcre/doc/pcretest.txt +++ b/pcre/doc/pcretest.txt @@ -47,15 +47,15 @@ INPUT DATA FORMAT PCRE's 8-BIT, 16-BIT AND 32-BIT LIBRARIES From release 8.30, two separate PCRE libraries can be built. The origi- - nal one supports 8-bit character strings, whereas the newer 16-bit - library supports character strings encoded in 16-bit units. From - release 8.32, a third library can be built, supporting character - strings encoded in 32-bit units. The pcretest program can be used to - test all three libraries. However, it is itself still an 8-bit program, - reading 8-bit input and writing 8-bit output. When testing the 16-bit - or 32-bit library, the patterns and data strings are converted to 16- - or 32-bit format before being passed to the PCRE library functions. - Results are converted to 8-bit for output. + nal one supports 8-bit character strings, whereas the newer 16-bit li- + brary supports character strings encoded in 16-bit units. From release + 8.32, a third library can be built, supporting character strings en- + coded in 32-bit units. The pcretest program can be used to test all + three libraries. However, it is itself still an 8-bit program, reading + 8-bit input and writing 8-bit output. When testing the 16-bit or + 32-bit library, the patterns and data strings are converted to 16- or + 32-bit format before being passed to the PCRE library functions. Re- + sults are converted to 8-bit for output. References to functions and structures of the form pcre[16|32]_xx below mean "pcre_xx when using the 8-bit library, pcre16_xx when using the @@ -64,34 +64,31 @@ PCRE's 8-BIT, 16-BIT AND 32-BIT LIBRARIES COMMAND LINE OPTIONS - -8 If both the 8-bit library has been built, this option causes - the 8-bit library to be used (which is the default); if the - 8-bit library has not been built, this option causes an - error. + -8 If the 8-bit library has been built, this option causes it to + be used (this is the default). If the 8-bit library has not + been built, this option causes an error. - -16 If both the 8-bit or the 32-bit, and the 16-bit libraries - have been built, this option causes the 16-bit library to be - used. If only the 16-bit library has been built, this is the - default (so has no effect). If only the 8-bit or the 32-bit - library has been built, this option causes an error. + -16 If the 16-bit library has been built, this option causes it + to be used. If only the 16-bit library has been built, this + is the default. If the 16-bit library has not been built, + this option causes an error. - -32 If both the 8-bit or the 16-bit, and the 32-bit libraries - have been built, this option causes the 32-bit library to be - used. If only the 32-bit library has been built, this is the - default (so has no effect). If only the 8-bit or the 16-bit - library has been built, this option causes an error. + -32 If the 32-bit library has been built, this option causes it + to be used. If only the 32-bit library has been built, this + is the default. If the 32-bit library has not been built, + this option causes an error. - -b Behave as if each pattern has the /B (show byte code) modi- + -b Behave as if each pattern has the /B (show byte code) modi- fier; the internal form is output after compilation. -C Output the version number of the PCRE library, and all avail- - able information about the optional features that are - included, and then exit with zero exit code. All other - options are ignored. + able information about the optional features that are in- + cluded, and then exit with zero exit code. All other options + are ignored. - -C option Output information about a specific build-time option, then - exit. This functionality is intended for use in scripts such - as RunTest. The following options output the value and set + -C option Output information about a specific build-time option, then + exit. This functionality is intended for use in scripts such + as RunTest. The following options output the value and set the exit code as indicated: ebcdic-nl the code for LF (= NL) in an EBCDIC environment: @@ -107,7 +104,7 @@ COMMAND LINE OPTIONS ANYCRLF or ANY exit code is always 0 - The following options output 1 for true or 0 for false, and + The following options output 1 for true or 0 for false, and set the exit code to the same value: ebcdic compiled for an EBCDIC environment @@ -119,61 +116,61 @@ COMMAND LINE OPTIONS utf UTF-8 and/or UTF-16 and/or UTF-32 support is available - If an unknown option is given, an error message is output; + If an unknown option is given, an error message is output; the exit code is 0. - -d Behave as if each pattern has the /D (debug) modifier; the - internal form and information about the compiled pattern is + -d Behave as if each pattern has the /D (debug) modifier; the + internal form and information about the compiled pattern is output after compilation; -d is equivalent to -b -i. - -dfa Behave as if each data line contains the \D escape sequence; + -dfa Behave as if each data line contains the \D escape sequence; this causes the alternative matching function, - pcre[16|32]_dfa_exec(), to be used instead of the standard + pcre[16|32]_dfa_exec(), to be used instead of the standard pcre[16|32]_exec() function (more detail is given below). -help Output a brief summary these options and then exit. - -i Behave as if each pattern has the /I modifier; information + -i Behave as if each pattern has the /I modifier; information about the compiled pattern is given after compilation. - -M Behave as if each data line contains the \M escape sequence; - this causes PCRE to discover the minimum MATCH_LIMIT and - MATCH_LIMIT_RECURSION settings by calling pcre[16|32]_exec() + -M Behave as if each data line contains the \M escape sequence; + this causes PCRE to discover the minimum MATCH_LIMIT and + MATCH_LIMIT_RECURSION settings by calling pcre[16|32]_exec() repeatedly with different limits. - -m Output the size of each compiled pattern after it has been - compiled. This is equivalent to adding /M to each regular - expression. The size is given in bytes for both libraries. + -m Output the size of each compiled pattern after it has been + compiled. This is equivalent to adding /M to each regular ex- + pression. The size is given in bytes for both libraries. - -O Behave as if each pattern has the /O modifier, that is dis- + -O Behave as if each pattern has the /O modifier, that is dis- able auto-possessification for all patterns. - -o osize Set the number of elements in the output vector that is used - when calling pcre[16|32]_exec() or pcre[16|32]_dfa_exec() to - be osize. The default value is 45, which is enough for 14 + -o osize Set the number of elements in the output vector that is used + when calling pcre[16|32]_exec() or pcre[16|32]_dfa_exec() to + be osize. The default value is 45, which is enough for 14 capturing subexpressions for pcre[16|32]_exec() or 22 differ- - ent matches for pcre[16|32]_dfa_exec(). The vector size can - be changed for individual matching calls by including \O in + ent matches for pcre[16|32]_dfa_exec(). The vector size can + be changed for individual matching calls by including \O in the data line (see below). - -p Behave as if each pattern has the /P modifier; the POSIX - wrapper API is used to call PCRE. None of the other options - has any effect when -p is set. This option can be used only + -p Behave as if each pattern has the /P modifier; the POSIX + wrapper API is used to call PCRE. None of the other options + has any effect when -p is set. This option can be used only with the 8-bit library. - -q Do not output the version number of pcretest at the start of + -q Do not output the version number of pcretest at the start of execution. - -S size On Unix-like systems, set the size of the run-time stack to + -S size On Unix-like systems, set the size of the run-time stack to size megabytes. - -s or -s+ Behave as if each pattern has the /S modifier; in other - words, force each pattern to be studied. If -s+ is used, all - the JIT compile options are passed to pcre[16|32]_study(), - causing just-in-time optimization to be set up if it is - available, for both full and partial matching. Specific JIT + -s or -s+ Behave as if each pattern has the /S modifier; in other + words, force each pattern to be studied. If -s+ is used, all + the JIT compile options are passed to pcre[16|32]_study(), + causing just-in-time optimization to be set up if it is + available, for both full and partial matching. Specific JIT compile options can be selected by following -s+ with a digit - in the range 1 to 7, which selects the JIT compile modes as + in the range 1 to 7, which selects the JIT compile modes as follows: 1 normal match only @@ -183,119 +180,119 @@ COMMAND LINE OPTIONS 6 soft and hard partial match 7 all three modes (default) - If -s++ is used instead of -s+ (with or without a following - digit), the text "(JIT)" is added to the first output line + If -s++ is used instead of -s+ (with or without a following + digit), the text "(JIT)" is added to the first output line after a match or no match when JIT-compiled code was actually used. - Note that there are pattern options that can override -s, - either specifying no studying at all, or suppressing JIT com- - pilation. - - If the /I or /D option is present on a pattern (requesting - output about the compiled pattern), information about the - result of studying is not included when studying is caused - only by -s and neither -i nor -d is present on the command - line. This behaviour means that the output from tests that - are run with and without -s should be identical, except when - options that output information about the actual running of a - match are set. - - The -M, -t, and -tm options, which give information about - resources used, are likely to produce different output with - and without -s. Output may also differ if the /C option is + Note that there are pattern options that can override -s, ei- + ther specifying no studying at all, or suppressing JIT compi- + lation. + + If the /I or /D option is present on a pattern (requesting + output about the compiled pattern), information about the re- + sult of studying is not included when studying is caused only + by -s and neither -i nor -d is present on the command line. + This behaviour means that the output from tests that are run + with and without -s should be identical, except when options + that output information about the actual running of a match + are set. + + The -M, -t, and -tm options, which give information about re- + sources used, are likely to produce different output with and + without -s. Output may also differ if the /C option is present on an individual pattern. This uses callouts to trace - the the matching process, and this may be different between - studied and non-studied patterns. If the pattern contains - (*MARK) items there may also be differences, for the same + the the matching process, and this may be different between + studied and non-studied patterns. If the pattern contains + (*MARK) items there may also be differences, for the same reason. The -s command line option can be overridden for spe- - cific patterns that should never be studied (see the /S pat- + cific patterns that should never be studied (see the /S pat- tern modifier below). - -t Run each compile, study, and match many times with a timer, - and output the resulting times per compile, study, or match - (in milliseconds). Do not set -m with -t, because you will + -t Run each compile, study, and match many times with a timer, + and output the resulting times per compile, study, or match + (in milliseconds). Do not set -m with -t, because you will then get the size output a zillion times, and the timing will - be distorted. You can control the number of iterations that + be distorted. You can control the number of iterations that are used for timing by following -t with a number (as a sepa- - rate item on the command line). For example, "-t 1000" iter- + rate item on the command line). For example, "-t 1000" iter- ates 1000 times. The default is to iterate 500000 times. -tm This is like -t except that it times only the matching phase, not the compile or study phases. - -T -TM These behave like -t and -tm, but in addition, at the end of + -T -TM These behave like -t and -tm, but in addition, at the end of a run, the total times for all compiles, studies, and matches are output. DESCRIPTION - If pcretest is given two filename arguments, it reads from the first + If pcretest is given two filename arguments, it reads from the first and writes to the second. If it is given only one filename argument, it - reads from that file and writes to stdout. Otherwise, it reads from - stdin and writes to stdout, and prompts for each line of input, using + reads from that file and writes to stdout. Otherwise, it reads from + stdin and writes to stdout, and prompts for each line of input, using "re>" to prompt for regular expressions, and "data>" to prompt for data lines. - When pcretest is built, a configuration option can specify that it - should be linked with the libreadline library. When this is done, if + When pcretest is built, a configuration option can specify that it + should be linked with the libreadline library. When this is done, if the input is from a terminal, it is read using the readline() function. - This provides line-editing and history facilities. The output from the + This provides line-editing and history facilities. The output from the -help option states whether or not readline() will be used. The program handles any number of sets of input on a single input file. - Each set starts with a regular expression, and continues with any num- + Each set starts with a regular expression, and continues with any num- ber of data lines to be matched against that pattern. - Each data line is matched separately and independently. If you want to + Each data line is matched separately and independently. If you want to do multi-line matches, you have to use the \n escape sequence (or \r or \r\n, etc., depending on the newline setting) in a single line of input - to encode the newline sequences. There is no limit on the length of - data lines; the input buffer is automatically extended if it is too + to encode the newline sequences. There is no limit on the length of + data lines; the input buffer is automatically extended if it is too small. - An empty line signals the end of the data lines, at which point a new - regular expression is read. The regular expressions are given enclosed + An empty line signals the end of the data lines, at which point a new + regular expression is read. The regular expressions are given enclosed in any non-alphanumeric delimiters other than backslash, for example: /(a|bc)x+yz/ - White space before the initial delimiter is ignored. A regular expres- - sion may be continued over several input lines, in which case the new- - line characters are included within it. It is possible to include the + White space before the initial delimiter is ignored. A regular expres- + sion may be continued over several input lines, in which case the new- + line characters are included within it. It is possible to include the delimiter within the pattern by escaping it, for example /abc\/def/ - If you do so, the escape and the delimiter form part of the pattern, - but since delimiters are always non-alphanumeric, this does not affect - its interpretation. If the terminating delimiter is immediately fol- + If you do so, the escape and the delimiter form part of the pattern, + but since delimiters are always non-alphanumeric, this does not affect + its interpretation. If the terminating delimiter is immediately fol- lowed by a backslash, for example, /abc/\ - then a backslash is added to the end of the pattern. This is done to - provide a way of testing the error condition that arises if a pattern + then a backslash is added to the end of the pattern. This is done to + provide a way of testing the error condition that arises if a pattern finishes with a backslash, because /abc\/ - is interpreted as the first line of a pattern that starts with "abc/", + is interpreted as the first line of a pattern that starts with "abc/", causing pcretest to read the next line as a continuation of the regular expression. PATTERN MODIFIERS - A pattern may be followed by any number of modifiers, which are mostly - single characters, though some of these can be qualified by further - characters. Following Perl usage, these are referred to below as, for - example, "the /i modifier", even though the delimiter of the pattern - need not always be a slash, and no slash is used when writing modi- - fiers. White space may appear between the final pattern delimiter and - the first modifier, and between the modifiers themselves. For refer- - ence, here is a complete list of modifiers. They fall into several + A pattern may be followed by any number of modifiers, which are mostly + single characters, though some of these can be qualified by further + characters. Following Perl usage, these are referred to below as, for + example, "the /i modifier", even though the delimiter of the pattern + need not always be a slash, and no slash is used when writing modi- + fiers. White space may appear between the final pattern delimiter and + the first modifier, and between the modifiers themselves. For refer- + ence, here is a complete list of modifiers. They fall into several groups that are described in detail in the following sections. /8 set UTF mode @@ -347,8 +344,8 @@ PATTERN MODIFIERS Perl-compatible modifiers The /i, /m, /s, and /x modifiers set the PCRE_CASELESS, PCRE_MULTILINE, - PCRE_DOTALL, or PCRE_EXTENDED options, respectively, when - pcre[16|32]_compile() is called. These four modifier letters have the + PCRE_DOTALL, or PCRE_EXTENDED options, respectively, when + pcre[16|32]_compile() is called. These four modifier letters have the same effect as they do in Perl. For example: /caseless/i @@ -356,7 +353,7 @@ PATTERN MODIFIERS Modifiers for other PCRE options - The following table shows additional modifiers for setting PCRE com- + The following table shows additional modifiers for setting PCRE com- pile-time options that do not correspond to anything in Perl: /8 PCRE_UTF8 ) when using the 8-bit @@ -389,145 +386,145 @@ PATTERN MODIFIERS /<bsr_unicode> PCRE_BSR_UNICODE /<JS> PCRE_JAVASCRIPT_COMPAT - The modifiers that are enclosed in angle brackets are literal strings - as shown, including the angle brackets, but the letters within can be - in either case. This example sets multiline matching with CRLF as the + The modifiers that are enclosed in angle brackets are literal strings + as shown, including the angle brackets, but the letters within can be + in either case. This example sets multiline matching with CRLF as the line ending sequence: /^abc/m<CRLF> - As well as turning on the PCRE_UTF8/16/32 option, the /8 modifier - causes all non-printing characters in output strings to be printed - using the \x{hh...} notation. Otherwise, those less than 0x100 are out- - put in hex without the curly brackets. + As well as turning on the PCRE_UTF8/16/32 option, the /8 modifier + causes all non-printing characters in output strings to be printed us- + ing the \x{hh...} notation. Otherwise, those less than 0x100 are output + in hex without the curly brackets. - Full details of the PCRE options are given in the pcreapi documenta- + Full details of the PCRE options are given in the pcreapi documenta- tion. Finding all matches in a string - Searching for all possible matches within each subject string can be - requested by the /g or /G modifier. After finding a match, PCRE is + Searching for all possible matches within each subject string can be + requested by the /g or /G modifier. After finding a match, PCRE is called again to search the remainder of the subject string. The differ- ence between /g and /G is that the former uses the startoffset argument - to pcre[16|32]_exec() to start searching at a new point within the - entire string (which is in effect what Perl does), whereas the latter - passes over a shortened substring. This makes a difference to the - matching process if the pattern begins with a lookbehind assertion - (including \b or \B). - - If any call to pcre[16|32]_exec() in a /g or /G sequence matches an - empty string, the next call is done with the PCRE_NOTEMPTY_ATSTART and - PCRE_ANCHORED flags set in order to search for another, non-empty, - match at the same point. If this second match fails, the start offset - is advanced, and the normal match is retried. This imitates the way + to pcre[16|32]_exec() to start searching at a new point within the en- + tire string (which is in effect what Perl does), whereas the latter + passes over a shortened substring. This makes a difference to the + matching process if the pattern begins with a lookbehind assertion (in- + cluding \b or \B). + + If any call to pcre[16|32]_exec() in a /g or /G sequence matches an + empty string, the next call is done with the PCRE_NOTEMPTY_ATSTART and + PCRE_ANCHORED flags set in order to search for another, non-empty, + match at the same point. If this second 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() func- - tion. Normally, the start offset is advanced by one character, but if - the newline convention recognizes CRLF as a newline, and the current + tion. 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 is used. Other modifiers There are yet more modifiers for controlling the way pcretest operates. - The /+ modifier requests that as well as outputting the substring that - matched the entire pattern, pcretest 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. If the + modi- - fier appears twice, the same action is taken for captured substrings. - In each case the remainder is output on the following line with a plus - character following the capture number. Note that this modifier must - not immediately follow the /S modifier because /S+ and /S++ have other + The /+ modifier requests that as well as outputting the substring that + matched the entire pattern, pcretest should in addition output the re- + mainder of the subject string. This is useful for tests where the sub- + ject contains multiple copies of the same substring. If the + modifier + appears twice, the same action is taken for captured substrings. In + each case the remainder is output on the following line with a plus + character following the capture number. Note that this modifier must + not immediately follow the /S modifier because /S+ and /S++ have other meanings. - The /= modifier requests that the values of all potential captured - parentheses be output after a match. By default, only those up to the + The /= modifier requests that the values of all potential captured + 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 pcre[16|32]_exec()). Values in the offsets vector cor- - responding to higher numbers should be set to -1, and these are output - as "<unset>". This modifier gives a way of checking that this is hap- + responding to higher numbers should be set to -1, and these are output + as "<unset>". This modifier gives a way of checking that this is hap- pening. - The /B modifier is a debugging feature. It requests that pcretest out- - put a representation of the compiled code after compilation. Normally - this information contains length and offset values; however, if /Z is - also present, this data is replaced by spaces. This is a special fea- - ture for use in the automatic test scripts; it ensures that the same + The /B modifier is a debugging feature. It requests that pcretest out- + put a representation of the compiled code after compilation. Normally + this information contains length and offset values; however, if /Z is + also present, this data is replaced by spaces. This is a special fea- + ture for use in the automatic test scripts; it ensures that the same output is generated for different internal link sizes. - The /D modifier is a PCRE debugging feature, and is equivalent to /BI, + The /D modifier is a PCRE debugging feature, and is equivalent to /BI, that is, both the /B and the /I modifiers. - The /F modifier causes pcretest to flip the byte order of the 2-byte + The /F modifier causes pcretest to flip the byte order of the 2-byte and 4-byte fields in the compiled pattern. This facility is for testing - the feature in PCRE that allows it to execute patterns that were com- + the feature in PCRE that allows it to execute patterns that were com- piled on a host with a different endianness. This feature is not avail- - able when the POSIX interface to PCRE is being used, that is, when the + able when the POSIX interface to PCRE is being used, that is, when the /P pattern modifier is specified. See also the section about saving and reloading compiled patterns below. - The /I modifier requests that pcretest output information about the - compiled pattern (whether it is anchored, has a fixed first character, - and so on). It does this by calling pcre[16|32]_fullinfo() after com- - piling a pattern. If the pattern is studied, the results of that are + The /I modifier requests that pcretest output information about the + compiled pattern (whether it is anchored, has a fixed first character, + and so on). It does this by calling pcre[16|32]_fullinfo() after com- + piling a pattern. If the pattern is studied, the results of that are also output. In this output, the word "char" means a non-UTF character, - that is, the value of a single data item (8-bit, 16-bit, or 32-bit, - depending on the library that is being tested). - - The /K modifier requests pcretest to show names from backtracking con- - trol verbs that are returned from calls to pcre[16|32]_exec(). It - causes pcretest to create a pcre[16|32]_extra block if one has not - already been created by a call to pcre[16|32]_study(), and to set the - PCRE_EXTRA_MARK flag and the mark field within it, every time that - pcre[16|32]_exec() is called. If the variable that the mark field - points to is non-NULL for a match, non-match, or partial match, - pcretest prints the string to which it points. For a match, this is - shown on a line by itself, tagged with "MK:". For a non-match it is + that is, the value of a single data item (8-bit, 16-bit, or 32-bit, de- + pending on the library that is being tested). + + The /K modifier requests pcretest to show names from backtracking con- + trol verbs that are returned from calls to pcre[16|32]_exec(). It + causes pcretest to create a pcre[16|32]_extra block if one has not al- + ready been created by a call to pcre[16|32]_study(), and to set the + PCRE_EXTRA_MARK flag and the mark field within it, every time that + pcre[16|32]_exec() is called. If the variable that the mark field + points to is non-NULL for a match, non-match, or partial match, + pcretest prints the string to which it points. For a match, this is + shown on a line by itself, tagged with "MK:". For a non-match it is added to the message. - The /L modifier must be followed directly by the name of a locale, for + The /L modifier must be followed directly by the name of a locale, for example, /pattern/Lfr_FR For this reason, it must be the last modifier. The given locale is set, - pcre[16|32]_maketables() is called to build a set of character tables - for the locale, and this is then passed to pcre[16|32]_compile() when - compiling the regular expression. Without an /L (or /T) modifier, NULL - is passed as the tables pointer; that is, /L applies only to the - expression on which it appears. - - The /M modifier causes the size in bytes of the memory block used to - hold the compiled pattern to be output. This does not include the size - of the pcre[16|32] block; it is just the actual compiled data. If the + pcre[16|32]_maketables() is called to build a set of character tables + for the locale, and this is then passed to pcre[16|32]_compile() when + compiling the regular expression. Without an /L (or /T) modifier, NULL + is passed as the tables pointer; that is, /L applies only to the ex- + pression on which it appears. + + The /M modifier causes the size in bytes of the memory block used to + hold the compiled pattern to be output. This does not include the size + of the pcre[16|32] block; it is just the actual compiled data. If the pattern is successfully studied with the PCRE_STUDY_JIT_COMPILE option, the size of the JIT compiled code is also output. The /Q modifier is used to test the use of pcre_stack_guard. It must be - followed by '0' or '1', specifying the return code to be given from an - external function that is passed to PCRE and used for stack checking + followed by '0' or '1', specifying the return code to be given from an + external function that is passed to PCRE and used for stack checking during compilation (see the pcreapi documentation for details). - The /S modifier causes pcre[16|32]_study() to be called after the - expression has been compiled, and the results used when the expression - is matched. There are a number of qualifying characters that may follow + The /S modifier causes pcre[16|32]_study() to be called after the ex- + pression has been compiled, and the results used when the expression is + matched. There are a number of qualifying characters that may follow /S. They may appear in any order. If /S is followed by an exclamation mark, pcre[16|32]_study() is called - with the PCRE_STUDY_EXTRA_NEEDED option, causing it always to return a + with the PCRE_STUDY_EXTRA_NEEDED option, causing it always to return a pcre_extra block, even when studying discovers no useful information. If /S is followed by a second S character, it suppresses studying, even - if it was requested externally by the -s command line option. This - makes it possible to specify that certain patterns are always studied, + if it was requested externally by the -s command line option. This + makes it possible to specify that certain patterns are always studied, and others are never studied, independently of -s. This feature is used in the test files in a few cases where the output is different when the pattern is studied. - If the /S modifier is followed by a + character, the call to - pcre[16|32]_study() is made with all the JIT study options, requesting - just-in-time optimization support if it is available, for both normal - and partial matching. If you want to restrict the JIT compiling modes, + If the /S modifier is followed by a + character, the call to + pcre[16|32]_study() is made with all the JIT study options, requesting + just-in-time optimization support if it is available, for both normal + and partial matching. If you want to restrict the JIT compiling modes, you can follow /S+ with a digit in the range 1 to 7: 1 normal match only @@ -538,40 +535,40 @@ PATTERN MODIFIERS 7 all three modes (default) If /S++ is used instead of /S+ (with or without a following digit), the - text "(JIT)" is added to the first output line after a match or no + text "(JIT)" is added to the first output line after a match or no match when JIT-compiled code was actually used. - Note that there is also an independent /+ modifier; it must not be + Note that there is also an independent /+ modifier; it must not be given immediately after /S or /S+ because this will be misinterpreted. If JIT studying is successful, the compiled JIT code will automatically - be used when pcre[16|32]_exec() is run, except when incompatible run- - time options are specified. For more details, see the pcrejit documen- - tation. See also the \J escape sequence below for a way of setting the + be used when pcre[16|32]_exec() is run, except when incompatible run- + time options are specified. For more details, see the pcrejit documen- + tation. See also the \J escape sequence below for a way of setting the size of the JIT stack. - Finally, if /S is followed by a minus character, JIT compilation is - suppressed, even if it was requested externally by the -s command line - option. This makes it possible to specify that JIT is never to be used + Finally, if /S is followed by a minus character, JIT compilation is + suppressed, even if it was requested externally by the -s command line + option. This makes it possible to specify that JIT is never to be used for certain patterns. - The /T modifier must be followed by a single digit. It causes a spe- + The /T modifier must be followed by a single digit. It causes a spe- cific set of built-in character tables to be passed to pcre[16|32]_com- - pile(). It is used in the standard PCRE tests to check behaviour with + pile(). It is used in the standard PCRE tests to check behaviour with different character tables. The digit specifies the tables as follows: 0 the default ASCII tables, as distributed in pcre_chartables.c.dist 1 a set of tables defining ISO 8859 characters - In table 1, some characters whose codes are greater than 128 are iden- + In table 1, some characters whose codes are greater than 128 are iden- tified as letters, digits, spaces, etc. Using the POSIX wrapper API - The /P modifier causes pcretest to call PCRE via the POSIX wrapper API - rather than its native API. This supports only the 8-bit library. When - /P is set, the following modifiers set options for the regcomp() func- + The /P modifier causes pcretest to call PCRE via the POSIX wrapper API + rather than its native API. This supports only the 8-bit library. When + /P is set, the following modifiers set options for the regcomp() func- tion: /i REG_ICASE @@ -582,48 +579,48 @@ PATTERN MODIFIERS /W REG_UCP ) the POSIX standard /8 REG_UTF8 ) - The /+ modifier works as described above. All other modifiers are - ignored. + The /+ modifier works as described above. All other modifiers are ig- + nored. Locking out certain modifiers - PCRE can be compiled with or without support for certain features such - as UTF-8/16/32 or Unicode properties. Accordingly, the standard tests - are split up into a number of different files that are selected for - running depending on which features are available. When updating the + PCRE can be compiled with or without support for certain features such + as UTF-8/16/32 or Unicode properties. Accordingly, the standard tests + are split up into a number of different files that are selected for + running depending on which features are available. When updating the tests, it is all too easy to put a new test into the wrong file by mis- - take; for example, to put a test that requires UTF support into a file - that is used when it is not available. To help detect such mistakes as - early as possible, there is a facility for locking out specific modi- + take; for example, to put a test that requires UTF support into a file + that is used when it is not available. To help detect such mistakes as + early as possible, there is a facility for locking out specific modi- fiers. If an input line for pcretest starts with the string "< forbid " - the following sequence of characters is taken as a list of forbidden + the following sequence of characters is taken as a list of forbidden modifiers. For example, in the test files that must not use UTF or Uni- code property support, this line appears: < forbid 8W - This locks out the /8 and /W modifiers. An immediate error is given if - they are subsequently encountered. If the character string contains < - but not >, all the multi-character modifiers that begin with < are - locked out. Otherwise, such modifiers must be explicitly listed, for + This locks out the /8 and /W modifiers. An immediate error is given if + they are subsequently encountered. If the character string contains < + but not >, all the multi-character modifiers that begin with < are + locked out. Otherwise, such modifiers must be explicitly listed, for example: < forbid <JS><cr> There must be a single space between < and "forbid" for this feature to - be recognised. If there is not, the line is interpreted either as a - request to re-load a pre-compiled pattern (see "SAVING AND RELOADING - COMPILED PATTERNS" below) or, if there is a another < character, as a - pattern that uses < as its delimiter. + be recognised. If there is not, the line is interpreted either as a re- + quest to re-load a pre-compiled pattern (see "SAVING AND RELOADING COM- + PILED PATTERNS" below) or, if there is a another < character, as a pat- + tern that uses < as its delimiter. DATA LINES - Before each data line is passed to pcre[16|32]_exec(), leading and - trailing white space is removed, and it is then scanned for \ escapes. - Some of these are pretty esoteric features, intended for checking out - some of the more complicated features of PCRE. If you are just testing - "ordinary" regular expressions, you probably don't need any of these. + Before each data line is passed to pcre[16|32]_exec(), leading and + trailing white space is removed, and it is then scanned for \ escapes. + Some of these are pretty esoteric features, intended for checking out + some of the more complicated features of PCRE. If you are just testing + "ordinary" regular expressions, you probably don't need any of these. The following escapes are recognized: \a alarm (BEL, \x07) @@ -684,7 +681,7 @@ DATA LINES (any number of digits) \R pass the PCRE_DFA_RESTART option to pcre[16|32]_dfa_exec() \S output details of memory get/free calls during matching - \Y pass the PCRE_NO_START_OPTIMIZE option to + \Y pass the PCRE_NO_START_OPTIMIZE option to pcre[16|32]_exec() or pcre[16|32]_dfa_exec() \Z pass the PCRE_NOTEOL option to pcre[16|32]_exec() @@ -693,7 +690,7 @@ DATA LINES pcre[16|32]_exec() or pcre[16|32]_dfa_exec() \>dd start the match at offset dd (optional "-"; then any number of digits); this sets the startoffset - argument for pcre[16|32]_exec() or + argument for pcre[16|32]_exec() or pcre[16|32]_dfa_exec() \<cr> pass the PCRE_NEWLINE_CR option to pcre[16|32]_exec() or pcre[16|32]_dfa_exec() @@ -706,103 +703,102 @@ DATA LINES \<any> pass the PCRE_NEWLINE_ANY option to pcre[16|32]_exec() or pcre[16|32]_dfa_exec() - The use of \x{hh...} is not dependent on the use of the /8 modifier on - the pattern. It is recognized always. There may be any number of hexa- - decimal digits inside the braces; invalid values provoke error mes- + The use of \x{hh...} is not dependent on the use of the /8 modifier on + the pattern. It is recognized always. There may be any number of hexa- + decimal digits inside the braces; invalid values provoke error mes- sages. - Note that \xhh specifies one byte rather than one character in UTF-8 - mode; this makes it possible to construct invalid UTF-8 sequences for - testing purposes. On the other hand, \x{hh} is interpreted as a UTF-8 - character in UTF-8 mode, generating more than one byte if the value is - greater than 127. When testing the 8-bit library not in UTF-8 mode, + Note that \xhh specifies one byte rather than one character in UTF-8 + mode; this makes it possible to construct invalid UTF-8 sequences for + testing purposes. On the other hand, \x{hh} is interpreted as a UTF-8 + character in UTF-8 mode, generating more than one byte if the value is + greater than 127. When testing the 8-bit library not in UTF-8 mode, \x{hh} generates one byte for values less than 256, and causes an error for greater values. In UTF-16 mode, all 4-digit \x{hhhh} values are accepted. This makes it possible to construct invalid UTF-16 sequences for testing purposes. - In UTF-32 mode, all 4- to 8-digit \x{...} values are accepted. This - makes it possible to construct invalid UTF-32 sequences for testing + In UTF-32 mode, all 4- to 8-digit \x{...} values are accepted. This + makes it possible to construct invalid UTF-32 sequences for testing purposes. - The escapes that specify line ending sequences are literal strings, - exactly as shown. No more than one newline setting should be present in + The escapes that specify line ending sequences are literal strings, ex- + actly as shown. No more than one newline setting should be present in any data line. - A backslash followed by anything else just escapes the anything else. - If the very last character is a backslash, it is ignored. This gives a - way of passing an empty line as data, since a real empty line termi- + A backslash followed by anything else just escapes the anything else. + If the very last character is a backslash, it is ignored. This gives a + way of passing an empty line as data, since a real empty line termi- nates the data input. - The \J escape provides a way of setting the maximum stack size that is - used by the just-in-time optimization code. It is ignored if JIT opti- - mization is not being used. Providing a stack that is larger than the + The \J escape provides a way of setting the maximum stack size that is + used by the just-in-time optimization code. It is ignored if JIT opti- + mization is not being used. Providing a stack that is larger than the default 32K is necessary only for very complicated patterns. If \M is present, pcretest calls pcre[16|32]_exec() several times, with different values in the match_limit and match_limit_recursion fields of - the pcre[16|32]_extra data structure, until it finds the minimum num- + the pcre[16|32]_extra data structure, until it finds the minimum num- bers for each parameter that allow pcre[16|32]_exec() to complete with- - out error. Because this is testing a specific feature of the normal - interpretive pcre[16|32]_exec() execution, the use of any JIT optimiza- - tion that might have been set up by the /S+ qualifier of -s+ option is + out error. Because this is testing a specific feature of the normal in- + terpretive pcre[16|32]_exec() execution, the use of any JIT optimiza- + tion that might have been set up by the /S+ qualifier of -s+ option is disabled. - The match_limit number is a measure of the amount of backtracking that - takes place, and checking it out 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. The match_limit_recursion - number is a measure of how much stack (or, if PCRE is compiled with - NO_RECURSE, how much heap) memory is needed to complete the match - attempt. + The match_limit number is a measure of the amount of backtracking that + takes place, and checking it out 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. The match_limit_recursion + number is a measure of how much stack (or, if PCRE is compiled with + NO_RECURSE, how much heap) memory is needed to complete the match at- + tempt. - When \O is used, the value specified may be higher or lower than the + When \O is used, the value specified may be higher or lower than the size set by the -O command line option (or defaulted to 45); \O applies - only to the call of pcre[16|32]_exec() for the line in which it - appears. + only to the call of pcre[16|32]_exec() for the line in which it ap- + pears. - If the /P modifier was present on the pattern, causing the POSIX wrap- - per API to be used, the only option-setting sequences that have any - effect are \B, \N, and \Z, causing REG_NOTBOL, REG_NOTEMPTY, and - REG_NOTEOL, respectively, to be passed to regexec(). + If the /P modifier was present on the pattern, causing the POSIX wrap- + per API to be used, the only option-setting sequences that have any ef- + fect are \B, \N, and \Z, causing REG_NOTBOL, REG_NOTEMPTY, and REG_NO- + TEOL, respectively, to be passed to regexec(). THE ALTERNATIVE MATCHING FUNCTION - By default, pcretest uses the standard PCRE matching function, - pcre[16|32]_exec() to match each data line. PCRE also supports an - alternative matching function, pcre[16|32]_dfa_test(), which operates - in a different way, and has some restrictions. The differences between - the two functions are described in the pcrematching documentation. + By default, pcretest uses the standard PCRE matching function, + pcre[16|32]_exec() to match each data line. PCRE also supports an al- + ternative matching function, pcre[16|32]_dfa_test(), which operates in + a different way, and has some restrictions. The differences between the + two functions are described in the pcrematching documentation. - If a data line contains the \D escape sequence, or if the command line - contains the -dfa option, the alternative matching function is used. + If a data line contains the \D escape sequence, or if the command line + contains the -dfa option, the alternative matching function is used. This function finds all possible matches at a given point. If, however, - the \F escape sequence is present in the data line, it stops after the + the \F escape sequence is present in the data line, it stops after the first match is found. This is always the shortest possible match. DEFAULT OUTPUT FROM PCRETEST - This section describes the output when the normal matching function, + This section describes the output when the normal matching function, pcre[16|32]_exec(), is being used. When a match succeeds, pcretest outputs the list of captured substrings - that pcre[16|32]_exec() returns, starting with number 0 for the string - that matched the whole pattern. Otherwise, it outputs "No match" when - the return is PCRE_ERROR_NOMATCH, and "Partial match:" followed by the - partially matching substring when pcre[16|32]_exec() returns - PCRE_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, pcretest outputs the PCRE negative - error number and a short descriptive phrase. If the error is a failed - UTF string check, the offset of the start of the failing character and - the reason code are also output, provided that the size of the output - vector is at least two. Here is an example of an interactive pcretest - run. + that pcre[16|32]_exec() returns, starting with number 0 for the string + that matched the whole pattern. Otherwise, it outputs "No match" when + the return is PCRE_ERROR_NOMATCH, and "Partial match:" followed by the + partially matching substring when pcre[16|32]_exec() returns PCRE_ER- + ROR_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, pcretest outputs the PCRE negative error number and a + short descriptive phrase. If the error is a failed UTF string check, + the offset of the start of the failing character and the reason code + are also output, provided that the size of the output vector is at + least two. Here is an example of an interactive pcretest run. $ pcretest PCRE version 8.13 2011-04-30 @@ -892,9 +888,9 @@ OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION (Using the normal matching function on this data finds only "tang".) The longest matching string is always given first (and numbered zero). After a PCRE_ERROR_PARTIAL return, the output is "Partial match:", fol- - lowed 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- + lowed by the partially matching substring. (Note that this is the en- + tire substring that was inspected during the partial match; it may in- + clude characters before the actual match start if a lookbehind asser- tion, \K, \b, or \B was involved.) If /g is present on the pattern, the search for further matches resumes @@ -909,9 +905,9 @@ OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION 1: tan 0: tan - Since the matching function does not support substring capture, the - escape sequences that are concerned with captured substrings are not - relevant. + Since the matching function does not support substring capture, the es- + cape sequences that are concerned with captured substrings are not rel- + evant. RESTARTING AFTER A PARTIAL MATCH @@ -942,9 +938,9 @@ CALLOUTS --->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 of the data, and when the next + This output indicates that callout number 0 occurred for a match at- + tempt starting at the fourth character of the subject string, when the + pointer was at the seventh character of the data, and when the next pattern item was \d. Just one circumflex is output if the start and current positions are the same. @@ -963,8 +959,8 @@ 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 - example: + ever a change of latest mark is passed to the callout function. For ex- + ample: re> /a(*MARK:X)bc/C data> abc @@ -999,8 +995,8 @@ NON-PRINTING CHARACTERS When pcretest 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 /L modifier). In this case, the - isprint() function to distinguish printing and non-printing characters. + set for the pattern (using the /L modifier). In this case, the is- + print() function to distinguish printing and non-printing characters. SAVING AND RELOADING COMPILED PATTERNS @@ -1020,14 +1016,14 @@ SAVING AND RELOADING COMPILED PATTERNS studied with JIT optimization, the JIT data cannot be saved. The data that is written is binary. The first eight bytes are the - length of the compiled pattern data followed by the length of the - optional study data, each written as four bytes in big-endian order - (most significant byte first). If there is no study data (either the - pattern was not studied, or studying did not return any data), the sec- - ond length is zero. The lengths are followed by an exact copy of the - compiled pattern. If there is additional study data, this (excluding - any JIT data) follows immediately after the compiled pattern. After - writing the file, pcretest expects to read a new pattern. + length of the compiled pattern data followed by the length of the op- + tional study data, each written as four bytes in big-endian order (most + significant byte first). If there is no study data (either the pattern + was not studied, or studying did not return any data), the second + length is zero. The lengths are followed by an exact copy of the com- + piled pattern. If there is additional study data, this (excluding any + JIT data) follows immediately after the compiled pattern. After writing + the file, pcretest expects to read a new pattern. A saved pattern can be reloaded into pcretest by specifying < and a file name instead of a pattern. There must be no space between < and @@ -1066,10 +1062,10 @@ SAVING AND RELOADING COMPILED PATTERNS ing and experimentation. It is not intended for production use because only a single pattern can be written to a file. Furthermore, there is no facility for supplying custom character tables for use with a - reloaded pattern. If the original pattern was compiled with custom - tables, an attempt to match a subject string using a reloaded pattern - is likely to cause pcretest to crash. Finally, if you attempt to load - a file that is not in the correct format, the result is undefined. + reloaded pattern. If the original pattern was compiled with custom ta- + bles, an attempt to match a subject string using a reloaded pattern is + likely to cause pcretest to crash. Finally, if you attempt to load a + file that is not in the correct format, the result is undefined. SEE ALSO @@ -1087,5 +1083,5 @@ AUTHOR REVISION - Last updated: 23 February 2017 - Copyright (c) 1997-2017 University of Cambridge. + Last updated: 10 February 2020 + Copyright (c) 1997-2020 University of Cambridge. |