summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornigel <nigel@2f5784b3-3f2a-0410-8824-cb99058d5e15>2007-02-24 21:38:41 +0000
committernigel <nigel@2f5784b3-3f2a-0410-8824-cb99058d5e15>2007-02-24 21:38:41 +0000
commitd2884975c80217601913be24ef07254f2b9900cd (patch)
tree4f646c0b5fc14e4a68773206405b926235e6bd2b
parent489b7b63a0c5e1e9226558d25970cc342e82c16d (diff)
downloadpcre-d2884975c80217601913be24ef07254f2b9900cd.tar.gz
Load pcre-2.00 into code/trunk.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@23 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r--ChangeLog48
-rw-r--r--Makefile15
-rw-r--r--Performance172
-rw-r--r--README86
-rwxr-xr-xRunTest69
-rw-r--r--Tech.Notes59
-rw-r--r--internal.h59
-rw-r--r--pcre.3687
-rw-r--r--pcre.c1796
-rw-r--r--pcre.h19
-rw-r--r--pcreposix.c12
-rw-r--r--pcretest.c167
-rwxr-xr-xperltest4
-rw-r--r--pgrep.c4
-rw-r--r--study.c87
-rw-r--r--testinput64
-rw-r--r--testinput2346
-rw-r--r--testinput31603
-rw-r--r--testoutput123
-rw-r--r--testoutput2737
-rw-r--r--testoutput32753
21 files changed, 7155 insertions, 1755 deletions
diff --git a/ChangeLog b/ChangeLog
index 38ad670..6a639d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,53 @@ ChangeLog for PCRE
------------------
-Version 1.09 28 Apr-98
+Version 2.00 24-Sep-98
+----------------------
+
+1. Since the (>?) facility is in Perl 5.005, don't require PCRE_EXTRA to enable
+it any more.
+
+2. Allow quantification of (?>) groups, and make it work correctly.
+
+3. The first character computation wasn't working for (?>) groups.
+
+4. Correct the implementation of \Z (it is permitted to match on the \n at the
+end of the subject) and add 5.005's \z, which really does match only at the
+very end of the subject.
+
+5. Remove the \X "cut" facility; Perl doesn't have it, and (?> is neater.
+
+6. Remove the ability to specify CASELESS, MULTILINE, DOTALL, and
+DOLLAR_END_ONLY at runtime, to make it possible to implement the Perl 5.005
+localized options. All options to pcre_study() were also removed.
+
+7. Add other new features from 5.005:
+
+ $(?<= positive lookbehind
+ $(?<! negative lookbehind
+ (?imsx-imsx) added the unsetting capability
+ such a setting is global if at outer level; local otherwise
+ (?imsx-imsx:) non-capturing groups with option setting
+ (?(cond)re|re) conditional pattern matching
+
+ A backreference to itself in a repeated group matches the previous
+ captured string.
+
+8. General tidying up of studying (both automatic and via "study")
+consequential on the addition of new assertions.
+
+9. As in 5.005, unlimited repeated groups that could match an empty substring
+are no longer faulted at compile time. Instead, the loop is forcibly broken at
+runtime if any iteration does actually match an empty substring.
+
+10. Include the RunTest script in the distribution.
+
+11. Added tests from the Perl 5.005_02 distribution. This showed up a few
+discrepancies, some of which were old and were also with respect to 5.004. They
+have now been fixed.
+
+
+Version 1.09 28-Apr-98
----------------------
1. A negated single character class followed by a quantifier with a minimum
diff --git a/Makefile b/Makefile
index d8efeb1..7c863d5 100644
--- a/Makefile
+++ b/Makefile
@@ -12,6 +12,7 @@
# lacks the strerror() function, but can provide the equivalent by indexing
# into errlist.
+AR = ar cq
CC = gcc -O2 -Wall
CFLAGS =
RANLIB = @true
@@ -30,18 +31,18 @@ pcretest: libpcre.a libpcreposix.a pcretest.o
libpcre.a: $(OBJ)
/bin/rm -f libpcre.a
- ar cq libpcre.a $(OBJ)
+ $(AR) libpcre.a $(OBJ)
$(RANLIB) libpcre.a
libpcreposix.a: pcreposix.o
/bin/rm -f libpcreposix.a
- ar cq libpcreposix.a pcreposix.o
+ $(AR) libpcreposix.a pcreposix.o
$(RANLIB) libpcreposix.a
pcre.o: pcre.c pcre.h internal.h Makefile
$(CC) -c $(CFLAGS) pcre.c
-pcreposix.o: pcreposix.c pcreposix.h internal.h Makefile
+pcreposix.o: pcreposix.c pcreposix.h internal.h pcre.h Makefile
$(CC) -c $(CFLAGS) pcreposix.c
chartables.o: chartables.c
@@ -70,13 +71,7 @@ maketables: maketables.c Makefile
clean:; /bin/rm -f *.o *.a pcretest pgrep
-# Run the tests
-
runtest: all
- ./pcretest testinput testtry
- diff testtry testoutput
- ./pcretest -i testinput2 testtry
- diff testtry testoutput2
- rm -f testtry
+ ./RunTest
# End
diff --git a/Performance b/Performance
deleted file mode 100644
index 2bb4b96..0000000
--- a/Performance
+++ /dev/null
@@ -1,172 +0,0 @@
-Some comparisons of PCRE with the original Henry Spencer (1986) regular
-expression functions were done on a SPARCstation IPC using gcc version 2.6.3
-with -O optimization, to give some idea as to how the two libraries compare.
-This is not a major statistical investigation.
-
-
-Code size
----------
-
-The code size of PCRE is a bit over twice the size of the Henry Spencer
-functions (roughly 33K vs 14K bytes on a SPARCstation with gcc -O).
-
-
-Store size for compiled expressions
------------------------------------
-
-For expressions that are compatible with both libraries, PCRE uses less store
-for the examples tried, except in some cases that involve the use of character
-classes. Except in the special case of a negated charcter class containing only
-one character (e.g. [^a]), PCRE uses a 32-byte bit map for each character
-class, in order to get the maximum matching speed. By contrast the Spencer code
-uses a strchr() call.
-
-The Spencer functions have an overhead of 92 bytes per expression, because
-there is a table for up to 10 matched substrings held with every compiled
-expression. In contrast, PCRE's overhead is just 9 bytes, since it requires the
-caller to supply a vector to receive the offsets of the matched substrings. In
-the table below, the size without the overhead is shown in brackets.
-
-PCRE Spencer Pattern
----- ------- -------
-
- 18 (09) 109 (17) /^$/
- 25 (16) 120 (28) /^.*nter/
- 26 (17) 121 (29) /^12.34/
- 37 (28) 126 (34) /the quick brown fox/
- 50 (41) 114 (22) /^[]cde]/
- 50 (41) 114 (22) /^[^]cde]/
- 51 (42) 125 (33) /^[.^$|()*+?{,}]+/
- 52 (43) 126 (34) /^[0-9]+$/
- 56 (47) 153 (61) /^(abc)(abc)?zz/
- 57 (48) 133 (41) /^xxx[0-9]+$/
- 57 (48) 145 (53) /([0-9a-fA-F:]+)$/
- 62 (53) 171 (79) /^([^!]+)!(.+)=apquxz\.ixr\.zzz\.ac\.uk$$/
- 70 (61) 170 (78) /^(b+|a)(b+|a)?c/
- 74 (65) 173 (81) /^(ba|b*)(ba|b*)?bc/
- 99 (90) 235 (143) /^(a(b(c)))(d(e(f)))(h(i(j)))$/
-119 (110) 157 (65) /^.+[0-9][0-9][0-9]$/
-165 (156) 446 (354) /^[a-zA-Z0-9][a-zA-Z0-9\-]*(\.[a-zA-Z0-9][a-zA-z0-9\-]*)*\.$/
-451 (442) 605 (513) /^From +([^ ]+) +[a-zA-Z][a-zA-Z][a-zA-Z] +[a-zA-Z][a-zA-Z][a-zA-Z] +[0-9]?[0-9] +[0-9][0-9]:[0-9][0-9]/
-
-
-Compilation time
-----------------
-
-Timing was done using the clock() function to time 2000 compilations of each
-expression and then dividing by twice the number of clocks per second, to get a
-value in milliseconds. The variation observed over several runs was never more
-than 0.01:
-
-PCRE Spencer Pattern
----- ------- -------
-
-0.04 0.07 /^$/
-0.06 0.12 /^.*nter/
-0.06 0.13 /^12.34/
-0.06 0.09 /^[]cde]/
-0.07 0.14 /^[0-9]+$/
-0.07 0.10 /^[^]cde]/
-0.08 0.17 /^xxx[0-9]+$/
-0.08 0.14 /the quick brown fox/
-0.09 0.14 /^[.^$|()*+?{,}]+/
-0.10 0.33 /([0-9a-fA-F:]+)$/
-0.12 0.26 /^.+[0-9][0-9][0-9]$/
-0.12 0.42 /^(abc)(abc)?zz/
-0.14 0.51 /^(b+|a)(b+|a)?c/
-0.15 0.53 /^(ba|b*)(ba|b*)?bc/
-0.19 0.51 /^([^!]+)!(.+)=apquxz\.ixr\.zzz\.ac\.uk$/
-0.34 1.59 /^(a(b(c)))(d(e(f)))(h(i(j)))$/
-0.47 1.32 /^[a-zA-Z0-9][a-zA-Z0-9\-]*(\.[a-zA-Z0-9][a-zA-z0-9\-]*)*\.$/
-0.66 1.78 /^From +([^ ]+) +[a-zA-Z][a-zA-Z][a-zA-Z] +[a-zA-Z][a-zA-Z][a-zA-Z] +[0-9]?[0-9] +[0-9][0-9]:[0-9][0-9]/
-
-
-Execution time
---------------
-
-Execution timing was done in a similar manner. Blank entries in the "pattern"
-column below indicate the use of the same pattern as before.
-
-PCRE Spencer Subject Pattern
----- ------- ------- -------
-
-0.03 0.02 <null string> /^$/
-0.04 0.04 enter /^.*nter/
-0.04 0.04 uponter
-0.03 0.03 12\r34 /^12.34/
-0.03 0.03 0 /^[0-9]+$/
-0.04 0.03 100
-0.03 0.03 ]thing /^[]cde]/
-0.03 0.03 ething
-0.03 0.03 athing /^[^]cde]/
-0.04 0.04 xxx0 /^xxx[0-9]+$/
-0.04 0.04 xxx1234
-0.04 0.07 .^\$(*+)|{?,?} /^[.^$|()*+?{,}]+/
-0.03 0.03 the quick brown fox /the quick brown fox/
-0.06 0.08 What do you know about the quick brown fox?
-0.04 0.07 0abc /([0-9a-fA-F:]+)$/
-0.04 0.07 abc
-0.05 0.13 5f03:12C0::932e
-0.06 0.07 x123 /^.+[0-9][0-9][0-9]$/
-0.06 0.07 123456
-0.06 0.09 abczz /^(abc)(abc)?zz/
-0.06 0.12 abcabczz /^(abc)(abc)?zz/
- /^([^!]+)!(.+)=apquxz\.ixr\.zzz\.ac\.uk$/
-0.23 0.28 abc!pqr=apquxz.ixr.zzz.ac.uk
-0.09 0.15 bc /^(b+|a)(b+|a)?c/
-0.09 0.15 bbc
-0.08 0.15 bbbc
-0.09 0.15 bac
-0.09 0.15 bbac
-0.07 0.14 aac
-0.09 0.15 abbbbbbbbbbbc
-0.09 0.15 bbbbbbbbbbbac
-0.09 0.18 babc /^(ba|b*)(ba|b*)?bc/
-0.12 0.24 bbabc
-0.07 0.15 bababc
-0.06 0.10 a. /^[a-zA-Z0-9][a-zA-Z0-9\-]*(\.[a-zA-Z0-9][a-zA-z0-9\-]*)*\.$/
-0.13 0.34 ab-c.pq-r.
-0.24 0.58 sxk.zzz.ac.uk.
-0.12 0.34 x-.y-.
-0.20 0.38 abcdefhij /^(a(b(c)))(d(e(f)))(h(i(j)))$/
- /^From +([^ ]+) +[a-zA-Z][a-zA-Z][a-zA-Z] +[a-zA-Z][a-zA-Z][a-zA-Z] +[0-9]?[0-9] +[0-9][0-9]:[0-9][0-9]/
-0.18 0.30 From abcd Mon Sep 01 12:33:02 1997
-
-In general, PCRE runs faster than the Spencer function, but remember, this
-is just for one particular compiler on one set of hardware and operating
-system. Until comprehensive tests have been run in other environments, the most
-one can plausibly say is that it is probably no worse on average for the kinds
-of expression tested here.
-
-
-Speeding up matching
---------------------
-
-A character class is much more efficient than a set of bracketed alternatives.
-Matching /^[abc]{12}/ against "abcabcabcabc" took 0.03 ms, whereas
-/^(a|b|c){12}/ took 0.33 ms. This is because brackets and alternatives involve
-recursion.
-
-
-Serious test
-------------
-
-One of the tests of PCRE is the monster regular expression from "Mastering
-Regular Expressions" (O'Reilly's "hip owls" book, 1997, ISBN 1-56592-257-3)
-which recognizes email addresses. There are two versions, unoptimized and
-optimized. For interest, here are their timings, again on a SPARCstation IPC.
-The compile times were 55 ms and 94 ms, and the compiled expressions
-occupied 11010 and 15426 bytes of store, respectively. The following strings
-were matched in the times shown (unoptimized first):
-
-0.34 0.38 user@dom.ain
-0.38 0.42 <user@dom.ain>
-0.88 0.60 Alan Other <user@dom.ain>
-1.87 0.82 "A. Other" <user.1234@dom.ain> (a comment)
-1.77 1.19 A. Other <user.1234@dom.ain> (a comment)
-2.21 0.42 "/s=user/ou=host/o=place/prmd=uu.yy/admd= /c=gb/"@x400-re.lay
-
-The optimization of the expression clearly has a dramatic effect in some cases.
-
-Philip Hazel <ph10@cus.cam.ac.uk>
-October 1997
diff --git a/README b/README
index 80d9d05..8c47c1b 100644
--- a/README
+++ b/README
@@ -1,12 +1,21 @@
README file for PCRE (Perl-compatible regular expressions)
----------------------------------------------------------
+*******************************************************************************
+* IMPORTANT FOR THOSE UPGRADING FROM VERSIONS BEFORE 2.00 *
+* *
+* Please note that there has been a change in the API such that a larger *
+* ovector is required at matching time, to provide some additional workspace. *
+* The new man page has details. This change was necessary in order to support *
+* some of the new functionality in Perl 5.005. *
+*******************************************************************************
+
The distribution should contain the following files:
ChangeLog log of changes to the code
Makefile for building PCRE
- Performance notes on performance
README this file
+ RunTest a shell script for running tests
Tech.Notes notes on the encoding
pcre.3 man page for the functions
pcreposix.3 man page for the POSIX wrapper API
@@ -21,34 +30,36 @@ The distribution should contain the following files:
pgrep.1 man page for pgrep
pgrep.c source of a grep utility that uses PCRE
perltest Perl test program
- testinput test data, compatible with Perl
+ testinput test data, compatible with Perl 5.004 and 5.005
testinput2 test data for error messages and non-Perl things
+ testinput3 test data, compatible with Perl 5.005
testoutput test results corresponding to testinput
testoutput2 test results corresponding to testinput2
+ testoutput3 test results corresponding to testinpug3
-To build PCRE, edit Makefile for your system (it is a fairly simple make file)
-and then run it. It builds a two libraries called libpcre.a and libpcreposix.a,
-a test program called pcretest, and the pgrep command.
-
-To test PCRE, run pcretest on the file testinput, and compare the output with
-the contents of testoutput. There should be no differences. For example:
+To build PCRE, edit Makefile for your system (it is a fairly simple make file,
+and there are some comments at the top) and then run it. It builds two
+libraries called libpcre.a and libpcreposix.a, a test program called pcretest,
+and the pgrep command.
- pcretest testinput some.file
- diff some.file testoutput
+To test PCRE, run the RunTest script in the pcre directory. This runs pcretest
+on each of the testinput files in turn, and compares the output with the
+contents of the corresponding testoutput file. A file called testtry is used to
+hold the output from pcretest (which is documented below).
-Do the same with testinput2, comparing the output with testoutput2, but this
-time using the -i flag for pcretest, i.e.
+To run pcretest on just one of the test files, give its number as an argument
+to RunTest, for example:
- pcretest -i testinput2 some.file
- diff some.file testoutput2
+ RunTest 3
-The make target "runtest" runs both these tests, using the file "testtry" to
-store the intermediate output, deleting it at the end if all goes well.
+The first and third test files can also be fed directly into the perltest
+program to check that Perl gives the same results. The third file requires the
+additional features of release 5.005, which is why it is kept separate from the
+main test input, which needs only Perl 5.004. In the long run, when 5.005 is
+widespread, these two test files may get amalgamated.
-There are two sets of tests because the first set can also be fed directly into
-the perltest program to check that Perl gives the same results. The second set
-of tests check pcre_info(), pcre_study(), error detection and run-time flags
-that are specific to PCRE, as well as the POSIX wrapper API.
+The second set of tests check pcre_info(), pcre_study(), error detection and
+run-time flags that are specific to PCRE, as well as the POSIX wrapper API.
To install PCRE, copy libpcre.a to any suitable library directory (e.g.
/usr/local/lib), pcre.h to any suitable include directory (e.g.
@@ -66,7 +77,7 @@ themselves still follow Perl syntax and semantics. The header file
for the POSIX-style functions is called pcreposix.h. The official POSIX name is
regex.h, but I didn't want to risk possible problems with existing files of
that name by distributing it that way. To use it with an existing program that
-uses the POSIX API it will have to be renamed or pointed at by a link.
+uses the POSIX API, it will have to be renamed or pointed at by a link.
Character tables
@@ -130,8 +141,7 @@ and /X set PCRE_ANCHORED, PCRE_DOLLAR_ENDONLY, and PCRE_EXTRA respectively.
The /D option is a PCRE debugging feature. It causes the internal form of
compiled regular expressions to be output after compilation. The /S option
causes pcre_study() to be called after the expression has been compiled, and
-the results used when the expression is matched. If /I is present as well as
-/S, then pcre_study() is called with the PCRE_CASELESS option.
+the results used when the expression is matched.
Finally, the /P option causes pcretest to call PCRE via the POSIX wrapper API
rather than its native API. When this is done, all other options except /i and
@@ -140,7 +150,7 @@ is present. The wrapper functions force PCRE_DOLLAR_ENDONLY always, and
PCRE_DOTALL unless REG_NEWLINE is set.
A regular expression can extend over several lines of input; the newlines are
-included in it. See the testinput file for many examples.
+included in it. See the testinput files for many examples.
Before each data line is passed to pcre_exec(), leading and trailing whitespace
is removed, and it is then scanned for \ escapes. The following are recognized:
@@ -158,10 +168,6 @@ is removed, and it is then scanned for \ escapes. The following are recognized:
\A pass the PCRE_ANCHORED option to pcre_exec()
\B pass the PCRE_NOTBOL option to pcre_exec()
- \E pass the PCRE_DOLLAR_ENDONLY option to pcre_exec()
- \I pass the PCRE_CASELESS option to pcre_exec()
- \M pass the PCRE_MULTILINE option to pcre_exec()
- \S pass the PCRE_DOTALL option to pcre_exec()
\Odd set the size of the output vector passed to pcre_exec() to dd
(any number of decimal digits)
\Z pass the PCRE_NOTEOL option to pcre_exec()
@@ -182,11 +188,11 @@ whole pattern. Here is an example of an interactive pcretest run.
Testing Perl-Compatible Regular Expressions
PCRE version 0.90 08-Sep-1997
- re> /^abc(\d+)/
- data> abc123
- 0: abc123
- 1: 123
- data> xyz
+ re> /^abc(\d+)/
+ data> abc123
+ 0: abc123
+ 1: 123
+ data> xyz
No match
Note that while patterns can be continued over several lines (a plain ">"
@@ -207,10 +213,12 @@ pattern is studied, the results of that are also output.
If the option -s is given to pcretest, it outputs the size of each compiled
pattern after it has been compiled.
-If the -t option is given, each compile, study, and match is run 2000 times
+If the -t option is given, each compile, study, and match is run 10000 times
while being timed, and the resulting time per compile or match is output in
milliseconds. Do not set -t with -s, because you will then get the size output
-2000 times and the timing will be distorted.
+10000 times and the timing will be distorted. If you want to change the number
+of repetitions used for timing, edit the definition of LOOPREPEAT at the top of
+pcretest.c
@@ -219,7 +227,8 @@ The perltest program
The perltest program tests Perl's regular expressions; it has the same
specification as pcretest, and so can be given identical input, except that
-input patterns can be followed only by Perl's lower case options.
+input patterns can be followed only by Perl's lower case options. The contents
+of testinput and testinput3 meet this condition.
The data lines are processed as Perl strings, so if they contain $ or @
characters, these have to be escaped. For this reason, all such characters in
@@ -230,7 +239,8 @@ from the initial identifying banner.
The testinput2 file is not suitable for feeding to Perltest, since it does
make use of the special upper case options and escapes that pcretest uses to
-test additional features of PCRE.
+test some features of PCRE. It also contains malformed regular expressions, in
+order to check that PCRE diagnoses them correctly.
Philip Hazel <ph10@cam.ac.uk>
-October 1997
+September 1998
diff --git a/RunTest b/RunTest
new file mode 100755
index 0000000..1e0c521
--- /dev/null
+++ b/RunTest
@@ -0,0 +1,69 @@
+#! /bin/sh
+
+# Run PCRE tests
+
+cf=diff
+
+# Select which tests to run; if no selection, run all
+
+do1=no
+do2=no
+do3=no
+
+while [ $# -gt 0 ] ; do
+ case $1 in
+ 1) do1=yes;;
+ 2) do2=yes;;
+ 3) do3=yes;;
+ *) echo "Unknown test number $1"; exit 1;;
+ esac
+ shift
+done
+
+if [ $do1 = no -a $do2 = no -a $do3 = no ] ; then
+ do1=yes
+ do2=yes
+ do3=yes
+fi
+
+# Primary test, Perl-compatible
+
+if [ $do1 = yes ] ; then
+ echo "Testing main functionality (Perl compatible)"
+ ./pcretest testinput testtry
+ if [ $? = 0 ] ; then
+ $cf testtry testoutput
+ if [ $? != 0 ] ; then exit 1; fi
+ else exit 1
+ fi
+fi
+
+# PCRE tests that are not Perl-compatible - API & error tests, mostly
+
+if [ $do2 = yes ] ; then
+ echo "Testing API and error handling (not Perl compatible)"
+ ./pcretest -i testinput2 testtry
+ if [ $? = 0 ] ; then
+ $cf testtry testoutput2
+ if [ $? != 0 ] ; then exit 1; fi
+ else exit 1
+ fi
+fi
+
+# Additional Perl-compatible tests for Perl 5.005's new features
+
+if [ $do3 = yes ] ; then
+ echo "Testing Perl 5.005 features (Perl 5.005 compatible)"
+ ./pcretest testinput3 testtry
+ if [ $? = 0 ] ; then
+ $cf testtry testoutput3
+ if [ $? != 0 ] ; then exit 1; fi
+ else exit 1
+ fi
+fi
+
+if [ $do1 = yes -a $do2 = yes -a $do3 = yes ] ; then
+ echo "Tests all ran OK"
+fi
+
+# End
diff --git a/Tech.Notes b/Tech.Notes
index 69c5504..6660e14 100644
--- a/Tech.Notes
+++ b/Tech.Notes
@@ -18,22 +18,23 @@ expected in Unix and Perl-style regular expressions.
By contrast, the code originally written by Henry Spencer and subsequently
heavily modified for Perl actually compiles the expression twice: once in a
dummy mode in order to find out how much store will be needed, and then for
-real. The execution function operates by backtracking and maximizing (or
-minimizing in Perl) the amount of the subject that matches individual wild
-portions of the pattern. This is a "NFA algorithm".
+real. The execution function operates by backtracking and maximizing (or,
+optionally, minimizing in Perl) the amount of the subject that matches
+individual wild portions of the pattern. This is an "NFA algorithm" in Friedl's
+terminology.
For this set of functions, I tried at first to invent an algorithm that used an
amount of store bounded by a multiple of the number of characters in the
pattern, to save on compiling time. However, because of the greater complexity
in Perl regular expressions, I couldn't do this. In any case, a first pass
through the pattern is needed, in order to find internal flag settings like
-(?i). So it works by running a very degenerate first pass to calculate a
-maximum store size, and then a second pass to do the real compile - which may
-use a bit less than the predicted amount of store. The idea is that this is
-going to turn out faster because the first pass is degenerate and the second
-can just store stuff straight into the vector. It does make the compiling
-functions bigger, of course, but they have got quite big anyway to handle all
-the Perl stuff.
+(?i) at top level. So it works by running a very degenerate first pass to
+calculate a maximum store size, and then a second pass to do the real compile -
+which may use a bit less than the predicted amount of store. The idea is that
+this is going to turn out faster because the first pass is degenerate and the
+second can just store stuff straight into the vector. It does make the
+compiling functions bigger, of course, but they have got quite big anyway to
+handle all the Perl stuff.
The compiled form of a pattern is a vector of bytes, containing items of
variable length. The first byte in an item is an opcode, and the length of the
@@ -57,8 +58,8 @@ These items are all just one byte long
OP_WHITESPACE \s
OP_NOT_WORDCHAR \W
OP_WORDCHAR \w
- OP_CUT analogue of Prolog's "cut"
- OP_EOD match end of data: \Z
+ OP_EODN match end of data or \n at end: \Z
+ OP_EOD match end of data: \z
OP_DOLL $ (end of data, or before \n in multiline)
@@ -196,8 +197,12 @@ minimum. In effect, (abc){2,5} becomes (abc)(abc)(abc)?(abc)?(abc)?.
Assertions
----------
-Assertions are just like other subpatterns, but starting with one of the
-opcodes OP_ASSERT or OP_ASSERT_NOT.
+Forward assertions are just like other subpatterns, but starting with one of
+the opcodes OP_ASSERT or OP_ASSERT_NOT. Backward assertions use the opcodes
+OP_ASSERTBACK and OP_ASSERTBACK_NOT, and the first opcode inside the assertion
+is OP_REVERSE, followed by a two byte count of the number of characters to move
+back. A separate count is present in each alternative of a lookbehind
+assertion, allowing them to have different fixed lengths.
Once-only subpatterns
@@ -207,5 +212,29 @@ These are also just like other subpatterns, but they start with the opcode
OP_ONCE.
+Conditional subpatterns
+-----------------------
+
+These are like other subpatterns, but they start with the opcode OP_COND. If
+the condition is a back reference, this is stored at the start of the
+subpattern using the opcode OP_CREF followed by one byte containing the
+reference number. Otherwise, a conditional subpattern will always start with
+one of the assertions.
+
+
+Changing options
+----------------
+
+If any of the /i, /m, or /s options are changed within a parenthesized group,
+an OP_OPT opcode is compiled, followed by one byte containing the new settings
+of these flags. If there are several alternatives in a group, there is an
+occurrence of OP_OPT at the start of all those following the first options
+change, to set appropriate options for the start of the alternative.
+Immediately after the end of the group there is another such item to reset the
+flags to their previous values. Other changes of flag within the pattern can be
+handled entirely at compile time, and so do not cause anything to be put into
+the compiled data.
+
+
Philip Hazel
-December 1997
+September 1998
diff --git a/internal.h b/internal.h
index a64e922..18393d2 100644
--- a/internal.h
+++ b/internal.h
@@ -3,7 +3,7 @@
*************************************************/
-#define PCRE_VERSION "1.09 28-Apr-1998"
+#define PCRE_VERSION "2.00 24-Sep-1998"
/* This is a library of functions to support regular expressions whose syntax
@@ -46,7 +46,6 @@ define a macro for memmove() if USE_BCOPY is defined. */
#include <ctype.h>
#include <limits.h>
-#include <setjmp.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -60,31 +59,32 @@ Standard C system should have one. */
#define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field))
#endif
+/* These are the public options that can change during matching. */
+
+#define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL)
+
/* Private options flags start at the most significant end of the two bytes.
The public options defined in pcre.h start at the least significant end. Make
sure they don't overlap! */
#define PCRE_FIRSTSET 0x8000 /* first_char is set */
#define PCRE_STARTLINE 0x4000 /* start after \n for multiline */
-#define PCRE_COMPILED_CASELESS 0x2000 /* like it says */
+#define PCRE_INGROUP 0x2000 /* compiling inside a group */
/* Options for the "extra" block produced by pcre_study(). */
-#define PCRE_STUDY_CASELESS 0x01 /* study was caseless */
-#define PCRE_STUDY_MAPPED 0x02 /* a map of starting chars exists */
+#define PCRE_STUDY_MAPPED 0x01 /* a map of starting chars exists */
-/* Masks for identifying the public options: all permitted at compile time,
-only some permitted at run or study time. */
+/* Masks for identifying the public options which are permitted at compile
+time, run time or study time, respectively. */
#define PUBLIC_OPTIONS \
(PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY)
-#define PUBLIC_EXEC_OPTIONS \
- (PCRE_CASELESS|PCRE_ANCHORED|PCRE_MULTILINE|PCRE_NOTBOL|PCRE_NOTEOL| \
- PCRE_DOTALL|PCRE_DOLLAR_ENDONLY)
+#define PUBLIC_EXEC_OPTIONS (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL)
-#define PUBLIC_STUDY_OPTIONS (PCRE_CASELESS)
+#define PUBLIC_STUDY_OPTIONS 0 /* None defined */
/* Magic number to provide a small check against being handed junk. */
@@ -100,19 +100,14 @@ typedef int BOOL;
/* These are escaped items that aren't just an encoding of a particular data
value such as \n. They must have non-zero values, as check_escape() returns
their negation. Also, they must appear in the same order as in the opcode
-definitions below, up to ESC_Z. The final one must be ESC_REF as subsequent
+definitions below, up to ESC_z. The final one must be ESC_REF as subsequent
values are used for \1, \2, \3, etc. There is a test in the code for an escape
greater than ESC_b and less than ESC_X to detect the types that may be
repeated. If any new escapes are put in-between that don't consume a character,
that code will have to change. */
enum { ESC_A = 1, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W, ESC_w,
-
- /* These are not Perl escapes, so can't appear in the */
- ESC_X, /* simple table-lookup because they must be conditional */
- /* on PCRE_EXTRA. */
- ESC_Z,
- ESC_REF };
+ ESC_Z, ESC_z, ESC_REF };
/* Opcode table: OP_BRA must be last, as all values >= it are used for brackets
that extract substrings. Starting from 1 (i.e. after OP_END), the values up to
@@ -132,9 +127,10 @@ enum {
OP_WHITESPACE, /* \s */
OP_NOT_WORDCHAR, /* \W */
OP_WORDCHAR, /* \w */
- OP_CUT, /* The analogue of Prolog's "cut" operation (extension) */
- OP_EOD, /* End of data: \Z. */
+ OP_EODN, /* End of data or \n at end of data: \Z. */
+ OP_EOD, /* End of data: \z */
+ OP_OPT, /* Set runtime options */
OP_CIRC, /* Start of line - varies with multiline switch */
OP_DOLL, /* End of line - varies with multiline switch */
OP_ANY, /* Match any character */
@@ -181,7 +177,6 @@ enum {
OP_CRMINRANGE,
OP_CLASS, /* Match a character class */
- OP_NEGCLASS, /* Match a character class, specified negatively */
OP_REF, /* Match a back reference */
OP_ALT, /* Start of alternation */
@@ -189,9 +184,20 @@ enum {
OP_KETRMAX, /* These two must remain together and in this */
OP_KETRMIN, /* order. They are for groups the repeat for ever. */
- OP_ASSERT,
- OP_ASSERT_NOT,
+ /* The assertions must come before ONCE and COND */
+
+ OP_ASSERT, /* Positive lookahead */
+ OP_ASSERT_NOT, /* Negative lookahead */
+ OP_ASSERTBACK, /* Positive lookbehind */
+ OP_ASSERTBACK_NOT, /* Negative lookbehind */
+ OP_REVERSE, /* Move pointer back - used in lookbehind assertions */
+
+ /* ONCE and COND must come after the assertions, with ONCE first, as there's
+ a test for >= ONCE for a subpattern that isn't an assertion. */
+
OP_ONCE, /* Once matched, don't back up into the subpattern */
+ OP_COND, /* Conditional group */
+ OP_CREF, /* Used to hold an extraction string number */
OP_BRAZERO, /* These two must remain together and in this */
OP_BRAMINZERO, /* order. */
@@ -231,8 +237,13 @@ just to accommodate the POSIX wrapper. */
#define ERR19 "too many sets of parentheses"
#define ERR20 "regular expression too large"
#define ERR21 "failed to get memory"
-#define ERR22 "unmatched brackets"
+#define ERR22 "unmatched parentheses"
#define ERR23 "internal error: code overflow"
+#define ERR24 "unrecognized character after (?<"
+#define ERR25 "lookbehind assertion is not fixed length"
+#define ERR26 "malformed number after (?("
+#define ERR27 "conditional group contains more than two branches"
+#define ERR28 "assertion expected after (?("
/* All character handling must be done as unsigned characters. Otherwise there
are problems with top-bit-set characters and functions such as isspace().
diff --git a/pcre.3 b/pcre.3
index c96a9d7..6070e66 100644
--- a/pcre.3
+++ b/pcre.3
@@ -52,7 +52,7 @@ pcre - Perl-compatible regular expressions.
.SH DESCRIPTION
The PCRE library is a set of functions that implement regular expression
pattern matching using the same syntax and semantics as Perl 5, with just a few
-differences (see below). The current implementation corresponds to Perl 5.004.
+differences (see below). The current implementation corresponds to Perl 5.005.
PCRE has its own native API, which is described in this man page. There is also
a set of wrapper functions that correspond to the POSIX API. See
@@ -72,15 +72,14 @@ should be done before calling any PCRE functions.
The other global variables are character tables. They are initialized when PCRE
is compiled, from source that is generated by reference to the C character type
-functions, but which the maintainer of PCRE is free to modify. In principle
-they could also be modified at runtime. See PCRE's README file for more
-details.
+functions, but which a user of PCRE is free to modify. In principle the tables
+could also be modified at run time. See PCRE's README file for more details.
.SH MULTI-THREADING
The PCRE functions can be used in multi-threading applications, with the
proviso that the character tables and the memory management functions pointed
-to by \fBpcre_malloc\fR and \fBpcre_free\fR will be shared by all threads.
+to by \fBpcre_malloc\fR and \fBpcre_free\fR are shared by all threads.
The compiled form of a regular expression is not altered during matching, so
the same compiled pattern can safely be used by several threads at once.
@@ -101,11 +100,13 @@ quantifiers with a minimum greater than one or a bounded maximum cause the
relevant portions of the compiled pattern to be replicated.
.PP
The \fIoptions\fR argument contains independent bits that affect the
-compilation. It should be zero if no options are required. Those options that
-are compabible with Perl can also be set at compile time from within the
-pattern (see the detailed description of regular expressions below) and all
-options except PCRE_EXTENDED, PCRE_EXTRA and PCRE_UNGREEDY can be set at the
-time of matching.
+compilation. It should be zero if no options are required. Some of the options,
+in particular, those that are compatible with Perl, can also be set and unset
+from within the pattern (see the detailed description of regular expressions
+below). For these options, the contents of the \fIoptions\fR argument specifies
+their initial settings at the start of compilation and execution. The
+PCRE_ANCHORED option can be set at the time of matching as well as at compile
+time.
.PP
If \fIerrptr\fR is NULL, \fBpcre_compile()\fR returns NULL immediately.
Otherwise, if compilation of a pattern fails, \fBpcre_compile()\fR returns
@@ -128,30 +129,42 @@ constructs in the pattern itself, which is the only way to do it in Perl.
PCRE_CASELESS
If this bit is set, letters in the pattern match both upper and lower case
-letters in any subject string. It is equivalent to Perl's /i option.
+letters. It is equivalent to Perl's /i option.
PCRE_DOLLAR_ENDONLY
If this bit is set, a dollar metacharacter in the pattern matches only at the
-end of the subject string. By default, it also matches immediately before the
-final character if it is a newline (but not before any other newlines). The
-PCRE_DOLLAR_ENDONLY option is ignored if PCRE_MULTILINE is set. There is no
-equivalent to this option in Perl.
+end of the subject string. Without this option, a dollar also matches
+immediately before the final character if it is a newline (but not before any
+other newlines). The PCRE_DOLLAR_ENDONLY option is ignored if PCRE_MULTILINE is
+set. There is no equivalent to this option in Perl.
PCRE_DOTALL
If this bit is set, a dot metacharater in the pattern matches all characters,
-including newlines. By default, newlines are excluded. This option is
+including newlines. Without it, newlines are excluded. This option is
equivalent to Perl's /s option. A negative class such as [^a] always matches a
newline character, independent of the setting of this option.
PCRE_EXTENDED
-If this bit is set, whitespace characters in the pattern are totally ignored
-except when escaped or inside a character class, and characters between an
-unescaped # outside a character class and the next newline character,
+If this bit is set, whitespace data characters in the pattern are totally
+ignored except when escaped or inside a character class, and characters between
+an unescaped # outside a character class and the next newline character,
inclusive, are also ignored. This is equivalent to Perl's /x option, and makes
-it possible to include comments inside complicated patterns.
+it possible to include comments inside complicated patterns. Note, however,
+that this applies only to data characters. Whitespace characters may never
+appear within special character sequences in a pattern, for example within the
+sequence (?( which introduces a conditional subpattern.
+
+ PCRE_EXTRA
+
+This option turns on additional functionality of PCRE that is incompatible with
+Perl. Any backslash in a pattern that is followed by a letter that has no
+special meaning causes an error, thus reserving these combinations for future
+expansion. By default, as in Perl, a backslash followed by a letter with no
+special meaning is treated as a literal. There are at present no other features
+controlled by this option.
PCRE_MULTILINE
@@ -159,7 +172,8 @@ By default, PCRE treats the subject string as consisting of a single "line" of
characters (even if it actually contains several newlines). The "start of line"
metacharacter (^) matches only at the start of the string, while the "end of
line" metacharacter ($) matches only at the end of the string, or before a
-terminating newline. This is the same as Perl.
+terminating newline (unless PCRE_DOLLAR_ENDONLY is set). This is the same as
+Perl.
When PCRE_MULTILINE it is set, the "start of line" and "end of line" constructs
match immediately following or immediately before any newline in the subject
@@ -168,25 +182,6 @@ to Perl's /m option. If there are no "\\n" characters in a subject string, or
no occurrences of ^ or $ in a pattern, setting PCRE_MULTILINE has no
effect.
- PCRE_EXTRA
-
-This option turns on additional functionality of PCRE that is incompatible with
-Perl. Any backslash in a pattern that is followed by a letter that has no
-special meaning causes an error, thus reserving these combinations for future
-expansion. By default, as in Perl, a backslash followed by a letter with no
-special meaning is treated as a literal. There are two extra features currently
-provided, and both are in some sense experimental additions that are useful for
-influencing the progress of a match.
-
- (1) The sequence \\X inserts a Prolog-like "cut" into the expression.
-
- (2) Once a subpattern enclosed in (?>subpat) brackets has matched,
- backtracking never goes back into the pattern.
-
-See below for further details of both of these. PCRE_EXTRA can be set by a (?X)
-option setting within the pattern, but this must precede anything in the
-pattern which relies on its being set.
-
PCRE_UNGREEDY
This option inverts the "greediness" of the quantifiers so that they are not
@@ -194,7 +189,6 @@ greedy by default, but become greedy if followed by "?". It is not compatible
with Perl. It can also be set by a (?U) option setting within the pattern.
-
.SH STUDYING A PATTERN
When a pattern is going to be used several times, it is worth spending more
time analyzing it in order to speed up the time taken for matching. The
@@ -204,14 +198,8 @@ typedef) containing additional information about the pattern; this can be
passed to \fBpcre_exec()\fR. If no additional information is available, NULL
is returned.
-The second argument contains option bits. The only one currently supported is
-PCRE_CASELESS. It forces the studying to be done in a caseless manner, even if
-the original pattern was compiled without PCRE_CASELESS. When the result of
-\fBpcre_study()\fR is passed to \fBpcre_exec()\fR, it is used only if its
-caseless state is the same as that of the matching process. A pattern that is
-compiled without PCRE_CASELESS can be studied with and without PCRE_CASELESS,
-and the appropriate data passed to \fBpcre_exec()\fR with and without the
-PCRE_CASELESS flag.
+The second argument contains option bits. At present, no options are defined
+for \fBpcre_study()\fR, and this argument should always be zero.
The third argument for \fBpcre_study()\fR is a pointer to an error message. If
studying succeeds (even if no data is returned), the variable it points to is
@@ -231,10 +219,10 @@ pattern has been studied, the result of the study should be passed in the
The subject string is passed as a pointer in \fIsubject\fR and a length in
\fIlength\fR. Unlike the pattern string, it may contain binary zero characters.
-The options PCRE_ANCHORED, PCRE_CASELESS, PCRE_DOLLAR_ENDONLY, PCRE_DOTALL, and
-PCRE_MULTILINE can be passed in the \fIoptions\fR argument, whose unused bits
-must be zero. However, if a pattern is compiled with any of these options, they
-cannot be unset when it is obeyed.
+The PCRE_ANCHORED option can be passed in the \fIoptions\fR argument, whose
+unused bits must be zero. However, if a pattern was compiled with
+PCRE_ANCHORED, or turned out to be anchored by virtue of its contents, it
+cannot be made unachored at matching time.
There are also two further options that can be set only at matching time:
@@ -242,14 +230,14 @@ There are also two further options that can be set only at matching time:
The first character of the string is not the beginning of a line, so the
circumflex metacharacter should not match before it. Setting this without
-PCRE_MULTILINE (at either compile or match time) causes circumflex never to
-match.
+PCRE_MULTILINE (at compile time) causes circumflex never to match.
PCRE_NOTEOL
The end of the string is not the end of a line, so the dollar metacharacter
-should not match it. Setting this without PCRE_MULTILINE (at either compile or
-match time) causes dollar never to match.
+should not match it nor (except in multiline mode) a newline immediately before
+it. Setting this without PCRE_MULTILINE (at compile time) causes dollar never
+to match.
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
@@ -260,21 +248,28 @@ kinds of parenthesized subpattern that do not cause substrings to be captured.
Captured substrings are returned to the caller via a vector of integer offsets
whose address is passed in \fIovector\fR. The number of elements in the vector
-is passed in \fIovecsize\fR. This should always be an even number, because the
-elements are used in pairs. If an odd number is passed, it is rounded down.
-
-The first element of a 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. The first pair, \fIovector[0]\fR and \fIovector[1]\fR,
-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 \fBpcre_exec()\fR is the number of pairs that have been set. 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.
+is passed in \fIovecsize\fR. The first two-thirds of the vector is used to pass
+back captured substrings, each substring using a pair of integers. The
+remaining third of the vector is used as workspace by \fBpcre_exec()\fR while
+matching capturing subpatterns, and is not available for passing back
+information. The length passed in \fIovecsize\fR should always be a multiple of
+three. If it is not, it is rounded down.
+
+When a match has been successful, information about captured substrings is
+returned in pairs of integers, starting at the beginning of \fIovector\fR, and
+continuing up to two-thirds of its length at the most. The first element of a
+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. The
+first pair, \fIovector[0]\fR and \fIovector[1]\fR, 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 \fBpcre_exec()\fR
+is the number of pairs that have been set. 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.
It is possible for an capturing subpattern number \fIn+1\fR to match some
part of the subject when subpattern \fIn\fR has not been used at all. For
-example, if the string "abc" is matched against the pattern "(a|(z))(bc)",
+example, if the string "abc" is matched against the pattern (a|(z))(bc)
subpatterns 1 and 3 are matched, but 2 is not. When this happens, both offset
values corresponding to the unused subpattern are set to -1.
@@ -282,15 +277,18 @@ If a capturing subpattern is matched repeatedly, it is the last portion of the
string that it matched that gets returned.
If the vector is too small to hold all the captured substrings, it is used as
-far as possible, and the function returns a value of zero. In particular, if
-the substring offsets are not of interest, \fBpcre_exec()\fR may be called with
-\fIovector\fR passed as NULL and \fIovecsize\fR as zero. However, if the
-pattern contains back references and the \fIovector\fR isn't 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 \fIovector\fR.
+far as possible (up to two-thirds of its length), and the function returns a
+value of zero. In particular, if the substring offsets are not of interest,
+\fBpcre_exec()\fR may be called with \fIovector\fR passed as NULL and
+\fIovecsize\fR as zero. However, if the pattern contains back references and
+the \fIovector\fR isn't 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 \fIovector\fR.
Note that \fBpcre_info()\fR can be used to find out how many capturing
-subpatterns there are in a compiled pattern.
+subpatterns there are in a compiled pattern. The smallest size for
+\fIovector\fR that will allow for \fIn\fR captured substrings in addition to
+the offsets of the substring matched by the whole pattern is (\fIn\fR+1)*3.
If \fBpcre_exec()\fR fails, it returns a negative number. The following are
defined in the header file:
@@ -299,33 +297,28 @@ defined in the header file:
The subject string did not match the pattern.
- PCRE_ERROR_BADREF (-2)
-
-There was a back-reference in the pattern to a capturing subpattern that had
-not previously been set.
-
- PCRE_ERROR_NULL (-3)
+ PCRE_ERROR_NULL (-2)
Either \fIcode\fR or \fIsubject\fR was passed as NULL, or \fIovector\fR was
NULL and \fIovecsize\fR was not zero.
- PCRE_ERROR_BADOPTION (-4)
+ PCRE_ERROR_BADOPTION (-3)
An unrecognized bit was set in the \fIoptions\fR argument.
- PCRE_ERROR_BADMAGIC (-5)
+ PCRE_ERROR_BADMAGIC (-4)
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. This is the error it gives when the
magic number isn't present.
- PCRE_ERROR_UNKNOWN_NODE (-6)
+ PCRE_ERROR_UNKNOWN_NODE (-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 overwriting
of the compiled pattern.
- PCRE_ERROR_NOMEMORY (-7)
+ PCRE_ERROR_NOMEMORY (-6)
If a pattern contains back references, but the \fIovector\fR that is passed to
\fBpcre_exec()\fR is not big enough to remember the referenced substrings, PCRE
@@ -362,7 +355,7 @@ The maximum length of a compiled pattern is 65539 (sic) bytes.
All values in repeating quantifiers must be less than 65536.
The maximum number of capturing subpatterns is 99.
The maximum number of all parenthesized subpatterns, including capturing
-subpatterns and assertions, is 200.
+subpatterns, assertions, and other types of subpattern, is 200.
The maximum length of a subject string is the largest positive number that an
integer variable can hold. However, PCRE uses recursion to handle subpatterns
@@ -371,7 +364,7 @@ the size of a subject string that can be processed by certain patterns.
.SH DIFFERENCES FROM PERL
-The differences described here are with respect to Perl 5.004.
+The differences described here are with respect to Perl 5.005.
1. By default, a whitespace character is any character that the C library
function \fBisspace()\fR recognizes, though it is possible to compile PCRE with
@@ -380,10 +373,10 @@ formfeed, newline, carriage return, horizontal tab, and vertical tab. Perl 5
no longer includes vertical tab in its set of whitespace characters. The \\v
escape that was in the Perl documentation for a long time was never in fact
recognized. However, the character itself was treated as whitespace at least
-up to 5.002. In 5.004 it does not match \\s.
+up to 5.002. In 5.004 and 5.005 it does not match \\s.
2. PCRE does not allow repeat quantifiers on lookahead assertions. Perl permits
-them, but they do not mean what you might think. For example, "(?!a){3}" does
+them, but they do not mean what you might think. For example, (?!a){3} does
not assert that the next three characters are not "a". It just asserts that the
next character is not "a" three times.
@@ -405,30 +398,35 @@ are not part of its pattern matching engine.
6. The Perl \\G assertion is not supported as it is not relevant to single
pattern matches.
-7. If a backreference can never be matched, PCRE diagnoses an error. In a case
-like
+7. Fairly obviously, PCRE does not support the (?{code}) construction.
- /(123)\\2/
+8. There are at the time of writing some oddities in Perl 5.005_02 concerned
+with the settings of captured strings when part of a pattern is repeated. For
+example, matching "aba" against the pattern /^(a(b)?)+$/ sets $2 to the value
+"b", but matching "aabbaa" against /^(aa(bb)?)+$/ leaves $2 unset. However, if
+the pattern is changed to /^(aa(b(b))?)+$/ then $2 (and $3) get set.
-the error occurs at compile time. Perl gives no compile time error; version
-5.004 either always fails to match, or gives a segmentation fault at runtime.
-In more complicated cases such as
+In Perl 5.004 $2 is set in both cases, and that is also true of PCRE. If in the
+future Perl changes to a consistent state that is different, PCRE may change to
+follow.
- /(1)(2)(3)(4)(5)(6)(7)(8)(9)(10\\10)/
+9. Another as yet unresolved discrepancy is that in Perl 5.005_02 the pattern
+/^(a)?(?(1)a|b)+$/ matches the string "a", whereas in PCRE it does not.
+However, in both Perl and PCRE /^(a)?a/ matched against "a" leaves $1 unset.
-PCRE returns PCRE_ERROR_BADREF at run time. Perl always fails to match.
+10. PCRE provides some extensions to the Perl regular expression facilities:
-8. PCRE provides some extensions to the Perl regular expression facilities:
+(a) Although lookbehind assertions must match fixed length strings, each
+alternative branch of a lookbehind assertion can match a different length of
+string. Perl 5.005 requires them all to have the same length.
-(a) If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not set, the $ meta-
+(b) If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not set, the $ meta-
character matches only at the very end of the string.
-(b) If PCRE_EXTRA is set, the \\X assertion (a Prolog-like "cut") is
-recognized, and a backslash followed by a letter with no special meaning is
-faulted. There is also a new kind of parenthesized subpattern starting with (?>
-which has a block on backtracking into it once it has matched.
+(c) If PCRE_EXTRA is set, a backslash followed by a letter with no special
+meaning is faulted.
-(c) If PCRE_UNGREEDY is set, the greediness of the repetition quantifiers is
+(d) If PCRE_UNGREEDY is set, the greediness of the repetition quantifiers is
inverted, that is, by default they are not greedy, but if followed by a
question mark they are.
@@ -497,9 +495,10 @@ non-alphameric with "\\" to specify that it stands for itself. In particular,
if you want to match a backslash, you write "\\\\".
If a pattern is compiled with the PCRE_EXTENDED option, whitespace in the
-pattern and characters between a "#" outside a character class and the next
-newline character are ignored. An escaping backslash can be used to include a
-whitespace or "#" character as part of the pattern.
+pattern (other than in a character class) and characters between a "#" outside
+a character class and the next newline character are ignored. An escaping
+backslash can be used to include a whitespace or "#" character as part of the
+pattern.
A second use of backslash provides a way of encoding non-printing characters
in patterns in a visible manner. There is no restriction on the appearance of
@@ -516,7 +515,7 @@ represents:
\\r carriage return (hex 0D)
\\t tab (hex 09)
\\xhh character with hex code hh
- \\ddd character with octal code ddd or backreference
+ \\ddd character with octal code ddd, or backreference
The precise effect of "\\cx" is as follows: if "x" is a lower case letter, it
is converted to upper case. Then bit 6 of the character (hex 40) is inverted.
@@ -529,8 +528,8 @@ lower case).
After "\\0" up to two further octal digits are read. In both cases, if there
are fewer than two digits, just those that are present are used. Thus the
sequence "\\0\\x\\07" specifies two binary zeros followed by a BEL character.
-Make sure you supply two digits if the character that follows could otherwise
-be taken as another digit.
+Make sure you supply two digits after the initial zero if the character that
+follows is itself an octal digit.
The handling of a backslash followed by a digit other than 0 is complicated.
Outside a character class, PCRE reads it and any following digits as a decimal
@@ -586,51 +585,38 @@ one character of the appropriate type. If the current matching point is at the
end of the subject string, all of them fail, since there is no character to
match.
-The fourth use of backslash is for certain assertions. An assertion specifies a
-condition that has to be met at a particular point in a match, without
-consuming any characters from the subject string. The backslashed assertions
-are
+The fourth use of backslash is for certain simple assertions. An assertion
+specifies a condition that has to be met at a particular point in a match,
+without consuming any characters from the subject string. The use of
+subpatterns for more complicated assertions is described below. The backslashed
+assertions are
\\b word boundary
\\B not a word boundary
\\A start of subject (independent of multiline mode)
- \\Z end of subject (independent of multiline mode)
+ \\Z end of subject or newline at end (independent of multiline mode)
+ \\z end of subject (independent of multiline mode)
-Assertions may not appear in character classes (but note that "\\b" has a
+These assertions may not appear in character classes (but note that "\\b" has a
different meaning, namely the backspace character, inside a character class).
A word boundary is a position in the subject string where the current character
-and the previous character do not both match "\\w" or "\\W" (i.e. one matches
-"\\w" and the other matches "\\W"), or the start or end of the string if the
-first or last character matches "\\w", respectively. More complicated
-assertions are also supported (see below).
-
-The "\\A" and "\\Z" assertions differ from the traditional "^" and "$"
-(described below) in that they only ever match at the very start and end of the
-subject string, respectively, whatever options are set.
-
-When the PCRE_EXTRA flag is set on a call to \fBpcre_compile()\fR, the
-additional assertion \\X, which has no equivalent in Perl, is recognized.
-This operates like the "cut" operation in Prolog: it prevents the matching
-operation from backtracking past it. For example, if the expression
-
- .*/foo
-
-is matched against the string "/this/string/is/not" then after the greedy .*
-has swallowed the whole string, PCRE keeps backtracking all the way to the
-beginning before failing. If, on the other hand, the expression is
-
- .*/\\Xfoo
-
-then once it has discovered that "/not" is not "/foo", backtracking ceases, and
-the match fails. See also the section on "once-only" subpatterns below.
+and the previous character do not both match \\w or \\W (i.e. one matches
+\\w and the other matches \\W), or the start or end of the string if the
+first or last character matches \\w, respectively.
+The \\A, \\Z, and \\z assertions differ from the traditional circumflex and
+dollar (described below) in that they only ever match at the very start and end
+of the subject string, whatever options are set. They are not affected by the
+PCRE_NOTBOL or PCRE_NOTEOL options. The difference between \\Z and \\z is that
+\\Z matches before a newline that is the last character of the string as well
+as at the end of the string, whereas \\z matches only at the end.
.SH CIRCUMFLEX AND DOLLAR
-Outside a character class, the circumflex character is an assertion which is
-true only if the current matching point is at the start of the subject string,
-in the default matching mode. Inside a character class, circumflex has an
+Outside a character class, in the default matching mode, the circumflex
+character is an assertion which is true only if the current matching point is
+at the start of the subject string. Inside a character class, circumflex has an
entirely different meaning (see below).
Circumflex need not be the first character of the pattern if a number of
@@ -650,21 +636,20 @@ Dollar has no special meaning in a character class.
The meaning of dollar can be changed so that it matches only at the very end of
the string, by setting the PCRE_DOLLAR_ENDONLY option at compile or matching
-time.
+time. This does not affect the \\Z assertion.
The meanings of the circumflex and dollar characters are changed if the
-PCRE_MULTILINE option is set at compile or matching time. When this is the
-case, they match immediately after and immediately before an internal "\\n"
-character, respectively, in addition to matching at the start and end of the
-subject string. For example, the pattern /^abc$/ matches the subject string
-"def\\nabc" in multiline mode, but not otherwise. Consequently, patterns that
-are anchored in single line mode because all branches start with "^" are not
-anchored in multiline mode. The PCRE_DOLLAR_ENDONLY option is ignored if
-PCRE_MULTILINE is set.
+PCRE_MULTILINE option is set. When this is the case, they match immediately
+after and immediately before an internal "\\n" character, respectively, in
+addition to matching at the start and end of the subject string. For example,
+the pattern /^abc$/ matches the subject string "def\\nabc" in multiline mode,
+but not otherwise. Consequently, patterns that are anchored in single line mode
+because all branches start with "^" are not anchored in multiline mode. The
+PCRE_DOLLAR_ENDONLY option is ignored if PCRE_MULTILINE is set.
-Note that the sequences "\\A" and "\\Z" can be used to match the start and end
-of the subject in both modes, and if all branches of a pattern start with "\\A"
-is it always anchored.
+Note that the sequences \\A, \\Z, and \\z can be used to match the start and
+end of the subject in both modes, and if all branches of a pattern start with
+\\A is it always anchored, whether PCRE_MULTILINE is set or not.
.SH FULL STOP (PERIOD, DOT)
@@ -681,13 +666,14 @@ An opening square bracket introduces a character class, terminated by a closing
square bracket. A closing square bracket on its own is not special. If a
closing square bracket is required as a member of the class, it should be the
first data character in the class (after an initial circumflex, if present) or
-escaped with \\.
+escaped with a backslash.
A character class matches a single character in the subject; the character must
be in the set of characters defined by the class, unless the first character in
the class is a circumflex, in which case the subject character must not be in
the set defined by the class. If a circumflex is actually required as a member
-of the class, ensure it is not the first character, or escape it with \\.
+of the class, ensure it is not the first character, or escape it with a
+backslash.
For example, the character class [aeiou] matches any lower case vowel, while
[^aeiou] matches any character that is not a lower case vowel. Note that a
@@ -696,6 +682,11 @@ are in the class by enumerating those that are not. It is not an assertion: it
still consumes a character from the subject string, and fails if the current
pointer is at the end of the string.
+When PCRE_CASELESS is set, any letters in a class represent both their upper
+case and lower case versions, so for example, a caseless [aeiou] matches "A" as
+well as "a", and a caseless [^aeiou] does not match "A", whereas a caseful
+version would.
+
The newline character is never treated in any special way in character classes,
whatever the setting of the PCRE_DOTALL or PCRE_MULTILINE options is. A class
such as [^a] will always match a newline.
@@ -703,20 +694,24 @@ such as [^a] will always match a newline.
The minus (hyphen) character can be used to specify a range of characters 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
-\\ or appear in a position where it cannot be interpreted as indicating a
-range, typically as the first or last character in the class. It is not
-possible to have the character "]" as the end character of a range, since a
-sequence such as [w-] is interpreted as a class of two characters. The octal or
-hexadecimal representation of "]" can, however, be used to end a range.
+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. It
+is not possible to have the character "]" as the end character of a range,
+since a sequence such as [w-] is interpreted as a class of two characters. The
+octal or hexadecimal representation of "]" can, however, be used to end a
+range.
Ranges operate in ASCII collating sequence. They can also be used for
characters specified numerically, for example [\\000-\\037]. If a range such as
[W-c] is used when PCRE_CASELESS is set, it matches the letters involved in
-either case.
+either case, so is equivalent to [][\\^_`wxyzabc], matched caselessly.
The character types \\d, \\D, \\s, \\S, \\w, and \\W may also appear in a
character class, and add the characters that they match to the class. For
-example, the class [^\\W_] matches any letter or digit.
+example, [\\dABCDEF] matches any hexadecimal digit. 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.
All non-alphameric characters other than \\, -, ^ (at the start) and the
terminating ] are non-special in character classes, but it does no harm if they
@@ -724,13 +719,74 @@ are escaped.
.SH VERTICAL BAR
-Vertical bar characters are used to separate alternative patterns. The matching
-process tries all the alternatives in turn. For example, the pattern
+Vertical bar characters are used to separate alternative patterns. For example,
+the pattern
gilbert|sullivan
-matches either "gilbert" or "sullivan". Any number of alternatives can be used,
+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 rest of the main
+pattern as well as the alternative in the subpattern.
+
+
+.SH INTERNAL OPTION SETTING
+The settings of PCRE_CASELESS, PCRE_MULTILINE, PCRE_DOTALL, and PCRE_EXTENDED
+can be changed from within the pattern by a sequence of Perl option letters
+enclosed between "(?" and ")". The option letters are
+
+ i for PCRE_CASELESS
+ m for PCRE_MULTILINE
+ s for PCRE_DOTALL
+ x for PCRE_EXTENDED
+
+For example, (?im) sets caseless, multiline matching. It is also possible to
+unset these options by preceding the letter with a hyphen, and a combined
+setting and unsetting such as (?im-sx), which sets PCRE_CASELESS 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.
+
+The scope of these option changes depends on where in the pattern the setting
+occurs. For settings that are outside any subpattern (defined below), the
+effect is the same as if the options were set or unset at the start of
+matching. The following patterns all behave in exactly the same way:
+
+ (?i)abc
+ a(?i)bc
+ ab(?i)c
+ abc(?i)
+
+which in turn is the same as compiling the pattern abc with PCRE_CASELESS set.
+In other words, such "top level" settings apply to the whole pattern (unless
+there are other changes inside subpatterns). If there is more than one setting
+of the same option at top level, the rightmost setting is used.
+
+If an option change occurs inside a subpattern, the effect is different. This
+is a change of behaviour in Perl 5.005. An option change inside a subpattern
+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 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 some very weird
+behaviour otherwise.
+
+The PCRE-specific options PCRE_UNGREEDY and PCRE_EXTRA can be changed in the
+same way as the Perl-compatible options by using the characters U and X
+respectively. The (?X) flag setting is special in that it must always occur
+earlier in the pattern than any of the additional features it turns on, even
+when it is at top level. It is best put at the start.
.SH SUBPATTERNS
@@ -770,38 +826,17 @@ the captured substrings are "white queen" and "queen", and are numbered 1 and
2. The maximum number of captured substrings is 99, and the maximum number of
all subpatterns, both capturing and non-capturing, is 200.
+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
-.SH 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 subpattern earlier
-(i.e. 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 if there have not been that many previous capturing left parentheses.
-See the section entitled "Backslash" above for further details of the handling
-of digits following a backslash.
-
-A back reference matches whatever actually matched the capturing subpattern in
-the current subject string, rather than anything matching the subpattern
-itself. So the pattern
-
- (sens|respons)e and \\1ibility
-
-matches "sense and sensibility" and "response and responsibility", but not
-"sense and responsibility".
+ (?i:saturday|sunday)
+ (?:(?i)saturday|sunday)
-There may be more than one back reference to the same subpattern. If a
-subpattern has not actually been used in a particular match, then any back
-references to it always fail. For example, the pattern
-
- (a|(bc))\\2
-
-always fails if it starts to match "a" rather than "bc". Because there may be
-up to 99 back references, all digits following the backslash are taken
-as part of a potential back reference number. If the pattern continues with a
-digit character, then some delimiter must be used to terminate the back
-reference. If the PCRE_EXTENDED option is set, this can be whitespace.
-Otherwise an empty comment can be used.
+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 "Saturday".
.SH REPETITION
@@ -811,8 +846,8 @@ items:
a single character, possibly escaped
the . metacharacter
a character class
- a back reference
- a parenthesized subpattern
+ a back reference (see next section)
+ a parenthesized subpattern (unless it is an assertion - see below)
The general repetition quantifier specifies a minimum and maximum number of
permitted matches, by giving the two numbers in curly brackets (braces),
@@ -834,7 +869,7 @@ matches at least 3 successive vowels, but may match many more, while
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 example, "{,6}" is not a
+quantifier, is taken as a literal character. For example, {,6} is not a
quantifier, but a literal string of four characters.
The quantifier {0} is permitted, causing the expression to behave as if the
@@ -847,6 +882,16 @@ quantifiers have single-character abbreviations:
+ is equivalent to {1,}
? is equivalent to {0,1}
+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 broken.
+
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
@@ -874,14 +919,14 @@ 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
+ \\d??\\d
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 which is not available in Perl)
then the quantifiers are not greedy by default, but individual ones can be made
-greedy by following they by a question mark. In other words, it inverts the
+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
@@ -893,20 +938,87 @@ follows will be tried against every character position in the subject string.
PCRE treats this as though it were preceded by \\A.
When a capturing subpattern is repeated, the value captured is the substring
-that matched the final iteration. For example,
+that matched the final iteration. For example, after
- (\s*tweedle[dume]{3})+\\1
+ (tweedle[dume]{3}\\s*)+
-matches "tweedledum tweedledee tweedledee" but not "tweedledum tweedledee
-tweedledum".
+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 iterations. For
+example, after
+
+ /(a|(b))+/
+
+matches "aba" the value of the second captured substring is "b".
+
+
+.SH 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 subpattern earlier
+(i.e. 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 pattern. In other words, the
+parentheses that are referenced need not be to the left of the reference for
+numbers less than 10. See the section entitled "Backslash" above for further
+details of the handling of digits following a backslash.
+
+A back reference matches whatever actually matched the capturing subpattern in
+the current subject string, rather than anything matching the subpattern
+itself. 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, then the case of letters is relevant. For example,
+
+ ((?i)rah)\\s+\\1
+
+matches "rah rah" and "RAH RAH", but not "RAH rah", even though the original
+capturing subpattern is matched caselessly.
+
+There may be more than one back reference to the same subpattern. If a
+subpattern has not actually been used in a particular match, then any back
+references to it always fail. For example, the pattern
+
+ (a|(bc))\\2
+
+always fails if it starts to match "a" rather than "bc". Because there may be
+up to 99 back references, all digits following the backslash are taken
+as part of a potential back reference number. If the pattern continues with a
+digit character, then some delimiter must be used to terminate the back
+reference. If the PCRE_EXTENDED option is set, this can be whitespace.
+Otherwise an empty comment can be used.
+
+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 subpatterns. For
+example, the pattern
+
+ (a|b\\1)+
+
+matches any number of "a"s and also "aba", "ababaa" etc. At each iteration 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.
.SH ASSERTIONS
-An assertion is a test on the characters following the current matching point
-that does not actually consume any of those characters. The simple assertions
-coded as \\b, \\B, \\A, \\Z, ^ and $ are described above. More complicated
-assertions are coded as subpatterns starting with (?= for positive assertions,
-and (?! for negative assertions. For example,
+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, \\Z, \\z, ^ and $ are described above. More
+complicated assertions are coded as subpatterns. There are two kinds: those
+that look ahead of the current position in the subject string, and those that
+look behind it.
+
+An assertion subpattern is matched in the normal way, except that it does not
+cause the current matching position to be changed. Lookahead assertions start
+with (?= for positive assertions and (?! for negative assertions. For example,
\\w+(?=;)
@@ -922,7 +1034,48 @@ apparently similar pattern
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".
+(?!foo) is always true when the next three characters are "bar". A
+lookbehind assertion is needed to achieve this effect.
+
+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 strings it matches must
+have a fixed length. However, if there are several alternatives, they do not
+all have to have the same fixed length. Thus
+
+ (?<=bullock|donkey)
+
+is permitted, but
+
+ (?<!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. This is an
+extension compared with Perl 5.005, which requires all branches to match the
+same length of string. An assertion such as
+
+ (?<=ab(c|de))
+
+is not permitted, because its single branch can match two different lengths,
+but it is acceptable if rewritten to use two branches:
+
+ (?<=abc|abde)
+
+The implementation of lookbehind assertions is, for each alternative, to
+temporarily move the current position back by the fixed width and then try to
+match. If there are insufficient characters before the current position, the
+match is deemed to fail.
+
+Assertions can be nested in any combination. For example,
+
+ (?<=(?<!foo)bar)baz
+
+matches an occurrence of "baz" that is preceded by "bar" which in turn is not
+preceded by "foo".
Assertion subpatterns are not capturing subpatterns, and may not be repeated,
because it makes no sense to assert the same thing several times. If an
@@ -935,19 +1088,16 @@ Assertions count towards the maximum of 200 parenthesized subpatterns.
.SH ONCE-ONLY SUBPATTERNS
-The facility described in this section is available only when the PCRE_EXTRA
-option is set at compile time. It is an extension to Perl regular expressions.
-
With both maximizing and minimizing 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
+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 line
- 123456bar
+ 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+
@@ -957,64 +1107,83 @@ has matched, it is not to be re-evaluated in this way, so the matcher would
give up immediately on failing to match "foo" the first time. The notation is
another kind of special parenthesis, starting with (?> as in this example:
- (?>\d+)bar
+ (?>\\d+)bar
This kind of parenthesis "locks up" the part of the pattern it contains 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.
-For simple cases such as the above example, this feature can be though of as a
-maximizing repeat that must swallow everything it can. So, while both \\d+ and
-\\d+? are prepared 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.
+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.
+
+Once-only subpatterns are not capturing subpatterns. Simple cases such as the
+above example can be though of as a maximizing repeat that must swallow
+everything it can. So, while both \\d+ and \\d+? are prepared 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.
This construction can of course contain arbitrarily complicated subpatterns,
-and it can be nested. Contrast with the \\X assertion, which is a Prolog-like
-"cut".
+and it can be nested.
-.SH COMMENTS
-The sequence (?# marks the start of a comment which continues up to the next
-closing parenthesis. Nested parentheses are not permitted. The characters
-that make up a comment play no part in the pattern matching at all.
+.SH CONDITIONAL SUBPATTERNS
+It is possible to cause the matching process to obey a subpattern
+conditionally or to choose between two alternative subpatterns, depending on
+the result of an assertion, or whether a previous capturing subpattern matched
+or not. The two possible forms of conditional subpattern are
-If the PCRE_EXTENDED option is set, an unescaped # character outside a
-character class introduces a comment that continues up to the next newline
-character in the pattern.
+ (?(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 alternatives in the
+subpattern, a compile-time error occurs.
-.SH INTERNAL FLAG SETTING
-If the sequence (?i) occurs anywhere in a pattern, it has the effect of setting
-the PCRE_CASELESS option, that is, all letters are matched in a
-case-independent manner. The option applies to the whole pattern, not just to
-the portion that follows it.
+There are two kinds of condition. If the text between the parentheses consists
+of a sequence of digits, then the condition is satisfied if the capturing
+subpattern of that number has previously matched. 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:
-If the sequence (?m) occurs anywhere in a pattern, it has the effect of setting
-the PCRE_MULTILINE option, that is, subject strings matched by this pattern are
-treated as consisting of multiple lines.
+ ( \\( )? [^()]+ (?(1) \\) )
-If the sequence (?s) occurs anywhere in a pattern, it has the effect of setting
-the PCRE_DOTALL option, so that dot metacharacters match newlines as well as
-all other characters.
+The first part matches an optional opening parenthesis, and if that
+character is present, sets it as the first captured substring. The second part
+matches one or more characters that are not parentheses. The third part is a
+conditional subpattern that tests whether the first set of parentheses matched
+or not. 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. Otherwise, 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 the sequence (?x) occurs anywhere in a pattern, it has the effect of setting
-the PCRE_EXTENDED option, that is, whitespace is ignored and # introduces a
-comment that lasts till the next newline. The option applies to the whole
-pattern, not just to the portion that follows it.
+If the condition is not a sequence of digits, it must be an assertion. This may
+be a positive or negative lookahead or lookbehind assertion. Consider this
+pattern, again containing non-significant white space, and with the two
+alternatives on the second line:
-If the sequence (?U) occurs anywhere in a pattern, it has the effect of setting
-the PCRE_UNGREEDY option which inverts the greediness of quantifiers. This is
-an extension to Perl's facilities.
+ (?(?=[^a-z]*[a-z])
+ \\d{2}[a-z]{3}-\\d{2} | \\d{2}-\\d{2}-\\d{2} )
-If the sequence (?X) occurs in a pattern, it has the effect of setting the
-PCRE_EXTRA flag, which turns on some additional features not found in Perl.
-This flag setting is special in that it must occur earlier in the pattern than
-any of the additional features. It is best put at the start.
+The condition is a positive lookahead assertion that matches an optional
+sequence of non-letters followed by a letter. In other words, it tests for the
+presence of at least one letter in the subject. If a letter is found, the
+subject is matched against the first alternative; otherwise it is matched
+against the second. This pattern matches strings in one of the two forms
+dd-aaa-dd or dd-dd-dd, where aaa are letters and dd are digits.
-If more than one option is required, they can be specified jointly, for example
-as (?ix) or (?mi).
+
+.SH COMMENTS
+The sequence (?# marks the start of a comment which continues up to the next
+closing parenthesis. Nested parentheses are not permitted. The characters
+that make up a comment play no part in the pattern matching at all.
+
+If the PCRE_EXTENDED option is set, an unescaped # character outside a
+character class introduces a comment that continues up to the next newline
+character in the pattern.
.SH PERFORMANCE
@@ -1025,10 +1194,6 @@ required behaviour is usually the most efficient. Jeffrey Friedl's book
contains a lot of discussion about optimizing regular expressions for efficient
performance.
-The use of PCRE_MULTILINE causes additional processing and should be avoided
-when it is not necessary. Caseless matching of character classes is more
-efficient if PCRE_CASELESS is set when the pattern is compiled.
-
.SH AUTHOR
Philip Hazel <ph10@cam.ac.uk>
diff --git a/pcre.c b/pcre.c
index 862834b..521061b 100644
--- a/pcre.c
+++ b/pcre.c
@@ -33,9 +33,9 @@ restrictions:
/* #define DEBUG */
-/* Use a macro for debugging printing, 'cause that eliminates the the use
-of #ifdef inline, and there are *still* stupid compilers about that don't like
-indented pre-processor statements. I suppose it's only been 10 years... */
+/* Use a macro for debugging printing, 'cause that eliminates the use of #ifdef
+inline, and there are *still* stupid compilers about that don't like indented
+pre-processor statements. I suppose it's only been 10 years... */
#ifdef DEBUG
#define DPRINTF(p) printf p
@@ -56,6 +56,12 @@ the external pcre header. */
#endif
+/* Number of items on the nested bracket stacks at compile time. This should
+not be set greater than 200. */
+
+#define BRASTACK_SIZE 200
+
+
/* Min and max values for the common repeats; for the maxima, 0 => infinity */
static const char rep_min[] = { 0, 0, 1, 1, 0, 0 };
@@ -66,14 +72,15 @@ static const char rep_max[] = { 0, 0, 0, 0, 1, 1 };
#ifdef DEBUG
static const char *OP_names[] = {
"End", "\\A", "\\B", "\\b", "\\D", "\\d",
- "\\S", "\\s", "\\W", "\\w", "Cut", "\\Z", "^", "$", "Any", "chars",
- "not",
+ "\\S", "\\s", "\\W", "\\w", "\\Z", "\\z",
+ "Opt", "^", "$", "Any", "chars", "not",
"*", "*?", "+", "+?", "?", "??", "{", "{", "{",
"*", "*?", "+", "+?", "?", "??", "{", "{", "{",
"*", "*?", "+", "+?", "?", "??", "{", "{", "{",
"*", "*?", "+", "+?", "?", "??", "{", "{",
- "class", "negclass", "Ref",
- "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", "Once",
+ "class", "Ref",
+ "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not",
+ "AssertB", "AssertB not", "Reverse", "Once", "Cond", "Cref",
"Brazero", "Braminzero", "Bra"
};
#endif
@@ -93,13 +100,14 @@ static const short int escapes[] = {
'`', 7, -ESC_b, 0, -ESC_d, 27, '\f', 0, /* ` - g */
0, 0, 0, 0, 0, 0, '\n', 0, /* h - o */
0, 0, '\r', -ESC_s, '\t', 0, 0, -ESC_w, /* p - w */
- 0, 0, 0 /* x - z */
+ 0, 0, -ESC_z /* x - z */
};
/* Definition to allow mutual recursion */
static BOOL
- compile_regex(int, int *, uschar **, const uschar **, const char **);
+ compile_regex(int, int, int *, uschar **, const uschar **, const char **,
+ BOOL, int);
/* Structure for passing "static" information around between the functions
doing the matching, so that they are thread-safe. */
@@ -108,17 +116,13 @@ typedef struct match_data {
int errorcode; /* As it says */
int *offset_vector; /* Offset vector */
int offset_end; /* One past the end */
+ int offset_max; /* The maximum usable for return data */
BOOL offset_overflow; /* Set if too many extractions */
- BOOL caseless; /* Case-independent flag */
- BOOL runtime_caseless; /* Caseless forced at run time */
- BOOL multiline; /* Multiline flag */
BOOL notbol; /* NOTBOL flag */
BOOL noteol; /* NOTEOL flag */
- BOOL dotall; /* Dot matches any char */
BOOL endonly; /* Dollar not before final \n */
const uschar *start_subject; /* Start of the subject string */
const uschar *end_subject; /* End of the subject string */
- jmp_buf fail_env; /* Environment for longjump() break out */
const uschar *end_match_ptr; /* Subject position at end match */
int end_offset_top; /* Highwater mark at end of match */
} match_data;
@@ -218,151 +222,6 @@ while (length-- > 0)
/*************************************************
-* Check subpattern for empty operand *
-*************************************************/
-
-/* This function checks a bracketed subpattern to see if any of the paths
-through it could match an empty string. This is used to diagnose an error if
-such a subpattern is followed by a quantifier with an unlimited upper bound.
-
-Argument:
- code points to the opening bracket
-
-Returns: TRUE or FALSE
-*/
-
-static BOOL
-could_be_empty(uschar *code)
-{
-do {
- uschar *cc = code + 3;
-
- /* Scan along the opcodes for this branch; as soon as we find something
- that matches a non-empty string, break out and advance to test the next
- branch. If we get to the end of the branch, return TRUE for the whole
- sub-expression. */
-
- for (;;)
- {
- /* Test an embedded subpattern; if it could not be empty, break the
- loop. Otherwise carry on in the branch. */
-
- if ((int)(*cc) >= OP_BRA || (int)(*cc) == OP_ONCE)
- {
- if (!could_be_empty(cc)) break;
- do cc += (cc[1] << 8) + cc[2]; while (*cc == OP_ALT);
- cc += 3;
- }
-
- else switch (*cc)
- {
- /* Reached end of a branch: the subpattern may match the empty string */
-
- case OP_ALT:
- case OP_KET:
- case OP_KETRMAX:
- case OP_KETRMIN:
- return TRUE;
-
- /* Skip over entire bracket groups with zero lower bound */
-
- case OP_BRAZERO:
- case OP_BRAMINZERO:
- cc++;
- /* Fall through */
-
- /* Skip over assertive subpatterns */
-
- case OP_ASSERT:
- case OP_ASSERT_NOT:
- do cc += (cc[1] << 8) + cc[2]; while (*cc == OP_ALT);
- cc += 3;
- break;
-
- /* Skip over things that don't match chars */
-
- case OP_SOD:
- case OP_EOD:
- case OP_CIRC:
- case OP_DOLL:
- case OP_NOT_WORD_BOUNDARY:
- case OP_WORD_BOUNDARY:
- cc++;
- break;
-
- /* Skip over simple repeats with zero lower bound */
-
- case OP_STAR:
- case OP_MINSTAR:
- case OP_QUERY:
- case OP_MINQUERY:
- case OP_NOTSTAR:
- case OP_NOTMINSTAR:
- case OP_NOTQUERY:
- case OP_NOTMINQUERY:
- case OP_TYPESTAR:
- case OP_TYPEMINSTAR:
- case OP_TYPEQUERY:
- case OP_TYPEMINQUERY:
- cc += 2;
- break;
-
- /* Skip over UPTOs (lower bound is zero) */
-
- case OP_UPTO:
- case OP_MINUPTO:
- case OP_TYPEUPTO:
- case OP_TYPEMINUPTO:
- cc += 4;
- break;
-
- /* Check a class or a back reference for a zero minimum */
-
- case OP_CLASS:
- case OP_NEGCLASS:
- case OP_REF:
- cc += (*cc == OP_REF)? 2 : 33;
-
- switch (*cc)
- {
- case OP_CRSTAR:
- case OP_CRMINSTAR:
- case OP_CRQUERY:
- case OP_CRMINQUERY:
- cc++;
- break;
-
- case OP_CRRANGE:
- case OP_CRMINRANGE:
- if ((cc[1] << 8) + cc[2] != 0) goto NEXT_BRANCH;
- cc += 3;
- break;
-
- default:
- goto NEXT_BRANCH;
- }
- break;
-
- /* Anything else matches at least one character */
-
- default:
- goto NEXT_BRANCH;
- }
- }
-
- NEXT_BRANCH:
- code += (code[1] << 8) + code[2];
- }
-while (*code == OP_ALT);
-
-/* No branches match the empty string */
-
-return FALSE;
-}
-
-
-
-/*************************************************
* Handle escapes *
*************************************************/
@@ -493,10 +352,6 @@ else
default:
if ((options & PCRE_EXTRA) != 0) switch(c)
{
- case 'X':
- c = -ESC_X; /* This could be a lookup if it ever got into Perl */
- break;
-
default:
*errorptr = ERR3;
break;
@@ -600,25 +455,180 @@ return p;
/*************************************************
+* Find the fixed length of a pattern *
+*************************************************/
+
+/* Scan a pattern and compute the fixed length of subject that will match it,
+if the length is fixed. This is needed for dealing with backward assertions.
+
+Arguments:
+ code points to the start of the pattern (the bracket)
+
+Returns: the fixed length, or -1 if there is no fixed length
+*/
+
+static int
+find_fixedlength(uschar *code)
+{
+int length = -1;
+
+register int branchlength = 0;
+register uschar *cc = code + 3;
+
+/* Scan along the opcodes for this branch. If we get to the end of the
+branch, check the length against that of the other branches. */
+
+for (;;)
+ {
+ int d;
+ register int op = *cc;
+ if (op >= OP_BRA) op = OP_BRA;
+
+ switch (op)
+ {
+ case OP_BRA:
+ case OP_ONCE:
+ case OP_COND:
+ d = find_fixedlength(cc);
+ if (d < 0) return -1;
+ branchlength += d;
+ do cc += (cc[1] << 8) + cc[2]; while (*cc == OP_ALT);
+ cc += 3;
+ break;
+
+ /* Reached end of a branch; if it's a ket it is the end of a nested
+ call. If it's ALT it is an alternation in a nested call. If it is
+ END it's the end of the outer call. All can be handled by the same code. */
+
+ case OP_ALT:
+ case OP_KET:
+ case OP_KETRMAX:
+ case OP_KETRMIN:
+ case OP_END:
+ if (length < 0) length = branchlength;
+ else if (length != branchlength) return -1;
+ if (*cc != OP_ALT) return length;
+ cc += 3;
+ branchlength = 0;
+ break;
+
+ /* Skip over assertive subpatterns */
+
+ case OP_ASSERT:
+ case OP_ASSERT_NOT:
+ case OP_ASSERTBACK:
+ case OP_ASSERTBACK_NOT:
+ do cc += (cc[1] << 8) + cc[2]; while (*cc == OP_ALT);
+ cc += 3;
+ break;
+
+ /* Skip over things that don't match chars */
+
+ case OP_REVERSE:
+ cc++;
+
+ case OP_CREF:
+ case OP_OPT:
+ cc++;
+ /* Fall through */
+
+ case OP_SOD:
+ case OP_EOD:
+ case OP_EODN:
+ case OP_CIRC:
+ case OP_DOLL:
+ case OP_NOT_WORD_BOUNDARY:
+ case OP_WORD_BOUNDARY:
+ cc++;
+ break;
+
+ /* Handle char strings */
+
+ case OP_CHARS:
+ branchlength += *(++cc);
+ cc += *cc + 1;
+ break;
+
+ /* Handle exact repetitions */
+
+ case OP_EXACT:
+ case OP_TYPEEXACT:
+ branchlength += (cc[1] << 8) + cc[2];
+ cc += 4;
+ break;
+
+ /* Handle single-char matchers */
+
+ case OP_NOT_DIGIT:
+ case OP_DIGIT:
+ case OP_NOT_WHITESPACE:
+ case OP_WHITESPACE:
+ case OP_NOT_WORDCHAR:
+ case OP_WORDCHAR:
+ case OP_ANY:
+ branchlength++;
+ cc++;
+ break;
+
+
+ /* Check a class for variable quantification */
+
+ case OP_CLASS:
+ cc += (*cc == OP_REF)? 2 : 33;
+
+ switch (*cc)
+ {
+ case OP_CRSTAR:
+ case OP_CRMINSTAR:
+ case OP_CRQUERY:
+ case OP_CRMINQUERY:
+ return -1;
+
+ case OP_CRRANGE:
+ case OP_CRMINRANGE:
+ if ((cc[1] << 8) + cc[2] != (cc[3] << 8) + cc[4]) return -1;
+ branchlength += (cc[1] << 8) + cc[2];
+ cc += 5;
+ break;
+
+ default:
+ branchlength++;
+ }
+ break;
+
+ /* Anything else is variable length */
+
+ default:
+ return -1;
+ }
+ }
+/* Control never gets here */
+}
+
+
+
+
+/*************************************************
* Compile one branch *
*************************************************/
/* Scan the pattern, compiling it into the code vector.
Arguments:
- options the option bits
- bracket points to number of brackets used
- code points to the pointer to the current code point
- ptrptr points to the current pattern pointer
- errorptr points to pointer to error message
-
-Returns: TRUE on success
- FALSE, with *errorptr set on error
+ options the option bits
+ brackets points to number of brackets used
+ code points to the pointer to the current code point
+ ptrptr points to the current pattern pointer
+ errorptr points to pointer to error message
+ optchanged set to the value of the last OP_OPT item compiled
+
+Returns: TRUE on success
+ FALSE, with *errorptr set on error
*/
static BOOL
compile_branch(int options, int *brackets, uschar **codeptr,
- const uschar **ptrptr, const char **errorptr)
+ const uschar **ptrptr, const char **errorptr, int *optchanged)
{
int repeat_type, op_type;
int repeat_min, repeat_max;
@@ -626,8 +636,9 @@ int bravalue, length;
int greedy_default, greedy_non_default;
register int c;
register uschar *code = *codeptr;
+uschar *tempcode;
const uschar *ptr = *ptrptr;
-const uschar *oldptr;
+const uschar *tempptr;
uschar *previous = NULL;
uschar class[32];
@@ -641,8 +652,10 @@ greedy_non_default = greedy_default ^ 1;
for (;; ptr++)
{
BOOL negate_class;
- int class_charcount;
- int class_lastchar;
+ int class_charcount;
+ int class_lastchar;
+ int newoptions;
+ int condref;
c = *ptr;
if ((options & PCRE_EXTENDED) != 0)
@@ -690,22 +703,16 @@ for (;; ptr++)
case '[':
previous = code;
+ *code++ = OP_CLASS;
- /* If the first character is '^', set the negation flag, and use a
- different opcode. This only matters if caseless matching is specified at
- runtime. */
+ /* If the first character is '^', set the negation flag and skip it. */
if ((c = *(++ptr)) == '^')
{
negate_class = TRUE;
- *code++ = OP_NEGCLASS;
c = *(++ptr);
}
- else
- {
- negate_class = FALSE;
- *code++ = OP_CLASS;
- }
+ else negate_class = FALSE;
/* Keep a count of chars so that we can optimize the case of just a single
character. */
@@ -964,7 +971,7 @@ for (;; ptr++)
create a suitable repeat item. The code is shared with single-character
repeats by adding a suitable offset into repeat_type. */
- else if ((int)*previous < OP_EOD || *previous == OP_ANY)
+ else if ((int)*previous < OP_EODN || *previous == OP_ANY)
{
op_type = OP_TYPESTAR - OP_STAR; /* Use type opcodes */
c = *previous;
@@ -1050,8 +1057,7 @@ for (;; ptr++)
/* If previous was a character class or a back reference, we put the repeat
stuff after it. */
- else if (*previous == OP_CLASS || *previous == OP_NEGCLASS ||
- *previous == OP_REF)
+ else if (*previous == OP_CLASS || *previous == OP_REF)
{
if (repeat_min == 0 && repeat_max == -1)
*code++ = OP_CRSTAR + repeat_type;
@@ -1071,18 +1077,25 @@ for (;; ptr++)
}
/* If previous was a bracket group, we may have to replicate it in certain
- cases. If the maximum repeat count is unlimited, check that the bracket
- group cannot match the empty string, and diagnose an error if it can. */
+ cases. */
- else if ((int)*previous >= OP_BRA)
+ else if ((int)*previous >= OP_BRA || (int)*previous == OP_ONCE ||
+ (int)*previous == OP_COND)
{
- int i;
+ int i, ketoffset = 0;
int len = code - previous;
- if (repeat_max == -1 && could_be_empty(previous))
+ /* If the maximum repeat count is unlimited, find the end of the bracket
+ by scanning through from the start, and compute the offset back to it
+ from the current code pointer. There may be an OP_OPT setting following
+ the final KET, so we can't find the end just by going back from the code
+ pointer. */
+
+ if (repeat_max == -1)
{
- *errorptr = ERR10;
- goto FAILED;
+ register uschar *ket = previous;
+ do ket += (ket[1] << 8) + ket[2]; while (*ket != OP_KET);
+ ketoffset = code - ket;
}
/* If the minimum is greater than zero, and the maximum is unlimited or
@@ -1126,9 +1139,12 @@ for (;; ptr++)
}
}
- /* If the maximum is unlimited, set a repeater in the final copy. */
+ /* If the maximum is unlimited, set a repeater in the final copy. We
+ can't just offset backwards from the current code point, because we
+ don't know if there's been an options resetting after the ket. The
+ correct offset was computed above. */
- if (repeat_max == -1) code[-3] = OP_KETRMAX + repeat_type;
+ if (repeat_max == -1) code[-ketoffset] = OP_KETRMAX + repeat_type;
}
/* Else there's some kind of shambles */
@@ -1145,65 +1161,139 @@ for (;; ptr++)
break;
- /* Start of nested bracket sub-expression, or comment or lookahead.
- First deal with special things that can come after a bracket; all are
- introduced by ?, and the appearance of any of them means that this is not a
- referencing group. They were checked for validity in the first pass over
- the string, so we don't have to check for syntax errors here. */
+ /* Start of nested bracket sub-expression, or comment or lookahead or
+ lookbehind or option setting or condition. First deal with special things
+ that can come after a bracket; all are introduced by ?, and the appearance
+ of any of them means that this is not a referencing group. They were
+ checked for validity in the first pass over the string, so we don't have to
+ check for syntax errors here. */
case '(':
- previous = code; /* Only real brackets can be repeated */
+ newoptions = options;
+ condref = -1;
+
if (*(++ptr) == '?')
{
- bravalue = OP_BRA;
+ int set, unset;
+ int *optset;
switch (*(++ptr))
{
- case '#':
- case 'i':
- case 'm':
- case 's':
- case 'x':
- case 'U':
- case 'X':
+ case '#': /* Comment; skip to ket */
ptr++;
while (*ptr != ')') ptr++;
- previous = NULL;
continue;
case ':': /* Non-extracting bracket */
+ bravalue = OP_BRA;
ptr++;
break;
- case '=': /* Assertions can't be repeated */
+ case '(':
+ bravalue = OP_COND; /* Conditional group */
+ if ((pcre_ctypes[*(++ptr)] & ctype_digit) != 0)
+ {
+ condref = *ptr - '0';
+ while (*(++ptr) != ')') condref = condref*10 + *ptr - '0';
+ ptr++;
+ }
+ else ptr--;
+ break;
+
+ case '=': /* Positive lookahead */
bravalue = OP_ASSERT;
ptr++;
- previous = NULL;
break;
- case '!':
+ case '!': /* Negative lookahead */
bravalue = OP_ASSERT_NOT;
ptr++;
- previous = NULL;
break;
- case '>': /* "Match once" brackets */
- if ((options & PCRE_EXTRA) != 0) /* Not yet standard */
+ case '<': /* Lookbehinds */
+ switch (*(++ptr))
{
- bravalue = OP_ONCE;
+ case '=': /* Positive lookbehind */
+ bravalue = OP_ASSERTBACK;
+ ptr++;
+ break;
+
+ case '!': /* Negative lookbehind */
+ bravalue = OP_ASSERTBACK_NOT;
ptr++;
- previous = NULL;
break;
+
+ default: /* Syntax error */
+ *errorptr = ERR24;
+ goto FAILED;
}
- /* Else fall through */
+ break;
- default:
- *errorptr = ERR12;
- goto FAILED;
+ case '>': /* One-time brackets */
+ bravalue = OP_ONCE;
+ ptr++;
+ break;
+
+ default: /* Option setting */
+ set = unset = 0;
+ optset = &set;
+
+ while (*ptr != ')' && *ptr != ':')
+ {
+ switch (*ptr++)
+ {
+ case '-': optset = &unset; break;
+
+ case 'i': *optset |= PCRE_CASELESS; break;
+ case 'm': *optset |= PCRE_MULTILINE; break;
+ case 's': *optset |= PCRE_DOTALL; break;
+ case 'x': *optset |= PCRE_EXTENDED; break;
+ case 'U': *optset |= PCRE_UNGREEDY; break;
+ case 'X': *optset |= PCRE_EXTRA; break;
+
+ default:
+ *errorptr = ERR12;
+ goto FAILED;
+ }
+ }
+
+ /* Set up the changed option bits, but don't change anything yet. */
+
+ newoptions = (options | set) & (~unset);
+
+ /* If the options ended with ')' this is not the start of a nested
+ group with option changes, so the options change at this level. At top
+ level there is nothing else to be done (the options will in fact have
+ been set from the start of compiling as a result of the first pass) but
+ at an inner level we must compile code to change the ims options if
+ necessary, and pass the new setting back so that it can be put at the
+ start of any following branches, and when this group ends, a resetting
+ item can be compiled. */
+
+ if (*ptr == ')')
+ {
+ if ((options & PCRE_INGROUP) != 0 &&
+ (options & PCRE_IMS) != (newoptions & PCRE_IMS))
+ {
+ *code++ = OP_OPT;
+ *code++ = *optchanged = newoptions & PCRE_IMS;
+ }
+ options = newoptions; /* Change options at this level */
+ previous = NULL; /* This item can't be repeated */
+ continue; /* It is complete */
+ }
+
+ /* If the options ended with ':' we are heading into a nested group
+ with possible change of options. Such groups are non-capturing and are
+ not assertions of any kind. All we need to do is skip over the ':';
+ the newoptions value is handled below. */
+
+ bravalue = OP_BRA;
+ ptr++;
}
}
- /* Else we have a referencing group */
+ /* Else we have a referencing group; adjust the opcode. */
else
{
@@ -1215,18 +1305,60 @@ for (;; ptr++)
bravalue = OP_BRA + *brackets;
}
- /* Process nested bracketed re; at end pointer is on the bracket. We copy
- code into a non-register variable in order to be able to pass its address
- because some compilers complain otherwise. */
+ /* Process nested bracketed re. Assertions may not be repeated, but other
+ kinds can be. We copy code into a non-register variable in order to be able
+ to pass its address because some compilers complain otherwise. Pass in a
+ new setting for the ims options if they have changed. */
+ previous = (bravalue >= OP_ONCE)? code : NULL;
*code = bravalue;
+ tempcode = code;
+
+ if (!compile_regex(
+ options | PCRE_INGROUP, /* Set for all nested groups */
+ ((options & PCRE_IMS) != (newoptions & PCRE_IMS))?
+ newoptions & PCRE_IMS : -1, /* Pass ims options if changed */
+ brackets, /* Bracket level */
+ &tempcode, /* Where to put code (updated) */
+ &ptr, /* Input pointer (updated) */
+ errorptr, /* Where to put an error message */
+ (bravalue == OP_ASSERTBACK ||
+ bravalue == OP_ASSERTBACK_NOT), /* TRUE if back assert */
+ condref)) /* Condition reference number */
+ goto FAILED;
+
+ /* At the end of compiling, code is still pointing to the start of the
+ group, while tempcode has been updated to point past the end of the group
+ and any option resetting that may follow it. The pattern pointer (ptr)
+ is on the bracket. */
+
+ /* If this is a conditional bracket, check that there are no more than
+ two branches in the group. */
+
+ if (bravalue == OP_COND)
{
- uschar *mcode = code;
- if (!compile_regex(options, brackets, &mcode, &ptr, errorptr))
+ int branchcount = 0;
+ uschar *tc = code;
+
+ do {
+ branchcount++;
+ tc += (tc[1] << 8) | tc[2];
+ }
+ while (*tc != OP_KET);
+
+ if (branchcount > 2)
+ {
+ *errorptr = ERR27;
goto FAILED;
- code = mcode;
+ }
}
+ /* Now update the main code pointer to the end of the group. */
+
+ code = tempcode;
+
+ /* Error if hit end of pattern */
+
if (*ptr != ')')
{
*errorptr = ERR14;
@@ -1239,7 +1371,7 @@ for (;; ptr++)
for validity in the pre-compiling pass. */
case '\\':
- oldptr = ptr;
+ tempptr = ptr;
c = check_escape(&ptr, errorptr, *brackets, options, FALSE);
/* Handle metacharacters introduced by \. For ones like \d, the ESC_ values
@@ -1253,19 +1385,13 @@ for (;; ptr++)
{
if (-c >= ESC_REF)
{
- int refnum = -c - ESC_REF;
- if (*brackets < refnum)
- {
- *errorptr = ERR15;
- goto FAILED;
- }
previous = code;
*code++ = OP_REF;
- *code++ = refnum;
+ *code++ = -c - ESC_REF;
}
else
{
- previous = (-c > ESC_b && -c < ESC_X)? code : NULL;
+ previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;
*code++ = -c;
}
continue;
@@ -1273,7 +1399,7 @@ for (;; ptr++)
/* Data character: reset and fall through */
- ptr = oldptr;
+ ptr = tempptr;
c = '\\';
/* Handle a run of data characters until a metacharacter is encountered.
@@ -1306,9 +1432,9 @@ for (;; ptr++)
if (c == '\\')
{
- oldptr = ptr;
+ tempptr = ptr;
c = check_escape(&ptr, errorptr, *brackets, options, FALSE);
- if (c < 0) { ptr = oldptr; break; }
+ if (c < 0) { ptr = tempptr; break; }
}
/* Ordinary character or single-char escape */
@@ -1349,33 +1475,75 @@ return FALSE;
/* On entry, ptr is pointing past the bracket character, but on return
it points to the closing bracket, or vertical bar, or end of string.
The code variable is pointing at the byte into which the BRA operator has been
-stored.
+stored. If the ims options are changed at the start (for a (?ims: group) or
+during any branch, we need to insert an OP_OPT item at the start of every
+following branch to ensure they get set correctly at run time, and also pass
+the new options into every subsequent branch compile.
Argument:
- options the option bits
- brackets -> int containing the number of extracting brackets used
- codeptr -> the address of the current code pointer
- ptrptr -> the address of the current pattern pointer
- errorptr -> pointer to error message
-
-Returns: TRUE on success
+ options the option bits
+ optchanged new ims options to set as if (?ims) were at the start, or -1
+ for no change
+ brackets -> int containing the number of extracting brackets used
+ codeptr -> the address of the current code pointer
+ ptrptr -> the address of the current pattern pointer
+ errorptr -> pointer to error message
+ lookbehind TRUE if this is a lookbehind assertion
+ condref > 0 for OPT_CREF setting at start of conditional group
+
+Returns: TRUE on success
*/
static BOOL
-compile_regex(int options, int *brackets, uschar **codeptr,
- const uschar **ptrptr, const char **errorptr)
+compile_regex(int options, int optchanged, int *brackets, uschar **codeptr,
+ const uschar **ptrptr, const char **errorptr, BOOL lookbehind, int condref)
{
const uschar *ptr = *ptrptr;
uschar *code = *codeptr;
+uschar *last_branch = code;
uschar *start_bracket = code;
+uschar *reverse_count = NULL;
+int oldoptions = options & PCRE_IMS;
+
+code += 3;
+
+/* At the start of a reference-based conditional group, insert the reference
+number as an OP_CREF item. */
+
+if (condref > 0)
+ {
+ *code++ = OP_CREF;
+ *code++ = condref;
+ }
+
+/* Loop for each alternative branch */
for (;;)
{
int length;
- uschar *last_branch = code;
- code += 3;
- if (!compile_branch(options, brackets, &code, &ptr, errorptr))
+ /* Handle change of options */
+
+ if (optchanged >= 0)
+ {
+ *code++ = OP_OPT;
+ *code++ = optchanged;
+ options = (options & ~PCRE_IMS) | optchanged;
+ }
+
+ /* Set up dummy OP_REVERSE if lookbehind assertion */
+
+ if (lookbehind)
+ {
+ *code++ = OP_REVERSE;
+ reverse_count = code;
+ *code++ = 0;
+ *code++ = 0;
+ }
+
+ /* Now compile the branch */
+
+ if (!compile_branch(options, brackets, &code, &ptr, errorptr, &optchanged))
{
*ptrptr = ptr;
return FALSE;
@@ -1387,9 +1555,29 @@ for (;;)
last_branch[1] = length >> 8;
last_branch[2] = length & 255;
+ /* If lookbehind, check that this branch matches a fixed-length string,
+ and put the length into the OP_REVERSE item. Temporarily mark the end of
+ the branch with OP_END. */
+
+ if (lookbehind)
+ {
+ *code = OP_END;
+ length = find_fixedlength(last_branch);
+ DPRINTF(("fixed length = %d\n", length));
+ if (length < 0)
+ {
+ *errorptr = ERR25;
+ *ptrptr = ptr;
+ return FALSE;
+ }
+ reverse_count[0] = (length >> 8);
+ reverse_count[1] = length & 255;
+ }
+
/* Reached end of expression, either ')' or end of pattern. Insert a
terminating ket and the length of the whole bracketed item, and return,
- leaving the pointer at the terminating char. */
+ leaving the pointer at the terminating char. If any of the ims options
+ were changed inside the group, compile a resetting op-code following. */
if (*ptr != '|')
{
@@ -1397,6 +1585,11 @@ for (;;)
*code++ = OP_KET;
*code++ = length >> 8;
*code++ = length & 255;
+ if (optchanged >= 0)
+ {
+ *code++ = OP_OPT;
+ *code++ = oldoptions;
+ }
*codeptr = code;
*ptrptr = ptr;
return TRUE;
@@ -1405,6 +1598,8 @@ for (;;)
/* Another branch follows; insert an "or" node and advance the pointer. */
*code = OP_ALT;
+ last_branch = code;
+ code += 3;
ptr++;
}
/* Control never reaches here */
@@ -1412,6 +1607,65 @@ for (;;)
+
+/*************************************************
+* Find first significant op code *
+*************************************************/
+
+/* This is called by several functions that scan a compiled expression looking
+for a fixed first character, or an anchoring op code etc. It skips over things
+that do not influence this. For one application, a change of caseless option is
+important.
+
+Arguments:
+ code pointer to the start of the group
+ options pointer to external options
+ optbit the option bit whose changing is significant, or
+ zero if none are
+ optstop TRUE to return on option change, otherwise change the options
+ value and continue
+
+Returns: pointer to the first significant opcode
+*/
+
+static const uschar*
+first_significant_code(const uschar *code, int *options, int optbit,
+ BOOL optstop)
+{
+for (;;)
+ {
+ switch ((int)*code)
+ {
+ case OP_OPT:
+ if (optbit > 0 && ((int)code[1] & optbit) != (*options & optbit))
+ {
+ if (optstop) return code;
+ *options = (int)code[1];
+ }
+ code += 2;
+ break;
+
+ case OP_CREF:
+ code += 2;
+ break;
+
+ case OP_ASSERT_NOT:
+ case OP_ASSERTBACK:
+ case OP_ASSERTBACK_NOT:
+ do code += (code[1] << 8) + code[2]; while (*code == OP_ALT);
+ code += 3;
+ break;
+
+ default:
+ return code;
+ }
+ }
+/* Control never reaches here */
+}
+
+
+
+
/*************************************************
* Check for anchored expression *
*************************************************/
@@ -1426,20 +1680,27 @@ A branch is also implicitly anchored if it starts with .* because that will try
the rest of the pattern at all possible matching points, so there is no point
trying them again.
-Argument: points to start of expression (the bracket)
-Returns: TRUE or FALSE
+Arguments:
+ code points to start of expression (the bracket)
+ options points to the options setting
+
+Returns: TRUE or FALSE
*/
static BOOL
-is_anchored(register const uschar *code, BOOL multiline)
+is_anchored(register const uschar *code, int *options)
{
do {
- int op = (int)code[3];
- if (op >= OP_BRA || op == OP_ASSERT || op == OP_ONCE)
- { if (!is_anchored(code+3, multiline)) return FALSE; }
+ const uschar *scode = first_significant_code(code + 3, options,
+ PCRE_MULTILINE, FALSE);
+ register int op = *scode;
+ if (op >= OP_BRA || op == OP_ASSERT || op == OP_ONCE || op == OP_COND)
+ { if (!is_anchored(scode, options)) return FALSE; }
else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR)
- { if (code[4] != OP_ANY) return FALSE; }
- else if (op != OP_SOD && (multiline || op != OP_CIRC)) return FALSE;
+ { if (scode[1] != OP_ANY) return FALSE; }
+ else if (op != OP_SOD &&
+ ((*options & PCRE_MULTILINE) != 0 || op != OP_CIRC))
+ return FALSE;
code += (code[1] << 8) + code[2];
}
while (*code == OP_ALT);
@@ -1463,9 +1724,11 @@ static BOOL
is_startline(const uschar *code)
{
do {
- if ((int)code[3] >= OP_BRA || code[3] == OP_ASSERT)
- { if (!is_startline(code+3)) return FALSE; }
- else if (code[3] != OP_CIRC) return FALSE;
+ const uschar *scode = first_significant_code(code + 3, NULL, 0, FALSE);
+ register int op = *scode;
+ if (op >= OP_BRA || op == OP_ASSERT || op == OP_ONCE || op == OP_COND)
+ { if (!is_startline(scode)) return FALSE; }
+ else if (op != OP_CIRC) return FALSE;
code += (code[1] << 8) + code[2];
}
while (*code == OP_ALT);
@@ -1484,49 +1747,60 @@ Consider each alternative branch. If they all start with the same char, or with
a bracket all of whose alternatives start with the same char (recurse ad lib),
then we return that char, otherwise -1.
-Argument: points to start of expression (the bracket)
-Returns: -1 or the fixed first char
+Arguments:
+ code points to start of expression (the bracket)
+ options pointer to the options (used to check casing changes)
+
+Returns: -1 or the fixed first char
*/
static int
-find_firstchar(uschar *code)
+find_firstchar(const uschar *code, int *options)
{
register int c = -1;
-do
- {
- register int charoffset = 4;
-
- if ((int)code[3] >= OP_BRA || code[3] == OP_ASSERT)
- {
- register int d;
- if ((d = find_firstchar(code+3)) < 0) return -1;
- if (c < 0) c = d; else if (c != d) return -1;
- }
-
- else switch(code[3])
- {
- default:
- return -1;
-
- case OP_EXACT: /* Fall through */
- charoffset++;
-
- case OP_CHARS: /* Fall through */
- charoffset++;
+do {
+ int d;
+ const uschar *scode = first_significant_code(code + 3, options,
+ PCRE_CASELESS, TRUE);
+ register int op = *scode;
+
+ if (op >= OP_BRA) op = OP_BRA;
+
+ switch(op)
+ {
+ default:
+ return -1;
+
+ case OP_BRA:
+ case OP_ASSERT:
+ case OP_ONCE:
+ case OP_COND:
+ if ((d = find_firstchar(scode, options)) < 0) return -1;
+ if (c < 0) c = d; else if (c != d) return -1;
+ break;
+
+ case OP_EXACT: /* Fall through */
+ scode++;
+
+ case OP_CHARS: /* Fall through */
+ scode++;
+
+ case OP_PLUS:
+ case OP_MINPLUS:
+ if (c < 0) c = scode[1]; else if (c != scode[1]) return -1;
+ break;
+ }
- case OP_PLUS:
- case OP_MINPLUS:
- if (c < 0) c = code[charoffset]; else if (c != code[charoffset]) return -1;
- break;
- }
- code += (code[1] << 8) + code[2];
- }
+ code += (code[1] << 8) + code[2];
+ }
while (*code == OP_ALT);
return c;
}
+
+
/*************************************************
* Compile a Regular Expression *
*************************************************/
@@ -1549,16 +1823,18 @@ pcre_compile(const char *pattern, int options, const char **errorptr,
int *erroroffset)
{
real_pcre *re;
-int spaces = 0;
int length = 3; /* For initial BRA plus length */
int runlength;
int c, size;
int bracount = 0;
-int brastack[200];
int top_backref = 0;
+int branch_extra = 0;
+int branch_newextra;
unsigned int brastackptr = 0;
uschar *code;
const uschar *ptr;
+int brastack[BRASTACK_SIZE];
+uschar bralenstack[BRASTACK_SIZE];
#ifdef DEBUG
uschar *code_base, *code_end;
@@ -1601,16 +1877,14 @@ while ((c = *(++ptr)) != 0)
int min, max;
int class_charcount;
- if ((pcre_ctypes[c] & ctype_space) != 0)
- {
- if ((options & PCRE_EXTENDED) != 0) continue;
- spaces++;
- }
-
- if (c == '#' && (options & PCRE_EXTENDED) != 0)
+ if ((options & PCRE_EXTENDED) != 0)
{
- while ((c = *(++ptr)) != 0 && c != '\n');
- continue;
+ if ((pcre_ctypes[c] & ctype_space) != 0) continue;
+ if (c == '#')
+ {
+ while ((c = *(++ptr)) != 0 && c != '\n');
+ continue;
+ }
}
switch(c)
@@ -1684,9 +1958,13 @@ while ((c = *(++ptr)) != 0)
if (ptr[1] == '?') ptr++;
continue;
- /* An alternation contains an offset to the next branch or ket. */
+ /* An alternation contains an offset to the next branch or ket. If any ims
+ options changed in the previous branch(es), and/or if we are in a
+ lookbehind assertion, extra space will be needed at the start of the
+ branch. This is handled by branch_extra. */
+
case '|':
- length += 3;
+ length += 3 + branch_extra;
continue;
/* A character class uses 33 characters. Don't worry about character types
@@ -1734,87 +2012,182 @@ while ((c = *(++ptr)) != 0)
/* Brackets may be genuine groups or special things */
case '(':
+ branch_newextra = 0;
/* Handle special forms of bracket, which all start (? */
- if (ptr[1] == '?') switch (c = ptr[2])
+ if (ptr[1] == '?')
{
- /* Skip over comments entirely */
- case '#':
- ptr += 3;
- while (*ptr != 0 && *ptr != ')') ptr++;
- if (*ptr == 0)
- {
- *errorptr = ERR18;
- goto PCRE_ERROR_RETURN;
- }
- continue;
+ int set, unset;
+ int *optset;
- /* Non-referencing groups and lookaheads just move the pointer on, and
- then behave like a non-special bracket, except that they don't increment
- the count of extracting brackets. */
-
- case ':':
- case '=':
- case '!':
- ptr += 2;
- break;
+ switch (c = ptr[2])
+ {
+ /* Skip over comments entirely */
+ case '#':
+ ptr += 3;
+ while (*ptr != 0 && *ptr != ')') ptr++;
+ if (*ptr == 0)
+ {
+ *errorptr = ERR18;
+ goto PCRE_ERROR_RETURN;
+ }
+ continue;
- /* Ditto for the "once only" bracket, allowed only if the extra bit
- is set. */
+ /* Non-referencing groups and lookaheads just move the pointer on, and
+ then behave like a non-special bracket, except that they don't increment
+ the count of extracting brackets. Ditto for the "once only" bracket,
+ which is in Perl from version 5.005. */
- case '>':
- if ((options & PCRE_EXTRA) != 0)
- {
+ case ':':
+ case '=':
+ case '!':
+ case '>':
ptr += 2;
break;
- }
- /* Else fall through */
- /* Else loop setting valid options until ) is met. Anything else is an
- error. */
+ /* Lookbehinds are in Perl from version 5.005 */
- default:
- ptr += 2;
- for (;; ptr++)
- {
- if ((c = *ptr) == 'i')
- {
- options |= PCRE_CASELESS;
- continue;
- }
- else if ((c = *ptr) == 'm')
+ case '<':
+ if (ptr[3] == '=' || ptr[3] == '!')
{
- options |= PCRE_MULTILINE;
- continue;
+ ptr += 3;
+ branch_newextra = 3;
+ length += 3; /* For the first branch */
+ break;
}
- else if (c == 's')
+ *errorptr = ERR24;
+ goto PCRE_ERROR_RETURN;
+
+ /* Conditionals are in Perl from version 5.005. The bracket must either
+ be followed by a number (for bracket reference) or by an assertion
+ group. */
+
+ case '(':
+ if ((pcre_ctypes[ptr[3]] & ctype_digit) != 0)
{
- options |= PCRE_DOTALL;
- continue;
+ ptr += 4;
+ length += 2;
+ while ((pcre_ctypes[*ptr] & ctype_digit) != 0) ptr++;
+ if (*ptr != ')')
+ {
+ *errorptr = ERR26;
+ goto PCRE_ERROR_RETURN;
+ }
}
- else if (c == 'x')
+ else /* An assertion must follow */
{
- options |= PCRE_EXTENDED;
- length -= spaces; /* Already counted spaces */
- continue;
+ ptr++; /* Can treat like ':' as far as spacing is concerned */
+
+ if (ptr[2] != '?' || strchr("=!<", ptr[3]) == NULL)
+ {
+ ptr += 2; /* To get right offset in message */
+ *errorptr = ERR28;
+ goto PCRE_ERROR_RETURN;
+ }
}
- else if (c == 'X')
+ break;
+
+ /* Else loop checking valid options until ) is met. Anything else is an
+ error. If we are without any brackets, i.e. at top level, the settings
+ act as if specified in the options, so massage the options immediately.
+ This is for backward compatibility with Perl 5.004. */
+
+ default:
+ set = unset = 0;
+ optset = &set;
+ ptr += 2;
+
+ for (;; ptr++)
{
- options |= PCRE_EXTRA;
- continue;
+ c = *ptr;
+ switch (c)
+ {
+ case 'i':
+ *optset |= PCRE_CASELESS;
+ continue;
+
+ case 'm':
+ *optset |= PCRE_MULTILINE;
+ continue;
+
+ case 's':
+ *optset |= PCRE_DOTALL;
+ continue;
+
+ case 'x':
+ *optset |= PCRE_EXTENDED;
+ continue;
+
+ case 'X':
+ *optset |= PCRE_EXTRA;
+ continue;
+
+ case 'U':
+ *optset |= PCRE_UNGREEDY;
+ continue;
+
+ case '-':
+ optset = &unset;
+ continue;
+
+ /* A termination by ')' indicates an options-setting-only item;
+ this is global at top level; otherwise nothing is done here and
+ it is handled during the compiling process on a per-bracket-group
+ basis. */
+
+ case ')':
+ if (brastackptr == 0)
+ {
+ options = (options | set) & (~unset);
+ set = unset = 0; /* To save length */
+ }
+ /* Fall through */
+
+ /* A termination by ':' indicates the start of a nested group with
+ the given options set. This is again handled at compile time, but
+ we must allow for compiled space if any of the ims options are
+ set. We also have to allow for resetting space at the end of
+ the group, which is why 4 is added to the length and not just 2.
+ If there are several changes of options within the same group, this
+ will lead to an over-estimate on the length, but this shouldn't
+ matter very much. We also have to allow for resetting options at
+ the start of any alternations, which we do by setting
+ branch_newextra to 2. */
+
+ case ':':
+ if (((set|unset) & PCRE_IMS) != 0)
+ {
+ length += 4;
+ branch_newextra = 2;
+ }
+ goto END_OPTIONS;
+
+ /* Unrecognized option character */
+
+ default:
+ *errorptr = ERR12;
+ goto PCRE_ERROR_RETURN;
+ }
}
- else if (c == 'U')
+
+ /* If we hit a closing bracket, that's it - this is a freestanding
+ option-setting. We need to ensure that branch_extra is updated if
+ necessary. The only values branch_newextra can have here are 0 or 2.
+ If the value is 2, then branch_extra must either be 2 or 5, depending
+ on whether this is a lookbehind group or not. */
+
+ END_OPTIONS:
+ if (c == ')')
{
- options |= PCRE_UNGREEDY;
+ if (branch_newextra == 2 && (branch_extra == 0 || branch_extra == 3))
+ branch_extra += branch_newextra;
continue;
}
- else if (c == ')') break;
- *errorptr = ERR12;
- goto PCRE_ERROR_RETURN;
+ /* If options were terminated by ':' control comes here. Fall through
+ to handle the group below. */
}
- continue; /* End of this bracket handling */
}
/* Extracting brackets must be counted so we can process escapes in a
@@ -1823,7 +2196,10 @@ while ((c = *(++ptr)) != 0)
else bracount++;
/* Non-special forms of bracket. Save length for computing whole length
- at end if there's a repeat that requires duplication of the group. */
+ at end if there's a repeat that requires duplication of the group. Also
+ save the current value of branch_extra, and start the new group with
+ the new value. If non-zero, this will either be 2 for a (?imsx: group, or 3
+ for a lookbehind assertion. */
if (brastackptr >= sizeof(brastack)/sizeof(int))
{
@@ -1831,6 +2207,9 @@ while ((c = *(++ptr)) != 0)
goto PCRE_ERROR_RETURN;
}
+ bralenstack[brastackptr] = branch_extra;
+ branch_extra = branch_newextra;
+
brastack[brastackptr++] = length;
length += 3;
continue;
@@ -1838,14 +2217,22 @@ while ((c = *(++ptr)) != 0)
/* Handle ket. Look for subsequent max/min; for certain sets of values we
have to replicate this bracket up to that many times. If brastackptr is
0 this is an unmatched bracket which will generate an error, but take care
- not to try to access brastack[-1]. */
+ not to try to access brastack[-1] when computing the length and restoring
+ the branch_extra value. */
case ')':
length += 3;
{
int minval = 1;
int maxval = 1;
- int duplength = (brastackptr > 0)? length - brastack[--brastackptr] : 0;
+ int duplength;
+
+ if (brastackptr > 0)
+ {
+ duplength = length - brastack[--brastackptr];
+ branch_extra = bralenstack[brastackptr];
+ }
+ else duplength = 0;
/* Leave ptr at the final char; for read_repeat_counts this happens
automatically; for the others we need an increment. */
@@ -1881,16 +2268,14 @@ while ((c = *(++ptr)) != 0)
runlength = 0;
do
{
- if ((pcre_ctypes[c] & ctype_space) != 0)
- {
- if ((options & PCRE_EXTENDED) != 0) continue;
- spaces++;
- }
-
- if (c == '#' && (options & PCRE_EXTENDED) != 0)
+ if ((options & PCRE_EXTENDED) != 0)
{
- while ((c = *(++ptr)) != 0 && c != '\n');
- continue;
+ if ((pcre_ctypes[c] & ctype_space) != 0) continue;
+ if (c == '#')
+ {
+ while ((c = *(++ptr)) != 0 && c != '\n');
+ continue;
+ }
}
/* Backslash may introduce a data char or a metacharacter; stop the
@@ -1955,7 +2340,7 @@ ptr = (const uschar *)pattern;
code = re->code;
*code = OP_BRA;
bracount = 0;
-(void)compile_regex(options, &bracount, &code, &ptr, errorptr);
+(void)compile_regex(options, -1, &bracount, &code, &ptr, errorptr, FALSE, -1);
re->top_bracket = bracount;
re->top_backref = top_backref;
@@ -1972,6 +2357,11 @@ if debugging, leave the test till after things are printed out. */
if (code - re->code > length) *errorptr = ERR23;
#endif
+/* Give an error if there's back reference to a non-existent capturing
+subpattern. */
+
+if (top_backref > re->top_bracket) *errorptr = ERR15;
+
/* Failed to compile */
if (*errorptr != NULL)
@@ -1990,11 +2380,12 @@ to set the PCRE_STARTLINE flag if all branches start with ^. */
if ((options & PCRE_ANCHORED) == 0)
{
- if (is_anchored(re->code, (options & PCRE_MULTILINE) != 0))
+ int temp_options = options;
+ if (is_anchored(re->code, &temp_options))
re->options |= PCRE_ANCHORED;
else
{
- int ch = find_firstchar(re->code);
+ int ch = find_firstchar(re->code, &temp_options);
if (ch >= 0)
{
re->first_char = ch;
@@ -2009,7 +2400,7 @@ if ((options & PCRE_ANCHORED) == 0)
#ifdef DEBUG
-printf("Length = %d top_bracket = %d top_backref=%d\n",
+printf("Length = %d top_bracket = %d top_backref = %d\n",
length, re->top_bracket, re->top_backref);
if (re->options != 0)
@@ -2048,6 +2439,21 @@ while (code < code_end)
else switch(*code)
{
+ case OP_OPT:
+ printf(" %.2x %s", code[1], OP_names[*code]);
+ code++;
+ break;
+
+ case OP_COND:
+ printf("%3d Cond", (code[1] << 8) + code[2]);
+ code += 2;
+ break;
+
+ case OP_CREF:
+ printf(" %.2d %s", code[1], OP_names[*code]);
+ code++;
+ break;
+
case OP_CHARS:
charlength = *(++code);
printf("%3d ", charlength);
@@ -2061,11 +2467,18 @@ while (code < code_end)
case OP_KET:
case OP_ASSERT:
case OP_ASSERT_NOT:
+ case OP_ASSERTBACK:
+ case OP_ASSERTBACK_NOT:
case OP_ONCE:
printf("%3d %s", (code[1] << 8) + code[2], OP_names[*code]);
code += 2;
break;
+ case OP_REVERSE:
+ printf("%3d %s", (code[1] << 8) + code[2], OP_names[*code]);
+ code += 2;
+ break;
+
case OP_STAR:
case OP_MINSTAR:
case OP_PLUS:
@@ -2139,12 +2552,10 @@ while (code < code_end)
goto CLASS_REF_REPEAT;
case OP_CLASS:
- case OP_NEGCLASS:
{
int i, min, max;
-
- if (*code++ == OP_CLASS) printf(" [");
- else printf(" ^[");
+ code++;
+ printf(" [");
for (i = 0; i < 256; i++)
{
@@ -2269,21 +2680,24 @@ return FALSE;
* Match a back-reference *
*************************************************/
-/* If a back reference hasn't been set, the match fails.
+/* If a back reference hasn't been set, the length that is passed is greater
+than the number of characters left in the string, so the match fails.
Arguments:
- number reference number
+ offset index into the offset vector
eptr points into the subject
length length to be matched
md points to match data block
+ ims the ims flags
Returns: TRUE if matched
*/
static BOOL
-match_ref(int number, register const uschar *eptr, int length, match_data *md)
+match_ref(int offset, register const uschar *eptr, int length, match_data *md,
+ int ims)
{
-const uschar *p = md->start_subject + md->offset_vector[number];
+const uschar *p = md->start_subject + md->offset_vector[offset];
#ifdef DEBUG
if (eptr >= md->end_subject)
@@ -2300,11 +2714,11 @@ printf("\n");
/* Always fail if not enough characters left */
-if (length > md->end_subject - p) return FALSE;
+if (length > md->end_subject - eptr) return FALSE;
/* Separate the caselesss case for speed */
-if (md->caseless)
+if ((ims & PCRE_CASELESS) != 0)
{ while (length-- > 0) if (pcre_lcc[*p++] != pcre_lcc[*eptr++]) return FALSE; }
else
{ while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
@@ -2318,101 +2732,173 @@ return TRUE;
* Match from current position *
*************************************************/
-/* On entry ecode points to the first opcode, and eptr to the first character.
+/* On entry ecode points to the first opcode, and eptr to the first character
+in the subject string, while eptrb holds the value of eptr at the start of the
+last bracketed group - used for breaking infinite loops matching zero-length
+strings.
Arguments:
eptr pointer in subject
ecode position in code
offset_top current top pointer
md pointer to "static" info for the match
+ ims current /i, /m, and /s options
+ condassert TRUE if called to check a condition assertion
+ eptrb eptr at start of last bracket
Returns: TRUE if matched
*/
static BOOL
-match(register const uschar *eptr, register const uschar *ecode, int offset_top,
- match_data *md)
+match(register const uschar *eptr, register const uschar *ecode,
+ int offset_top, match_data *md, int ims, BOOL condassert, const uschar *eptrb)
{
+int original_ims = ims; /* Save for resetting on ')' */
+
for (;;)
{
+ int op = (int)*ecode;
int min, max, ctype;
register int i;
register int c;
BOOL minimize = FALSE;
- /* Opening bracket. Check the alternative branches in turn, failing if none
- match. We have to set the start offset if required and there is space
- in the offset vector so that it is available for subsequent back references
- if the bracket matches. However, if the bracket fails, we must put back the
- previous value of both offsets in case they were set by a previous copy of
- the same bracket. Don't worry about setting the flag for the error case here;
- that is handled in the code for KET. */
+ /* Opening capturing bracket. If there is space in the offset vector, save
+ the current subject position in the working slot at the top of the vector. We
+ mustn't change the current values of the data slot, because they may be set
+ from a previous iteration of this group, and be referred to by a reference
+ inside the group.
+
+ If the bracket fails to match, we need to restore this value and also the
+ values of the final offsets, in case they were set by a previous iteration of
+ the same bracket.
- if ((int)*ecode >= OP_BRA)
+ If there isn't enough space in the offset vector, treat this as if it were a
+ non-capturing bracket. Don't worry about setting the flag for the error case
+ here; that is handled in the code for KET. */
+
+ if (op > OP_BRA)
{
- int number = (*ecode - OP_BRA) << 1;
- int save_offset1 = 0, save_offset2 = 0;
+ int number = op - OP_BRA;
+ int offset = number << 1;
- DPRINTF(("start bracket %d\n", number/2));
+ DPRINTF(("start bracket %d\n", number));
- if (number > 0 && number < md->offset_end)
+ if (offset < md->offset_max)
{
- save_offset1 = md->offset_vector[number];
- save_offset2 = md->offset_vector[number+1];
- md->offset_vector[number] = eptr - md->start_subject;
+ int save_offset1 = md->offset_vector[offset];
+ int save_offset2 = md->offset_vector[offset+1];
+ int save_offset3 = md->offset_vector[md->offset_end - number];
+
+ DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
+ md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
- DPRINTF(("saving %d %d\n", save_offset1, save_offset2));
+ do
+ {
+ if (match(eptr, ecode+3, offset_top, md, ims, FALSE, eptr)) return TRUE;
+ ecode += (ecode[1] << 8) + ecode[2];
+ }
+ while (*ecode == OP_ALT);
+
+ DPRINTF(("bracket %d failed\n", number));
+
+ md->offset_vector[offset] = save_offset1;
+ md->offset_vector[offset+1] = save_offset2;
+ md->offset_vector[md->offset_end - number] = save_offset3;
+ return FALSE;
}
- /* Recurse for all the alternatives. */
+ /* Insufficient room for saving captured contents */
+
+ else op = OP_BRA;
+ }
+
+ /* Other types of node can be handled by a switch */
+ switch(op)
+ {
+ case OP_BRA: /* Non-capturing bracket: optimized */
+ DPRINTF(("start bracket 0\n"));
do
{
- if (match(eptr, ecode+3, offset_top, md)) return TRUE;
+ if (match(eptr, ecode+3, offset_top, md, ims, FALSE, eptr)) return TRUE;
ecode += (ecode[1] << 8) + ecode[2];
}
while (*ecode == OP_ALT);
+ DPRINTF(("bracket 0 failed\n"));
+ return FALSE;
- DPRINTF(("bracket %d failed\n", number/2));
+ /* Conditional group: compilation checked that there are no more than
+ two branches. If the condition is false, skipping the first branch takes us
+ past the end if there is only one branch, but that's OK because that is
+ exactly what going to the ket would do. */
- if (number > 0 && number < md->offset_end)
+ case OP_COND:
+ if (ecode[3] == OP_CREF) /* Condition is extraction test */
{
- md->offset_vector[number] = save_offset1;
- md->offset_vector[number+1] = save_offset2;
+ int offset = ecode[4] << 1; /* Doubled reference number */
+ return match(eptr,
+ ecode + ((offset < offset_top && md->offset_vector[offset] >= 0)?
+ 5 : 3 + (ecode[1] << 8) + ecode[2]),
+ offset_top, md, ims, FALSE, eptr);
}
- return FALSE;
- }
+ /* The condition is an assertion. Call match() to evaluate it - setting
+ the final argument TRUE causes it to stop at the end of an assertion. */
- /* Other types of node can be handled by a switch */
+ else
+ {
+ if (match(eptr, ecode+3, offset_top, md, ims, TRUE, NULL))
+ {
+ ecode += 3 + (ecode[4] << 8) + ecode[5];
+ while (*ecode == OP_ALT) ecode += (ecode[1] << 8) + ecode[2];
+ }
+ else ecode += (ecode[1] << 8) + ecode[2];
+ return match(eptr, ecode+3, offset_top, md, ims, FALSE, eptr);
+ }
+ /* Control never reaches here */
+
+ /* Skip over conditional reference data if encountered (should not be) */
+
+ case OP_CREF:
+ ecode += 2;
+ break;
+
+ /* End of the pattern */
- switch(*ecode)
- {
case OP_END:
md->end_match_ptr = eptr; /* Record where we ended */
md->end_offset_top = offset_top; /* and how many extracts were taken */
return TRUE;
- /* The equivalent of Prolog's "cut" - if the rest doesn't match, the
- whole thing doesn't match, so we have to get out via a longjmp(). */
+ /* Change option settings */
- case OP_CUT:
- if (match(eptr, ecode+1, offset_top, md)) return TRUE;
- longjmp(md->fail_env, 1);
+ case OP_OPT:
+ ims = ecode[1];
+ ecode += 2;
+ DPRINTF(("ims set to %02x\n", ims));
+ break;
/* Assertion brackets. Check the alternative branches in turn - the
matching won't pass the KET for an assertion. If any one branch matches,
- the assertion is true. */
+ the assertion is true. Lookbehind assertions have an OP_REVERSE item at the
+ start of each branch to move the current point backwards, so the code at
+ this level is identical to the lookahead case. */
case OP_ASSERT:
+ case OP_ASSERTBACK:
do
{
- if (match(eptr, ecode+3, offset_top, md)) break;
+ if (match(eptr, ecode+3, offset_top, md, ims, FALSE, NULL)) break;
ecode += (ecode[1] << 8) + ecode[2];
}
while (*ecode == OP_ALT);
if (*ecode == OP_KET) return FALSE;
+ /* If checking an assertion for a condition, return TRUE. */
+
+ if (condassert) return TRUE;
+
/* Continue from after the assertion, updating the offsets high water
mark, since extracts may have been taken during the assertion. */
@@ -2424,38 +2910,94 @@ for (;;)
/* Negative assertion: all branches must fail to match */
case OP_ASSERT_NOT:
+ case OP_ASSERTBACK_NOT:
do
{
- if (match(eptr, ecode+3, offset_top, md)) return FALSE;
+ if (match(eptr, ecode+3, offset_top, md, ims, FALSE, NULL)) return FALSE;
ecode += (ecode[1] << 8) + ecode[2];
}
while (*ecode == OP_ALT);
+
+ if (condassert) return TRUE;
ecode += 3;
continue;
+ /* Move the subject pointer back. This occurs only at the start of
+ each branch of a lookbehind assertion. If we are too close to the start to
+ move back, this match function fails. */
+
+ case OP_REVERSE:
+ eptr -= (ecode[1] << 8) + ecode[2];
+ if (eptr < md->start_subject) return FALSE;
+ ecode += 3;
+ break;
+
+
/* "Once" brackets are like assertion brackets except that after a match,
the point in the subject string is not moved back. Thus there can never be
a move back into the brackets. Check the alternative branches in turn - the
matching won't pass the KET for this kind of subpattern. If any one branch
- matches, we carry on, leaving the subject pointer. */
+ matches, we carry on as at the end of a normal bracket, leaving the subject
+ pointer. */
case OP_ONCE:
- do
{
- if (match(eptr, ecode+3, offset_top, md)) break;
- ecode += (ecode[1] << 8) + ecode[2];
- }
- while (*ecode == OP_ALT);
- if (*ecode == OP_KET) return FALSE;
+ const uschar *prev = ecode;
- /* Continue as from after the assertion, updating the offsets high water
- mark, since extracts may have been taken. */
+ do
+ {
+ if (match(eptr, ecode+3, offset_top, md, ims, FALSE, eptr)) break;
+ ecode += (ecode[1] << 8) + ecode[2];
+ }
+ while (*ecode == OP_ALT);
- do ecode += (ecode[1] << 8) + ecode[2]; while (*ecode == OP_ALT);
- ecode += 3;
- offset_top = md->end_offset_top;
- eptr = md->end_match_ptr;
- continue;
+ /* If hit the end of the group (which could be repeated), fail */
+
+ if (*ecode != OP_ONCE && *ecode != OP_ALT) return FALSE;
+
+ /* Continue as from after the assertion, updating the offsets high water
+ mark, since extracts may have been taken. */
+
+ do ecode += (ecode[1] << 8) + ecode[2]; while (*ecode == OP_ALT);
+
+ offset_top = md->end_offset_top;
+ eptr = md->end_match_ptr;
+
+ /* For a non-repeating ket, just continue at this level. This also
+ happens for a repeating ket if no characters were matched in the group.
+ This is the forcible breaking of infinite loops as implemented in Perl
+ 5.005. If there is an options reset, it will get obeyed in the normal
+ course of events. */
+
+ if (*ecode == OP_KET || eptr == eptrb)
+ {
+ ecode += 3;
+ break;
+ }
+
+ /* The repeating kets try the rest of the pattern or restart from the
+ preceding bracket, in the appropriate order. We need to reset any options
+ that changed within the bracket before re-running it, so check the next
+ opcode. */
+
+ if (ecode[3] == OP_OPT)
+ {
+ ims = (ims & ~PCRE_IMS) | ecode[4];
+ DPRINTF(("ims set to %02x at group repeat\n", ims));
+ }
+
+ if (*ecode == OP_KETRMIN)
+ {
+ if (match(eptr, ecode+3, offset_top, md, ims, FALSE, eptr) ||
+ match(eptr, prev, offset_top, md, ims, FALSE, eptr)) return TRUE;
+ }
+ else /* OP_KETRMAX */
+ {
+ if (match(eptr, prev, offset_top, md, ims, FALSE, eptr) ||
+ match(eptr, ecode+3, offset_top, md, ims, FALSE, eptr)) return TRUE;
+ }
+ }
+ return FALSE;
/* An alternation is the end of a branch; scan along to find the end of the
bracketed group and go to there. */
@@ -2473,7 +3015,7 @@ for (;;)
case OP_BRAZERO:
{
const uschar *next = ecode+1;
- if (match(eptr, next, offset_top, md)) return TRUE;
+ if (match(eptr, next, offset_top, md, ims, FALSE, eptr)) return TRUE;
do next += (next[1] << 8) + next[2]; while (*next == OP_ALT);
ecode = next + 3;
}
@@ -2483,50 +3025,67 @@ for (;;)
{
const uschar *next = ecode+1;
do next += (next[1] << 8) + next[2]; while (*next == OP_ALT);
- if (match(eptr, next+3, offset_top, md)) return TRUE;
+ if (match(eptr, next+3, offset_top, md, ims, FALSE, eptr)) return TRUE;
ecode++;
}
- break;;
+ break;
/* End of a group, repeated or non-repeating. If we are at the end of
an assertion "group", stop matching and return TRUE, but record the
- current high water mark for use by positive assertions. */
+ current high water mark for use by positive assertions. Do this also
+ for the "once" (not-backup up) groups. */
case OP_KET:
case OP_KETRMIN:
case OP_KETRMAX:
{
- int number;
const uschar *prev = ecode - (ecode[1] << 8) - ecode[2];
- if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || *prev == OP_ONCE)
+ if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
+ *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
+ *prev == OP_ONCE)
{
md->end_match_ptr = eptr; /* For ONCE */
md->end_offset_top = offset_top;
return TRUE;
}
- /* In all other cases we have to check the group number back at the
- start and if necessary complete handling an extraction by setting the
- final offset and bumping the high water mark. */
+ /* In all other cases except a conditional group we have to check the
+ group number back at the start and if necessary complete handling an
+ extraction by setting the offsets and bumping the high water mark. */
- number = (*prev - OP_BRA) << 1;
+ if (*prev != OP_COND)
+ {
+ int number = *prev - OP_BRA;
+ int offset = number << 1;
- DPRINTF(("end bracket %d\n", number/2));
+ DPRINTF(("end bracket %d\n", number));
- if (number > 0)
- {
- if (number >= md->offset_end) md->offset_overflow = TRUE; else
+ if (number > 0)
{
- md->offset_vector[number+1] = eptr - md->start_subject;
- if (offset_top <= number) offset_top = number + 2;
+ if (offset >= md->offset_max) md->offset_overflow = TRUE; else
+ {
+ md->offset_vector[offset] =
+ md->offset_vector[md->offset_end - number];
+ md->offset_vector[offset+1] = eptr - md->start_subject;
+ if (offset_top <= offset) offset_top = offset + 2;
+ }
}
}
- /* For a non-repeating ket, just advance to the next node and continue at
- this level. */
+ /* Reset the value of the ims flags, in case they got changed during
+ the group. */
+
+ ims = original_ims;
+ DPRINTF(("ims reset to %02x\n", ims));
+
+ /* For a non-repeating ket, just continue at this level. This also
+ happens for a repeating ket if no characters were matched in the group.
+ This is the forcible breaking of infinite loops as implemented in Perl
+ 5.005. If there is an options reset, it will get obeyed in the normal
+ course of events. */
- if (*ecode == OP_KET)
+ if (*ecode == OP_KET || eptr == eptrb)
{
ecode += 3;
break;
@@ -2537,13 +3096,13 @@ for (;;)
if (*ecode == OP_KETRMIN)
{
- if (match(eptr, ecode+3, offset_top, md) ||
- match(eptr, prev, offset_top, md)) return TRUE;
+ if (match(eptr, ecode+3, offset_top, md, ims, FALSE, eptr) ||
+ match(eptr, prev, offset_top, md, ims, FALSE, eptr)) return TRUE;
}
else /* OP_KETRMAX */
{
- if (match(eptr, prev, offset_top, md) ||
- match(eptr, ecode+3, offset_top, md)) return TRUE;
+ if (match(eptr, prev, offset_top, md, ims, FALSE, eptr) ||
+ match(eptr, ecode+3, offset_top, md, ims, FALSE, eptr)) return TRUE;
}
}
return FALSE;
@@ -2552,7 +3111,7 @@ for (;;)
case OP_CIRC:
if (md->notbol && eptr == md->start_subject) return FALSE;
- if (md->multiline)
+ if ((ims & PCRE_MULTILINE) != 0)
{
if (eptr != md->start_subject && eptr[-1] != '\n') return FALSE;
ecode++;
@@ -2567,34 +3126,46 @@ for (;;)
ecode++;
break;
- /* Assert before internal newline if multiline, or before
- a terminating newline unless endonly is set, else end of subject unless
- noteol is set. */
+ /* Assert before internal newline if multiline, or before a terminating
+ newline unless endonly is set, else end of subject unless noteol is set. */
case OP_DOLL:
- if (md->noteol && eptr >= md->end_subject) return FALSE;
- if (md->multiline)
+ if ((ims & PCRE_MULTILINE) != 0)
{
- if (eptr < md->end_subject && *eptr != '\n') return FALSE;
+ if (eptr < md->end_subject) { if (*eptr != '\n') return FALSE; }
+ else { if (md->noteol) return FALSE; }
ecode++;
break;
}
- else if (!md->endonly)
+ else
{
- if (eptr < md->end_subject - 1 ||
- (eptr == md->end_subject - 1 && *eptr != '\n')) return FALSE;
- ecode++;
- break;
+ if (md->noteol) return FALSE;
+ if (!md->endonly)
+ {
+ if (eptr < md->end_subject - 1 ||
+ (eptr == md->end_subject - 1 && *eptr != '\n')) return FALSE;
+
+ ecode++;
+ break;
+ }
}
/* ... else fall through */
- /* End of subject assertion */
+ /* End of subject assertion (\z) */
case OP_EOD:
if (eptr < md->end_subject) return FALSE;
ecode++;
break;
+ /* End of subject or ending \n assertion (\Z) */
+
+ case OP_EODN:
+ if (eptr < md->end_subject - 1 ||
+ (eptr == md->end_subject - 1 && *eptr != '\n')) return FALSE;
+ ecode++;
+ break;
+
/* Word boundary assertions */
case OP_NOT_WORD_BOUNDARY:
@@ -2613,7 +3184,8 @@ for (;;)
/* Match a single character type; inline for speed */
case OP_ANY:
- if (!md->dotall && eptr < md->end_subject && *eptr == '\n') return FALSE;
+ if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == '\n')
+ return FALSE;
if (eptr++ >= md->end_subject) return FALSE;
ecode++;
break;
@@ -2665,16 +3237,19 @@ for (;;)
case OP_REF:
{
int length;
- int number = ecode[1] << 1; /* Doubled reference number */
+ int offset = ecode[1] << 1; /* Doubled reference number */
ecode += 2; /* Advance past the item */
- if (number >= offset_top || md->offset_vector[number] < 0)
- {
- md->errorcode = PCRE_ERROR_BADREF;
- return FALSE;
- }
+ /* If the reference is unset, set the length to be longer than the amount
+ of subject left; this ensures that every attempt at a match fails. We
+ can't just fail here, because of the possibility of quantifiers with zero
+ minima. */
- length = md->offset_vector[number+1] - md->offset_vector[number];
+ length = (offset >= offset_top || md->offset_vector[offset] < 0)?
+ md->end_subject - eptr + 1 :
+ md->offset_vector[offset+1] - md->offset_vector[offset];
+
+ /* Set up for repetition, or handle the non-repeated case */
switch (*ecode)
{
@@ -2701,7 +3276,7 @@ for (;;)
break;
default: /* No repeat follows */
- if (!match_ref(number, eptr, length, md)) return FALSE;
+ if (!match_ref(offset, eptr, length, md, ims)) return FALSE;
eptr += length;
continue; /* With the main loop */
}
@@ -2717,7 +3292,7 @@ for (;;)
for (i = 1; i <= min; i++)
{
- if (!match_ref(number, eptr, length, md)) return FALSE;
+ if (!match_ref(offset, eptr, length, md, ims)) return FALSE;
eptr += length;
}
@@ -2732,8 +3307,9 @@ for (;;)
{
for (i = min;; i++)
{
- if (match(eptr, ecode, offset_top, md)) return TRUE;
- if (i >= max || !match_ref(number, eptr, length, md))
+ if (match(eptr, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
+ if (i >= max || !match_ref(offset, eptr, length, md, ims))
return FALSE;
eptr += length;
}
@@ -2747,12 +3323,13 @@ for (;;)
const uschar *pp = eptr;
for (i = min; i < max; i++)
{
- if (!match_ref(number, eptr, length, md)) break;
+ if (!match_ref(offset, eptr, length, md, ims)) break;
eptr += length;
}
while (eptr >= pp)
{
- if (match(eptr, ecode, offset_top, md)) return TRUE;
+ if (match(eptr, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
eptr -= length;
}
return FALSE;
@@ -2760,18 +3337,14 @@ for (;;)
}
/* Control never gets here */
+
+
/* Match a character class, possibly repeatedly. Look past the end of the
item to see if there is repeat information following. Then obey similar
- code to character type repeats - written out again for speed. If caseless
- matching was set at runtime but not at compile time, we have to check both
- versions of a character, and we have to behave differently for positive and
- negative classes. This is the only time where OP_CLASS and OP_NEGCLASS are
- treated differently. */
+ code to character type repeats - written out again for speed. */
case OP_CLASS:
- case OP_NEGCLASS:
{
- BOOL nasty_case = *ecode == OP_NEGCLASS && md->runtime_caseless;
const uschar *data = ecode + 1; /* Save for matching */
ecode += 33; /* Advance past the item */
@@ -2810,30 +3383,7 @@ for (;;)
{
if (eptr >= md->end_subject) return FALSE;
c = *eptr++;
-
- /* Either not runtime caseless, or it was a positive class. For
- runtime caseless, continue if either case is in the map. */
-
- if (!nasty_case)
- {
- if ((data[c/8] & (1 << (c&7))) != 0) continue;
- if (md->runtime_caseless)
- {
- c = pcre_fcc[c];
- if ((data[c/8] & (1 << (c&7))) != 0) continue;
- }
- }
-
- /* Runtime caseless and it was a negative class. Continue only if
- both cases are in the map. */
-
- else
- {
- if ((data[c/8] & (1 << (c&7))) == 0) return FALSE;
- c = pcre_fcc[c];
- if ((data[c/8] & (1 << (c&7))) != 0) continue;
- }
-
+ if ((data[c/8] & (1 << (c&7))) != 0) continue;
return FALSE;
}
@@ -2849,33 +3399,11 @@ for (;;)
{
for (i = min;; i++)
{
- if (match(eptr, ecode, offset_top, md)) return TRUE;
+ if (match(eptr, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
if (i >= max || eptr >= md->end_subject) return FALSE;
c = *eptr++;
-
- /* Either not runtime caseless, or it was a positive class. For
- runtime caseless, continue if either case is in the map. */
-
- if (!nasty_case)
- {
- if ((data[c/8] & (1 << (c&7))) != 0) continue;
- if (md->runtime_caseless)
- {
- c = pcre_fcc[c];
- if ((data[c/8] & (1 << (c&7))) != 0) continue;
- }
- }
-
- /* Runtime caseless and it was a negative class. Continue only if
- both cases are in the map. */
-
- else
- {
- if ((data[c/8] & (1 << (c&7))) == 0) return FALSE;
- c = pcre_fcc[c];
- if ((data[c/8] & (1 << (c&7))) != 0) continue;
- }
-
+ if ((data[c/8] & (1 << (c&7))) != 0) continue;
return FALSE;
}
/* Control never gets here */
@@ -2890,35 +3418,13 @@ for (;;)
{
if (eptr >= md->end_subject) break;
c = *eptr;
-
- /* Either not runtime caseless, or it was a positive class. For
- runtime caseless, continue if either case is in the map. */
-
- if (!nasty_case)
- {
- if ((data[c/8] & (1 << (c&7))) != 0) continue;
- if (md->runtime_caseless)
- {
- c = pcre_fcc[c];
- if ((data[c/8] & (1 << (c&7))) != 0) continue;
- }
- }
-
- /* Runtime caseless and it was a negative class. Continue only if
- both cases are in the map. */
-
- else
- {
- if ((data[c/8] & (1 << (c&7))) == 0) break;
- c = pcre_fcc[c];
- if ((data[c/8] & (1 << (c&7))) != 0) continue;
- }
-
+ if ((data[c/8] & (1 << (c&7))) != 0) continue;
break;
}
while (eptr >= pp)
- if (match(eptr--, ecode, offset_top, md)) return TRUE;
+ if (match(eptr--, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
return FALSE;
}
}
@@ -2945,7 +3451,7 @@ for (;;)
#endif
if (length > md->end_subject - eptr) return FALSE;
- if (md->caseless)
+ if ((ims & PCRE_CASELESS) != 0)
{
while (length-- > 0) if (pcre_lcc[*ecode++] != pcre_lcc[*eptr++]) return FALSE;
}
@@ -3002,7 +3508,7 @@ for (;;)
DPRINTF(("matching %c{%d,%d} against subject %.*s\n", c, min, max,
max, eptr));
- if (md->caseless)
+ if ((ims & PCRE_CASELESS) != 0)
{
c = pcre_lcc[c];
for (i = 1; i <= min; i++) if (c != pcre_lcc[*eptr++]) return FALSE;
@@ -3011,7 +3517,8 @@ for (;;)
{
for (i = min;; i++)
{
- if (match(eptr, ecode, offset_top, md)) return TRUE;
+ if (match(eptr, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
if (i >= max || eptr >= md->end_subject || c != pcre_lcc[*eptr++])
return FALSE;
}
@@ -3026,7 +3533,8 @@ for (;;)
eptr++;
}
while (eptr >= pp)
- if (match(eptr--, ecode, offset_top, md)) return TRUE;
+ if (match(eptr--, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
return FALSE;
}
/* Control never gets here */
@@ -3042,7 +3550,8 @@ for (;;)
{
for (i = min;; i++)
{
- if (match(eptr, ecode, offset_top, md)) return TRUE;
+ if (match(eptr, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
if (i >= max || eptr >= md->end_subject || c != *eptr++) return FALSE;
}
/* Control never gets here */
@@ -3056,7 +3565,8 @@ for (;;)
eptr++;
}
while (eptr >= pp)
- if (match(eptr--, ecode, offset_top, md)) return TRUE;
+ if (match(eptr--, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
return FALSE;
}
}
@@ -3067,7 +3577,7 @@ for (;;)
case OP_NOT:
if (eptr >= md->end_subject) return FALSE;
ecode++;
- if (md->caseless)
+ if ((ims & PCRE_CASELESS) != 0)
{
if (pcre_lcc[*ecode++] == pcre_lcc[*eptr++]) return FALSE;
}
@@ -3127,7 +3637,7 @@ for (;;)
DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", c, min, max,
max, eptr));
- if (md->caseless)
+ if ((ims & PCRE_CASELESS) != 0)
{
c = pcre_lcc[c];
for (i = 1; i <= min; i++) if (c == pcre_lcc[*eptr++]) return FALSE;
@@ -3136,7 +3646,8 @@ for (;;)
{
for (i = min;; i++)
{
- if (match(eptr, ecode, offset_top, md)) return TRUE;
+ if (match(eptr, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
if (i >= max || eptr >= md->end_subject || c == pcre_lcc[*eptr++])
return FALSE;
}
@@ -3151,7 +3662,8 @@ for (;;)
eptr++;
}
while (eptr >= pp)
- if (match(eptr--, ecode, offset_top, md)) return TRUE;
+ if (match(eptr--, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
return FALSE;
}
/* Control never gets here */
@@ -3167,7 +3679,8 @@ for (;;)
{
for (i = min;; i++)
{
- if (match(eptr, ecode, offset_top, md)) return TRUE;
+ if (match(eptr, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
if (i >= max || eptr >= md->end_subject || c == *eptr++) return FALSE;
}
/* Control never gets here */
@@ -3181,7 +3694,8 @@ for (;;)
eptr++;
}
while (eptr >= pp)
- if (match(eptr--, ecode, offset_top, md)) return TRUE;
+ if (match(eptr--, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
return FALSE;
}
}
@@ -3231,7 +3745,7 @@ for (;;)
if (min > 0) switch(ctype)
{
case OP_ANY:
- if (!md->dotall)
+ if ((ims & PCRE_DOTALL) == 0)
{ for (i = 1; i <= min; i++) if (*eptr++ == '\n') return FALSE; }
else eptr += min;
break;
@@ -3278,9 +3792,9 @@ for (;;)
{
for (i = min;; i++)
{
- if (match(eptr, ecode, offset_top, md)) return TRUE;
+ if (match(eptr, ecode, offset_top, md, ims, FALSE, eptrb)) return TRUE;
if (i >= max || eptr >= md->end_subject ||
- !match_type(ctype, *eptr++, md->dotall))
+ !match_type(ctype, *eptr++, (ims & PCRE_DOTALL) != 0))
return FALSE;
}
/* Control never gets here */
@@ -3295,7 +3809,7 @@ for (;;)
switch(ctype)
{
case OP_ANY:
- if (!md->dotall)
+ if ((ims & PCRE_DOTALL) == 0)
{
for (i = min; i < max; i++)
{
@@ -3367,7 +3881,8 @@ for (;;)
}
while (eptr >= pp)
- if (match(eptr--, ecode, offset_top, md)) return TRUE;
+ if (match(eptr--, ecode, offset_top, md, ims, FALSE, eptrb))
+ return TRUE;
return FALSE;
}
/* Control never gets here */
@@ -3390,34 +3905,6 @@ for (;;)
-/*************************************************
-* Segregate setjmp() *
-*************************************************/
-
-/* The -Wall option of gcc gives warnings for all local variables when setjmp()
-is used, even if the coding conforms to the rules of ANSI C. To avoid this, we
-hide it in a separate function. This is called only when PCRE_EXTRA is set,
-since it's needed only for the extension \X option, and with any luck, a good
-compiler will spot the tail recursion and compile it efficiently.
-
-Arguments:
- eptr pointer in subject
- ecode position in code
- offset_top current top pointer
- md pointer to "static" info for the match
-
-Returns: TRUE if matched
-*/
-
-static BOOL
-match_with_setjmp(const uschar *eptr, const uschar *ecode, int offset_top,
- match_data *match_block)
-{
-return setjmp(match_block->fail_env) == 0 &&
- match(eptr, ecode, offset_top, match_block);
-}
-
-
/*************************************************
* Execute a Regular Expression *
@@ -3448,6 +3935,7 @@ pcre_exec(const pcre *external_re, const pcre_extra *external_extra,
{
int resetcount, ocount;
int first_char = -1;
+int ims = 0;
match_data match_block;
const uschar *start_bits = NULL;
const uschar *start_match = (const uschar *)subject;
@@ -3468,28 +3956,29 @@ match_block.start_subject = (const uschar *)subject;
match_block.end_subject = match_block.start_subject + length;
end_subject = match_block.end_subject;
-match_block.caseless = ((re->options | options) & PCRE_CASELESS) != 0;
-match_block.runtime_caseless = match_block.caseless &&
- (re->options & PCRE_CASELESS) == 0;
-
-match_block.multiline = ((re->options | options) & PCRE_MULTILINE) != 0;
-match_block.dotall = ((re->options | options) & PCRE_DOTALL) != 0;
-match_block.endonly = ((re->options | options) & PCRE_DOLLAR_ENDONLY) != 0;
+match_block.endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
match_block.notbol = (options & PCRE_NOTBOL) != 0;
match_block.noteol = (options & PCRE_NOTEOL) != 0;
match_block.errorcode = PCRE_ERROR_NOMATCH; /* Default error */
+/* The ims options can vary during the matching as a result of the presence
+of (?ims) items in the pattern. They are kept in a local variable so that
+restoring at the exit of a group is easy. */
+
+ims = re->options & (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL);
+
/* If the expression has got more back references than the offsets supplied can
hold, we get a temporary bit of working store to use during the matching.
Otherwise, we can use the vector supplied, rounding down its size to a multiple
-of 2. */
+of 3. */
+
+ocount = offsetcount - (offsetcount % 3);
-ocount = offsetcount & (-2);
-if (re->top_backref > 0 && re->top_backref >= ocount/2)
+if (re->top_backref > 0 && re->top_backref >= ocount/3)
{
- ocount = re->top_backref * 2 + 2;
+ ocount = re->top_backref * 3 + 3;
match_block.offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));
if (match_block.offset_vector == NULL) return PCRE_ERROR_NOMEMORY;
using_temporary_offsets = TRUE;
@@ -3498,6 +3987,7 @@ if (re->top_backref > 0 && re->top_backref >= ocount/2)
else match_block.offset_vector = offsets;
match_block.offset_end = ocount;
+match_block.offset_max = (2*ocount)/3;
match_block.offset_overflow = FALSE;
/* Compute the minimum number of offsets that we need to reset each time. Doing
@@ -3507,38 +3997,22 @@ in the pattern. */
resetcount = 2 + re->top_bracket * 2;
if (resetcount > offsetcount) resetcount = ocount;
-/* If MULTILINE is set at exec time but was not set at compile time, and the
-anchored flag is set, we must re-check because a setting provoked by ^ in the
-pattern is not right in multi-line mode. Calling is_anchored() again here does
-the right check, because multiline is now set. If it now yields FALSE, the
-expression must have had ^ starting some of its branches. Check to see if
-that is true for *all* branches, and if so, set the startline flag. */
-
-if (match_block. multiline && anchored && (re->options & PCRE_MULTILINE) == 0 &&
- !is_anchored(re->code, match_block.multiline))
- {
- anchored = FALSE;
- if (is_startline(re->code)) startline = TRUE;
- }
-
/* Set up the first character to match, if available. The first_char value is
never set for an anchored regular expression, but the anchoring may be forced
at run time, so we have to test for anchoring. The first char may be unset for
an unanchored pattern, of course. If there's no first char and the pattern was
-studied, the may be a bitmap of possible first characters. However, we can
-use this only if the caseless state of the studying was correct. */
+studied, there may be a bitmap of possible first characters. */
if (!anchored)
{
if ((re->options & PCRE_FIRSTSET) != 0)
{
first_char = re->first_char;
- if (match_block.caseless) first_char = pcre_lcc[first_char];
+ if ((ims & PCRE_CASELESS) != 0) first_char = pcre_lcc[first_char];
}
else
if (!startline && extra != NULL &&
- (extra->options & PCRE_STUDY_MAPPED) != 0 &&
- ((extra->options & PCRE_STUDY_CASELESS) != 0) == match_block.caseless)
+ (extra->options & PCRE_STUDY_MAPPED) != 0)
start_bits = extra->start_bits;
}
@@ -3558,7 +4032,7 @@ do
if (first_char >= 0)
{
- if (match_block.caseless)
+ if ((ims & PCRE_CASELESS) != 0)
while (start_match < end_subject && pcre_lcc[*start_match] != first_char)
start_match++;
else
@@ -3599,20 +4073,10 @@ do
there were too many extractions, set the return code to zero. In the case
where we had to get some local store to hold offsets for backreferences, copy
those back references that we can. In this case there need not be overflow
- if certain parts of the pattern were not used.
-
- Before starting the match, we have to set up a longjmp() target to enable
- the "cut" operation to fail a match completely without backtracking. This
- is done in a separate function to avoid compiler warnings. We need not do
- it unless PCRE_EXTRA is set, since only in that case is the "cut" operation
- enabled. */
+ if certain parts of the pattern were not used. */
- if ((re->options & PCRE_EXTRA) != 0)
- {
- if (!match_with_setjmp(start_match, re->code, 2, &match_block))
- continue;
- }
- else if (!match(start_match, re->code, 2, &match_block)) continue;
+ if (!match(start_match, re->code, 2, &match_block, ims, FALSE, start_match))
+ continue;
/* Copy the offset information from temporary store if necessary */
diff --git a/pcre.h b/pcre.h
index 525dca4..76ba364 100644
--- a/pcre.h
+++ b/pcre.h
@@ -22,10 +22,10 @@ extern "C" {
/* Options */
#define PCRE_CASELESS 0x0001
-#define PCRE_EXTENDED 0x0002
-#define PCRE_ANCHORED 0x0004
-#define PCRE_MULTILINE 0x0008
-#define PCRE_DOTALL 0x0010
+#define PCRE_MULTILINE 0x0002
+#define PCRE_DOTALL 0x0004
+#define PCRE_EXTENDED 0x0008
+#define PCRE_ANCHORED 0x0010
#define PCRE_DOLLAR_ENDONLY 0x0020
#define PCRE_EXTRA 0x0040
#define PCRE_NOTBOL 0x0080
@@ -35,12 +35,11 @@ extern "C" {
/* Exec-time error codes */
#define PCRE_ERROR_NOMATCH (-1)
-#define PCRE_ERROR_BADREF (-2)
-#define PCRE_ERROR_NULL (-3)
-#define PCRE_ERROR_BADOPTION (-4)
-#define PCRE_ERROR_BADMAGIC (-5)
-#define PCRE_ERROR_UNKNOWN_NODE (-6)
-#define PCRE_ERROR_NOMEMORY (-7)
+#define PCRE_ERROR_NULL (-2)
+#define PCRE_ERROR_BADOPTION (-3)
+#define PCRE_ERROR_BADMAGIC (-4)
+#define PCRE_ERROR_UNKNOWN_NODE (-5)
+#define PCRE_ERROR_NOMEMORY (-6)
/* Types */
diff --git a/pcreposix.c b/pcreposix.c
index 649399e..27c810e 100644
--- a/pcreposix.c
+++ b/pcreposix.c
@@ -42,7 +42,7 @@ restrictions:
static const char *estring[] = {
ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10,
ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20,
- ERR21, ERR22, ERR23 };
+ ERR21, ERR22, ERR23, ERR24, ERR25 };
static int eint[] = {
REG_EESCAPE, /* "\\ at end of pattern" */
@@ -67,7 +67,12 @@ static int eint[] = {
REG_ESIZE, /* "regular expression too large" */
REG_ESPACE, /* "failed to get memory" */
REG_EPAREN, /* "unmatched brackets" */
- REG_ASSERT /* "internal error: code overflow" */
+ REG_ASSERT, /* "internal error: code overflow" */
+ REG_BADPAT, /* "unrecognized character after (?<" */
+ REG_BADPAT, /* "lookbehind assertion is not fixed length" */
+ REG_BADPAT, /* "malformed number after (?(" */
+ REG_BADPAT, /* "conditional group containe more than two branches" */
+ REG_BADPAT /* "assertion expected after (?(" */
};
/* Table of texts corresponding to POSIX error codes */
@@ -135,7 +140,7 @@ addlength = (preg != NULL && (int)preg->re_erroffset != -1)?
if (errbuf_size > 0)
{
if (addlength > 0 && errbuf_size >= length + addlength)
- sprintf(errbuf, "%s%s%-6d", message, addmessage, preg->re_erroffset);
+ sprintf(errbuf, "%s%s%-6d", message, addmessage, (int)preg->re_erroffset);
else
{
strncpy(errbuf, message, errbuf_size - 1);
@@ -229,7 +234,6 @@ if (rc > 0)
else switch(rc)
{
case PCRE_ERROR_NOMATCH: return REG_NOMATCH;
- case PCRE_ERROR_BADREF: return REG_ESUBREG;
case PCRE_ERROR_NULL: return REG_INVARG;
case PCRE_ERROR_BADOPTION: return REG_INVARG;
case PCRE_ERROR_BADMAGIC: return REG_INVARG;
diff --git a/pcretest.c b/pcretest.c
index 5bc1f3a..507c6bf 100644
--- a/pcretest.c
+++ b/pcretest.c
@@ -21,6 +21,8 @@
#endif
#endif
+#define LOOPREPEAT 10000
+
static FILE *outfile;
static int log_store = 0;
@@ -32,49 +34,66 @@ code as contained in pcre.c under the DEBUG macro. */
static const char *OP_names[] = {
"End", "\\A", "\\B", "\\b", "\\D", "\\d",
- "\\S", "\\s", "\\W", "\\w", "Cut", "\\Z", "^", "$", "Any", "chars",
- "not",
+ "\\S", "\\s", "\\W", "\\w", "\\Z", "\\z",
+ "Opt", "^", "$", "Any", "chars", "not",
"*", "*?", "+", "+?", "?", "??", "{", "{", "{",
"*", "*?", "+", "+?", "?", "??", "{", "{", "{",
"*", "*?", "+", "+?", "?", "??", "{", "{", "{",
"*", "*?", "+", "+?", "?", "??", "{", "{",
- "class", "negclass", "Ref",
- "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", "Once",
+ "class", "Ref",
+ "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not",
+ "AssertB", "AssertB not", "Reverse", "Once", "Cond", "Cref",
"Brazero", "Braminzero", "Bra"
};
-static void print_internals(pcre *re)
+static void print_internals(pcre *re, FILE *outfile)
{
unsigned char *code = ((real_pcre *)re)->code;
-printf("------------------------------------------------------------------\n");
+fprintf(outfile, "------------------------------------------------------------------\n");
for(;;)
{
int c;
int charlength;
- printf("%3d ", code - ((real_pcre *)re)->code);
+ fprintf(outfile, "%3d ", (int)(code - ((real_pcre *)re)->code));
if (*code >= OP_BRA)
{
- printf("%3d Bra %d", (code[1] << 8) + code[2], *code - OP_BRA);
+ fprintf(outfile, "%3d Bra %d", (code[1] << 8) + code[2], *code - OP_BRA);
code += 2;
}
else switch(*code)
{
case OP_END:
- printf(" %s\n", OP_names[*code]);
- printf("------------------------------------------------------------------\n");
+ fprintf(outfile, " %s\n", OP_names[*code]);
+ fprintf(outfile, "------------------------------------------------------------------\n");
return;
+ case OP_OPT:
+ fprintf(outfile, " %.2x %s", code[1], OP_names[*code]);
+ code++;
+ break;
+
+ case OP_COND:
+ fprintf(outfile, "%3d Cond", (code[1] << 8) + code[2]);
+ code += 2;
+ break;
+
+ case OP_CREF:
+ fprintf(outfile, " %.2d %s", code[1], OP_names[*code]);
+ code++;
+ break;
+
case OP_CHARS:
charlength = *(++code);
- printf("%3d ", charlength);
+ fprintf(outfile, "%3d ", charlength);
while (charlength-- > 0)
- if (isprint(c = *(++code))) printf("%c", c); else printf("\\x%02x", c);
+ if (isprint(c = *(++code))) fprintf(outfile, "%c", c);
+ else fprintf(outfile, "\\x%02x", c);
break;
case OP_KETRMAX:
@@ -83,8 +102,15 @@ for(;;)
case OP_KET:
case OP_ASSERT:
case OP_ASSERT_NOT:
+ case OP_ASSERTBACK:
+ case OP_ASSERTBACK_NOT:
case OP_ONCE:
- printf("%3d %s", (code[1] << 8) + code[2], OP_names[*code]);
+ fprintf(outfile, "%3d %s", (code[1] << 8) + code[2], OP_names[*code]);
+ code += 2;
+ break;
+
+ case OP_REVERSE:
+ fprintf(outfile, "%3d %s", (code[1] << 8) + code[2], OP_names[*code]);
code += 2;
break;
@@ -101,36 +127,36 @@ for(;;)
case OP_TYPEQUERY:
case OP_TYPEMINQUERY:
if (*code >= OP_TYPESTAR)
- printf(" %s", OP_names[code[1]]);
- else if (isprint(c = code[1])) printf(" %c", c);
- else printf(" \\x%02x", c);
- printf("%s", OP_names[*code++]);
+ fprintf(outfile, " %s", OP_names[code[1]]);
+ else if (isprint(c = code[1])) fprintf(outfile, " %c", c);
+ else fprintf(outfile, " \\x%02x", c);
+ fprintf(outfile, "%s", OP_names[*code++]);
break;
case OP_EXACT:
case OP_UPTO:
case OP_MINUPTO:
- if (isprint(c = code[3])) printf(" %c{", c);
- else printf(" \\x%02x{", c);
- if (*code != OP_EXACT) printf(",");
- printf("%d}", (code[1] << 8) + code[2]);
- if (*code == OP_MINUPTO) printf("?");
+ if (isprint(c = code[3])) fprintf(outfile, " %c{", c);
+ else fprintf(outfile, " \\x%02x{", c);
+ if (*code != OP_EXACT) fprintf(outfile, ",");
+ fprintf(outfile, "%d}", (code[1] << 8) + code[2]);
+ if (*code == OP_MINUPTO) fprintf(outfile, "?");
code += 3;
break;
case OP_TYPEEXACT:
case OP_TYPEUPTO:
case OP_TYPEMINUPTO:
- printf(" %s{", OP_names[code[3]]);
- if (*code != OP_TYPEEXACT) printf("0,");
- printf("%d}", (code[1] << 8) + code[2]);
- if (*code == OP_TYPEMINUPTO) printf("?");
+ fprintf(outfile, " %s{", OP_names[code[3]]);
+ if (*code != OP_TYPEEXACT) fprintf(outfile, "0,");
+ fprintf(outfile, "%d}", (code[1] << 8) + code[2]);
+ if (*code == OP_TYPEMINUPTO) fprintf(outfile, "?");
code += 3;
break;
case OP_NOT:
- if (isprint(c = *(++code))) printf(" [^%c]", c);
- else printf(" [^\\x%02x]", c);
+ if (isprint(c = *(++code))) fprintf(outfile, " [^%c]", c);
+ else fprintf(outfile, " [^\\x%02x]", c);
break;
case OP_NOTSTAR:
@@ -139,33 +165,32 @@ for(;;)
case OP_NOTMINPLUS:
case OP_NOTQUERY:
case OP_NOTMINQUERY:
- if (isprint(c = code[1])) printf(" [^%c]", c);
- else printf(" [^\\x%02x]", c);
- printf("%s", OP_names[*code++]);
+ if (isprint(c = code[1])) fprintf(outfile, " [^%c]", c);
+ else fprintf(outfile, " [^\\x%02x]", c);
+ fprintf(outfile, "%s", OP_names[*code++]);
break;
case OP_NOTEXACT:
case OP_NOTUPTO:
case OP_NOTMINUPTO:
- if (isprint(c = code[3])) printf(" [^%c]{", c);
- else printf(" [^\\x%02x]{", c);
- if (*code != OP_NOTEXACT) printf(",");
- printf("%d}", (code[1] << 8) + code[2]);
- if (*code == OP_NOTMINUPTO) printf("?");
+ if (isprint(c = code[3])) fprintf(outfile, " [^%c]{", c);
+ else fprintf(outfile, " [^\\x%02x]{", c);
+ if (*code != OP_NOTEXACT) fprintf(outfile, ",");
+ fprintf(outfile, "%d}", (code[1] << 8) + code[2]);
+ if (*code == OP_NOTMINUPTO) fprintf(outfile, "?");
code += 3;
break;
case OP_REF:
- printf(" \\%d", *(++code));
+ fprintf(outfile, " \\%d", *(++code));
code++;
goto CLASS_REF_REPEAT;
case OP_CLASS:
- case OP_NEGCLASS:
{
int i, min, max;
- if (*code++ == OP_CLASS) printf(" [");
- else printf(" ^[");
+ code++;
+ fprintf(outfile, " [");
for (i = 0; i < 256; i++)
{
@@ -174,18 +199,18 @@ for(;;)
int j;
for (j = i+1; j < 256; j++)
if ((code[j/8] & (1 << (j&7))) == 0) break;
- if (i == '-' || i == ']') printf("\\");
- if (isprint(i)) printf("%c", i); else printf("\\x%02x", i);
+ if (i == '-' || i == ']') fprintf(outfile, "\\");
+ if (isprint(i)) fprintf(outfile, "%c", i); else fprintf(outfile, "\\x%02x", i);
if (--j > i)
{
- printf("-");
- if (j == '-' || j == ']') printf("\\");
- if (isprint(j)) printf("%c", j); else printf("\\x%02x", j);
+ fprintf(outfile, "-");
+ if (j == '-' || j == ']') fprintf(outfile, "\\");
+ if (isprint(j)) fprintf(outfile, "%c", j); else fprintf(outfile, "\\x%02x", j);
}
i = j;
}
}
- printf("]");
+ fprintf(outfile, "]");
code += 32;
CLASS_REF_REPEAT:
@@ -198,16 +223,16 @@ for(;;)
case OP_CRMINPLUS:
case OP_CRQUERY:
case OP_CRMINQUERY:
- printf("%s", OP_names[*code]);
+ fprintf(outfile, "%s", OP_names[*code]);
break;
case OP_CRRANGE:
case OP_CRMINRANGE:
min = (code[1] << 8) + code[2];
max = (code[3] << 8) + code[4];
- if (max == 0) printf("{%d,}", min);
- else printf("{%d,%d}", min, max);
- if (*code == OP_CRMINRANGE) printf("?");
+ if (max == 0) fprintf(outfile, "{%d,}", min);
+ else fprintf(outfile, "{%d,%d}", min, max);
+ if (*code == OP_CRMINRANGE) fprintf(outfile, "?");
code += 4;
break;
@@ -220,12 +245,12 @@ for(;;)
/* Anything else is just a one-node item */
default:
- printf(" %s", OP_names[*code]);
+ fprintf(outfile, " %s", OP_names[*code]);
break;
}
code++;
- printf("\n");
+ fprintf(outfile, "\n");
}
}
@@ -320,9 +345,8 @@ if (argc > 2)
pcre_malloc = new_malloc;
-/* Heading line, then prompt for first re if stdin */
+/* Heading line, then prompt for first regex if stdin */
-fprintf(outfile, "Testing Perl-Compatible Regular Expressions\n");
fprintf(outfile, "PCRE version %s\n\n", pcre_version());
/* Main loop */
@@ -341,7 +365,7 @@ while (!done)
if (infile == stdin) printf(" re> ");
if (fgets((char *)buffer, sizeof(buffer), infile) == NULL) break;
- if (infile != stdin) fprintf(outfile, (char *)buffer);
+ if (infile != stdin) fprintf(outfile, "%s", (char *)buffer);
p = buffer;
while (isspace(*p)) p++;
@@ -379,7 +403,7 @@ while (!done)
done = 1;
goto CONTINUE;
}
- if (infile != stdin) fprintf(outfile, (char *)pp);
+ if (infile != stdin) fprintf(outfile, "%s", (char *)pp);
}
/* Terminate the pattern at the delimiter */
@@ -403,7 +427,6 @@ while (!done)
case 'E': options |= PCRE_DOLLAR_ENDONLY; break;
case 'P': do_posix = 1; break;
case 'S': do_study = 1; break;
- case 'I': study_options |= PCRE_CASELESS; break;
case 'U': options |= PCRE_UNGREEDY; break;
case 'X': options |= PCRE_EXTRA; break;
case '\n': case ' ': break;
@@ -444,7 +467,7 @@ while (!done)
register int i;
clock_t time_taken;
clock_t start_time = clock();
- for (i = 0; i < 4000; i++)
+ for (i = 0; i < LOOPREPEAT; i++)
{
re = pcre_compile((char *)p, options, &error, &erroroffset);
if (re != NULL) free(re);
@@ -487,7 +510,7 @@ while (!done)
{
int first_char, count;
- if (debug || do_debug) print_internals(re);
+ if (debug || do_debug) print_internals(re, outfile);
count = pcre_info(re, &options, &first_char);
if (count < 0) fprintf(outfile,
@@ -533,7 +556,7 @@ while (!done)
register int i;
clock_t time_taken;
clock_t start_time = clock();
- for (i = 0; i < 4000; i++)
+ for (i = 0; i < LOOPREPEAT; i++)
extra = pcre_study(re, study_options, &error);
time_taken = clock() - start_time;
if (extra != NULL) free(extra);
@@ -593,7 +616,7 @@ while (!done)
{
unsigned char *q;
int count, c;
- int offsets[30];
+ int offsets[45];
int size_offsets = sizeof(offsets)/sizeof(int);
options = 0;
@@ -604,7 +627,7 @@ while (!done)
done = 1;
goto CONTINUE;
}
- if (infile != stdin) fprintf(outfile, (char *)buffer);
+ if (infile != stdin) fprintf(outfile, "%s", (char *)buffer);
len = (int)strlen((char *)buffer);
while (len > 0 && isspace(buffer[len-1])) len--;
@@ -658,22 +681,6 @@ while (!done)
options |= PCRE_NOTBOL;
continue;
- case 'E':
- options |= PCRE_DOLLAR_ENDONLY;
- continue;
-
- case 'I':
- options |= PCRE_CASELESS;
- continue;
-
- case 'M':
- options |= PCRE_MULTILINE;
- continue;
-
- case 'S':
- options |= PCRE_DOTALL;
- continue;
-
case 'O':
while(isdigit(*p)) n = n * 10 + *p++ - '0';
if (n <= (int)(sizeof(offsets)/sizeof(int))) size_offsets = n;
@@ -714,7 +721,7 @@ while (!done)
{
if (pmatch[i].rm_so >= 0)
{
- fprintf(outfile, "%2d: ", i);
+ fprintf(outfile, "%2d: ", (int)i);
pchars(dbuffer + pmatch[i].rm_so,
pmatch[i].rm_eo - pmatch[i].rm_so);
fprintf(outfile, "\n");
@@ -746,7 +753,7 @@ while (!done)
if (count == 0)
{
fprintf(outfile, "Matched, but too many substrings\n");
- count = size_offsets/2;
+ count = size_offsets/3;
}
if (count >= 0)
diff --git a/perltest b/perltest
index 7c2114b..c6faeda 100755
--- a/perltest
+++ b/perltest
@@ -39,7 +39,7 @@ if (@ARGV > 1)
}
else { $outfile = "STDOUT"; }
-printf($outfile "Perl Regular Expressions\n\n");
+printf($outfile "Perl $] Regular Expressions\n\n");
# Main loop
@@ -70,7 +70,7 @@ for (;;)
eval "\$_ =~ ${pattern}";
if ($@)
{
- printf $outfile "Error: $@\n";
+ printf $outfile "Error: $@";
next NEXT_RE;
}
diff --git a/pgrep.c b/pgrep.c
index b2ec7cb..2f48d06 100644
--- a/pgrep.c
+++ b/pgrep.c
@@ -64,7 +64,7 @@ pgrep(FILE *in, char *name)
int rc = 1;
int linenumber = 0;
int count = 0;
-int offsets[2];
+int offsets[99];
char buffer[BUFSIZ];
while (fgets(buffer, sizeof(buffer), in) != NULL)
@@ -74,7 +74,7 @@ while (fgets(buffer, sizeof(buffer), in) != NULL)
if (length > 0 && buffer[length-1] == '\n') buffer[--length] = 0;
linenumber++;
- match = pcre_exec(pattern, hints, buffer, length, 0, offsets, 2) >= 0;
+ match = pcre_exec(pattern, hints, buffer, length, 0, offsets, 99) >= 0;
if (match && whole_lines && offsets[1] != length) match = FALSE;
if (match != invert)
diff --git a/study.c b/study.c
index e81d41f..fca503b 100644
--- a/study.c
+++ b/study.c
@@ -37,6 +37,31 @@ the external pcre header. */
/*************************************************
+* Set a bit and maybe its alternate case *
+*************************************************/
+
+/* Given a character, set its bit in the table, and also the bit for the other
+version of a letter if we are caseless.
+
+Arguments:
+ start_bits points to the bit map
+ c is the character
+ caseless the caseless flag
+
+Returns: nothing
+*/
+
+static void
+set_bit(uschar *start_bits, int c, BOOL caseless)
+{
+start_bits[c/8] |= (1 << (c&7));
+if (caseless && (pcre_ctypes[c] & ctype_letter) != 0)
+ start_bits[pcre_fcc[c]/8] |= (1 << (pcre_fcc[c]&7));
+}
+
+
+
+/*************************************************
* Create bitmap of starting chars *
*************************************************/
@@ -47,12 +72,13 @@ goes by, we may be able to get more clever at doing this.
Arguments:
code points to an expression
start_bits points to a 32-byte table, initialized to 0
+ caseless the current state of the caseless flag
Returns: TRUE if table built, FALSE otherwise
*/
static BOOL
-set_start_bits(const uschar *code, uschar *start_bits)
+set_start_bits(const uschar *code, uschar *start_bits, BOOL caseless)
{
register int c;
@@ -65,9 +91,12 @@ do
{
try_next = FALSE;
+ /* If a branch starts with a bracket or a positive lookahead assertion,
+ recurse to set bits from within them. That's all for this branch. */
+
if ((int)*tcode >= OP_BRA || *tcode == OP_ASSERT)
{
- if (!set_start_bits(tcode, start_bits)) return FALSE;
+ if (!set_start_bits(tcode, start_bits, caseless)) return FALSE;
}
else switch(*tcode)
@@ -75,11 +104,29 @@ do
default:
return FALSE;
+ /* Skip over lookbehind and negative lookahead assertions */
+
+ case OP_ASSERT_NOT:
+ case OP_ASSERTBACK:
+ case OP_ASSERTBACK_NOT:
+ try_next = TRUE;
+ do tcode += (tcode[1] << 8) + tcode[2]; while (*tcode == OP_ALT);
+ tcode += 3;
+ break;
+
+ /* Skip over an option setting, changing the caseless flag */
+
+ case OP_OPT:
+ caseless = (tcode[1] & PCRE_CASELESS) != 0;
+ tcode += 2;
+ try_next = TRUE;
+ break;
+
/* BRAZERO does the bracket, but carries on. */
case OP_BRAZERO:
case OP_BRAMINZERO:
- if (!set_start_bits(++tcode, start_bits)) return FALSE;
+ if (!set_start_bits(++tcode, start_bits, caseless)) return FALSE;
do tcode += (tcode[1] << 8) + tcode[2]; while (*tcode == OP_ALT);
tcode += 3;
try_next = TRUE;
@@ -91,7 +138,7 @@ do
case OP_MINSTAR:
case OP_QUERY:
case OP_MINQUERY:
- start_bits[tcode[1]/8] |= (1 << (tcode[1]&7));
+ set_bit(start_bits, tcode[1], caseless);
tcode += 2;
try_next = TRUE;
break;
@@ -100,7 +147,7 @@ do
case OP_UPTO:
case OP_MINUPTO:
- start_bits[tcode[3]/8] |= (1 << (tcode[3]&7));
+ set_bit(start_bits, tcode[3], caseless);
tcode += 4;
try_next = TRUE;
break;
@@ -115,7 +162,7 @@ do
case OP_PLUS:
case OP_MINPLUS:
- start_bits[tcode[1]/8] |= (1 << (tcode[1]&7));
+ set_bit(start_bits, tcode[1], caseless);
break;
/* Single character type sets the bits and stops */
@@ -208,7 +255,6 @@ do
according to the repeat count. */
case OP_CLASS:
- case OP_NEGCLASS:
{
tcode++;
for (c = 0; c < 32; c++) start_bits[c] |= tcode[c];
@@ -267,7 +313,6 @@ Returns: pointer to a pcre_extra block,
pcre_extra *
pcre_study(const pcre *external_re, int options, const char **errorptr)
{
-BOOL caseless;
uschar start_bits[32];
real_pcre_extra *extra;
const real_pcre *re = (const real_pcre *)external_re;
@@ -286,10 +331,6 @@ if ((options & ~PUBLIC_STUDY_OPTIONS) != 0)
return NULL;
}
-/* Caseless can either be from the compiled regex or from options. */
-
-caseless = ((re->options | options) & PCRE_CASELESS) != 0;
-
/* For an anchored pattern, or an unchored pattern that has a first char, or a
multiline pattern that matches only at "line starts", no further processing at
present. */
@@ -300,24 +341,8 @@ if ((re->options & (PCRE_ANCHORED|PCRE_FIRSTSET|PCRE_STARTLINE)) != 0)
/* See if we can find a fixed set of initial characters for the pattern. */
memset(start_bits, 0, 32 * sizeof(uschar));
-if (!set_start_bits(re->code, start_bits)) return NULL;
-
-/* If this studying is caseless, scan the created bit map and duplicate the
-bits for any letters. */
-
-if (caseless)
- {
- register int c;
- for (c = 0; c < 256; c++)
- {
- if ((start_bits[c/8] & (1 << (c&7))) != 0 &&
- (pcre_ctypes[c] & ctype_letter) != 0)
- {
- int d = pcre_fcc[c];
- start_bits[d/8] |= (1 << (d&7));
- }
- }
- }
+if (!set_start_bits(re->code, start_bits, (re->options & PCRE_CASELESS) != 0))
+ return NULL;
/* Get an "extra" block and put the information therein. */
@@ -329,7 +354,7 @@ if (extra == NULL)
return NULL;
}
-extra->options = PCRE_STUDY_MAPPED | (caseless? PCRE_STUDY_CASELESS : 0);
+extra->options = PCRE_STUDY_MAPPED;
memcpy(extra->start_bits, start_bits, sizeof(start_bits));
return (pcre_extra *)extra;
diff --git a/testinput b/testinput
index 9d56fef..43f2914 100644
--- a/testinput
+++ b/testinput
@@ -1383,11 +1383,12 @@
/\Aabc\Z/m
abc
+ abc\n
*** Failers
qqq\nabc
abc\nzzz
qqq\nabc\nzzz
-
+
/\A(.)*\Z/s
abc\ndef
@@ -1440,9 +1441,9 @@
ABCabc
abcABC
-/(main(OPT)?)+/
+/(main(O)?)+/
mainmain
- mainOPTmain
+ mainOmain
/ab{3cd/
ab{3cd
@@ -1599,5 +1600,60 @@
/P[^*]TAIRE[^*]{1,}?LL/
xxxxxxxxxxxPSTAIREISLLxxxxxxxxx
-
+
+/(\.\d\d[1-9]?)\d+/
+ 1.230003938
+ 1.875000282
+ 1.235
+
+/(\.\d\d((?=0)|\d(?=\d)))/
+ 1.230003938
+ 1.875000282
+ *** Failers
+ 1.235
+
+/a(?)b/
+ ab
+
+/\b(foo)\s+(\w+)/i
+ Food is on the foo table
+
+/foo(.*)bar/
+ The food is under the bar in the barn.
+
+/foo(.*?)bar/
+ The food is under the bar in the barn.
+
+/(.*)(\d*)/
+ I have 2 numbers: 53147
+
+/(.*)(\d+)/
+ I have 2 numbers: 53147
+
+/(.*?)(\d*)/
+ I have 2 numbers: 53147
+
+/(.*?)(\d+)/
+ I have 2 numbers: 53147
+
+/(.*)(\d+)$/
+ I have 2 numbers: 53147
+
+/(.*?)(\d+)$/
+ I have 2 numbers: 53147
+
+/(.*)\b(\d+)$/
+ I have 2 numbers: 53147
+
+/(.*\D)(\d+)$/
+ I have 2 numbers: 53147
+
+/^\D*(?!123)/
+ ABC123
+
+/^(\D*)(?=\d)(?!123)/
+ ABC445
+ *** Failers
+ ABC123
+
/ End of test input /
diff --git a/testinput2 b/testinput2
index e922811..360e48b 100644
--- a/testinput2
+++ b/testinput2
@@ -1,14 +1,9 @@
/(a)b|/
-/(a*)*/
-
-/(abc|)+/
-
/abc/
abc
defabc
\Aabc
- \IABC
*** Failers
\Adefabc
ABC
@@ -30,7 +25,6 @@
/^abc$/
abc
- \Mdef\nabc
*** Failers
def\nabc
@@ -76,14 +70,6 @@
this sentence eventually mentions a CAT cat
this sentences rambles on and on for a while to elephant ElePhant
-/cat|dog|elephant/IS
- this sentence eventually mentions a CAT cat
- this sentences rambles on and on for a while to elephant ElePhant
-
-/cat|dog|elephant/IS
- \Ithis sentence eventually mentions a CAT cat
- \Ithis sentences rambles on and on for a while to elephant ElePhant
-
/a|[bcd]/S
/(a|[^\dZ])/S
@@ -97,25 +83,22 @@
/(a)(b)(c)\2/
abcb
\O0abcb
- \O2abcb
- \O4abcb
+ \O3abcb
\O6abcb
- \O8abcb
+ \O9abcb
+ \O12abcb
/(a)bc|(a)(b)\2/
abc
\O0abc
- \O2abc
- \O4abc
+ \O3abc
+ \O6abc
aba
\O0aba
- \O2aba
- \O4aba
+ \O3aba
\O6aba
- \O8aba
-
-/^a.b/
- \Sa\nb
+ \O9aba
+ \O12aba
/abc$/E
abc
@@ -123,15 +106,6 @@
abc\n
abc\ndef
-/abc$/
- *** Failers
- \Eabc\n
- \Eabc\ndef
-
-/abc$/m
- \Eabc\n
- \Eabc\ndef
-
/(a)(b)(c)(d)(e)\6/
/the quick brown fox/
@@ -145,40 +119,6 @@
/ab(?z)cd/
-".*/\Xfoo"X
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/it/you/see/
-
-"(?X).*/\Xfoo"
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/it/you/see/
-
-".*/\Xfoo"X
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
-
-"(?X).*/\Xfoo"
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
-
-/(\.\d\d[1-9]?)\d+/
- 1.230003938
- 1.875000282
- 1.235
-
-/(\.\d\d[1-9]?)\X\d+/X
- 1.230003938
- 1.875000282
- *** Failers
- 1.235
-
-/(\.\d\d((?=0)|\d(?=\d)))/
- 1.230003938
- 1.875000282
- *** Failers
- 1.235
-
-/^(\w+\X|\s+\X)*$/X
- now is the time for all good men to come to the aid of the party
- *** Failers
- this is not a line with only words and spaces!
-
/^abc|def/
abcdef
abcdef\B
@@ -223,97 +163,239 @@
/(abc\1)/P
abc
-"(?>.*/)foo"X
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/it/you/see/
+/)/
-"(?>.*/)foo"X
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
+/a[]b/
-/(?>(\.\d\d[1-9]?))\d+/X
- 1.230003938
- 1.875000282
- *** Failers
- 1.235
+/[^aeiou ]{3,}/
+ co-processors, and for
+
+/<.*>/
+ abc<def>ghi<klm>nop
-/^((?>\w+)|(?>\s+))*$/X
- now is the time for all good men to come to the aid of the party
- *** Failers
- this is not a line with only words and spaces!
+/<.*?>/
+ abc<def>ghi<klm>nop
+
+/<.*>/U
+ abc<def>ghi<klm>nop
-/(\d+)(\w)/X
- 12345a
- 12345+
+/<.*>(?U)/
+ abc<def>ghi<klm>nop
-/((?>\d+))(\w)/X
- 12345a
+/<.*?>/U
+ abc<def>ghi<klm>nop
+
+/={3,}/U
+ abc========def
+
+/(?U)={3,}?/
+ abc========def
+
+/(?<!bar|cattle)foo/
+ foo
+ catfoo
*** Failers
- 12345+
+ the barfoo
+ and cattlefoo
-/([a]*)*/
+/(?<=a+)b/
-/([ab]*)*/
+/(?<=aaa|b{0,3})b/
-/([^a]*)*/
+/(?<!(foo)a\1)bar/
-/([^ab]*)*/
+/(?i)abc/
-/([a]*?)*/
+/(a|(?m)a)/
-/([ab]*?)*/
+/(?i)^1234/
-/([^a]*?)*/
+/(^b|(?i)^d)/
-/([^ab]*?)*/
+/(?s).*/
-/(?>a*)*/X
+/[abcd]/S
-/((?>a*))*/X
+/(?i)[abcd]/S
-/((?>a*?))*/X
+/(?m)[xy]|(b|c)/S
-/)/
+/(^a|^b)/m
-/a[]b/
+/(?i)(^a|^b)/m
-/[^a]/
- \Iaaaabcd
- \IaaAabcd
+/(a)(?(1)a|b|c)/
-/[^az]/
- \Iaaaabcd
- \IaaAabcd
+/(?(?=a)a|b|c)/
-/[^az]/
- \Izazabcd
- \IAaZabcd
-
-/[^aeiou ]{3,}/
- co-processors, and for
- \Ico-processors, and for
-
-/((a)*)*/
-
-/((a|b|c)*)*/
+/(?(1a)/
-/<.*>/
- abc<def>ghi<klm>nop
+/(?(?i))/
-/<.*?>/
- abc<def>ghi<klm>nop
+/(?(abc))/
-/<.*>/U
- abc<def>ghi<klm>nop
-
-/<.*>(?U)/
- abc<def>ghi<klm>nop
+/(?(?<ab))/
-/<.*?>/U
- abc<def>ghi<klm>nop
+/((?s)blah)\s+\1/
+
+/((?i)blah)\s+\1/
+
+/((?i)b)/DS
+
+/(a*b|(?i:c*(?-i)d))/S
+
+/a$/
+ a
+ a\n
+ *** Failers
+ \Za
+ \Za\n
+
+/a$/m
+ a
+ a\n
+ \Za\n
+ *** Failers
+ \Za
-/={3,}/U
- abc========def
+/\Aabc/m
+
+/^abc/m
+
+/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/
+ aaaaabbbbbcccccdef
+
+/(?<=foo)[ab]/S
+
+/(?<!foo)(alpha|omega)/S
+
+/(?!alphabet)[ab]/S
+
+/(?<=foo\n)^bar/m
+
+/(?>^abc)/m
+ abc
+ def\nabc
+ *** Failers
+ defabc
+
+/(?<=ab(c+)d)ef/
+
+/(?<=ab(?<=c+)d)ef/
+
+/(?<=ab(c|de)f)g/
+
+/The next two are in testinput2 because they have variable length branches/
+
+/(?<=bullock|donkey)-cart/
+ the bullock-cart
+ a donkey-cart race
+ *** Failers
+ cart
+ horse-and-cart
+
+/(?<=ab(?i)x|y|z)/
+
+/(?<=ab(?i)x(?-i)y|(?i)z|b)ZZ/
+ abxyZZ
+ abXyZZ
+ ZZZ
+ zZZ
+ bZZ
+ BZZ
+ *** Failers
+ ZZ
+ abXYZZ
+ zzz
+ bzz
+
+/(?<!(foo)a)bar/
+ bar
+ foobbar
+ *** Failers
+ fooabar
+
+/This one is here because Perl 5.005_02 doesn't fail it/
+
+/^(a)?(?(1)a|b)+$/
+ *** Failers
+ a
+
+/This one is here because I think Perl 5.005_02 gets the setting of $1 wrong/
+
+/^(a\1?){4}$/
+ aaaaaa
-/(?U)={3,}?/
- abc========def
+/These are syntax tests from Perl 5.005/
+
+/a[b-a]/
+
+/a[]b/
+
+/a[/
+
+/*a/
+
+/(*)b/
+
+/a\/
+
+/abc)/
+
+/(abc/
+
+/a**/
+
+/)(/
+
+/\1/
+
+/\2/
+
+/(a)|\2/
+
+/a[b-a]/i
+
+/a[]b/i
+
+/a[/i
+
+/*a/i
+
+/(*)b/i
+
+/a\/i
+
+/abc)/i
+
+/(abc/i
+
+/a**/i
+
+/)(/i
+
+/:(?:/
+
+/(?<%)b/
+
+/a(?{)b/
+
+/a(?{{})b/
+
+/a(?{}})b/
+
+/a(?{"{"})b/
+
+/a(?{"{"}})b/
+
+/(?(1?)a|b)/
+
+/(?(1)a|b|c)/
+
+/[a[:xyz:/
+
+/(?<=x+)y/
+
+/a{37,17}/
/ End of test input /
diff --git a/testinput3 b/testinput3
new file mode 100644
index 0000000..2816cf2
--- /dev/null
+++ b/testinput3
@@ -0,0 +1,1603 @@
+/(?<!bar)foo/
+ foo
+ catfood
+ arfootle
+ rfoosh
+ *** Failers
+ barfoo
+ towbarfoo
+
+/\w{3}(?<!bar)foo/
+ catfood
+ *** Failers
+ foo
+ barfoo
+ towbarfoo
+
+/(?<=(foo)a)bar/
+ fooabar
+ *** Failers
+ bar
+ foobbar
+
+/\Aabc\z/m
+ abc
+ *** Failers
+ abc\n
+ qqq\nabc
+ abc\nzzz
+ qqq\nabc\nzzz
+
+"(?>.*/)foo"
+ /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/it/you/see/
+
+"(?>.*/)foo"
+ /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
+
+/(?>(\.\d\d[1-9]?))\d+/
+ 1.230003938
+ 1.875000282
+ *** Failers
+ 1.235
+
+/^((?>\w+)|(?>\s+))*$/
+ now is the time for all good men to come to the aid of the party
+ *** Failers
+ this is not a line with only words and spaces!
+
+/(\d+)(\w)/
+ 12345a
+ 12345+
+
+/((?>\d+))(\w)/
+ 12345a
+ *** Failers
+ 12345+
+
+/(?>a+)b/
+ aaab
+
+/((?>a+)b)/
+ aaab
+
+/(?>(a+))b/
+ aaab
+
+/(?>b)+/
+ aaabbbccc
+
+/(?>a+|b+|c+)*c/
+ aaabbbbccccd
+
+/((?>[^()]+)|\([^()]*\))+/
+ ((abc(ade)ufh()()x
+
+/\(((?>[^()]+)|\([^()]+\))+\)/
+ (abc)
+ (abc(def)xyz)
+ *** Failers
+ ((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+
+/a(?-i)b/i
+ ab
+ *** Failers
+ Ab
+ aB
+ AB
+
+/(a (?x)b c)d e/
+ a bcd e
+ *** Failers
+ a b cd e
+ abcd e
+ a bcde
+
+/(a b(?x)c d (?-x)e f)/
+ a bcde f
+ *** Failers
+ abcdef
+
+/(a(?i)b)c/
+ abc
+ aBc
+ *** Failers
+ abC
+ aBC
+ Abc
+ ABc
+ ABC
+ AbC
+
+/a(?i:b)c/
+ abc
+ aBc
+ *** Failers
+ ABC
+ abC
+ aBC
+
+/a(?i:b)*c/
+ aBc
+ aBBc
+ *** Failers
+ aBC
+ aBBC
+
+/a(?=b(?i)c)\w\wd/
+ abcd
+ abCd
+ *** Failers
+ aBCd
+ abcD
+
+/(?s-i:more.*than).*million/i
+ more than million
+ more than MILLION
+ more \n than Million
+ *** Failers
+ MORE THAN MILLION
+ more \n than \n million
+
+/(?:(?s-i)more.*than).*million/i
+ more than million
+ more than MILLION
+ more \n than Million
+ *** Failers
+ MORE THAN MILLION
+ more \n than \n million
+
+/(?>a(?i)b+)+c/
+ abc
+ aBbc
+ aBBc
+ *** Failers
+ Abc
+ abAb
+ abbC
+
+/(?=a(?i)b)\w\wc/
+ abc
+ aBc
+ *** Failers
+ Ab
+ abC
+ aBC
+
+/(?<=a(?i)b)(\w\w)c/
+ abxxc
+ aBxxc
+ *** Failers
+ Abxxc
+ ABxxc
+ abxxC
+
+/(?:(a)|b)(?(1)A|B)/
+ aA
+ bB
+ *** Failers
+ aB
+ bA
+
+/^(a)?(?(1)a|b)+$/
+ aa
+ b
+ bb
+ *** Failers
+ ab
+
+/^(?(?=abc)\w{3}:|\d\d)$/
+ abc:
+ 12
+ *** Failers
+ 123
+ xyz
+
+/^(?(?!abc)\d\d|\w{3}:)$/
+ abc:
+ 12
+ *** Failers
+ 123
+ xyz
+
+/(?(?<=foo)bar|cat)/
+ foobar
+ cat
+ fcat
+ focat
+ *** Failers
+ foocat
+
+/(?(?<!foo)cat|bar)/
+ foobar
+ cat
+ fcat
+ focat
+ *** Failers
+ foocat
+
+/( \( )? [^()]+ (?(1) \) |) /x
+ abcd
+ (abcd)
+ the quick (abcd) fox
+ (abcd
+
+/( \( )? [^()]+ (?(1) \) ) /x
+ abcd
+ (abcd)
+ the quick (abcd) fox
+ (abcd
+
+/^(?(2)a|(1)(2))+$/
+ 12
+ 12a
+ 12aa
+ *** Failers
+ 1234
+
+/((?i)blah)\s+\1/
+ blah blah
+ BLAH BLAH
+ Blah Blah
+ blaH blaH
+ *** Failers
+ blah BLAH
+ Blah blah
+ blaH blah
+
+/((?i)blah)\s+(?i:\1)/
+ blah blah
+ BLAH BLAH
+ Blah Blah
+ blaH blaH
+ blah BLAH
+ Blah blah
+ blaH blah
+
+/(?>a*)*/
+ a
+ aa
+ aaaa
+
+/(abc|)+/
+ abc
+ abcabc
+ abcabcabc
+ xyz
+
+/([a]*)*/
+ a
+ aaaaa
+
+/([ab]*)*/
+ a
+ b
+ ababab
+ aaaabcde
+ bbbb
+
+/([^a]*)*/
+ b
+ bbbb
+ aaa
+
+/([^ab]*)*/
+ cccc
+ abab
+
+/([a]*?)*/
+ a
+ aaaa
+
+/([ab]*?)*/
+ a
+ b
+ abab
+ baba
+
+/([^a]*?)*/
+ b
+ bbbb
+ aaa
+
+/([^ab]*?)*/
+ c
+ cccc
+ baba
+
+/(?>a*)*/
+ a
+ aaabcde
+
+/((?>a*))*/
+ aaaaa
+ aabbaa
+
+/((?>a*?))*/
+ aaaaa
+ aabbaa
+
+/(?(?=[^a-z]+[a-z]) \d{2}-[a-z]{3}-\d{2} | \d{2}-\d{2}-\d{2} ) /x
+ 12-sep-98
+ 12-09-98
+ *** Failers
+ sep-12-98
+
+/(?<=(foo))bar\1/
+ foobarfoo
+ foobarfootling
+ *** Failers
+ foobar
+ barfoo
+
+/(?i:saturday|sunday)/
+ saturday
+ sunday
+ Saturday
+ Sunday
+ SATURDAY
+ SUNDAY
+ SunDay
+
+/(a(?i)bc|BB)x/
+ abcx
+ aBCx
+ bbx
+ BBx
+ *** Failers
+ abcX
+ aBCX
+ bbX
+ BBX
+
+/^([ab](?i)[cd]|[ef])/
+ ac
+ aC
+ bD
+ elephant
+ Europe
+ frog
+ France
+ *** Failers
+ Africa
+
+/^(ab|a(?i)[b-c](?m-i)d|x(?i)y|z)/
+ ab
+ aBd
+ xy
+ xY
+ zebra
+ Zambesi
+ *** Failers
+ aCD
+ XY
+
+/(?<=foo\n)^bar/m
+ foo\nbar
+ *** Failers
+ bar
+ baz\nbar
+
+/(?<=(?<!foo)bar)baz/
+ barbaz
+ barbarbaz
+ koobarbaz
+ *** Failers
+ baz
+ foobarbaz
+
+/The case of aaaaaa is missed out below because I think Perl 5.005_02 gets/
+/it wrong; it sets $1 to aaa rather than aa. Compare the following test,/
+/where it does set $1 to aa when matching aaaaaa./
+
+/^(a\1?){4}$/
+ a
+ aa
+ aaa
+ aaaa
+ aaaaa
+ aaaaaaa
+ aaaaaaaa
+ aaaaaaaaa
+ aaaaaaaaaa
+ aaaaaaaaaaa
+ aaaaaaaaaaaa
+ aaaaaaaaaaaaa
+ aaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaa
+
+/^(a\1?)(a\1?)(a\2?)(a\3?)$/
+ a
+ aa
+ aaa
+ aaaa
+ aaaaa
+ aaaaaa
+ aaaaaaa
+ aaaaaaaa
+ aaaaaaaaa
+ aaaaaaaaaa
+ aaaaaaaaaaa
+ aaaaaaaaaaaa
+ aaaaaaaaaaaaa
+ aaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaa
+
+/The following tests are taken from the Perl 5.005 test suite; some of them/
+/are compatible with 5.004, but I'd rather not have to sort them out./
+
+/abc/
+ abc
+ xabcy
+ ababc
+ *** Failers
+ xbc
+ axc
+ abx
+
+/ab*c/
+ abc
+
+/ab*bc/
+ abc
+ abbc
+ abbbbc
+
+/.{1}/
+ abbbbc
+
+/.{3,4}/
+ abbbbc
+
+/ab{0,}bc/
+ abbbbc
+
+/ab+bc/
+ abbc
+ *** Failers
+ abc
+ abq
+
+/ab{1,}bc/
+
+/ab+bc/
+ abbbbc
+
+/ab{1,}bc/
+ abbbbc
+
+/ab{1,3}bc/
+ abbbbc
+
+/ab{3,4}bc/
+ abbbbc
+
+/ab{4,5}bc/
+ *** Failers
+ abq
+ abbbbc
+
+/ab?bc/
+ abbc
+ abc
+
+/ab{0,1}bc/
+ abc
+
+/ab?bc/
+
+/ab?c/
+ abc
+
+/ab{0,1}c/
+ abc
+
+/^abc$/
+ abc
+ *** Failers
+ abbbbc
+ abcc
+
+/^abc/
+ abcc
+
+/^abc$/
+
+/abc$/
+ aabc
+ *** Failers
+ aabc
+ aabcd
+
+/^/
+ abc
+
+/$/
+ abc
+
+/a.c/
+ abc
+ axc
+
+/a.*c/
+ axyzc
+
+/a[bc]d/
+ abd
+ *** Failers
+ axyzd
+ abc
+
+/a[b-d]e/
+ ace
+
+/a[b-d]/
+ aac
+
+/a[-b]/
+ a-
+
+/a[b-]/
+ a-
+
+/a]/
+ a]
+
+/a[]]b/
+ a]b
+
+/a[^bc]d/
+ aed
+ *** Failers
+ abd
+ abd
+
+/a[^-b]c/
+ adc
+
+/a[^]b]c/
+ adc
+ *** Failers
+ a-c
+ a]c
+
+/\ba\b/
+ a-
+ -a
+ -a-
+
+/\by\b/
+ *** Failers
+ xy
+ yz
+ xyz
+
+/\Ba\B/
+ *** Failers
+ a-
+ -a
+ -a-
+
+/\By\b/
+ xy
+
+/\by\B/
+ yz
+
+/\By\B/
+ xyz
+
+/\w/
+ a
+
+/\W/
+ -
+ *** Failers
+ -
+ a
+
+/a\sb/
+ a b
+
+/a\Sb/
+ a-b
+ *** Failers
+ a-b
+ a b
+
+/\d/
+ 1
+
+/\D/
+ -
+ *** Failers
+ -
+ 1
+
+/[\w]/
+ a
+
+/[\W]/
+ -
+ *** Failers
+ -
+ a
+
+/a[\s]b/
+ a b
+
+/a[\S]b/
+ a-b
+ *** Failers
+ a-b
+ a b
+
+/[\d]/
+ 1
+
+/[\D]/
+ -
+ *** Failers
+ -
+ 1
+
+/ab|cd/
+ abc
+ abcd
+
+/()ef/
+ def
+
+/$b/
+
+/a\(b/
+ a(b
+
+/a\(*b/
+ ab
+ a((b
+
+/a\\b/
+ a\b
+
+/((a))/
+ abc
+
+/(a)b(c)/
+ abc
+
+/a+b+c/
+ aabbabc
+
+/a{1,}b{1,}c/
+ aabbabc
+
+/a.+?c/
+ abcabc
+
+/(a+|b)*/
+ ab
+
+/(a+|b){0,}/
+ ab
+
+/(a+|b)+/
+ ab
+
+/(a+|b){1,}/
+ ab
+
+/(a+|b)?/
+ ab
+
+/(a+|b){0,1}/
+ ab
+
+/[^ab]*/
+ cde
+
+/abc/
+ *** Failers
+ b
+
+
+/a*/
+
+
+/([abc])*d/
+ abbbcd
+
+/([abc])*bcd/
+ abcd
+
+/a|b|c|d|e/
+ e
+
+/(a|b|c|d|e)f/
+ ef
+
+/abcd*efg/
+ abcdefg
+
+/ab*/
+ xabyabbbz
+ xayabbbz
+
+/(ab|cd)e/
+ abcde
+
+/[abhgefdc]ij/
+ hij
+
+/^(ab|cd)e/
+
+/(abc|)ef/
+ abcdef
+
+/(a|b)c*d/
+ abcd
+
+/(ab|ab*)bc/
+ abc
+
+/a([bc]*)c*/
+ abc
+
+/a([bc]*)(c*d)/
+ abcd
+
+/a([bc]+)(c*d)/
+ abcd
+
+/a([bc]*)(c+d)/
+ abcd
+
+/a[bcd]*dcdcde/
+ adcdcde
+
+/a[bcd]+dcdcde/
+ *** Failers
+ abcde
+ adcdcde
+
+/(ab|a)b*c/
+ abc
+
+/((a)(b)c)(d)/
+ abcd
+
+/[a-zA-Z_][a-zA-Z0-9_]*/
+ alpha
+
+/^a(bc+|b[eh])g|.h$/
+ abh
+
+/(bc+d$|ef*g.|h?i(j|k))/
+ effgz
+ ij
+ reffgz
+ *** Failers
+ effg
+ bcdd
+
+/((((((((((a))))))))))/
+ a
+
+/((((((((((a))))))))))\10/
+ aa
+
+/(((((((((a)))))))))/
+ a
+
+/multiple words of text/
+ *** Failers
+ aa
+ uh-uh
+
+/multiple words/
+ multiple words, yeah
+
+/(.*)c(.*)/
+ abcde
+
+/\((.*), (.*)\)/
+ (a, b)
+
+/[k]/
+
+/abcd/
+ abcd
+
+/a(bc)d/
+ abcd
+
+/a[-]?c/
+ ac
+
+/(abc)\1/
+ abcabc
+
+/([a-c]*)\1/
+ abcabc
+
+/(a)|\1/
+ a
+ *** Failers
+ ab
+ x
+
+/(([a-c])b*?\2)*/
+ ababbbcbc
+
+/(([a-c])b*?\2){3}/
+ ababbbcbc
+
+/((\3|b)\2(a)x)+/
+ aaaxabaxbaaxbbax
+
+/((\3|b)\2(a)){2,}/
+ bbaababbabaaaaabbaaaabba
+
+/abc/i
+ ABC
+ XABCY
+ ABABC
+ *** Failers
+ aaxabxbaxbbx
+ XBC
+ AXC
+ ABX
+
+/ab*c/i
+ ABC
+
+/ab*bc/i
+ ABC
+ ABBC
+
+/ab*?bc/i
+ ABBBBC
+
+/ab{0,}?bc/i
+ ABBBBC
+
+/ab+?bc/i
+ ABBC
+
+/ab+bc/i
+ *** Failers
+ ABC
+ ABQ
+
+/ab{1,}bc/i
+
+/ab+bc/i
+ ABBBBC
+
+/ab{1,}?bc/i
+ ABBBBC
+
+/ab{1,3}?bc/i
+ ABBBBC
+
+/ab{3,4}?bc/i
+ ABBBBC
+
+/ab{4,5}?bc/i
+ *** Failers
+ ABQ
+ ABBBBC
+
+/ab??bc/i
+ ABBC
+ ABC
+
+/ab{0,1}?bc/i
+ ABC
+
+/ab??bc/i
+
+/ab??c/i
+ ABC
+
+/ab{0,1}?c/i
+ ABC
+
+/^abc$/i
+ ABC
+ *** Failers
+ ABBBBC
+ ABCC
+
+/^abc/i
+ ABCC
+
+/^abc$/i
+
+/abc$/i
+ AABC
+
+/^/i
+ ABC
+
+/$/i
+ ABC
+
+/a.c/i
+ ABC
+ AXC
+
+/a.*?c/i
+ AXYZC
+
+/a.*c/i
+ *** Failers
+ AABC
+ AXYZD
+
+/a[bc]d/i
+ ABD
+
+/a[b-d]e/i
+ ACE
+ *** Failers
+ ABC
+ ABD
+
+/a[b-d]/i
+ AAC
+
+/a[-b]/i
+ A-
+
+/a[b-]/i
+ A-
+
+/a]/i
+ A]
+
+/a[]]b/i
+ A]B
+
+/a[^bc]d/i
+ AED
+
+/a[^-b]c/i
+ ADC
+ *** Failers
+ ABD
+ A-C
+
+/a[^]b]c/i
+ ADC
+
+/ab|cd/i
+ ABC
+ ABCD
+
+/()ef/i
+ DEF
+
+/$b/i
+ *** Failers
+ A]C
+ B
+
+/a\(b/i
+ A(B
+
+/a\(*b/i
+ AB
+ A((B
+
+/a\\b/i
+ A\B
+
+/((a))/i
+ ABC
+
+/(a)b(c)/i
+ ABC
+
+/a+b+c/i
+ AABBABC
+
+/a{1,}b{1,}c/i
+ AABBABC
+
+/a.+?c/i
+ ABCABC
+
+/a.*?c/i
+ ABCABC
+
+/a.{0,5}?c/i
+ ABCABC
+
+/(a+|b)*/i
+ AB
+
+/(a+|b){0,}/i
+ AB
+
+/(a+|b)+/i
+ AB
+
+/(a+|b){1,}/i
+ AB
+
+/(a+|b)?/i
+ AB
+
+/(a+|b){0,1}/i
+ AB
+
+/(a+|b){0,1}?/i
+ AB
+
+/[^ab]*/i
+ CDE
+
+/abc/i
+
+/a*/i
+
+
+/([abc])*d/i
+ ABBBCD
+
+/([abc])*bcd/i
+ ABCD
+
+/a|b|c|d|e/i
+ E
+
+/(a|b|c|d|e)f/i
+ EF
+
+/abcd*efg/i
+ ABCDEFG
+
+/ab*/i
+ XABYABBBZ
+ XAYABBBZ
+
+/(ab|cd)e/i
+ ABCDE
+
+/[abhgefdc]ij/i
+ HIJ
+
+/^(ab|cd)e/i
+ ABCDE
+
+/(abc|)ef/i
+ ABCDEF
+
+/(a|b)c*d/i
+ ABCD
+
+/(ab|ab*)bc/i
+ ABC
+
+/a([bc]*)c*/i
+ ABC
+
+/a([bc]*)(c*d)/i
+ ABCD
+
+/a([bc]+)(c*d)/i
+ ABCD
+
+/a([bc]*)(c+d)/i
+ ABCD
+
+/a[bcd]*dcdcde/i
+ ADCDCDE
+
+/a[bcd]+dcdcde/i
+
+/(ab|a)b*c/i
+ ABC
+
+/((a)(b)c)(d)/i
+ ABCD
+
+/[a-zA-Z_][a-zA-Z0-9_]*/i
+ ALPHA
+
+/^a(bc+|b[eh])g|.h$/i
+ ABH
+
+/(bc+d$|ef*g.|h?i(j|k))/i
+ EFFGZ
+ IJ
+ REFFGZ
+ *** Failers
+ ADCDCDE
+ EFFG
+ BCDD
+
+/((((((((((a))))))))))/i
+ A
+
+/((((((((((a))))))))))\10/i
+ AA
+
+/(((((((((a)))))))))/i
+ A
+
+/(?:(?:(?:(?:(?:(?:(?:(?:(?:(a))))))))))/i
+ A
+
+/(?:(?:(?:(?:(?:(?:(?:(?:(?:(a|b|c))))))))))/i
+ C
+
+/multiple words of text/i
+ *** Failers
+ AA
+ UH-UH
+
+/multiple words/i
+ MULTIPLE WORDS, YEAH
+
+/(.*)c(.*)/i
+ ABCDE
+
+/\((.*), (.*)\)/i
+ (A, B)
+
+/[k]/i
+
+/abcd/i
+ ABCD
+
+/a(bc)d/i
+ ABCD
+
+/a[-]?c/i
+ AC
+
+/(abc)\1/i
+ ABCABC
+
+/([a-c]*)\1/i
+ ABCABC
+
+/a(?!b)./
+ abad
+
+/a(?=d)./
+ abad
+
+/a(?=c|d)./
+ abad
+
+/a(?:b|c|d)(.)/
+ ace
+
+/a(?:b|c|d)*(.)/
+ ace
+
+/a(?:b|c|d)+?(.)/
+ ace
+ acdbcdbe
+
+/a(?:b|c|d)+(.)/
+ acdbcdbe
+
+/a(?:b|c|d){2}(.)/
+ acdbcdbe
+
+/a(?:b|c|d){4,5}(.)/
+ acdbcdbe
+
+/a(?:b|c|d){4,5}?(.)/
+ acdbcdbe
+
+/((foo)|(bar))*/
+ foobar
+
+/a(?:b|c|d){6,7}(.)/
+ acdbcdbe
+
+/a(?:b|c|d){6,7}?(.)/
+ acdbcdbe
+
+/a(?:b|c|d){5,6}(.)/
+ acdbcdbe
+
+/a(?:b|c|d){5,6}?(.)/
+ acdbcdbe
+
+/a(?:b|c|d){5,7}(.)/
+ acdbcdbe
+
+/a(?:b|c|d){5,7}?(.)/
+ acdbcdbe
+
+/a(?:b|(c|e){1,2}?|d)+?(.)/
+ ace
+
+/^(.+)?B/
+ AB
+
+/^([^a-z])|(\^)$/
+ .
+
+/^[<>]&/
+ <&OUT
+
+/^(a\1?){4}$/
+ aaaaaaaaaa
+ *** Failers
+ AB
+ aaaaaaaaa
+ aaaaaaaaaaa
+
+/^(a(?(1)\1)){4}$/
+ aaaaaaaaaa
+ *** Failers
+ aaaaaaaaa
+ aaaaaaaaaaa
+
+/(?:(f)(o)(o)|(b)(a)(r))*/
+ foobar
+
+/(?<=a)b/
+ ab
+ *** Failers
+ cb
+ b
+
+/(?<!c)b/
+ ab
+ b
+ b
+
+/(?:..)*a/
+ aba
+
+/(?:..)*?a/
+ aba
+
+/^(?:b|a(?=(.)))*\1/
+ abc
+
+/^(){3,5}/
+ abc
+
+/^(a+)*ax/
+ aax
+
+/^((a|b)+)*ax/
+ aax
+
+/^((a|bc)+)*ax/
+ aax
+
+/(a|x)*ab/
+ cab
+
+/(a)*ab/
+ cab
+
+/(?:(?i)a)b/
+ ab
+
+/((?i)a)b/
+ ab
+
+/(?:(?i)a)b/
+ Ab
+
+/((?i)a)b/
+ Ab
+
+/(?:(?i)a)b/
+ *** Failers
+ cb
+ aB
+
+/((?i)a)b/
+
+/(?i:a)b/
+ ab
+
+/((?i:a))b/
+ ab
+
+/(?i:a)b/
+ Ab
+
+/((?i:a))b/
+ Ab
+
+/(?i:a)b/
+ *** Failers
+ aB
+ aB
+
+/((?i:a))b/
+
+/(?:(?-i)a)b/i
+ ab
+
+/((?-i)a)b/i
+ ab
+
+/(?:(?-i)a)b/i
+ aB
+
+/((?-i)a)b/i
+ aB
+
+/(?:(?-i)a)b/i
+ *** Failers
+ aB
+ Ab
+
+/((?-i)a)b/i
+
+/(?:(?-i)a)b/i
+ aB
+
+/((?-i)a)b/i
+ aB
+
+/(?:(?-i)a)b/i
+ *** Failers
+ Ab
+ AB
+
+/((?-i)a)b/i
+
+/(?-i:a)b/i
+ ab
+
+/((?-i:a))b/i
+ ab
+
+/(?-i:a)b/i
+ aB
+
+/((?-i:a))b/i
+ aB
+
+/(?-i:a)b/i
+ *** Failers
+ AB
+ Ab
+
+/((?-i:a))b/i
+
+/(?-i:a)b/i
+ aB
+
+/((?-i:a))b/i
+ aB
+
+/(?-i:a)b/i
+ *** Failers
+ Ab
+ AB
+
+/((?-i:a))b/i
+
+/((?-i:a.))b/i
+ *** Failers
+ AB
+ a\nB
+
+/((?s-i:a.))b/i
+ a\nB
+
+/(?:c|d)(?:)(?:a(?:)(?:b)(?:b(?:))(?:b(?:)(?:b)))/
+ cabbbb
+
+/(?:c|d)(?:)(?:aaaaaaaa(?:)(?:bbbbbbbb)(?:bbbbbbbb(?:))(?:bbbbbbbb(?:)(?:bbbbbbbb)))/
+ caaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+
+/(ab)\d\1/i
+ Ab4ab
+ ab4Ab
+
+/foo\w*\d{4}baz/
+ foobar1234baz
+
+/x(~~)*(?:(?:F)?)?/
+ x~~
+
+/^a(?#xxx){3}c/
+ aaac
+
+/^a (?#xxx) (?#yyy) {3}c/x
+ aaac
+
+/(?<![cd])b/
+ *** Failers
+ B\nB
+ dbcb
+
+/(?<![cd])[ab]/
+ dbaacb
+
+/(?<!(c|d))b/
+
+/(?<!(c|d))[ab]/
+ dbaacb
+
+/(?<!cd)[ab]/
+ cdaccb
+
+/^(?:a?b?)*$/
+ *** Failers
+ dbcb
+ a--
+
+/((?s)^a(.))((?m)^b$)/
+ a\nb\nc\n
+
+/((?m)^b$)/
+ a\nb\nc\n
+
+/(?m)^b/
+ a\nb\n
+
+/(?m)^(b)/
+ a\nb\n
+
+/((?m)^b)/
+ a\nb\n
+
+/\n((?m)^b)/
+ a\nb\n
+
+/((?s).)c(?!.)/
+ a\nb\nc\n
+ a\nb\nc\n
+
+/((?s)b.)c(?!.)/
+ a\nb\nc\n
+ a\nb\nc\n
+
+/^b/
+
+/()^b/
+ *** Failers
+ a\nb\nc\n
+ a\nb\nc\n
+
+/((?m)^b)/
+ a\nb\nc\n
+
+/(?(1)a|b)/
+
+/(?(1)b|a)/
+ a
+
+/(x)?(?(1)a|b)/
+ *** Failers
+ a
+ a
+
+/(x)?(?(1)b|a)/
+ a
+
+/()?(?(1)b|a)/
+ a
+
+/()(?(1)b|a)/
+
+/()?(?(1)a|b)/
+ a
+
+/^(\()?blah(?(1)(\)))$/
+ (blah)
+ blah
+ *** Failers
+ a
+ blah)
+ (blah
+
+/^(\(+)?blah(?(1)(\)))$/
+ (blah)
+ blah
+ *** Failers
+ blah)
+ (blah
+
+/(?(?!a)a|b)/
+
+/(?(?!a)b|a)/
+ a
+
+/(?(?=a)b|a)/
+ *** Failers
+ a
+ a
+
+/(?(?=a)a|b)/
+ a
+
+/(?=(a+?))(\1ab)/
+ aaab
+
+/^(?=(a+?))\1ab/
+
+/(\w+:)+/
+ one:
+
+/$(?<=^(a))/
+ a
+
+/(?=(a+?))(\1ab)/
+ aaab
+
+/^(?=(a+?))\1ab/
+ *** Failers
+ aaab
+ aaab
+
+/([\w:]+::)?(\w+)$/
+ abcd
+ xy:z:::abcd
+
+/^[^bcd]*(c+)/
+ aexycd
+
+/(a*)b+/
+ caab
+
+/([\w:]+::)?(\w+)$/
+ abcd
+ xy:z:::abcd
+ *** Failers
+ abcd:
+ abcd:
+
+/^[^bcd]*(c+)/
+ aexycd
+
+/(>a+)ab/
+
+/(?>a+)b/
+ aaab
+
+/([[:]+)/
+ a:[b]:
+
+/([[=]+)/
+ a=[b]=
+
+/([[.]+)/
+ a.[b].
+
+/((?>a+)b)/
+ aaab
+
+/(?>(a+))b/
+ aaab
+
+/((?>[^()]+)|\([^()]*\))+/
+ ((abc(ade)ufh()()x
+
+/a\Z/
+ *** Failers
+ aaab
+ a\nb\n
+
+/b\Z/
+ a\nb\n
+
+/b\z/
+
+/b\Z/
+ a\nb
+
+/b\z/
+ a\nb
+ *** Failers
+
+/ End of test input /
diff --git a/testoutput b/testoutput
index c326b93..6ecbc17 100644
--- a/testoutput
+++ b/testoutput
@@ -1,5 +1,4 @@
-Testing Perl-Compatible Regular Expressions
-PCRE version 1.09 28-Apr-1998
+PCRE version 2.00 24-Sep-1998
/the quick brown fox/
the quick brown fox
@@ -1984,6 +1983,8 @@ No match
/\Aabc\Z/m
abc
0: abc
+ abc\n
+ 0: abc
*** Failers
No match
qqq\nabc
@@ -1992,7 +1993,7 @@ No match
No match
qqq\nabc\nzzz
No match
-
+
/\A(.)*\Z/s
abc\ndef
0: abc\x0adef
@@ -2078,14 +2079,14 @@ No match
0: abcABC
1: abc
-/(main(OPT)?)+/
+/(main(O)?)+/
mainmain
0: mainmain
1: main
- mainOPTmain
- 0: mainOPTmain
+ mainOmain
+ 0: mainOmain
1: main
- 2: OPT
+ 2: O
/ab{3cd/
ab{3cd
@@ -2377,6 +2378,112 @@ No match
/P[^*]TAIRE[^*]{1,}?LL/
xxxxxxxxxxxPSTAIREISLLxxxxxxxxx
0: PSTAIREISLL
-
+
+/(\.\d\d[1-9]?)\d+/
+ 1.230003938
+ 0: .230003938
+ 1: .23
+ 1.875000282
+ 0: .875000282
+ 1: .875
+ 1.235
+ 0: .235
+ 1: .23
+
+/(\.\d\d((?=0)|\d(?=\d)))/
+ 1.230003938
+ 0: .23
+ 1: .23
+ 2:
+ 1.875000282
+ 0: .875
+ 1: .875
+ 2: 5
+ *** Failers
+No match
+ 1.235
+No match
+
+/a(?)b/
+ ab
+ 0: ab
+
+/\b(foo)\s+(\w+)/i
+ Food is on the foo table
+ 0: foo table
+ 1: foo
+ 2: table
+
+/foo(.*)bar/
+ The food is under the bar in the barn.
+ 0: food is under the bar in the bar
+ 1: d is under the bar in the
+
+/foo(.*?)bar/
+ The food is under the bar in the barn.
+ 0: food is under the bar
+ 1: d is under the
+
+/(.*)(\d*)/
+ I have 2 numbers: 53147
+ 0: I have 2 numbers: 53147
+ 1: I have 2 numbers: 53147
+ 2:
+
+/(.*)(\d+)/
+ I have 2 numbers: 53147
+ 0: I have 2 numbers: 53147
+ 1: I have 2 numbers: 5314
+ 2: 7
+
+/(.*?)(\d*)/
+ I have 2 numbers: 53147
+ 0:
+ 1:
+ 2:
+
+/(.*?)(\d+)/
+ I have 2 numbers: 53147
+ 0: I have 2
+ 1: I have
+ 2: 2
+
+/(.*)(\d+)$/
+ I have 2 numbers: 53147
+ 0: I have 2 numbers: 53147
+ 1: I have 2 numbers: 5314
+ 2: 7
+
+/(.*?)(\d+)$/
+ I have 2 numbers: 53147
+ 0: I have 2 numbers: 53147
+ 1: I have 2 numbers:
+ 2: 53147
+
+/(.*)\b(\d+)$/
+ I have 2 numbers: 53147
+ 0: I have 2 numbers: 53147
+ 1: I have 2 numbers:
+ 2: 53147
+
+/(.*\D)(\d+)$/
+ I have 2 numbers: 53147
+ 0: I have 2 numbers: 53147
+ 1: I have 2 numbers:
+ 2: 53147
+
+/^\D*(?!123)/
+ ABC123
+ 0: AB
+
+/^(\D*)(?=\d)(?!123)/
+ ABC445
+ 0: ABC
+ 1: ABC
+ *** Failers
+No match
+ ABC123
+No match
+
/ End of test input /
diff --git a/testoutput2 b/testoutput2
index 9e84b1c..5625359 100644
--- a/testoutput2
+++ b/testoutput2
@@ -1,17 +1,10 @@
-Testing Perl-Compatible Regular Expressions
-PCRE version 1.09 28-Apr-1998
+PCRE version 2.00 24-Sep-1998
/(a)b|/
Identifying subpattern count = 1
No options
No first char
-/(a*)*/
-Failed: operand of unlimited repeat could match the empty string at offset 4
-
-/(abc|)+/
-Failed: operand of unlimited repeat could match the empty string at offset 6
-
/abc/
Identifying subpattern count = 0
No options
@@ -22,8 +15,6 @@ First char = 'a'
0: abc
\Aabc
0: abc
- \IABC
- 0: ABC
*** Failers
No match
\Adefabc
@@ -72,8 +63,6 @@ Options: anchored
No first char
abc
0: abc
- \Mdef\nabc
- 0: abc
*** Failers
No match
def\nabc
@@ -157,26 +146,6 @@ Starting character set: C D E c d e
this sentences rambles on and on for a while to elephant ElePhant
0: elephant
-/cat|dog|elephant/IS
-Identifying subpattern count = 0
-No options
-No first char
-Starting character set: C D E c d e
- this sentence eventually mentions a CAT cat
- 0: cat
- this sentences rambles on and on for a while to elephant ElePhant
- 0: elephant
-
-/cat|dog|elephant/IS
-Identifying subpattern count = 0
-No options
-No first char
-Starting character set: C D E c d e
- \Ithis sentence eventually mentions a CAT cat
- 0: CAT
- \Ithis sentences rambles on and on for a while to elephant ElePhant
- 0: elephant
-
/a|[bcd]/S
Identifying subpattern count = 0
No options
@@ -209,7 +178,7 @@ No first char
Starting character set: \x09 \x0a \x0b \x0c \x0d \x20 a b
/(ab\2)/
-Failed: back reference to non-existent subpattern at offset 4
+Failed: back reference to non-existent subpattern at offset 6
/{4,5}abc/
Failed: nothing to repeat at offset 4
@@ -225,19 +194,19 @@ First char = 'a'
3: c
\O0abcb
Matched, but too many substrings
- \O2abcb
+ \O3abcb
Matched, but too many substrings
0: abcb
- \O4abcb
+ \O6abcb
Matched, but too many substrings
0: abcb
1: a
- \O6abcb
+ \O9abcb
Matched, but too many substrings
0: abcb
1: a
2: b
- \O8abcb
+ \O12abcb
0: abcb
1: a
2: b
@@ -252,10 +221,10 @@ First char = 'a'
1: a
\O0abc
Matched, but too many substrings
- \O2abc
+ \O3abc
Matched, but too many substrings
0: abc
- \O4abc
+ \O6abc
0: abc
1: a
aba
@@ -265,31 +234,24 @@ Matched, but too many substrings
3: b
\O0aba
Matched, but too many substrings
- \O2aba
+ \O3aba
Matched, but too many substrings
0: aba
- \O4aba
+ \O6aba
Matched, but too many substrings
0: aba
1: <unset>
- \O6aba
+ \O9aba
Matched, but too many substrings
0: aba
1: <unset>
2: a
- \O8aba
+ \O12aba
0: aba
1: <unset>
2: a
3: b
-/^a.b/
-Identifying subpattern count = 0
-Options: anchored
-No first char
- \Sa\nb
- 0: a\x0ab
-
/abc$/E
Identifying subpattern count = 0
Options: dollar_endonly
@@ -303,28 +265,8 @@ No match
abc\ndef
No match
-/abc$/
-Identifying subpattern count = 0
-No options
-First char = 'a'
- *** Failers
-No match
- \Eabc\n
-No match
- \Eabc\ndef
-No match
-
-/abc$/m
-Identifying subpattern count = 0
-Options: multiline
-First char = 'a'
- \Eabc\n
- 0: abc
- \Eabc\ndef
- 0: abc
-
/(a)(b)(c)(d)(e)\6/
-Failed: back reference to non-existent subpattern at offset 16
+Failed: back reference to non-existent subpattern at offset 17
/the quick brown fox/
Identifying subpattern count = 0
@@ -349,92 +291,6 @@ No match
/ab(?z)cd/
Failed: unrecognized character after (? at offset 4
-".*/\Xfoo"X
-Identifying subpattern count = 0
-Options: anchored extra
-No first char
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/it/you/see/
-No match
-
-"(?X).*/\Xfoo"
-Identifying subpattern count = 0
-Options: anchored extra
-No first char
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/it/you/see/
-No match
-
-".*/\Xfoo"X
-Identifying subpattern count = 0
-Options: anchored extra
-No first char
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
- 0: /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
-
-"(?X).*/\Xfoo"
-Identifying subpattern count = 0
-Options: anchored extra
-No first char
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
- 0: /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
-
-/(\.\d\d[1-9]?)\d+/
-Identifying subpattern count = 1
-No options
-First char = '.'
- 1.230003938
- 0: .230003938
- 1: .23
- 1.875000282
- 0: .875000282
- 1: .875
- 1.235
- 0: .235
- 1: .23
-
-/(\.\d\d[1-9]?)\X\d+/X
-Identifying subpattern count = 1
-Options: extra
-First char = '.'
- 1.230003938
- 0: .230003938
- 1: .23
- 1.875000282
- 0: .875000282
- 1: .875
- *** Failers
-No match
- 1.235
-No match
-
-/(\.\d\d((?=0)|\d(?=\d)))/
-Identifying subpattern count = 2
-No options
-First char = '.'
- 1.230003938
- 0: .23
- 1: .23
- 2:
- 1.875000282
- 0: .875
- 1: .875
- 2: 5
- *** Failers
-No match
- 1.235
-No match
-
-/^(\w+\X|\s+\X)*$/X
-Identifying subpattern count = 1
-Options: anchored extra
-No first char
- now is the time for all good men to come to the aid of the party
- 0: now is the time for all good men to come to the aid of the party
- 1: party
- *** Failers
-No match
- this is not a line with only words and spaces!
-No match
-
/^abc|def/
Identifying subpattern count = 0
No options
@@ -510,160 +366,25 @@ No match: POSIX code 17: match failed
Failed: POSIX code 9: bad escape sequence at offset 4
/(abc)\2/P
-Failed: POSIX code 15: bad back reference at offset 6
+Failed: POSIX code 15: bad back reference at offset 7
/(abc\1)/P
abc
-No match: POSIX code 15: bad back reference
-
-"(?>.*/)foo"X
-Identifying subpattern count = 0
-Options: anchored extra
-No first char
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/it/you/see/
-No match
-
-"(?>.*/)foo"X
-Identifying subpattern count = 0
-Options: anchored extra
-No first char
- /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
- 0: /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
-
-/(?>(\.\d\d[1-9]?))\d+/X
-Identifying subpattern count = 1
-Options: extra
-No first char
- 1.230003938
- 0: .230003938
- 1: .23
- 1.875000282
- 0: .875000282
- 1: .875
- *** Failers
-No match
- 1.235
-No match
-
-/^((?>\w+)|(?>\s+))*$/X
-Identifying subpattern count = 1
-Options: anchored extra
-No first char
- now is the time for all good men to come to the aid of the party
- 0: now is the time for all good men to come to the aid of the party
- 1: party
- *** Failers
-No match
- this is not a line with only words and spaces!
-No match
-
-/(\d+)(\w)/X
-Identifying subpattern count = 2
-Options: extra
-No first char
- 12345a
- 0: 12345a
- 1: 12345
- 2: a
- 12345+
- 0: 12345
- 1: 1234
- 2: 5
-
-/((?>\d+))(\w)/X
-Identifying subpattern count = 2
-Options: extra
-No first char
- 12345a
- 0: 12345a
- 1: 12345
- 2: a
- *** Failers
-No match
- 12345+
-No match
-
-/([a]*)*/
-Failed: operand of unlimited repeat could match the empty string at offset 6
-
-/([ab]*)*/
-Failed: operand of unlimited repeat could match the empty string at offset 7
-
-/([^a]*)*/
-Failed: operand of unlimited repeat could match the empty string at offset 7
-
-/([^ab]*)*/
-Failed: operand of unlimited repeat could match the empty string at offset 8
-
-/([a]*?)*/
-Failed: operand of unlimited repeat could match the empty string at offset 7
-
-/([ab]*?)*/
-Failed: operand of unlimited repeat could match the empty string at offset 8
-
-/([^a]*?)*/
-Failed: operand of unlimited repeat could match the empty string at offset 8
-
-/([^ab]*?)*/
-Failed: operand of unlimited repeat could match the empty string at offset 9
-
-/(?>a*)*/X
-Failed: nothing to repeat at offset 6
-
-/((?>a*))*/X
-Failed: operand of unlimited repeat could match the empty string at offset 8
-
-/((?>a*?))*/X
-Failed: operand of unlimited repeat could match the empty string at offset 9
+No match: POSIX code 17: match failed
/)/
-Failed: unmatched brackets at offset 0
+Failed: unmatched parentheses at offset 0
/a[]b/
Failed: missing terminating ] for character class at offset 4
-/[^a]/
-Identifying subpattern count = 0
-No options
-No first char
- \Iaaaabcd
- 0: b
- \IaaAabcd
- 0: b
-
-/[^az]/
-Identifying subpattern count = 0
-No options
-No first char
- \Iaaaabcd
- 0: b
- \IaaAabcd
- 0: b
-
-/[^az]/
-Identifying subpattern count = 0
-No options
-No first char
- \Izazabcd
- 0: b
- \IAaZabcd
- 0: b
-
/[^aeiou ]{3,}/
Identifying subpattern count = 0
No options
No first char
co-processors, and for
0: -pr
- \Ico-processors, and for
- 0: -pr
-/((a)*)*/
-Failed: operand of unlimited repeat could match the empty string at offset 6
-
-/((a|b|c)*)*/
-Failed: operand of unlimited repeat could match the empty string at offset 10
-
/<.*>/
Identifying subpattern count = 0
No options
@@ -712,6 +433,432 @@ Options: ungreedy
First char = '='
abc========def
0: ========
+
+/(?<!bar|cattle)foo/
+Identifying subpattern count = 0
+No options
+First char = 'f'
+ foo
+ 0: foo
+ catfoo
+ 0: foo
+ *** Failers
+No match
+ the barfoo
+No match
+ and cattlefoo
+No match
+
+/(?<=a+)b/
+Failed: lookbehind assertion is not fixed length at offset 6
+
+/(?<=aaa|b{0,3})b/
+Failed: lookbehind assertion is not fixed length at offset 14
+
+/(?<!(foo)a\1)bar/
+Failed: lookbehind assertion is not fixed length at offset 12
+
+/(?i)abc/
+Identifying subpattern count = 0
+Options: caseless
+First char = 'a'
+
+/(a|(?m)a)/
+Identifying subpattern count = 1
+No options
+First char = 'a'
+
+/(?i)^1234/
+Identifying subpattern count = 0
+Options: anchored caseless
+No first char
+
+/(^b|(?i)^d)/
+Identifying subpattern count = 1
+Options: anchored
+No first char
+
+/(?s).*/
+Identifying subpattern count = 0
+Options: anchored dotall
+No first char
+
+/[abcd]/S
+Identifying subpattern count = 0
+No options
+No first char
+Starting character set: a b c d
+
+/(?i)[abcd]/S
+Identifying subpattern count = 0
+Options: caseless
+No first char
+Starting character set: A B C D a b c d
+
+/(?m)[xy]|(b|c)/S
+Identifying subpattern count = 1
+Options: multiline
+No first char
+Starting character set: b c x y
+
+/(^a|^b)/m
+Identifying subpattern count = 1
+Options: multiline
+First char at start or follows \n
+
+/(?i)(^a|^b)/m
+Identifying subpattern count = 1
+Options: caseless multiline
+First char at start or follows \n
+
+/(a)(?(1)a|b|c)/
+Failed: conditional group contains more than two branches at offset 13
+
+/(?(?=a)a|b|c)/
+Failed: conditional group contains more than two branches at offset 12
+
+/(?(1a)/
+Failed: malformed number after (?( at offset 4
+
+/(?(?i))/
+Failed: assertion expected after (?( at offset 3
+
+/(?(abc))/
+Failed: assertion expected after (?( at offset 3
+
+/(?(?<ab))/
+Failed: unrecognized character after (?< at offset 2
+
+/((?s)blah)\s+\1/
+Identifying subpattern count = 1
+No options
+First char = 'b'
+
+/((?i)blah)\s+\1/
+Identifying subpattern count = 1
+No options
+No first char
+
+/((?i)b)/DS
+------------------------------------------------------------------
+ 0 16 Bra 0
+ 3 8 Bra 1
+ 6 01 Opt
+ 8 1 b
+ 11 8 Ket
+ 14 00 Opt
+ 16 16 Ket
+ 19 End
+------------------------------------------------------------------
+Identifying subpattern count = 1
+No options
+No first char
+Starting character set: B b
+
+/(a*b|(?i:c*(?-i)d))/S
+Identifying subpattern count = 1
+No options
+No first char
+Starting character set: C a b c d
+
+/a$/
+Identifying subpattern count = 0
+No options
+First char = 'a'
+ a
+ 0: a
+ a\n
+ 0: a
+ *** Failers
+No match
+ \Za
+No match
+ \Za\n
+No match
+
+/a$/m
+Identifying subpattern count = 0
+Options: multiline
+First char = 'a'
+ a
+ 0: a
+ a\n
+ 0: a
+ \Za\n
+ 0: a
+ *** Failers
+No match
+ \Za
+No match
+
+/\Aabc/m
+Identifying subpattern count = 0
+Options: anchored multiline
+No first char
+
+/^abc/m
+Identifying subpattern count = 0
+Options: multiline
+First char at start or follows \n
+
+/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/
+Identifying subpattern count = 5
+Options: anchored
+No first char
+ aaaaabbbbbcccccdef
+ 0: aaaaabbbbbcccccdef
+ 1: aaaaabbbbbcccccdef
+ 2: aaaaa
+ 3: b
+ 4: bbbbccccc
+ 5: def
+
+/(?<=foo)[ab]/S
+Identifying subpattern count = 0
+No options
+No first char
+Starting character set: a b
+
+/(?<!foo)(alpha|omega)/S
+Identifying subpattern count = 1
+No options
+No first char
+Starting character set: a o
+
+/(?!alphabet)[ab]/S
+Identifying subpattern count = 0
+No options
+No first char
+Starting character set: a b
+
+/(?<=foo\n)^bar/m
+Identifying subpattern count = 0
+Options: multiline
+First char at start or follows \n
+
+/(?>^abc)/m
+Identifying subpattern count = 0
+Options: multiline
+First char at start or follows \n
+ abc
+ 0: abc
+ def\nabc
+ 0: abc
+ *** Failers
+No match
+ defabc
+No match
+
+/(?<=ab(c+)d)ef/
+Failed: lookbehind assertion is not fixed length at offset 11
+
+/(?<=ab(?<=c+)d)ef/
+Failed: lookbehind assertion is not fixed length at offset 12
+
+/(?<=ab(c|de)f)g/
+Failed: lookbehind assertion is not fixed length at offset 13
+
+/The next two are in testinput2 because they have variable length branches/
+Identifying subpattern count = 0
+No options
+First char = 'T'
+
+/(?<=bullock|donkey)-cart/
+Identifying subpattern count = 0
+No options
+First char = '-'
+ the bullock-cart
+ 0: -cart
+ a donkey-cart race
+ 0: -cart
+ *** Failers
+No match
+ cart
+No match
+ horse-and-cart
+No match
+
+/(?<=ab(?i)x|y|z)/
+Identifying subpattern count = 0
+No options
+No first char
+
+/(?<=ab(?i)x(?-i)y|(?i)z|b)ZZ/
+Identifying subpattern count = 0
+No options
+First char = 'Z'
+ abxyZZ
+ 0: ZZ
+ abXyZZ
+ 0: ZZ
+ ZZZ
+ 0: ZZ
+ zZZ
+ 0: ZZ
+ bZZ
+ 0: ZZ
+ BZZ
+ 0: ZZ
+ *** Failers
+No match
+ ZZ
+No match
+ abXYZZ
+No match
+ zzz
+No match
+ bzz
+No match
+
+/(?<!(foo)a)bar/
+Identifying subpattern count = 1
+No options
+First char = 'b'
+ bar
+ 0: bar
+ foobbar
+ 0: bar
+ *** Failers
+No match
+ fooabar
+No match
+
+/This one is here because Perl 5.005_02 doesn't fail it/
+Identifying subpattern count = 0
+No options
+First char = 'T'
+
+/^(a)?(?(1)a|b)+$/
+Identifying subpattern count = 1
+Options: anchored
+No first char
+ *** Failers
+No match
+ a
+No match
+
+/This one is here because I think Perl 5.005_02 gets the setting of $1 wrong/
+Identifying subpattern count = 0
+No options
+First char = 'T'
+
+/^(a\1?){4}$/
+Identifying subpattern count = 1
+Options: anchored
+No first char
+ aaaaaa
+ 0: aaaaaa
+ 1: aa
+
+/These are syntax tests from Perl 5.005/
+Identifying subpattern count = 0
+No options
+First char = 'T'
+
+/a[b-a]/
+Failed: range out of order in character class at offset 4
+
+/a[]b/
+Failed: missing terminating ] for character class at offset 4
+
+/a[/
+Failed: missing terminating ] for character class at offset 2
+
+/*a/
+Failed: nothing to repeat at offset 0
+
+/(*)b/
+Failed: nothing to repeat at offset 1
+
+/a\/
+Failed: \ at end of pattern at offset 2
+
+/abc)/
+Failed: unmatched parentheses at offset 3
+
+/(abc/
+Failed: missing ) at offset 4
+
+/a**/
+Failed: nothing to repeat at offset 2
+
+/)(/
+Failed: unmatched parentheses at offset 0
+
+/\1/
+Failed: back reference to non-existent subpattern at offset 2
+
+/\2/
+Failed: back reference to non-existent subpattern at offset 2
+
+/(a)|\2/
+Failed: back reference to non-existent subpattern at offset 6
+
+/a[b-a]/i
+Failed: range out of order in character class at offset 4
+
+/a[]b/i
+Failed: missing terminating ] for character class at offset 4
+
+/a[/i
+Failed: missing terminating ] for character class at offset 2
+
+/*a/i
+Failed: nothing to repeat at offset 0
+
+/(*)b/i
+Failed: nothing to repeat at offset 1
+
+/a\/i
+Failed: \ at end of pattern at offset 2
+
+/abc)/i
+Failed: unmatched parentheses at offset 3
+
+/(abc/i
+Failed: missing ) at offset 4
+
+/a**/i
+Failed: nothing to repeat at offset 2
+
+/)(/i
+Failed: unmatched parentheses at offset 0
+
+/:(?:/
+Failed: missing ) at offset 4
+
+/(?<%)b/
+Failed: unrecognized character after (?< at offset 0
+
+/a(?{)b/
+Failed: unrecognized character after (? at offset 3
+
+/a(?{{})b/
+Failed: unrecognized character after (? at offset 3
+
+/a(?{}})b/
+Failed: unrecognized character after (? at offset 3
+
+/a(?{"{"})b/
+Failed: unrecognized character after (? at offset 3
+
+/a(?{"{"}})b/
+Failed: unrecognized character after (? at offset 3
+
+/(?(1?)a|b)/
+Failed: malformed number after (?( at offset 4
+
+/(?(1)a|b|c)/
+Failed: conditional group contains more than two branches at offset 10
+
+/[a[:xyz:/
+Failed: missing terminating ] for character class at offset 8
+
+/(?<=x+)y/
+Failed: lookbehind assertion is not fixed length at offset 6
+
+/a{37,17}/
+Failed: numbers out of order in {} quantifier at offset 7
/ End of test input /
Identifying subpattern count = 0
diff --git a/testoutput3 b/testoutput3
new file mode 100644
index 0000000..3b7b158
--- /dev/null
+++ b/testoutput3
@@ -0,0 +1,2753 @@
+PCRE version 2.00 24-Sep-1998
+
+/(?<!bar)foo/
+ foo
+ 0: foo
+ catfood
+ 0: foo
+ arfootle
+ 0: foo
+ rfoosh
+ 0: foo
+ *** Failers
+No match
+ barfoo
+No match
+ towbarfoo
+No match
+
+/\w{3}(?<!bar)foo/
+ catfood
+ 0: catfoo
+ *** Failers
+No match
+ foo
+No match
+ barfoo
+No match
+ towbarfoo
+No match
+
+/(?<=(foo)a)bar/
+ fooabar
+ 0: bar
+ 1: foo
+ *** Failers
+No match
+ bar
+No match
+ foobbar
+No match
+
+/\Aabc\z/m
+ abc
+ 0: abc
+ *** Failers
+No match
+ abc\n
+No match
+ qqq\nabc
+No match
+ abc\nzzz
+No match
+ qqq\nabc\nzzz
+No match
+
+"(?>.*/)foo"
+ /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/it/you/see/
+No match
+
+"(?>.*/)foo"
+ /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
+ 0: /this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo
+
+/(?>(\.\d\d[1-9]?))\d+/
+ 1.230003938
+ 0: .230003938
+ 1: .23
+ 1.875000282
+ 0: .875000282
+ 1: .875
+ *** Failers
+No match
+ 1.235
+No match
+
+/^((?>\w+)|(?>\s+))*$/
+ now is the time for all good men to come to the aid of the party
+ 0: now is the time for all good men to come to the aid of the party
+ 1: party
+ *** Failers
+No match
+ this is not a line with only words and spaces!
+No match
+
+/(\d+)(\w)/
+ 12345a
+ 0: 12345a
+ 1: 12345
+ 2: a
+ 12345+
+ 0: 12345
+ 1: 1234
+ 2: 5
+
+/((?>\d+))(\w)/
+ 12345a
+ 0: 12345a
+ 1: 12345
+ 2: a
+ *** Failers
+No match
+ 12345+
+No match
+
+/(?>a+)b/
+ aaab
+ 0: aaab
+
+/((?>a+)b)/
+ aaab
+ 0: aaab
+ 1: aaab
+
+/(?>(a+))b/
+ aaab
+ 0: aaab
+ 1: aaa
+
+/(?>b)+/
+ aaabbbccc
+ 0: bbb
+
+/(?>a+|b+|c+)*c/
+ aaabbbbccccd
+ 0: aaabbbbc
+
+/((?>[^()]+)|\([^()]*\))+/
+ ((abc(ade)ufh()()x
+ 0: abc(ade)ufh()()x
+ 1: x
+
+/\(((?>[^()]+)|\([^()]+\))+\)/
+ (abc)
+ 0: (abc)
+ 1: abc
+ (abc(def)xyz)
+ 0: (abc(def)xyz)
+ 1: xyz
+ *** Failers
+No match
+ ((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+No match
+
+/a(?-i)b/i
+ ab
+ 0: ab
+ *** Failers
+No match
+ Ab
+No match
+ aB
+No match
+ AB
+No match
+
+/(a (?x)b c)d e/
+ a bcd e
+ 0: a bcd e
+ 1: a bc
+ *** Failers
+No match
+ a b cd e
+No match
+ abcd e
+No match
+ a bcde
+No match
+
+/(a b(?x)c d (?-x)e f)/
+ a bcde f
+ 0: a bcde f
+ 1: a bcde f
+ *** Failers
+No match
+ abcdef
+No match
+
+/(a(?i)b)c/
+ abc
+ 0: abc
+ 1: ab
+ aBc
+ 0: aBc
+ 1: aB
+ *** Failers
+No match
+ abC
+No match
+ aBC
+No match
+ Abc
+No match
+ ABc
+No match
+ ABC
+No match
+ AbC
+No match
+
+/a(?i:b)c/
+ abc
+ 0: abc
+ aBc
+ 0: aBc
+ *** Failers
+No match
+ ABC
+No match
+ abC
+No match
+ aBC
+No match
+
+/a(?i:b)*c/
+ aBc
+ 0: aBc
+ aBBc
+ 0: aBBc
+ *** Failers
+No match
+ aBC
+No match
+ aBBC
+No match
+
+/a(?=b(?i)c)\w\wd/
+ abcd
+ 0: abcd
+ abCd
+ 0: abCd
+ *** Failers
+No match
+ aBCd
+No match
+ abcD
+No match
+
+/(?s-i:more.*than).*million/i
+ more than million
+ 0: more than million
+ more than MILLION
+ 0: more than MILLION
+ more \n than Million
+ 0: more \x0a than Million
+ *** Failers
+No match
+ MORE THAN MILLION
+No match
+ more \n than \n million
+No match
+
+/(?:(?s-i)more.*than).*million/i
+ more than million
+ 0: more than million
+ more than MILLION
+ 0: more than MILLION
+ more \n than Million
+ 0: more \x0a than Million
+ *** Failers
+No match
+ MORE THAN MILLION
+No match
+ more \n than \n million
+No match
+
+/(?>a(?i)b+)+c/
+ abc
+ 0: abc
+ aBbc
+ 0: aBbc
+ aBBc
+ 0: aBBc
+ *** Failers
+No match
+ Abc
+No match
+ abAb
+No match
+ abbC
+No match
+
+/(?=a(?i)b)\w\wc/
+ abc
+ 0: abc
+ aBc
+ 0: aBc
+ *** Failers
+No match
+ Ab
+No match
+ abC
+No match
+ aBC
+No match
+
+/(?<=a(?i)b)(\w\w)c/
+ abxxc
+ 0: xxc
+ 1: xx
+ aBxxc
+ 0: xxc
+ 1: xx
+ *** Failers
+No match
+ Abxxc
+No match
+ ABxxc
+No match
+ abxxC
+No match
+
+/(?:(a)|b)(?(1)A|B)/
+ aA
+ 0: aA
+ 1: a
+ bB
+ 0: bB
+ *** Failers
+No match
+ aB
+No match
+ bA
+No match
+
+/^(a)?(?(1)a|b)+$/
+ aa
+ 0: aa
+ 1: a
+ b
+ 0: b
+ bb
+ 0: bb
+ *** Failers
+No match
+ ab
+No match
+
+/^(?(?=abc)\w{3}:|\d\d)$/
+ abc:
+ 0: abc:
+ 12
+ 0: 12
+ *** Failers
+No match
+ 123
+No match
+ xyz
+No match
+
+/^(?(?!abc)\d\d|\w{3}:)$/
+ abc:
+ 0: abc:
+ 12
+ 0: 12
+ *** Failers
+No match
+ 123
+No match
+ xyz
+No match
+
+/(?(?<=foo)bar|cat)/
+ foobar
+ 0: bar
+ cat
+ 0: cat
+ fcat
+ 0: cat
+ focat
+ 0: cat
+ *** Failers
+No match
+ foocat
+No match
+
+/(?(?<!foo)cat|bar)/
+ foobar
+ 0: bar
+ cat
+ 0: cat
+ fcat
+ 0: cat
+ focat
+ 0: cat
+ *** Failers
+No match
+ foocat
+No match
+
+/( \( )? [^()]+ (?(1) \) |) /x
+ abcd
+ 0: abcd
+ (abcd)
+ 0: (abcd)
+ 1: (
+ the quick (abcd) fox
+ 0: the quick
+ (abcd
+ 0: abcd
+
+/( \( )? [^()]+ (?(1) \) ) /x
+ abcd
+ 0: abcd
+ (abcd)
+ 0: (abcd)
+ 1: (
+ the quick (abcd) fox
+ 0: the quick
+ (abcd
+ 0: abcd
+
+/^(?(2)a|(1)(2))+$/
+ 12
+ 0: 12
+ 1: 1
+ 2: 2
+ 12a
+ 0: 12a
+ 1: 1
+ 2: 2
+ 12aa
+ 0: 12aa
+ 1: 1
+ 2: 2
+ *** Failers
+No match
+ 1234
+No match
+
+/((?i)blah)\s+\1/
+ blah blah
+ 0: blah blah
+ 1: blah
+ BLAH BLAH
+ 0: BLAH BLAH
+ 1: BLAH
+ Blah Blah
+ 0: Blah Blah
+ 1: Blah
+ blaH blaH
+ 0: blaH blaH
+ 1: blaH
+ *** Failers
+No match
+ blah BLAH
+No match
+ Blah blah
+No match
+ blaH blah
+No match
+
+/((?i)blah)\s+(?i:\1)/
+ blah blah
+ 0: blah blah
+ 1: blah
+ BLAH BLAH
+ 0: BLAH BLAH
+ 1: BLAH
+ Blah Blah
+ 0: Blah Blah
+ 1: Blah
+ blaH blaH
+ 0: blaH blaH
+ 1: blaH
+ blah BLAH
+ 0: blah BLAH
+ 1: blah
+ Blah blah
+ 0: Blah blah
+ 1: Blah
+ blaH blah
+ 0: blaH blah
+ 1: blaH
+
+/(?>a*)*/
+ a
+ 0: a
+ aa
+ 0: aa
+ aaaa
+ 0: aaaa
+
+/(abc|)+/
+ abc
+ 0: abc
+ 1:
+ abcabc
+ 0: abcabc
+ 1:
+ abcabcabc
+ 0: abcabcabc
+ 1:
+ xyz
+ 0:
+ 1:
+
+/([a]*)*/
+ a
+ 0: a
+ 1:
+ aaaaa
+ 0: aaaaa
+ 1:
+
+/([ab]*)*/
+ a
+ 0: a
+ 1:
+ b
+ 0: b
+ 1:
+ ababab
+ 0: ababab
+ 1:
+ aaaabcde
+ 0: aaaab
+ 1:
+ bbbb
+ 0: bbbb
+ 1:
+
+/([^a]*)*/
+ b
+ 0: b
+ 1:
+ bbbb
+ 0: bbbb
+ 1:
+ aaa
+ 0:
+ 1:
+
+/([^ab]*)*/
+ cccc
+ 0: cccc
+ 1:
+ abab
+ 0:
+ 1:
+
+/([a]*?)*/
+ a
+ 0:
+ 1:
+ aaaa
+ 0:
+ 1:
+
+/([ab]*?)*/
+ a
+ 0:
+ 1:
+ b
+ 0:
+ 1:
+ abab
+ 0:
+ 1:
+ baba
+ 0:
+ 1:
+
+/([^a]*?)*/
+ b
+ 0:
+ 1:
+ bbbb
+ 0:
+ 1:
+ aaa
+ 0:
+ 1:
+
+/([^ab]*?)*/
+ c
+ 0:
+ 1:
+ cccc
+ 0:
+ 1:
+ baba
+ 0:
+ 1:
+
+/(?>a*)*/
+ a
+ 0: a
+ aaabcde
+ 0: aaa
+
+/((?>a*))*/
+ aaaaa
+ 0: aaaaa
+ 1:
+ aabbaa
+ 0: aa
+ 1:
+
+/((?>a*?))*/
+ aaaaa
+ 0:
+ 1:
+ aabbaa
+ 0:
+ 1:
+
+/(?(?=[^a-z]+[a-z]) \d{2}-[a-z]{3}-\d{2} | \d{2}-\d{2}-\d{2} ) /x
+ 12-sep-98
+ 0: 12-sep-98
+ 12-09-98
+ 0: 12-09-98
+ *** Failers
+No match
+ sep-12-98
+No match
+
+/(?<=(foo))bar\1/
+ foobarfoo
+ 0: barfoo
+ 1: foo
+ foobarfootling
+ 0: barfoo
+ 1: foo
+ *** Failers
+No match
+ foobar
+No match
+ barfoo
+No match
+
+/(?i:saturday|sunday)/
+ saturday
+ 0: saturday
+ sunday
+ 0: sunday
+ Saturday
+ 0: Saturday
+ Sunday
+ 0: Sunday
+ SATURDAY
+ 0: SATURDAY
+ SUNDAY
+ 0: SUNDAY
+ SunDay
+ 0: SunDay
+
+/(a(?i)bc|BB)x/
+ abcx
+ 0: abcx
+ 1: abc
+ aBCx
+ 0: aBCx
+ 1: aBC
+ bbx
+ 0: bbx
+ 1: bb
+ BBx
+ 0: BBx
+ 1: BB
+ *** Failers
+No match
+ abcX
+No match
+ aBCX
+No match
+ bbX
+No match
+ BBX
+No match
+
+/^([ab](?i)[cd]|[ef])/
+ ac
+ 0: ac
+ 1: ac
+ aC
+ 0: aC
+ 1: aC
+ bD
+ 0: bD
+ 1: bD
+ elephant
+ 0: e
+ 1: e
+ Europe
+ 0: E
+ 1: E
+ frog
+ 0: f
+ 1: f
+ France
+ 0: F
+ 1: F
+ *** Failers
+No match
+ Africa
+No match
+
+/^(ab|a(?i)[b-c](?m-i)d|x(?i)y|z)/
+ ab
+ 0: ab
+ 1: ab
+ aBd
+ 0: aBd
+ 1: aBd
+ xy
+ 0: xy
+ 1: xy
+ xY
+ 0: xY
+ 1: xY
+ zebra
+ 0: z
+ 1: z
+ Zambesi
+ 0: Z
+ 1: Z
+ *** Failers
+No match
+ aCD
+No match
+ XY
+No match
+
+/(?<=foo\n)^bar/m
+ foo\nbar
+ 0: bar
+ *** Failers
+No match
+ bar
+No match
+ baz\nbar
+No match
+
+/(?<=(?<!foo)bar)baz/
+ barbaz
+ 0: baz
+ barbarbaz
+ 0: baz
+ koobarbaz
+ 0: baz
+ *** Failers
+No match
+ baz
+No match
+ foobarbaz
+No match
+
+/The case of aaaaaa is missed out below because I think Perl 5.005_02 gets/
+/it wrong; it sets $1 to aaa rather than aa. Compare the following test,/
+No match
+/where it does set $1 to aa when matching aaaaaa./
+No match
+
+/^(a\1?){4}$/
+ a
+No match
+ aa
+No match
+ aaa
+No match
+ aaaa
+ 0: aaaa
+ 1: a
+ aaaaa
+ 0: aaaaa
+ 1: a
+ aaaaaaa
+ 0: aaaaaaa
+ 1: a
+ aaaaaaaa
+No match
+ aaaaaaaaa
+No match
+ aaaaaaaaaa
+ 0: aaaaaaaaaa
+ 1: aaaa
+ aaaaaaaaaaa
+No match
+ aaaaaaaaaaaa
+No match
+ aaaaaaaaaaaaa
+No match
+ aaaaaaaaaaaaaa
+No match
+ aaaaaaaaaaaaaaa
+No match
+ aaaaaaaaaaaaaaaa
+No match
+
+/^(a\1?)(a\1?)(a\2?)(a\3?)$/
+ a
+No match
+ aa
+No match
+ aaa
+No match
+ aaaa
+ 0: aaaa
+ 1: a
+ 2: a
+ 3: a
+ 4: a
+ aaaaa
+ 0: aaaaa
+ 1: a
+ 2: aa
+ 3: a
+ 4: a
+ aaaaaa
+ 0: aaaaaa
+ 1: a
+ 2: aa
+ 3: a
+ 4: aa
+ aaaaaaa
+ 0: aaaaaaa
+ 1: a
+ 2: aa
+ 3: aaa
+ 4: a
+ aaaaaaaa
+No match
+ aaaaaaaaa
+No match
+ aaaaaaaaaa
+ 0: aaaaaaaaaa
+ 1: a
+ 2: aa
+ 3: aaa
+ 4: aaaa
+ aaaaaaaaaaa
+No match
+ aaaaaaaaaaaa
+No match
+ aaaaaaaaaaaaa
+No match
+ aaaaaaaaaaaaaa
+No match
+ aaaaaaaaaaaaaaa
+No match
+ aaaaaaaaaaaaaaaa
+No match
+
+/The following tests are taken from the Perl 5.005 test suite; some of them/
+/are compatible with 5.004, but I'd rather not have to sort them out./
+No match
+
+/abc/
+ abc
+ 0: abc
+ xabcy
+ 0: abc
+ ababc
+ 0: abc
+ *** Failers
+No match
+ xbc
+No match
+ axc
+No match
+ abx
+No match
+
+/ab*c/
+ abc
+ 0: abc
+
+/ab*bc/
+ abc
+ 0: abc
+ abbc
+ 0: abbc
+ abbbbc
+ 0: abbbbc
+
+/.{1}/
+ abbbbc
+ 0: a
+
+/.{3,4}/
+ abbbbc
+ 0: abbb
+
+/ab{0,}bc/
+ abbbbc
+ 0: abbbbc
+
+/ab+bc/
+ abbc
+ 0: abbc
+ *** Failers
+No match
+ abc
+No match
+ abq
+No match
+
+/ab{1,}bc/
+
+/ab+bc/
+ abbbbc
+ 0: abbbbc
+
+/ab{1,}bc/
+ abbbbc
+ 0: abbbbc
+
+/ab{1,3}bc/
+ abbbbc
+ 0: abbbbc
+
+/ab{3,4}bc/
+ abbbbc
+ 0: abbbbc
+
+/ab{4,5}bc/
+ *** Failers
+No match
+ abq
+No match
+ abbbbc
+No match
+
+/ab?bc/
+ abbc
+ 0: abbc
+ abc
+ 0: abc
+
+/ab{0,1}bc/
+ abc
+ 0: abc
+
+/ab?bc/
+
+/ab?c/
+ abc
+ 0: abc
+
+/ab{0,1}c/
+ abc
+ 0: abc
+
+/^abc$/
+ abc
+ 0: abc
+ *** Failers
+No match
+ abbbbc
+No match
+ abcc
+No match
+
+/^abc/
+ abcc
+ 0: abc
+
+/^abc$/
+
+/abc$/
+ aabc
+ 0: abc
+ *** Failers
+No match
+ aabc
+ 0: abc
+ aabcd
+No match
+
+/^/
+ abc
+ 0:
+
+/$/
+ abc
+ 0:
+
+/a.c/
+ abc
+ 0: abc
+ axc
+ 0: axc
+
+/a.*c/
+ axyzc
+ 0: axyzc
+
+/a[bc]d/
+ abd
+ 0: abd
+ *** Failers
+No match
+ axyzd
+No match
+ abc
+No match
+
+/a[b-d]e/
+ ace
+ 0: ace
+
+/a[b-d]/
+ aac
+ 0: ac
+
+/a[-b]/
+ a-
+ 0: a-
+
+/a[b-]/
+ a-
+ 0: a-
+
+/a]/
+ a]
+ 0: a]
+
+/a[]]b/
+ a]b
+ 0: a]b
+
+/a[^bc]d/
+ aed
+ 0: aed
+ *** Failers
+No match
+ abd
+No match
+ abd
+No match
+
+/a[^-b]c/
+ adc
+ 0: adc
+
+/a[^]b]c/
+ adc
+ 0: adc
+ *** Failers
+No match
+ a-c
+ 0: a-c
+ a]c
+No match
+
+/\ba\b/
+ a-
+ 0: a
+ -a
+ 0: a
+ -a-
+ 0: a
+
+/\by\b/
+ *** Failers
+No match
+ xy
+No match
+ yz
+No match
+ xyz
+No match
+
+/\Ba\B/
+ *** Failers
+ 0: a
+ a-
+No match
+ -a
+No match
+ -a-
+No match
+
+/\By\b/
+ xy
+ 0: y
+
+/\by\B/
+ yz
+ 0: y
+
+/\By\B/
+ xyz
+ 0: y
+
+/\w/
+ a
+ 0: a
+
+/\W/
+ -
+ 0: -
+ *** Failers
+ 0: *
+ -
+ 0: -
+ a
+No match
+
+/a\sb/
+ a b
+ 0: a b
+
+/a\Sb/
+ a-b
+ 0: a-b
+ *** Failers
+No match
+ a-b
+ 0: a-b
+ a b
+No match
+
+/\d/
+ 1
+ 0: 1
+
+/\D/
+ -
+ 0: -
+ *** Failers
+ 0: *
+ -
+ 0: -
+ 1
+No match
+
+/[\w]/
+ a
+ 0: a
+
+/[\W]/
+ -
+ 0: -
+ *** Failers
+ 0: *
+ -
+ 0: -
+ a
+No match
+
+/a[\s]b/
+ a b
+ 0: a b
+
+/a[\S]b/
+ a-b
+ 0: a-b
+ *** Failers
+No match
+ a-b
+ 0: a-b
+ a b
+No match
+
+/[\d]/
+ 1
+ 0: 1
+
+/[\D]/
+ -
+ 0: -
+ *** Failers
+ 0: *
+ -
+ 0: -
+ 1
+No match
+
+/ab|cd/
+ abc
+ 0: ab
+ abcd
+ 0: ab
+
+/()ef/
+ def
+ 0: ef
+ 1:
+
+/$b/
+
+/a\(b/
+ a(b
+ 0: a(b
+
+/a\(*b/
+ ab
+ 0: ab
+ a((b
+ 0: a((b
+
+/a\\b/
+ a\b
+No match
+
+/((a))/
+ abc
+ 0: a
+ 1: a
+ 2: a
+
+/(a)b(c)/
+ abc
+ 0: abc
+ 1: a
+ 2: c
+
+/a+b+c/
+ aabbabc
+ 0: abc
+
+/a{1,}b{1,}c/
+ aabbabc
+ 0: abc
+
+/a.+?c/
+ abcabc
+ 0: abc
+
+/(a+|b)*/
+ ab
+ 0: ab
+ 1: b
+
+/(a+|b){0,}/
+ ab
+ 0: ab
+ 1: b
+
+/(a+|b)+/
+ ab
+ 0: ab
+ 1: b
+
+/(a+|b){1,}/
+ ab
+ 0: ab
+ 1: b
+
+/(a+|b)?/
+ ab
+ 0: a
+ 1: a
+
+/(a+|b){0,1}/
+ ab
+ 0: a
+ 1: a
+
+/[^ab]*/
+ cde
+ 0: cde
+
+/abc/
+ *** Failers
+No match
+ b
+No match
+
+
+/a*/
+
+
+/([abc])*d/
+ abbbcd
+ 0: abbbcd
+ 1: c
+
+/([abc])*bcd/
+ abcd
+ 0: abcd
+ 1: a
+
+/a|b|c|d|e/
+ e
+ 0: e
+
+/(a|b|c|d|e)f/
+ ef
+ 0: ef
+ 1: e
+
+/abcd*efg/
+ abcdefg
+ 0: abcdefg
+
+/ab*/
+ xabyabbbz
+ 0: ab
+ xayabbbz
+ 0: a
+
+/(ab|cd)e/
+ abcde
+ 0: cde
+ 1: cd
+
+/[abhgefdc]ij/
+ hij
+ 0: hij
+
+/^(ab|cd)e/
+
+/(abc|)ef/
+ abcdef
+ 0: ef
+ 1:
+
+/(a|b)c*d/
+ abcd
+ 0: bcd
+ 1: b
+
+/(ab|ab*)bc/
+ abc
+ 0: abc
+ 1: a
+
+/a([bc]*)c*/
+ abc
+ 0: abc
+ 1: bc
+
+/a([bc]*)(c*d)/
+ abcd
+ 0: abcd
+ 1: bc
+ 2: d
+
+/a([bc]+)(c*d)/
+ abcd
+ 0: abcd
+ 1: bc
+ 2: d
+
+/a([bc]*)(c+d)/
+ abcd
+ 0: abcd
+ 1: b
+ 2: cd
+
+/a[bcd]*dcdcde/
+ adcdcde
+ 0: adcdcde
+
+/a[bcd]+dcdcde/
+ *** Failers
+No match
+ abcde
+No match
+ adcdcde
+No match
+
+/(ab|a)b*c/
+ abc
+ 0: abc
+ 1: ab
+
+/((a)(b)c)(d)/
+ abcd
+ 0: abcd
+ 1: abc
+ 2: a
+ 3: b
+ 4: d
+
+/[a-zA-Z_][a-zA-Z0-9_]*/
+ alpha
+ 0: alpha
+
+/^a(bc+|b[eh])g|.h$/
+ abh
+ 0: bh
+
+/(bc+d$|ef*g.|h?i(j|k))/
+ effgz
+ 0: effgz
+ 1: effgz
+ ij
+ 0: ij
+ 1: ij
+ 2: j
+ reffgz
+ 0: effgz
+ 1: effgz
+ *** Failers
+No match
+ effg
+No match
+ bcdd
+No match
+
+/((((((((((a))))))))))/
+ a
+ 0: a
+ 1: a
+ 2: a
+ 3: a
+ 4: a
+ 5: a
+ 6: a
+ 7: a
+ 8: a
+ 9: a
+10: a
+
+/((((((((((a))))))))))\10/
+ aa
+ 0: aa
+ 1: a
+ 2: a
+ 3: a
+ 4: a
+ 5: a
+ 6: a
+ 7: a
+ 8: a
+ 9: a
+10: a
+
+/(((((((((a)))))))))/
+ a
+ 0: a
+ 1: a
+ 2: a
+ 3: a
+ 4: a
+ 5: a
+ 6: a
+ 7: a
+ 8: a
+ 9: a
+
+/multiple words of text/
+ *** Failers
+No match
+ aa
+No match
+ uh-uh
+No match
+
+/multiple words/
+ multiple words, yeah
+ 0: multiple words
+
+/(.*)c(.*)/
+ abcde
+ 0: abcde
+ 1: ab
+ 2: de
+
+/\((.*), (.*)\)/
+ (a, b)
+ 0: (a, b)
+ 1: a
+ 2: b
+
+/[k]/
+
+/abcd/
+ abcd
+ 0: abcd
+
+/a(bc)d/
+ abcd
+ 0: abcd
+ 1: bc
+
+/a[-]?c/
+ ac
+ 0: ac
+
+/(abc)\1/
+ abcabc
+ 0: abcabc
+ 1: abc
+
+/([a-c]*)\1/
+ abcabc
+ 0: abcabc
+ 1: abc
+
+/(a)|\1/
+ a
+ 0: a
+ 1: a
+ *** Failers
+ 0: a
+ 1: a
+ ab
+ 0: a
+ 1: a
+ x
+No match
+
+/(([a-c])b*?\2)*/
+ ababbbcbc
+ 0: ababb
+ 1: bb
+ 2: b
+
+/(([a-c])b*?\2){3}/
+ ababbbcbc
+ 0: ababbbcbc
+ 1: cbc
+ 2: c
+
+/((\3|b)\2(a)x)+/
+ aaaxabaxbaaxbbax
+ 0: bbax
+ 1: bbax
+ 2: b
+ 3: a
+
+/((\3|b)\2(a)){2,}/
+ bbaababbabaaaaabbaaaabba
+ 0: bbaaaabba
+ 1: bba
+ 2: b
+ 3: a
+
+/abc/i
+ ABC
+ 0: ABC
+ XABCY
+ 0: ABC
+ ABABC
+ 0: ABC
+ *** Failers
+No match
+ aaxabxbaxbbx
+No match
+ XBC
+No match
+ AXC
+No match
+ ABX
+No match
+
+/ab*c/i
+ ABC
+ 0: ABC
+
+/ab*bc/i
+ ABC
+ 0: ABC
+ ABBC
+ 0: ABBC
+
+/ab*?bc/i
+ ABBBBC
+ 0: ABBBBC
+
+/ab{0,}?bc/i
+ ABBBBC
+ 0: ABBBBC
+
+/ab+?bc/i
+ ABBC
+ 0: ABBC
+
+/ab+bc/i
+ *** Failers
+No match
+ ABC
+No match
+ ABQ
+No match
+
+/ab{1,}bc/i
+
+/ab+bc/i
+ ABBBBC
+ 0: ABBBBC
+
+/ab{1,}?bc/i
+ ABBBBC
+ 0: ABBBBC
+
+/ab{1,3}?bc/i
+ ABBBBC
+ 0: ABBBBC
+
+/ab{3,4}?bc/i
+ ABBBBC
+ 0: ABBBBC
+
+/ab{4,5}?bc/i
+ *** Failers
+No match
+ ABQ
+No match
+ ABBBBC
+No match
+
+/ab??bc/i
+ ABBC
+ 0: ABBC
+ ABC
+ 0: ABC
+
+/ab{0,1}?bc/i
+ ABC
+ 0: ABC
+
+/ab??bc/i
+
+/ab??c/i
+ ABC
+ 0: ABC
+
+/ab{0,1}?c/i
+ ABC
+ 0: ABC
+
+/^abc$/i
+ ABC
+ 0: ABC
+ *** Failers
+No match
+ ABBBBC
+No match
+ ABCC
+No match
+
+/^abc/i
+ ABCC
+ 0: ABC
+
+/^abc$/i
+
+/abc$/i
+ AABC
+ 0: ABC
+
+/^/i
+ ABC
+ 0:
+
+/$/i
+ ABC
+ 0:
+
+/a.c/i
+ ABC
+ 0: ABC
+ AXC
+ 0: AXC
+
+/a.*?c/i
+ AXYZC
+ 0: AXYZC
+
+/a.*c/i
+ *** Failers
+No match
+ AABC
+ 0: AABC
+ AXYZD
+No match
+
+/a[bc]d/i
+ ABD
+ 0: ABD
+
+/a[b-d]e/i
+ ACE
+ 0: ACE
+ *** Failers
+No match
+ ABC
+No match
+ ABD
+No match
+
+/a[b-d]/i
+ AAC
+ 0: AC
+
+/a[-b]/i
+ A-
+ 0: A-
+
+/a[b-]/i
+ A-
+ 0: A-
+
+/a]/i
+ A]
+ 0: A]
+
+/a[]]b/i
+ A]B
+ 0: A]B
+
+/a[^bc]d/i
+ AED
+ 0: AED
+
+/a[^-b]c/i
+ ADC
+ 0: ADC
+ *** Failers
+No match
+ ABD
+No match
+ A-C
+No match
+
+/a[^]b]c/i
+ ADC
+ 0: ADC
+
+/ab|cd/i
+ ABC
+ 0: AB
+ ABCD
+ 0: AB
+
+/()ef/i
+ DEF
+ 0: EF
+ 1:
+
+/$b/i
+ *** Failers
+No match
+ A]C
+No match
+ B
+No match
+
+/a\(b/i
+ A(B
+ 0: A(B
+
+/a\(*b/i
+ AB
+ 0: AB
+ A((B
+ 0: A((B
+
+/a\\b/i
+ A\B
+No match
+
+/((a))/i
+ ABC
+ 0: A
+ 1: A
+ 2: A
+
+/(a)b(c)/i
+ ABC
+ 0: ABC
+ 1: A
+ 2: C
+
+/a+b+c/i
+ AABBABC
+ 0: ABC
+
+/a{1,}b{1,}c/i
+ AABBABC
+ 0: ABC
+
+/a.+?c/i
+ ABCABC
+ 0: ABC
+
+/a.*?c/i
+ ABCABC
+ 0: ABC
+
+/a.{0,5}?c/i
+ ABCABC
+ 0: ABC
+
+/(a+|b)*/i
+ AB
+ 0: AB
+ 1: B
+
+/(a+|b){0,}/i
+ AB
+ 0: AB
+ 1: B
+
+/(a+|b)+/i
+ AB
+ 0: AB
+ 1: B
+
+/(a+|b){1,}/i
+ AB
+ 0: AB
+ 1: B
+
+/(a+|b)?/i
+ AB
+ 0: A
+ 1: A
+
+/(a+|b){0,1}/i
+ AB
+ 0: A
+ 1: A
+
+/(a+|b){0,1}?/i
+ AB
+ 0:
+
+/[^ab]*/i
+ CDE
+ 0: CDE
+
+/abc/i
+
+/a*/i
+
+
+/([abc])*d/i
+ ABBBCD
+ 0: ABBBCD
+ 1: C
+
+/([abc])*bcd/i
+ ABCD
+ 0: ABCD
+ 1: A
+
+/a|b|c|d|e/i
+ E
+ 0: E
+
+/(a|b|c|d|e)f/i
+ EF
+ 0: EF
+ 1: E
+
+/abcd*efg/i
+ ABCDEFG
+ 0: ABCDEFG
+
+/ab*/i
+ XABYABBBZ
+ 0: AB
+ XAYABBBZ
+ 0: A
+
+/(ab|cd)e/i
+ ABCDE
+ 0: CDE
+ 1: CD
+
+/[abhgefdc]ij/i
+ HIJ
+ 0: HIJ
+
+/^(ab|cd)e/i
+ ABCDE
+No match
+
+/(abc|)ef/i
+ ABCDEF
+ 0: EF
+ 1:
+
+/(a|b)c*d/i
+ ABCD
+ 0: BCD
+ 1: B
+
+/(ab|ab*)bc/i
+ ABC
+ 0: ABC
+ 1: A
+
+/a([bc]*)c*/i
+ ABC
+ 0: ABC
+ 1: BC
+
+/a([bc]*)(c*d)/i
+ ABCD
+ 0: ABCD
+ 1: BC
+ 2: D
+
+/a([bc]+)(c*d)/i
+ ABCD
+ 0: ABCD
+ 1: BC
+ 2: D
+
+/a([bc]*)(c+d)/i
+ ABCD
+ 0: ABCD
+ 1: B
+ 2: CD
+
+/a[bcd]*dcdcde/i
+ ADCDCDE
+ 0: ADCDCDE
+
+/a[bcd]+dcdcde/i
+
+/(ab|a)b*c/i
+ ABC
+ 0: ABC
+ 1: AB
+
+/((a)(b)c)(d)/i
+ ABCD
+ 0: ABCD
+ 1: ABC
+ 2: A
+ 3: B
+ 4: D
+
+/[a-zA-Z_][a-zA-Z0-9_]*/i
+ ALPHA
+ 0: ALPHA
+
+/^a(bc+|b[eh])g|.h$/i
+ ABH
+ 0: BH
+
+/(bc+d$|ef*g.|h?i(j|k))/i
+ EFFGZ
+ 0: EFFGZ
+ 1: EFFGZ
+ IJ
+ 0: IJ
+ 1: IJ
+ 2: J
+ REFFGZ
+ 0: EFFGZ
+ 1: EFFGZ
+ *** Failers
+No match
+ ADCDCDE
+No match
+ EFFG
+No match
+ BCDD
+No match
+
+/((((((((((a))))))))))/i
+ A
+ 0: A
+ 1: A
+ 2: A
+ 3: A
+ 4: A
+ 5: A
+ 6: A
+ 7: A
+ 8: A
+ 9: A
+10: A
+
+/((((((((((a))))))))))\10/i
+ AA
+ 0: AA
+ 1: A
+ 2: A
+ 3: A
+ 4: A
+ 5: A
+ 6: A
+ 7: A
+ 8: A
+ 9: A
+10: A
+
+/(((((((((a)))))))))/i
+ A
+ 0: A
+ 1: A
+ 2: A
+ 3: A
+ 4: A
+ 5: A
+ 6: A
+ 7: A
+ 8: A
+ 9: A
+
+/(?:(?:(?:(?:(?:(?:(?:(?:(?:(a))))))))))/i
+ A
+ 0: A
+ 1: A
+
+/(?:(?:(?:(?:(?:(?:(?:(?:(?:(a|b|c))))))))))/i
+ C
+ 0: C
+ 1: C
+
+/multiple words of text/i
+ *** Failers
+No match
+ AA
+No match
+ UH-UH
+No match
+
+/multiple words/i
+ MULTIPLE WORDS, YEAH
+ 0: MULTIPLE WORDS
+
+/(.*)c(.*)/i
+ ABCDE
+ 0: ABCDE
+ 1: AB
+ 2: DE
+
+/\((.*), (.*)\)/i
+ (A, B)
+ 0: (A, B)
+ 1: A
+ 2: B
+
+/[k]/i
+
+/abcd/i
+ ABCD
+ 0: ABCD
+
+/a(bc)d/i
+ ABCD
+ 0: ABCD
+ 1: BC
+
+/a[-]?c/i
+ AC
+ 0: AC
+
+/(abc)\1/i
+ ABCABC
+ 0: ABCABC
+ 1: ABC
+
+/([a-c]*)\1/i
+ ABCABC
+ 0: ABCABC
+ 1: ABC
+
+/a(?!b)./
+ abad
+ 0: ad
+
+/a(?=d)./
+ abad
+ 0: ad
+
+/a(?=c|d)./
+ abad
+ 0: ad
+
+/a(?:b|c|d)(.)/
+ ace
+ 0: ace
+ 1: e
+
+/a(?:b|c|d)*(.)/
+ ace
+ 0: ace
+ 1: e
+
+/a(?:b|c|d)+?(.)/
+ ace
+ 0: ace
+ 1: e
+ acdbcdbe
+ 0: acd
+ 1: d
+
+/a(?:b|c|d)+(.)/
+ acdbcdbe
+ 0: acdbcdbe
+ 1: e
+
+/a(?:b|c|d){2}(.)/
+ acdbcdbe
+ 0: acdb
+ 1: b
+
+/a(?:b|c|d){4,5}(.)/
+ acdbcdbe
+ 0: acdbcdb
+ 1: b
+
+/a(?:b|c|d){4,5}?(.)/
+ acdbcdbe
+ 0: acdbcd
+ 1: d
+
+/((foo)|(bar))*/
+ foobar
+ 0: foobar
+ 1: bar
+ 2: foo
+ 3: bar
+
+/a(?:b|c|d){6,7}(.)/
+ acdbcdbe
+ 0: acdbcdbe
+ 1: e
+
+/a(?:b|c|d){6,7}?(.)/
+ acdbcdbe
+ 0: acdbcdbe
+ 1: e
+
+/a(?:b|c|d){5,6}(.)/
+ acdbcdbe
+ 0: acdbcdbe
+ 1: e
+
+/a(?:b|c|d){5,6}?(.)/
+ acdbcdbe
+ 0: acdbcdb
+ 1: b
+
+/a(?:b|c|d){5,7}(.)/
+ acdbcdbe
+ 0: acdbcdbe
+ 1: e
+
+/a(?:b|c|d){5,7}?(.)/
+ acdbcdbe
+ 0: acdbcdb
+ 1: b
+
+/a(?:b|(c|e){1,2}?|d)+?(.)/
+ ace
+ 0: ace
+ 1: c
+ 2: e
+
+/^(.+)?B/
+ AB
+ 0: AB
+ 1: A
+
+/^([^a-z])|(\^)$/
+ .
+ 0: .
+ 1: .
+
+/^[<>]&/
+ <&OUT
+ 0: <&
+
+/^(a\1?){4}$/
+ aaaaaaaaaa
+ 0: aaaaaaaaaa
+ 1: aaaa
+ *** Failers
+No match
+ AB
+No match
+ aaaaaaaaa
+No match
+ aaaaaaaaaaa
+No match
+
+/^(a(?(1)\1)){4}$/
+ aaaaaaaaaa
+ 0: aaaaaaaaaa
+ 1: aaaa
+ *** Failers
+No match
+ aaaaaaaaa
+No match
+ aaaaaaaaaaa
+No match
+
+/(?:(f)(o)(o)|(b)(a)(r))*/
+ foobar
+ 0: foobar
+ 1: f
+ 2: o
+ 3: o
+ 4: b
+ 5: a
+ 6: r
+
+/(?<=a)b/
+ ab
+ 0: b
+ *** Failers
+No match
+ cb
+No match
+ b
+No match
+
+/(?<!c)b/
+ ab
+ 0: b
+ b
+ 0: b
+ b
+ 0: b
+
+/(?:..)*a/
+ aba
+ 0: aba
+
+/(?:..)*?a/
+ aba
+ 0: a
+
+/^(?:b|a(?=(.)))*\1/
+ abc
+ 0: ab
+ 1: b
+
+/^(){3,5}/
+ abc
+ 0:
+ 1:
+
+/^(a+)*ax/
+ aax
+ 0: aax
+ 1: a
+
+/^((a|b)+)*ax/
+ aax
+ 0: aax
+ 1: a
+ 2: a
+
+/^((a|bc)+)*ax/
+ aax
+ 0: aax
+ 1: a
+ 2: a
+
+/(a|x)*ab/
+ cab
+ 0: ab
+
+/(a)*ab/
+ cab
+ 0: ab
+
+/(?:(?i)a)b/
+ ab
+ 0: ab
+
+/((?i)a)b/
+ ab
+ 0: ab
+ 1: a
+
+/(?:(?i)a)b/
+ Ab
+ 0: Ab
+
+/((?i)a)b/
+ Ab
+ 0: Ab
+ 1: A
+
+/(?:(?i)a)b/
+ *** Failers
+No match
+ cb
+No match
+ aB
+No match
+
+/((?i)a)b/
+
+/(?i:a)b/
+ ab
+ 0: ab
+
+/((?i:a))b/
+ ab
+ 0: ab
+ 1: a
+
+/(?i:a)b/
+ Ab
+ 0: Ab
+
+/((?i:a))b/
+ Ab
+ 0: Ab
+ 1: A
+
+/(?i:a)b/
+ *** Failers
+No match
+ aB
+No match
+ aB
+No match
+
+/((?i:a))b/
+
+/(?:(?-i)a)b/i
+ ab
+ 0: ab
+
+/((?-i)a)b/i
+ ab
+ 0: ab
+ 1: a
+
+/(?:(?-i)a)b/i
+ aB
+ 0: aB
+
+/((?-i)a)b/i
+ aB
+ 0: aB
+ 1: a
+
+/(?:(?-i)a)b/i
+ *** Failers
+No match
+ aB
+ 0: aB
+ Ab
+No match
+
+/((?-i)a)b/i
+
+/(?:(?-i)a)b/i
+ aB
+ 0: aB
+
+/((?-i)a)b/i
+ aB
+ 0: aB
+ 1: a
+
+/(?:(?-i)a)b/i
+ *** Failers
+No match
+ Ab
+No match
+ AB
+No match
+
+/((?-i)a)b/i
+
+/(?-i:a)b/i
+ ab
+ 0: ab
+
+/((?-i:a))b/i
+ ab
+ 0: ab
+ 1: a
+
+/(?-i:a)b/i
+ aB
+ 0: aB
+
+/((?-i:a))b/i
+ aB
+ 0: aB
+ 1: a
+
+/(?-i:a)b/i
+ *** Failers
+No match
+ AB
+No match
+ Ab
+No match
+
+/((?-i:a))b/i
+
+/(?-i:a)b/i
+ aB
+ 0: aB
+
+/((?-i:a))b/i
+ aB
+ 0: aB
+ 1: a
+
+/(?-i:a)b/i
+ *** Failers
+No match
+ Ab
+No match
+ AB
+No match
+
+/((?-i:a))b/i
+
+/((?-i:a.))b/i
+ *** Failers
+No match
+ AB
+No match
+ a\nB
+No match
+
+/((?s-i:a.))b/i
+ a\nB
+ 0: a\x0aB
+ 1: a\x0a
+
+/(?:c|d)(?:)(?:a(?:)(?:b)(?:b(?:))(?:b(?:)(?:b)))/
+ cabbbb
+ 0: cabbbb
+
+/(?:c|d)(?:)(?:aaaaaaaa(?:)(?:bbbbbbbb)(?:bbbbbbbb(?:))(?:bbbbbbbb(?:)(?:bbbbbbbb)))/
+ caaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+ 0: caaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+
+/(ab)\d\1/i
+ Ab4ab
+ 0: Ab4ab
+ 1: Ab
+ ab4Ab
+ 0: ab4Ab
+ 1: ab
+
+/foo\w*\d{4}baz/
+ foobar1234baz
+ 0: foobar1234baz
+
+/x(~~)*(?:(?:F)?)?/
+ x~~
+ 0: x~~
+ 1: ~~
+
+/^a(?#xxx){3}c/
+ aaac
+ 0: aaac
+
+/^a (?#xxx) (?#yyy) {3}c/x
+ aaac
+ 0: aaac
+
+/(?<![cd])b/
+ *** Failers
+No match
+ B\nB
+No match
+ dbcb
+No match
+
+/(?<![cd])[ab]/
+ dbaacb
+ 0: a
+
+/(?<!(c|d))b/
+
+/(?<!(c|d))[ab]/
+ dbaacb
+ 0: a
+
+/(?<!cd)[ab]/
+ cdaccb
+ 0: b
+
+/^(?:a?b?)*$/
+ *** Failers
+No match
+ dbcb
+No match
+ a--
+No match
+
+/((?s)^a(.))((?m)^b$)/
+ a\nb\nc\n
+ 0: a\x0ab
+ 1: a\x0a
+ 2: \x0a
+ 3: b
+
+/((?m)^b$)/
+ a\nb\nc\n
+ 0: b
+ 1: b
+
+/(?m)^b/
+ a\nb\n
+ 0: b
+
+/(?m)^(b)/
+ a\nb\n
+ 0: b
+ 1: b
+
+/((?m)^b)/
+ a\nb\n
+ 0: b
+ 1: b
+
+/\n((?m)^b)/
+ a\nb\n
+ 0: \x0ab
+ 1: b
+
+/((?s).)c(?!.)/
+ a\nb\nc\n
+ 0: \x0ac
+ 1: \x0a
+ a\nb\nc\n
+ 0: \x0ac
+ 1: \x0a
+
+/((?s)b.)c(?!.)/
+ a\nb\nc\n
+ 0: b\x0ac
+ 1: b\x0a
+ a\nb\nc\n
+ 0: b\x0ac
+ 1: b\x0a
+
+/^b/
+
+/()^b/
+ *** Failers
+No match
+ a\nb\nc\n
+No match
+ a\nb\nc\n
+No match
+
+/((?m)^b)/
+ a\nb\nc\n
+ 0: b
+ 1: b
+
+/(?(1)a|b)/
+
+/(?(1)b|a)/
+ a
+ 0: a
+
+/(x)?(?(1)a|b)/
+ *** Failers
+No match
+ a
+No match
+ a
+No match
+
+/(x)?(?(1)b|a)/
+ a
+ 0: a
+
+/()?(?(1)b|a)/
+ a
+ 0: a
+
+/()(?(1)b|a)/
+
+/()?(?(1)a|b)/
+ a
+ 0: a
+ 1:
+
+/^(\()?blah(?(1)(\)))$/
+ (blah)
+ 0: (blah)
+ 1: (
+ 2: )
+ blah
+ 0: blah
+ *** Failers
+No match
+ a
+No match
+ blah)
+No match
+ (blah
+No match
+
+/^(\(+)?blah(?(1)(\)))$/
+ (blah)
+ 0: (blah)
+ 1: (
+ 2: )
+ blah
+ 0: blah
+ *** Failers
+No match
+ blah)
+No match
+ (blah
+No match
+
+/(?(?!a)a|b)/
+
+/(?(?!a)b|a)/
+ a
+ 0: a
+
+/(?(?=a)b|a)/
+ *** Failers
+No match
+ a
+No match
+ a
+No match
+
+/(?(?=a)a|b)/
+ a
+ 0: a
+
+/(?=(a+?))(\1ab)/
+ aaab
+ 0: aab
+ 1: a
+ 2: aab
+
+/^(?=(a+?))\1ab/
+
+/(\w+:)+/
+ one:
+ 0: one:
+ 1: one:
+
+/$(?<=^(a))/
+ a
+ 0:
+ 1: a
+
+/(?=(a+?))(\1ab)/
+ aaab
+ 0: aab
+ 1: a
+ 2: aab
+
+/^(?=(a+?))\1ab/
+ *** Failers
+No match
+ aaab
+No match
+ aaab
+No match
+
+/([\w:]+::)?(\w+)$/
+ abcd
+ 0: abcd
+ 1: <unset>
+ 2: abcd
+ xy:z:::abcd
+ 0: xy:z:::abcd
+ 1: xy:z:::
+ 2: abcd
+
+/^[^bcd]*(c+)/
+ aexycd
+ 0: aexyc
+ 1: c
+
+/(a*)b+/
+ caab
+ 0: aab
+ 1: aa
+
+/([\w:]+::)?(\w+)$/
+ abcd
+ 0: abcd
+ 1: <unset>
+ 2: abcd
+ xy:z:::abcd
+ 0: xy:z:::abcd
+ 1: xy:z:::
+ 2: abcd
+ *** Failers
+ 0: Failers
+ 1: <unset>
+ 2: Failers
+ abcd:
+No match
+ abcd:
+No match
+
+/^[^bcd]*(c+)/
+ aexycd
+ 0: aexyc
+ 1: c
+
+/(>a+)ab/
+
+/(?>a+)b/
+ aaab
+ 0: aaab
+
+/([[:]+)/
+ a:[b]:
+ 0: :[
+ 1: :[
+
+/([[=]+)/
+ a=[b]=
+ 0: =[
+ 1: =[
+
+/([[.]+)/
+ a.[b].
+ 0: .[
+ 1: .[
+
+/((?>a+)b)/
+ aaab
+ 0: aaab
+ 1: aaab
+
+/(?>(a+))b/
+ aaab
+ 0: aaab
+ 1: aaa
+
+/((?>[^()]+)|\([^()]*\))+/
+ ((abc(ade)ufh()()x
+ 0: abc(ade)ufh()()x
+ 1: x
+
+/a\Z/
+ *** Failers
+No match
+ aaab
+No match
+ a\nb\n
+No match
+
+/b\Z/
+ a\nb\n
+ 0: b
+
+/b\z/
+
+/b\Z/
+ a\nb
+ 0: b
+
+/b\z/
+ a\nb
+ 0: b
+ *** Failers
+No match
+
+/ End of test input /
+