]> granicus.if.org Git - php/commitdiff
upgrade pcre to version 7.0
authorNuno Lopes <nlopess@php.net>
Fri, 9 Feb 2007 19:48:47 +0000 (19:48 +0000)
committerNuno Lopes <nlopess@php.net>
Fri, 9 Feb 2007 19:48:47 +0000 (19:48 +0000)
65 files changed:
NEWS
ext/pcre/config.w32
ext/pcre/config0.m4
ext/pcre/pcrelib/COPYING
ext/pcre/pcrelib/ChangeLog
ext/pcre/pcrelib/LICENCE
ext/pcre/pcrelib/NEWS
ext/pcre/pcrelib/NON-UNIX-USE
ext/pcre/pcrelib/README
ext/pcre/pcrelib/dftables.c
ext/pcre/pcrelib/doc/Tech.Notes
ext/pcre/pcrelib/doc/pcre.txt
ext/pcre/pcrelib/pcre.h
ext/pcre/pcrelib/pcre_compile.c
ext/pcre/pcrelib/pcre_config.c
ext/pcre/pcrelib/pcre_exec.c
ext/pcre/pcrelib/pcre_fullinfo.c
ext/pcre/pcrelib/pcre_get.c
ext/pcre/pcrelib/pcre_globals.c
ext/pcre/pcrelib/pcre_info.c
ext/pcre/pcrelib/pcre_internal.h
ext/pcre/pcrelib/pcre_maketables.c
ext/pcre/pcrelib/pcre_newline.c [new file with mode: 0644]
ext/pcre/pcrelib/pcre_ord2utf8.c
ext/pcre/pcrelib/pcre_printint.src
ext/pcre/pcrelib/pcre_refcount.c
ext/pcre/pcrelib/pcre_scanner.cc
ext/pcre/pcrelib/pcre_scanner.h
ext/pcre/pcrelib/pcre_scanner_unittest.cc
ext/pcre/pcrelib/pcre_study.c
ext/pcre/pcrelib/pcre_tables.c
ext/pcre/pcrelib/pcre_try_flipped.c
ext/pcre/pcrelib/pcre_ucp_searchfuncs.c
ext/pcre/pcrelib/pcre_valid_utf8.c
ext/pcre/pcrelib/pcre_version.c
ext/pcre/pcrelib/pcre_xclass.c
ext/pcre/pcrelib/pcrecpp.cc
ext/pcre/pcrelib/pcrecpp.h
ext/pcre/pcrelib/pcrecpp_unittest.cc
ext/pcre/pcrelib/pcregrep.c
ext/pcre/pcrelib/pcreposix.c
ext/pcre/pcrelib/pcreposix.h
ext/pcre/pcrelib/pcretest.c
ext/pcre/pcrelib/testdata/grepinput
ext/pcre/pcrelib/testdata/grepinput8 [new file with mode: 0644]
ext/pcre/pcrelib/testdata/grepoutput
ext/pcre/pcrelib/testdata/grepoutput8 [new file with mode: 0644]
ext/pcre/pcrelib/testdata/testinput1
ext/pcre/pcrelib/testdata/testinput2
ext/pcre/pcrelib/testdata/testinput4
ext/pcre/pcrelib/testdata/testinput5
ext/pcre/pcrelib/testdata/testinput6
ext/pcre/pcrelib/testdata/testinput7
ext/pcre/pcrelib/testdata/testinput8
ext/pcre/pcrelib/testdata/testoutput1
ext/pcre/pcrelib/testdata/testoutput2
ext/pcre/pcrelib/testdata/testoutput3
ext/pcre/pcrelib/testdata/testoutput4
ext/pcre/pcrelib/testdata/testoutput5
ext/pcre/pcrelib/testdata/testoutput6
ext/pcre/pcrelib/testdata/testoutput7
ext/pcre/pcrelib/testdata/testoutput8
ext/pcre/pcrelib/ucp.h
ext/pcre/pcrelib/ucpinternal.h
ext/pcre/pcrelib/ucptable.c

diff --git a/NEWS b/NEWS
index 3f27292389302fe6db052054f88393b86d19c2b0..50bd51052cf6f4a4a9a09f1c44658fb045fc0ddd 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2007, PHP 5.2.2
 - Upgraded SQLite 3 to version 3.3.12 (Ilia)
+- Upgraded PCRE to version 7.0 (Nuno)
 - Add --ri switch to CLI which allows to check extension information. (Marcus)
 - Fixed bug #40410 (ext/posix does not compile on MacOS 10.3.9). (Tony)
 - Fixed bug #39836 (SplObjectStorage empty after unserialize). (Marcus)
index 8700b3ca084b5f7ff7a9d4d9aabd0f2d8bb43f18..110fb2a7f9524488e1f59f736df7dbc04395d0a5 100644 (file)
@@ -5,8 +5,8 @@ ARG_WITH("pcre-regex", "Perl Compatible Regular Expressions", "yes");
 
 if (PHP_PCRE_REGEX == "yes") {
        EXTENSION("pcre", "php_pcre.c", PHP_PCRE_REGEX_SHARED,
-               "-DEXPORT= -DNEWLINE=10 -DSUPPORT_UTF8 -DSUPPORT_UCP -DLINK_SIZE=2 -DPOSIX_MALLOC_THRESHOLD=10 -DMATCH_LIMIT=10000000 -DMATCH_LIMIT_RECURSION=10000000 -DMAX_NAME_SIZE=32 -DMAX_NAME_COUNT=10000 -DMAX_DUPLENGTH=30000 -DNO_RECURSE -Iext/pcre/pcrelib");
-       ADD_SOURCES("ext/pcre/pcrelib", "pcre_chartables.c pcre_ucp_searchfuncs.c pcre_compile.c pcre_config.c pcre_exec.c pcre_fullinfo.c pcre_get.c pcre_globals.c pcre_info.c pcre_maketables.c pcre_ord2utf8.c pcre_refcount.c pcre_study.c pcre_tables.c pcre_try_flipped.c pcre_valid_utf8.c pcre_version.c pcre_xclass.c", "pcre");
+               "-DEXPORT= -DNEWLINE=10 -DSUPPORT_UTF8 -DSUPPORT_UCP -DLINK_SIZE=2 -DPOSIX_MALLOC_THRESHOLD=10 -DMATCH_LIMIT=10000000 -DMATCH_LIMIT_RECURSION=10000000 -DMAX_NAME_SIZE=32 -DMAX_NAME_COUNT=10000 -DMAX_DUPLENGTH=30000 -DEBCDIC=0 -DNO_RECURSE -Iext/pcre/pcrelib");
+       ADD_SOURCES("ext/pcre/pcrelib", "pcre_chartables.c pcre_ucp_searchfuncs.c pcre_compile.c pcre_config.c pcre_exec.c pcre_fullinfo.c pcre_get.c pcre_globals.c pcre_info.c pcre_maketables.c pcre_newline.c pcre_ord2utf8.c pcre_refcount.c pcre_study.c pcre_tables.c pcre_try_flipped.c pcre_valid_utf8.c pcre_version.c pcre_xclass.c", "pcre");
        ADD_DEF_FILE("ext\\pcre\\php_pcre.def");
 
        AC_DEFINE('HAVE_BUNDLED_PCRE', 1, 'Using bundled PCRE library');
index e762327d00400b76649195aea0f4ea3c63a7e1bf..24e1902a47b5e99a9c1a0574af11f20dc8e330bf 100644 (file)
@@ -13,7 +13,7 @@ PHP_ARG_WITH(pcre-regex,for PCRE support,
 
 if test "$PHP_PCRE_REGEX" != "no"; then
   if test "$PHP_PCRE_REGEX" = "yes"; then
-    PHP_NEW_EXTENSION(pcre, pcrelib/pcre_chartables.c pcrelib/pcre_ucp_searchfuncs.c pcrelib/pcre_compile.c pcrelib/pcre_config.c pcrelib/pcre_exec.c pcrelib/pcre_fullinfo.c pcrelib/pcre_get.c pcrelib/pcre_globals.c pcrelib/pcre_info.c pcrelib/pcre_maketables.c pcrelib/pcre_ord2utf8.c pcrelib/pcre_refcount.c pcrelib/pcre_study.c pcrelib/pcre_tables.c pcrelib/pcre_try_flipped.c pcrelib/pcre_valid_utf8.c pcrelib/pcre_version.c pcrelib/pcre_xclass.c php_pcre.c, $ext_shared,,-DEXPORT= -DNEWLINE=10 -DSUPPORT_UTF8 -DSUPPORT_UCP -DLINK_SIZE=2 -DPOSIX_MALLOC_THRESHOLD=10 -DMATCH_LIMIT=10000000 -DMATCH_LIMIT_RECURSION=10000000 -DMAX_NAME_SIZE=32 -DMAX_NAME_COUNT=10000 -DMAX_DUPLENGTH=30000 -I@ext_srcdir@/pcrelib)
+    PHP_NEW_EXTENSION(pcre, pcrelib/pcre_chartables.c pcrelib/pcre_ucp_searchfuncs.c pcrelib/pcre_compile.c pcrelib/pcre_config.c pcrelib/pcre_exec.c pcrelib/pcre_fullinfo.c pcrelib/pcre_get.c pcrelib/pcre_globals.c pcrelib/pcre_info.c pcrelib/pcre_maketables.c pcrelib/pcre_newline.c pcrelib/pcre_ord2utf8.c pcrelib/pcre_refcount.c pcrelib/pcre_study.c pcrelib/pcre_tables.c pcrelib/pcre_try_flipped.c pcrelib/pcre_valid_utf8.c pcrelib/pcre_version.c pcrelib/pcre_xclass.c php_pcre.c, $ext_shared,,-DEXPORT= -DNEWLINE=10 -DSUPPORT_UTF8 -DSUPPORT_UCP -DLINK_SIZE=2 -DPOSIX_MALLOC_THRESHOLD=10 -DMATCH_LIMIT=10000000 -DMATCH_LIMIT_RECURSION=10000000 -DMAX_NAME_SIZE=32 -DMAX_NAME_COUNT=10000 -DMAX_DUPLENGTH=30000 -DEBCDIC=0 -I@ext_srcdir@/pcrelib)
     PHP_ADD_BUILD_DIR($ext_builddir/pcrelib)
     PHP_INSTALL_HEADERS([ext/pcre], [php_pcre.h pcrelib/])
     AC_DEFINE(HAVE_BUNDLED_PCRE, 1, [ ])
index daea2e48a3f06cf8039a58e8d5414ed9236667bb..58241b2bdae10081919a7466c1aacdd3d32831e4 100644 (file)
@@ -4,7 +4,7 @@ PCRE LICENCE
 PCRE is a library of functions to support regular expressions whose syntax
 and semantics are as close as possible to those of the Perl 5 language.
 
-Release 6 of PCRE is distributed under the terms of the "BSD" licence, as
+Release 7 of PCRE is distributed under the terms of the "BSD" licence, as
 specified below. The documentation for PCRE, supplied in the "doc"
 directory, is distributed under the same terms as the software itself.
 
index 2a141348482c135cb17a74f6e3a408c9015c314e..7d32804d05f2fc1a33a64dc03ab5eda49cedad89 100644 (file)
@@ -1,6 +1,279 @@
 ChangeLog for PCRE
 ------------------
 
+Version 7.0 19-Dec-06
+---------------------
+
+ 1. Fixed a signed/unsigned compiler warning in pcre_compile.c, shown up by
+    moving to gcc 4.1.1.
+
+ 2. The -S option for pcretest uses setrlimit(); I had omitted to #include
+    sys/time.h, which is documented as needed for this function. It doesn't
+    seem to matter on Linux, but it showed up on some releases of OS X.
+
+ 3. It seems that there are systems where bytes whose values are greater than
+    127 match isprint() in the "C" locale. The "C" locale should be the
+    default when a C program starts up. In most systems, only ASCII printing
+    characters match isprint(). This difference caused the output from pcretest
+    to vary, making some of the tests fail. I have changed pcretest so that:
+
+    (a) When it is outputting text in the compiled version of a pattern, bytes
+        other than 32-126 are always shown as hex escapes.
+
+    (b) When it is outputting text that is a matched part of a subject string,
+        it does the same, unless a different locale has been set for the match
+        (using the /L modifier). In this case, it uses isprint() to decide.
+
+ 4. Fixed a major bug that caused incorrect computation of the amount of memory
+    required for a compiled pattern when options that changed within the
+    pattern affected the logic of the preliminary scan that determines the
+    length. The relevant options are -x, and -i in UTF-8 mode. The result was
+    that the computed length was too small. The symptoms of this bug were
+    either the PCRE error "internal error: code overflow" from pcre_compile(),
+    or a glibc crash with a message such as "pcretest: free(): invalid next
+    size (fast)". Examples of patterns that provoked this bug (shown in
+    pcretest format) are:
+
+      /(?-x: )/x
+      /(?x)(?-x: \s*#\s*)/
+      /((?i)[\x{c0}])/8
+      /(?i:[\x{c0}])/8
+
+    HOWEVER: Change 17 below makes this fix obsolete as the memory computation
+    is now done differently.
+
+ 5. Applied patches from Google to: (a) add a QuoteMeta function to the C++
+    wrapper classes; (b) implement a new function in the C++ scanner that is
+    more efficient than the old way of doing things because it avoids levels of
+    recursion in the regex matching; (c) add a paragraph to the documentation
+    for the FullMatch() function.
+
+ 6. The escape sequence \n was being treated as whatever was defined as
+    "newline". Not only was this contrary to the documentation, which states
+    that \n is character 10 (hex 0A), but it also went horribly wrong when
+    "newline" was defined as CRLF. This has been fixed.
+
+ 7. In pcre_dfa_exec.c the value of an unsigned integer (the variable called c)
+    was being set to -1 for the "end of line" case (supposedly a value that no
+    character can have). Though this value is never used (the check for end of
+    line is "zero bytes in current character"), it caused compiler complaints.
+    I've changed it to 0xffffffff.
+
+ 8. In pcre_version.c, the version string was being built by a sequence of
+    C macros that, in the event of PCRE_PRERELEASE being defined as an empty
+    string (as it is for production releases) called a macro with an empty
+    argument. The C standard says the result of this is undefined. The gcc
+    compiler treats it as an empty string (which was what was wanted) but it is
+    reported that Visual C gives an error. The source has been hacked around to
+    avoid this problem.
+
+ 9. On the advice of a Windows user, included <io.h> and <fcntl.h> in Windows
+    builds of pcretest, and changed the call to _setmode() to use _O_BINARY
+    instead of 0x8000. Made all the #ifdefs test both _WIN32 and WIN32 (not all
+    of them did).
+
+10. Originally, pcretest opened its input and output without "b"; then I was
+    told that "b" was needed in some environments, so it was added for release
+    5.0 to both the input and output. (It makes no difference on Unix-like
+    systems.) Later I was told that it is wrong for the input on Windows. I've
+    now abstracted the modes into two macros, to make it easier to fiddle with
+    them, and removed "b" from the input mode under Windows.
+
+11. Added pkgconfig support for the C++ wrapper library, libpcrecpp.
+
+12. Added -help and --help to pcretest as an official way of being reminded
+    of the options.
+
+13. Removed some redundant semicolons after macro calls in pcrecpparg.h.in
+    and pcrecpp.cc because they annoy compilers at high warning levels.
+
+14. A bit of tidying/refactoring in pcre_exec.c in the main bumpalong loop.
+
+15. Fixed an occurrence of == in configure.ac that should have been = (shell
+    scripts are not C programs :-) and which was not noticed because it works
+    on Linux.
+
+16. pcretest is supposed to handle any length of pattern and data line (as one
+    line or as a continued sequence of lines) by extending its input buffer if
+    necessary. This feature was broken for very long pattern lines, leading to
+    a string of junk being passed to pcre_compile() if the pattern was longer
+    than about 50K.
+
+17. I have done a major re-factoring of the way pcre_compile() computes the
+    amount of memory needed for a compiled pattern. Previously, there was code
+    that made a preliminary scan of the pattern in order to do this. That was
+    OK when PCRE was new, but as the facilities have expanded, it has become
+    harder and harder to keep it in step with the real compile phase, and there
+    have been a number of bugs (see for example, 4 above). I have now found a
+    cunning way of running the real compile function in a "fake" mode that
+    enables it to compute how much memory it would need, while actually only
+    ever using a few hundred bytes of working memory and without too many
+    tests of the mode. This should make future maintenance and development
+    easier. A side effect of this work is that the limit of 200 on the nesting
+    depth of parentheses has been removed (though this was never a serious
+    limitation, I suspect). However, there is a downside: pcre_compile() now
+    runs more slowly than before (30% or more, depending on the pattern). I
+    hope this isn't a big issue. There is no effect on runtime performance.
+
+18. Fixed a minor bug in pcretest: if a pattern line was not terminated by a
+    newline (only possible for the last line of a file) and it was a
+    pattern that set a locale (followed by /Lsomething), pcretest crashed.
+
+19. Added additional timing features to pcretest. (1) The -tm option now times
+    matching only, not compiling. (2) Both -t and -tm can be followed, as a
+    separate command line item, by a number that specifies the number of
+    repeats to use when timing. The default is 50000; this gives better
+    precision, but takes uncomfortably long for very large patterns.
+
+20. Extended pcre_study() to be more clever in cases where a branch of a
+    subpattern has no definite first character. For example, (a*|b*)[cd] would
+    previously give no result from pcre_study(). Now it recognizes that the
+    first character must be a, b, c, or d.
+
+21. There was an incorrect error "recursive call could loop indefinitely" if
+    a subpattern (or the entire pattern) that was being tested for matching an
+    empty string contained only one non-empty item after a nested subpattern.
+    For example, the pattern (?>\x{100}*)\d(?R) provoked this error
+    incorrectly, because the \d was being skipped in the check.
+
+22. The pcretest program now has a new pattern option /B and a command line
+    option -b, which is equivalent to adding /B to every pattern. This causes
+    it to show the compiled bytecode, without the additional information that
+    -d shows. The effect of -d is now the same as -b with -i (and similarly, /D
+    is the same as /B/I).
+
+23. A new optimization is now able automatically to treat some sequences such
+    as a*b as a*+b. More specifically, if something simple (such as a character
+    or a simple class like \d) has an unlimited quantifier, and is followed by
+    something that cannot possibly match the quantified thing, the quantifier
+    is automatically "possessified".
+
+24. A recursive reference to a subpattern whose number was greater than 39
+    went wrong under certain circumstances in UTF-8 mode. This bug could also
+    have affected the operation of pcre_study().
+
+25. Realized that a little bit of performance could be had by replacing
+    (c & 0xc0) == 0xc0 with c >= 0xc0 when processing UTF-8 characters.
+
+26. Timing data from pcretest is now shown to 4 decimal places instead of 3.
+
+27. Possessive quantifiers such as a++ were previously implemented by turning
+    them into atomic groups such as ($>a+). Now they have their own opcodes,
+    which improves performance. This includes the automatically created ones
+    from 23 above.
+
+28. A pattern such as (?=(\w+))\1: which simulates an atomic group using a
+    lookahead was broken if it was not anchored. PCRE was mistakenly expecting
+    the first matched character to be a colon. This applied both to named and
+    numbered groups.
+
+29. The ucpinternal.h header file was missing its idempotency #ifdef.
+
+30. I was sent a "project" file called libpcre.a.dev which I understand makes
+    building PCRE on Windows easier, so I have included it in the distribution.
+
+31. There is now a check in pcretest against a ridiculously large number being
+    returned by pcre_exec() or pcre_dfa_exec(). If this happens in a /g or /G
+    loop, the loop is abandoned.
+
+32. Forward references to subpatterns in conditions such as (?(2)...) where
+    subpattern 2 is defined later cause pcre_compile() to search forwards in
+    the pattern for the relevant set of parentheses. This search went wrong
+    when there were unescaped parentheses in a character class, parentheses
+    escaped with \Q...\E, or parentheses in a #-comment in /x mode.
+
+33. "Subroutine" calls and backreferences were previously restricted to
+    referencing subpatterns earlier in the regex. This restriction has now
+    been removed.
+
+34. Added a number of extra features that are going to be in Perl 5.10. On the
+    whole, these are just syntactic alternatives for features that PCRE had
+    previously implemented using the Python syntax or my own invention. The
+    other formats are all retained for compatibility.
+
+    (a) Named groups can now be defined as (?<name>...) or (?'name'...) as well
+        as (?P<name>...). The new forms, as well as being in Perl 5.10, are
+        also .NET compatible.
+
+    (b) A recursion or subroutine call to a named group can now be defined as
+        (?&name) as well as (?P>name).
+
+    (c) A backreference to a named group can now be defined as \k<name> or
+        \k'name' as well as (?P=name). The new forms, as well as being in Perl
+        5.10, are also .NET compatible.
+
+    (d) A conditional reference to a named group can now use the syntax
+        (?(<name>) or (?('name') as well as (?(name).
+
+    (e) A "conditional group" of the form (?(DEFINE)...) can be used to define
+        groups (named and numbered) that are never evaluated inline, but can be
+        called as "subroutines" from elsewhere. In effect, the DEFINE condition
+        is always false. There may be only one alternative in such a group.
+
+    (f) A test for recursion can be given as (?(R1).. or (?(R&name)... as well
+        as the simple (?(R). The condition is true only if the most recent
+        recursion is that of the given number or name. It does not search out
+        through the entire recursion stack.
+
+    (g) The escape \gN or \g{N} has been added, where N is a positive or
+        negative number, specifying an absolute or relative reference.
+
+35. Tidied to get rid of some further signed/unsigned compiler warnings and
+    some "unreachable code" warnings.
+
+36. Updated the Unicode property tables to Unicode version 5.0.0. Amongst other
+    things, this adds five new scripts.
+
+37. Perl ignores orphaned \E escapes completely. PCRE now does the same.
+    There were also incompatibilities regarding the handling of \Q..\E inside
+    character classes, for example with patterns like [\Qa\E-\Qz\E] where the
+    hyphen was adjacent to \Q or \E. I hope I've cleared all this up now.
+
+38. Like Perl, PCRE detects when an indefinitely repeated parenthesized group
+    matches an empty string, and forcibly breaks the loop. There were bugs in
+    this code in non-simple cases. For a pattern such as  ^(a()*)*  matched
+    against  aaaa  the result was just "a" rather than "aaaa", for example. Two
+    separate and independent bugs (that affected different cases) have been
+    fixed.
+
+39. Refactored the code to abolish the use of different opcodes for small
+    capturing bracket numbers. This is a tidy that I avoided doing when I
+    removed the limit on the number of capturing brackets for 3.5 back in 2001.
+    The new approach is not only tidier, it makes it possible to reduce the
+    memory needed to fix the previous bug (38).
+
+40. Implemented PCRE_NEWLINE_ANY to recognize any of the Unicode newline
+    sequences (http://unicode.org/unicode/reports/tr18/) as "newline" when
+    processing dot, circumflex, or dollar metacharacters, or #-comments in /x
+    mode.
+
+41. Add \R to match any Unicode newline sequence, as suggested in the Unicode
+    report.
+
+42. Applied patch, originally from Ari Pollak, modified by Google, to allow
+    copy construction and assignment in the C++ wrapper.
+
+43. Updated pcregrep to support "--newline=any". In the process, I fixed a
+    couple of bugs that could have given wrong results in the "--newline=crlf"
+    case.
+
+44. Added a number of casts and did some reorganization of signed/unsigned int
+    variables following suggestions from Dair Grant. Also renamed the variable
+    "this" as "item" because it is a C++ keyword.
+
+45. Arranged for dftables to add
+
+      #include "pcre_internal.h"
+
+    to pcre_chartables.c because without it, gcc 4.x may remove the array
+    definition from the final binary if PCRE is built into a static library and
+    dead code stripping is activated.
+
+46. For an unanchored pattern, if a match attempt fails at the start of a
+    newline sequence, and the newline setting is CRLF or ANY, and the next two
+    characters are CRLF, advance by two characters instead of one.
+
+
 Version 6.7 04-Jul-06
 ---------------------
 
index daea2e48a3f06cf8039a58e8d5414ed9236667bb..58241b2bdae10081919a7466c1aacdd3d32831e4 100644 (file)
@@ -4,7 +4,7 @@ PCRE LICENCE
 PCRE is a library of functions to support regular expressions whose syntax
 and semantics are as close as possible to those of the Perl 5 language.
 
-Release 6 of PCRE is distributed under the terms of the "BSD" licence, as
+Release 7 of PCRE is distributed under the terms of the "BSD" licence, as
 specified below. The documentation for PCRE, supplied in the "doc"
 directory, is distributed under the same terms as the software itself.
 
index 4f17b198a0a114ee922f3fc7ec4e0c120fcfd010..92768eaa8cad82a2bb0cb3f057372a71f6e8f160 100644 (file)
@@ -1,6 +1,36 @@
 News about PCRE releases
 ------------------------
 
+Release 7.0 23-Nov-06
+---------------------
+
+This release has a new major number because there have been some internal
+upheavals to facilitate the addition of new optimizations and other facilities,
+and to make subsequent maintenance and extension easier. Compilation is likely
+to be a bit slower, but there should be no major effect on runtime performance.
+Previously compiled patterns are NOT upwards compatible with this release. If
+you have saved compiled patterns from a previous release, you will have to
+re-compile them. Important changes that are visible to users are:
+
+1. The Unicode property tables have been updated to Unicode 5.0.0, which adds
+   some more scripts.
+
+2. The option PCRE_NEWLINE_ANY causes PCRE to recognize any Unicode newline
+   sequence as a newline.
+
+3. The \R escape matches a single Unicode newline sequence as a single unit.
+
+4. New features that will appear in Perl 5.10 are now in PCRE. These include
+   alternative Perl syntax for named parentheses, and Perl syntax for
+   recursion.
+
+5. The C++ wrapper interface has been extended by the addition of a
+   QuoteMeta function and the ability to allow copy construction and
+   assignment.
+
+For a complete list of changes, see the ChangeLog file.
+
+
 Release 6.7 04-Jul-06
 ---------------------
 
index 459bdf2b4fe8f8254cbab419fecb51aff4be1c7a..bcc0dc9af226f56520ceae6c161e43f7863752b1 100644 (file)
@@ -22,7 +22,7 @@ The following are generic comments about building PCRE. The interspersed
 indented commands are suggestions from Mark Tetrode as to which commands you
 might use on a Windows system to build a static library.
 
-(1) Copy or rename the file config.in as config.h, and change the macros that
+(1) Copy or rename the file config.h.in as config.h, and change the macros that
 define HAVE_STRERROR and HAVE_MEMMOVE to define them as 1 rather than 0.
 Unfortunately, because of the way Unix autoconf works, the default setting has
 to be 0. You may also want to make changes to other macros in config.h. In
@@ -31,7 +31,7 @@ the NEWLINE macro. The default is to use '\n', thereby using whatever value
 your compiler gives to '\n'.
 
   rem Mark Tetrode's commands
-  copy config.in config.h
+  copy config.h.in config.h
   rem Use write, because notepad cannot handle UNIX files. Change values.
   write config.h
 
@@ -56,6 +56,7 @@ character tables and writes them to that file.
   pcre_globals.c
   pcre_info.c
   pcre_maketables.c
+  pcre_newline.c
   pcre_ord2utf8.c
   pcre_refcount.c
   pcre_study.c
@@ -93,10 +94,10 @@ pcre and pcreposix libraries when linking.
   cl /F0x400000 pcretest.c pcre.lib pcreposix.lib
 
 (6) Run pcretest on the testinput files in the testdata directory, and check
-that the output matches the corresponding testoutput files. You must use the
--i option when checking testinput2. Note that the supplied files are in Unix
-format, with just LF characters as line terminators. You may need to edit them
-to change this if your system uses a different convention.
+that the output matches the corresponding testoutput files. Note that the
+supplied files are in Unix format, with just LF characters as line terminators.
+You may need to edit them to change this if your system uses a different
+convention.
 
   rem Mark Tetrode's commands
   pcretest testdata\testinput1 testdata\myoutput1
@@ -135,6 +136,17 @@ If you have a system without "configure" but where you can use a Makefile, edit
 Makefile.in to create Makefile, substituting suitable values for the variables
 at the head of the file.
 
+Michael Roy sent these comments about building PCRE under Windows with BCC5.5:
+
+  Some of the core BCC libraries have a version of PCRE from 1998 built in,
+  which can lead to pcre_exec() giving an erroneous PCRE_ERROR_NULL from a
+  version mismatch. I'm including an easy workaround below, if you'd like to
+  include it in the non-unix instructions:
+
+  When linking a project with BCC5.5, pcre.lib must be included before any of
+  the libraries cw32.lib, cw32i.lib, cw32mt.lib, and cw32mti.lib on the command
+  line.
+
 Some help in building a Win32 DLL of PCRE in GnuWin32 environments was
 contributed by Paul Sokolovsky. These environments are Mingw32
 (http://www.xraylith.wisc.edu/~khan/software/gnu-win32/) and CygWin
index 24d0b9749730c14998cdc40c075f36a0a575960d..55e8fd0940f4a45e0f6d33cb21367dc7ed15752e 100644 (file)
@@ -118,13 +118,13 @@ library. You can read more about them in the pcrebuild man page.
   property table); only the basic two-letter properties such as Lu are
   supported.
 
-. You can build PCRE to recognize either CR or LF or the sequence CRLF as
-  indicating the end of a line. Whatever you specify at build time is the
-  default; the caller of PCRE can change the selection at run time. The default
-  newline indicator is a single LF character (the Unix standard). You can
-  specify the default newline indicator by adding --newline-is-cr or
-  --newline-is-lf or --newline-is-crlf to the "configure" command,
-  respectively.
+. You can build PCRE to recognize either CR or LF or the sequence CRLF or any
+  of the Unicode newline sequences as indicating the end of a line. Whatever
+  you specify at build time is the default; the caller of PCRE can change the
+  selection at run time. The default newline indicator is a single LF character
+  (the Unix standard). You can specify the default newline indicator by adding
+  --newline-is-cr or --newline-is-lf or --newline-is-crlf or --newline-is-any
+  to the "configure" command, respectively.
 
 . When called via the POSIX interface, PCRE uses malloc() to get additional
   storage for processing capturing parentheses if there are more than 10 of
@@ -283,7 +283,7 @@ to the values of CC and CFLAGS.
 Using HP's ANSI C++ compiler (aCC)
 ----------------------------------
 
-Unless C++ support is disabled by specifiying the "--disable-cpp" option of the
+Unless C++ support is disabled by specifying the "--disable-cpp" option of the
 "configure" script, you *must* include the "-AA" option in the CXXFLAGS
 environment variable in order for the C++ components to compile correctly.
 
@@ -305,8 +305,8 @@ PCRE in the same way as for Unix systems.
 
 PCRE has been compiled on Windows systems and on Macintoshes, but I don't know
 the details because I don't use those systems. It should be straightforward to
-build PCRE on any system that has a Standard C compiler, because it uses only
-Standard C functions.
+build PCRE on any system that has a Standard C compiler and library, because it
+uses only Standard C functions.
 
 
 Testing PCRE
@@ -325,15 +325,15 @@ NON-UNIX-USE.
 The RunTest script runs the pcretest test program (which is documented in its
 own man page) on each of the testinput files (in the testdata directory) in
 turn, and compares the output with the contents of the corresponding testoutput
-file. A file called testtry is used to hold the main output from pcretest
+files. A file called testtry is used to hold the main output from pcretest
 (testsavedregex is also used as a working file). To run pcretest on just one of
 the test files, give its number as an argument to RunTest, for example:
 
   RunTest 2
 
-The first file can also be fed directly into the perltest script to check that
-Perl gives the same results. The only difference you should see is in the first
-few lines, where the Perl version is given instead of the PCRE version.
+The first test file can also be fed directly into the perltest script to check
+that Perl gives the same results. The only difference you should see is in the
+first few lines, where the Perl version is given instead of the PCRE version.
 
 The second set of tests check pcre_fullinfo(), pcre_info(), pcre_study(),
 pcre_copy_substring(), pcre_get_substring(), pcre_get_substring_list(), error
@@ -442,6 +442,7 @@ The distribution should contain the following files:
   pcre_globals.c        )   and some internal functions that they use
   pcre_info.c           )
   pcre_maketables.c     )
+  pcre_newline.c        )
   pcre_ord2utf8.c       )
   pcre_refcount.c       )
   pcre_study.c          )
@@ -525,4 +526,4 @@ The distribution should contain the following files:
 Philip Hazel
 Email local part: ph10
 Email domain: cam.ac.uk
-June 2006
+November 2006
index 8c76b65df697b5bae740ad67db629905e8ec5010..a94b7a61d550d30c5b25c9af305cc1fb33df9273 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -86,7 +86,16 @@ fprintf(f,
 fprintf(f,
   "This file contains the default tables for characters with codes less than\n"
   "128 (ASCII characters). These tables are used when no external tables are\n"
-  "passed to PCRE. */\n\n"
+  "passed to PCRE.\n\n");
+fprintf(f,
+  "The following #include is present because without it gcc 4.x may remove\n"
+  "the array definition from the final binary if PCRE is built into a static\n"
+  "library and dead code stripping is activated. This leads to link errors.\n"
+  "Pulling in the header ensures that the array gets flagged as \"someone\n"
+  "outside this compilation unit might reference this\" and so it will always\n"
+  "be supplied to the linker. */\n\n"
+  "#include \"pcre_internal.h\"\n\n");
+fprintf(f,
   "const unsigned char _pcre_default_tables[] = {\n\n"
   "/* This table is a lower casing table. */\n\n");
 
index 21dbe1f9b53c8e5fd8acfcf0b7379f0c47e8a717..c75b3e8a5d1d60d07cbcea6675b1a0d6e5a9cb79 100644 (file)
@@ -16,10 +16,11 @@ not operate by backtracking, as the original Henry Spencer code and current
 Perl code does, but instead checked all possibilities simultaneously by keeping
 a list of current states and checking all of them as it advanced through the
 subject string. In the terminology of Jeffrey Friedl's book, it was a "DFA
-algorithm". When the pattern was all used up, all remaining states were
-possible matches, and the one matching the longest subset of the subject string
-was chosen. This did not necessarily maximize the individual wild portions of
-the pattern, as is expected in Unix and Perl-style regular expressions.
+algorithm", though it was not a traditional Finite State Machine (FSM). When
+the pattern was all used up, all remaining states were possible matches, and
+the one matching the longest subset of the subject string was chosen. This did
+not necessarily maximize the individual wild portions of the pattern, as is
+expected in Unix and Perl-style regular expressions.
 
 Historical note 2
 -----------------
@@ -41,14 +42,38 @@ unrelated to those mentioned above), 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, for a number of reasons. PCRE 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 pass can just store stuff
-straight into the vector, which it knows is big enough. It does make the
-compiling functions bigger, of course, but they have become quite big anyway to
-handle all the Perl stuff.
+first pass through the pattern is helpful for other reasons. 
+
+Computing the memory requirement: how it was
+--------------------------------------------
+
+Up to and including release 6.7, PCRE worked by running a very degenerate first
+pass to calculate a maximum store size, and then a second pass to do the real
+compile - which might use a bit less than the predicted amount of memory. The
+idea was that this would turn out faster than the Henry Spencer code because
+the first pass is degenerate and the second pass can just store stuff straight
+into the vector, which it knows is big enough.
+
+Computing the memory requirement: how it is
+-------------------------------------------
+
+By the time I was working on a potential 6.8 release, the degenerate first pass
+had become very complicated and hard to maintain. Indeed one of the early
+things I did for 6.8 was to fix Yet Another Bug in the memory computation. Then
+I had a flash of inspiration as to how I could run the real compile function in
+a "fake" mode that enables it to compute how much memory it would need, while
+actually only ever using a few hundred bytes of working memory, and without too
+many tests of the mode that might slow it down. So I re-factored the compiling
+functions to work this way. This got rid of about 600 lines of source. It
+should make future maintenance and development easier. As this was such a major 
+change, I never released 6.8, instead upping the number to 7.0 (other quite 
+major changes are also present in the 7.0 release).
+
+A side effect of this work is that the previous limit of 200 on the nesting
+depth of parentheses was removed. However, there is a downside: pcre_compile()
+runs more slowly than before (30% or more, depending on the pattern) because it
+is doing a full analysis of the pattern. My hope is that this is not a big
+issue.
 
 Traditional matching function
 -----------------------------
@@ -70,6 +95,12 @@ intreprets the same compiled pattern data as pcre_exec(); however, not all the
 facilities are available, and those that are do not always work in quite the 
 same way. See the user documentation for details.
 
+The algorithm that is used for pcre_dfa_exec() is not a traditional FSM, 
+because it may have a number of states active at one time. More work would be 
+needed at compile time to produce a traditional FSM where only one state is 
+ever active at once. I believe some other regex matchers work this way.
+
+
 Format of compiled patterns
 ---------------------------
 
@@ -79,10 +110,12 @@ item is either implicit in the opcode or contained in the data bytes that
 follow it. 
 
 In many cases below "two-byte" data values are specified. This is in fact just
-a default. PCRE can be compiled to use 3-byte or 4-byte values (impairing the
+a default when the number is an offset within the compiled pattern. PCRE can be
+compiled to use 3-byte or 4-byte values for these offsets (impairing the
 performance). This is necessary only when patterns whose compiled length is
-greater than 64K are going to be processed. In this description, we assume the 
-"normal" compilation options.
+greater than 64K are going to be processed. In this description, we assume the
+"normal" compilation options. "Two-byte" data values that are counts (e.g. for 
+quantifiers) are always just two bytes.
 
 A list of all the opcodes follows:
 
@@ -109,6 +142,7 @@ These items are all just one byte long
   OP_EOD                 match end of data: \z
   OP_DOLL                $ (end of data, or before \n in multiline)
   OP_EXTUNI              match an extended Unicode character 
+  OP_ANYNL               match any Unicode newline sequence 
   
 
 Repeating single characters
@@ -119,23 +153,28 @@ following opcodes:
 
   OP_STAR
   OP_MINSTAR
+  OP_POSSTAR 
   OP_PLUS
   OP_MINPLUS
+  OP_POSPLUS 
   OP_QUERY
   OP_MINQUERY
+  OP_POSQUERY 
 
 In ASCII mode, these are two-byte items; in UTF-8 mode, the length is variable.
-Those with "MIN" in their name are the minimizing versions. Each is followed by
-the character that is to be repeated. Other repeats make use of
+Those with "MIN" in their name are the minimizing versions. Those with "POS" in 
+their names are possessive versions. Each is followed by the character that is
+to be repeated. Other repeats make use of
 
   OP_UPTO
   OP_MINUPTO
+  OP_POSUPTO 
   OP_EXACT
 
 which are followed by a two-byte count (most significant first) and the
 repeated character. OP_UPTO matches from 0 to the given number. A repeat with a
 non-zero minimum and a fixed maximum is coded as an OP_EXACT followed by an
-OP_UPTO (or OP_MINUPTO).
+OP_UPTO (or OP_MINUPTO or OPT_POSUPTO).
 
 
 Repeating character types
@@ -147,12 +186,16 @@ byte. The opcodes are:
 
   OP_TYPESTAR
   OP_TYPEMINSTAR
+  OP_TYPEPOSSTAR 
   OP_TYPEPLUS
   OP_TYPEMINPLUS
+  OP_TYPEPOSPLUS 
   OP_TYPEQUERY
   OP_TYPEMINQUERY
+  OP_TYPEPOSQUERY 
   OP_TYPEUPTO
   OP_TYPEMINUPTO
+  OP_TYPEPOSUPTO 
   OP_TYPEEXACT
 
 
@@ -216,9 +259,10 @@ OP_REF is followed by two bytes containing the reference number.
 Repeating character classes and back references
 -----------------------------------------------
 
-Single-character classes are handled specially (see above). This applies to
-OP_CLASS and OP_REF. In both cases, the repeat information follows the base
-item. The matching code looks at the following opcode to see if it is one of
+Single-character classes are handled specially (see above). This section
+applies to OP_CLASS and OP_REF. In both cases, the repeat information follows
+the base item. The matching code looks at the following opcode to see if it is
+one of
 
   OP_CRSTAR
   OP_CRMINSTAR
@@ -230,7 +274,9 @@ item. The matching code looks at the following opcode to see if it is one of
   OP_CRMINRANGE
 
 All but the last two are just single-byte items. The others are followed by
-four bytes of data, comprising the minimum and maximum repeat counts.
+four bytes of data, comprising the minimum and maximum repeat counts. There are 
+no special possessive opcodes for these repeats; a possessive repeat is 
+compiled into an atomic group.
 
 
 Brackets and alternation
@@ -239,29 +285,25 @@ Brackets and alternation
 A pair of non-capturing (round) brackets is wrapped round each expression at
 compile time, so alternation always happens in the context of brackets.
 
-Non-capturing brackets use the opcode OP_BRA, while capturing brackets use
-OP_BRA+1, OP_BRA+2, etc. [Note for North Americans: "bracket" to some English
-speakers, including myself, can be round, square, curly, or pointy. Hence this
-usage.]
+[Note for North Americans: "bracket" to some English speakers, including
+myself, can be round, square, curly, or pointy. Hence this usage.]
 
-Originally PCRE was limited to 99 capturing brackets (so as not to use up all
-the opcodes). From release 3.5, there is no limit. What happens is that the
-first ones, up to EXTRACT_BASIC_MAX are handled with separate opcodes, as
-above. If there are more, the opcode is set to EXTRACT_BASIC_MAX+1, and the
-first operation in the bracket is OP_BRANUMBER, followed by a 2-byte bracket
-number. This opcode is ignored while matching, but is fished out when handling
-the bracket itself. (They could have all been done like this, but I was making
-minimal changes.)
+Non-capturing brackets use the opcode OP_BRA. Originally PCRE was limited to 99
+capturing brackets and it used a different opcode for each one. From release
+3.5, the limit was removed by putting the bracket number into the data for
+higher-numbered brackets. From release 7.0 all capturing brackets are handled
+this way, using the single opcode OP_CBRA.
 
 A bracket opcode is followed by LINK_SIZE bytes which give the offset to the
 next alternative OP_ALT or, if there aren't any branches, to the matching
 OP_KET opcode. Each OP_ALT is followed by LINK_SIZE bytes giving the offset to
-the next one, or to the OP_KET opcode.
+the next one, or to the OP_KET opcode. For capturing brackets, the bracket 
+number immediately follows the offset, always as a 2-byte item.
 
 OP_KET is used for subpatterns that do not repeat indefinitely, while
 OP_KETRMIN and OP_KETRMAX are used for indefinite repetitions, minimally or
 maximally respectively. All three are followed by LINK_SIZE bytes giving (as a
-positive number) the offset back to the matching OP_BRA opcode.
+positive number) the offset back to the matching bracket opcode.
 
 If a subpattern is quantified such that it is permitted to match zero times, it
 is preceded by one of OP_BRAZERO or OP_BRAMINZERO. These are single-byte
@@ -276,7 +318,14 @@ as appropriate.
 A subpattern with a bounded maximum repetition is replicated in a nested
 fashion up to the maximum number of times, with OP_BRAZERO or OP_BRAMINZERO
 before each replication after the minimum, so that, for example, (abc){2,5} is
-compiled as (abc)(abc)((abc)((abc)(abc)?)?)?.
+compiled as (abc)(abc)((abc)((abc)(abc)?)?)?, except that each bracketed group 
+has the same number.
+
+When a repeated subpattern has an unbounded upper limit, it is checked to see 
+whether it could match an empty string. If this is the case, the opcode in the 
+final replication is changed to OP_SBRA or OP_SCBRA. This tells the matcher
+that it needs to check for matching an empty string when it hits OP_KETRMIN or
+OP_KETRMAX, and if so, to break the loop.
 
 
 Assertions
@@ -292,22 +341,27 @@ each alternative of a lookbehind assertion, allowing them to have different
 fixed lengths.
 
 
-Once-only subpatterns
----------------------
+Once-only (atomic) subpatterns
+------------------------------
 
 These are also just like other subpatterns, but they start with the opcode
-OP_ONCE.
+OP_ONCE. The check for matching an empty string in an unbounded repeat is 
+handled entirely at runtime, so there is just this one opcode.
 
 
 Conditional subpatterns
 -----------------------
 
-These are like other subpatterns, but they start with the opcode OP_COND. If
+These are like other subpatterns, but they start with the opcode OP_COND, or
+OP_SCOND for one that might match an empty string in an unbounded repeat. If
 the condition is a back reference, this is stored at the start of the
 subpattern using the opcode OP_CREF followed by two bytes containing the
-reference number. If the condition is "in recursion" (coded as "(?(R)"), the
-same scheme is used, with a "reference number" of 0xffff. Otherwise, a
-conditional subpattern always starts with one of the assertions.
+reference number. If the condition is "in recursion" (coded as "(?(R)"), or "in
+recursion of group x" (coded as "(?(Rx)"), the group number is stored at the
+start of the subpattern using the opcode OP_RREF, and a value of zero for "the
+whole pattern". For a DEFINE condition, just the single byte OP_DEF is used (it
+has no associated data). Otherwise, a conditional subpattern always starts with
+one of the assertions.
 
 
 Recursion
@@ -345,4 +399,4 @@ at compile time, and so does not cause anything to be put into the compiled
 data.
 
 Philip Hazel
-June 2006
+November 2006
index d6c204b5744da9da6d6b08a2429ce35903937df2..9c7884998c1d3636f6a6109673959ffdd4290e93 100644 (file)
@@ -18,52 +18,57 @@ INTRODUCTION
 
        The  PCRE  library is a set of functions that implement regular expres-
        sion pattern matching using the same syntax and semantics as Perl, with
-       just  a  few  differences.  The current implementation of PCRE (release
-       6.x) corresponds approximately with Perl  5.8,  including  support  for
-       UTF-8 encoded strings and Unicode general category properties. However,
-       this support has to be explicitly enabled; it is not the default.
-
-       In addition to the Perl-compatible matching function,  PCRE  also  con-
-       tains  an  alternative matching function that matches the same compiled
-       patterns in a different way. In certain circumstances, the  alternative
-       function  has  some  advantages.  For  a discussion of the two matching
-       algorithms, see the pcrematching page.
-
-       PCRE is written in C and released as a C library. A  number  of  people
-       have  written  wrappers and interfaces of various kinds. In particular,
-       Google Inc.  have provided a comprehensive C++  wrapper.  This  is  now
+       just  a  few differences. (Certain features that appeared in Python and
+       PCRE before they appeared in Perl are also available using  the  Python
+       syntax.)
+
+       The  current  implementation of PCRE (release 7.x) corresponds approxi-
+       mately with Perl 5.10, including support for UTF-8 encoded strings  and
+       Unicode general category properties. However, UTF-8 and Unicode support
+       has to be explicitly enabled; it is not the default. The Unicode tables
+       correspond to Unicode release 5.0.0.
+
+       In  addition to the Perl-compatible matching function, PCRE contains an
+       alternative matching function that matches the same  compiled  patterns
+       in  a different way. In certain circumstances, the alternative function
+       has some advantages. For a discussion of the two  matching  algorithms,
+       see the pcrematching page.
+
+       PCRE  is  written  in C and released as a C library. A number of people
+       have written wrappers and interfaces of various kinds.  In  particular,
+       Google  Inc.   have  provided  a comprehensive C++ wrapper. This is now
        included as part of the PCRE distribution. The pcrecpp page has details
-       of this interface. Other people's contributions can  be  found  in  the
+       of  this  interface.  Other  people's contributions can be found in the
        Contrib directory at the primary FTP site, which is:
 
        ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre
 
-       Details  of  exactly which Perl regular expression features are and are
+       Details of exactly which Perl regular expression features are  and  are
        not supported by PCRE are given in separate documents. See the pcrepat-
        tern and pcrecompat pages.
 
-       Some  features  of  PCRE can be included, excluded, or changed when the
-       library is built. The pcre_config() function makes it  possible  for  a
-       client  to  discover  which  features are available. The features them-
-       selves are described in the pcrebuild page. Documentation about  build-
-       ing  PCRE for various operating systems can be found in the README file
+       Some features of PCRE can be included, excluded, or  changed  when  the
+       library  is  built.  The pcre_config() function makes it possible for a
+       client to discover which features are  available.  The  features  them-
+       selves  are described in the pcrebuild page. Documentation about build-
+       ing PCRE for various operating systems can be found in the README  file
        in the source distribution.
 
-       The library contains a number of undocumented  internal  functions  and
-       data  tables  that  are  used by more than one of the exported external
-       functions, but which are not intended  for  use  by  external  callers.
-       Their  names  all begin with "_pcre_", which hopefully will not provoke
+       The  library  contains  a number of undocumented internal functions and
+       data tables that are used by more than one  of  the  exported  external
+       functions,  but  which  are  not  intended for use by external callers.
+       Their names all begin with "_pcre_", which hopefully will  not  provoke
        any name clashes. In some environments, it is possible to control which
-       external  symbols  are  exported when a shared library is built, and in
+       external symbols are exported when a shared library is  built,  and  in
        these cases the undocumented symbols are not exported.
 
 
 USER DOCUMENTATION
 
-       The user documentation for PCRE comprises a number  of  different  sec-
-       tions.  In the "man" format, each of these is a separate "man page". In
-       the HTML format, each is a separate page, linked from the  index  page.
-       In  the  plain text format, all the sections are concatenated, for ease
+       The  user  documentation  for PCRE comprises a number of different sec-
+       tions. In the "man" format, each of these is a separate "man page".  In
+       the  HTML  format, each is a separate page, linked from the index page.
+       In the plain text format, all the sections are concatenated,  for  ease
        of searching. The sections are as follows:
 
          pcre              this document
@@ -84,124 +89,122 @@ USER DOCUMENTATION
          pcrestack         discussion of stack usage
          pcretest          description of the pcretest testing command
 
-       In  addition,  in the "man" and HTML formats, there is a short page for
+       In addition, in the "man" and HTML formats, there is a short  page  for
        each C library function, listing its arguments and results.
 
 
 LIMITATIONS
 
-       There are some size limitations in PCRE but it is hoped that they  will
+       There  are some size limitations in PCRE but it is hoped that they will
        never in practice be relevant.
 
-       The  maximum  length of a compiled pattern is 65539 (sic) bytes if PCRE
+       The maximum length of a compiled pattern is 65539 (sic) bytes  if  PCRE
        is compiled with the default internal linkage size of 2. If you want to
-       process  regular  expressions  that are truly enormous, you can compile
-       PCRE with an internal linkage size of 3 or 4 (see the  README  file  in
-       the  source  distribution and the pcrebuild documentation for details).
-       In these cases the limit is substantially larger.  However,  the  speed
-       of execution will be slower.
-
-       All  values in repeating quantifiers must be less than 65536. The maxi-
-       mum compiled length of subpattern with  an  explicit  repeat  count  is
+       process regular expressions that are truly enormous,  you  can  compile
+       PCRE  with  an  internal linkage size of 3 or 4 (see the README file in
+       the source distribution and the pcrebuild documentation  for  details).
+       In  these  cases the limit is substantially larger.  However, the speed
+       of execution is slower.
+
+       All values in repeating quantifiers must be less than 65536. The  maxi-
+       mum  compiled  length  of  subpattern  with an explicit repeat count is
        30000 bytes. The maximum number of capturing subpatterns is 65535.
 
-       There  is  no limit to the number of non-capturing subpatterns, but the
-       maximum depth of nesting of  all  kinds  of  parenthesized  subpattern,
-       including capturing subpatterns, assertions, and other types of subpat-
-       tern, is 200.
+       There is no limit to the number of parenthesized subpatterns, but there
+       can be no more than 65535 capturing subpatterns.
 
-       The maximum length of name for a named subpattern is 32, and the  maxi-
-       mum number of named subpatterns is 10000.
+       The maximum length of name for a named subpattern is 32 characters, and
+       the maximum number of named subpatterns is 10000.
 
-       The  maximum  length of a subject string is the largest positive number
-       that an integer variable can hold. However, when using the  traditional
+       The maximum length of a subject string is the largest  positive  number
+       that  an integer variable can hold. However, when using the traditional
        matching function, PCRE uses recursion to handle subpatterns and indef-
-       inite repetition.  This means that the available stack space may  limit
+       inite  repetition.  This means that the available stack space may limit
        the size of a subject string that can be processed by certain patterns.
        For a discussion of stack issues, see the pcrestack documentation.
 
 
 UTF-8 AND UNICODE PROPERTY SUPPORT
 
-       From release 3.3, PCRE has  had  some  support  for  character  strings
-       encoded  in the UTF-8 format. For release 4.0 this was greatly extended
-       to cover most common requirements, and in release 5.0  additional  sup-
+       From  release  3.3,  PCRE  has  had  some support for character strings
+       encoded in the UTF-8 format. For release 4.0 this was greatly  extended
+       to  cover  most common requirements, and in release 5.0 additional sup-
        port for Unicode general category properties was added.
 
-       In  order  process  UTF-8 strings, you must build PCRE to include UTF-8
-       support in the code, and, in addition,  you  must  call  pcre_compile()
-       with  the PCRE_UTF8 option flag. When you do this, both the pattern and
-       any subject strings that are matched against it are  treated  as  UTF-8
+       In order process UTF-8 strings, you must build PCRE  to  include  UTF-8
+       support  in  the  code,  and, in addition, you must call pcre_compile()
+       with the PCRE_UTF8 option flag. When you do this, both the pattern  and
+       any  subject  strings  that are matched against it are treated as UTF-8
        strings instead of just strings of bytes.
 
-       If  you compile PCRE with UTF-8 support, but do not use it at run time,
-       the library will be a bit bigger, but the additional run time  overhead
-       is  limited  to testing the PCRE_UTF8 flag in several places, so should
-       not be very large.
+       If you compile PCRE with UTF-8 support, but do not use it at run  time,
+       the  library will be a bit bigger, but the additional run time overhead
+       is limited to testing the PCRE_UTF8 flag occasionally, so should not be
+       very big.
 
        If PCRE is built with Unicode character property support (which implies
-       UTF-8  support),  the  escape sequences \p{..}, \P{..}, and \X are sup-
+       UTF-8 support), the escape sequences \p{..}, \P{..}, and  \X  are  sup-
        ported.  The available properties that can be tested are limited to the
-       general  category  properties such as Lu for an upper case letter or Nd
-       for a decimal number, the Unicode script names such as Arabic  or  Han,
-       and  the  derived  properties  Any  and L&. A full list is given in the
+       general category properties such as Lu for an upper case letter  or  Nd
+       for  a  decimal number, the Unicode script names such as Arabic or Han,
+       and the derived properties Any and L&. A full  list  is  given  in  the
        pcrepattern documentation. Only the short names for properties are sup-
-       ported.  For example, \p{L} matches a letter. Its Perl synonym, \p{Let-
-       ter}, is not supported.  Furthermore,  in  Perl,  many  properties  may
-       optionally  be  prefixed by "Is", for compatibility with Perl 5.6. PCRE
+       ported. For example, \p{L} matches a letter. Its Perl synonym,  \p{Let-
+       ter},  is  not  supported.   Furthermore,  in Perl, many properties may
+       optionally be prefixed by "Is", for compatibility with Perl  5.6.  PCRE
        does not support this.
 
        The following comments apply when PCRE is running in UTF-8 mode:
 
-       1. When you set the PCRE_UTF8 flag, the strings passed as patterns  and
-       subjects  are  checked for validity on entry to the relevant functions.
+       1.  When you set the PCRE_UTF8 flag, the strings passed as patterns and
+       subjects are checked for validity on entry to the  relevant  functions.
        If an invalid UTF-8 string is passed, an error return is given. In some
-       situations,  you  may  already  know  that  your strings are valid, and
+       situations, you may already know  that  your  strings  are  valid,  and
        therefore want to skip these checks in order to improve performance. If
-       you  set  the  PCRE_NO_UTF8_CHECK  flag at compile time or at run time,
-       PCRE assumes that the pattern or subject  it  is  given  (respectively)
-       contains  only valid UTF-8 codes. In this case, it does not diagnose an
-       invalid UTF-8 string. If you pass an invalid UTF-8 string to PCRE  when
-       PCRE_NO_UTF8_CHECK  is set, the results are undefined. Your program may
+       you set the PCRE_NO_UTF8_CHECK flag at compile time  or  at  run  time,
+       PCRE  assumes  that  the  pattern or subject it is given (respectively)
+       contains only valid UTF-8 codes. In this case, it does not diagnose  an
+       invalid  UTF-8 string. If you pass an invalid UTF-8 string to PCRE when
+       PCRE_NO_UTF8_CHECK is set, the results are undefined. Your program  may
        crash.
 
-       2. An unbraced hexadecimal escape sequence (such  as  \xb3)  matches  a
+       2.  An  unbraced  hexadecimal  escape sequence (such as \xb3) matches a
        two-byte UTF-8 character if the value is greater than 127.
 
-       3.  Octal  numbers  up to \777 are recognized, and match two-byte UTF-8
+       3. Octal numbers up to \777 are recognized, and  match  two-byte  UTF-8
        characters for values greater than \177.
 
-       4. Repeat quantifiers apply to complete UTF-8 characters, not to  indi-
+       4.  Repeat quantifiers apply to complete UTF-8 characters, not to indi-
        vidual bytes, for example: \x{100}{3}.
 
-       5.  The dot metacharacter matches one UTF-8 character instead of a sin-
+       5. The dot metacharacter matches one UTF-8 character instead of a  sin-
        gle byte.
 
-       6. The escape sequence \C can be used to match a single byte  in  UTF-8
-       mode,  but  its  use can lead to some strange effects. This facility is
+       6.  The  escape sequence \C can be used to match a single byte in UTF-8
+       mode, but its use can lead to some strange effects.  This  facility  is
        not available in the alternative matching function, pcre_dfa_exec().
 
-       7. The character escapes \b, \B, \d, \D, \s, \S, \w, and  \W  correctly
-       test  characters of any code value, but the characters that PCRE recog-
-       nizes as digits, spaces, or word characters  remain  the  same  set  as
+       7.  The  character escapes \b, \B, \d, \D, \s, \S, \w, and \W correctly
+       test characters of any code value, but the characters that PCRE  recog-
+       nizes  as  digits,  spaces,  or  word characters remain the same set as
        before, all with values less than 256. This remains true even when PCRE
-       includes Unicode property support, because to do otherwise  would  slow
-       down  PCRE in many common cases. If you really want to test for a wider
-       sense of, say, "digit", you must use Unicode  property  tests  such  as
+       includes  Unicode  property support, because to do otherwise would slow
+       down PCRE in many common cases. If you really want to test for a  wider
+       sense  of,  say,  "digit",  you must use Unicode property tests such as
        \p{Nd}.
 
-       8.  Similarly,  characters that match the POSIX named character classes
+       8. Similarly, characters that match the POSIX named  character  classes
        are all low-valued characters.
 
-       9. Case-insensitive matching applies only to  characters  whose  values
-       are  less than 128, unless PCRE is built with Unicode property support.
-       Even when Unicode property support is available, PCRE  still  uses  its
-       own  character  tables when checking the case of low-valued characters,
-       so as not to degrade performance.  The Unicode property information  is
+       9.  Case-insensitive  matching  applies only to characters whose values
+       are less than 128, unless PCRE is built with Unicode property  support.
+       Even  when  Unicode  property support is available, PCRE still uses its
+       own character tables when checking the case of  low-valued  characters,
+       so  as not to degrade performance.  The Unicode property information is
        used only for characters with higher values. Even when Unicode property
        support is available, PCRE supports case-insensitive matching only when
-       there  is  a  one-to-one  mapping between a letter's cases. There are a
-       small number of many-to-one mappings in Unicode;  these  are  not  sup-
+       there is a one-to-one mapping between a letter's  cases.  There  are  a
+       small  number  of  many-to-one  mappings in Unicode; these are not sup-
        ported by PCRE.
 
 
@@ -209,13 +212,13 @@ AUTHOR
 
        Philip Hazel
        University Computing Service,
-       Cambridge CB2 3QG, England.
+       Cambridge CB2 3QH, England.
 
-       Putting  an actual email address here seems to have been a spam magnet,
+       Putting an actual email address here seems to have been a spam  magnet,
        so I've taken it away. If you want to email me, use my initial and sur-
        name, separated by a dot, at the domain ucs.cam.ac.uk.
 
-Last updated: 05 June 2006
+Last updated: 23 November 2006
 Copyright (c) 1997-2006 University of Cambridge.
 ------------------------------------------------------------------------------
 
@@ -305,16 +308,21 @@ CODE VALUE OF NEWLINE
 
          --enable-newline-is-crlf
 
-       to  the  configure command. Whatever line ending convention is selected
-       when PCRE is built can be overridden when  the  library  functions  are
-       called.  At  build time it is conventional to use the standard for your
-       operating system.
+       to the configure command. There is a fourth option, specified by
+
+         --enable-newline-is-any
+
+       which causes PCRE to recognize any Unicode newline sequence.
+
+       Whatever  line  ending convention is selected when PCRE is built can be
+       overridden when the library functions are called. At build time  it  is
+       conventional to use the standard for your operating system.
 
 
 BUILDING SHARED AND STATIC LIBRARIES
 
-       The PCRE building process uses libtool to build both shared and  static
-       Unix  libraries by default. You can suppress one of these by adding one
+       The  PCRE building process uses libtool to build both shared and static
+       Unix libraries by default. You can suppress one of these by adding  one
        of
 
          --disable-shared
@@ -326,9 +334,9 @@ BUILDING SHARED AND STATIC LIBRARIES
 POSIX MALLOC USAGE
 
        When PCRE is called through the POSIX interface (see the pcreposix doc-
-       umentation),  additional  working  storage  is required for holding the
-       pointers to capturing substrings, because PCRE requires three  integers
-       per  substring,  whereas  the POSIX interface provides only two. If the
+       umentation), additional working storage is  required  for  holding  the
+       pointers  to capturing substrings, because PCRE requires three integers
+       per substring, whereas the POSIX interface provides only  two.  If  the
        number of expected substrings is small, the wrapper function uses space
        on the stack, because this is faster than using malloc() for each call.
        The default threshold above which the stack is no longer used is 10; it
@@ -341,95 +349,100 @@ POSIX MALLOC USAGE
 
 HANDLING VERY LARGE PATTERNS
 
-       Within  a  compiled  pattern,  offset values are used to point from one
-       part to another (for example, from an opening parenthesis to an  alter-
-       nation  metacharacter).  By default, two-byte values are used for these
-       offsets, leading to a maximum size for a  compiled  pattern  of  around
-       64K.  This  is sufficient to handle all but the most gigantic patterns.
-       Nevertheless, some people do want to process enormous patterns,  so  it
-       is  possible  to compile PCRE to use three-byte or four-byte offsets by
+       Within a compiled pattern, offset values are used  to  point  from  one
+       part  to another (for example, from an opening parenthesis to an alter-
+       nation metacharacter). By default, two-byte values are used  for  these
+       offsets,  leading  to  a  maximum size for a compiled pattern of around
+       64K. This is sufficient to handle all but the most  gigantic  patterns.
+       Nevertheless,  some  people do want to process enormous patterns, so it
+       is possible to compile PCRE to use three-byte or four-byte  offsets  by
        adding a setting such as
 
          --with-link-size=3
 
-       to the configure command. The value given must be 2,  3,  or  4.  Using
-       longer  offsets slows down the operation of PCRE because it has to load
+       to  the  configure  command.  The value given must be 2, 3, or 4. Using
+       longer offsets slows down the operation of PCRE because it has to  load
        additional bytes when handling them.
 
-       If you build PCRE with an increased link size, test 2 (and  test  5  if
-       you  are using UTF-8) will fail. Part of the output of these tests is a
-       representation of the compiled pattern, and this changes with the  link
+       If  you  build  PCRE with an increased link size, test 2 (and test 5 if
+       you are using UTF-8) will fail. Part of the output of these tests is  a
+       representation  of the compiled pattern, and this changes with the link
        size.
 
 
 AVOIDING EXCESSIVE STACK USAGE
 
        When matching with the pcre_exec() function, PCRE implements backtrack-
-       ing by making recursive calls to an internal function  called  match().
-       In  environments  where  the size of the stack is limited, this can se-
-       verely limit PCRE's operation. (The Unix environment does  not  usually
+       ing  by  making recursive calls to an internal function called match().
+       In environments where the size of the stack is limited,  this  can  se-
+       verely  limit  PCRE's operation. (The Unix environment does not usually
        suffer from this problem, but it may sometimes be necessary to increase
-       the maximum stack size.  There is a discussion in the  pcrestack  docu-
-       mentation.)  An alternative approach to recursion that uses memory from
-       the heap to remember data, instead of using recursive  function  calls,
-       has  been  implemented to work round the problem of limited stack size.
+       the  maximum  stack size.  There is a discussion in the pcrestack docu-
+       mentation.) An alternative approach to recursion that uses memory  from
+       the  heap  to remember data, instead of using recursive function calls,
+       has been implemented to work round the problem of limited  stack  size.
        If you want to build a version of PCRE that works this way, add
 
          --disable-stack-for-recursion
 
-       to the configure command. With this configuration, PCRE  will  use  the
-       pcre_stack_malloc  and pcre_stack_free variables to call memory manage-
-       ment functions. Separate functions are provided because  the  usage  is
-       very  predictable:  the  block sizes requested are always the same, and
-       the blocks are always freed in reverse order. A calling  program  might
-       be  able  to implement optimized functions that perform better than the
-       standard malloc() and  free()  functions.  PCRE  runs  noticeably  more
+       to  the  configure  command. With this configuration, PCRE will use the
+       pcre_stack_malloc and pcre_stack_free variables to call memory  manage-
+       ment  functions.  Separate  functions are provided because the usage is
+       very predictable: the block sizes requested are always  the  same,  and
+       the  blocks  are always freed in reverse order. A calling program might
+       be able to implement optimized functions that perform better  than  the
+       standard  malloc()  and  free()  functions.  PCRE  runs noticeably more
        slowly when built in this way. This option affects only the pcre_exec()
        function; it is not relevant for the the pcre_dfa_exec() function.
 
 
 LIMITING PCRE RESOURCE USAGE
 
-       Internally, PCRE has a function called match(), which it calls  repeat-
-       edly   (sometimes   recursively)  when  matching  a  pattern  with  the
-       pcre_exec() function. By controlling the maximum number of  times  this
-       function  may be called during a single matching operation, a limit can
-       be placed on the resources used by a single call  to  pcre_exec().  The
-       limit  can be changed at run time, as described in the pcreapi documen-
-       tation. The default is 10 million, but this can be changed by adding  a
+       Internally,  PCRE has a function called match(), which it calls repeat-
+       edly  (sometimes  recursively)  when  matching  a  pattern   with   the
+       pcre_exec()  function.  By controlling the maximum number of times this
+       function may be called during a single matching operation, a limit  can
+       be  placed  on  the resources used by a single call to pcre_exec(). The
+       limit can be changed at run time, as described in the pcreapi  documen-
+       tation.  The default is 10 million, but this can be changed by adding a
        setting such as
 
          --with-match-limit=500000
 
-       to   the   configure  command.  This  setting  has  no  effect  on  the
+       to  the  configure  command.  This  setting  has  no  effect   on   the
        pcre_dfa_exec() matching function.
 
-       In some environments it is desirable to limit the  depth  of  recursive
+       In  some  environments  it is desirable to limit the depth of recursive
        calls of match() more strictly than the total number of calls, in order
-       to restrict the maximum amount of stack (or heap,  if  --disable-stack-
+       to  restrict  the maximum amount of stack (or heap, if --disable-stack-
        for-recursion is specified) that is used. A second limit controls this;
-       it defaults to the value that  is  set  for  --with-match-limit,  which
-       imposes  no  additional constraints. However, you can set a lower limit
+       it  defaults  to  the  value  that is set for --with-match-limit, which
+       imposes no additional constraints. However, you can set a  lower  limit
        by adding, for example,
 
          --with-match-limit-recursion=10000
 
-       to the configure command. This value can  also  be  overridden  at  run
+       to  the  configure  command.  This  value can also be overridden at run
        time.
 
 
 USING EBCDIC CODE
 
-       PCRE  assumes  by  default that it will run in an environment where the
-       character code is ASCII (or Unicode, which is  a  superset  of  ASCII).
-       PCRE  can,  however,  be  compiled  to  run in an EBCDIC environment by
+       PCRE assumes by default that it will run in an  environment  where  the
+       character  code  is  ASCII  (or Unicode, which is a superset of ASCII).
+       PCRE can, however, be compiled to  run  in  an  EBCDIC  environment  by
        adding
 
          --enable-ebcdic
 
        to the configure command.
 
-Last updated: 06 June 2006
+
+SEE ALSO
+
+       pcreapi(3), pcre_config(3).
+
+Last updated: 30 November 2006
 Copyright (c) 1997-2006 University of Cambridge.
 ------------------------------------------------------------------------------
 
@@ -466,7 +479,7 @@ PCRE MATCHING ALGORITHMS
          <something> <something else> <something further>
 
        there are three possible answers. The standard algorithm finds only one
-       of them, whereas the DFA algorithm finds all three.
+       of them, whereas the alternative algorithm finds all three.
 
 
 REGULAR EXPRESSIONS AS TREES
@@ -507,21 +520,22 @@ THE STANDARD MATCHING ALGORITHM
        This provides support for capturing parentheses and back references.
 
 
-THE DFA MATCHING ALGORITHM
+THE ALTERNATIVE MATCHING ALGORITHM
 
-       DFA stands for "deterministic finite automaton", but you do not need to
-       understand the origins of that name. This algorithm conducts a breadth-
-       first search of the tree. Starting from the first matching point in the
-       subject,  it scans the subject string from left to right, once, charac-
-       ter by character, and as it does  this,  it  remembers  all  the  paths
-       through the tree that represent valid matches.
+       This algorithm conducts a breadth-first search of  the  tree.  Starting
+       from  the  first  matching  point  in the subject, it scans the subject
+       string from left to right, once, character by character, and as it does
+       this,  it remembers all the paths through the tree that represent valid
+       matches. In Friedl's terminology, this is a kind  of  "DFA  algorithm",
+       though  it is not implemented as a traditional finite state machine (it
+       keeps multiple states active simultaneously).
 
-       The  scan  continues until either the end of the subject is reached, or
-       there are no more unterminated paths. At this point,  terminated  paths
-       represent  the different matching possibilities (if there are none, the
-       match has failed).  Thus, if there is more  than  one  possible  match,
+       The scan continues until either the end of the subject is  reached,  or
+       there  are  no more unterminated paths. At this point, terminated paths
+       represent the different matching possibilities (if there are none,  the
+       match  has  failed).   Thus,  if there is more than one possible match,
        this algorithm finds all of them, and in particular, it finds the long-
-       est. In PCRE, there is an option to stop the algorithm after the  first
+       est.  In PCRE, there is an option to stop the algorithm after the first
        match (which is necessarily the shortest) has been found.
 
        Note that all the matches that are found start at the same point in the
@@ -529,75 +543,86 @@ THE DFA MATCHING ALGORITHM
 
          cat(er(pillar)?)
 
-       is matched against the string "the caterpillar catchment",  the  result
-       will  be the three strings "cat", "cater", and "caterpillar" that start
+       is  matched  against the string "the caterpillar catchment", the result
+       will be the three strings "cat", "cater", and "caterpillar" that  start
        at the fourth character of the subject. The algorithm does not automat-
        ically move on to find matches that start at later positions.
 
        There are a number of features of PCRE regular expressions that are not
-       supported by the DFA matching algorithm. They are as follows:
+       supported by the alternative matching algorithm. They are as follows:
+
+       1.  Because  the  algorithm  finds  all possible matches, the greedy or
+       ungreedy nature of repetition quantifiers is not relevant.  Greedy  and
+       ungreedy quantifiers are treated in exactly the same way. However, pos-
+       sessive quantifiers can make a difference when what follows could  also
+       match what is quantified, for example in a pattern like this:
 
-       1. Because the algorithm finds all  possible  matches,  the  greedy  or
-       ungreedy  nature  of repetition quantifiers is not relevant. Greedy and
-       ungreedy quantifiers are treated in exactly the same way.
+         ^a++\w!
+
+       This  pattern matches "aaab!" but not "aaa!", which would be matched by
+       a non-possessive quantifier. Similarly, if an atomic group is  present,
+       it  is matched as if it were a standalone pattern at the current point,
+       and the longest match is then "locked in" for the rest of  the  overall
+       pattern.
 
        2. When dealing with multiple paths through the tree simultaneously, it
-       is  not  straightforward  to  keep track of captured substrings for the
-       different matching possibilities, and  PCRE's  implementation  of  this
+       is not straightforward to keep track of  captured  substrings  for  the
+       different  matching  possibilities,  and  PCRE's implementation of this
        algorithm does not attempt to do this. This means that no captured sub-
        strings are available.
 
-       3. Because no substrings are captured, back references within the  pat-
+       3.  Because no substrings are captured, back references within the pat-
        tern are not supported, and cause errors if encountered.
 
-       4.  For  the same reason, conditional expressions that use a backrefer-
-       ence as the condition are not supported.
+       4. For the same reason, conditional expressions that use  a  backrefer-
+       ence  as  the  condition or test for a specific group recursion are not
+       supported.
 
        5. Callouts are supported, but the value of the  capture_top  field  is
        always 1, and the value of the capture_last field is always -1.
 
        6.  The \C escape sequence, which (in the standard algorithm) matches a
-       single byte, even in UTF-8 mode, is not supported because the DFA algo-
-       rithm moves through the subject string one character at a time, for all
-       active paths through the tree.
+       single byte, even in UTF-8 mode, is not supported because the  alterna-
+       tive  algorithm  moves  through  the  subject string one character at a
+       time, for all active paths through the tree.
 
 
-ADVANTAGES OF THE DFA ALGORITHM
+ADVANTAGES OF THE ALTERNATIVE ALGORITHM
 
-       Using the DFA matching algorithm provides the following advantages:
+       Using the alternative matching algorithm provides the following  advan-
+       tages:
 
        1. All possible matches (at a single point in the subject) are automat-
-       ically  found,  and  in particular, the longest match is found. To find
+       ically found, and in particular, the longest match is  found.  To  find
        more than one match using the standard algorithm, you have to do kludgy
        things with callouts.
 
-       2.  There is much better support for partial matching. The restrictions
-       on the content of the pattern that apply when using the standard  algo-
-       rithm  for partial matching do not apply to the DFA algorithm. For non-
-       anchored patterns, the starting position of a partial match  is  avail-
-       able.
+       2. There is much better support for partial matching. The  restrictions
+       on  the content of the pattern that apply when using the standard algo-
+       rithm for partial matching do not apply to the  alternative  algorithm.
+       For  non-anchored patterns, the starting position of a partial match is
+       available.
 
-       3.  Because  the  DFA algorithm scans the subject string just once, and
-       never needs to backtrack, it is possible  to  pass  very  long  subject
-       strings  to  the matching function in several pieces, checking for par-
-       tial matching each time.
+       3. Because the alternative algorithm  scans  the  subject  string  just
+       once,  and  never  needs to backtrack, it is possible to pass very long
+       subject strings to the matching function in  several  pieces,  checking
+       for partial matching each time.
 
 
-DISADVANTAGES OF THE DFA ALGORITHM
+DISADVANTAGES OF THE ALTERNATIVE ALGORITHM
 
-       The DFA algorithm suffers from a number of disadvantages:
+       The alternative algorithm suffers from a number of disadvantages:
 
-       1. It is substantially slower than  the  standard  algorithm.  This  is
-       partly  because  it has to search for all possible matches, but is also
+       1.  It  is  substantially  slower  than the standard algorithm. This is
+       partly because it has to search for all possible matches, but  is  also
        because it is less susceptible to optimization.
 
        2. Capturing parentheses and back references are not supported.
 
-       3. The "atomic group" feature of PCRE regular expressions is supported,
-       but  does not provide the advantage that it does for the standard algo-
-       rithm.
+       3. Although atomic groups are supported, their use does not provide the
+       performance advantage that it does for the standard algorithm.
 
-Last updated: 06 June 2006
+Last updated: 24 November 2006
 Copyright (c) 1997-2006 University of Cambridge.
 ------------------------------------------------------------------------------
 
@@ -692,7 +717,7 @@ PCRE NATIVE API
 PCRE API OVERVIEW
 
        PCRE has its own native API, which is described in this document. There
-       is also a set of wrapper functions that correspond to the POSIX regular
+       are also some wrapper functions that correspond to  the  POSIX  regular
        expression  API.  These  are  described in the pcreposix documentation.
        Both of these APIs define a set of C function calls. A C++  wrapper  is
        distributed with PCRE. It is documented in the pcrecpp page.
@@ -715,10 +740,10 @@ PCRE API OVERVIEW
        A second matching function, pcre_dfa_exec(), which is not Perl-compati-
        ble,  is  also provided. This uses a different algorithm for the match-
        ing. The alternative algorithm finds all possible matches (at  a  given
-       point in the subject). However, this algorithm does not return captured
-       substrings. A description of the  two  matching  algorithms  and  their
-       advantages  and  disadvantages  is given in the pcrematching documenta-
-       tion.
+       point  in  the subject), and scans the subject just once. However, this
+       algorithm does not return captured substrings. A description of the two
+       matching  algorithms and their advantages and disadvantages is given in
+       the pcrematching documentation.
 
        In addition to the main compiling and  matching  functions,  there  are
        convenience functions for extracting captured substrings from a subject
@@ -779,26 +804,38 @@ PCRE API OVERVIEW
 
 
 NEWLINES
-       PCRE supports three different conventions for indicating line breaks in
-       strings: a single CR character, a single LF character, or the two-char-
-       acter  sequence  CRLF.  All  three  are used as "standard" by different
-       operating systems.  When PCRE is built, a default can be specified. The
-       default  default  is  LF, which is the Unix standard. When PCRE is run,
-       the default can be overridden, either when a pattern  is  compiled,  or
-       when it is matched.
+
+       PCRE  supports four different conventions for indicating line breaks in
+       strings: a single CR (carriage return) character, a  single  LF  (line-
+       feed)  character,  the two-character sequence CRLF, or any Unicode new-
+       line sequence.  The Unicode newline sequences are the three  just  men-
+       tioned, plus the single characters VT (vertical tab, U+000B), FF (form-
+       feed, U+000C), NEL (next line, U+0085), LS  (line  separator,  U+2028),
+       and PS (paragraph separator, U+2029).
+
+       Each  of  the first three conventions is used by at least one operating
+       system as its standard newline sequence. When PCRE is built, a  default
+       can  be  specified.  The default default is LF, which is the Unix stan-
+       dard. When PCRE is run, the default can be overridden,  either  when  a
+       pattern is compiled, or when it is matched.
 
        In the PCRE documentation the word "newline" is used to mean "the char-
-       acter or pair of characters that indicate a line break".
+       acter or pair of characters that indicate a line break". The choice  of
+       newline  convention  affects  the  handling of the dot, circumflex, and
+       dollar metacharacters, the handling of #-comments in /x mode, and, when
+       CRLF  is a recognized line ending sequence, the match position advance-
+       ment for a non-anchored pattern. The choice of newline convention  does
+       not affect the interpretation of the \n or \r escape sequences.
 
 
 MULTITHREADING
 
-       The PCRE functions can be used in  multi-threading  applications,  with
+       The  PCRE  functions  can be used in multi-threading applications, with
        the  proviso  that  the  memory  management  functions  pointed  to  by
        pcre_malloc, pcre_free, pcre_stack_malloc, and pcre_stack_free, and the
        callout function pointed to by pcre_callout, are shared by all threads.
 
-       The compiled form of a regular expression is not altered during  match-
+       The  compiled form of a regular expression is not altered during match-
        ing, so the same compiled pattern can safely be used by several threads
        at once.
 
@@ -806,8 +843,8 @@ MULTITHREADING
 SAVING PRECOMPILED PATTERNS FOR LATER USE
 
        The compiled form of a regular expression can be saved and re-used at a
-       later  time,  possibly by a different program, and even on a host other
-       than the one on which  it  was  compiled.  Details  are  given  in  the
+       later time, possibly by a different program, and even on a  host  other
+       than  the  one  on  which  it  was  compiled.  Details are given in the
        pcreprecompile documentation.
 
 
@@ -815,32 +852,33 @@ CHECKING BUILD-TIME OPTIONS
 
        int pcre_config(int what, void *where);
 
-       The  function pcre_config() makes it possible for a PCRE client to dis-
+       The function pcre_config() makes it possible for a PCRE client to  dis-
        cover which optional features have been compiled into the PCRE library.
-       The  pcrebuild documentation has more details about these optional fea-
+       The pcrebuild documentation has more details about these optional  fea-
        tures.
 
-       The first argument for pcre_config() is an  integer,  specifying  which
+       The  first  argument  for pcre_config() is an integer, specifying which
        information is required; the second argument is a pointer to a variable
-       into which the information is  placed.  The  following  information  is
+       into  which  the  information  is  placed. The following information is
        available:
 
          PCRE_CONFIG_UTF8
 
-       The  output is an integer that is set to one if UTF-8 support is avail-
+       The output is an integer that is set to one if UTF-8 support is  avail-
        able; otherwise it is set to zero.
 
          PCRE_CONFIG_UNICODE_PROPERTIES
 
-       The output is an integer that is set to  one  if  support  for  Unicode
+       The  output  is  an  integer  that is set to one if support for Unicode
        character properties is available; otherwise it is set to zero.
 
          PCRE_CONFIG_NEWLINE
 
-       The  output  is  an integer whose value specifies the default character
-       sequence that is recognized as meaning "newline". The three values that
-       are supported are: 10 for LF, 13 for CR, and 3338 for CRLF. The default
-       should normally be the standard sequence for your operating system.
+       The output is an integer whose value specifies  the  default  character
+       sequence  that is recognized as meaning "newline". The four values that
+       are supported are: 10 for LF, 13 for CR, 3338 for CRLF, and -1 for ANY.
+       The default should normally be the standard sequence for your operating
+       system.
 
          PCRE_CONFIG_LINK_SIZE
 
@@ -909,8 +947,8 @@ COMPILING A PATTERN
        fully relocatable, because it may contain a copy of the tableptr  argu-
        ment, which is an address (see below).
 
-       The options argument contains independent bits that affect the compila-
-       tion. It should be zero if  no  options  are  required.  The  available
+       The options argument contains various bit settings that affect the com-
+       pilation. It should be zero if no options are required.  The  available
        options  are  described  below. Some of them, in particular, those that
        are compatible with Perl, can also be set and  unset  from  within  the
        pattern  (see  the  detailed  description in the pcrepattern documenta-
@@ -1000,7 +1038,7 @@ COMPILING A PATTERN
        not  match  when  the  current position is at a newline. This option is
        equivalent to Perl's /s option, and it can be changed within a  pattern
        by  a (?s) option setting. A negative class such as [^a] always matches
-       newlines, independent of the setting of this option.
+       newline characters, independent of the setting of this option.
 
          PCRE_DUPNAMES
 
@@ -1064,19 +1102,37 @@ COMPILING A PATTERN
          PCRE_NEWLINE_CR
          PCRE_NEWLINE_LF
          PCRE_NEWLINE_CRLF
+         PCRE_NEWLINE_ANY
 
        These  options  override the default newline definition that was chosen
        when PCRE was built. Setting the first or the second specifies  that  a
        newline  is  indicated  by a single character (CR or LF, respectively).
-       Setting both of them specifies that a newline is indicated by the  two-
-       character  CRLF sequence. For convenience, PCRE_NEWLINE_CRLF is defined
-       to contain both bits. The only time that a line break is relevant  when
-       compiling a pattern is if PCRE_EXTENDED is set, and an unescaped # out-
-       side a character class is encountered. This indicates  a  comment  that
-       lasts until after the next newline.
-
-       The newline option set at compile time becomes the default that is used
-       for pcre_exec() and pcre_dfa_exec(), but it can be overridden.
+       Setting PCRE_NEWLINE_CRLF specifies that a newline is indicated by  the
+       two-character  CRLF  sequence.  Setting PCRE_NEWLINE_ANY specifies that
+       any Unicode newline sequence should be recognized. The Unicode  newline
+       sequences  are  the three just mentioned, plus the single characters VT
+       (vertical tab, U+000B), FF (formfeed, U+000C), NEL (next line, U+0085),
+       LS  (line separator, U+2028), and PS (paragraph separator, U+2029). The
+       last two are recognized only in UTF-8 mode.
+
+       The newline setting in the  options  word  uses  three  bits  that  are
+       treated  as  a  number, giving eight possibilities. Currently only five
+       are used (default plus the four values above). This means that  if  you
+       set  more  than  one  newline option, the combination may or may not be
+       sensible. For example, PCRE_NEWLINE_CR with PCRE_NEWLINE_LF is  equiva-
+       lent  to PCRE_NEWLINE_CRLF, but other combinations yield unused numbers
+       and cause an error.
+
+       The only time that a line break is specially recognized when  compiling
+       a  pattern  is  if  PCRE_EXTENDED  is set, and an unescaped # outside a
+       character class is encountered. This indicates  a  comment  that  lasts
+       until  after the next line break sequence. In other circumstances, line
+       break  sequences  are  treated  as  literal  data,   except   that   in
+       PCRE_EXTENDED mode, both CR and LF are treated as whitespace characters
+       and are therefore ignored.
+
+       The newline option that is set at compile time becomes the default that
+       is  used for pcre_exec() and pcre_dfa_exec(), but it can be overridden.
 
          PCRE_NO_AUTO_CAPTURE
 
@@ -1119,7 +1175,8 @@ COMPILATION ERROR CODES
 
        The following table lists the error  codes  than  may  be  returned  by
        pcre_compile2(),  along with the error messages that may be returned by
-       both compiling functions.
+       both compiling functions. As PCRE has developed, some error codes  have
+       fallen out of use. To avoid confusion, they have not been re-used.
 
           0  no error
           1  \ at end of pattern
@@ -1131,7 +1188,7 @@ COMPILATION ERROR CODES
           7  invalid escape sequence in character class
           8  range out of order in character class
           9  nothing to repeat
-         10  operand of unlimited repeat could match the empty string
+         10  [this code is not in use]
          11  internal error: unexpected repeat
          12  unrecognized character after (?
          13  POSIX named classes are supported only within a class
@@ -1140,7 +1197,7 @@ COMPILATION ERROR CODES
          16  erroffset passed as NULL
          17  unknown option bit(s) set
          18  missing ) after comment
-         19  parentheses nested too deeply
+         19  [this code is not in use]
          20  regular expression too large
          21  failed to get memory
          22  unmatched parentheses
@@ -1154,7 +1211,7 @@ COMPILATION ERROR CODES
          30  unknown POSIX class name
          31  POSIX collating elements are not supported
          32  this version of PCRE is not compiled with PCRE_UTF8 support
-         33  spare error
+         33  [this code is not in use]
          34  character value in \x{...} sequence is too large
          35  invalid condition (?(0)
          36  \C not allowed in lookbehind assertion
@@ -1163,7 +1220,7 @@ COMPILATION ERROR CODES
          39  closing ) for (?C expected
          40  recursive call could loop indefinitely
          41  unrecognized character after (?P
-         42  syntax error after (?P
+         42  syntax error in subpattern name (missing terminator)
          43  two named subpatterns have the same name
          44  invalid UTF-8 string
          45  support for \P, \p, and \X has not been compiled
@@ -1173,6 +1230,12 @@ COMPILATION ERROR CODES
          49  too many named subpatterns (maximum 10,000)
          50  repeated subpattern is too long
          51  octal value is greater than \377 (not in UTF-8 mode)
+         52  internal error: overran compiling workspace
+         53   internal  error:  previously-checked  referenced  subpattern not
+       found
+         54  DEFINE group contains more than one branch
+         55  repeating a DEFINE group is not allowed
+         56  inconsistent NEWLINE options"
 
 
 STUDYING A PATTERN
@@ -1331,7 +1394,7 @@ INFORMATION ABOUT A PATTERN
        is still recognized for backwards compatibility.)
 
        If there is a fixed first byte, for example, from  a  pattern  such  as
-       (cat|cow|coyote). Otherwise, if either
+       (cat|cow|coyote), its value is returned. Otherwise, if either
 
        (a)  the pattern was compiled with the PCRE_MULTILINE option, and every
        branch starts with "^", or
@@ -1388,8 +1451,8 @@ INFORMATION ABOUT A PATTERN
        PCRE_EXTENDED  is  set,  so  white  space  -  including  newlines  - is
        ignored):
 
-         (?P<date> (?P<year>(\d\d)?\d\d) -
-         (?P<month>\d\d) - (?P<day>\d\d) )
+         (?<date> (?<year>(\d\d)?\d\d) -
+         (?<month>\d\d) - (?<day>\d\d) )
 
        There are four named subpatterns, so the table has  four  entries,  and
        each  entry  in the table is eight bytes long. The table is as follows,
@@ -1616,191 +1679,197 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION
          PCRE_NEWLINE_CR
          PCRE_NEWLINE_LF
          PCRE_NEWLINE_CRLF
+         PCRE_NEWLINE_ANY
 
        These options override  the  newline  definition  that  was  chosen  or
        defaulted  when the pattern was compiled. For details, see the descrip-
-       tion pcre_compile() above. During matching, the newline choice  affects
-       the behaviour of the dot, circumflex, and dollar metacharacters.
+       tion of pcre_compile()  above.  During  matching,  the  newline  choice
+       affects  the  behaviour  of the dot, circumflex, and dollar metacharac-
+       ters. It may also alter the way the match position is advanced after  a
+       match  failure  for  an  unanchored  pattern. When PCRE_NEWLINE_CRLF or
+       PCRE_NEWLINE_ANY is set, and a match attempt  fails  when  the  current
+       position  is  at a CRLF sequence, the match position is advanced by two
+       characters instead of one, in other words, to after the CRLF.
 
          PCRE_NOTBOL
 
        This option specifies that first character of the subject string is not
-       the beginning of a line, so the  circumflex  metacharacter  should  not
-       match  before it. Setting this without PCRE_MULTILINE (at compile time)
-       causes circumflex never to match. This option affects only  the  behav-
+       the  beginning  of  a  line, so the circumflex metacharacter should not
+       match before it. Setting this without PCRE_MULTILINE (at compile  time)
+       causes  circumflex  never to match. This option affects only the behav-
        iour of the circumflex metacharacter. It does not affect \A.
 
          PCRE_NOTEOL
 
        This option specifies that the end of the subject string is not the end
-       of a line, so the dollar metacharacter should not match it nor  (except
-       in  multiline mode) a newline immediately before it. Setting this with-
+       of  a line, so the dollar metacharacter should not match it nor (except
+       in multiline mode) a newline immediately before it. Setting this  with-
        out PCRE_MULTILINE (at compile time) causes dollar never to match. This
-       option  affects only the behaviour of the dollar metacharacter. It does
+       option affects only the behaviour of the dollar metacharacter. It  does
        not affect \Z or \z.
 
          PCRE_NOTEMPTY
 
        An empty string is not considered to be a valid match if this option is
-       set.  If  there are alternatives in the pattern, they are tried. If all
-       the alternatives match the empty string, the entire  match  fails.  For
+       set. If there are alternatives in the pattern, they are tried.  If  all
+       the  alternatives  match  the empty string, the entire match fails. For
        example, if the pattern
 
          a?b?
 
-       is  applied  to  a string not beginning with "a" or "b", it matches the
-       empty string at the start of the subject. With PCRE_NOTEMPTY set,  this
+       is applied to a string not beginning with "a" or "b",  it  matches  the
+       empty  string at the start of the subject. With PCRE_NOTEMPTY set, this
        match is not valid, so PCRE searches further into the string for occur-
        rences of "a" or "b".
 
        Perl has no direct equivalent of PCRE_NOTEMPTY, but it does make a spe-
-       cial  case  of  a  pattern match of the empty string within its split()
-       function, and when using the /g modifier. It  is  possible  to  emulate
+       cial case of a pattern match of the empty  string  within  its  split()
+       function,  and  when  using  the /g modifier. It is possible to emulate
        Perl's behaviour after matching a null string by first trying the match
        again at the same offset with PCRE_NOTEMPTY and PCRE_ANCHORED, and then
-       if  that  fails by advancing the starting offset (see below) and trying
+       if that fails by advancing the starting offset (see below)  and  trying
        an ordinary match again. There is some code that demonstrates how to do
        this in the pcredemo.c sample program.
 
          PCRE_NO_UTF8_CHECK
 
        When PCRE_UTF8 is set at compile time, the validity of the subject as a
-       UTF-8 string is automatically checked when pcre_exec() is  subsequently
-       called.   The  value  of  startoffset is also checked to ensure that it
-       points to the start of a UTF-8 character. If an invalid UTF-8  sequence
+       UTF-8  string is automatically checked when pcre_exec() is subsequently
+       called.  The value of startoffset is also checked  to  ensure  that  it
+       points  to the start of a UTF-8 character. If an invalid UTF-8 sequence
        of bytes is found, pcre_exec() returns the error PCRE_ERROR_BADUTF8. If
-       startoffset contains an  invalid  value,  PCRE_ERROR_BADUTF8_OFFSET  is
+       startoffset  contains  an  invalid  value, PCRE_ERROR_BADUTF8_OFFSET is
        returned.
 
-       If  you  already  know that your subject is valid, and you want to skip
-       these   checks   for   performance   reasons,   you   can    set    the
-       PCRE_NO_UTF8_CHECK  option  when calling pcre_exec(). You might want to
-       do this for the second and subsequent calls to pcre_exec() if  you  are
-       making  repeated  calls  to  find  all  the matches in a single subject
-       string. However, you should be  sure  that  the  value  of  startoffset
-       points  to  the  start of a UTF-8 character. When PCRE_NO_UTF8_CHECK is
-       set, the effect of passing an invalid UTF-8 string as a subject,  or  a
-       value  of startoffset that does not point to the start of a UTF-8 char-
+       If you already know that your subject is valid, and you  want  to  skip
+       these    checks    for   performance   reasons,   you   can   set   the
+       PCRE_NO_UTF8_CHECK option when calling pcre_exec(). You might  want  to
+       do  this  for the second and subsequent calls to pcre_exec() if you are
+       making repeated calls to find all  the  matches  in  a  single  subject
+       string.  However,  you  should  be  sure  that the value of startoffset
+       points to the start of a UTF-8 character.  When  PCRE_NO_UTF8_CHECK  is
+       set,  the  effect of passing an invalid UTF-8 string as a subject, or a
+       value of startoffset that does not point to the start of a UTF-8  char-
        acter, is undefined. Your program may crash.
 
          PCRE_PARTIAL
 
-       This option turns on the  partial  matching  feature.  If  the  subject
-       string  fails to match the pattern, but at some point during the match-
-       ing process the end of the subject was reached (that  is,  the  subject
-       partially  matches  the  pattern and the failure to match occurred only
-       because there were not enough subject characters), pcre_exec()  returns
-       PCRE_ERROR_PARTIAL  instead of PCRE_ERROR_NOMATCH. When PCRE_PARTIAL is
-       used, there are restrictions on what may appear in the  pattern.  These
+       This  option  turns  on  the  partial  matching feature. If the subject
+       string fails to match the pattern, but at some point during the  match-
+       ing  process  the  end of the subject was reached (that is, the subject
+       partially matches the pattern and the failure to  match  occurred  only
+       because  there were not enough subject characters), pcre_exec() returns
+       PCRE_ERROR_PARTIAL instead of PCRE_ERROR_NOMATCH. When PCRE_PARTIAL  is
+       used,  there  are restrictions on what may appear in the pattern. These
        are discussed in the pcrepartial documentation.
 
    The string to be matched by pcre_exec()
 
-       The  subject string is passed to pcre_exec() as a pointer in subject, a
-       length in length, and a starting byte offset in startoffset.  In  UTF-8
-       mode,  the  byte  offset  must point to the start of a UTF-8 character.
-       Unlike the pattern string, the subject may contain binary  zero  bytes.
-       When  the starting offset is zero, the search for a match starts at the
+       The subject string is passed to pcre_exec() as a pointer in subject,  a
+       length  in  length, and a starting byte offset in startoffset. In UTF-8
+       mode, the byte offset must point to the start  of  a  UTF-8  character.
+       Unlike  the  pattern string, the subject may contain binary zero bytes.
+       When the starting offset is zero, the search for a match starts at  the
        beginning of the subject, and this is by far the most common case.
 
-       A non-zero starting offset is useful when searching for  another  match
-       in  the same subject by calling pcre_exec() again after a previous suc-
-       cess.  Setting startoffset differs from just passing over  a  shortened
-       string  and  setting  PCRE_NOTBOL  in the case of a pattern that begins
+       A  non-zero  starting offset is useful when searching for another match
+       in the same subject by calling pcre_exec() again after a previous  suc-
+       cess.   Setting  startoffset differs from just passing over a shortened
+       string and setting PCRE_NOTBOL in the case of  a  pattern  that  begins
        with any kind of lookbehind. For example, consider the pattern
 
          \Biss\B
 
-       which finds occurrences of "iss" in the middle of  words.  (\B  matches
-       only  if  the  current position in the subject is not a word boundary.)
-       When applied to the string "Mississipi" the first call  to  pcre_exec()
-       finds  the  first  occurrence. If pcre_exec() is called again with just
-       the remainder of the subject,  namely  "issipi",  it  does  not  match,
+       which  finds  occurrences  of "iss" in the middle of words. (\B matches
+       only if the current position in the subject is not  a  word  boundary.)
+       When  applied  to the string "Mississipi" the first call to pcre_exec()
+       finds the first occurrence. If pcre_exec() is called  again  with  just
+       the  remainder  of  the  subject,  namely  "issipi", it does not match,
        because \B is always false at the start of the subject, which is deemed
-       to be a word boundary. However, if pcre_exec()  is  passed  the  entire
+       to  be  a  word  boundary. However, if pcre_exec() is passed the entire
        string again, but with startoffset set to 4, it finds the second occur-
-       rence of "iss" because it is able to look behind the starting point  to
+       rence  of "iss" because it is able to look behind the starting point to
        discover that it is preceded by a letter.
 
-       If  a  non-zero starting offset is passed when the pattern is anchored,
+       If a non-zero starting offset is passed when the pattern  is  anchored,
        one attempt to match at the given offset is made. This can only succeed
-       if  the  pattern  does  not require the match to be at the start of the
+       if the pattern does not require the match to be at  the  start  of  the
        subject.
 
    How pcre_exec() returns captured substrings
 
-       In general, a pattern matches a certain portion of the subject, and  in
-       addition,  further  substrings  from  the  subject may be picked out by
-       parts of the pattern. Following the usage  in  Jeffrey  Friedl's  book,
-       this  is  called "capturing" in what follows, and the phrase "capturing
-       subpattern" is used for a fragment of a pattern that picks out  a  sub-
-       string.  PCRE  supports several other kinds of parenthesized subpattern
+       In  general, a pattern matches a certain portion of the subject, and in
+       addition, further substrings from the subject  may  be  picked  out  by
+       parts  of  the  pattern.  Following the usage in Jeffrey Friedl's book,
+       this is called "capturing" in what follows, and the  phrase  "capturing
+       subpattern"  is  used for a fragment of a pattern that picks out a sub-
+       string. PCRE supports several other kinds of  parenthesized  subpattern
        that do not cause substrings to be captured.
 
-       Captured substrings are returned to the caller via a vector of  integer
-       offsets  whose  address is passed in ovector. The number of elements in
-       the vector is passed in ovecsize, which must be a non-negative  number.
+       Captured  substrings are returned to the caller via a vector of integer
+       offsets whose address is passed in ovector. The number of  elements  in
+       the  vector is passed in ovecsize, which must be a non-negative number.
        Note: this argument is NOT the size of ovector in bytes.
 
-       The  first  two-thirds of the vector is used to pass back captured sub-
-       strings, each substring using a pair of integers. The  remaining  third
-       of  the  vector is used as workspace by pcre_exec() while matching cap-
-       turing subpatterns, and is not available for passing back  information.
-       The  length passed in ovecsize should always be a multiple of three. If
+       The first two-thirds of the vector is used to pass back  captured  sub-
+       strings,  each  substring using a pair of integers. The remaining third
+       of the vector is used as workspace by pcre_exec() while  matching  cap-
+       turing  subpatterns, and is not available for passing back information.
+       The length passed in ovecsize should always be a multiple of three.  If
        it is not, it is rounded down.
 
-       When a match is successful, information about  captured  substrings  is
-       returned  in  pairs  of integers, starting at the beginning of ovector,
-       and continuing up to two-thirds of its length at the  most.  The  first
+       When  a  match  is successful, information about captured substrings is
+       returned in pairs of integers, starting at the  beginning  of  ovector,
+       and  continuing  up  to two-thirds of its length at the most. The first
        element of a pair is set to the offset of the first character in a sub-
-       string, and the second is set to the  offset  of  the  first  character
-       after  the  end  of  a  substring. The first pair, ovector[0] and ovec-
-       tor[1], identify the portion of  the  subject  string  matched  by  the
-       entire  pattern.  The next pair is used for the first capturing subpat-
+       string,  and  the  second  is  set to the offset of the first character
+       after the end of a substring. The  first  pair,  ovector[0]  and  ovec-
+       tor[1],  identify  the  portion  of  the  subject string matched by the
+       entire pattern. The next pair is used for the first  capturing  subpat-
        tern, and so on. The value returned by pcre_exec() is one more than the
        highest numbered pair that has been set. For example, if two substrings
-       have been captured, the returned value is 3. If there are no  capturing
-       subpatterns,  the return value from a successful match is 1, indicating
+       have  been captured, the returned value is 3. If there are no capturing
+       subpatterns, the return value from a successful match is 1,  indicating
        that just the first pair of offsets has been set.
 
        If a capturing subpattern is matched repeatedly, it is the last portion
        of the string that it matched that is returned.
 
-       If  the vector is too small to hold all the captured substring offsets,
+       If the vector is too small to hold all the captured substring  offsets,
        it is used as far as possible (up to two-thirds of its length), and the
-       function  returns a value of zero. In particular, if the substring off-
+       function returns a value of zero. In particular, if the substring  off-
        sets are not of interest, pcre_exec() may be called with ovector passed
-       as  NULL  and  ovecsize  as zero. However, if the pattern contains back
-       references and the ovector is not big enough to  remember  the  related
-       substrings,  PCRE has to get additional memory for use during matching.
+       as NULL and ovecsize as zero. However, if  the  pattern  contains  back
+       references  and  the  ovector is not big enough to remember the related
+       substrings, PCRE has to get additional memory for use during  matching.
        Thus it is usually advisable to supply an ovector.
 
-       The pcre_info() function can be used to find  out  how  many  capturing
-       subpatterns  there  are  in  a  compiled pattern. The smallest size for
-       ovector that will allow for n captured substrings, in addition  to  the
+       The  pcre_info()  function  can  be used to find out how many capturing
+       subpatterns there are in a compiled  pattern.  The  smallest  size  for
+       ovector  that  will allow for n captured substrings, in addition to the
        offsets of the substring matched by the whole pattern, is (n+1)*3.
 
-       It  is  possible for capturing subpattern number n+1 to match some part
+       It is possible for capturing subpattern number n+1 to match  some  part
        of the subject when subpattern n has not been used at all. For example,
-       if  the  string  "abc"  is  matched against the pattern (a|(z))(bc) the
+       if the string "abc" is matched  against  the  pattern  (a|(z))(bc)  the
        return from the function is 4, and subpatterns 1 and 3 are matched, but
-       2  is  not.  When  this happens, both values in the offset pairs corre-
+       2 is not. When this happens, both values in  the  offset  pairs  corre-
        sponding to unused subpatterns are set to -1.
 
-       Offset values that correspond to unused subpatterns at the end  of  the
-       expression  are  also  set  to  -1. For example, if the string "abc" is
-       matched against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are  not
-       matched.  The  return  from the function is 2, because the highest used
+       Offset  values  that correspond to unused subpatterns at the end of the
+       expression are also set to -1. For example,  if  the  string  "abc"  is
+       matched  against the pattern (abc)(x(yz)?)? subpatterns 2 and 3 are not
+       matched. The return from the function is 2, because  the  highest  used
        capturing subpattern number is 1. However, you can refer to the offsets
-       for  the  second  and third capturing subpatterns if you wish (assuming
+       for the second and third capturing subpatterns if  you  wish  (assuming
        the vector is large enough, of course).
 
-       Some convenience functions are provided  for  extracting  the  captured
+       Some  convenience  functions  are  provided for extracting the captured
        substrings as separate strings. These are described below.
 
    Error return values from pcre_exec()
 
-       If  pcre_exec()  fails, it returns a negative number. The following are
+       If pcre_exec() fails, it returns a negative number. The  following  are
        defined in the header file:
 
          PCRE_ERROR_NOMATCH        (-1)
@@ -1809,7 +1878,7 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION
 
          PCRE_ERROR_NULL           (-2)
 
-       Either code or subject was passed as NULL,  or  ovector  was  NULL  and
+       Either  code  or  subject  was  passed as NULL, or ovector was NULL and
        ovecsize was not zero.
 
          PCRE_ERROR_BADOPTION      (-3)
@@ -1818,80 +1887,94 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION
 
          PCRE_ERROR_BADMAGIC       (-4)
 
-       PCRE  stores a 4-byte "magic number" at the start of the compiled code,
+       PCRE stores a 4-byte "magic number" at the start of the compiled  code,
        to catch the case when it is passed a junk pointer and to detect when a
        pattern that was compiled in an environment of one endianness is run in
-       an environment with the other endianness. This is the error  that  PCRE
+       an  environment  with the other endianness. This is the error that PCRE
        gives when the magic number is not present.
 
-         PCRE_ERROR_UNKNOWN_NODE   (-5)
+         PCRE_ERROR_UNKNOWN_OPCODE (-5)
 
        While running the pattern match, an unknown item was encountered in the
-       compiled pattern. This error could be caused by a bug  in  PCRE  or  by
+       compiled  pattern.  This  error  could be caused by a bug in PCRE or by
        overwriting of the compiled pattern.
 
          PCRE_ERROR_NOMEMORY       (-6)
 
-       If  a  pattern contains back references, but the ovector that is passed
+       If a pattern contains back references, but the ovector that  is  passed
        to pcre_exec() is not big enough to remember the referenced substrings,
-       PCRE  gets  a  block of memory at the start of matching to use for this
-       purpose. If the call via pcre_malloc() fails, this error is given.  The
+       PCRE gets a block of memory at the start of matching to  use  for  this
+       purpose.  If the call via pcre_malloc() fails, this error is given. The
        memory is automatically freed at the end of matching.
 
          PCRE_ERROR_NOSUBSTRING    (-7)
 
-       This  error is used by the pcre_copy_substring(), pcre_get_substring(),
+       This error is used by the pcre_copy_substring(),  pcre_get_substring(),
        and  pcre_get_substring_list()  functions  (see  below).  It  is  never
        returned by pcre_exec().
 
          PCRE_ERROR_MATCHLIMIT     (-8)
 
-       The  backtracking  limit,  as  specified  by the match_limit field in a
-       pcre_extra structure (or defaulted) was reached.  See  the  description
+       The backtracking limit, as specified by  the  match_limit  field  in  a
+       pcre_extra  structure  (or  defaulted) was reached. See the description
        above.
 
-         PCRE_ERROR_RECURSIONLIMIT (-21)
-
-       The internal recursion limit, as specified by the match_limit_recursion
-       field in a pcre_extra structure (or defaulted)  was  reached.  See  the
-       description above.
-
          PCRE_ERROR_CALLOUT        (-9)
 
        This error is never generated by pcre_exec() itself. It is provided for
-       use by callout functions that want to yield a distinctive  error  code.
+       use  by  callout functions that want to yield a distinctive error code.
        See the pcrecallout documentation for details.
 
          PCRE_ERROR_BADUTF8        (-10)
 
-       A  string  that contains an invalid UTF-8 byte sequence was passed as a
+       A string that contains an invalid UTF-8 byte sequence was passed  as  a
        subject.
 
          PCRE_ERROR_BADUTF8_OFFSET (-11)
 
        The UTF-8 byte sequence that was passed as a subject was valid, but the
-       value  of startoffset did not point to the beginning of a UTF-8 charac-
+       value of startoffset did not point to the beginning of a UTF-8  charac-
        ter.
 
          PCRE_ERROR_PARTIAL        (-12)
 
-       The subject string did not match, but it did match partially.  See  the
+       The  subject  string did not match, but it did match partially. See the
        pcrepartial documentation for details of partial matching.
 
          PCRE_ERROR_BADPARTIAL     (-13)
 
-       The  PCRE_PARTIAL  option  was  used with a compiled pattern containing
-       items that are not supported for partial matching. See the  pcrepartial
+       The PCRE_PARTIAL option was used with  a  compiled  pattern  containing
+       items  that are not supported for partial matching. See the pcrepartial
        documentation for details of partial matching.
 
          PCRE_ERROR_INTERNAL       (-14)
 
-       An  unexpected  internal error has occurred. This error could be caused
+       An unexpected internal error has occurred. This error could  be  caused
        by a bug in PCRE or by overwriting of the compiled pattern.
 
          PCRE_ERROR_BADCOUNT       (-15)
 
-       This error is given if the value of the ovecsize argument is  negative.
+       This  error is given if the value of the ovecsize argument is negative.
+
+         PCRE_ERROR_RECURSIONLIMIT (-21)
+
+       The internal recursion limit, as specified by the match_limit_recursion
+       field  in  a  pcre_extra  structure (or defaulted) was reached. See the
+       description above.
+
+         PCRE_ERROR_NULLWSLIMIT    (-22)
+
+       When a group that can match an empty  substring  is  repeated  with  an
+       unbounded  upper  limit, the subject position at the start of the group
+       must be remembered, so that a test for an empty string can be made when
+       the  end  of the group is reached. Some workspace is required for this;
+       if it runs out, this error is given.
+
+         PCRE_ERROR_BADNEWLINE     (-23)
+
+       An invalid combination of PCRE_NEWLINE_xxx options was given.
+
+       Error numbers -16 to -20 are not used by pcre_exec().
 
 
 EXTRACTING CAPTURED SUBSTRINGS BY NUMBER
@@ -1907,57 +1990,58 @@ EXTRACTING CAPTURED SUBSTRINGS BY NUMBER
        int pcre_get_substring_list(const char *subject,
             int *ovector, int stringcount, const char ***listptr);
 
-       Captured  substrings  can  be  accessed  directly  by using the offsets
-       returned by pcre_exec() in  ovector.  For  convenience,  the  functions
+       Captured substrings can be  accessed  directly  by  using  the  offsets
+       returned  by  pcre_exec()  in  ovector.  For convenience, the functions
        pcre_copy_substring(),    pcre_get_substring(),    and    pcre_get_sub-
-       string_list() are provided for extracting captured substrings  as  new,
-       separate,  zero-terminated strings. These functions identify substrings
-       by number. The next section describes functions  for  extracting  named
+       string_list()  are  provided for extracting captured substrings as new,
+       separate, zero-terminated strings. These functions identify  substrings
+       by  number.  The  next section describes functions for extracting named
        substrings.
 
-       A  substring that contains a binary zero is correctly extracted and has
-       a further zero added on the end, but the result is not, of course, a  C
-       string.   However,  you  can  process such a string by referring to the
-       length that is  returned  by  pcre_copy_substring()  and  pcre_get_sub-
+       A substring that contains a binary zero is correctly extracted and  has
+       a  further zero added on the end, but the result is not, of course, a C
+       string.  However, you can process such a string  by  referring  to  the
+       length  that  is  returned  by  pcre_copy_substring() and pcre_get_sub-
        string().  Unfortunately, the interface to pcre_get_substring_list() is
-       not adequate for handling strings containing binary zeros, because  the
+       not  adequate for handling strings containing binary zeros, because the
        end of the final string is not independently indicated.
 
-       The  first  three  arguments  are the same for all three of these func-
-       tions: subject is the subject string that has  just  been  successfully
+       The first three arguments are the same for all  three  of  these  func-
+       tions:  subject  is  the subject string that has just been successfully
        matched, ovector is a pointer to the vector of integer offsets that was
        passed to pcre_exec(), and stringcount is the number of substrings that
-       were  captured  by  the match, including the substring that matched the
+       were captured by the match, including the substring  that  matched  the
        entire regular expression. This is the value returned by pcre_exec() if
-       it  is greater than zero. If pcre_exec() returned zero, indicating that
-       it ran out of space in ovector, the value passed as stringcount  should
+       it is greater than zero. If pcre_exec() returned zero, indicating  that
+       it  ran out of space in ovector, the value passed as stringcount should
        be the number of elements in the vector divided by three.
 
-       The  functions pcre_copy_substring() and pcre_get_substring() extract a
-       single substring, whose number is given as  stringnumber.  A  value  of
-       zero  extracts  the  substring that matched the entire pattern, whereas
-       higher values  extract  the  captured  substrings.  For  pcre_copy_sub-
-       string(),  the  string  is  placed  in buffer, whose length is given by
-       buffersize, while for pcre_get_substring() a new  block  of  memory  is
-       obtained  via  pcre_malloc,  and its address is returned via stringptr.
-       The yield of the function is the length of the  string,  not  including
-       the terminating zero, or one of
+       The functions pcre_copy_substring() and pcre_get_substring() extract  a
+       single  substring,  whose  number  is given as stringnumber. A value of
+       zero extracts the substring that matched the  entire  pattern,  whereas
+       higher  values  extract  the  captured  substrings.  For pcre_copy_sub-
+       string(), the string is placed in buffer,  whose  length  is  given  by
+       buffersize,  while  for  pcre_get_substring()  a new block of memory is
+       obtained via pcre_malloc, and its address is  returned  via  stringptr.
+       The  yield  of  the function is the length of the string, not including
+       the terminating zero, or one of these error codes:
 
          PCRE_ERROR_NOMEMORY       (-6)
 
-       The  buffer  was too small for pcre_copy_substring(), or the attempt to
+       The buffer was too small for pcre_copy_substring(), or the  attempt  to
        get memory failed for pcre_get_substring().
 
          PCRE_ERROR_NOSUBSTRING    (-7)
 
        There is no substring whose number is stringnumber.
 
-       The pcre_get_substring_list()  function  extracts  all  available  sub-
-       strings  and  builds  a list of pointers to them. All this is done in a
+       The  pcre_get_substring_list()  function  extracts  all  available sub-
+       strings and builds a list of pointers to them. All this is  done  in  a
        single block of memory that is obtained via pcre_malloc. The address of
-       the  memory  block  is returned via listptr, which is also the start of
-       the list of string pointers. The end of the list is marked  by  a  NULL
-       pointer. The yield of the function is zero if all went well, or
+       the memory block is returned via listptr, which is also  the  start  of
+       the  list  of  string pointers. The end of the list is marked by a NULL
+       pointer. The yield of the function is zero if all  went  well,  or  the
+       error code
 
          PCRE_ERROR_NOMEMORY       (-6)
 
@@ -1999,7 +2083,7 @@ EXTRACTING CAPTURED SUBSTRINGS BY NAME
        To extract a substring by name, you first have to find associated  num-
        ber.  For example, for this pattern
 
-         (a+)b(?P<xxx>\d+)...
+         (a+)b(?<xxx>\d+)...
 
        the number of the subpattern called "xxx" is 2. If the name is known to
        be unique (PCRE_DUPNAMES was not set), you can find the number from the
@@ -2050,11 +2134,11 @@ DUPLICATE SUBPATTERN NAMES
        third  and  fourth  are  pointers to variables which are updated by the
        function. After it has run, they point to the first and last entries in
        the  name-to-number  table  for  the  given  name.  The function itself
-       returns the length of each entry, or  PCRE_ERROR_NOSUBSTRING  if  there
-       are  none.  The  format  of the table is described above in the section
-       entitled Information about a pattern. Given all  the  relevant  entries
-       for the name, you can extract each of their numbers, and hence the cap-
-       tured data, if any.
+       returns the length of each entry,  or  PCRE_ERROR_NOSUBSTRING  (-7)  if
+       there  are none. The format of the table is described above in the sec-
+       tion entitled Information about a  pattern.   Given  all  the  relevant
+       entries  for the name, you can extract each of their numbers, and hence
+       the captured data, if any.
 
 
 FINDING ALL POSSIBLE MATCHES
@@ -2083,23 +2167,24 @@ MATCHING A PATTERN: THE ALTERNATIVE FUNCTION
             int *workspace, int wscount);
 
        The  function  pcre_dfa_exec()  is  called  to  match  a subject string
-       against a compiled pattern, using a "DFA" matching algorithm. This  has
-       different  characteristics to the normal algorithm, and is not compati-
-       ble with Perl. Some of the features of PCRE patterns are not supported.
-       Nevertheless, there are times when this kind of matching can be useful.
-       For a discussion of the two matching algorithms, see  the  pcrematching
-       documentation.
+       against a compiled pattern, using a matching algorithm that  scans  the
+       subject  string  just  once, and does not backtrack. This has different
+       characteristics to the normal algorithm, and  is  not  compatible  with
+       Perl.  Some  of the features of PCRE patterns are not supported. Never-
+       theless, there are times when this kind of matching can be useful.  For
+       a discussion of the two matching algorithms, see the pcrematching docu-
+       mentation.
 
-       The  arguments  for  the  pcre_dfa_exec()  function are the same as for
+       The arguments for the pcre_dfa_exec() function  are  the  same  as  for
        pcre_exec(), plus two extras. The ovector argument is used in a differ-
-       ent  way,  and  this is described below. The other common arguments are
-       used in the same way as for pcre_exec(), so their  description  is  not
+       ent way, and this is described below. The other  common  arguments  are
+       used  in  the  same way as for pcre_exec(), so their description is not
        repeated here.
 
-       The  two  additional  arguments provide workspace for the function. The
-       workspace vector should contain at least 20 elements. It  is  used  for
+       The two additional arguments provide workspace for  the  function.  The
+       workspace  vector  should  contain at least 20 elements. It is used for
        keeping  track  of  multiple  paths  through  the  pattern  tree.  More
-       workspace will be needed for patterns and subjects where  there  are  a
+       workspace  will  be  needed for patterns and subjects where there are a
        lot of potential matches.
 
        Here is an example of a simple call to pcre_dfa_exec():
@@ -2121,47 +2206,47 @@ MATCHING A PATTERN: THE ALTERNATIVE FUNCTION
 
    Option bits for pcre_dfa_exec()
 
-       The  unused  bits  of  the options argument for pcre_dfa_exec() must be
-       zero. The only bits  that  may  be  set  are  PCRE_ANCHORED,  PCRE_NEW-
-       LINE_xxx,  PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, PCRE_NO_UTF8_CHECK,
+       The unused bits of the options argument  for  pcre_dfa_exec()  must  be
+       zero.  The  only  bits  that  may  be  set are PCRE_ANCHORED, PCRE_NEW-
+       LINE_xxx, PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY,  PCRE_NO_UTF8_CHECK,
        PCRE_PARTIAL, PCRE_DFA_SHORTEST, and PCRE_DFA_RESTART. All but the last
        three of these are the same as for pcre_exec(), so their description is
        not repeated here.
 
          PCRE_PARTIAL
 
-       This has the same general effect as it does for  pcre_exec(),  but  the
-       details   are   slightly   different.  When  PCRE_PARTIAL  is  set  for
-       pcre_dfa_exec(), the return code PCRE_ERROR_NOMATCH is  converted  into
-       PCRE_ERROR_PARTIAL  if  the  end  of the subject is reached, there have
+       This  has  the  same general effect as it does for pcre_exec(), but the
+       details  are  slightly  different.  When  PCRE_PARTIAL   is   set   for
+       pcre_dfa_exec(),  the  return code PCRE_ERROR_NOMATCH is converted into
+       PCRE_ERROR_PARTIAL if the end of the subject  is  reached,  there  have
        been no complete matches, but there is still at least one matching pos-
-       sibility.  The portion of the string that provided the partial match is
+       sibility. The portion of the string that provided the partial match  is
        set as the first matching string.
 
          PCRE_DFA_SHORTEST
 
-       Setting the PCRE_DFA_SHORTEST option causes the matching  algorithm  to
-       stop  as  soon  as  it  has found one match. Because of the way the DFA
-       algorithm works, this is necessarily the shortest possible match at the
-       first possible matching point in the subject string.
+       Setting  the  PCRE_DFA_SHORTEST option causes the matching algorithm to
+       stop as soon as it has found one match. Because of the way the alterna-
+       tive  algorithm  works, this is necessarily the shortest possible match
+       at the first possible matching point in the subject string.
 
          PCRE_DFA_RESTART
 
-       When  pcre_dfa_exec()  is  called  with  the  PCRE_PARTIAL  option, and
-       returns a partial match, it is possible to call it  again,  with  addi-
-       tional  subject  characters,  and have it continue with the same match.
-       The PCRE_DFA_RESTART option requests this action; when it is  set,  the
-       workspace  and wscount options must reference the same vector as before
-       because data about the match so far is left in  them  after  a  partial
-       match.  There  is  more  discussion of this facility in the pcrepartial
+       When pcre_dfa_exec()  is  called  with  the  PCRE_PARTIAL  option,  and
+       returns  a  partial  match, it is possible to call it again, with addi-
+       tional subject characters, and have it continue with  the  same  match.
+       The  PCRE_DFA_RESTART  option requests this action; when it is set, the
+       workspace and wscount options must reference the same vector as  before
+       because  data  about  the  match so far is left in them after a partial
+       match. There is more discussion of this  facility  in  the  pcrepartial
        documentation.
 
    Successful returns from pcre_dfa_exec()
 
-       When pcre_dfa_exec() succeeds, it may have matched more than  one  sub-
+       When  pcre_dfa_exec()  succeeds, it may have matched more than one sub-
        string in the subject. Note, however, that all the matches from one run
-       of the function start at the same point in  the  subject.  The  shorter
-       matches  are all initial substrings of the longer matches. For example,
+       of  the  function  start  at the same point in the subject. The shorter
+       matches are all initial substrings of the longer matches. For  example,
        if the pattern
 
          <.*>
@@ -2176,58 +2261,64 @@ MATCHING A PATTERN: THE ALTERNATIVE FUNCTION
          <something> <something else>
          <something> <something else> <something further>
 
-       On success, the yield of the function is a number  greater  than  zero,
-       which  is  the  number of matched substrings. The substrings themselves
-       are returned in ovector. Each string uses two elements;  the  first  is
-       the  offset  to the start, and the second is the offset to the end. All
-       the strings have the same start offset. (Space could have been saved by
-       giving  this only once, but it was decided to retain some compatibility
-       with the way pcre_exec() returns data, even though the meaning  of  the
-       strings is different.)
+       On  success,  the  yield of the function is a number greater than zero,
+       which is the number of matched substrings.  The  substrings  themselves
+       are  returned  in  ovector. Each string uses two elements; the first is
+       the offset to the start, and the second is the offset to  the  end.  In
+       fact,  all  the  strings  have the same start offset. (Space could have
+       been saved by giving this only once, but it was decided to retain  some
+       compatibility  with  the  way pcre_exec() returns data, even though the
+       meaning of the strings is different.)
 
        The strings are returned in reverse order of length; that is, the long-
-       est matching string is given first. If there were too many  matches  to
-       fit  into ovector, the yield of the function is zero, and the vector is
+       est  matching  string is given first. If there were too many matches to
+       fit into ovector, the yield of the function is zero, and the vector  is
        filled with the longest matches.
 
    Error returns from pcre_dfa_exec()
 
-       The pcre_dfa_exec() function returns a negative number when  it  fails.
-       Many  of  the  errors  are  the  same as for pcre_exec(), and these are
-       described above.  There are in addition the following errors  that  are
+       The  pcre_dfa_exec()  function returns a negative number when it fails.
+       Many of the errors are the same  as  for  pcre_exec(),  and  these  are
+       described  above.   There are in addition the following errors that are
        specific to pcre_dfa_exec():
 
          PCRE_ERROR_DFA_UITEM      (-16)
 
-       This  return is given if pcre_dfa_exec() encounters an item in the pat-
-       tern that it does not support, for instance, the use of \C  or  a  back
+       This return is given if pcre_dfa_exec() encounters an item in the  pat-
+       tern  that  it  does not support, for instance, the use of \C or a back
        reference.
 
          PCRE_ERROR_DFA_UCOND      (-17)
 
-       This  return is given if pcre_dfa_exec() encounters a condition item in
-       a pattern that uses a back reference for the  condition.  This  is  not
-       supported.
+       This return is given if pcre_dfa_exec()  encounters  a  condition  item
+       that  uses  a back reference for the condition, or a test for recursion
+       in a specific group. These are not supported.
 
          PCRE_ERROR_DFA_UMLIMIT    (-18)
 
-       This  return  is given if pcre_dfa_exec() is called with an extra block
+       This return is given if pcre_dfa_exec() is called with an  extra  block
        that contains a setting of the match_limit field. This is not supported
        (it is meaningless).
 
          PCRE_ERROR_DFA_WSSIZE     (-19)
 
-       This  return  is  given  if  pcre_dfa_exec()  runs  out of space in the
+       This return is given if  pcre_dfa_exec()  runs  out  of  space  in  the
        workspace vector.
 
          PCRE_ERROR_DFA_RECURSE    (-20)
 
-       When a recursive subpattern is processed, the matching  function  calls
-       itself  recursively,  using  private vectors for ovector and workspace.
-       This error is given if the output vector  is  not  large  enough.  This
+       When  a  recursive subpattern is processed, the matching function calls
+       itself recursively, using private vectors for  ovector  and  workspace.
+       This  error  is  given  if  the output vector is not large enough. This
        should be extremely rare, as a vector of size 1000 is used.
 
-Last updated: 08 June 2006
+
+SEE ALSO
+
+       pcrebuild(3), pcrecallout(3), pcrecpp(3)(3), pcrematching(3),  pcrepar-
+       tial(3),  pcreposix(3), pcreprecompile(3), pcresample(3), pcrestack(3).
+
+Last updated: 30 November 2006
 Copyright (c) 1997-2006 University of Cambridge.
 ------------------------------------------------------------------------------
 
@@ -2401,45 +2492,46 @@ NAME
 DIFFERENCES BETWEEN PCRE AND PERL
 
        This  document describes the differences in the ways that PCRE and Perl
-       handle regular expressions. The differences  described  here  are  with
-       respect to Perl 5.8.
+       handle regular expressions. The differences described here  are  mainly
+       with  respect  to  Perl 5.8, though PCRE version 7.0 contains some fea-
+       tures that are expected to be in the forthcoming Perl 5.10.
 
-       1.  PCRE has only a subset of Perl's UTF-8 and Unicode support. Details
-       of what it does have are given in the section on UTF-8 support  in  the
+       1. PCRE has only a subset of Perl's UTF-8 and Unicode support.  Details
+       of  what  it does have are given in the section on UTF-8 support in the
        main pcre page.
 
        2. PCRE does not allow repeat quantifiers on lookahead assertions. Perl
-       permits them, but they do not mean what you might think.  For  example,
+       permits  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.
 
-       3. Capturing subpatterns that occur inside  negative  lookahead  asser-
-       tions  are  counted,  but their entries in the offsets vector are never
-       set. Perl sets its numerical variables from any such patterns that  are
+       3.  Capturing  subpatterns  that occur inside negative lookahead asser-
+       tions are counted, but their entries in the offsets  vector  are  never
+       set.  Perl sets its numerical variables from any such patterns that are
        matched before the assertion fails to match something (thereby succeed-
-       ing), but only if the negative lookahead assertion  contains  just  one
+       ing),  but  only  if the negative lookahead assertion contains just one
        branch.
 
-       4.  Though  binary zero characters are supported in the subject string,
+       4. Though binary zero characters are supported in the  subject  string,
        they are not allowed in a pattern string because it is passed as a nor-
        mal C string, terminated by zero. The escape sequence \0 can be used in
        the pattern to represent a binary zero.
 
-       5. The following Perl escape sequences are not supported: \l,  \u,  \L,
+       5.  The  following Perl escape sequences are not supported: \l, \u, \L,
        \U, and \N. In fact these are implemented by Perl's general string-han-
-       dling and are not part of its pattern matching engine. If any of  these
+       dling  and are not part of its pattern matching engine. If any of these
        are encountered by PCRE, an error is generated.
 
-       6.  The Perl escape sequences \p, \P, and \X are supported only if PCRE
-       is built with Unicode character property support. The  properties  that
-       can  be tested with \p and \P are limited to the general category prop-
-       erties such as Lu and Nd, script names such as Greek or  Han,  and  the
+       6. The Perl escape sequences \p, \P, and \X are supported only if  PCRE
+       is  built  with Unicode character property support. The properties that
+       can be tested with \p and \P are limited to the general category  prop-
+       erties  such  as  Lu and Nd, script names such as Greek or Han, and the
        derived properties Any and L&.
 
        7. PCRE does support the \Q...\E escape for quoting substrings. Charac-
-       ters in between are treated as literals.  This  is  slightly  different
-       from  Perl  in  that  $  and  @ are also handled as literals inside the
-       quotes. In Perl, they cause variable interpolation (but of course  PCRE
+       ters  in  between  are  treated as literals. This is slightly different
+       from Perl in that $ and @ are  also  handled  as  literals  inside  the
+       quotes.  In Perl, they cause variable interpolation (but of course PCRE
        does not have variables). Note the following examples:
 
            Pattern            PCRE matches      Perl matches
@@ -2449,66 +2541,61 @@ DIFFERENCES BETWEEN PCRE AND PERL
            \Qabc\$xyz\E       abc\$xyz          abc\$xyz
            \Qabc\E\$\Qxyz\E   abc$xyz           abc$xyz
 
-       The  \Q...\E  sequence  is recognized both inside and outside character
+       The \Q...\E sequence is recognized both inside  and  outside  character
        classes.
 
-       8. Fairly obviously, PCRE does not support the (?{code}) and (?p{code})
-       constructions.  However,  there is support for recursive patterns using
-       the non-Perl items (?R),  (?number),  and  (?P>name).  Also,  the  PCRE
-       "callout"  feature allows an external function to be called during pat-
+       8. Fairly obviously, PCRE does not support the (?{code}) and (??{code})
+       constructions. However, there is support for recursive  patterns.  This
+       is  not available in Perl 5.8, but will be in Perl 5.10. Also, the PCRE
+       "callout" feature allows an external function to be called during  pat-
        tern matching. See the pcrecallout documentation for details.
 
-       9. There are some differences that are concerned with the  settings  of
-       captured  strings  when  part  of  a  pattern is repeated. For example,
-       matching "aba" against the  pattern  /^(a(b)?)+$/  in  Perl  leaves  $2
+       9.  Subpatterns  that  are  called  recursively or as "subroutines" are
+       always treated as atomic groups in  PCRE.  This  is  like  Python,  but
+       unlike Perl.
+
+       10.  There are some differences that are concerned with the settings of
+       captured strings when part of  a  pattern  is  repeated.  For  example,
+       matching  "aba"  against  the  pattern  /^(a(b)?)+$/  in Perl leaves $2
        unset, but in PCRE it is set to "b".
 
-       10. PCRE provides some extensions to the Perl regular expression facil-
-       ities:
+       11. PCRE provides some extensions to the Perl regular expression facil-
+       ities.   Perl  5.10  will  include new features that are not in earlier
+       versions, some of which (such as named parentheses) have been  in  PCRE
+       for some time. This list is with respect to Perl 5.10:
 
-       (a) Although lookbehind assertions must  match  fixed  length  strings,
+       (a)  Although  lookbehind  assertions  must match fixed length strings,
        each alternative branch of a lookbehind assertion can match a different
        length of string. Perl requires them all to have the same length.
 
-       (b) If PCRE_DOLLAR_ENDONLY is set and PCRE_MULTILINE is not set, the  $
+       (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.
 
        (c) If PCRE_EXTRA is set, a backslash followed by a letter with no spe-
-       cial meaning  is  faulted.  Otherwise,  like  Perl,  the  backslash  is
+       cial  meaning  is  faulted.  Otherwise,  like  Perl,  the  backslash is
        ignored. (Perl can be made to issue a warning.)
 
-       (d)  If  PCRE_UNGREEDY is set, the greediness of the repetition quanti-
+       (d) If PCRE_UNGREEDY is set, the greediness of the  repetition  quanti-
        fiers is inverted, that is, by default they are not greedy, but if fol-
        lowed by a question mark they are.
 
        (e) PCRE_ANCHORED can be used at matching time to force a pattern to be
        tried only at the first matching position in the subject string.
 
-       (f) The PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, and  PCRE_NO_AUTO_CAP-
+       (f)  The PCRE_NOTBOL, PCRE_NOTEOL, PCRE_NOTEMPTY, and PCRE_NO_AUTO_CAP-
        TURE options for pcre_exec() have no Perl equivalents.
 
-       (g)  The (?R), (?number), and (?P>name) constructs allows for recursive
-       pattern matching (Perl can do  this  using  the  (?p{code})  construct,
-       which PCRE cannot support.)
-
-       (h)  PCRE supports named capturing substrings, using the Python syntax.
-
-       (i) PCRE supports the possessive quantifier  "++"  syntax,  taken  from
-       Sun's Java package.
+       (g) The callout facility is PCRE-specific.
 
-       (j) The (R) condition, for testing recursion, is a PCRE extension.
+       (h) The partial matching facility is PCRE-specific.
 
-       (k) The callout facility is PCRE-specific.
-
-       (l) The partial matching facility is PCRE-specific.
-
-       (m) Patterns compiled by PCRE can be saved and re-used at a later time,
+       (i) Patterns compiled by PCRE can be saved and re-used at a later time,
        even on different hosts that have the other endianness.
 
-       (n) The alternative matching function (pcre_dfa_exec())  matches  in  a
+       (j)  The  alternative  matching function (pcre_dfa_exec()) matches in a
        different way and is not Perl-compatible.
 
-Last updated: 06 June 2006
+Last updated: 28 November 2006
 Copyright (c) 1997-2006 University of Cambridge.
 ------------------------------------------------------------------------------
 
@@ -2545,6 +2632,9 @@ PCRE REGULAR EXPRESSION DETAILS
        function, and how it differs from the normal function, are discussed in
        the pcrematching page.
 
+
+CHARACTERS AND METACHARACTERS
+
        A regular expression is a pattern that is  matched  against  a  subject
        string  from  left  to right. Most characters stand for themselves in a
        pattern, and match the corresponding characters in the  subject.  As  a
@@ -2569,8 +2659,8 @@ PCRE REGULAR EXPRESSION DETAILS
 
        There are two different sets of metacharacters: those that  are  recog-
        nized  anywhere in the pattern except within square brackets, and those
-       that are recognized in square brackets. Outside  square  brackets,  the
-       metacharacters are as follows:
+       that are recognized within square brackets.  Outside  square  brackets,
+       the metacharacters are as follows:
 
          \      general escape character with several uses
          ^      assert start of string (or line, in multiline mode)
@@ -2692,7 +2782,7 @@ BACKSLASH
 
        Inside a character class, or if the decimal number is  greater  than  9
        and  there have not been that many capturing subpatterns, PCRE re-reads
-       up to three octal digits following the backslash, ane uses them to gen-
+       up to three octal digits following the backslash, and uses them to gen-
        erate  a data character. Any subsequent digits stand for themselves. In
        non-UTF-8 mode, the value of a character specified  in  octal  must  be
        less  than  \400.  In  UTF-8 mode, values up to \777 are permitted. For
@@ -2719,13 +2809,21 @@ BACKSLASH
        All the sequences that define a single character value can be used both
        inside and outside character classes. In addition, inside  a  character
        class,  the  sequence \b is interpreted as the backspace character (hex
-       08), and the sequence \X is interpreted as the character "X". Outside a
-       character class, these sequences have different meanings (see below).
+       08), and the sequences \R and \X are interpreted as the characters  "R"
+       and  "X", respectively. Outside a character class, these sequences have
+       different meanings (see below).
+
+   Absolute and relative back references
+
+       The sequence \g followed by a positive or negative  number,  optionally
+       enclosed  in  braces,  is  an absolute or relative back reference. Back
+       references are discussed later, following the discussion  of  parenthe-
+       sized subpatterns.
 
    Generic character types
 
-       The  third  use of backslash is for specifying generic character types.
-       The following are always recognized:
+       Another use of backslash is for specifying generic character types. The
+       following are always recognized:
 
          \d     any decimal digit
          \D     any character that is not a decimal digit
@@ -2762,6 +2860,28 @@ BACKSLASH
        code  character  property support is available. The use of locales with
        Unicode is discouraged.
 
+   Newline sequences
+
+       Outside a character class, the escape sequence \R matches  any  Unicode
+       newline sequence. This is an extension to Perl. In non-UTF-8 mode \R is
+       equivalent to the following:
+
+         (?>\r\n|\n|\x0b|\f|\r|\x85)
+
+       This is an example of an "atomic group", details  of  which  are  given
+       below.  This particular group matches either the two-character sequence
+       CR followed by LF, or  one  of  the  single  characters  LF  (linefeed,
+       U+000A), VT (vertical tab, U+000B), FF (formfeed, U+000C), CR (carriage
+       return, U+000D), or NEL (next line, U+0085). The two-character sequence
+       is treated as a single unit that cannot be split.
+
+       In  UTF-8  mode, two additional characters whose codepoints are greater
+       than 255 are added: LS (line separator, U+2028) and PS (paragraph sepa-
+       rator,  U+2029).   Unicode character property support is not needed for
+       these characters to be recognized.
+
+       Inside a character class, \R matches the letter "R".
+
    Unicode character properties
 
        When PCRE is built with Unicode character property support, three addi-
@@ -2788,15 +2908,15 @@ BACKSLASH
        Those that are not part of an identified script are lumped together  as
        "Common". The current list of scripts is:
 
-       Arabic,  Armenian,  Bengali,  Bopomofo, Braille, Buginese, Buhid, Cana-
-       dian_Aboriginal, Cherokee, Common, Coptic, Cypriot, Cyrillic,  Deseret,
-       Devanagari,  Ethiopic,  Georgian,  Glagolitic, Gothic, Greek, Gujarati,
-       Gurmukhi, Han, Hangul, Hanunoo, Hebrew, Hiragana,  Inherited,  Kannada,
-       Katakana,  Kharoshthi,  Khmer,  Lao, Latin, Limbu, Linear_B, Malayalam,
-       Mongolian, Myanmar, New_Tai_Lue, Ogham, Old_Italic, Old_Persian, Oriya,
-       Osmanya,  Runic,  Shavian, Sinhala, Syloti_Nagri, Syriac, Tagalog, Tag-
-       banwa,  Tai_Le,  Tamil,  Telugu,  Thaana,  Thai,   Tibetan,   Tifinagh,
-       Ugaritic, Yi.
+       Arabic,  Armenian,  Balinese,  Bengali,  Bopomofo,  Braille,  Buginese,
+       Buhid,  Canadian_Aboriginal,  Cherokee,  Common,   Coptic,   Cuneiform,
+       Cypriot, Cyrillic, Deseret, Devanagari, Ethiopic, Georgian, Glagolitic,
+       Gothic, Greek, Gujarati, Gurmukhi, Han, Hangul, Hanunoo, Hebrew,  Hira-
+       gana,  Inherited,  Kannada,  Katakana,  Kharoshthi,  Khmer, Lao, Latin,
+       Limbu,  Linear_B,  Malayalam,  Mongolian,  Myanmar,  New_Tai_Lue,  Nko,
+       Ogham,  Old_Italic,  Old_Persian, Oriya, Osmanya, Phags_Pa, Phoenician,
+       Runic,  Shavian,  Sinhala,  Syloti_Nagri,  Syriac,  Tagalog,  Tagbanwa,
+       Tai_Le, Tamil, Telugu, Thaana, Thai, Tibetan, Tifinagh, Ugaritic, Yi.
 
        Each  character has exactly one general category property, specified by
        a two-letter abbreviation. For compatibility with Perl, negation can be
@@ -2889,7 +3009,7 @@ BACKSLASH
 
    Simple assertions
 
-       The fourth use of backslash is for certain simple assertions. An asser-
+       The  final use of backslash is for certain simple assertions. An asser-
        tion specifies a condition that has to be met at a particular point  in
        a  match, without consuming any characters from the subject string. The
        use of subpatterns for more complicated assertions is described  below.
@@ -2897,10 +3017,11 @@ BACKSLASH
 
          \b     matches at a word boundary
          \B     matches when not at a word boundary
-         \A     matches at start of subject
-         \Z     matches at end of subject or before newline at end
-         \z     matches at end of subject
-         \G     matches at first matching position in subject
+         \A     matches at the start of the subject
+         \Z     matches at the end of the subject
+                 also matches before a newline at the end of the subject
+         \z     matches only at the end of the subject
+         \G     matches at the first matching position in the subject
 
        These  assertions may not appear in character classes (but note that \b
        has a different meaning, namely the backspace character, inside a char-
@@ -2997,30 +3118,34 @@ FULL STOP (PERIOD, DOT)
        Outside a character class, a dot in the pattern matches any one charac-
        ter in the subject string except (by default) a character  that  signi-
        fies  the  end  of  a line. In UTF-8 mode, the matched character may be
-       more than one byte long. When a line ending  is  defined  as  a  single
-       character  (CR  or LF), dot never matches that character; when the two-
-       character sequence CRLF is used, dot does not match CR if it is immedi-
-       ately  followed by LF, but otherwise it matches all characters (includ-
-       ing isolated CRs and LFs).
-
-       The behaviour of dot with regard to newlines can  be  changed.  If  the
-       PCRE_DOTALL  option  is  set,  a dot matches any one character, without
-       exception. If newline is defined as the two-character sequence CRLF, it
-       takes two dots to match it.
-
-       The  handling of dot is entirely independent of the handling of circum-
-       flex and dollar, the only relationship being  that  they  both  involve
+       more than one byte long.
+
+       When a line ending is defined as a single character, dot never  matches
+       that  character; when the two-character sequence CRLF is used, dot does
+       not match CR if it is immediately followed  by  LF,  but  otherwise  it
+       matches  all characters (including isolated CRs and LFs). When any Uni-
+       code line endings are being recognized, dot does not match CR or LF  or
+       any of the other line ending characters.
+
+       The  behaviour  of  dot  with regard to newlines can be changed. If the
+       PCRE_DOTALL option is set, a dot matches  any  one  character,  without
+       exception. If the two-character sequence CRLF is present in the subject
+       string, it takes two dots to match it.
+
+       The handling of dot is entirely independent of the handling of  circum-
+       flex  and  dollar,  the  only relationship being that they both involve
        newlines. Dot has no special meaning in a character class.
 
 
 MATCHING A SINGLE BYTE
 
        Outside a character class, the escape sequence \C matches any one byte,
-       both in and out of UTF-8 mode. Unlike a dot, it always matches  CR  and
-       LF.  The feature is provided in Perl in order to match individual bytes
-       in UTF-8 mode.  Because it breaks up UTF-8 characters  into  individual
-       bytes,  what remains in the string may be a malformed UTF-8 string. For
-       this reason, the \C escape sequence is best avoided.
+       both  in  and  out  of  UTF-8 mode. Unlike a dot, it always matches any
+       line-ending characters. The feature is provided in  Perl  in  order  to
+       match  individual bytes in UTF-8 mode. Because it breaks up UTF-8 char-
+       acters into individual bytes, what remains in the string may be a  mal-
+       formed  UTF-8  string.  For this reason, the \C escape sequence is best
+       avoided.
 
        PCRE does not allow \C to appear in  lookbehind  assertions  (described
        below),  because  in UTF-8 mode this would make it impossible to calcu-
@@ -3067,11 +3192,11 @@ SQUARE BRACKETS AND CHARACTER CLASSES
        PCRE  is  compiled  with Unicode property support as well as with UTF-8
        support.
 
-       Characters that might indicate  line  breaks  (CR  and  LF)  are  never
-       treated  in  any  special way when matching character classes, whatever
-       line-ending sequence is in use, and whatever setting of the PCRE_DOTALL
-       and PCRE_MULTILINE options is used. A class such as [^a] always matches
-       one of these characters.
+       Characters that might indicate line breaks are  never  treated  in  any
+       special  way  when  matching  character  classes,  whatever line-ending
+       sequence is in  use,  and  whatever  setting  of  the  PCRE_DOTALL  and
+       PCRE_MULTILINE options is used. A class such as [^a] always matches one
+       of these characters.
 
        The minus (hyphen) character can be used to specify a range of  charac-
        ters  in  a  character  class.  For  example,  [d-m] matches any letter
@@ -3203,26 +3328,27 @@ INTERNAL OPTION SETTING
        PCRE extracts it into the global options (and it will therefore show up
        in data extracted by the pcre_fullinfo() function).
 
-       An option change within a subpattern affects only that part of the cur-
-       rent pattern that follows it, so
+       An  option  change  within a subpattern (see below for a description of
+       subpatterns) affects only that part of the current pattern that follows
+       it, so
 
          (a(?i)b)c
 
        matches abc and aBc and no other strings (assuming PCRE_CASELESS is not
-       used).   By  this means, options can be made to have different settings
-       in different parts of the pattern. Any changes made in one  alternative
-       do  carry  on  into subsequent branches within the same subpattern. For
+       used).  By this means, options can be made to have  different  settings
+       in  different parts of the pattern. Any changes made in one alternative
+       do carry on into subsequent branches within the  same  subpattern.  For
        example,
 
          (a(?i)b|c)
 
-       matches "ab", "aB", "c", and "C", even though  when  matching  "C"  the
-       first  branch  is  abandoned before the option setting. This is because
-       the effects of option settings happen at compile time. There  would  be
+       matches  "ab",  "aB",  "c",  and "C", even though when matching "C" the
+       first branch is abandoned before the option setting.  This  is  because
+       the  effects  of option settings happen at compile time. There would be
        some very weird behaviour otherwise.
 
-       The  PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and PCRE_EXTRA
-       can be changed in the same way as the Perl-compatible options by  using
+       The PCRE-specific options PCRE_DUPNAMES, PCRE_UNGREEDY, and  PCRE_EXTRA
+       can  be changed in the same way as the Perl-compatible options by using
        the characters J, U and X respectively.
 
 
@@ -3235,18 +3361,18 @@ SUBPATTERNS
 
          cat(aract|erpillar|)
 
-       matches one of the words "cat", "cataract", or  "caterpillar".  Without
-       the  parentheses,  it  would  match "cataract", "erpillar" or the empty
+       matches  one  of the words "cat", "cataract", or "caterpillar". Without
+       the parentheses, it would match  "cataract",  "erpillar"  or  an  empty
        string.
 
-       2. It sets up the subpattern as  a  capturing  subpattern.  This  means
-       that,  when  the  whole  pattern  matches,  that portion of the subject
+       2.  It  sets  up  the  subpattern as a capturing subpattern. This means
+       that, when the whole pattern  matches,  that  portion  of  the  subject
        string that matched the subpattern is passed back to the caller via the
-       ovector  argument  of pcre_exec(). Opening parentheses are counted from
-       left to right (starting from 1) to obtain  numbers  for  the  capturing
+       ovector argument of pcre_exec(). Opening parentheses are  counted  from
+       left  to  right  (starting  from 1) to obtain numbers for the capturing
        subpatterns.
 
-       For  example,  if the string "the red king" is matched against the pat-
+       For example, if the string "the red king" is matched against  the  pat-
        tern
 
          the ((red|white) (king|queen))
@@ -3254,51 +3380,56 @@ SUBPATTERNS
        the captured substrings are "red king", "red", and "king", and are num-
        bered 1, 2, and 3, respectively.
 
-       The  fact  that  plain  parentheses  fulfil two functions is not always
-       helpful.  There are often times when a grouping subpattern is  required
-       without  a capturing requirement. If an opening parenthesis is followed
-       by a question mark and a colon, the subpattern does not do any  captur-
-       ing,  and  is  not  counted when computing the number of any subsequent
-       capturing subpatterns. For example, if the string "the white queen"  is
+       The fact that plain parentheses fulfil  two  functions  is  not  always
+       helpful.   There are often times when a grouping subpattern is required
+       without a capturing requirement. If an opening parenthesis is  followed
+       by  a question mark and a colon, the subpattern does not do any captur-
+       ing, and is not counted when computing the  number  of  any  subsequent
+       capturing  subpatterns. For example, if the string "the white queen" is
        matched against the pattern
 
          the ((?:red|white) (king|queen))
 
        the captured substrings are "white queen" and "queen", and are numbered
-       1 and 2. The maximum number of capturing subpatterns is 65535, and  the
-       maximum  depth  of  nesting of all subpatterns, both capturing and non-
-       capturing, is 200.
+       1 and 2. The maximum number of capturing subpatterns is 65535.
 
-       As a convenient shorthand, if any option settings are required  at  the
-       start  of  a  non-capturing  subpattern,  the option letters may appear
+       As  a  convenient shorthand, if any option settings are required at the
+       start of a non-capturing subpattern,  the  option  letters  may  appear
        between the "?" and the ":". Thus the two patterns
 
          (?i:saturday|sunday)
          (?:(?i)saturday|sunday)
 
        match exactly the same set of strings. Because alternative branches are
-       tried  from  left  to right, and options are not reset until the end of
-       the subpattern is reached, an option setting in one branch does  affect
-       subsequent  branches,  so  the above patterns match "SUNDAY" as well as
+       tried from left to right, and options are not reset until  the  end  of
+       the  subpattern is reached, an option setting in one branch does affect
+       subsequent branches, so the above patterns match "SUNDAY"  as  well  as
        "Saturday".
 
 
 NAMED SUBPATTERNS
 
-       Identifying capturing parentheses by number is simple, but  it  can  be
-       very  hard  to keep track of the numbers in complicated regular expres-
-       sions. Furthermore, if an  expression  is  modified,  the  numbers  may
-       change.  To help with this difficulty, PCRE supports the naming of sub-
-       patterns, something that Perl  does  not  provide.  The  Python  syntax
-       (?P<name>...)  is  used. References to capturing parentheses from other
-       parts of the pattern, such as  backreferences,  recursion,  and  condi-
-       tions, can be made by name as well as by number.
-
-       Names  consist  of  up  to  32 alphanumeric characters and underscores.
-       Named capturing parentheses are still  allocated  numbers  as  well  as
-       names. The PCRE API provides function calls for extracting the name-to-
-       number translation table from a compiled pattern. There is also a  con-
-       venience function for extracting a captured substring by name.
+       Identifying  capturing  parentheses  by number is simple, but it can be
+       very hard to keep track of the numbers in complicated  regular  expres-
+       sions.  Furthermore,  if  an  expression  is  modified, the numbers may
+       change. To help with this difficulty, PCRE supports the naming of  sub-
+       patterns. This feature was not added to Perl until release 5.10. Python
+       had the feature earlier, and PCRE introduced it at release  4.0,  using
+       the  Python syntax. PCRE now supports both the Perl and the Python syn-
+       tax.
+
+       In PCRE, a subpattern can be named in one of three  ways:  (?<name>...)
+       or  (?'name'...)  as in Perl, or (?P<name>...) as in Python. References
+       to capturing parentheses from other parts of the pattern, such as back-
+       references,  recursion,  and conditions, can be made by name as well as
+       by number.
+
+       Names consist of up to  32  alphanumeric  characters  and  underscores.
+       Named  capturing  parentheses  are  still  allocated numbers as well as
+       names, exactly as if the names were not present. The PCRE API  provides
+       function calls for extracting the name-to-number translation table from
+       a compiled pattern. There is also a convenience function for extracting
+       a captured substring by name.
 
        By  default, a name must be unique within a pattern, but it is possible
        to relax this constraint by setting the PCRE_DUPNAMES option at compile
@@ -3308,15 +3439,15 @@ NAMED SUBPATTERNS
        both cases you want to extract the abbreviation. This pattern (ignoring
        the line breaks) does the job:
 
-         (?P<DN>Mon|Fri|Sun)(?:day)?|
-         (?P<DN>Tue)(?:sday)?|
-         (?P<DN>Wed)(?:nesday)?|
-         (?P<DN>Thu)(?:rsday)?|
-         (?P<DN>Sat)(?:urday)?
+         (?<DN>Mon|Fri|Sun)(?:day)?|
+         (?<DN>Tue)(?:sday)?|
+         (?<DN>Wed)(?:nesday)?|
+         (?<DN>Thu)(?:rsday)?|
+         (?<DN>Sat)(?:urday)?
 
        There  are  five capturing substrings, but only one is ever set after a
        match.  The convenience  function  for  extracting  the  data  by  name
-       returns  the  substring  for  the first, and in this example, the only,
+       returns  the  substring  for  the first (and in this example, the only)
        subpattern of that name that matched.  This  saves  searching  to  find
        which  numbered  subpattern  it  was. If you make a reference to a non-
        unique named subpattern from elsewhere in the  pattern,  the  one  that
@@ -3331,9 +3462,10 @@ REPETITION
        following items:
 
          a literal data character
-         the . metacharacter
+         the dot metacharacter
          the \C escape sequence
          the \X escape sequence (in UTF-8 mode with Unicode properties)
+         the \R escape sequence
          an escape such as \d that matches a single character
          a character class
          a back reference (see next section)
@@ -3373,8 +3505,8 @@ REPETITION
        The quantifier {0} is permitted, causing the expression to behave as if
        the previous item and the quantifier were not present.
 
-       For  convenience  (and  historical compatibility) the three most common
-       quantifiers have single-character abbreviations:
+       For  convenience, the three most common quantifiers have single-charac-
+       ter abbreviations:
 
          *    is equivalent to {0,}
          +    is equivalent to {1,}
@@ -3426,7 +3558,7 @@ REPETITION
        which matches one digit by preference, but can match two if that is the
        only way the rest of the pattern matches.
 
-       If the PCRE_UNGREEDY option is set (an option which is not available in
+       If the PCRE_UNGREEDY option is set (an option that is not available  in
        Perl),  the  quantifiers are not greedy by default, but individual ones
        can be made greedy by following them with a  question  mark.  In  other
        words, it inverts the default behaviour.
@@ -3437,24 +3569,25 @@ REPETITION
        minimum or maximum.
 
        If a pattern starts with .* or .{0,} and the PCRE_DOTALL option (equiv-
-       alent  to Perl's /s) is set, thus allowing the . to match newlines, the
-       pattern is implicitly anchored, because whatever follows will be  tried
-       against  every character position in the subject string, so there is no
-       point in retrying the overall match at any position  after  the  first.
-       PCRE normally treats such a pattern as though it were preceded by \A.
-
-       In  cases  where  it  is known that the subject string contains no new-
-       lines, it is worth setting PCRE_DOTALL in order to  obtain  this  opti-
+       alent  to  Perl's  /s) is set, thus allowing the dot to match newlines,
+       the pattern is implicitly anchored, because whatever  follows  will  be
+       tried  against every character position in the subject string, so there
+       is no point in retrying the overall match at  any  position  after  the
+       first.  PCRE  normally treats such a pattern as though it were preceded
+       by \A.
+
+       In cases where it is known that the subject  string  contains  no  new-
+       lines,  it  is  worth setting PCRE_DOTALL in order to obtain this opti-
        mization, or alternatively using ^ to indicate anchoring explicitly.
 
-       However,  there is one situation where the optimization cannot be used.
-       When .*  is inside capturing parentheses that  are  the  subject  of  a
-       backreference  elsewhere in the pattern, a match at the start may fail,
-       and a later one succeed. Consider, for example:
+       However, there is one situation where the optimization cannot be  used.
+       When  .*   is  inside  capturing  parentheses that are the subject of a
+       backreference elsewhere in the pattern, a match at the start  may  fail
+       where a later one succeeds. Consider, for example:
 
          (.*)abc\1
 
-       If the subject is "xyz123abc123" the match point is the fourth  charac-
+       If  the subject is "xyz123abc123" the match point is the fourth charac-
        ter. For this reason, such a pattern is not implicitly anchored.
 
        When a capturing subpattern is repeated, the value captured is the sub-
@@ -3463,8 +3596,8 @@ REPETITION
          (tweedle[dume]{3}\s*)+
 
        has matched "tweedledum tweedledee" the value of the captured substring
-       is  "tweedledee".  However,  if there are nested capturing subpatterns,
-       the corresponding captured values may have been set in previous  itera-
+       is "tweedledee". However, if there are  nested  capturing  subpatterns,
+       the  corresponding captured values may have been set in previous itera-
        tions. For example, after
 
          /(a|(b))+/
@@ -3474,12 +3607,13 @@ REPETITION
 
 ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS
 
-       With both maximizing and minimizing repetition, failure of what follows
-       normally causes the repeated item to be re-evaluated to see if  a  dif-
-       ferent number of repeats allows the rest of the pattern to match. Some-
-       times it is useful to prevent this, either to change the nature of  the
-       match,  or  to  cause it fail earlier than it otherwise might, when the
-       author of the pattern knows there is no point in carrying on.
+       With both maximizing ("greedy") and minimizing ("ungreedy"  or  "lazy")
+       repetition,  failure  of what follows normally causes the repeated item
+       to be re-evaluated to see if a different number of repeats  allows  the
+       rest  of  the pattern to match. Sometimes it is useful to prevent this,
+       either to change the nature of the match, or to cause it  fail  earlier
+       than  it otherwise might, when the author of the pattern knows there is
+       no point in carrying on.
 
        Consider, for example, the pattern \d+foo when applied to  the  subject
        line
@@ -3493,10 +3627,9 @@ ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS
        the  means for specifying that once a subpattern has matched, it is not
        to be re-evaluated in this way.
 
-       If we use atomic grouping for the previous example, the  matcher  would
-       give up immediately on failing to match "foo" the first time. The nota-
-       tion is a kind of special parenthesis, starting with  (?>  as  in  this
-       example:
+       If we use atomic grouping for the previous example, the  matcher  gives
+       up  immediately  on failing to match "foo" the first time. The notation
+       is a kind of special parenthesis, starting with (?> as in this example:
 
          (?>\d+)foo
 
@@ -3528,63 +3661,95 @@ ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS
        Possessive  quantifiers  are  always  greedy;  the   setting   of   the
        PCRE_UNGREEDY option is ignored. They are a convenient notation for the
        simpler forms of atomic group. However, there is no difference  in  the
-       meaning  or  processing  of  a possessive quantifier and the equivalent
-       atomic group.
-
-       The possessive quantifier syntax is an extension to  the  Perl  syntax.
-       Jeffrey  Friedl originated the idea (and the name) in the first edition
-       of his book.  Mike McCloskey liked it, so implemented it when he  built
-       Sun's Java package, and PCRE copied it from there.
-
-       When  a  pattern  contains an unlimited repeat inside a subpattern that
-       can itself be repeated an unlimited number of  times,  the  use  of  an
-       atomic  group  is  the  only way to avoid some failing matches taking a
+       meaning  of  a  possessive  quantifier and the equivalent atomic group,
+       though there may be a performance  difference;  possessive  quantifiers
+       should be slightly faster.
+
+       The  possessive  quantifier syntax is an extension to the Perl 5.8 syn-
+       tax.  Jeffrey Friedl originated the idea (and the name)  in  the  first
+       edition of his book. Mike McCloskey liked it, so implemented it when he
+       built Sun's Java package, and PCRE copied it from there. It  ultimately
+       found its way into Perl at release 5.10.
+
+       PCRE has an optimization that automatically "possessifies" certain sim-
+       ple pattern constructs. For example, the sequence  A+B  is  treated  as
+       A++B  because  there is no point in backtracking into a sequence of A's
+       when B must follow.
+
+       When a pattern contains an unlimited repeat inside  a  subpattern  that
+       can  itself  be  repeated  an  unlimited number of times, the use of an
+       atomic group is the only way to avoid some  failing  matches  taking  a
        very long time indeed. The pattern
 
          (\D+|<\d+>)*[!?]
 
-       matches an unlimited number of substrings that either consist  of  non-
-       digits,  or  digits  enclosed in <>, followed by either ! or ?. When it
+       matches  an  unlimited number of substrings that either consist of non-
+       digits, or digits enclosed in <>, followed by either ! or  ?.  When  it
        matches, it runs quickly. However, if it is applied to
 
          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
-       it takes a long time before reporting  failure.  This  is  because  the
-       string  can be divided between the internal \D+ repeat and the external
-       * repeat in a large number of ways, and all  have  to  be  tried.  (The
-       example  uses  [!?]  rather than a single character at the end, because
-       both PCRE and Perl have an optimization that allows  for  fast  failure
-       when  a single character is used. They remember the last single charac-
-       ter that is required for a match, and fail early if it is  not  present
-       in  the  string.)  If  the pattern is changed so that it uses an atomic
+       it  takes  a  long  time  before reporting failure. This is because the
+       string can be divided between the internal \D+ repeat and the  external
+       *  repeat  in  a  large  number of ways, and all have to be tried. (The
+       example uses [!?] rather than a single character at  the  end,  because
+       both  PCRE  and  Perl have an optimization that allows for fast failure
+       when a single character is used. They remember the last single  charac-
+       ter  that  is required for a match, and fail early if it is not present
+       in the string.) If the pattern is changed so that  it  uses  an  atomic
        group, like this:
 
          ((?>\D+)|<\d+>)*[!?]
 
-       sequences of non-digits cannot be broken, and failure happens  quickly.
+       sequences  of non-digits cannot be broken, and failure happens quickly.
 
 
 BACK REFERENCES
 
        Outside a character class, a backslash followed by a digit greater than
        0 (and possibly further digits) is a back reference to a capturing sub-
-       pattern  earlier  (that is, to its left) in the pattern, provided there
+       pattern earlier (that is, to its left) in the pattern,  provided  there
        have been that many previous capturing left parentheses.
 
        However, if the decimal number following the backslash is less than 10,
-       it  is  always  taken  as a back reference, and causes an error only if
-       there are not that many capturing left parentheses in the  entire  pat-
-       tern.  In  other words, the parentheses that are referenced need not be
-       to the left of the reference for numbers less than 10. A "forward  back
-       reference"  of  this  type can make sense when a repetition is involved
-       and the subpattern to the right has participated in an  earlier  itera-
+       it is always taken as a back reference, and causes  an  error  only  if
+       there  are  not that many capturing left parentheses in the entire pat-
+       tern. In other words, the parentheses that are referenced need  not  be
+       to  the left of the reference for numbers less than 10. A "forward back
+       reference" of this type can make sense when a  repetition  is  involved
+       and  the  subpattern to the right has participated in an earlier itera-
        tion.
 
-       It is not possible to have a numerical "forward back reference" to sub-
-       pattern whose number is 10 or more. However, a back  reference  to  any
-       subpattern  is  possible  using named parentheses (see below). See also
-       the subsection entitled "Non-printing  characters"  above  for  further
-       details of the handling of digits following a backslash.
+       It is not possible to have a numerical "forward back  reference"  to  a
+       subpattern  whose  number  is  10  or  more using this syntax because a
+       sequence such as \50 is interpreted as a character  defined  in  octal.
+       See the subsection entitled "Non-printing characters" above for further
+       details of the handling of digits following a backslash.  There  is  no
+       such  problem  when named parentheses are used. A back reference to any
+       subpattern is possible using named parentheses (see below).
+
+       Another way of avoiding the ambiguity inherent in  the  use  of  digits
+       following a backslash is to use the \g escape sequence, which is a fea-
+       ture introduced in Perl 5.10. This escape must be followed by  a  posi-
+       tive  or  a negative number, optionally enclosed in braces. These exam-
+       ples are all identical:
+
+         (ring), \1
+         (ring), \g1
+         (ring), \g{1}
+
+       A positive number specifies an absolute reference without the ambiguity
+       that  is  present  in  the older syntax. It is also useful when literal
+       digits follow the reference. A negative number is a relative reference.
+       Consider this example:
+
+         (abc(def)ghi)\g{-1}
+
+       The sequence \g{-1} is a reference to the most recently started captur-
+       ing subpattern before \g, that is, is it equivalent to  \2.  Similarly,
+       \g{-2} would be equivalent to \1. The use of relative references can be
+       helpful in long patterns, and also in  patterns  that  are  created  by
+       joining together fragments that contain references within themselves.
 
        A  back  reference matches whatever actually matched the capturing sub-
        pattern in the current subject string, rather  than  anything  matching
@@ -3603,62 +3768,64 @@ BACK REFERENCES
        matches  "rah  rah"  and  "RAH RAH", but not "RAH rah", even though the
        original capturing subpattern is matched caselessly.
 
-       Back references to named subpatterns use the Python  syntax  (?P=name).
-       We could rewrite the above example as follows:
+       Back references to named subpatterns use the Perl  syntax  \k<name>  or
+       \k'name'  or  the  Python  syntax (?P=name). We could rewrite the above
+       example in either of the following ways:
 
+         (?<p1>(?i)rah)\s+\k<p1>
          (?P<p1>(?i)rah)\s+(?P=p1)
 
-       A  subpattern  that  is  referenced  by  name may appear in the pattern
+       A subpattern that is referenced by  name  may  appear  in  the  pattern
        before or after the reference.
 
-       There may be more than one back reference to the same subpattern. If  a
-       subpattern  has  not actually been used in a particular match, any back
+       There  may be more than one back reference to the same subpattern. If a
+       subpattern has not actually been used in a particular match,  any  back
        references to it always fail. For example, the pattern
 
          (a|(bc))\2
 
-       always fails if it starts to match "a" rather than "bc". Because  there
-       may  be  many  capturing parentheses in a pattern, all digits following
-       the backslash are taken as part of a potential back  reference  number.
+       always  fails if it starts to match "a" rather than "bc". Because there
+       may be many capturing parentheses in a pattern,  all  digits  following
+       the  backslash  are taken as part of a potential back reference number.
        If the pattern continues with a digit character, some delimiter must be
-       used to terminate the back reference. If the  PCRE_EXTENDED  option  is
-       set,  this  can  be  whitespace.  Otherwise an empty comment (see "Com-
+       used  to  terminate  the back reference. If the PCRE_EXTENDED option is
+       set, this can be whitespace.  Otherwise an  empty  comment  (see  "Com-
        ments" below) 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  sub-
+       A  back reference that occurs inside the parentheses to which it refers
+       fails when the subpattern is first used, so, for example,  (a\1)  never
+       matches.   However,  such references can be useful inside repeated sub-
        patterns. For example, the pattern
 
          (a|b\1)+
 
        matches any number of "a"s and also "aba", "ababbaa" etc. At each iter-
-       ation of the subpattern,  the  back  reference  matches  the  character
-       string  corresponding  to  the previous iteration. In order for this to
-       work, the pattern must be such that the first iteration does  not  need
-       to  match the back reference. This can be done using alternation, as in
+       ation  of  the  subpattern,  the  back  reference matches the character
+       string corresponding to the previous iteration. In order  for  this  to
+       work,  the  pattern must be such that the first iteration does not need
+       to match the back reference. This can be done using alternation, as  in
        the example above, or by a quantifier with a minimum of zero.
 
 
 ASSERTIONS
 
-       An assertion is a test on the characters  following  or  preceding  the
-       current  matching  point that does not actually consume any characters.
-       The simple assertions coded as \b, \B, \A, \G, \Z,  \z,  ^  and  $  are
+       An  assertion  is  a  test on the characters following or preceding the
+       current matching point that does not actually consume  any  characters.
+       The  simple  assertions  coded  as  \b, \B, \A, \G, \Z, \z, ^ and $ are
        described above.
 
-       More  complicated  assertions  are  coded as subpatterns. There are two
-       kinds: those that look ahead of the current  position  in  the  subject
-       string,  and  those  that  look  behind  it. An assertion subpattern is
-       matched in the normal way, except that it does not  cause  the  current
+       More complicated assertions are coded as  subpatterns.  There  are  two
+       kinds:  those  that  look  ahead of the current position in the subject
+       string, and those that look  behind  it.  An  assertion  subpattern  is
+       matched  in  the  normal way, except that it does not cause the current
        matching position to be changed.
 
-       Assertion  subpatterns  are  not  capturing subpatterns, and may not be
-       repeated, because it makes no sense to assert the  same  thing  several
-       times.  If  any kind of assertion contains capturing subpatterns within
-       it, these are counted for the purposes of numbering the capturing  sub-
+       Assertion subpatterns are not capturing subpatterns,  and  may  not  be
+       repeated,  because  it  makes no sense to assert the same thing several
+       times. If any kind of assertion contains capturing  subpatterns  within
+       it,  these are counted for the purposes of numbering the capturing sub-
        patterns in the whole pattern.  However, substring capturing is carried
-       out only for positive assertions, because it does not  make  sense  for
+       out  only  for  positive assertions, because it does not make sense for
        negative assertions.
 
    Lookahead assertions
@@ -3668,37 +3835,37 @@ ASSERTIONS
 
          \w+(?=;)
 
-       matches a word followed by a semicolon, but does not include the  semi-
+       matches  a word followed by a semicolon, but does not include the semi-
        colon in the match, and
 
          foo(?!bar)
 
-       matches  any  occurrence  of  "foo" that is not followed by "bar". Note
+       matches any occurrence of "foo" that is not  followed  by  "bar".  Note
        that the apparently similar pattern
 
          (?!foo)bar
 
-       does not find an occurrence of "bar"  that  is  preceded  by  something
-       other  than "foo"; it finds any occurrence of "bar" whatsoever, because
+       does  not  find  an  occurrence  of "bar" that is preceded by something
+       other than "foo"; it finds any occurrence of "bar" whatsoever,  because
        the assertion (?!foo) is always true when the next three characters are
        "bar". A lookbehind assertion is needed to achieve the other effect.
 
        If you want to force a matching failure at some point in a pattern, the
-       most convenient way to do it is  with  (?!)  because  an  empty  string
-       always  matches, so an assertion that requires there not to be an empty
+       most  convenient  way  to  do  it  is with (?!) because an empty string
+       always matches, so an assertion that requires there not to be an  empty
        string must always fail.
 
    Lookbehind assertions
 
-       Lookbehind assertions start with (?<= for positive assertions and  (?<!
+       Lookbehind  assertions start with (?<= for positive assertions and (?<!
        for negative assertions. For example,
 
          (?<!foo)bar
 
-       does  find  an  occurrence  of "bar" that is not preceded by "foo". The
-       contents of a lookbehind assertion are restricted  such  that  all  the
+       does find an occurrence of "bar" that is not  preceded  by  "foo".  The
+       contents  of  a  lookbehind  assertion are restricted such that all the
        strings it matches must have a fixed length. However, if there are sev-
-       eral top-level alternatives, they do not all  have  to  have  the  same
+       eral  top-level  alternatives,  they  do  not all have to have the same
        fixed length. Thus
 
          (?<=bullock|donkey)
@@ -3707,59 +3874,55 @@ ASSERTIONS
 
          (?<!dogs?|cats?)
 
-       causes  an  error at compile time. Branches that match different length
-       strings are permitted only at the top level of a lookbehind  assertion.
-       This  is  an  extension  compared  with  Perl (at least for 5.8), which
-       requires all branches to match the same length of string. An  assertion
+       causes an error at compile time. Branches that match  different  length
+       strings  are permitted only at the top level of a lookbehind assertion.
+       This is an extension compared with  Perl  (at  least  for  5.8),  which
+       requires  all branches to match the same length of string. An assertion
        such as
 
          (?<=ab(c|de))
 
-       is  not  permitted,  because  its single top-level branch can match two
-       different lengths, but it is acceptable if rewritten to  use  two  top-
+       is not permitted, because its single top-level  branch  can  match  two
+       different  lengths,  but  it is acceptable if rewritten to use two top-
        level branches:
 
          (?<=abc|abde)
 
-       The  implementation  of lookbehind assertions is, for each alternative,
-       to temporarily move the current position back by the  fixed  width  and
+       The implementation of lookbehind assertions is, for  each  alternative,
+       to  temporarily  move the current position back by the fixed length and
        then try to match. If there are insufficient characters before the cur-
-       rent position, the match is deemed to fail.
+       rent position, the assertion fails.
 
        PCRE does not allow the \C escape (which matches a single byte in UTF-8
-       mode)  to appear in lookbehind assertions, because it makes it impossi-
-       ble to calculate the length of the lookbehind. The \X escape, which can
-       match different numbers of bytes, is also not permitted.
+       mode) to appear in lookbehind assertions, because it makes it  impossi-
+       ble  to  calculate the length of the lookbehind. The \X and \R escapes,
+       which can match different numbers of bytes, are also not permitted.
 
-       Atomic  groups can be used in conjunction with lookbehind assertions to
-       specify efficient matching at the end of the subject string. Consider a
-       simple pattern such as
+       Possessive quantifiers can  be  used  in  conjunction  with  lookbehind
+       assertions  to  specify  efficient  matching  at the end of the subject
+       string. Consider a simple pattern such as
 
          abcd$
 
-       when  applied  to  a  long string that does not match. Because matching
+       when applied to a long string that does  not  match.  Because  matching
        proceeds from left to right, PCRE will look for each "a" in the subject
-       and  then  see  if what follows matches the rest of the pattern. If the
+       and then see if what follows matches the rest of the  pattern.  If  the
        pattern is specified as
 
          ^.*abcd$
 
-       the initial .* matches the entire string at first, but when this  fails
+       the  initial .* matches the entire string at first, but when this fails
        (because there is no following "a"), it backtracks to match all but the
-       last character, then all but the last two characters, and so  on.  Once
-       again  the search for "a" covers the entire string, from right to left,
+       last  character,  then all but the last two characters, and so on. Once
+       again the search for "a" covers the entire string, from right to  left,
        so we are no better off. However, if the pattern is written as
 
-         ^(?>.*)(?<=abcd)
-
-       or, equivalently, using the possessive quantifier syntax,
-
          ^.*+(?<=abcd)
 
-       there can be no backtracking for the .* item; it  can  match  only  the
-       entire  string.  The subsequent lookbehind assertion does a single test
-       on the last four characters. If it fails, the match fails  immediately.
-       For  long  strings, this approach makes a significant difference to the
+       there  can  be  no backtracking for the .*+ item; it can match only the
+       entire string. The subsequent lookbehind assertion does a  single  test
+       on  the last four characters. If it fails, the match fails immediately.
+       For long strings, this approach makes a significant difference  to  the
        processing time.
 
    Using multiple assertions
@@ -3768,18 +3931,18 @@ ASSERTIONS
 
          (?<=\d{3})(?<!999)foo
 
-       matches "foo" preceded by three digits that are not "999". Notice  that
-       each  of  the  assertions is applied independently at the same point in
-       the subject string. First there is a  check  that  the  previous  three
-       characters  are  all  digits,  and  then there is a check that the same
+       matches  "foo" preceded by three digits that are not "999". Notice that
+       each of the assertions is applied independently at the  same  point  in
+       the  subject  string.  First  there  is a check that the previous three
+       characters are all digits, and then there is  a  check  that  the  same
        three characters are not "999".  This pattern does not match "foo" pre-
-       ceded  by  six  characters,  the first of which are digits and the last
-       three of which are not "999". For example, it  doesn't  match  "123abc-
+       ceded by six characters, the first of which are  digits  and  the  last
+       three  of  which  are not "999". For example, it doesn't match "123abc-
        foo". A pattern to do that is
 
          (?<=\d{3}...)(?<!999)foo
 
-       This  time  the  first assertion looks at the preceding six characters,
+       This time the first assertion looks at the  preceding  six  characters,
        checking that the first three are digits, and then the second assertion
        checks that the preceding three characters are not "999".
 
@@ -3787,39 +3950,38 @@ ASSERTIONS
 
          (?<=(?<!foo)bar)baz
 
-       matches  an occurrence of "baz" that is preceded by "bar" which in turn
+       matches an occurrence of "baz" that is preceded by "bar" which in  turn
        is not preceded by "foo", while
 
          (?<=\d{3}(?!999)...)foo
 
-       is another pattern that matches "foo" preceded by three digits and  any
+       is  another pattern that matches "foo" preceded by three digits and any
        three characters that are not "999".
 
 
 CONDITIONAL SUBPATTERNS
 
-       It  is possible to cause the matching process to obey a subpattern con-
-       ditionally or to choose between two alternative subpatterns,  depending
-       on  the result of an assertion, or whether a previous capturing subpat-
-       tern matched or not. The two possible forms of  conditional  subpattern
+       It is possible to cause the matching process to obey a subpattern  con-
+       ditionally  or to choose between two alternative subpatterns, depending
+       on the result of an assertion, or whether a previous capturing  subpat-
+       tern  matched  or not. The two possible forms of conditional subpattern
        are
 
          (?(condition)yes-pattern)
          (?(condition)yes-pattern|no-pattern)
 
-       If  the  condition is satisfied, the yes-pattern is used; otherwise the
-       no-pattern (if present) is used. If there are more  than  two  alterna-
+       If the condition is satisfied, the yes-pattern is used;  otherwise  the
+       no-pattern  (if  present)  is used. If there are more than two alterna-
        tives in the subpattern, a compile-time error occurs.
 
-       There are three kinds of condition. If the text between the parentheses
-       consists of a sequence of digits, or a sequence of alphanumeric charac-
-       ters  and underscores, the condition is satisfied if the capturing sub-
-       pattern of that number or name has previously matched. There is a  pos-
-       sible  ambiguity here, because subpattern names may consist entirely of
-       digits. PCRE looks first for a named subpattern; if it cannot find  one
-       and  the text consists entirely of digits, it looks for a subpattern of
-       that number, which must be greater than zero.  Using  subpattern  names
-       that consist entirely of digits is not recommended.
+       There are four kinds of condition: references  to  subpatterns,  refer-
+       ences to recursion, a pseudo-condition called DEFINE, and assertions.
+
+   Checking for a used subpattern by number
+
+       If  the  text between the parentheses consists of a sequence of digits,
+       the condition is true 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
@@ -3836,18 +3998,68 @@ CONDITIONAL SUBPATTERNS
        tern  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. Rewriting it to use a named subpat-
-       tern gives this:
+       optionally enclosed in parentheses.
+
+   Checking for a used subpattern by name
+
+       Perl uses the syntax (?(<name>)...) or (?('name')...)  to  test  for  a
+       used  subpattern  by  name.  For compatibility with earlier versions of
+       PCRE, which had this facility before Perl, the syntax  (?(name)...)  is
+       also  recognized. However, there is a possible ambiguity with this syn-
+       tax, because subpattern names may  consist  entirely  of  digits.  PCRE
+       looks  first for a named subpattern; if it cannot find one and the name
+       consists entirely of digits, PCRE looks for a subpattern of  that  num-
+       ber,  which must be greater than zero. Using subpattern names that con-
+       sist entirely of digits is not recommended.
+
+       Rewriting the above example to use a named subpattern gives this:
+
+         (?<OPEN> \( )?    [^()]+    (?(<OPEN>) \) )
+
 
-         (?P<OPEN> \( )?    [^()]+    (?(OPEN) \) )
+   Checking for pattern recursion
 
        If the condition is the string (R), and there is no subpattern with the
-       name R, the condition is satisfied if a recursive call to  the  pattern
-       or  subpattern  has  been made. At "top level", the condition is false.
-       This is a PCRE extension.  Recursive patterns are described in the next
-       section.
+       name  R, the condition is true if a recursive call to the whole pattern
+       or any subpattern has been made. If digits or a name preceded by amper-
+       sand follow the letter R, for example:
+
+         (?(R3)...) or (?(R&name)...)
+
+       the  condition is true if the most recent recursion is into the subpat-
+       tern whose number or name is given. This condition does not  check  the
+       entire recursion stack.
+
+       At  "top  level", all these recursion test conditions are false. Recur-
+       sive patterns are described below.
+
+   Defining subpatterns for use by reference only
+
+       If the condition is the string (DEFINE), and  there  is  no  subpattern
+       with  the  name  DEFINE,  the  condition is always false. In this case,
+       there may be only one alternative  in  the  subpattern.  It  is  always
+       skipped  if  control  reaches  this  point  in the pattern; the idea of
+       DEFINE is that it can be used to define "subroutines" that can be  ref-
+       erenced  from elsewhere. (The use of "subroutines" is described below.)
+       For example, a pattern to match an IPv4 address could be  written  like
+       this (ignore whitespace and line breaks):
+
+         (?(DEFINE) (?<byte> 2[0-4]\d | 25[0-5] | 1\d\d | [1-9]?\d) )
+         \b (?&byte) (\.(?&byte)){3} \b
+
+       The  first part of the pattern is a DEFINE group inside which a another
+       group named "byte" is defined. This matches an individual component  of
+       an  IPv4  address  (a number less than 256). When matching takes place,
+       this part of the pattern is skipped because DEFINE acts  like  a  false
+       condition.
 
-       If  the  condition  is  not  a sequence of digits or (R), it must be an
+       The rest of the pattern uses references to the named group to match the
+       four dot-separated components of an IPv4 address, insisting on  a  word
+       boundary at each end.
+
+   Assertion conditions
+
+       If  the  condition  is  not  in any of the above formats, it must be an
        assertion.  This may be a positive or negative lookahead or  lookbehind
        assertion.  Consider  this  pattern,  again  containing non-significant
        white space, and with the two alternatives on the second line:
@@ -3882,110 +4094,116 @@ RECURSIVE PATTERNS
        unlimited nested parentheses. Without the use of  recursion,  the  best
        that  can  be  done  is  to use a pattern that matches up to some fixed
        depth of nesting. It is not possible to  handle  an  arbitrary  nesting
-       depth.  Perl  provides  a  facility  that allows regular expressions to
-       recurse (amongst other things). It does this by interpolating Perl code
-       in the expression at run time, and the code can refer to the expression
-       itself. A Perl pattern to solve the parentheses problem can be  created
-       like this:
+       depth.
+
+       For some time, Perl has provided a facility that allows regular expres-
+       sions to recurse (amongst other things). It does this by  interpolating
+       Perl  code in the expression at run time, and the code can refer to the
+       expression itself. A Perl pattern using code interpolation to solve the
+       parentheses problem can be created like this:
 
          $re = qr{\( (?: (?>[^()]+) | (?p{$re}) )* \)}x;
 
        The (?p{...}) item interpolates Perl code at run time, and in this case
-       refers recursively to the pattern in which it appears. Obviously,  PCRE
-       cannot  support  the  interpolation  of Perl code. Instead, it supports
-       some special syntax for recursion of the entire pattern, and  also  for
-       individual subpattern recursion.
+       refers recursively to the pattern in which it appears.
+
+       Obviously, PCRE cannot support the interpolation of Perl code. Instead,
+       it  supports  special  syntax  for recursion of the entire pattern, and
+       also for individual subpattern recursion.  After  its  introduction  in
+       PCRE  and  Python,  this  kind of recursion was introduced into Perl at
+       release 5.10.
 
-       The  special item that consists of (? followed by a number greater than
+       A special item that consists of (? followed by a  number  greater  than
        zero and a closing parenthesis is a recursive call of the subpattern of
-       the  given  number, provided that it occurs inside that subpattern. (If
-       not, it is a "subroutine" call, which is described  in  the  next  sec-
-       tion.)  The special item (?R) is a recursive call of the entire regular
-       expression.
+       the given number, provided that it occurs inside that  subpattern.  (If
+       not,  it  is  a  "subroutine" call, which is described in the next sec-
+       tion.) The special item (?R) or (?0) is a recursive call of the  entire
+       regular expression.
 
-       A recursive subpattern call is always treated as an atomic group.  That
-       is,  once  it  has  matched some of the subject string, it is never re-
-       entered, even if it contains untried alternatives and there is a subse-
-       quent matching failure.
+       In  PCRE (like Python, but unlike Perl), a recursive subpattern call is
+       always treated as an atomic group. That is, once it has matched some of
+       the subject string, it is never re-entered, even if it contains untried
+       alternatives and there is a subsequent matching failure.
 
-       This  PCRE  pattern  solves  the nested parentheses problem (assume the
+       This PCRE pattern solves the nested  parentheses  problem  (assume  the
        PCRE_EXTENDED option is set so that white space is ignored):
 
          \( ( (?>[^()]+) | (?R) )* \)
 
-       First it matches an opening parenthesis. Then it matches any number  of
-       substrings  which  can  either  be  a sequence of non-parentheses, or a
-       recursive match of the pattern itself (that is, a  correctly  parenthe-
+       First  it matches an opening parenthesis. Then it matches any number of
+       substrings which can either be a  sequence  of  non-parentheses,  or  a
+       recursive  match  of the pattern itself (that is, a correctly parenthe-
        sized substring).  Finally there is a closing parenthesis.
 
-       If  this  were  part of a larger pattern, you would not want to recurse
+       If this were part of a larger pattern, you would not  want  to  recurse
        the entire pattern, so instead you could use this:
 
          ( \( ( (?>[^()]+) | (?1) )* \) )
 
-       We have put the pattern into parentheses, and caused the  recursion  to
-       refer  to them instead of the whole pattern. In a larger pattern, keep-
-       ing track of parenthesis numbers can be tricky. It may be  more  conve-
-       nient  to use named parentheses instead. For this, PCRE uses (?P>name),
-       which is an extension to the Python syntax that  PCRE  uses  for  named
-       parentheses (Perl does not provide named parentheses). We could rewrite
-       the above example as follows:
+       We  have  put the pattern into parentheses, and caused the recursion to
+       refer to them instead of the whole pattern. In a larger pattern,  keep-
+       ing  track  of parenthesis numbers can be tricky. It may be more conve-
+       nient to use named parentheses instead. The Perl  syntax  for  this  is
+       (?&name);  PCRE's  earlier syntax (?P>name) is also supported. We could
+       rewrite the above example as follows:
 
-         (?P<pn> \( ( (?>[^()]+) | (?P>pn) )* \) )
+         (?<pn> \( ( (?>[^()]+) | (?&pn) )* \) )
 
-       This particular example pattern contains nested unlimited repeats,  and
-       so  the  use of atomic grouping for matching strings of non-parentheses
-       is important when applying the pattern to strings that  do  not  match.
-       For example, when this pattern is applied to
+       If there is more than one subpattern with the same name,  the  earliest
+       one  is used. This particular example pattern contains nested unlimited
+       repeats, and so the use of atomic grouping for matching strings of non-
+       parentheses  is  important when applying the pattern to strings that do
+       not match. For example, when this pattern is applied to
 
          (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
 
-       it  yields "no match" quickly. However, if atomic grouping is not used,
-       the match runs for a very long time indeed because there  are  so  many
-       different  ways  the  + and * repeats can carve up the subject, and all
+       it yields "no match" quickly. However, if atomic grouping is not  used,
+       the  match  runs  for a very long time indeed because there are so many
+       different ways the + and * repeats can carve up the  subject,  and  all
        have to be tested before failure can be reported.
 
        At the end of a match, the values set for any capturing subpatterns are
        those from the outermost level of the recursion at which the subpattern
-       value is set.  If you want to obtain  intermediate  values,  a  callout
-       function can be used (see the next section and the pcrecallout documen-
-       tation). If the pattern above is matched against
+       value  is  set.   If  you want to obtain intermediate values, a callout
+       function can be used (see below and the pcrecallout documentation).  If
+       the pattern above is matched against
 
          (ab(cd)ef)
 
-       the value for the capturing parentheses is  "ef",  which  is  the  last
-       value  taken  on at the top level. If additional parentheses are added,
+       the  value  for  the  capturing  parentheses is "ef", which is the last
+       value taken on at the top level. If additional parentheses  are  added,
        giving
 
          \( ( ( (?>[^()]+) | (?R) )* ) \)
             ^                        ^
             ^                        ^
 
-       the string they capture is "ab(cd)ef", the contents of  the  top  level
-       parentheses.  If there are more than 15 capturing parentheses in a pat-
+       the  string  they  capture is "ab(cd)ef", the contents of the top level
+       parentheses. If there are more than 15 capturing parentheses in a  pat-
        tern, PCRE has to obtain extra memory to store data during a recursion,
-       which  it  does  by  using pcre_malloc, freeing it via pcre_free after-
-       wards. If  no  memory  can  be  obtained,  the  match  fails  with  the
+       which it does by using pcre_malloc, freeing  it  via  pcre_free  after-
+       wards.  If  no  memory  can  be  obtained,  the  match  fails  with the
        PCRE_ERROR_NOMEMORY error.
 
-       Do  not  confuse  the (?R) item with the condition (R), which tests for
-       recursion.  Consider this pattern, which matches text in  angle  brack-
-       ets,  allowing for arbitrary nesting. Only digits are allowed in nested
-       brackets (that is, when recursing), whereas any characters are  permit-
+       Do not confuse the (?R) item with the condition (R),  which  tests  for
+       recursion.   Consider  this pattern, which matches text in angle brack-
+       ets, allowing for arbitrary nesting. Only digits are allowed in  nested
+       brackets  (that is, when recursing), whereas any characters are permit-
        ted at the outer level.
 
          < (?: (?(R) \d++  | [^<>]*+) | (?R)) * >
 
-       In  this  pattern, (?(R) is the start of a conditional subpattern, with
-       two different alternatives for the recursive and  non-recursive  cases.
+       In this pattern, (?(R) is the start of a conditional  subpattern,  with
+       two  different  alternatives for the recursive and non-recursive cases.
        The (?R) item is the actual recursive call.
 
 
 SUBPATTERNS AS SUBROUTINES
 
        If the syntax for a recursive subpattern reference (either by number or
-       by name) is used outside the parentheses to which it refers,  it  oper-
-       ates  like  a  subroutine in a programming language. An earlier example
+       by  name)  is used outside the parentheses to which it refers, it oper-
+       ates like a subroutine in a programming language. The "called"  subpat-
+       tern  may  be defined before or after the reference. An earlier example
        pointed out that the pattern
 
          (sens|respons)e and \1ibility
@@ -3996,15 +4214,23 @@ SUBPATTERNS AS SUBROUTINES
          (sens|respons)e and (?1)ibility
 
        is  used, it does match "sense and responsibility" as well as the other
-       two strings. Such references, if given  numerically,  must  follow  the
-       subpattern  to which they refer. However, named references can refer to
-       later subpatterns.
+       two strings. Another example is  given  in  the  discussion  of  DEFINE
+       above.
 
        Like recursive subpatterns, a "subroutine" call is always treated as an
-       atomic  group. That is, once it has matched some of the subject string,
-       it is never re-entered, even if it contains  untried  alternatives  and
+       atomic group. That is, once it has matched some of the subject  string,
+       it  is  never  re-entered, even if it contains untried alternatives and
        there is a subsequent matching failure.
 
+       When a subpattern is used as a subroutine, processing options  such  as
+       case-independence are fixed when the subpattern is defined. They cannot
+       be changed for different calls. For example, consider this pattern:
+
+         (abc)(?i:(?1))
+
+       It matches "abcabc". It does not match "abcABC" because the  change  of
+       processing option does not affect the called subpattern.
+
 
 CALLOUTS
 
@@ -4040,7 +4266,12 @@ CALLOUTS
        gether. A complete description of the interface to the callout function
        is given in the pcrecallout documentation.
 
-Last updated: 06 June 2006
+
+SEE ALSO
+
+       pcreapi(3), pcrecallout(3), pcrematching(3), pcre(3).
+
+Last updated: 06 December 2006
 Copyright (c) 1997-2006 University of Cambridge.
 ------------------------------------------------------------------------------
 
@@ -4146,8 +4377,8 @@ EXAMPLE OF PARTIAL MATCHING USING PCRETEST
        The first data string is matched  completely,  so  pcretest  shows  the
        matched  substrings.  The  remaining four strings do not match the com-
        plete pattern, but the first two are partial matches.  The  same  test,
-       using  DFA  matching (by means of the \D escape sequence), produces the
-       following output:
+       using  pcre_dfa_exec()  matching  (by means of the \D escape sequence),
+       produces the following output:
 
            re> /^?(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)$/
          data> 25jun04\P\D
@@ -4169,11 +4400,12 @@ MULTI-SEGMENT MATCHING WITH pcre_dfa_exec()
 
        When a partial match has been found using pcre_dfa_exec(), it is possi-
        ble to continue the match by  providing  additional  subject  data  and
-       calling  pcre_dfa_exec() again with the PCRE_DFA_RESTART option and the
-       same working space (where details of the  previous  partial  match  are
-       stored).  Here  is  an  example  using  pcretest,  where  the \R escape
-       sequence sets the PCRE_DFA_RESTART option and the  \D  escape  sequence
-       requests the use of pcre_dfa_exec():
+       calling  pcre_dfa_exec()  again  with the same compiled regular expres-
+       sion, this time setting the PCRE_DFA_RESTART option. You must also pass
+       the  same working space as before, because this is where details of the
+       previous partial match are stored. Here is an example  using  pcretest,
+       using the \R escape sequence to set the PCRE_DFA_RESTART option (\P and
+       \D are as above):
 
            re> /^?(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)$/
          data> 23ja\P\D
@@ -4181,16 +4413,17 @@ MULTI-SEGMENT MATCHING WITH pcre_dfa_exec()
          data> n05\R\D
           0: n05
 
-       The  first  call has "23ja" as the subject, and requests partial match-
-       ing; the second call  has  "n05"  as  the  subject  for  the  continued
-       (restarted)  match.   Notice  that when the match is complete, only the
-       last part is shown; PCRE does  not  retain  the  previously  partially-
-       matched  string. It is up to the calling program to do that if it needs
+       The first call has "23ja" as the subject, and requests  partial  match-
+       ing;  the  second  call  has  "n05"  as  the  subject for the continued
+       (restarted) match.  Notice that when the match is  complete,  only  the
+       last  part  is  shown;  PCRE  does not retain the previously partially-
+       matched string. It is up to the calling program to do that if it  needs
        to.
 
-       This facility can  be  used  to  pass  very  long  subject  strings  to
-       pcre_dfa_exec(). However, some care is needed for certain types of pat-
-       tern.
+       You  can  set  PCRE_PARTIAL  with  PCRE_DFA_RESTART to continue partial
+       matching over multiple segments. This facility can be used to pass very
+       long  subject  strings to pcre_dfa_exec(). However, some care is needed
+       for certain types of pattern.
 
        1. If the pattern contains tests for the beginning or end  of  a  line,
        you  need  to pass the PCRE_NOTBOL or PCRE_NOTEOL options, as appropri-
@@ -4199,7 +4432,7 @@ MULTI-SEGMENT MATCHING WITH pcre_dfa_exec()
 
        2.  If  the  pattern contains backward assertions (including \b or \B),
        you need to arrange for some overlap in the subject  strings  to  allow
-       for  this.  For example, you could pass the subject in chunks that were
+       for  this.  For  example, you could pass the subject in chunks that are
        500 bytes long, but in a buffer of 700 bytes, with the starting  offset
        set to 200 and the previous 200 bytes at the start of the buffer.
 
@@ -4249,7 +4482,7 @@ MULTI-SEGMENT MATCHING WITH pcre_dfa_exec()
 
        where no string can be a partial match for both alternatives.
 
-Last updated: 16 January 2006
+Last updated: 30 November 2006
 Copyright (c) 1997-2006 University of Cambridge.
 ------------------------------------------------------------------------------
 
@@ -4361,14 +4594,17 @@ COMPATIBILITY WITH DIFFERENT PCRE RELEASES
        makes  up  a  compiled pattern was changed for release 5.0. If you have
        any saved patterns that were compiled with  previous  releases  (not  a
        facility  that  was  previously advertised), you will have to recompile
-       them for release 5.0. However, from now on, it should  be  possible  to
-       make changes in a compatible manner.
+       them for release 5.0 and above.
+
+       If you have any saved patterns in UTF-8 mode that use  \p  or  \P  that
+       were  compiled  with any release up to and including 6.4, you will have
+       to recompile them for release 6.5 and above.
 
-       Notwithstanding the above, if you have any saved patterns in UTF-8 mode
-       that use \p or \P that were compiled with any release up to and includ-
-       ing 6.4, you will have to recompile them for release 6.5 and above.
+       All saved patterns from earlier releases must be recompiled for release
+       7.0  or  higher,  because  there was an internal reorganization at that
+       release.
 
-Last updated: 01 February 2006
+Last updated: 28 November 2006
 Copyright (c) 1997-2006 University of Cambridge.
 ------------------------------------------------------------------------------
 
@@ -4382,14 +4618,70 @@ NAME
 
 PCRE PERFORMANCE
 
-       Certain  items  that may appear in regular expression patterns are more
-       efficient than others. It is more efficient to use  a  character  class
-       like  [aeiou]  than  a set of alternatives such as (a|e|i|o|u). In gen-
-       eral, the simplest construction that provides the required behaviour is
-       usually  the  most  efficient.  Jeffrey Friedl's book contains a lot of
-       useful general discussion  about  optimizing  regular  expressions  for
-       efficient  performance. This document contains a few observations about
-       PCRE.
+       Two  aspects  of performance are discussed below: memory usage and pro-
+       cessing time. The way you express your pattern as a regular  expression
+       can affect both of them.
+
+
+MEMORY USAGE
+
+       Patterns are compiled by PCRE into a reasonably efficient byte code, so
+       that most simple patterns do not use much memory. However, there is one
+       case where memory usage can be unexpectedly large. When a parenthesized
+       subpattern has a quantifier with a minimum greater than 1 and/or a lim-
+       ited  maximum,  the  whole subpattern is repeated in the compiled code.
+       For example, the pattern
+
+         (abc|def){2,4}
+
+       is compiled as if it were
+
+         (abc|def)(abc|def)((abc|def)(abc|def)?)?
+
+       (Technical aside: It is done this way so that backtrack  points  within
+       each of the repetitions can be independently maintained.)
+
+       For  regular expressions whose quantifiers use only small numbers, this
+       is not usually a problem. However, if the numbers are large,  and  par-
+       ticularly  if  such repetitions are nested, the memory usage can become
+       an embarrassment. For example, the very simple pattern
+
+         ((ab){1,1000}c){1,3}
+
+       uses 51K bytes when compiled. When PCRE is compiled  with  its  default
+       internal  pointer  size of two bytes, the size limit on a compiled pat-
+       tern is 64K, and this is reached with the above pattern  if  the  outer
+       repetition is increased from 3 to 4. PCRE can be compiled to use larger
+       internal pointers and thus handle larger compiled patterns, but  it  is
+       better to try to rewrite your pattern to use less memory if you can.
+
+       One  way  of reducing the memory usage for such patterns is to make use
+       of PCRE's "subroutine" facility. Re-writing the above pattern as
+
+         ((ab)(?2){0,999}c)(?1){0,2}
+
+       reduces the memory requirements to 18K, and indeed it remains under 20K
+       even  with the outer repetition increased to 100. However, this pattern
+       is not exactly equivalent, because the "subroutine" calls  are  treated
+       as  atomic groups into which there can be no backtracking if there is a
+       subsequent matching failure. Therefore, PCRE cannot  do  this  kind  of
+       rewriting  automatically.   Furthermore,  there is a noticeable loss of
+       speed when executing the modified pattern. Nevertheless, if the  atomic
+       grouping  is  not  a  problem and the loss of speed is acceptable, this
+       kind of rewriting will allow you to process patterns that  PCRE  cannot
+       otherwise handle.
+
+
+PROCESSING TIME
+
+       Certain  items  in regular expression patterns are processed more effi-
+       ciently than others. It is more efficient to use a character class like
+       [aeiou]   than   a   set   of  single-character  alternatives  such  as
+       (a|e|i|o|u). In general, the simplest construction  that  provides  the
+       required behaviour is usually the most efficient. Jeffrey Friedl's book
+       contains a lot of useful general discussion  about  optimizing  regular
+       expressions  for  efficient  performance.  This document contains a few
+       observations about PCRE.
 
        Using Unicode character properties (the \p,  \P,  and  \X  escapes)  is
        slow,  because PCRE has to scan a structure that contains data for over
@@ -4423,15 +4715,15 @@ PCRE PERFORMANCE
        take  a  long time to run when applied to a string that does not match.
        Consider the pattern fragment
 
-         (a+)*
+         ^(a+)*
 
-       This can match "aaaa" in 33 different ways, and this  number  increases
+       This can match "aaaa" in 16 different ways, and this  number  increases
        very  rapidly  as the string gets longer. (The * repeat can match 0, 1,
-       2, 3, or 4 times, and for each of those  cases  other  than  0,  the  +
+       2, 3, or 4 times, and for each of those cases other than 0 or 4, the  +
        repeats  can  match  different numbers of times.) When the remainder of
        the pattern is such that the entire match is going to fail, PCRE has in
        principle  to  try  every  possible  variation,  and  this  can take an
-       extremely long time.
+       extremely long time, even for relatively short strings.
 
        An optimization catches some of the more simple cases such as
 
@@ -4452,8 +4744,8 @@ PCRE PERFORMANCE
        In many cases, the solution to this kind of performance issue is to use
        an atomic group or a possessive quantifier.
 
-Last updated: 28 February 2005
-Copyright (c) 1997-2005 University of Cambridge.
+Last updated: 20 September 2006
+Copyright (c) 1997-2006 University of Cambridge.
 ------------------------------------------------------------------------------
 
 
@@ -4667,7 +4959,7 @@ AUTHOR
 
        Philip Hazel
        University Computing Service,
-       Cambridge CB2 3QG, England.
+       Cambridge CB2 3QH, England.
 
 Last updated: 16 January 2006
 Copyright (c) 1997-2006 University of Cambridge.
@@ -4762,11 +5054,34 @@ MATCHING INTERFACE
             number of sub-patterns, "i"th captured sub-pattern is
             ignored.
 
+       CAVEAT: An optional sub-pattern that does  not  exist  in  the  matched
+       string  is  assigned  the  empty  string. Therefore, the following will
+       return false (because the empty string is not a valid number):
+
+          int number;
+          pcrecpp::RE::FullMatch("abc", "[a-z]+(\d+)?", &number);
+
        The matching interface supports at most 16 arguments per call.  If  you
        need    more,    consider    using    the    more   general   interface
        pcrecpp::RE::DoMatch. See pcrecpp.h for the signature for DoMatch.
 
 
+QUOTING METACHARACTERS
+
+       You can use the "QuoteMeta" operation to insert backslashes before  all
+       potentially  meaningful  characters  in  a string. The returned string,
+       used as a regular expression, will exactly match the original string.
+
+         Example:
+            string quoted = RE::QuoteMeta(unquoted);
+
+       Note that it's legal to escape a character even if it  has  no  special
+       meaning  in  a  regular expression -- so this function does that. (This
+       also makes it identical to the perl function  of  the  same  name;  see
+       "perldoc    -f    quotemeta".)    For   example,   "1.5-2.0?"   becomes
+       "1\.5\-2\.0\?".
+
+
 PARTIAL MATCHES
 
        You can use the "PartialMatch" operation when you want the  pattern  to
@@ -4978,7 +5293,7 @@ REPLACING PARTS OF STRINGS
 AUTHOR
 
        The C++ wrapper was contributed by Google Inc.
-       Copyright (c) 2005 Google Inc.
+       Copyright (c) 2006 Google Inc.
 ------------------------------------------------------------------------------
 
 
@@ -5108,21 +5423,25 @@ PCRE DISCUSSION OF STACK USAGE
        quantifier  is  used  to stop any backtracking into the runs of non-"<"
        characters, but that is not related to stack usage.
 
+       This example shows that one way of avoiding stack problems when  match-
+       ing long subject strings is to write repeated parenthesized subpatterns
+       to match more than one character whenever possible.
+
        In environments where stack memory is constrained, you  might  want  to
        compile  PCRE to use heap memory instead of stack for remembering back-
        up points. This makes it run a lot more slowly, however. Details of how
        to do this are given in the pcrebuild documentation.
 
-       In Unix-like environments, there is not often a problem with the stack,
-       though the default limit on stack size varies from  system  to  system.
-       Values  from 8Mb to 64Mb are common. You can find your default limit by
-       running the command:
+       In  Unix-like environments, there is not often a problem with the stack
+       unless very long strings are involved,  though  the  default  limit  on
+       stack  size  varies  from system to system. Values from 8Mb to 64Mb are
+       common. You can find your default limit by running the command:
 
          ulimit -s
 
-       The effect of running out of stack is often SIGSEGV,  though  sometimes
-       an error message is given. You can normally increase the limit on stack
-       size by code such as this:
+       Unfortunately, the effect of running out of  stack  is  often  SIGSEGV,
+       though  sometimes  a more explicit error message is given. You can nor-
+       mally increase the limit on stack size by code such as this:
 
          struct rlimit rlim;
          getrlimit(RLIMIT_STACK, &rlim);
@@ -5144,9 +5463,10 @@ PCRE DISCUSSION OF STACK USAGE
        recursion. Thus, if you want to limit your  stack  usage  to  8Mb,  you
        should  set  the  limit at 16000 recursions. A 64Mb stack, on the other
        hand, can support around 128000 recursions. The pcretest  test  program
-       has  a command line option (-S) that can be used to increase its stack.
+       has a command line option (-S) that can be used to increase the size of
+       its stack.
 
-Last updated: 29 June 2006
+Last updated: 14 September 2006
 Copyright (c) 1997-2006 University of Cambridge.
 ------------------------------------------------------------------------------
 
index b4a19d2fa15901f6f04abe6f1a20a2fbaa686d85..c1961e597cae792f7ea05f6f29c484b30fdc6ad0 100644 (file)
@@ -5,7 +5,7 @@
 /* This is the public header file for the PCRE library, to be #included by
 applications that call the PCRE functions.
 
-           Copyright (c) 1997-2005 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #ifndef _PCRE_H
 #define _PCRE_H
+
 #include "php_compat.h"
 
 /* The current PCRE version information. */
@@ -54,10 +54,10 @@ and libpcre.pc. The values are not put into configure.ac and substituted here
 cannot run ./configure. As it now stands, this file need not be edited in that
 circumstance. */
 
-#define PCRE_MAJOR          6
-#define PCRE_MINOR          7
+#define PCRE_MAJOR          7
+#define PCRE_MINOR          0
 #define PCRE_PRERELEASE
-#define PCRE_DATE           04-Jul-2006
+#define PCRE_DATE           18-Dec-2006
 
 /* Win32 uses DLL by default; it needs special stuff for exported functions
 when building PCRE. */
@@ -120,6 +120,7 @@ extern "C" {
 #define PCRE_NEWLINE_CR         0x00100000
 #define PCRE_NEWLINE_LF         0x00200000
 #define PCRE_NEWLINE_CRLF       0x00300000
+#define PCRE_NEWLINE_ANY        0x00400000
 
 /* Exec-time and get/set-time error codes */
 
@@ -127,7 +128,8 @@ extern "C" {
 #define PCRE_ERROR_NULL            (-2)
 #define PCRE_ERROR_BADOPTION       (-3)
 #define PCRE_ERROR_BADMAGIC        (-4)
-#define PCRE_ERROR_UNKNOWN_NODE    (-5)
+#define PCRE_ERROR_UNKNOWN_OPCODE  (-5)
+#define PCRE_ERROR_UNKNOWN_NODE    (-5)  /* For backward compatibility */
 #define PCRE_ERROR_NOMEMORY        (-6)
 #define PCRE_ERROR_NOSUBSTRING     (-7)
 #define PCRE_ERROR_MATCHLIMIT      (-8)
@@ -144,6 +146,8 @@ extern "C" {
 #define PCRE_ERROR_DFA_WSSIZE     (-19)
 #define PCRE_ERROR_DFA_RECURSE    (-20)
 #define PCRE_ERROR_RECURSIONLIMIT (-21)
+#define PCRE_ERROR_NULLWSLIMIT    (-22)
+#define PCRE_ERROR_BADNEWLINE     (-23)
 
 /* Request types for pcre_fullinfo() */
 
index 5a82bcf0a32c9f0ce9631aa004fa17ecd168a45d..34721c8863d1a8aa77809ffcac7a1c2d2650bfa8 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -42,7 +42,11 @@ POSSIBILITY OF SUCH DAMAGE.
 supporting internal functions that are not used by other modules. */
 
 
-#define NLBLOCK cd            /* The block containing newline information */
+#define NLBLOCK cd             /* Block containing newline information */
+#define PSSTART start_pattern  /* Field containing processed string start */
+#define PSEND   end_pattern    /* Field containing processed string end */
+
+
 #include "pcre_internal.h"
 
 
@@ -54,18 +58,23 @@ used by pcretest. DEBUG is not defined when building a production library. */
 #endif
 
 
-
 /*************************************************
 *      Code parameters and static tables         *
 *************************************************/
 
-/* Maximum number of items on the nested bracket stacks at compile time. This
-applies to the nesting of all kinds of parentheses. It does not limit
-un-nested, non-capturing parentheses. This number can be made bigger if
-necessary - it is used to dimension one int and one unsigned char vector at
-compile time. */
+/* This value specifies the size of stack workspace that is used during the
+first pre-compile phase that determines how much memory is required. The regex
+is partly compiled into this space, but the compiled parts are discarded as
+soon as they can be, so that hopefully there will never be an overrun. The code
+does, however, check for an overrun. The largest amount I've seen used is 218,
+so this number is very generous.
+
+The same workspace is used during the second, actual compile phase for
+remembering forward references to groups so that they can be filled in at the
+end. Each entry in this list occupies LINK_SIZE bytes, so even when LINK_SIZE
+is 4 there is plenty of room. */
 
-#define BRASTACK_SIZE 200
+#define COMPILE_WORK_SIZE (4096)
 
 
 /* Table for handling escaped characters in the range '0'-'z'. Positive returns
@@ -79,10 +88,10 @@ static const short int escapes[] = {
      0,      0,    ':',    ';',    '<',    '=',    '>',    '?',   /* 8 - ? */
    '@', -ESC_A, -ESC_B, -ESC_C, -ESC_D, -ESC_E,      0, -ESC_G,   /* @ - G */
      0,      0,      0,      0,      0,      0,      0,      0,   /* H - O */
--ESC_P, -ESC_Q,      0, -ESC_S,      0,      0,      0, -ESC_W,   /* P - W */
+-ESC_P, -ESC_Q, -ESC_R, -ESC_S,      0,      0,      0, -ESC_W,   /* P - W */
 -ESC_X,      0, -ESC_Z,    '[',   '\\',    ']',    '^',    '_',   /* X - _ */
    '`',      7, -ESC_b,      0, -ESC_d,  ESC_e,  ESC_f,      0,   /* ` - g */
-     0,      0,      0,      0,      0,      0,  ESC_n,      0,   /* h - o */
+     0,      0,      0, -ESC_k,      0,      0,  ESC_n,      0,   /* h - o */
 -ESC_p,      0,  ESC_r, -ESC_s,  ESC_tee,    0,      0, -ESC_w,   /* p - w */
      0,      0, -ESC_z                                            /* x - z */
 };
@@ -98,7 +107,7 @@ static const short int escapes[] = {
 /*  78 */     0,   '`',    ':',     '#',    '@',  '\'',    '=',    '"',
 /*  80 */     0,     7, -ESC_b,       0, -ESC_d, ESC_e,  ESC_f,      0,
 /*  88 */     0,     0,      0,     '{',      0,     0,      0,      0,
-/*  90 */     0,     0,      0,     'l',      0, ESC_n,      0, -ESC_p,
+/*  90 */     0,     0, -ESC_k,     'l',      0, ESC_n,      0, -ESC_p,
 /*  98 */     0, ESC_r,      0,     '}',      0,     0,      0,      0,
 /*  A0 */     0,   '~', -ESC_s, ESC_tee,      0,     0, -ESC_w,      0,
 /*  A8 */     0,-ESC_z,      0,       0,      0,   '[',      0,      0,
@@ -107,7 +116,7 @@ static const short int escapes[] = {
 /*  C0 */   '{',-ESC_A, -ESC_B,  -ESC_C, -ESC_D,-ESC_E,      0, -ESC_G,
 /*  C8 */     0,     0,      0,       0,      0,     0,      0,      0,
 /*  D0 */   '}',     0,      0,       0,      0,     0,      0, -ESC_P,
-/*  D8 */-ESC_Q,     0,      0,       0,      0,     0,      0,      0,
+/*  D8 */-ESC_Q,-ESC_R,      0,       0,      0,     0,      0,      0,
 /*  E0 */  '\\',     0, -ESC_S,       0,      0,     0, -ESC_W, -ESC_X,
 /*  E8 */     0,-ESC_Z,      0,       0,      0,     0,      0,      0,
 /*  F0 */     0,     0,      0,       0,      0,     0,      0,      0,
@@ -156,8 +165,13 @@ static const int posix_class_maps[] = {
 };
 
 
+#define STRING(a)  # a
+#define XSTRING(s) STRING(s)
+
 /* The texts of compile-time error messages. These are "char *" because they
-are passed to the outside world. */
+are passed to the outside world. Do not ever re-use any error number, because
+they are documented. Always add a new error instead. Messages marked DEAD below
+are no longer used. */
 
 static const char *error_texts[] = {
   "no error",
@@ -172,7 +186,7 @@ static const char *error_texts[] = {
   "range out of order in character class",
   "nothing to repeat",
   /* 10 */
-  "operand of unlimited repeat could match the empty string",
+  "operand of unlimited repeat could match the empty string",  /** DEAD **/
   "internal error: unexpected repeat",
   "unrecognized character after (?",
   "POSIX named classes are supported only within a class",
@@ -182,7 +196,7 @@ static const char *error_texts[] = {
   "erroffset passed as NULL",
   "unknown option bit(s) set",
   "missing ) after comment",
-  "parentheses nested too deeply",
+  "parentheses nested too deeply",  /** DEAD **/
   /* 20 */
   "regular expression too large",
   "failed to get memory",
@@ -199,7 +213,7 @@ static const char *error_texts[] = {
   "unknown POSIX class name",
   "POSIX collating elements are not supported",
   "this version of PCRE is not compiled with PCRE_UTF8 support",
-  "spare error",
+  "spare error",  /** DEAD **/
   "character value in \\x{...} sequence is too large",
   /* 35 */
   "invalid condition (?(0)",
@@ -210,18 +224,25 @@ static const char *error_texts[] = {
   /* 40 */
   "recursive call could loop indefinitely",
   "unrecognized character after (?P",
-  "syntax error after (?P",
+  "syntax error in subpattern name (missing terminator)",
   "two named subpatterns have the same name",
   "invalid UTF-8 string",
   /* 45 */
   "support for \\P, \\p, and \\X has not been compiled",
   "malformed \\P or \\p sequence",
   "unknown property name after \\P or \\p",
-  "subpattern name is too long (maximum 32 characters)",
-  "too many named subpatterns (maximum 10,000)",
+  "subpattern name is too long (maximum " XSTRING(MAX_NAME_SIZE) " characters)",
+  "too many named subpatterns (maximum " XSTRING(MAX_NAME_COUNT) ")",
   /* 50 */
   "repeated subpattern is too long",
-  "octal value is greater than \\377 (not in UTF-8 mode)"
+  "octal value is greater than \\377 (not in UTF-8 mode)",
+  "internal error: overran compiling workspace",
+  "internal error: previously-checked referenced subpattern not found",
+  "DEFINE group contains more than one branch",
+  /* 55 */
+  "repeating a DEFINE group is not allowed",
+  "inconsistent NEWLINE options",
+  "\\g is not followed by an (optionally braced) non-zero number"
 };
 
 
@@ -352,8 +373,8 @@ static const unsigned char ebcdic_chartab[] = { /* chartable partial dup */
 /* Definition to allow mutual recursion */
 
 static BOOL
-  compile_regex(int, int, int *, uschar **, const uschar **, int *, BOOL, int,
-    int *, int *, branch_chain *, compile_data *);
+  compile_regex(int, int, uschar **, const uschar **, int *, BOOL, int, int *,
+    int *, branch_chain *, compile_data *, int *);
 
 
 
@@ -363,9 +384,11 @@ static BOOL
 
 /* This function is called when a \ has been encountered. It either returns a
 positive value for a simple escape such as \n, or a negative value which
-encodes one of the more complicated things such as \d. When UTF-8 is enabled,
-a positive value greater than 255 may be returned. On entry, ptr is pointing at
-the \. On exit, it is on the final character of the escape sequence.
+encodes one of the more complicated things such as \d. A backreference to group
+n is returned as -(ESC_REF + n); ESC_REF is the highest ESC_xxx macro. When
+UTF-8 is enabled, a positive value greater than 255 may be returned. On entry,
+ptr is pointing at the \. On exit, it is on the final character of the escape
+sequence.
 
 Arguments:
   ptrptr         points to the pattern position pointer
@@ -412,6 +435,8 @@ else if ((i = escapes[c - 0x48]) != 0)  c = i;
 else
   {
   const uschar *oldptr;
+  BOOL braced, negated;
+
   switch (c)
     {
     /* A number of Perl escapes are not handled by PCRE. We give an explicit
@@ -425,6 +450,48 @@ else
     *errorcodeptr = ERR37;
     break;
 
+    /* \g must be followed by a number, either plain or braced. If positive, it
+    is an absolute backreference. If negative, it is a relative backreference.
+    This is a Perl 5.10 feature. */
+
+    case 'g':
+    if (ptr[1] == '{')
+      {
+      braced = TRUE;
+      ptr++;
+      }
+    else braced = FALSE;
+
+    if (ptr[1] == '-')
+      {
+      negated = TRUE;
+      ptr++;
+      }
+    else negated = FALSE;
+
+    c = 0;
+    while ((digitab[ptr[1]] & ctype_digit) != 0)
+      c = c * 10 + *(++ptr) - '0';
+
+    if (c == 0 || (braced && *(++ptr) != '}'))
+      {
+      *errorcodeptr = ERR57;
+      return 0;
+      }
+
+    if (negated)
+      {
+      if (c > bracount)
+        {
+        *errorcodeptr = ERR15;
+        return 0;
+        }
+      c = bracount - (c - 1);
+      }
+
+    c = -(ESC_REF + c);
+    break;
+
     /* The handling of escape sequences consisting of a string of digits
     starting with one that is not zero is not straightforward. By experiment,
     the way Perl works seems to be as follows:
@@ -532,7 +599,9 @@ else
       }
     break;
 
-    /* Other special escapes not starting with a digit are straightforward */
+    /* For \c, a following letter is upper-cased; then the 0x40 bit is flipped.
+    This coding is ASCII-specific, but then the whole concept of \cx is
+    ASCII-specific. (However, an EBCDIC equivalent has now been added.) */
 
     case 'c':
     c = *(++ptr);
@@ -542,10 +611,6 @@ else
       return 0;
       }
 
-    /* A letter is upper-cased; then the 0x40 bit is flipped. This coding
-    is ASCII-specific, but then the whole concept of \cx is ASCII-specific.
-    (However, an EBCDIC equivalent has now been added.) */
-
 #if !EBCDIC    /* ASCII coding */
     if (c >= 'a' && c <= 'z') c -= 32;
     c ^= 0x40;
@@ -772,42 +837,111 @@ return p;
 
 
 /*************************************************
-*     Find forward referenced named subpattern   *
+*       Find forward referenced subpattern       *
 *************************************************/
 
-/* This function scans along a pattern looking for capturing subpatterns, and
-counting them. If it finds a named pattern that matches the name it is given,
-it returns its number. This is used for forward references to named
-subpatterns. We know that if (?P< is encountered, the name will be terminated
-by '>' because that is checked in the first pass.
+/* This function scans along a pattern's text looking for capturing
+subpatterns, and counting them. If it finds a named pattern that matches the
+name it is given, it returns its number. Alternatively, if the name is NULL, it
+returns when it reaches a given numbered subpattern. This is used for forward
+references to subpatterns. We know that if (?P< is encountered, the name will
+be terminated by '>' because that is checked in the first pass.
 
 Arguments:
-  pointer      current position in the pattern
-  count        current count of capturing parens
-  name         name to seek
-  namelen      name length
+  ptr          current position in the pattern
+  count        current count of capturing parens so far encountered
+  name         name to seek, or NULL if seeking a numbered subpattern
+  lorn         name length, or subpattern number if name is NULL
+  xmode        TRUE if we are in /x mode
 
 Returns:       the number of the named subpattern, or -1 if not found
 */
 
 static int
-find_named_parens(const uschar *ptr, int count, const uschar *name, int namelen)
+find_parens(const uschar *ptr, int count, const uschar *name, int lorn,
+  BOOL xmode)
 {
 const uschar *thisname;
+
 for (; *ptr != 0; ptr++)
   {
-  if (*ptr == '\\' && ptr[1] != 0) { ptr++; continue; }
+  int term;
+
+  /* Skip over backslashed characters and also entire \Q...\E */
+
+  if (*ptr == '\\')
+    {
+    if (*(++ptr) == 0) return -1;
+    if (*ptr == 'Q') for (;;)
+      {
+      while (*(++ptr) != 0 && *ptr != '\\');
+      if (*ptr == 0) return -1;
+      if (*(++ptr) == 'E') break;
+      }
+    continue;
+    }
+
+  /* Skip over character classes */
+
+  if (*ptr == '[')
+    {
+    while (*(++ptr) != ']')
+      {
+      if (*ptr == '\\')
+        {
+        if (*(++ptr) == 0) return -1;
+        if (*ptr == 'Q') for (;;)
+          {
+          while (*(++ptr) != 0 && *ptr != '\\');
+          if (*ptr == 0) return -1;
+          if (*(++ptr) == 'E') break;
+          }
+        continue;
+        }
+      }
+    continue;
+    }
+
+  /* Skip comments in /x mode */
+
+  if (xmode && *ptr == '#')
+    {
+    while (*(++ptr) != 0 && *ptr != '\n');
+    if (*ptr == 0) return -1;
+    continue;
+    }
+
+  /* An opening parens must now be a real metacharacter */
+
   if (*ptr != '(') continue;
-  if (ptr[1] != '?') { count++; continue; }
-  if (ptr[2] == '(') { ptr += 2; continue; }
-  if (ptr[2] != 'P' || ptr[3] != '<') continue;
+  if (ptr[1] != '?')
+    {
+    count++;
+    if (name == NULL && count == lorn) return count;
+    continue;
+    }
+
+  ptr += 2;
+  if (*ptr == 'P') ptr++;                      /* Allow optional P */
+
+  /* We have to disambiguate (?<! and (?<= from (?<name> */
+
+  if ((*ptr != '<' || ptr[1] == '!' || ptr[1] == '=') &&
+       *ptr != '\'')
+    continue;
+
   count++;
-  ptr += 4;
+
+  if (name == NULL && count == lorn) return count;
+  term = *ptr++;
+  if (term == '<') term = '>';
   thisname = ptr;
-  while (*ptr != '>') ptr++;
-  if (namelen == ptr - thisname && strncmp(name, thisname, namelen) == 0)
+  while (*ptr != term) ptr++;
+  if (name != NULL && lorn == ptr - thisname &&
+      strncmp((const char *)name, (const char *)thisname, lorn) == 0)
     return count;
   }
+
 return -1;
 }
 
@@ -862,7 +996,8 @@ for (;;)
 
     case OP_CALLOUT:
     case OP_CREF:
-    case OP_BRANUMBER:
+    case OP_RREF:
+    case OP_DEF:
     code += _pcre_OP_lengths[*code];
     break;
 
@@ -907,14 +1042,14 @@ for (;;)
   {
   int d;
   register int op = *cc;
-  if (op >= OP_BRA) op = OP_BRA;
 
   switch (op)
     {
+    case OP_CBRA:
     case OP_BRA:
     case OP_ONCE:
     case OP_COND:
-    d = find_fixedlength(cc, options);
+    d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), options);
     if (d < 0) return d;
     branchlength += d;
     do cc += GET(cc, 1); while (*cc == OP_ALT);
@@ -949,8 +1084,9 @@ for (;;)
     /* Skip over things that don't match chars */
 
     case OP_REVERSE:
-    case OP_BRANUMBER:
     case OP_CREF:
+    case OP_RREF:
+    case OP_DEF:
     case OP_OPT:
     case OP_CALLOUT:
     case OP_SOD:
@@ -1094,21 +1230,18 @@ for (;;)
 
   if (c == OP_XCLASS) code += GET(code, 1);
 
-  /* Handle bracketed group */
+  /* Handle capturing bracket */
 
-  else if (c > OP_BRA)
+  else if (c == OP_CBRA)
     {
-    int n = c - OP_BRA;
-    if (n > EXTRACT_BASIC_MAX) n = GET2(code, 2+LINK_SIZE);
+    int n = GET2(code, 1+LINK_SIZE);
     if (n == number) return (uschar *)code;
-    code += _pcre_OP_lengths[OP_BRA];
+    code += _pcre_OP_lengths[c];
     }
 
-  /* Otherwise, we get the item's length from the table. In UTF-8 mode, opcodes
-  that are followed by a character may be followed by a multi-byte character.
-  The length in the table is a minimum, so we have to scan along to skip the
-  extra bytes. All opcodes are less than 128, so we can use relatively
-  efficient code. */
+  /* In UTF-8 mode, opcodes that are followed by a character may be followed by
+  a multi-byte character. The length in the table is a minimum, so we have to
+  arrange to skip the extra bytes. */
 
   else
     {
@@ -1120,13 +1253,17 @@ for (;;)
       case OP_EXACT:
       case OP_UPTO:
       case OP_MINUPTO:
+      case OP_POSUPTO:
       case OP_STAR:
       case OP_MINSTAR:
+      case OP_POSSTAR:
       case OP_PLUS:
       case OP_MINPLUS:
+      case OP_POSPLUS:
       case OP_QUERY:
       case OP_MINQUERY:
-      while ((*code & 0xc0) == 0x80) code++;
+      case OP_POSQUERY:
+      if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f];
       break;
       }
     }
@@ -1164,18 +1301,10 @@ for (;;)
 
   if (c == OP_XCLASS) code += GET(code, 1);
 
-  /* All bracketed groups have the same length. */
-
-  else if (c > OP_BRA)
-    {
-    code += _pcre_OP_lengths[OP_BRA];
-    }
-
   /* Otherwise, we get the item's length from the table. In UTF-8 mode, opcodes
   that are followed by a character may be followed by a multi-byte character.
-  The length in the table is a minimum, so we have to scan along to skip the
-  extra bytes. All opcodes are less than 128, so we can use relatively
-  efficient code. */
+  The length in the table is a minimum, so we have to arrange to skip the extra
+  bytes. */
 
   else
     {
@@ -1187,13 +1316,17 @@ for (;;)
       case OP_EXACT:
       case OP_UPTO:
       case OP_MINUPTO:
+      case OP_POSUPTO:
       case OP_STAR:
       case OP_MINSTAR:
+      case OP_POSSTAR:
       case OP_PLUS:
       case OP_MINPLUS:
+      case OP_POSPLUS:
       case OP_QUERY:
       case OP_MINQUERY:
-      while ((*code & 0xc0) == 0x80) code++;
+      case OP_POSQUERY:
+      if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f];
       break;
       }
     }
@@ -1207,10 +1340,11 @@ for (;;)
 *************************************************/
 
 /* This function scans through a branch of a compiled pattern to see whether it
-can match the empty string or not. It is called only from could_be_empty()
-below. Note that first_significant_code() skips over assertions. If we hit an
-unclosed bracket, we return "empty" - this means we've struck an inner bracket
-whose current branch will already have been scanned.
+can match the empty string or not. It is called from could_be_empty()
+below and from compile_branch() when checking for an unlimited repeat of a
+group that can match nothing. Note that first_significant_code() skips over
+assertions. If we hit an unclosed bracket, we return "empty" - this means we've
+struck an inner bracket whose current branch will already have been scanned.
 
 Arguments:
   code        points to start of search
@@ -1224,7 +1358,7 @@ static BOOL
 could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8)
 {
 register int c;
-for (code = first_significant_code(code + 1 + LINK_SIZE, NULL, 0, TRUE);
+for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE);
      code < endcode;
      code = first_significant_code(code + _pcre_OP_lengths[c], NULL, 0, TRUE))
   {
@@ -1232,7 +1366,7 @@ for (code = first_significant_code(code + 1 + LINK_SIZE, NULL, 0, TRUE);
 
   c = *code;
 
-  if (c >= OP_BRA)
+  if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE)
     {
     BOOL empty_branch;
     if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */
@@ -1248,11 +1382,18 @@ for (code = first_significant_code(code + 1 + LINK_SIZE, NULL, 0, TRUE);
       }
     while (*code == OP_ALT);
     if (!empty_branch) return FALSE;   /* All branches are non-empty */
-    code += 1 + LINK_SIZE;
-    c = *code;
+
+    /* Move past the KET and fudge things so that the increment in the "for"
+    above has no effect. */
+
+    c = OP_END;
+    code += 1 + LINK_SIZE - _pcre_OP_lengths[c];
+    continue;
     }
 
-  else switch (c)
+  /* Handle the other opcodes */
+
+  switch (c)
     {
     /* Check for quantifiers after a class */
 
@@ -1308,12 +1449,15 @@ for (code = first_significant_code(code + 1 + LINK_SIZE, NULL, 0, TRUE);
     case OP_NOT:
     case OP_PLUS:
     case OP_MINPLUS:
+    case OP_POSPLUS:
     case OP_EXACT:
     case OP_NOTPLUS:
     case OP_NOTMINPLUS:
+    case OP_NOTPOSPLUS:
     case OP_NOTEXACT:
     case OP_TYPEPLUS:
     case OP_TYPEMINPLUS:
+    case OP_TYPEPOSPLUS:
     case OP_TYPEEXACT:
     return FALSE;
 
@@ -1325,16 +1469,19 @@ for (code = first_significant_code(code + 1 + LINK_SIZE, NULL, 0, TRUE);
     case OP_ALT:
     return TRUE;
 
-    /* In UTF-8 mode, STAR, MINSTAR, QUERY, MINQUERY, UPTO, and MINUPTO  may be
-    followed by a multibyte character */
+    /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO,
+    MINUPTO, and POSUPTO may be followed by a multibyte character */
 
 #ifdef SUPPORT_UTF8
     case OP_STAR:
     case OP_MINSTAR:
+    case OP_POSSTAR:
     case OP_QUERY:
     case OP_MINQUERY:
+    case OP_POSQUERY:
     case OP_UPTO:
     case OP_MINUPTO:
+    case OP_POSUPTO:
     if (utf8) while ((code[2] & 0xc0) == 0x80) code++;
     break;
 #endif
@@ -1452,26 +1599,57 @@ earlier groups that are outside the current group). However, when a group is
 optional (i.e. the minimum quantifier is zero), OP_BRAZERO is inserted before
 it, after it has been compiled. This means that any OP_RECURSE items within it
 that refer to the group itself or any contained groups have to have their
-offsets adjusted. That is the job of this function. Before it is called, the
-partially compiled regex must be temporarily terminated with OP_END.
+offsets adjusted. That one of the jobs of this function. Before it is called,
+the partially compiled regex must be temporarily terminated with OP_END.
+
+This function has been extended with the possibility of forward references for
+recursions and subroutine calls. It must also check the list of such references
+for the group we are dealing with. If it finds that one of the recursions in
+the current group is on this list, it adjusts the offset in the list, not the
+value in the reference (which is a group number).
 
 Arguments:
   group      points to the start of the group
   adjust     the amount by which the group is to be moved
   utf8       TRUE in UTF-8 mode
   cd         contains pointers to tables etc.
+  save_hwm   the hwm forward reference pointer at the start of the group
 
 Returns:     nothing
 */
 
 static void
-adjust_recurse(uschar *group, int adjust, BOOL utf8, compile_data *cd)
+adjust_recurse(uschar *group, int adjust, BOOL utf8, compile_data *cd,
+  uschar *save_hwm)
 {
 uschar *ptr = group;
 while ((ptr = (uschar *)find_recurse(ptr, utf8)) != NULL)
   {
-  int offset = GET(ptr, 1);
-  if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust);
+  int offset;
+  uschar *hc;
+
+  /* See if this recursion is on the forward reference list. If so, adjust the
+  reference. */
+
+  for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE)
+    {
+    offset = GET(hc, 0);
+    if (cd->start_code + offset == ptr + 1)
+      {
+      PUT(hc, 0, offset + adjust);
+      break;
+      }
+    }
+
+  /* Otherwise, adjust the recursion offset if it's after the start of this
+  group. */
+
+  if (hc >= cd->hwm)
+    {
+    offset = GET(ptr, 1);
+    if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust);
+    }
+
   ptr += 1 + LINK_SIZE;
   }
 }
@@ -1550,12 +1728,13 @@ Yield:        TRUE when range returned; FALSE when no more
 */
 
 static BOOL
-get_othercase_range(int *cptr, int d, int *ocptr, int *odptr)
+get_othercase_range(unsigned int *cptr, unsigned int d, unsigned int *ocptr,
+  unsigned int *odptr)
 {
-int c, othercase, next;
+unsigned int c, othercase, next;
 
 for (c = *cptr; c <= d; c++)
-  { if ((othercase = _pcre_ucp_othercase(c)) >= 0) break; }
+  { if ((othercase = _pcre_ucp_othercase(c)) != NOTACHAR) break; }
 
 if (c > d) return FALSE;
 
@@ -1576,17 +1755,249 @@ return TRUE;
 #endif  /* SUPPORT_UCP */
 
 
+
+/*************************************************
+*     Check if auto-possessifying is possible    *
+*************************************************/
+
+/* This function is called for unlimited repeats of certain items, to see
+whether the next thing could possibly match the repeated item. If not, it makes
+sense to automatically possessify the repeated item.
+
+Arguments:
+  op_code       the repeated op code
+  this          data for this item, depends on the opcode
+  utf8          TRUE in UTF-8 mode
+  utf8_char     used for utf8 character bytes, NULL if not relevant
+  ptr           next character in pattern
+  options       options bits
+  cd            contains pointers to tables etc.
+
+Returns:        TRUE if possessifying is wanted
+*/
+
+static BOOL
+check_auto_possessive(int op_code, int item, BOOL utf8, uschar *utf8_char,
+  const uschar *ptr, int options, compile_data *cd)
+{
+int next;
+
+/* Skip whitespace and comments in extended mode */
+
+if ((options & PCRE_EXTENDED) != 0)
+  {
+  for (;;)
+    {
+    while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++;
+    if (*ptr == '#')
+      {
+      while (*(++ptr) != 0)
+        if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
+      }
+    else break;
+    }
+  }
+
+/* If the next item is one that we can handle, get its value. A non-negative
+value is a character, a negative value is an escape value. */
+
+if (*ptr == '\\')
+  {
+  int temperrorcode = 0;
+  next = check_escape(&ptr, &temperrorcode, cd->bracount, options, FALSE);
+  if (temperrorcode != 0) return FALSE;
+  ptr++;    /* Point after the escape sequence */
+  }
+
+else if ((cd->ctypes[*ptr] & ctype_meta) == 0)
+  {
+#ifdef SUPPORT_UTF8
+  if (utf8) { GETCHARINC(next, ptr); } else
+#endif
+  next = *ptr++;
+  }
+
+else return FALSE;
+
+/* Skip whitespace and comments in extended mode */
+
+if ((options & PCRE_EXTENDED) != 0)
+  {
+  for (;;)
+    {
+    while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++;
+    if (*ptr == '#')
+      {
+      while (*(++ptr) != 0)
+        if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
+      }
+    else break;
+    }
+  }
+
+/* If the next thing is itself optional, we have to give up. */
+
+if (*ptr == '*' || *ptr == '?' || strncmp((char *)ptr, "{0,", 3) == 0)
+  return FALSE;
+
+/* Now compare the next item with the previous opcode. If the previous is a
+positive single character match, "item" either contains the character or, if
+"item" is greater than 127 in utf8 mode, the character's bytes are in
+utf8_char. */
+
+
+/* Handle cases when the next item is a character. */
+
+if (next >= 0) switch(op_code)
+  {
+  case OP_CHAR:
+#ifdef SUPPORT_UTF8
+  if (utf8 && item > 127) { GETCHAR(item, utf8_char); }
+#endif
+  return item != next;
+
+  /* For CHARNC (caseless character) we must check the other case. If we have
+  Unicode property support, we can use it to test the other case of
+  high-valued characters. */
+
+  case OP_CHARNC:
+#ifdef SUPPORT_UTF8
+  if (utf8 && item > 127) { GETCHAR(item, utf8_char); }
+#endif
+  if (item == next) return FALSE;
+#ifdef SUPPORT_UTF8
+  if (utf8)
+    {
+    unsigned int othercase;
+    if (next < 128) othercase = cd->fcc[next]; else
+#ifdef SUPPORT_UCP
+    othercase = _pcre_ucp_othercase((unsigned int)next);
+#else
+    othercase = NOTACHAR;
+#endif
+    return (unsigned int)item != othercase;
+    }
+  else
+#endif  /* SUPPORT_UTF8 */
+  return (item != cd->fcc[next]);  /* Non-UTF-8 mode */
+
+  /* For OP_NOT, "item" must be a single-byte character. */
+
+  case OP_NOT:
+  if (next < 0) return FALSE;  /* Not a character */
+  if (item == next) return TRUE;
+  if ((options & PCRE_CASELESS) == 0) return FALSE;
+#ifdef SUPPORT_UTF8
+  if (utf8)
+    {
+    unsigned int othercase;
+    if (next < 128) othercase = cd->fcc[next]; else
+#ifdef SUPPORT_UCP
+    othercase = _pcre_ucp_othercase(next);
+#else
+    othercase = NOTACHAR;
+#endif
+    return (unsigned int)item == othercase;
+    }
+  else
+#endif  /* SUPPORT_UTF8 */
+  return (item == cd->fcc[next]);  /* Non-UTF-8 mode */
+
+  case OP_DIGIT:
+  return next > 127 || (cd->ctypes[next] & ctype_digit) == 0;
+
+  case OP_NOT_DIGIT:
+  return next <= 127 && (cd->ctypes[next] & ctype_digit) != 0;
+
+  case OP_WHITESPACE:
+  return next > 127 || (cd->ctypes[next] & ctype_space) == 0;
+
+  case OP_NOT_WHITESPACE:
+  return next <= 127 && (cd->ctypes[next] & ctype_space) != 0;
+
+  case OP_WORDCHAR:
+  return next > 127 || (cd->ctypes[next] & ctype_word) == 0;
+
+  case OP_NOT_WORDCHAR:
+  return next <= 127 && (cd->ctypes[next] & ctype_word) != 0;
+
+  default:
+  return FALSE;
+  }
+
+
+/* Handle the case when the next item is \d, \s, etc. */
+
+switch(op_code)
+  {
+  case OP_CHAR:
+  case OP_CHARNC:
+#ifdef SUPPORT_UTF8
+  if (utf8 && item > 127) { GETCHAR(item, utf8_char); }
+#endif
+  switch(-next)
+    {
+    case ESC_d:
+    return item > 127 || (cd->ctypes[item] & ctype_digit) == 0;
+
+    case ESC_D:
+    return item <= 127 && (cd->ctypes[item] & ctype_digit) != 0;
+
+    case ESC_s:
+    return item > 127 || (cd->ctypes[item] & ctype_space) == 0;
+
+    case ESC_S:
+    return item <= 127 && (cd->ctypes[item] & ctype_space) != 0;
+
+    case ESC_w:
+    return item > 127 || (cd->ctypes[item] & ctype_word) == 0;
+
+    case ESC_W:
+    return item <= 127 && (cd->ctypes[item] & ctype_word) != 0;
+
+    default:
+    return FALSE;
+    }
+
+  case OP_DIGIT:
+  return next == -ESC_D || next == -ESC_s || next == -ESC_W;
+
+  case OP_NOT_DIGIT:
+  return next == -ESC_d;
+
+  case OP_WHITESPACE:
+  return next == -ESC_S || next == -ESC_d || next == -ESC_w;
+
+  case OP_NOT_WHITESPACE:
+  return next == -ESC_s;
+
+  case OP_WORDCHAR:
+  return next == -ESC_W || next == -ESC_s;
+
+  case OP_NOT_WORDCHAR:
+  return next == -ESC_w || next == -ESC_d;
+
+  default:
+  return FALSE;
+  }
+
+/* Control does not reach here */
+}
+
+
+
 /*************************************************
 *           Compile one branch                   *
 *************************************************/
 
-/* Scan the pattern, compiling it into the code vector. If the options are
+/* Scan the pattern, compiling it into the a vector. If the options are
 changed during the branch, the pointer is used to change the external options
-bits.
+bits. This function is used during the pre-compile phase when we are trying
+to find out the amount of memory needed, as well as during the real compile
+phase. The value of lengthptr distinguishes the two phases.
 
 Arguments:
   optionsptr     pointer to the option bits
-  brackets       points to number of extracting brackets used
   codeptr        points to the pointer to the current code point
   ptrptr         points to the current pattern pointer
   errorcodeptr   points to error code variable
@@ -1594,15 +2005,17 @@ Arguments:
   reqbyteptr     set to the last literal character required, else < 0
   bcptr          points to current branch chain
   cd             contains pointers to tables etc.
+  lengthptr      NULL during the real compile phase
+                 points to length accumulator during pre-compile phase
 
 Returns:         TRUE on success
                  FALSE, with *errorcodeptr set non-zero on error
 */
 
 static BOOL
-compile_branch(int *optionsptr, int *brackets, uschar **codeptr,
-  const uschar **ptrptr, int *errorcodeptr, int *firstbyteptr,
-  int *reqbyteptr, branch_chain *bcptr, compile_data *cd)
+compile_branch(int *optionsptr, uschar **codeptr, const uschar **ptrptr,
+  int *errorcodeptr, int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr,
+  compile_data *cd, int *lengthptr)
 {
 int repeat_type, op_type;
 int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */
@@ -1613,8 +2026,11 @@ int zeroreqbyte, zerofirstbyte;
 int req_caseopt, reqvary, tempreqvary;
 int options = *optionsptr;
 int after_manual_callout = 0;
+int length_prevgroup = 0;
 register int c;
 register uschar *code = *codeptr;
+uschar *last_code = code;
+uschar *orig_code = code;
 uschar *tempcode;
 BOOL inescq = FALSE;
 BOOL groupsetfirstbyte = FALSE;
@@ -1622,6 +2038,7 @@ const uschar *ptr = *ptrptr;
 const uschar *tempptr;
 uschar *previous = NULL;
 uschar *previous_callout = NULL;
+uschar *save_hwm = NULL;
 uschar classbits[32];
 
 #ifdef SUPPORT_UTF8
@@ -1631,6 +2048,11 @@ uschar *class_utf8data;
 uschar utf8_char[6];
 #else
 BOOL utf8 = FALSE;
+uschar *utf8_char = NULL;
+#endif
+
+#ifdef DEBUG
+if (lengthptr != NULL) DPRINTF((">> start branch\n"));
 #endif
 
 /* Set up the default and non-default settings for greediness */
@@ -1664,6 +2086,7 @@ for (;; ptr++)
   BOOL negate_class;
   BOOL possessive_quantifier;
   BOOL is_quantifier;
+  BOOL is_recurse;
   int class_charcount;
   int class_lastchar;
   int newoptions;
@@ -1671,13 +2094,68 @@ for (;; ptr++)
   int skipbytes;
   int subreqbyte;
   int subfirstbyte;
+  int terminator;
   int mclength;
   uschar mcbuffer[8];
 
-  /* Next byte in the pattern */
+  /* Get next byte in the pattern */
 
   c = *ptr;
 
+  /* If we are in the pre-compile phase, accumulate the length used for the
+  previous cycle of this loop. */
+
+  if (lengthptr != NULL)
+    {
+#ifdef DEBUG
+    if (code > cd->hwm) cd->hwm = code;                 /* High water info */
+#endif
+    if (code > cd->start_workspace + COMPILE_WORK_SIZE) /* Check for overrun */
+      {
+      *errorcodeptr = ERR52;
+      goto FAILED;
+      }
+
+    /* There is at least one situation where code goes backwards: this is the
+    case of a zero quantifier after a class (e.g. [ab]{0}). At compile time,
+    the class is simply eliminated. However, it is created first, so we have to
+    allow memory for it. Therefore, don't ever reduce the length at this point.
+    */
+
+    if (code < last_code) code = last_code;
+    *lengthptr += code - last_code;
+    DPRINTF(("length=%d added %d c=%c\n", *lengthptr, code - last_code, c));
+
+    /* If "previous" is set and it is not at the start of the work space, move
+    it back to there, in order to avoid filling up the work space. Otherwise,
+    if "previous" is NULL, reset the current code pointer to the start. */
+
+    if (previous != NULL)
+      {
+      if (previous > orig_code)
+        {
+        memmove(orig_code, previous, code - previous);
+        code -= previous - orig_code;
+        previous = orig_code;
+        }
+      }
+    else code = orig_code;
+
+    /* Remember where this code item starts so we can pick up the length
+    next time round. */
+
+    last_code = code;
+    }
+
+  /* In the real compile phase, just check the workspace used by the forward
+  reference list. */
+
+  else if (cd->hwm > cd->start_workspace + COMPILE_WORK_SIZE)
+    {
+    *errorcodeptr = ERR52;
+    goto FAILED;
+    }
+
   /* If in \Q...\E, check for the end; if not, we have a literal */
 
   if (inescq && c != 0)
@@ -1692,7 +2170,8 @@ for (;; ptr++)
       {
       if (previous_callout != NULL)
         {
-        complete_callout(previous_callout, ptr, cd);
+        if (lengthptr == NULL)  /* Don't attempt in pre-compile phase */
+          complete_callout(previous_callout, ptr, cd);
         previous_callout = NULL;
         }
       if ((options & PCRE_AUTO_CALLOUT) != 0)
@@ -1713,7 +2192,8 @@ for (;; ptr++)
   if (!is_quantifier && previous_callout != NULL &&
        after_manual_callout-- <= 0)
     {
-    complete_callout(previous_callout, ptr, cd);
+    if (lengthptr == NULL)      /* Don't attempt in pre-compile phase */
+      complete_callout(previous_callout, ptr, cd);
     previous_callout = NULL;
     }
 
@@ -1724,12 +2204,12 @@ for (;; ptr++)
     if ((cd->ctypes[c] & ctype_space) != 0) continue;
     if (c == '#')
       {
-      while (*(++ptr) != 0) if (IS_NEWLINE(ptr)) break;
-      if (*ptr != 0)
+      while (*(++ptr) != 0)
         {
-        ptr += cd->nllen - 1;
-        continue;
+        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
         }
+      if (*ptr != 0) continue;
+
       /* Else fall through to handle end of string */
       c = 0;
       }
@@ -1745,17 +2225,23 @@ for (;; ptr++)
 
   switch(c)
     {
-    /* The branch terminates at end of string, |, or ). */
-
-    case 0:
-    case '|':
+    /* ===================================================================*/
+    case 0:                        /* The branch terminates at string end */
+    case '|':                      /* or | or ) */
     case ')':
     *firstbyteptr = firstbyte;
     *reqbyteptr = reqbyte;
     *codeptr = code;
     *ptrptr = ptr;
+    if (lengthptr != NULL)
+      {
+      *lengthptr += code - last_code;   /* To include callout length */
+      DPRINTF((">> end branch\n"));
+      }
     return TRUE;
 
+
+    /* ===================================================================*/
     /* Handle single-character metacharacters. In multiline mode, ^ disables
     the setting of any following char as a first character. */
 
@@ -1784,6 +2270,8 @@ for (;; ptr++)
     *code++ = OP_ANY;
     break;
 
+
+    /* ===================================================================*/
     /* Character classes. If the included characters are all < 256, we build a
     32-byte bitmap of the permitted characters, except in the special case
     where there is only one such character. For negated classes, we build the
@@ -1822,32 +2310,32 @@ for (;; ptr++)
       }
 
     /* Keep a count of chars with values < 256 so that we can optimize the case
-    of just a single character (as long as it's < 256). For higher valued UTF-8
-    characters, we don't yet do any optimization. */
+    of just a single character (as long as it's < 256). However, For higher
+    valued UTF-8 characters, we don't yet do any optimization. */
 
     class_charcount = 0;
     class_lastchar = -1;
 
+    /* Initialize the 32-char bit map to all zeros. We build the map in a
+    temporary bit of memory, in case the class contains only 1 character (less
+    than 256), because in that case the compiled code doesn't use the bit map.
+    */
+
+    memset(classbits, 0, 32 * sizeof(uschar));
+
 #ifdef SUPPORT_UTF8
     class_utf8 = FALSE;                       /* No chars >= 256 */
-    class_utf8data = code + LINK_SIZE + 34;   /* For UTF-8 items */
+    class_utf8data = code + LINK_SIZE + 2;    /* For UTF-8 items */
 #endif
 
-    /* Initialize the 32-char bit map to all zeros. We have to build the
-    map in a temporary bit of store, in case the class contains only 1
-    character (< 256), because in that case the compiled code doesn't use the
-    bit map. */
-
-    memset(classbits, 0, 32 * sizeof(uschar));
-
     /* Process characters until ] is reached. By writing this as a "do" it
-    means that an initial ] is taken as a data character. The first pass
-    through the regex checked the overall syntax, so we don't need to be very
-    strict here. At the start of the loop, c contains the first byte of the
-    character. */
+    means that an initial ] is taken as a data character. At the start of the
+    loop, c contains the first byte of the character. */
 
-    do
+    if (c != 0) do
       {
+      const uschar *oldptr;
+
 #ifdef SUPPORT_UTF8
       if (utf8 && c > 127)
         {                           /* Braces are required because the */
@@ -1859,13 +2347,13 @@ for (;; ptr++)
 
       if (inescq)
         {
-        if (c == '\\' && ptr[1] == 'E')
+        if (c == '\\' && ptr[1] == 'E')     /* If we are at \E */
           {
-          inescq = FALSE;
-          ptr++;
-          continue;
+          inescq = FALSE;                   /* Reset literal state */
+          ptr++;                            /* Skip the 'E' */
+          continue;                         /* Carry on with next */
           }
-        else goto LONE_SINGLE_CHARACTER;
+        goto CHECK_RANGE;                   /* Could be range if \E follows */
         }
 
       /* Handle POSIX class names. Perl allows a negation extension of the
@@ -1956,19 +2444,20 @@ for (;; ptr++)
         }
 
       /* Backslash may introduce a single character, or it may introduce one
-      of the specials, which just set a flag. Escaped items are checked for
-      validity in the pre-compiling pass. The sequence \b is a special case.
-      Inside a class (and only there) it is treated as backspace. Elsewhere
-      it marks a word boundary. Other escapes have preset maps ready to
-      or into the one we are building. We assume they have more than one
+      of the specials, which just set a flag. The sequence \b is a special
+      case. Inside a class (and only there) it is treated as backspace.
+      Elsewhere it marks a word boundary. Other escapes have preset maps ready
+      to or into the one we are building. We assume they have more than one
       character in them, so set class_charcount bigger than one. */
 
       if (c == '\\')
         {
-        c = check_escape(&ptr, errorcodeptr, *brackets, options, TRUE);
+        c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);
+        if (*errorcodeptr != 0) goto FAILED;
 
         if (-c == ESC_b) c = '\b';       /* \b is backslash in a class */
         else if (-c == ESC_X) c = 'X';   /* \X is literal X in a class */
+        else if (-c == ESC_R) c = 'R';   /* \R is literal R in a class */
         else if (-c == ESC_Q)            /* Handle start of quoted string */
           {
           if (ptr[1] == '\\' && ptr[2] == 'E')
@@ -1983,7 +2472,10 @@ for (;; ptr++)
           {
           register const uschar *cbits = cd->cbits;
           class_charcount += 2;     /* Greater than 1 is what matters */
-          switch (-c)
+
+          /* Save time by not doing this in the pre-compile phase. */
+
+          if (lengthptr == NULL) switch (-c)
             {
             case ESC_d:
             for (c = 0; c < 32; c++) classbits[c] |= cbits[c+cbit_digit];
@@ -2011,52 +2503,91 @@ for (;; ptr++)
             classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */
             continue;
 
-#ifdef SUPPORT_UCP
-            case ESC_p:
-            case ESC_P:
-              {
-              BOOL negated;
-              int pdata;
-              int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
-              if (ptype < 0) goto FAILED;
-              class_utf8 = TRUE;
-              *class_utf8data++ = ((-c == ESC_p) != negated)?
-                XCL_PROP : XCL_NOTPROP;
-              *class_utf8data++ = ptype;
-              *class_utf8data++ = pdata;
-              class_charcount -= 2;   /* Not a < 256 character */
-              }
+            case ESC_E: /* Perl ignores an orphan \E */
             continue;
-#endif
-
-            /* Unrecognized escapes are faulted if PCRE is running in its
-            strict mode. By default, for compatibility with Perl, they are
-            treated as literals. */
 
-            default:
-            if ((options & PCRE_EXTRA) != 0)
-              {
-              *errorcodeptr = ERR7;
-              goto FAILED;
-              }
-            c = *ptr;              /* The final character */
-            class_charcount -= 2;  /* Undo the default count from above */
+            default:    /* Not recognized; fall through */
+            break;      /* Need "default" setting to stop compiler warning. */
             }
-          }
 
-        /* Fall through if we have a single character (c >= 0). This may be
-        > 256 in UTF-8 mode. */
+          /* In the pre-compile phase, just do the recognition. */
 
-        }   /* End of backslash handling */
+          else if (c == -ESC_d || c == -ESC_D || c == -ESC_w ||
+                   c == -ESC_W || c == -ESC_s || c == -ESC_S) continue;
+
+          /* We need to deal with \P and \p in both phases. */
+
+#ifdef SUPPORT_UCP
+          if (-c == ESC_p || -c == ESC_P)
+            {
+            BOOL negated;
+            int pdata;
+            int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
+            if (ptype < 0) goto FAILED;
+            class_utf8 = TRUE;
+            *class_utf8data++ = ((-c == ESC_p) != negated)?
+              XCL_PROP : XCL_NOTPROP;
+            *class_utf8data++ = ptype;
+            *class_utf8data++ = pdata;
+            class_charcount -= 2;   /* Not a < 256 character */
+            continue;
+            }
+#endif
+          /* Unrecognized escapes are faulted if PCRE is running in its
+          strict mode. By default, for compatibility with Perl, they are
+          treated as literals. */
+
+          if ((options & PCRE_EXTRA) != 0)
+            {
+            *errorcodeptr = ERR7;
+            goto FAILED;
+            }
+
+          class_charcount -= 2;  /* Undo the default count from above */
+          c = *ptr;              /* Get the final character and fall through */
+          }
+
+        /* Fall through if we have a single character (c >= 0). This may be
+        greater than 256 in UTF-8 mode. */
+
+        }   /* End of backslash handling */
 
       /* A single character may be followed by '-' to form a range. However,
       Perl does not permit ']' to be the end of the range. A '-' character
-      here is treated as a literal. */
+      at the end is treated as a literal. Perl ignores orphaned \E sequences
+      entirely. The code for handling \Q and \E is messy. */
+
+      CHECK_RANGE:
+      while (ptr[1] == '\\' && ptr[2] == 'E')
+        {
+        inescq = FALSE;
+        ptr += 2;
+        }
+
+      oldptr = ptr;
 
-      if (ptr[1] == '-' && ptr[2] != ']')
+      if (!inescq && ptr[1] == '-')
         {
         int d;
         ptr += 2;
+        while (*ptr == '\\' && ptr[1] == 'E') ptr += 2;
+
+        /* If we hit \Q (not followed by \E) at this point, go into escaped
+        mode. */
+
+        while (*ptr == '\\' && ptr[1] == 'Q')
+          {
+          ptr += 2;
+          if (*ptr == '\\' && ptr[1] == 'E') { ptr += 2; continue; }
+          inescq = TRUE;
+          break;
+          }
+
+        if (*ptr == 0 || (!inescq && *ptr == ']'))
+          {
+          ptr = oldptr;
+          goto LONE_SINGLE_CHARACTER;
+          }
 
 #ifdef SUPPORT_UTF8
         if (utf8)
@@ -2071,27 +2602,34 @@ for (;; ptr++)
         not any of the other escapes. Perl 5.6 treats a hyphen as a literal
         in such circumstances. */
 
-        if (d == '\\')
+        if (!inescq && d == '\\')
           {
-          const uschar *oldptr = ptr;
-          d = check_escape(&ptr, errorcodeptr, *brackets, options, TRUE);
+          d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);
+          if (*errorcodeptr != 0) goto FAILED;
 
-          /* \b is backslash; \X is literal X; any other special means the '-'
-          was literal */
+          /* \b is backslash; \X is literal X; \R is literal R; any other
+          special means the '-' was literal */
 
           if (d < 0)
             {
             if (d == -ESC_b) d = '\b';
-            else if (d == -ESC_X) d = 'X'; else
+            else if (d == -ESC_X) d = 'X';
+            else if (d == -ESC_R) d = 'R'; else
               {
-              ptr = oldptr - 2;
+              ptr = oldptr;
               goto LONE_SINGLE_CHARACTER;  /* A few lines below */
               }
             }
           }
 
-        /* The check that the two values are in the correct order happens in
-        the pre-pass. Optimize one-character ranges */
+        /* Check that the two values are in the correct order. Optimize
+        one-character ranges */
+
+        if (d < c)
+          {
+          *errorcodeptr = ERR8;
+          goto FAILED;
+          }
 
         if (d == c) goto LONE_SINGLE_CHARACTER;  /* A few lines below */
 
@@ -2112,9 +2650,9 @@ for (;; ptr++)
 #ifdef SUPPORT_UCP
           if ((options & PCRE_CASELESS) != 0)
             {
-            int occ, ocd;
-            int cc = c;
-            int origd = d;
+            unsigned int occ, ocd;
+            unsigned int cc = c;
+            unsigned int origd = d;
             while (get_othercase_range(&cc, origd, &occ, &ocd))
               {
               if (occ >= c && ocd <= d) continue;  /* Skip embedded ranges */
@@ -2172,7 +2710,12 @@ for (;; ptr++)
         ranges that lie entirely within 0-127 when there is UCP support; else
         for partial ranges without UCP support. */
 
-        for (; c <= d; c++)
+        class_charcount += d - c + 1;
+        class_lastchar = d;
+
+        /* We can save a bit of time by skipping this in the pre-compile. */
+
+        if (lengthptr == NULL) for (; c <= d; c++)
           {
           classbits[c/8] |= (1 << (c&7));
           if ((options & PCRE_CASELESS) != 0)
@@ -2180,8 +2723,6 @@ for (;; ptr++)
             int uc = cd->fcc[c];           /* flip case */
             classbits[uc/8] |= (1 << (uc&7));
             }
-          class_charcount++;                /* in case a one-char range */
-          class_lastchar = c;
           }
 
         continue;   /* Go get the next char in the class */
@@ -2205,8 +2746,8 @@ for (;; ptr++)
 #ifdef SUPPORT_UCP
         if ((options & PCRE_CASELESS) != 0)
           {
-          int othercase;
-          if ((othercase = _pcre_ucp_othercase(c)) >= 0)
+          unsigned int othercase;
+          if ((othercase = _pcre_ucp_othercase(c)) != NOTACHAR)
             {
             *class_utf8data++ = XCL_SINGLE;
             class_utf8data += _pcre_ord2utf8(othercase, class_utf8data);
@@ -2231,10 +2772,15 @@ for (;; ptr++)
         }
       }
 
-    /* Loop until ']' reached; the check for end of string happens inside the
-    loop. This "while" is the end of the "do" above. */
+    /* Loop until ']' reached. This "while" is the end of the "do" above. */
 
-    while ((c = *(++ptr)) != ']' || inescq);
+    while ((c = *(++ptr)) != 0 && (c != ']' || inescq));
+
+    if (c == 0)                          /* Missing terminating ']' */
+      {
+      *errorcodeptr = ERR6;
+      goto FAILED;
+      }
 
     /* If class_charcount is 1, we saw precisely one character whose value is
     less than 256. In non-UTF-8 mode we can always optimize. In UTF-8 mode, we
@@ -2298,7 +2844,7 @@ for (;; ptr++)
 
     /* If there are characters with values > 255, we have to compile an
     extended class, with its own opcode. If there are no characters < 256,
-    we can omit the bitmap. */
+    we can omit the bitmap in the actual compiled code. */
 
 #ifdef SUPPORT_UTF8
     if (class_utf8)
@@ -2308,24 +2854,17 @@ for (;; ptr++)
       code += LINK_SIZE;
       *code = negate_class? XCL_NOT : 0;
 
-      /* If the map is required, install it, and move on to the end of
-      the extra data */
+      /* If the map is required, move up the extra data to make room for it;
+      otherwise just move the code pointer to the end of the extra data. */
 
       if (class_charcount > 0)
         {
         *code++ |= XCL_MAP;
+        memmove(code + 32, code, class_utf8data - code);
         memcpy(code, classbits, 32);
-        code = class_utf8data;
-        }
-
-      /* If the map is not required, slide down the extra data. */
-
-      else
-        {
-        int len = class_utf8data - (code + 33);
-        memmove(code + 1, code + 33, len);
-        code += len + 1;
+        code = class_utf8data + 32;
         }
+      else code = class_utf8data;
 
       /* Now fill in the complete length of the item */
 
@@ -2342,7 +2881,8 @@ for (;; ptr++)
     if (negate_class)
       {
       *code++ = OP_NCLASS;
-      for (c = 0; c < 32; c++) code[c] = ~classbits[c];
+      if (lengthptr == NULL)    /* Save time in the pre-compile phase */
+        for (c = 0; c < 32; c++) code[c] = ~classbits[c];
       }
     else
       {
@@ -2352,6 +2892,8 @@ for (;; ptr++)
     code += 32;
     break;
 
+
+    /* ===================================================================*/
     /* Various kinds of repeat; '{' is not necessarily a quantifier, but this
     has been tested above. */
 
@@ -2419,20 +2961,6 @@ for (;; ptr++)
       }
     else repeat_type = greedy_default;
 
-    /* If previous was a recursion, we need to wrap it inside brackets so that
-    it can be replicated if necessary. */
-
-    if (*previous == OP_RECURSE)
-      {
-      memmove(previous + 1 + LINK_SIZE, previous, 1 + LINK_SIZE);
-      code += 1 + LINK_SIZE;
-      *previous = OP_BRA;
-      PUT(previous, 1, code - previous);
-      *code = OP_KET;
-      PUT(code, 1, code - previous);
-      code += 1 + LINK_SIZE;
-      }
-
     /* If previous was a character match, abolish the item and generate a
     repeat item instead. If a char item has a minumum of more than one, ensure
     that it is set in reqbyte - it might not be if a sequence such as x{3} is
@@ -2466,18 +2994,40 @@ for (;; ptr++)
         if (repeat_min > 1) reqbyte = c | req_caseopt | cd->req_varyopt;
         }
 
+      /* If the repetition is unlimited, it pays to see if the next thing on
+      the line is something that cannot possibly match this character. If so,
+      automatically possessifying this item gains some performance in the case
+      where the match fails. */
+
+      if (!possessive_quantifier &&
+          repeat_max < 0 &&
+          check_auto_possessive(*previous, c, utf8, utf8_char, ptr + 1,
+            options, cd))
+        {
+        repeat_type = 0;    /* Force greedy */
+        possessive_quantifier = TRUE;
+        }
+
       goto OUTPUT_SINGLE_REPEAT;   /* Code shared with single character types */
       }
 
     /* If previous was a single negated character ([^a] or similar), we use
     one of the special opcodes, replacing it. The code is shared with single-
     character repeats by setting opt_type to add a suitable offset into
-    repeat_type. OP_NOT is currently used only for single-byte chars. */
+    repeat_type. We can also test for auto-possessification. OP_NOT is
+    currently used only for single-byte chars. */
 
     else if (*previous == OP_NOT)
       {
       op_type = OP_NOTSTAR - OP_STAR;  /* Use "not" opcodes */
       c = previous[1];
+      if (!possessive_quantifier &&
+          repeat_max < 0 &&
+          check_auto_possessive(OP_NOT, c, utf8, NULL, ptr + 1, options, cd))
+        {
+        repeat_type = 0;    /* Force greedy */
+        possessive_quantifier = TRUE;
+        }
       goto OUTPUT_SINGLE_REPEAT;
       }
 
@@ -2495,6 +3045,14 @@ for (;; ptr++)
       op_type = OP_TYPESTAR - OP_STAR;  /* Use type opcodes */
       c = *previous;
 
+      if (!possessive_quantifier &&
+          repeat_max < 0 &&
+          check_auto_possessive(c, 0, utf8, NULL, ptr + 1, options, cd))
+        {
+        repeat_type = 0;    /* Force greedy */
+        possessive_quantifier = TRUE;
+        }
+
       OUTPUT_SINGLE_REPEAT:
       if (*previous == OP_PROP || *previous == OP_NOTPROP)
         {
@@ -2535,7 +3093,7 @@ for (;; ptr++)
         }
 
       /* A repeat minimum of 1 is optimized into some special cases. If the
-      maximum is unlimited, we use OP_PLUS. Otherwise, the original item it
+      maximum is unlimited, we use OP_PLUS. Otherwise, the original item is
       left in place and, if the maximum is greater than 1, we use OP_UPTO with
       one less than the maximum. */
 
@@ -2588,7 +3146,8 @@ for (;; ptr++)
           }
 
         /* Else insert an UPTO if the max is greater than the min, again
-        preceded by the character, for the previously inserted code. */
+        preceded by the character, for the previously inserted code. If the
+        UPTO is just for 1 instance, we can use QUERY instead. */
 
         else if (repeat_max != repeat_min)
           {
@@ -2607,8 +3166,16 @@ for (;; ptr++)
             *code++ = prop_value;
             }
           repeat_max -= repeat_min;
-          *code++ = OP_UPTO + repeat_type;
-          PUT2INC(code, 0, repeat_max);
+
+          if (repeat_max == 1)
+            {
+            *code++ = OP_QUERY + repeat_type;
+            }
+          else
+            {
+            *code++ = OP_UPTO + repeat_type;
+            PUT2INC(code, 0, repeat_max);
+            }
           }
         }
 
@@ -2675,14 +3242,30 @@ for (;; ptr++)
     /* If previous was a bracket group, we may have to replicate it in certain
     cases. */
 
-    else if (*previous >= OP_BRA || *previous == OP_ONCE ||
-             *previous == OP_COND)
+    else if (*previous == OP_BRA  || *previous == OP_CBRA ||
+             *previous == OP_ONCE || *previous == OP_COND)
       {
       register int i;
       int ketoffset = 0;
       int len = code - previous;
       uschar *bralink = NULL;
 
+      /* Repeating a DEFINE group is pointless */
+
+      if (*previous == OP_COND && previous[LINK_SIZE+1] == OP_DEF)
+        {
+        *errorcodeptr = ERR55;
+        goto FAILED;
+        }
+
+      /* This is a paranoid check to stop integer overflow later on */
+
+      if (len > MAX_DUPLENGTH)
+        {
+        *errorcodeptr = ERR50;
+        goto FAILED;
+        }
+
       /* 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
@@ -2717,13 +3300,14 @@ for (;; ptr++)
         /* If the maximum is 1 or unlimited, we just have to stick in the
         BRAZERO and do no more at this point. However, we do need to adjust
         any OP_RECURSE calls inside the group that refer to the group itself or
-        any internal group, because the offset is from the start of the whole
-        regex. Temporarily terminate the pattern while doing this. */
+        any internal or forward referenced group, because the offset is from
+        the start of the whole regex. Temporarily terminate the pattern while
+        doing this. */
 
         if (repeat_max <= 1)
           {
           *code = OP_END;
-          adjust_recurse(previous, 1, utf8, cd);
+          adjust_recurse(previous, 1, utf8, cd, save_hwm);
           memmove(previous+1, previous, len);
           code++;
           *previous++ = OP_BRAZERO + repeat_type;
@@ -2741,7 +3325,7 @@ for (;; ptr++)
           {
           int offset;
           *code = OP_END;
-          adjust_recurse(previous, 2 + LINK_SIZE, utf8, cd);
+          adjust_recurse(previous, 2 + LINK_SIZE, utf8, cd, save_hwm);
           memmove(previous + 2 + LINK_SIZE, previous, len);
           code += 2 + LINK_SIZE;
           *previous++ = OP_BRAZERO + repeat_type;
@@ -2761,19 +3345,41 @@ for (;; ptr++)
       /* If the minimum is greater than zero, replicate the group as many
       times as necessary, and adjust the maximum to the number of subsequent
       copies that we need. If we set a first char from the group, and didn't
-      set a required char, copy the latter from the former. */
+      set a required char, copy the latter from the former. If there are any
+      forward reference subroutine calls in the group, there will be entries on
+      the workspace list; replicate these with an appropriate increment. */
 
       else
         {
         if (repeat_min > 1)
           {
-          if (groupsetfirstbyte && reqbyte < 0) reqbyte = firstbyte;
-          for (i = 1; i < repeat_min; i++)
+          /* In the pre-compile phase, we don't actually do the replication. We
+          just adjust the length as if we had. */
+
+          if (lengthptr != NULL)
+            *lengthptr += (repeat_min - 1)*length_prevgroup;
+
+          /* This is compiling for real */
+
+          else
             {
-            memcpy(code, previous, len);
-            code += len;
+            if (groupsetfirstbyte && reqbyte < 0) reqbyte = firstbyte;
+            for (i = 1; i < repeat_min; i++)
+              {
+              uschar *hc;
+              uschar *this_hwm = cd->hwm;
+              memcpy(code, previous, len);
+              for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
+                {
+                PUT(cd->hwm, 0, GET(hc, 0) + len);
+                cd->hwm += LINK_SIZE;
+                }
+              save_hwm = this_hwm;
+              code += len;
+              }
             }
           }
+
         if (repeat_max > 0) repeat_max -= repeat_min;
         }
 
@@ -2781,12 +3387,27 @@ for (;; ptr++)
       the maximum is limited, it replicates the group in a nested fashion,
       remembering the bracket starts on a stack. In the case of a zero minimum,
       the first one was set up above. In all cases the repeat_max now specifies
-      the number of additional copies needed. */
+      the number of additional copies needed. Again, we must remember to
+      replicate entries on the forward reference list. */
 
       if (repeat_max >= 0)
         {
-        for (i = repeat_max - 1; i >= 0; i--)
+        /* In the pre-compile phase, we don't actually do the replication. We
+        just adjust the length as if we had. For each repetition we must add 1
+        to the length for BRAZERO and for all but the last repetition we must
+        add 2 + 2*LINKSIZE to allow for the nesting that occurs. */
+
+        if (lengthptr != NULL && repeat_max > 0)
+          *lengthptr += repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -
+            2 - 2*LINK_SIZE;  /* Last one doesn't nest */
+
+        /* This is compiling for real */
+
+        else for (i = repeat_max - 1; i >= 0; i--)
           {
+          uschar *hc;
+          uschar *this_hwm = cd->hwm;
+
           *code++ = OP_BRAZERO + repeat_type;
 
           /* All but the final copy start a new nesting, maintaining the
@@ -2802,6 +3423,12 @@ for (;; ptr++)
             }
 
           memcpy(code, previous, len);
+          for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
+            {
+            PUT(cd->hwm, 0, GET(hc, 0) + len + ((i != 0)? 2+LINK_SIZE : 1));
+            cd->hwm += LINK_SIZE;
+            }
+          save_hwm = this_hwm;
           code += len;
           }
 
@@ -2824,9 +3451,34 @@ for (;; ptr++)
       /* 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. */
+      correct offset was computed above.
 
-      else code[-ketoffset] = OP_KETRMAX + repeat_type;
+      Then, when we are doing the actual compile phase, check to see whether
+      this group is a non-atomic one that could match an empty string. If so,
+      convert the initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so
+      that runtime checking can be done. [This check is also applied to
+      atomic groups at runtime, but in a different way.] */
+
+      else
+        {
+        uschar *ketcode = code - ketoffset;
+        uschar *bracode = ketcode - GET(ketcode, 1);
+        *ketcode = OP_KETRMAX + repeat_type;
+        if (lengthptr == NULL && *bracode != OP_ONCE)
+          {
+          uschar *scode = bracode;
+          do
+            {
+            if (could_be_empty_branch(scode, ketcode, utf8))
+              {
+              *bracode += OP_SBRA - OP_BRA;
+              break;
+              }
+            scode += GET(scode, 1);
+            }
+          while (*scode == OP_ALT);
+          }
+        }
       }
 
     /* Else there's some kind of shambles */
@@ -2837,22 +3489,53 @@ for (;; ptr++)
       goto FAILED;
       }
 
-    /* If the character following a repeat is '+', we wrap the entire repeated
-    item inside OP_ONCE brackets. This is just syntactic sugar, taken from
-    Sun's Java package. The repeated item starts at tempcode, not at previous,
-    which might be the first part of a string whose (former) last char we
-    repeated. However, we don't support '+' after a greediness '?'. */
+    /* If the character following a repeat is '+', or if certain optimization
+    tests above succeeded, possessive_quantifier is TRUE. For some of the
+    simpler opcodes, there is an special alternative opcode for this. For
+    anything else, we wrap the entire repeated item inside OP_ONCE brackets.
+    The '+' notation is just syntactic sugar, taken from Sun's Java package,
+    but the special opcodes can optimize it a bit. The repeated item starts at
+    tempcode, not at previous, which might be the first part of a string whose
+    (former) last char we repeated.
+
+    Possessifying an 'exact' quantifier has no effect, so we can ignore it. But
+    an 'upto' may follow. We skip over an 'exact' item, and then test the
+    length of what remains before proceeding. */
 
     if (possessive_quantifier)
       {
-      int len = code - tempcode;
-      memmove(tempcode + 1+LINK_SIZE, tempcode, len);
-      code += 1 + LINK_SIZE;
-      len += 1 + LINK_SIZE;
-      tempcode[0] = OP_ONCE;
-      *code++ = OP_KET;
-      PUTINC(code, 0, len);
-      PUT(tempcode, 1, len);
+      int len;
+      if (*tempcode == OP_EXACT || *tempcode == OP_TYPEEXACT ||
+          *tempcode == OP_NOTEXACT)
+        tempcode += _pcre_OP_lengths[*tempcode];
+      len = code - tempcode;
+      if (len > 0) switch (*tempcode)
+        {
+        case OP_STAR:  *tempcode = OP_POSSTAR; break;
+        case OP_PLUS:  *tempcode = OP_POSPLUS; break;
+        case OP_QUERY: *tempcode = OP_POSQUERY; break;
+        case OP_UPTO:  *tempcode = OP_POSUPTO; break;
+
+        case OP_TYPESTAR:  *tempcode = OP_TYPEPOSSTAR; break;
+        case OP_TYPEPLUS:  *tempcode = OP_TYPEPOSPLUS; break;
+        case OP_TYPEQUERY: *tempcode = OP_TYPEPOSQUERY; break;
+        case OP_TYPEUPTO:  *tempcode = OP_TYPEPOSUPTO; break;
+
+        case OP_NOTSTAR:  *tempcode = OP_NOTPOSSTAR; break;
+        case OP_NOTPLUS:  *tempcode = OP_NOTPOSPLUS; break;
+        case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break;
+        case OP_NOTUPTO:  *tempcode = OP_NOTPOSUPTO; break;
+
+        default:
+        memmove(tempcode + 1+LINK_SIZE, tempcode, len);
+        code += 1 + LINK_SIZE;
+        len += 1 + LINK_SIZE;
+        tempcode[0] = OP_ONCE;
+        *code++ = OP_KET;
+        PUTINC(code, 0, len);
+        PUT(tempcode, 1, len);
+        break;
+        }
       }
 
     /* In all case we no longer have a previous item. We also set the
@@ -2865,162 +3548,275 @@ for (;; ptr++)
     break;
 
 
-    /* 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.  */
+    /* ===================================================================*/
+    /* Start of nested parenthesized sub-expression, or comment or lookahead or
+    lookbehind or option setting or condition or all the other extended
+    parenthesis forms. First deal with the specials; all are introduced by ?,
+    and the appearance of any of them means that this is not a capturing
+    group. */
 
     case '(':
     newoptions = options;
     skipbytes = 0;
+    bravalue = OP_CBRA;
+    save_hwm = cd->hwm;
 
     if (*(++ptr) == '?')
       {
-      int set, unset;
+      int i, set, unset, namelen;
       int *optset;
+      const uschar *name;
+      uschar *slot;
 
       switch (*(++ptr))
         {
         case '#':                 /* Comment; skip to ket */
         ptr++;
-        while (*ptr != ')') ptr++;
+        while (*ptr != 0 && *ptr != ')') ptr++;
+        if (*ptr == 0)
+          {
+          *errorcodeptr = ERR18;
+          goto FAILED;
+          }
         continue;
 
-        case ':':                 /* Non-extracting bracket */
+
+        /* ------------------------------------------------------------ */
+        case ':':                 /* Non-capturing bracket */
         bravalue = OP_BRA;
         ptr++;
         break;
 
+
+        /* ------------------------------------------------------------ */
         case '(':
         bravalue = OP_COND;       /* Conditional group */
 
-        /* A condition can be a number, referring to a numbered group, a name,
-        referring to a named group, 'R', referring to recursion, or an
-        assertion. There are two unfortunate ambiguities, caused by history.
-        (a) 'R' can be the recursive thing or the name 'R', and (b) a number
-        could be a name that consists of digits. In both cases, we look for a
-        name first; if not found, we try the other cases. If the first
-        character after (?( is a word character, we know the rest up to ) will
-        also be word characters because the syntax was checked in the first
-        pass. */
-
-        if ((cd->ctypes[ptr[1]] & ctype_word) != 0)
+        /* A condition can be an assertion, a number (referring to a numbered
+        group), a name (referring to a named group), or 'R', referring to
+        recursion. R<digits> and R&name are also permitted for recursion tests.
+
+        There are several syntaxes for testing a named group: (?(name)) is used
+        by Python; Perl 5.10 onwards uses (?(<name>) or (?('name')).
+
+        There are two unfortunate ambiguities, caused by history. (a) 'R' can
+        be the recursive thing or the name 'R' (and similarly for 'R' followed
+        by digits), and (b) a number could be a name that consists of digits.
+        In both cases, we look for a name first; if not found, we try the other
+        cases. */
+
+        /* For conditions that are assertions, check the syntax, and then exit
+        the switch. This will take control down to where bracketed groups,
+        including assertions, are processed. */
+
+        if (ptr[1] == '?' && (ptr[2] == '=' || ptr[2] == '!' || ptr[2] == '<'))
+          break;
+
+        /* Most other conditions use OP_CREF (a couple change to OP_RREF
+        below), and all need to skip 3 bytes at the start of the group. */
+
+        code[1+LINK_SIZE] = OP_CREF;
+        skipbytes = 3;
+
+        /* Check for a test for recursion in a named group. */
+
+        if (ptr[1] == 'R' && ptr[2] == '&')
           {
-          int i, namelen;
-          int condref = 0;
-          const uschar *name;
-          uschar *slot = cd->name_table;
+          terminator = -1;
+          ptr += 2;
+          code[1+LINK_SIZE] = OP_RREF;    /* Change the type of test */
+          }
 
-          /* This is needed for all successful cases. */
+        /* Check for a test for a named group's having been set, using the Perl
+        syntax (?(<name>) or (?('name') */
 
-          skipbytes = 3;
+        else if (ptr[1] == '<')
+          {
+          terminator = '>';
+          ptr++;
+          }
+        else if (ptr[1] == '\'')
+          {
+          terminator = '\'';
+          ptr++;
+          }
+        else terminator = 0;
 
-          /* Read the name, but also get it as a number if it's all digits */
+        /* We now expect to read a name; any thing else is an error */
 
-          name = ++ptr;
-          while (*ptr != ')')
-            {
-            if (condref >= 0)
-              condref = ((digitab[*ptr] & ctype_digit) != 0)?
-                condref * 10 + *ptr - '0' : -1;
-            ptr++;
-            }
-          namelen = ptr - name;
+        if ((cd->ctypes[ptr[1]] & ctype_word) == 0)
+          {
+          ptr += 1;  /* To get the right offset */
+          *errorcodeptr = ERR28;
+          goto FAILED;
+          }
+
+        /* Read the name, but also get it as a number if it's all digits */
+
+        recno = 0;
+        name = ++ptr;
+        while ((cd->ctypes[*ptr] & ctype_word) != 0)
+          {
+          if (recno >= 0)
+            recno = ((digitab[*ptr] & ctype_digit) != 0)?
+              recno * 10 + *ptr - '0' : -1;
           ptr++;
+          }
+        namelen = ptr - name;
 
-          for (i = 0; i < cd->names_found; i++)
-            {
-            if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break;
-            slot += cd->name_entry_size;
-            }
+        if ((terminator > 0 && *ptr++ != terminator) || *ptr++ != ')')
+          {
+          ptr--;      /* Error offset */
+          *errorcodeptr = ERR26;
+          goto FAILED;
+          }
 
-          /* Found a previous named subpattern */
+        /* Do no further checking in the pre-compile phase. */
 
-          if (i < cd->names_found)
-            {
-            condref = GET2(slot, 0);
-            code[1+LINK_SIZE] = OP_CREF;
-            PUT2(code, 2+LINK_SIZE, condref);
-            }
+        if (lengthptr != NULL) break;
 
-          /* Search the pattern for a forward reference */
+        /* In the real compile we do the work of looking for the actual
+        reference. */
 
-          else if ((i = find_named_parens(ptr, *brackets, name, namelen)) > 0)
-            {
-            code[1+LINK_SIZE] = OP_CREF;
-            PUT2(code, 2+LINK_SIZE, i);
-            }
+        slot = cd->name_table;
+        for (i = 0; i < cd->names_found; i++)
+          {
+          if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break;
+          slot += cd->name_entry_size;
+          }
 
-          /* Check for 'R' for recursion */
+        /* Found a previous named subpattern */
 
-          else if (namelen == 1 && *name == 'R')
-            {
-            code[1+LINK_SIZE] = OP_CREF;
-            PUT2(code, 2+LINK_SIZE, CREF_RECURSE);
-            }
+        if (i < cd->names_found)
+          {
+          recno = GET2(slot, 0);
+          PUT2(code, 2+LINK_SIZE, recno);
+          }
 
-          /* Check for a subpattern number */
+        /* Search the pattern for a forward reference */
 
-          else if (condref > 0)
-            {
-            code[1+LINK_SIZE] = OP_CREF;
-            PUT2(code, 2+LINK_SIZE, condref);
-            }
+        else if ((i = find_parens(ptr, cd->bracount, name, namelen,
+                        (options & PCRE_EXTENDED) != 0)) > 0)
+          {
+          PUT2(code, 2+LINK_SIZE, i);
+          }
 
-          /* Either an unidentified subpattern, or a reference to (?(0) */
+        /* If terminator == 0 it means that the name followed directly after
+        the opening parenthesis [e.g. (?(abc)...] and in this case there are
+        some further alternatives to try. For the cases where terminator != 0
+        [things like (?(<name>... or (?('name')... or (?(R&name)... ] we have
+        now checked all the possibilities, so give an error. */
 
-          else
+        else if (terminator != 0)
+          {
+          *errorcodeptr = ERR15;
+          goto FAILED;
+          }
+
+        /* Check for (?(R) for recursion. Allow digits after R to specify a
+        specific group number. */
+
+        else if (*name == 'R')
+          {
+          recno = 0;
+          for (i = 1; i < namelen; i++)
             {
-            *errorcodeptr = (condref == 0)? ERR35: ERR15;
-            goto FAILED;
+            if ((digitab[name[i]] & ctype_digit) == 0)
+              {
+              *errorcodeptr = ERR15;
+              goto FAILED;
+              }
+            recno = recno * 10 + name[i] - '0';
             }
+          if (recno == 0) recno = RREF_ANY;
+          code[1+LINK_SIZE] = OP_RREF;      /* Change test type */
+          PUT2(code, 2+LINK_SIZE, recno);
+          }
+
+        /* Similarly, check for the (?(DEFINE) "condition", which is always
+        false. */
+
+        else if (namelen == 6 && strncmp((char *)name, "DEFINE", 6) == 0)
+          {
+          code[1+LINK_SIZE] = OP_DEF;
+          skipbytes = 1;
+          }
+
+        /* Check for the "name" actually being a subpattern number. */
+
+        else if (recno > 0)
+          {
+          PUT2(code, 2+LINK_SIZE, recno);
           }
 
-        /* For conditions that are assertions, we just fall through, having
-        set bravalue above. */
+        /* Either an unidentified subpattern, or a reference to (?(0) */
 
+        else
+          {
+          *errorcodeptr = (recno == 0)? ERR35: ERR15;
+          goto FAILED;
+          }
         break;
 
+
+        /* ------------------------------------------------------------ */
         case '=':                 /* Positive lookahead */
         bravalue = OP_ASSERT;
         ptr++;
         break;
 
+
+        /* ------------------------------------------------------------ */
         case '!':                 /* Negative lookahead */
         bravalue = OP_ASSERT_NOT;
         ptr++;
         break;
 
-        case '<':                 /* Lookbehinds */
-        switch (*(++ptr))
+
+        /* ------------------------------------------------------------ */
+        case '<':                 /* Lookbehind or named define */
+        switch (ptr[1])
           {
           case '=':               /* Positive lookbehind */
           bravalue = OP_ASSERTBACK;
-          ptr++;
+          ptr += 2;
           break;
 
           case '!':               /* Negative lookbehind */
           bravalue = OP_ASSERTBACK_NOT;
-          ptr++;
+          ptr += 2;
           break;
+
+          default:                /* Could be name define, else bad */
+          if ((cd->ctypes[ptr[1]] & ctype_word) != 0) goto DEFINE_NAME;
+          ptr++;                  /* Correct offset for error */
+          *errorcodeptr = ERR24;
+          goto FAILED;
           }
         break;
 
+
+        /* ------------------------------------------------------------ */
         case '>':                 /* One-time brackets */
         bravalue = OP_ONCE;
         ptr++;
         break;
 
+
+        /* ------------------------------------------------------------ */
         case 'C':                 /* Callout - may be followed by digits; */
         previous_callout = code;  /* Save for later completion */
         after_manual_callout = 1; /* Skip one item before completing */
-        *code++ = OP_CALLOUT;     /* Already checked that the terminating */
-          {                       /* closing parenthesis is present. */
+        *code++ = OP_CALLOUT;
+          {
           int n = 0;
           while ((digitab[*(++ptr)] & ctype_digit) != 0)
             n = n * 10 + *ptr - '0';
+          if (*ptr != ')')
+            {
+            *errorcodeptr = ERR39;
+            goto FAILED;
+            }
           if (n > 255)
             {
             *errorcodeptr = ERR38;
@@ -3034,134 +3830,232 @@ for (;; ptr++)
         previous = NULL;
         continue;
 
-        case 'P':                 /* Named subpattern handling */
-        if (*(++ptr) == '<')      /* Definition */
+
+        /* ------------------------------------------------------------ */
+        case 'P':                 /* Python-style named subpattern handling */
+        if (*(++ptr) == '=' || *ptr == '>')  /* Reference or recursion */
+          {
+          is_recurse = *ptr == '>';
+          terminator = ')';
+          goto NAMED_REF_OR_RECURSE;
+          }
+        else if (*ptr != '<')    /* Test for Python-style definition */
           {
-          int i, namelen;
-          uschar *slot = cd->name_table;
-          const uschar *name;     /* Don't amalgamate; some compilers */
-          name = ++ptr;           /* grumble at autoincrement in declaration */
+          *errorcodeptr = ERR41;
+          goto FAILED;
+          }
+        /* Fall through to handle (?P< as (?< is handled */
 
-          while (*ptr++ != '>');
-          namelen = ptr - name - 1;
 
-          for (i = 0; i < cd->names_found; i++)
+        /* ------------------------------------------------------------ */
+        DEFINE_NAME:    /* Come here from (?< handling */
+        case '\'':
+          {
+          terminator = (*ptr == '<')? '>' : '\'';
+          name = ++ptr;
+
+          while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++;
+          namelen = ptr - name;
+
+          /* In the pre-compile phase, just do a syntax check. */
+
+          if (lengthptr != NULL)
             {
-            int crc = memcmp(name, slot+2, namelen);
-            if (crc == 0)
+            if (*ptr != terminator)
+              {
+              *errorcodeptr = ERR42;
+              goto FAILED;
+              }
+            if (cd->names_found >= MAX_NAME_COUNT)
+              {
+              *errorcodeptr = ERR49;
+              goto FAILED;
+              }
+            if (namelen + 3 > cd->name_entry_size)
               {
-              if (slot[2+namelen] == 0)
+              cd->name_entry_size = namelen + 3;
+              if (namelen > MAX_NAME_SIZE)
                 {
-                if ((options & PCRE_DUPNAMES) == 0)
-                  {
-                  *errorcodeptr = ERR43;
-                  goto FAILED;
-                  }
+                *errorcodeptr = ERR48;
+                goto FAILED;
                 }
-              else crc = -1;      /* Current name is substring */
               }
-            if (crc < 0)
+            }
+
+          /* In the real compile, create the entry in the table */
+
+          else
+            {
+            slot = cd->name_table;
+            for (i = 0; i < cd->names_found; i++)
               {
-              memmove(slot + cd->name_entry_size, slot,
-                (cd->names_found - i) * cd->name_entry_size);
-              break;
+              int crc = memcmp(name, slot+2, namelen);
+              if (crc == 0)
+                {
+                if (slot[2+namelen] == 0)
+                  {
+                  if ((options & PCRE_DUPNAMES) == 0)
+                    {
+                    *errorcodeptr = ERR43;
+                    goto FAILED;
+                    }
+                  }
+                else crc = -1;      /* Current name is substring */
+                }
+              if (crc < 0)
+                {
+                memmove(slot + cd->name_entry_size, slot,
+                  (cd->names_found - i) * cd->name_entry_size);
+                break;
+                }
+              slot += cd->name_entry_size;
               }
-            slot += cd->name_entry_size;
-            }
 
-          PUT2(slot, 0, *brackets + 1);
-          memcpy(slot + 2, name, namelen);
-          slot[2+namelen] = 0;
-          cd->names_found++;
-          goto NUMBERED_GROUP;
+            PUT2(slot, 0, cd->bracount + 1);
+            memcpy(slot + 2, name, namelen);
+            slot[2+namelen] = 0;
+            }
           }
 
-        if (*ptr == '=' || *ptr == '>')  /* Reference or recursion */
-          {
-          int i, namelen;
-          int type = *ptr++;
-          const uschar *name = ptr;
-          uschar *slot = cd->name_table;
+        /* In both cases, count the number of names we've encountered. */
 
-          while (*ptr != ')') ptr++;
-          namelen = ptr - name;
+        ptr++;                    /* Move past > or ' */
+        cd->names_found++;
+        goto NUMBERED_GROUP;
 
-          for (i = 0; i < cd->names_found; i++)
-            {
-            if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break;
-            slot += cd->name_entry_size;
-            }
+
+        /* ------------------------------------------------------------ */
+        case '&':                 /* Perl recursion/subroutine syntax */
+        terminator = ')';
+        is_recurse = TRUE;
+        /* Fall through */
+
+        /* We come here from the Python syntax above that handles both
+        references (?P=name) and recursion (?P>name), as well as falling
+        through from the Perl recursion syntax (?&name). */
+
+        NAMED_REF_OR_RECURSE:
+        name = ++ptr;
+        while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++;
+        namelen = ptr - name;
+
+        /* In the pre-compile phase, do a syntax check and set a dummy
+        reference number. */
+
+        if (lengthptr != NULL)
+          {
+          if (*ptr != terminator)
+            {
+            *errorcodeptr = ERR42;
+            goto FAILED;
+            }
+          if (namelen > MAX_NAME_SIZE)
+            {
+            *errorcodeptr = ERR48;
+            goto FAILED;
+            }
+          recno = 0;
+          }
+
+        /* In the real compile, seek the name in the table */
+
+        else
+          {
+          slot = cd->name_table;
+          for (i = 0; i < cd->names_found; i++)
+            {
+            if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break;
+            slot += cd->name_entry_size;
+            }
 
           if (i < cd->names_found)         /* Back reference */
             {
             recno = GET2(slot, 0);
             }
           else if ((recno =                /* Forward back reference */
-                    find_named_parens(ptr, *brackets, name, namelen)) <= 0)
+                    find_parens(ptr, cd->bracount, name, namelen,
+                      (options & PCRE_EXTENDED) != 0)) <= 0)
             {
             *errorcodeptr = ERR15;
             goto FAILED;
             }
+          }
 
-          if (type == '>') goto HANDLE_RECURSION;  /* A few lines below */
-
-          /* Back reference */
+        /* In both phases, we can now go to the code than handles numerical
+        recursion or backreferences. */
 
-          previous = code;
-          *code++ = OP_REF;
-          PUT2INC(code, 0, recno);
-          cd->backref_map |= (recno < 32)? (1 << recno) : 1;
-          if (recno > cd->top_backref) cd->top_backref = recno;
-          continue;
-          }
+        if (is_recurse) goto HANDLE_RECURSION;
+          else goto HANDLE_REFERENCE;
 
-        /* Should never happen */
-        break;
 
-        case 'R':                 /* Pattern recursion */
+        /* ------------------------------------------------------------ */
+        case 'R':                 /* Recursion */
         ptr++;                    /* Same as (?0)      */
         /* Fall through */
 
-        /* Recursion or "subroutine" call */
 
-        case '0': case '1': case '2': case '3': case '4':
-        case '5': case '6': case '7': case '8': case '9':
+        /* ------------------------------------------------------------ */
+        case '0': case '1': case '2': case '3': case '4':   /* Recursion or */
+        case '5': case '6': case '7': case '8': case '9':   /* subroutine */
           {
           const uschar *called;
           recno = 0;
           while((digitab[*ptr] & ctype_digit) != 0)
             recno = recno * 10 + *ptr++ - '0';
+          if (*ptr != ')')
+            {
+            *errorcodeptr = ERR29;
+            goto FAILED;
+            }
 
           /* Come here from code above that handles a named recursion */
 
           HANDLE_RECURSION:
 
           previous = code;
+          called = cd->start_code;
 
-          /* Find the bracket that is being referenced. Temporarily end the
-          regex in case it doesn't exist. */
+          /* When we are actually compiling, find the bracket that is being
+          referenced. Temporarily end the regex in case it doesn't exist before
+          this point. If we end up with a forward reference, first check that
+          the bracket does occur later so we can give the error (and position)
+          now. Then remember this forward reference in the workspace so it can
+          be filled in at the end. */
 
-          *code = OP_END;
-          called = (recno == 0)? cd->start_code :
-            find_bracket(cd->start_code, utf8, recno);
-          if (called == NULL)
+          if (lengthptr == NULL)
             {
-            *errorcodeptr = ERR15;
-            goto FAILED;
-            }
+            *code = OP_END;
+            if (recno != 0) called = find_bracket(cd->start_code, utf8, recno);
 
-          /* If the subpattern is still open, this is a recursive call. We
-          check to see if this is a left recursion that could loop for ever,
-          and diagnose that case. */
+            /* Forward reference */
 
-          if (GET(called, 1) == 0 && could_be_empty(called, code, bcptr, utf8))
-            {
-            *errorcodeptr = ERR40;
-            goto FAILED;
+            if (called == NULL)
+              {
+              if (find_parens(ptr, cd->bracount, NULL, recno,
+                   (options & PCRE_EXTENDED) != 0) < 0)
+                {
+                *errorcodeptr = ERR15;
+                goto FAILED;
+                }
+              called = cd->start_code + recno;
+              PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code);
+              }
+
+            /* If not a forward reference, and the subpattern is still open,
+            this is a recursive call. We check to see if this is a left
+            recursion that could loop for ever, and diagnose that case. */
+
+            else if (GET(called, 1) == 0 &&
+                     could_be_empty(called, code, bcptr, utf8))
+              {
+              *errorcodeptr = ERR40;
+              goto FAILED;
+              }
             }
 
           /* Insert the recursion/subroutine item, automatically wrapped inside
-          "once" brackets. */
+          "once" brackets. Set up a "previous group" length so that a
+          subsequent quantifier will work. */
 
           *code = OP_ONCE;
           PUT(code, 1, 2 + 2*LINK_SIZE);
@@ -3174,12 +4068,18 @@ for (;; ptr++)
           *code = OP_KET;
           PUT(code, 1, 2 + 2*LINK_SIZE);
           code += 1 + LINK_SIZE;
+
+          length_prevgroup = 3 + 3*LINK_SIZE;
           }
+
+        /* Can't determine a first byte now */
+
+        if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;
         continue;
 
-        /* Character after (? not specially recognized */
 
-        default:                  /* Option setting */
+        /* ------------------------------------------------------------ */
+        default:              /* Other characters: check option setting */
         set = unset = 0;
         optset = &set;
 
@@ -3189,13 +4089,21 @@ for (;; ptr++)
             {
             case '-': optset = &unset; break;
 
+            case 'J':    /* Record that it changed in the external options */
+            *optset |= PCRE_DUPNAMES;
+            cd->external_options |= PCRE_JCHANGED;
+            break;
+
             case 'i': *optset |= PCRE_CASELESS; break;
-            case 'J': *optset |= PCRE_DUPNAMES; 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:  *errorcodeptr = ERR12;
+                      ptr--;    /* Correct the offset */
+                      goto FAILED;
             }
           }
 
@@ -3204,32 +4112,54 @@ for (;; ptr++)
         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. Compile
-        code to change the ims options if this setting actually changes any of
-        them. We also pass the new setting back so that it can be put at the
-        start of any following branches, and when this group ends (if we are in
-        a group), a resetting item can be compiled.
-
-        Note that if this item is right at the start of the pattern, the
-        options will have been abstracted and made global, so there will be no
-        change to compile. */
+        group with option changes, so the options change at this level. If this
+        item is right at the start of the pattern, the options can be
+        abstracted and made external in the pre-compile phase, and ignored in
+        the compile phase. This can be helpful when matching -- for instance in
+        caseless checking of required bytes.
+
+        If the code pointer is not (cd->start_code + 1 + LINK_SIZE), we are
+        definitely *not* at the start of the pattern because something has been
+        compiled. In the pre-compile phase, however, the code pointer can have
+        that value after the start, because it gets reset as code is discarded
+        during the pre-compile. However, this can happen only at top level - if
+        we are within parentheses, the starting BRA will still be present. At
+        any parenthesis level, the length value can be used to test if anything
+        has been compiled at that level. Thus, a test for both these conditions
+        is necessary to ensure we correctly detect the start of the pattern in
+        both phases.
+
+        If we are not at the pattern start, compile code to change the ims
+        options if this setting actually changes any of them. We also pass the
+        new setting back so that it can be put at the start of any following
+        branches, and when this group ends (if we are in a group), a resetting
+        item can be compiled. */
 
         if (*ptr == ')')
           {
-          if ((options & PCRE_IMS) != (newoptions & PCRE_IMS))
+          if (code == cd->start_code + 1 + LINK_SIZE &&
+               (lengthptr == NULL || *lengthptr == 2 + 2*LINK_SIZE))
             {
-            *code++ = OP_OPT;
-            *code++ = newoptions & PCRE_IMS;
+            cd->external_options = newoptions;
+            options = newoptions;
             }
+         else
+            {
+            if ((options & PCRE_IMS) != (newoptions & PCRE_IMS))
+              {
+              *code++ = OP_OPT;
+              *code++ = newoptions & PCRE_IMS;
+              }
 
-          /* Change options at this level, and pass them back for use
-          in subsequent branches. Reset the greedy defaults and the case
-          value for firstbyte and reqbyte. */
+            /* Change options at this level, and pass them back for use
+            in subsequent branches. Reset the greedy defaults and the case
+            value for firstbyte and reqbyte. */
 
-          *optionsptr = options = newoptions;
-          greedy_default = ((newoptions & PCRE_UNGREEDY) != 0);
-          greedy_non_default = greedy_default ^ 1;
-          req_caseopt = ((options & PCRE_CASELESS) != 0)? REQ_CASELESS : 0;
+            *optionsptr = options = newoptions;
+            greedy_default = ((newoptions & PCRE_UNGREEDY) != 0);
+            greedy_non_default = greedy_default ^ 1;
+            req_caseopt = ((options & PCRE_CASELESS) != 0)? REQ_CASELESS : 0;
+            }
 
           previous = NULL;       /* This item can't be repeated */
           continue;              /* It is complete */
@@ -3242,58 +4172,56 @@ for (;; ptr++)
 
         bravalue = OP_BRA;
         ptr++;
-        }
-      }
+        }     /* End of switch for character following (? */
+      }       /* End of (? handling */
 
-    /* If PCRE_NO_AUTO_CAPTURE is set, all unadorned brackets become
-    non-capturing and behave like (?:...) brackets */
+    /* Opening parenthesis not followed by '?'. If PCRE_NO_AUTO_CAPTURE is set,
+    all unadorned brackets become non-capturing and behave like (?:...)
+    brackets. */
 
     else if ((options & PCRE_NO_AUTO_CAPTURE) != 0)
       {
       bravalue = OP_BRA;
       }
 
-    /* Else we have a referencing group; adjust the opcode. If the bracket
-    number is greater than EXTRACT_BASIC_MAX, we set the opcode one higher, and
-    arrange for the true number to follow later, in an OP_BRANUMBER item. */
+    /* Else we have a capturing group. */
 
     else
       {
       NUMBERED_GROUP:
-      if (++(*brackets) > EXTRACT_BASIC_MAX)
-        {
-        bravalue = OP_BRA + EXTRACT_BASIC_MAX + 1;
-        code[1+LINK_SIZE] = OP_BRANUMBER;
-        PUT2(code, 2+LINK_SIZE, *brackets);
-        skipbytes = 3;
-        }
-      else bravalue = OP_BRA + *brackets;
+      cd->bracount += 1;
+      PUT2(code, 1+LINK_SIZE, cd->bracount);
+      skipbytes = 2;
       }
 
-    /* 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. */
+    /* Process nested bracketed regex. Assertions may not be repeated, but
+    other kinds can be. All their opcodes are >= OP_ONCE. 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;
     tempreqvary = cd->req_varyopt;     /* Save value before bracket */
+    length_prevgroup = 0;              /* Initialize for pre-compile phase */
 
     if (!compile_regex(
          newoptions,                   /* The complete new option state */
          options & PCRE_IMS,           /* The previous ims option state */
-         brackets,                     /* Extracting bracket count */
          &tempcode,                    /* Where to put code (updated) */
          &ptr,                         /* Input pointer (updated) */
          errorcodeptr,                 /* Where to put an error message */
          (bravalue == OP_ASSERTBACK ||
           bravalue == OP_ASSERTBACK_NOT), /* TRUE if back assert */
-         skipbytes,                    /* Skip over OP_COND/OP_BRANUMBER */
+         skipbytes,                    /* Skip over bracket number */
          &subfirstbyte,                /* For possible first char */
          &subreqbyte,                  /* For possible last char */
          bcptr,                        /* Current branch chain */
-         cd))                          /* Tables block */
+         cd,                           /* Tables block */
+         (lengthptr == NULL)? NULL :   /* Actual compile phase */
+           &length_prevgroup           /* Pre-compile phase */
+         ))
       goto FAILED;
 
     /* At the end of compiling, code is still pointing to the start of the
@@ -3302,9 +4230,9 @@ for (;; ptr++)
     is on the bracket. */
 
     /* If this is a conditional bracket, check that there are no more than
-    two branches in the group. */
+    two branches in the group, or just one if it's a DEFINE group. */
 
-    else if (bravalue == OP_COND)
+    if (bravalue == OP_COND)
       {
       uschar *tc = code;
       int condcount = 0;
@@ -3315,29 +4243,77 @@ for (;; ptr++)
          }
       while (*tc != OP_KET);
 
-      if (condcount > 2)
+      /* A DEFINE group is never obeyed inline (the "condition" is always
+      false). It must have only one branch. */
+
+      if (code[LINK_SIZE+1] == OP_DEF)
         {
-        *errorcodeptr = ERR27;
-        goto FAILED;
+        if (condcount > 1)
+          {
+          *errorcodeptr = ERR54;
+          goto FAILED;
+          }
+        bravalue = OP_DEF;   /* Just a flag to suppress char handling below */
+        }
+
+      /* A "normal" conditional group. If there is just one branch, we must not
+      make use of its firstbyte or reqbyte, because this is equivalent to an
+      empty second branch. */
+
+      else
+        {
+        if (condcount > 2)
+          {
+          *errorcodeptr = ERR27;
+          goto FAILED;
+          }
+        if (condcount == 1) subfirstbyte = subreqbyte = REQ_NONE;
         }
+      }
 
-      /* If there is just one branch, we must not make use of its firstbyte or
-      reqbyte, because this is equivalent to an empty second branch. */
+    /* Error if hit end of pattern */
+
+    if (*ptr != ')')
+      {
+      *errorcodeptr = ERR14;
+      goto FAILED;
+      }
+
+    /* In the pre-compile phase, update the length by the length of the nested
+    group, less the brackets at either end. Then reduce the compiled code to
+    just the brackets so that it doesn't use much memory if it is duplicated by
+    a quantifier. */
 
-      if (condcount == 1) subfirstbyte = subreqbyte = REQ_NONE;
+    if (lengthptr != NULL)
+      {
+      *lengthptr += length_prevgroup - 2 - 2*LINK_SIZE;
+      code++;
+      PUTINC(code, 0, 1 + LINK_SIZE);
+      *code++ = OP_KET;
+      PUTINC(code, 0, 1 + LINK_SIZE);
       }
 
-    /* Handle updating of the required and first characters. Update for normal
-    brackets of all kinds, and conditions with two branches (see code above).
-    If the bracket is followed by a quantifier with zero repeat, we have to
-    back off. Hence the definition of zeroreqbyte and zerofirstbyte outside the
-    main loop so that they can be accessed for the back off. */
+    /* Otherwise update the main code pointer to the end of the group. */
+
+    else code = tempcode;
+
+    /* For a DEFINE group, required and first character settings are not
+    relevant. */
+
+    if (bravalue == OP_DEF) break;
+
+    /* Handle updating of the required and first characters for other types of
+    group. Update for normal brackets of all kinds, and conditions with two
+    branches (see code above). If the bracket is followed by a quantifier with
+    zero repeat, we have to back off. Hence the definition of zeroreqbyte and
+    zerofirstbyte outside the main loop so that they can be accessed for the
+    back off. */
 
     zeroreqbyte = reqbyte;
     zerofirstbyte = firstbyte;
     groupsetfirstbyte = FALSE;
 
-    if (bravalue >= OP_BRA || bravalue == OP_ONCE || bravalue == OP_COND)
+    if (bravalue >= OP_ONCE)
       {
       /* If we have not yet set a firstbyte in this branch, take it from the
       subpattern, remembering that it was set here so that a repeat of more
@@ -3378,35 +4354,22 @@ for (;; ptr++)
     firstbyte, looking for an asserted first char. */
 
     else if (bravalue == OP_ASSERT && subreqbyte >= 0) reqbyte = subreqbyte;
+    break;     /* End of processing '(' */
 
-    /* Now update the main code pointer to the end of the group. */
-
-    code = tempcode;
-
-    /* Error if hit end of pattern */
-
-    if (*ptr != ')')
-      {
-      *errorcodeptr = ERR14;
-      goto FAILED;
-      }
-    break;
 
-    /* Check \ for being a real metacharacter; if not, fall through and handle
-    it as a data character at the start of a string. Escape items are checked
-    for validity in the pre-compiling pass. */
-
-    case '\\':
-    tempptr = ptr;
-    c = check_escape(&ptr, errorcodeptr, *brackets, options, FALSE);
-
-    /* Handle metacharacters introduced by \. For ones like \d, the ESC_ values
+    /* ===================================================================*/
+    /* Handle metasequences introduced by \. For ones like \d, the ESC_ values
     are arranged to be the negation of the corresponding OP_values. For the
     back references, the values are ESC_REF plus the reference number. Only
     back references and those types that consume a character may be repeated.
     We can test for values between ESC_b and ESC_Z for the latter; this may
     have to change if any new ones are ever created. */
 
+    case '\\':
+    tempptr = ptr;
+    c = check_escape(&ptr, errorcodeptr, cd->bracount, options, FALSE);
+    if (*errorcodeptr != 0) goto FAILED;
+
     if (c < 0)
       {
       if (-c == ESC_Q)            /* Handle start of quoted string */
@@ -3416,6 +4379,8 @@ for (;; ptr++)
         continue;
         }
 
+      if (-c == ESC_E) continue;  /* Perl ignores an orphan \E */
+
       /* For metasequences that actually match a character, we disable the
       setting of a first character if it hasn't already been set. */
 
@@ -3427,18 +4392,33 @@ for (;; ptr++)
       zerofirstbyte = firstbyte;
       zeroreqbyte = reqbyte;
 
-      /* Back references are handled specially */
+      /* \k<name> or \k'name' is a back reference by name (Perl syntax) */
+
+      if (-c == ESC_k && (ptr[1] == '<' || ptr[1] == '\''))
+        {
+        is_recurse = FALSE;
+        terminator = (*(++ptr) == '<')? '>' : '\'';
+        goto NAMED_REF_OR_RECURSE;
+        }
+
+      /* Back references are handled specially; must disable firstbyte if
+      not set to cope with cases like (?=(\w+))\1: which would otherwise set
+      ':' later. */
 
       if (-c >= ESC_REF)
         {
-        int number = -c - ESC_REF;
+        recno = -c - ESC_REF;
+
+        HANDLE_REFERENCE:    /* Come here from named backref handling */
+        if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;
         previous = code;
         *code++ = OP_REF;
-        PUT2INC(code, 0, number);
+        PUT2INC(code, 0, recno);
+        cd->backref_map |= (recno < 32)? (1 << recno) : 1;
+        if (recno > cd->top_backref) cd->top_backref = recno;
         }
 
-      /* So are Unicode property matches, if supported. We know that get_ucp
-      won't fail because it was tested in the pre-pass. */
+      /* So are Unicode property matches, if supported. */
 
 #ifdef SUPPORT_UCP
       else if (-c == ESC_P || -c == ESC_p)
@@ -3446,15 +4426,26 @@ for (;; ptr++)
         BOOL negated;
         int pdata;
         int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
+        if (ptype < 0) goto FAILED;
         previous = code;
         *code++ = ((-c == ESC_p) != negated)? OP_PROP : OP_NOTPROP;
         *code++ = ptype;
         *code++ = pdata;
         }
+#else
+
+      /* If Unicode properties are not supported, \X, \P, and \p are not
+      allowed. */
+
+      else if (-c == ESC_X || -c == ESC_P || -c == ESC_p)
+        {
+        *errorcodeptr = ERR45;
+        goto FAILED;
+        }
 #endif
 
-      /* For the rest, we can obtain the OP value by negating the escape
-      value */
+      /* For the rest (including \X when Unicode properties are supported), we
+      can obtain the OP value by negating the escape value. */
 
       else
         {
@@ -3478,9 +4469,10 @@ for (;; ptr++)
      mcbuffer[0] = c;
      mclength = 1;
      }
-
     goto ONE_CHAR;
 
+
+    /* ===================================================================*/
     /* Handle a literal character. It is guaranteed not to be whitespace or #
     when the extended flag is set. If we are in UTF-8 mode, it may be a
     multi-byte literal character. */
@@ -3491,7 +4483,7 @@ for (;; ptr++)
     mcbuffer[0] = c;
 
 #ifdef SUPPORT_UTF8
-    if (utf8 && (c & 0xc0) == 0xc0)
+    if (utf8 && c >= 0xc0)
       {
       while ((ptr[1] & 0xc0) == 0x80)
         mcbuffer[mclength++] = *(++ptr);
@@ -3542,6 +4534,7 @@ for (;; ptr++)
     }
   }                   /* end of big loop */
 
+
 /* Control never reaches here by falling through, only by a goto for all the
 error states. Pass back the position in the pattern so that it can be displayed
 to the user for diagnosing the error. */
@@ -3558,35 +4551,40 @@ return FALSE;
 *     Compile sequence of alternatives           *
 *************************************************/
 
-/* 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. 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.
+/* 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.
+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.
+
+This function is used during the pre-compile phase when we are trying to find
+out the amount of memory needed, as well as during the real compile phase. The
+value of lengthptr distinguishes the two phases.
 
 Argument:
   options        option bits, including any changes for this subpattern
   oldims         previous settings of ims 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
   errorcodeptr   -> pointer to error code variable
   lookbehind     TRUE if this is a lookbehind assertion
-  skipbytes      skip this many bytes at start (for OP_COND, OP_BRANUMBER)
+  skipbytes      skip this many bytes at start (for brackets and OP_COND)
   firstbyteptr   place to put the first required character, or a negative number
   reqbyteptr     place to put the last required character, or a negative number
   bcptr          pointer to the chain of currently open branches
   cd             points to the data block with tables pointers etc.
+  lengthptr      NULL during the real compile phase
+                 points to length accumulator during pre-compile phase
 
-Returns:      TRUE on success
+Returns:         TRUE on success
 */
 
 static BOOL
-compile_regex(int options, int oldims, int *brackets, uschar **codeptr,
-  const uschar **ptrptr, int *errorcodeptr, BOOL lookbehind, int skipbytes,
-  int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr, compile_data *cd)
+compile_regex(int options, int oldims, uschar **codeptr, const uschar **ptrptr,
+  int *errorcodeptr, BOOL lookbehind, int skipbytes, int *firstbyteptr,
+  int *reqbyteptr, branch_chain *bcptr, compile_data *cd, int *lengthptr)
 {
 const uschar *ptr = *ptrptr;
 uschar *code = *codeptr;
@@ -3595,6 +4593,7 @@ uschar *start_bracket = code;
 uschar *reverse_count = NULL;
 int firstbyte, reqbyte;
 int branchfirstbyte, branchreqbyte;
+int length;
 branch_chain bc;
 
 bc.outer = bcptr;
@@ -3602,6 +4601,20 @@ bc.current = code;
 
 firstbyte = reqbyte = REQ_UNSET;
 
+/* Accumulate the length for use in the pre-compile phase. Start with the
+length of the BRA and KET and any extra bytes that are required at the
+beginning. We accumulate in a local variable to save frequent testing of
+lenthptr for NULL. We cannot do this by looking at the value of code at the
+start and end of each alternative, because compiled items are discarded during
+the pre-compile phase so that the work space is not exceeded. */
+
+length = 2 + 2*LINK_SIZE + skipbytes;
+
+/* WARNING: If the above line is changed for any reason, you must also change
+the code that abstracts option settings at the start of the pattern and makes
+them global. It tests the value of length for (2 + 2*LINK_SIZE) in the
+pre-compile phase to find out whether anything has yet been compiled or not. */
+
 /* Offset is set zero to mark that this bracket is still open */
 
 PUT(code, 1, 0);
@@ -3617,6 +4630,7 @@ for (;;)
     {
     *code++ = OP_OPT;
     *code++ = options & PCRE_IMS;
+    length += 2;
     }
 
   /* Set up dummy OP_REVERSE if lookbehind assertion */
@@ -3626,73 +4640,80 @@ for (;;)
     *code++ = OP_REVERSE;
     reverse_count = code;
     PUTINC(code, 0, 0);
+    length += 1 + LINK_SIZE;
     }
 
-  /* Now compile the branch */
+  /* Now compile the branch; in the pre-compile phase its length gets added
+  into the length. */
 
-  if (!compile_branch(&options, brackets, &code, &ptr, errorcodeptr,
-        &branchfirstbyte, &branchreqbyte, &bc, cd))
+  if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstbyte,
+        &branchreqbyte, &bc, cd, (lengthptr == NULL)? NULL : &length))
     {
     *ptrptr = ptr;
     return FALSE;
     }
 
-  /* If this is the first branch, the firstbyte and reqbyte values for the
-  branch become the values for the regex. */
+  /* In the real compile phase, there is some post-processing to be done. */
 
-  if (*last_branch != OP_ALT)
+  if (lengthptr == NULL)
     {
-    firstbyte = branchfirstbyte;
-    reqbyte = branchreqbyte;
-    }
+    /* If this is the first branch, the firstbyte and reqbyte values for the
+    branch become the values for the regex. */
 
-  /* If this is not the first branch, the first char and reqbyte have to
-  match the values from all the previous branches, except that if the previous
-  value for reqbyte didn't have REQ_VARY set, it can still match, and we set
-  REQ_VARY for the regex. */
+    if (*last_branch != OP_ALT)
+      {
+      firstbyte = branchfirstbyte;
+      reqbyte = branchreqbyte;
+      }
 
-  else
-    {
-    /* If we previously had a firstbyte, but it doesn't match the new branch,
-    we have to abandon the firstbyte for the regex, but if there was previously
-    no reqbyte, it takes on the value of the old firstbyte. */
+    /* If this is not the first branch, the first char and reqbyte have to
+    match the values from all the previous branches, except that if the
+    previous value for reqbyte didn't have REQ_VARY set, it can still match,
+    and we set REQ_VARY for the regex. */
 
-    if (firstbyte >= 0 && firstbyte != branchfirstbyte)
+    else
       {
-      if (reqbyte < 0) reqbyte = firstbyte;
-      firstbyte = REQ_NONE;
-      }
+      /* If we previously had a firstbyte, but it doesn't match the new branch,
+      we have to abandon the firstbyte for the regex, but if there was
+      previously no reqbyte, it takes on the value of the old firstbyte. */
+
+      if (firstbyte >= 0 && firstbyte != branchfirstbyte)
+        {
+        if (reqbyte < 0) reqbyte = firstbyte;
+        firstbyte = REQ_NONE;
+        }
 
-    /* If we (now or from before) have no firstbyte, a firstbyte from the
-    branch becomes a reqbyte if there isn't a branch reqbyte. */
+      /* If we (now or from before) have no firstbyte, a firstbyte from the
+      branch becomes a reqbyte if there isn't a branch reqbyte. */
 
-    if (firstbyte < 0 && branchfirstbyte >= 0 && branchreqbyte < 0)
-        branchreqbyte = branchfirstbyte;
+      if (firstbyte < 0 && branchfirstbyte >= 0 && branchreqbyte < 0)
+          branchreqbyte = branchfirstbyte;
 
-    /* Now ensure that the reqbytes match */
+      /* Now ensure that the reqbytes match */
 
-    if ((reqbyte & ~REQ_VARY) != (branchreqbyte & ~REQ_VARY))
-      reqbyte = REQ_NONE;
-    else reqbyte |= branchreqbyte;   /* To "or" REQ_VARY */
-    }
+      if ((reqbyte & ~REQ_VARY) != (branchreqbyte & ~REQ_VARY))
+        reqbyte = REQ_NONE;
+      else reqbyte |= branchreqbyte;   /* To "or" REQ_VARY */
+      }
 
-  /* 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, 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)
-    {
-    int length;
-    *code = OP_END;
-    length = find_fixedlength(last_branch, options);
-    DPRINTF(("fixed length = %d\n", length));
-    if (length < 0)
+    if (lookbehind)
       {
-      *errorcodeptr = (length == -2)? ERR36 : ERR25;
-      *ptrptr = ptr;
-      return FALSE;
+      int fixed_length;
+      *code = OP_END;
+      fixed_length = find_fixedlength(last_branch, options);
+      DPRINTF(("fixed length = %d\n", fixed_length));
+      if (fixed_length < 0)
+        {
+        *errorcodeptr = (fixed_length == -2)? ERR36 : ERR25;
+        *ptrptr = ptr;
+        return FALSE;
+        }
+      PUT(reverse_count, 0, fixed_length);
       }
-    PUT(reverse_count, 0, length);
     }
 
   /* Reached end of expression, either ')' or end of pattern. Go back through
@@ -3706,15 +4727,15 @@ for (;;)
 
   if (*ptr != '|')
     {
-    int length = code - last_branch;
+    int branch_length = code - last_branch;
     do
       {
       int prev_length = GET(last_branch, 1);
-      PUT(last_branch, 1, length);
-      length = prev_length;
-      last_branch -= length;
+      PUT(last_branch, 1, branch_length);
+      branch_length = prev_length;
+      last_branch -= branch_length;
       }
-    while (length > 0);
+    while (branch_length > 0);
 
     /* Fill in the ket */
 
@@ -3728,6 +4749,7 @@ for (;;)
       {
       *code++ = OP_OPT;
       *code++ = oldims;
+      length += 2;
       }
 
     /* Set values to pass back */
@@ -3736,6 +4758,7 @@ for (;;)
     *ptrptr = ptr;
     *firstbyteptr = firstbyte;
     *reqbyteptr = reqbyte;
+    if (lengthptr != NULL) *lengthptr += length;
     return TRUE;
     }
 
@@ -3749,6 +4772,7 @@ for (;;)
   bc.current = last_branch = code;
   code += 1 + LINK_SIZE;
   ptr++;
+  length += 1 + LINK_SIZE;
   }
 /* Control never reaches here */
 }
@@ -3799,24 +4823,29 @@ is_anchored(register const uschar *code, int *options, unsigned int bracket_map,
   unsigned int backref_map)
 {
 do {
-   const uschar *scode =
-     first_significant_code(code + 1+LINK_SIZE, options, PCRE_MULTILINE, FALSE);
+   const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code],
+     options, PCRE_MULTILINE, FALSE);
    register int op = *scode;
 
+   /* Non-capturing brackets */
+
+   if (op == OP_BRA)
+     {
+     if (!is_anchored(scode, options, bracket_map, backref_map)) return FALSE;
+     }
+
    /* Capturing brackets */
 
-   if (op > OP_BRA)
+   else if (op == OP_CBRA)
      {
-     int new_map;
-     op -= OP_BRA;
-     if (op > EXTRACT_BASIC_MAX) op = GET2(scode, 2+LINK_SIZE);
-     new_map = bracket_map | ((op < 32)? (1 << op) : 1);
+     int n = GET2(scode, 1+LINK_SIZE);
+     int new_map = bracket_map | ((n < 32)? (1 << n) : 1);
      if (!is_anchored(scode, options, new_map, backref_map)) return FALSE;
      }
 
    /* Other brackets */
 
-   else if (op == OP_BRA || op == OP_ASSERT || op == OP_ONCE || op == OP_COND)
+   else if (op == OP_ASSERT || op == OP_ONCE || op == OP_COND)
      {
      if (!is_anchored(scode, options, bracket_map, backref_map)) return FALSE;
      }
@@ -3824,7 +4853,8 @@ do {
    /* .* is not anchored unless DOTALL is set and it isn't in brackets that
    are or may be referenced. */
 
-   else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR) &&
+   else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR ||
+             op == OP_TYPEPOSSTAR) &&
             (*options & PCRE_DOTALL) != 0)
      {
      if (scode[1] != OP_ANY || (bracket_map & backref_map) != 0) return FALSE;
@@ -3869,30 +4899,35 @@ is_startline(const uschar *code, unsigned int bracket_map,
   unsigned int backref_map)
 {
 do {
-   const uschar *scode = first_significant_code(code + 1+LINK_SIZE, NULL, 0,
-     FALSE);
+   const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code],
+     NULL, 0, FALSE);
    register int op = *scode;
 
+   /* Non-capturing brackets */
+
+   if (op == OP_BRA)
+     {
+     if (!is_startline(scode, bracket_map, backref_map)) return FALSE;
+     }
+
    /* Capturing brackets */
 
-   if (op > OP_BRA)
+   else if (op == OP_CBRA)
      {
-     int new_map;
-     op -= OP_BRA;
-     if (op > EXTRACT_BASIC_MAX) op = GET2(scode, 2+LINK_SIZE);
-     new_map = bracket_map | ((op < 32)? (1 << op) : 1);
+     int n = GET2(scode, 1+LINK_SIZE);
+     int new_map = bracket_map | ((n < 32)? (1 << n) : 1);
      if (!is_startline(scode, new_map, backref_map)) return FALSE;
      }
 
    /* Other brackets */
 
-   else if (op == OP_BRA || op == OP_ASSERT || op == OP_ONCE || op == OP_COND)
+   else if (op == OP_ASSERT || op == OP_ONCE || op == OP_COND)
      { if (!is_startline(scode, bracket_map, backref_map)) return FALSE; }
 
    /* .* means "start at start or after \n" if it isn't in brackets that
    may be referenced. */
 
-   else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR)
+   else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR || op == OP_TYPEPOSSTAR)
      {
      if (scode[1] != OP_ANY || (bracket_map & backref_map) != 0) return FALSE;
      }
@@ -3941,14 +4976,13 @@ do {
      first_significant_code(code + 1+LINK_SIZE, 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_CBRA:
      case OP_ASSERT:
      case OP_ONCE:
      case OP_COND:
@@ -3964,6 +4998,7 @@ do {
      case OP_CHARNC:
      case OP_PLUS:
      case OP_MINPLUS:
+     case OP_POSPLUS:
      if (!inassert) return -1;
      if (c < 0)
        {
@@ -4012,37 +5047,36 @@ return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
 }
 
 
-
 PCRE_DATA_SCOPE pcre *
 pcre_compile2(const char *pattern, int options, int *errorcodeptr,
   const char **errorptr, int *erroroffset, const unsigned char *tables)
 {
 real_pcre *re;
-int length = 1 + LINK_SIZE;      /* For initial BRA plus length */
-int c, firstbyte, reqbyte, newline;
-int bracount = 0;
-int branch_extra = 0;
-int branch_newextra;
-int item_count = -1;
-int name_count = 0;
-int max_name_size = 0;
-int lastitemlength = 0;
+int length = 1;  /* For final END opcode */
+int firstbyte, reqbyte, newline;
 int errorcode = 0;
 #ifdef SUPPORT_UTF8
 BOOL utf8;
-BOOL class_utf8;
 #endif
-BOOL inescq = FALSE;
-BOOL capturing;
-unsigned int brastackptr = 0;
 size_t size;
 uschar *code;
 const uschar *codestart;
 const uschar *ptr;
 compile_data compile_block;
 compile_data *cd = &compile_block;
-int brastack[BRASTACK_SIZE];
-uschar bralenstack[BRASTACK_SIZE];
+
+/* This space is used for "compiling" into during the first phase, when we are
+computing the amount of memory that is needed. Compiled items are thrown away
+as soon as possible, so that a fairly large buffer should be sufficient for
+this purpose. The same space is used in the second phase for remembering where
+to fill in forward references to subpatterns. */
+
+uschar cworkspace[COMPILE_WORK_SIZE];
+
+
+/* Set this early so that early errors get offset 0. */
+
+ptr = (const uschar *)pattern;
 
 /* We can't pass back an error message if errorptr is NULL; I guess the best we
 can do is just return NULL, but we can set a code value if there is a code
@@ -4075,7 +5109,7 @@ if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&
      (*erroroffset = _pcre_valid_utf8((uschar *)pattern, -1)) >= 0)
   {
   errorcode = ERR44;
-  goto PCRE_EARLY_ERROR_RETURN;
+  goto PCRE_UTF8_ERROR_RETURN;
   }
 #else
 if ((options & PCRE_UTF8) != 0)
@@ -4099,34 +5133,43 @@ cd->fcc = tables + fcc_offset;
 cd->cbits = tables + cbits_offset;
 cd->ctypes = tables + ctypes_offset;
 
-/* Handle different types of newline. The two bits give four cases. The current
-code allows for one- or two-byte sequences. */
+/* Handle different types of newline. The three bits give seven cases. The
+current code allows for fixed one- or two-byte sequences, plus "any". */
 
-switch (options & PCRE_NEWLINE_CRLF)
+switch (options & (PCRE_NEWLINE_CRLF | PCRE_NEWLINE_ANY))
   {
-  default:              newline = NEWLINE; break;   /* Compile-time default */
+  case 0: newline = NEWLINE; break;   /* Compile-time default */
   case PCRE_NEWLINE_CR: newline = '\r'; break;
   case PCRE_NEWLINE_LF: newline = '\n'; break;
   case PCRE_NEWLINE_CR+
        PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;
+  case PCRE_NEWLINE_ANY: newline = -1; break;
+  default: errorcode = ERR56; goto PCRE_EARLY_ERROR_RETURN;
   }
 
-if (newline > 255)
+if (newline < 0)
   {
-  cd->nllen = 2;
-  cd->nl[0] = (newline >> 8) & 255;
-  cd->nl[1] = newline & 255;
+  cd->nltype = NLTYPE_ANY;
   }
 else
   {
-  cd->nllen = 1;
-  cd->nl[0] = newline;
+  cd->nltype = NLTYPE_FIXED;
+  if (newline > 255)
+    {
+    cd->nllen = 2;
+    cd->nl[0] = (newline >> 8) & 255;
+    cd->nl[1] = newline & 255;
+    }
+  else
+    {
+    cd->nllen = 1;
+    cd->nl[0] = newline;
+    }
   }
 
-/* Maximum back reference and backref bitmap. This is updated for numeric
-references during the first pass, but for named references during the actual
-compile pass. The bitmap records up to 31 back references to help in deciding
-whether (.*) can be treated as anchored or not. */
+/* Maximum back reference and backref bitmap. The bitmap records up to 31 back
+references to help in deciding whether (.*) can be treated as anchored or not.
+*/
 
 cd->top_backref = 0;
 cd->backref_map = 0;
@@ -4136,1041 +5179,151 @@ cd->backref_map = 0;
 DPRINTF(("------------------------------------------------------------------\n"));
 DPRINTF(("%s\n", pattern));
 
-/* The first thing to do is to make a pass over the pattern to compute the
-amount of store required to hold the compiled code. This does not have to be
-perfect as long as errors are overestimates. At the same time we can detect any
-flag settings right at the start, and extract them. Make an attempt to correct
-for any counted white space if an "extended" flag setting appears late in the
-pattern. We can't be so clever for #-comments. */
+/* Pretend to compile the pattern while actually just accumulating the length
+of memory required. This behaviour is triggered by passing a non-NULL final
+argument to compile_regex(). We pass a block of workspace (cworkspace) for it
+to compile parts of the pattern into; the compiled code is discarded when it is
+no longer needed, so hopefully this workspace will never overflow, though there
+is a test for its doing so. */
 
-ptr = (const uschar *)(pattern - 1);
-while ((c = *(++ptr)) != 0)
-  {
-  int min, max;
-  int class_optcount;
-  int bracket_length;
-  int duplength;
+cd->bracount = 0;
+cd->names_found = 0;
+cd->name_entry_size = 0;
+cd->name_table = NULL;
+cd->start_workspace = cworkspace;
+cd->start_code = cworkspace;
+cd->hwm = cworkspace;
+cd->start_pattern = (const uschar *)pattern;
+cd->end_pattern = (const uschar *)(pattern + strlen(pattern));
+cd->req_varyopt = 0;
+cd->nopartial = FALSE;
+cd->external_options = options;
 
-  /* If we are inside a \Q...\E sequence, all chars are literal */
+/* Now do the pre-compile. On error, errorcode will be set non-zero, so we
+don't need to look at the result of the function here. The initial options have
+been put into the cd block so that they can be changed if an option setting is
+found within the regex right at the beginning. Bringing initial option settings
+outside can help speed up starting point checks. */
 
-  if (inescq)
-    {
-    if ((options & PCRE_AUTO_CALLOUT) != 0) length += 2 + 2*LINK_SIZE;
-    goto NORMAL_CHAR;
-    }
+code = cworkspace;
+*code = OP_BRA;
+(void)compile_regex(cd->external_options, cd->external_options & PCRE_IMS,
+  &code, &ptr, &errorcode, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, &length);
+if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;
 
-  /* Otherwise, first check for ignored whitespace and comments */
+DPRINTF(("end pre-compile: length=%d workspace=%d\n", length,
+  cd->hwm - cworkspace));
 
-  if ((options & PCRE_EXTENDED) != 0)
-    {
-    if ((cd->ctypes[c] & ctype_space) != 0) continue;
-    if (c == '#')
-      {
-      while (*(++ptr) != 0) if (IS_NEWLINE(ptr)) break;
-      if (*ptr != 0)
-        {
-        ptr += cd->nllen - 1;
-        continue;
-        }
-      break;    /* End loop at end of pattern */
-      }
-    }
+if (length > MAX_PATTERN_SIZE)
+  {
+  errorcode = ERR20;
+  goto PCRE_EARLY_ERROR_RETURN;
+  }
 
-  item_count++;    /* Is zero for the first non-comment item */
+/* Compute the size of data block needed and get it, either from malloc or
+externally provided function. Integer overflow should no longer be possible
+because nowadays we limit the maximum value of cd->names_found and
+cd->name_entry_size. */
 
-  /* Allow space for auto callout before every item except quantifiers. */
+size = length + sizeof(real_pcre) + cd->names_found * (cd->name_entry_size + 3);
+re = (real_pcre *)(pcre_malloc)(size);
 
-  if ((options & PCRE_AUTO_CALLOUT) != 0 &&
-       c != '*' && c != '+' && c != '?' &&
-       (c != '{' || !is_counted_repeat(ptr + 1)))
-    length += 2 + 2*LINK_SIZE;
+if (re == NULL)
+  {
+  errorcode = ERR21;
+  goto PCRE_EARLY_ERROR_RETURN;
+  }
 
-  switch(c)
-    {
-    /* A backslashed item may be an escaped data character or it may be a
-    character type. */
+/* Put in the magic number, and save the sizes, initial options, and character
+table pointer. NULL is used for the default character tables. The nullpad field
+is at the end; it's there to help in the case when a regex compiled on a system
+with 4-byte pointers is run on another with 8-byte pointers. */
 
-    case '\\':
-    c = check_escape(&ptr, &errorcode, bracount, options, FALSE);
-    if (errorcode != 0) goto PCRE_ERROR_RETURN;
+re->magic_number = MAGIC_NUMBER;
+re->size = size;
+re->options = cd->external_options;
+re->dummy1 = 0;
+re->first_byte = 0;
+re->req_byte = 0;
+re->name_table_offset = sizeof(real_pcre);
+re->name_entry_size = cd->name_entry_size;
+re->name_count = cd->names_found;
+re->ref_count = 0;
+re->tables = (tables == _pcre_default_tables)? NULL : tables;
+re->nullpad = NULL;
 
-    lastitemlength = 1;     /* Default length of last item for repeats */
+/* The starting points of the name/number translation table and of the code are
+passed around in the compile data block. The start/end pattern and initial
+options are already set from the pre-compile phase, as is the name_entry_size
+field. Reset the bracket count and the names_found field. Also reset the hwm
+field; this time it's used for remembering forward references to subpatterns.
+*/
 
-    if (c >= 0)             /* Data character */
-      {
-      length += 2;          /* For a one-byte character */
+cd->bracount = 0;
+cd->names_found = 0;
+cd->name_table = (uschar *)re + re->name_table_offset;
+codestart = cd->name_table + re->name_entry_size * re->name_count;
+cd->start_code = codestart;
+cd->hwm = cworkspace;
+cd->req_varyopt = 0;
+cd->nopartial = FALSE;
 
-#ifdef SUPPORT_UTF8
-      if (utf8 && c > 127)
-        {
-        int i;
-        for (i = 0; i < _pcre_utf8_table1_size; i++)
-          if (c <= _pcre_utf8_table1[i]) break;
-        length += i;
-        lastitemlength += i;
-        }
-#endif
+/* Set up a starting, non-extracting bracket, then compile the expression. On
+error, errorcode will be set non-zero, so we don't need to look at the result
+of the function here. */
 
-      continue;
-      }
+ptr = (const uschar *)pattern;
+code = (uschar *)codestart;
+*code = OP_BRA;
+(void)compile_regex(re->options, re->options & PCRE_IMS, &code, &ptr,
+  &errorcode, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, NULL);
+re->top_bracket = cd->bracount;
+re->top_backref = cd->top_backref;
 
-    /* If \Q, enter "literal" mode */
+if (cd->nopartial) re->options |= PCRE_NOPARTIAL;
 
-    if (-c == ESC_Q)
-      {
-      inescq = TRUE;
-      continue;
-      }
+/* If not reached end of pattern on success, there's an excess bracket. */
 
-    /* \X is supported only if Unicode property support is compiled */
+if (errorcode == 0 && *ptr != 0) errorcode = ERR22;
 
-#ifndef SUPPORT_UCP
-    if (-c == ESC_X)
-      {
-      errorcode = ERR45;
-      goto PCRE_ERROR_RETURN;
-      }
-#endif
+/* Fill in the terminating state and check for disastrous overflow, but
+if debugging, leave the test till after things are printed out. */
 
-    /* \P and \p are for Unicode properties, but only when the support has
-    been compiled. Each item needs 3 bytes. */
+*code++ = OP_END;
 
-    else if (-c == ESC_P || -c == ESC_p)
-      {
-#ifdef SUPPORT_UCP
-      BOOL negated;
-      BOOL pdata;
-      length += 3;
-      lastitemlength = 3;
-      if (get_ucp(&ptr, &negated, &pdata, &errorcode) < 0)
-        goto PCRE_ERROR_RETURN;
-      continue;
-#else
-      errorcode = ERR45;
-      goto PCRE_ERROR_RETURN;
-#endif
-      }
-
-    /* Other escapes need one byte */
-
-    length++;
-
-    /* A back reference needs an additional 2 bytes, plus either one or 5
-    bytes for a repeat. We also need to keep the value of the highest
-    back reference. */
-
-    if (c <= -ESC_REF)
-      {
-      int refnum = -c - ESC_REF;
-      cd->backref_map |= (refnum < 32)? (1 << refnum) : 1;
-      if (refnum > cd->top_backref)
-        cd->top_backref = refnum;
-      length += 2;   /* For single back reference */
-      if (ptr[1] == '{' && is_counted_repeat(ptr+2))
-        {
-        ptr = read_repeat_counts(ptr+2, &min, &max, &errorcode);
-        if (errorcode != 0) goto PCRE_ERROR_RETURN;
-        if ((min == 0 && (max == 1 || max == -1)) ||
-          (min == 1 && max == -1))
-            length++;
-        else length += 5;
-        if (ptr[1] == '?') ptr++;
-        }
-      }
-    continue;
-
-    case '^':     /* Single-byte metacharacters */
-    case '.':
-    case '$':
-    length++;
-    lastitemlength = 1;
-    continue;
-
-    case '*':            /* These repeats won't be after brackets; */
-    case '+':            /* those are handled separately */
-    case '?':
-    length++;
-    goto POSESSIVE;      /* A few lines below */
-
-    /* This covers the cases of braced repeats after a single char, metachar,
-    class, or back reference. */
-
-    case '{':
-    if (!is_counted_repeat(ptr+1)) goto NORMAL_CHAR;
-    ptr = read_repeat_counts(ptr+1, &min, &max, &errorcode);
-    if (errorcode != 0) goto PCRE_ERROR_RETURN;
-
-    /* These special cases just insert one extra opcode */
-
-    if ((min == 0 && (max == 1 || max == -1)) ||
-      (min == 1 && max == -1))
-        length++;
-
-    /* These cases might insert additional copies of a preceding character. */
-
-    else
-      {
-      if (min != 1)
-        {
-        length -= lastitemlength;   /* Uncount the original char or metachar */
-        if (min > 0) length += 3 + lastitemlength;
-        }
-      length += lastitemlength + ((max > 0)? 3 : 1);
-      }
-
-    if (ptr[1] == '?') ptr++;      /* Needs no extra length */
-
-    POSESSIVE:                     /* Test for possessive quantifier */
-    if (ptr[1] == '+')
-      {
-      ptr++;
-      length += 2 + 2*LINK_SIZE;   /* Allow for atomic brackets */
-      }
-    continue;
-
-    /* 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 += 1 + LINK_SIZE + branch_extra;
-    continue;
-
-    /* A character class uses 33 characters provided that all the character
-    values are less than 256. Otherwise, it uses a bit map for low valued
-    characters, and individual items for others. Don't worry about character
-    types that aren't allowed in classes - they'll get picked up during the
-    compile. A character class that contains only one single-byte character
-    uses 2 or 3 bytes, depending on whether it is negated or not. Notice this
-    where we can. (In UTF-8 mode we can do this only for chars < 128.) */
-
-    case '[':
-    if (*(++ptr) == '^')
-      {
-      class_optcount = 10;  /* Greater than one */
-      ptr++;
-      }
-    else class_optcount = 0;
-
-#ifdef SUPPORT_UTF8
-    class_utf8 = FALSE;
-#endif
-
-    /* Written as a "do" so that an initial ']' is taken as data */
-
-    if (*ptr != 0) do
-      {
-      /* Inside \Q...\E everything is literal except \E */
-
-      if (inescq)
-        {
-        if (*ptr != '\\' || ptr[1] != 'E') goto GET_ONE_CHARACTER;
-        inescq = FALSE;
-        ptr += 1;
-        continue;
-        }
-
-      /* Outside \Q...\E, check for escapes */
-
-      if (*ptr == '\\')
-        {
-        c = check_escape(&ptr, &errorcode, bracount, options, TRUE);
-        if (errorcode != 0) goto PCRE_ERROR_RETURN;
-
-        /* \b is backspace inside a class; \X is literal */
-
-        if (-c == ESC_b) c = '\b';
-        else if (-c == ESC_X) c = 'X';
-
-        /* \Q enters quoting mode */
-
-        else if (-c == ESC_Q)
-          {
-          inescq = TRUE;
-          continue;
-          }
-
-        /* Handle escapes that turn into characters */
-
-        if (c >= 0) goto NON_SPECIAL_CHARACTER;
-
-        /* Escapes that are meta-things. The normal ones just affect the
-        bit map, but Unicode properties require an XCLASS extended item. */
-
-        else
-          {
-          class_optcount = 10;         /* \d, \s etc; make sure > 1 */
-#ifdef SUPPORT_UTF8
-          if (-c == ESC_p || -c == ESC_P)
-            {
-            if (!class_utf8)
-              {
-              class_utf8 = TRUE;
-              length += LINK_SIZE + 2;
-              }
-            length += 3;
-            }
-#endif
-          }
-        }
-
-      /* Check the syntax for POSIX stuff. The bits we actually handle are
-      checked during the real compile phase. */
-
-      else if (*ptr == '[' &&
-                (ptr[1] == ':' || ptr[1] == '.' || ptr[1] == '=') &&
-                check_posix_syntax(ptr, &ptr, cd))
-        {
-        ptr++;
-        class_optcount = 10;    /* Make sure > 1 */
-        }
-
-      /* Anything else increments the possible optimization count. We have to
-      detect ranges here so that we can compute the number of extra ranges for
-      caseless wide characters when UCP support is available. If there are wide
-      characters, we are going to have to use an XCLASS, even for single
-      characters. */
-
-      else
-        {
-        int d;
-
-        GET_ONE_CHARACTER:
-
-#ifdef SUPPORT_UTF8
-        if (utf8)
-          {
-          int extra = 0;
-          GETCHARLEN(c, ptr, extra);
-          ptr += extra;
-          }
-        else c = *ptr;
-#else
-        c = *ptr;
-#endif
-
-        /* Come here from handling \ above when it escapes to a char value */
-
-        NON_SPECIAL_CHARACTER:
-        class_optcount++;
-
-        d = -1;
-        if (ptr[1] == '-')
-          {
-          uschar const *hyptr = ptr++;
-          if (ptr[1] == '\\')
-            {
-            ptr++;
-            d = check_escape(&ptr, &errorcode, bracount, options, TRUE);
-            if (errorcode != 0) goto PCRE_ERROR_RETURN;
-            if (-d == ESC_b) d = '\b';        /* backspace */
-            else if (-d == ESC_X) d = 'X';    /* literal X in a class */
-            }
-          else if (ptr[1] != 0 && ptr[1] != ']')
-            {
-            ptr++;
-#ifdef SUPPORT_UTF8
-            if (utf8)
-              {
-              int extra = 0;
-              GETCHARLEN(d, ptr, extra);
-              ptr += extra;
-              }
-            else
-#endif
-            d = *ptr;
-            }
-          if (d < 0) ptr = hyptr;      /* go back to hyphen as data */
-          }
-
-        /* If d >= 0 we have a range. In UTF-8 mode, if the end is > 255, or >
-        127 for caseless matching, we will need to use an XCLASS. */
-
-        if (d >= 0)
-          {
-          class_optcount = 10;     /* Ensure > 1 */
-          if (d < c)
-            {
-            errorcode = ERR8;
-            goto PCRE_ERROR_RETURN;
-            }
-
-#ifdef SUPPORT_UTF8
-          if (utf8 && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))
-            {
-            uschar buffer[6];
-            if (!class_utf8)         /* Allow for XCLASS overhead */
-              {
-              class_utf8 = TRUE;
-              length += LINK_SIZE + 2;
-              }
-
-#ifdef SUPPORT_UCP
-            /* If we have UCP support, find out how many extra ranges are
-            needed to map the other case of characters within this range. We
-            have to mimic the range optimization here, because extending the
-            range upwards might push d over a boundary that makes is use
-            another byte in the UTF-8 representation. */
-
-            if ((options & PCRE_CASELESS) != 0)
-              {
-              int occ, ocd;
-              int cc = c;
-              int origd = d;
-              while (get_othercase_range(&cc, origd, &occ, &ocd))
-                {
-                if (occ >= c && ocd <= d) continue;   /* Skip embedded */
-
-                if (occ < c  && ocd >= c - 1)  /* Extend the basic range */
-                  {                            /* if there is overlap,   */
-                  c = occ;                     /* noting that if occ < c */
-                  continue;                    /* we can't have ocd > d  */
-                  }                            /* because a subrange is  */
-                if (ocd > d && occ <= d + 1)   /* always shorter than    */
-                  {                            /* the basic range.       */
-                  d = ocd;
-                  continue;
-                  }
-
-                /* An extra item is needed */
-
-                length += 1 + _pcre_ord2utf8(occ, buffer) +
-                  ((occ == ocd)? 0 : _pcre_ord2utf8(ocd, buffer));
-                }
-              }
-#endif  /* SUPPORT_UCP */
-
-            /* The length of the (possibly extended) range */
-
-            length += 1 + _pcre_ord2utf8(c, buffer) + _pcre_ord2utf8(d, buffer);
-            }
-#endif  /* SUPPORT_UTF8 */
-
-          }
-
-        /* We have a single character. There is nothing to be done unless we
-        are in UTF-8 mode. If the char is > 255, or 127 when caseless, we must
-        allow for an XCL_SINGLE item, doubled for caselessness if there is UCP
-        support. */
-
-        else
-          {
-#ifdef SUPPORT_UTF8
-          if (utf8 && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))
-            {
-            uschar buffer[6];
-            class_optcount = 10;     /* Ensure > 1 */
-            if (!class_utf8)         /* Allow for XCLASS overhead */
-              {
-              class_utf8 = TRUE;
-              length += LINK_SIZE + 2;
-              }
-#ifdef SUPPORT_UCP
-            length += (((options & PCRE_CASELESS) != 0)? 2 : 1) *
-              (1 + _pcre_ord2utf8(c, buffer));
-#else   /* SUPPORT_UCP */
-            length += 1 + _pcre_ord2utf8(c, buffer);
-#endif  /* SUPPORT_UCP */
-            }
-#endif  /* SUPPORT_UTF8 */
-          }
-        }
-      }
-    while (*(++ptr) != 0 && (inescq || *ptr != ']')); /* Concludes "do" above */
-
-    if (*ptr == 0)                          /* Missing terminating ']' */
-      {
-      errorcode = ERR6;
-      goto PCRE_ERROR_RETURN;
-      }
-
-    /* We can optimize when there was only one optimizable character. Repeats
-    for positive and negated single one-byte chars are handled by the general
-    code. Here, we handle repeats for the class opcodes. */
-
-    if (class_optcount == 1) length += 3; else
-      {
-      length += 33;
-
-      /* A repeat needs either 1 or 5 bytes. If it is a possessive quantifier,
-      we also need extra for wrapping the whole thing in a sub-pattern. */
-
-      if (*ptr != 0 && ptr[1] == '{' && is_counted_repeat(ptr+2))
-        {
-        ptr = read_repeat_counts(ptr+2, &min, &max, &errorcode);
-        if (errorcode != 0) goto PCRE_ERROR_RETURN;
-        if ((min == 0 && (max == 1 || max == -1)) ||
-          (min == 1 && max == -1))
-            length++;
-        else length += 5;
-        if (ptr[1] == '+')
-          {
-          ptr++;
-          length += 2 + 2*LINK_SIZE;
-          }
-        else if (ptr[1] == '?') ptr++;
-        }
-      }
-    continue;
-
-    /* Brackets may be genuine groups or special things */
-
-    case '(':
-    branch_newextra = 0;
-    bracket_length = 1 + LINK_SIZE;
-    capturing = FALSE;
-
-    /* Handle special forms of bracket, which all start (? */
-
-    if (ptr[1] == '?')
-      {
-      int set, unset;
-      int *optset;
-
-      switch (c = ptr[2])
-        {
-        /* Skip over comments entirely */
-        case '#':
-        ptr += 3;
-        while (*ptr != 0 && *ptr != ')') ptr++;
-        if (*ptr == 0)
-          {
-          errorcode = ERR18;
-          goto PCRE_ERROR_RETURN;
-          }
-        continue;
-
-        /* 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 ':':
-        case '=':
-        case '!':
-        case '>':
-        ptr += 2;
-        break;
-
-        /* Named subpatterns are an extension copied from Python */
-
-        case 'P':
-        ptr += 3;
-
-        /* Handle the definition of a named subpattern */
-
-        if (*ptr == '<')
-          {
-          const uschar *p;    /* Don't amalgamate; some compilers */
-          p = ++ptr;          /* grumble at autoincrement in declaration */
-          while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++;
-          if (*ptr != '>')
-            {
-            errorcode = ERR42;
-            goto PCRE_ERROR_RETURN;
-            }
-          name_count++;
-          if (name_count > MAX_NAME_COUNT)
-            {
-            errorcode = ERR49;
-            goto PCRE_ERROR_RETURN;
-            }
-          if (ptr - p > max_name_size)
-            {
-            max_name_size = (ptr - p);
-            if (max_name_size > MAX_NAME_SIZE)
-              {
-              errorcode = ERR48;
-              goto PCRE_ERROR_RETURN;
-              }
-            }
-          capturing = TRUE;   /* Named parentheses are always capturing */
-          break;              /* Go handle capturing parentheses */
-          }
-
-        /* Handle back references and recursive calls to named subpatterns */
-
-        if (*ptr == '=' || *ptr == '>')
-          {
-          length += 3 + 3*LINK_SIZE;  /* Allow for the automatic "once" */
-          while ((cd->ctypes[*(++ptr)] & ctype_word) != 0);
-          if (*ptr != ')')
-            {
-            errorcode = ERR42;
-            goto PCRE_ERROR_RETURN;
-            }
-          goto RECURSE_CHECK_QUANTIFIED;
-          }
-
-        /* Unknown character after (?P */
-
-        errorcode = ERR41;
-        goto PCRE_ERROR_RETURN;
-
-        /* (?R) specifies a recursive call to the regex, which is an extension
-        to provide the facility which can be obtained by (?p{perl-code}) in
-        Perl 5.6. In Perl 5.8 this has become (??{perl-code}).
-
-        From PCRE 4.00, items such as (?3) specify subroutine-like "calls" to
-        the appropriate numbered brackets. This includes both recursive and
-        non-recursive calls. (?R) is now synonymous with (?0). */
-
-        case 'R':
-        ptr++;
-
-        case '0': case '1': case '2': case '3': case '4':
-        case '5': case '6': case '7': case '8': case '9':
-        ptr += 2;
-        if (c != 'R')
-          while ((digitab[*(++ptr)] & ctype_digit) != 0);
-        if (*ptr != ')')
-          {
-          errorcode = ERR29;
-          goto PCRE_ERROR_RETURN;
-          }
-        length += 3 + 3*LINK_SIZE;  /* Allows for the automatic "once" */
-
-        /* If this item is quantified, it will get wrapped inside brackets so
-        as to use the code for quantified brackets. We jump down and use the
-        code that handles this for real brackets. Come here from code for
-        named recursions/subroutines. */
-
-        RECURSE_CHECK_QUANTIFIED:
-        if (ptr[1] == '+' || ptr[1] == '*' || ptr[1] == '?' || ptr[1] == '{')
-          {
-          length += 2 + 2 * LINK_SIZE;       /* to make bracketed */
-          duplength = 5 + 3 * LINK_SIZE;
-          goto HANDLE_QUANTIFIED_BRACKETS;
-          }
-        continue;
-
-        /* (?C) is an extension which provides "callout" - to provide a bit of
-        the functionality of the Perl (?{...}) feature. An optional number may
-        follow (default is zero). */
-
-        case 'C':
-        ptr += 2;
-        while ((digitab[*(++ptr)] & ctype_digit) != 0);
-        if (*ptr != ')')
-          {
-          errorcode = ERR39;
-          goto PCRE_ERROR_RETURN;
-          }
-        length += 2 + 2*LINK_SIZE;
-        continue;
-
-        /* Lookbehinds are in Perl from version 5.005 */
-
-        case '<':
-        ptr += 3;
-        if (*ptr == '=' || *ptr == '!')
-          {
-          branch_newextra = 1 + LINK_SIZE;
-          length += 1 + LINK_SIZE;         /* For the first branch */
-          break;
-          }
-        errorcode = 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. PCRE extends this by allowing a name to reference a named group;
-        unfortunately, previously 'R' was implemented for a recursion test.
-        When this is compiled, we look for the named group 'R' first. At this
-        point we just do a basic syntax check. */
-
-        case '(':
-        if ((cd->ctypes[ptr[3]] & ctype_word) != 0)
-          {
-          ptr += 4;
-          length += 3;
-          while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++;
-          if (*ptr != ')')
-            {
-            errorcode = ERR26;
-            goto PCRE_ERROR_RETURN;
-            }
-          }
-        else   /* An assertion must follow */
-          {
-          ptr++;   /* Can treat like ':' as far as spacing is concerned */
-          if (ptr[2] != '?' ||
-             (ptr[3] != '=' && ptr[3] != '!' && ptr[3] != '<') )
-            {
-            ptr += 2;    /* To get right offset in message */
-            errorcode = ERR28;
-            goto PCRE_ERROR_RETURN;
-            }
-          }
-        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++)
-          {
-          c = *ptr;
-          switch (c)
-            {
-            case 'i':
-            *optset |= PCRE_CASELESS;
-            continue;
-
-            case 'J':
-            *optset |= PCRE_DUPNAMES;
-            options |= PCRE_JCHANGED;   /* Record that it changed */
-            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; if
-            this is at the very start of the pattern (indicated by item_count
-            being zero), we use it to set the global options. This is helpful
-            when analyzing the pattern for first characters, etc. Otherwise
-            nothing is done here and it is handled during the compiling
-            process.
-
-            We allow for more than one options setting at the start. If such
-            settings do not change the existing options, nothing is compiled.
-            However, we must leave space just in case something is compiled.
-            This can happen for pathological sequences such as (?i)(?-i)
-            because the global options will end up with -i set. The space is
-            small and not significant. (Before I did this there was a reported
-            bug with (?i)(?-i) in a machine-generated pattern.)
-
-            [Historical note: Up to Perl 5.8, options settings at top level
-            were always global settings, wherever they appeared in the pattern.
-            That is, they were equivalent to an external setting. From 5.8
-            onwards, they apply only to what follows (which is what you might
-            expect).] */
-
-            case ')':
-            if (item_count == 0)
-              {
-              options = (options | set) & (~unset);
-              set = unset = 0;     /* To save length */
-              item_count--;        /* To allow for several */
-              length += 2;
-              }
-
-            /* 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:
-            errorcode = ERR12;
-            goto PCRE_ERROR_RETURN;
-            }
-          }
-
-        /* 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 == ')')
-          {
-          if (branch_newextra == 2 &&
-              (branch_extra == 0 || branch_extra == 1+LINK_SIZE))
-            branch_extra += branch_newextra;
-          continue;
-          }
-
-        /* If options were terminated by ':' control comes here. This is a
-        non-capturing group with an options change. There is nothing more that
-        needs to be done because "capturing" is already set FALSE by default;
-        we can just fall through. */
-
-        }
-      }
-
-    /* Ordinary parentheses, not followed by '?', are capturing unless
-    PCRE_NO_AUTO_CAPTURE is set. */
-
-    else capturing = (options & PCRE_NO_AUTO_CAPTURE) == 0;
-
-    /* Capturing brackets must be counted so we can process escapes in a
-    Perlish way. If the number exceeds EXTRACT_BASIC_MAX we are going to need
-    an additional 3 bytes of memory per capturing bracket. */
-
-    if (capturing)
-      {
-      bracount++;
-      if (bracount > EXTRACT_BASIC_MAX) bracket_length += 3;
-      }
-
-    /* Save length for computing whole length 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))
-      {
-      errorcode = ERR19;
-      goto PCRE_ERROR_RETURN;
-      }
-
-    bralenstack[brastackptr] = branch_extra;
-    branch_extra = branch_newextra;
-
-    brastack[brastackptr++] = length;
-    length += bracket_length;
-    continue;
-
-    /* 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] when computing the length and restoring
-    the branch_extra value. */
-
-    case ')':
-    length += 1 + LINK_SIZE;
-    if (brastackptr > 0)
-      {
-      duplength = length - brastack[--brastackptr];
-      branch_extra = bralenstack[brastackptr];
-      /* This is a paranoid check to stop integer overflow later on */
-      if (duplength > MAX_DUPLENGTH)
-        {
-        errorcode = ERR50;
-        goto PCRE_ERROR_RETURN;
-        }
-      }
-    else duplength = 0;
-
-    /* The following code is also used when a recursion such as (?3) is
-    followed by a quantifier, because in that case, it has to be wrapped inside
-    brackets so that the quantifier works. The value of duplength must be
-    set before arrival. */
-
-    HANDLE_QUANTIFIED_BRACKETS:
-
-    /* Leave ptr at the final char; for read_repeat_counts this happens
-    automatically; for the others we need an increment. */
-
-    if ((c = ptr[1]) == '{' && is_counted_repeat(ptr+2))
-      {
-      ptr = read_repeat_counts(ptr+2, &min, &max, &errorcode);
-      if (errorcode != 0) goto PCRE_ERROR_RETURN;
-      }
-    else if (c == '*') { min = 0; max = -1; ptr++; }
-    else if (c == '+') { min = 1; max = -1; ptr++; }
-    else if (c == '?') { min = 0; max = 1;  ptr++; }
-    else { min = 1; max = 1; }
-
-    /* If the minimum is zero, we have to allow for an OP_BRAZERO before the
-    group, and if the maximum is greater than zero, we have to replicate
-    maxval-1 times; each replication acquires an OP_BRAZERO plus a nesting
-    bracket set. */
-
-    if (min == 0)
-      {
-      length++;
-      if (max > 0) length += (max - 1) * (duplength + 3 + 2*LINK_SIZE);
-      }
-
-    /* When the minimum is greater than zero, we have to replicate up to
-    minval-1 times, with no additions required in the copies. Then, if there
-    is a limited maximum we have to replicate up to maxval-1 times allowing
-    for a BRAZERO item before each optional copy and nesting brackets for all
-    but one of the optional copies. */
-
-    else
-      {
-      length += (min - 1) * duplength;
-      if (max > min)   /* Need this test as max=-1 means no limit */
-        length += (max - min) * (duplength + 3 + 2*LINK_SIZE)
-          - (2 + 2*LINK_SIZE);
-      }
-
-    /* Allow space for once brackets for "possessive quantifier" */
-
-    if (ptr[1] == '+')
-      {
-      ptr++;
-      length += 2 + 2*LINK_SIZE;
-      }
-    continue;
-
-    /* Non-special character. It won't be space or # in extended mode, so it is
-    always a genuine character. If we are in a \Q...\E sequence, check for the
-    end; if not, we have a literal. */
-
-    default:
-    NORMAL_CHAR:
-
-    if (inescq && c == '\\' && ptr[1] == 'E')
-      {
-      inescq = FALSE;
-      ptr++;
-      continue;
-      }
-
-    length += 2;          /* For a one-byte character */
-    lastitemlength = 1;   /* Default length of last item for repeats */
-
-    /* In UTF-8 mode, check for additional bytes. */
-
-#ifdef SUPPORT_UTF8
-    if (utf8 && (c & 0xc0) == 0xc0)
-      {
-      while ((ptr[1] & 0xc0) == 0x80)         /* Can't flow over the end */
-        {                                     /* because the end is marked */
-        lastitemlength++;                     /* by a zero byte. */
-        length++;
-        ptr++;
-        }
-      }
+#ifndef DEBUG
+if (code - codestart > length) errorcode = ERR23;
 #endif
 
-    continue;
-    }
-  }
-
-length += 2 + LINK_SIZE;    /* For final KET and END */
-
-if ((options & PCRE_AUTO_CALLOUT) != 0)
-  length += 2 + 2*LINK_SIZE;  /* For final callout */
+/* Fill in any forward references that are required. */
 
-if (length > MAX_PATTERN_SIZE)
+while (errorcode == 0 && cd->hwm > cworkspace)
   {
-  errorcode = ERR20;
-  goto PCRE_EARLY_ERROR_RETURN;
+  int offset, recno;
+  const uschar *groupptr;
+  cd->hwm -= LINK_SIZE;
+  offset = GET(cd->hwm, 0);
+  recno = GET(codestart, offset);
+  groupptr = find_bracket(codestart, (re->options & PCRE_UTF8) != 0, recno);
+  if (groupptr == NULL) errorcode = ERR53;
+    else PUT(((uschar *)codestart), offset, groupptr - codestart);
   }
 
-/* Compute the size of data block needed and get it, either from malloc or
-externally provided function. Integer overflow should no longer be possible
-because nowadays we limit the maximum value of name_count and max_name size. */
-
-size = length + sizeof(real_pcre) + name_count * (max_name_size + 3);
-re = (real_pcre *)(pcre_malloc)(size);
-
-if (re == NULL)
-  {
-  errorcode = ERR21;
-  goto PCRE_EARLY_ERROR_RETURN;
-  }
-
-/* Put in the magic number, and save the sizes, options, and character table
-pointer. NULL is used for the default character tables. The nullpad field is at
-the end; it's there to help in the case when a regex compiled on a system with
-4-byte pointers is run on another with 8-byte pointers. */
-
-re->magic_number = MAGIC_NUMBER;
-re->size = size;
-re->options = options;
-re->dummy1 = 0;
-re->name_table_offset = sizeof(real_pcre);
-re->name_entry_size = max_name_size + 3;
-re->name_count = name_count;
-re->ref_count = 0;
-re->tables = (tables == _pcre_default_tables)? NULL : tables;
-re->nullpad = NULL;
-
-/* The starting points of the name/number translation table and of the code are
-passed around in the compile data block. */
-
-cd->names_found = 0;
-cd->name_entry_size = max_name_size + 3;
-cd->name_table = (uschar *)re + re->name_table_offset;
-codestart = cd->name_table + re->name_entry_size * re->name_count;
-cd->start_code = codestart;
-cd->start_pattern = (const uschar *)pattern;
-cd->req_varyopt = 0;
-cd->nopartial = FALSE;
-
-/* Set up a starting, non-extracting bracket, then compile the expression. On
-error, errorcode will be set non-zero, so we don't need to look at the result
-of the function here. */
-
-ptr = (const uschar *)pattern;
-code = (uschar *)codestart;
-*code = OP_BRA;
-bracount = 0;
-(void)compile_regex(options, options & PCRE_IMS, &bracount, &code, &ptr,
-  &errorcode, FALSE, 0, &firstbyte, &reqbyte, NULL, cd);
-re->top_bracket = bracount;
-re->top_backref = cd->top_backref;
-
-if (cd->nopartial) re->options |= PCRE_NOPARTIAL;
-
-/* If not reached end of pattern on success, there's an excess bracket. */
-
-if (errorcode == 0 && *ptr != 0) errorcode = ERR22;
-
-/* Fill in the terminating state and check for disastrous overflow, but
-if debugging, leave the test till after things are printed out. */
-
-*code++ = OP_END;
-
-#ifndef DEBUG
-if (code - codestart > length) errorcode = ERR23;
-#endif
-
 /* Give an error if there's back reference to a non-existent capturing
 subpattern. */
 
-if (re->top_backref > re->top_bracket) errorcode = ERR15;
+if (errorcode == 0 && re->top_backref > re->top_bracket) errorcode = ERR15;
 
 /* Failed to compile, or error while post-processing */
 
 if (errorcode != 0)
   {
   (pcre_free)(re);
-  PCRE_ERROR_RETURN:
-  *erroroffset = ptr - (const uschar *)pattern;
   PCRE_EARLY_ERROR_RETURN:
+  *erroroffset = ptr - (const uschar *)pattern;
+#ifdef SUPPORT_UTF8
+  PCRE_UTF8_ERROR_RETURN:
+#endif
   *errorptr = error_texts[errorcode];
   if (errorcodeptr != NULL) *errorcodeptr = errorcode;
   return NULL;
@@ -5180,15 +5333,15 @@ if (errorcode != 0)
 the pattern is anchored by virtue of ^ characters or \A or anything else (such
 as starting with .* when DOTALL is set).
 
-Otherwise, if we know what the first character has to be, save it, because that
+Otherwise, if we know what the first byte has to be, save it, because that
 speeds up unanchored matches no end. If not, see if we can set the
 PCRE_STARTLINE flag. This is helpful for multiline matches when all branches
 start with ^. and also when all branches start with .* for non-DOTALL matches.
 */
 
-if ((options & PCRE_ANCHORED) == 0)
+if ((re->options & PCRE_ANCHORED) == 0)
   {
-  int temp_options = options;
+  int temp_options = re->options;   /* May get changed during these scans */
   if (is_anchored(codestart, &temp_options, 0, cd->backref_map))
     re->options |= PCRE_ANCHORED;
   else
@@ -5273,7 +5426,7 @@ if (code - codestart > length)
   if (errorcodeptr != NULL) *errorcodeptr = ERR23;
   return NULL;
   }
-#endif
+#endif   /* DEBUG */
 
 return (pcre *)re;
 }
index bcc8a1e2901a99130cafb00b3d764d5b8f7527de..29e6c1a358d3316c82a95d79820673d1fd98e7aa 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
index a67855bfef51bdee65cf434b92411bd878b7fa1a..890e0f731a5e9781844743f3f456809e75a54b3b 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -42,25 +42,22 @@ POSSIBILITY OF SUCH DAMAGE.
 pattern matching using an NFA algorithm, trying to mimic Perl as closely as
 possible. There are also some static supporting functions. */
 
-#define NLBLOCK md           /* The block containing newline information */
-#include "pcre_internal.h"
+#define NLBLOCK md             /* Block containing newline information */
+#define PSSTART start_subject  /* Field containing processed string start */
+#define PSEND   end_subject    /* Field containing processed string end */
 
+#include "pcre_internal.h"
 
-/* Structure for building a chain of data that actually lives on the
-stack, for holding the values of the subject pointer at the start of each
-subpattern, so as to detect when an empty string has been matched by a
-subpattern - to break infinite loops. When NO_RECURSE is set, these blocks
-are on the heap, not on the stack. */
+/* The chain of eptrblocks for tail recursions uses memory in stack workspace,
+obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */
 
-typedef struct eptrblock {
-  struct eptrblock *epb_prev;
-  USPTR epb_saved_eptr;
-} eptrblock;
+#define EPTR_WORK_SIZE (1000)
 
 /* Flag bits for the match() function */
 
-#define match_condassert   0x01    /* Called to check a condition assertion */
-#define match_isgroup      0x02    /* Set if start of bracketed group */
+#define match_condassert     0x01  /* Called to check a condition assertion */
+#define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
+#define match_tail_recursed  0x04  /* Tail recursive call */
 
 /* Non-error returns from the match() function. Error returns are externally
 defined PCRE_ERROR_xxx codes, which are all negative. */
@@ -101,7 +98,7 @@ Returns:     nothing
 static void
 pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
 {
-int c;
+unsigned int c;
 if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
 while (length-- > 0)
   if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);
@@ -291,7 +288,6 @@ typedef struct heapframe {
 
   BOOL Xcur_is_word;
   BOOL Xcondition;
-  BOOL Xminimize;
   BOOL Xprev_is_word;
 
   unsigned long int Xoriginal_ims;
@@ -303,11 +299,10 @@ typedef struct heapframe {
   int Xprop_category;
   int Xprop_chartype;
   int Xprop_script;
-  int *Xprop_test_variable;
 #endif
 
   int Xctype;
-  int Xfc;
+  unsigned int Xfc;
   int Xfi;
   int Xlength;
   int Xmax;
@@ -340,10 +335,7 @@ typedef struct heapframe {
 *         Match from current position            *
 *************************************************/
 
-/* 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. This function is called recursively in many circumstances. Whenever it
+/* This function is called recursively in many circumstances. Whenever it
 returns a negative (error) response, the outer incarnation must also return the
 same response.
 
@@ -353,8 +345,8 @@ performance. Tests using gcc on a SPARC disproved this; in the first case, it
 made performance worse.
 
 Arguments:
-   eptr        pointer in subject
-   ecode       position in code
+   eptr        pointer to current character in subject
+   ecode       pointer to current position in compiled code
    offset_top  current top pointer
    md          pointer to "static" info for the match
    ims         current /i, /m, and /s options
@@ -362,7 +354,9 @@ Arguments:
                  brackets - for testing for empty matches
    flags       can contain
                  match_condassert - this is an assertion condition
-                 match_isgroup - this is the start of a bracketed group
+                 match_cbegroup - this is the start of an unlimited repeat
+                   group that can match an empty string
+                 match_tail_recursed - this is a tail_recursed group
    rdepth      the recursion depth
 
 Returns:       MATCH_MATCH if matched            )  these values are >= 0
@@ -377,14 +371,16 @@ match(REGISTER USPTR eptr, REGISTER const uschar *ecode,
   int flags, unsigned int rdepth)
 {
 /* These variables do not need to be preserved over recursion in this function,
-so they can be ordinary variables in all cases. Mark them with "register"
-because they are used a lot in loops. */
+so they can be ordinary variables in all cases. Mark some of them with
+"register" because they are used a lot in loops. */
 
 register int  rrc;         /* Returns from recursive calls */
 register int  i;           /* Used for loops not involving calls to RMATCH() */
-register unsigned int  c;  /* Character values not kept over RMATCH() calls */
+register unsigned int c;   /* Character values not kept over RMATCH() calls */
 register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
 
+BOOL minimize, possessive; /* Quantifier options */
+
 /* When recursion is not being used, all "local" variables that have to be
 preserved over calls to RMATCH() are part of a "frame" which is obtained from
 heap storage. Set up the top-level frame here; others are obtained from the
@@ -434,7 +430,6 @@ HEAP_RECURSE:
 
 #define cur_is_word        frame->Xcur_is_word
 #define condition          frame->Xcondition
-#define minimize           frame->Xminimize
 #define prev_is_word       frame->Xprev_is_word
 
 #define original_ims       frame->Xoriginal_ims
@@ -446,7 +441,6 @@ HEAP_RECURSE:
 #define prop_category      frame->Xprop_category
 #define prop_chartype      frame->Xprop_chartype
 #define prop_script        frame->Xprop_script
-#define prop_test_variable frame->Xprop_test_variable
 #endif
 
 #define ctype              frame->Xctype
@@ -470,7 +464,7 @@ HEAP_RECURSE:
 get preserved during recursion in the normal way. In this environment, fi and
 i, and fc and c, can be the same variables. */
 
-#else
+#else         /* NO_RECURSE not defined */
 #define fi i
 #define fc c
 
@@ -489,7 +483,6 @@ recursion_info new_recursive;      /* within blocks below are for variables  */
                                    /* that do not have to be preserved over  */
 BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
 BOOL condition;
-BOOL minimize;
 BOOL prev_is_word;
 
 unsigned long int original_ims;
@@ -501,7 +494,6 @@ int prop_fail_result;
 int prop_category;
 int prop_chartype;
 int prop_script;
-int *prop_test_variable;
 #endif
 
 int ctype;
@@ -516,7 +508,7 @@ int save_offset1, save_offset2, save_offset3;
 int stacksave[REC_STACK_SAVE_MAX];
 
 eptrblock newptrb;
-#endif
+#endif     /* NO_RECURSE */
 
 /* These statements are here to stop the compiler complaining about unitialized
 variables. */
@@ -524,9 +516,9 @@ variables. */
 #ifdef SUPPORT_UCP
 prop_value = 0;
 prop_fail_result = 0;
-prop_test_variable = NULL;
 #endif
 
+
 /* This label is used for tail recursion, which is used in a few cases even
 when NO_RECURSE is not defined, in order to reduce the amount of stack that is
 used. Thanks to Ian Taylor for noticing this possibility and sending the
@@ -556,24 +548,34 @@ utf8 = md->utf8;       /* Local copy of the flag */
 utf8 = FALSE;
 #endif
 
-/* At the start of a bracketed group, add the current subject pointer to the
-stack of such pointers, to be re-instated at the end of the group when we hit
-the closing ket. When match() is called in other circumstances, we don't add to
-this stack. */
+/* At the start of a group with an unlimited repeat that may match an empty
+string, the match_cbegroup flag is set. When this is the case, add the current
+subject pointer to the chain of such remembered pointers, to be checked when we
+hit the closing ket, in order to break infinite loops that match no characters.
+When match() is called in other circumstances, don't add to the chain. If this
+is a tail recursion, use a block from the workspace, as the one on the stack is
+already used. */
 
-if ((flags & match_isgroup) != 0)
+if ((flags & match_cbegroup) != 0)
   {
-  newptrb.epb_prev = eptrb;
-  newptrb.epb_saved_eptr = eptr;
-  eptrb = &newptrb;
+  eptrblock *p;
+  if ((flags & match_tail_recursed) != 0)
+    {
+    if (md->eptrn >= EPTR_WORK_SIZE) RRETURN(PCRE_ERROR_NULLWSLIMIT);
+    p = md->eptrchain + md->eptrn++;
+    }
+  else p = &newptrb;
+  p->epb_saved_eptr = eptr;
+  p->epb_prev = eptrb;
+  eptrb = p;
   }
 
-/* Now start processing the operations. */
+/* Now start processing the opcodes. */
 
 for (;;)
   {
+  minimize = possessive = FALSE;
   op = *ecode;
-  minimize = FALSE;
 
   /* For partial matching, remember if we ever hit the end of the subject after
   matching at least one subject character. */
@@ -583,33 +585,30 @@ for (;;)
       eptr > md->start_match)
     md->hitend = TRUE;
 
-  /* 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 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)
+  switch(op)
     {
-    number = op - OP_BRA;
-
-    /* For extended extraction brackets (large number), we have to fish out the
-    number from a dummy opcode at the start. */
-
-    if (number > EXTRACT_BASIC_MAX)
-      number = GET2(ecode, 2+LINK_SIZE);
+    /* Handle a 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 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. */
+
+    case OP_CBRA:
+    case OP_SCBRA:
+    number = GET2(ecode, 1+LINK_SIZE);
     offset = number << 1;
 
 #ifdef DEBUG
-    printf("start bracket %d subject=", number);
+    printf("start bracket %d\n", number);
+    printf("subject=");
     pchars(eptr, 16, TRUE, md);
     printf("\n");
 #endif
@@ -624,10 +623,11 @@ for (;;)
       DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
       md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
 
+      flags = (op == OP_SCBRA)? match_cbegroup : 0;
       do
         {
-        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,
-          match_isgroup);
+        RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
+          ims, eptrb, flags);
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);
         md->capture_last = save_capture_last;
         ecode += GET(ecode, 1);
@@ -643,39 +643,35 @@ for (;;)
       RRETURN(MATCH_NOMATCH);
       }
 
-    /* Insufficient room for saving captured contents */
+    /* Insufficient room for saving captured contents. Treat as a non-capturing
+    bracket. */
 
-    else op = OP_BRA;
-    }
+    DPRINTF(("insufficient capture room: treat as non-capturing\n"));
 
-  /* Other types of node can be handled by a switch */
-
-  switch(op)
-    {
-    case OP_BRA:     /* Non-capturing bracket: optimized */
-    DPRINTF(("start bracket 0\n"));
-
-    /* Loop for all the alternatives */
+    /* Non-capturing bracket. Loop for all the alternatives. When we get to the
+    final alternative within the brackets, we would return the result of a
+    recursive call to match() whatever happened. We can reduce stack usage by
+    turning this into a tail recursion. */
 
+    case OP_BRA:
+    case OP_SBRA:
+    DPRINTF(("start non-capturing bracket\n"));
+    flags = (op >= OP_SBRA)? match_cbegroup : 0;
     for (;;)
       {
-      /* When we get to the final alternative within the brackets, we would
-      return the result of a recursive call to match() whatever happened. We
-      can reduce stack usage by turning this into a tail recursion. */
-
       if (ecode[GET(ecode, 1)] != OP_ALT)
-       {
-       ecode += 1 + LINK_SIZE;
-       flags = match_isgroup;
-       DPRINTF(("bracket 0 tail recursion\n"));
-       goto TAIL_RECURSE;
-       }
+        {
+        ecode += _pcre_OP_lengths[*ecode];
+        flags |= match_tail_recursed;
+        DPRINTF(("bracket 0 tail recursion\n"));
+        goto TAIL_RECURSE;
+        }
 
       /* For non-final alternatives, continue the loop for a NOMATCH result;
       otherwise return. */
 
-      RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,
-        match_isgroup);
+      RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
+        eptrb, flags);
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       ecode += GET(ecode, 1);
       }
@@ -688,54 +684,72 @@ for (;;)
     obeyed, we can use tail recursion to avoid using another stack frame. */
 
     case OP_COND:
-    if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */
+    case OP_SCOND:
+    if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */
+      {
+      offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
+      condition = md->recursive != NULL &&
+        (offset == RREF_ANY || offset == md->recursive->group_num);
+      ecode += condition? 3 : GET(ecode, 1);
+      }
+
+    else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */
       {
       offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
-      condition = (offset == CREF_RECURSE * 2)?
-        (md->recursive != NULL) :
-        (offset < offset_top && md->offset_vector[offset] >= 0);
-      ecode += condition? (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1));
-      flags = match_isgroup;
-      goto TAIL_RECURSE;
+      condition = offset < offset_top && md->offset_vector[offset] >= 0;
+      ecode += condition? 3 : GET(ecode, 1);
+      }
+
+    else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */
+      {
+      condition = FALSE;
+      ecode += GET(ecode, 1);
       }
 
     /* 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. */
+    the final argument match_condassert causes it to stop at the end of an
+    assertion. */
 
     else
       {
       RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
-          match_condassert | match_isgroup);
+          match_condassert);
       if (rrc == MATCH_MATCH)
         {
-        ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2);
+        condition = TRUE;
+        ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
         while (*ecode == OP_ALT) ecode += GET(ecode, 1);
         }
       else if (rrc != MATCH_NOMATCH)
         {
         RRETURN(rrc);         /* Need braces because of following else */
         }
-      else ecode += GET(ecode, 1);
+      else
+        {
+        condition = FALSE;
+        ecode += GET(ecode, 1);
+        }
+      }
 
-      /* We are now at the branch that is to be obeyed. As there is only one,
-      we can use tail recursion to avoid using another stack frame. */
+    /* We are now at the branch that is to be obeyed. As there is only one,
+    we can use tail recursion to avoid using another stack frame. If the second
+    alternative doesn't exist, we can just plough on. */
 
+    if (condition || *ecode == OP_ALT)
+      {
       ecode += 1 + LINK_SIZE;
-      flags = match_isgroup;
+      flags = match_tail_recursed | ((op == OP_SCOND)? match_cbegroup : 0);
       goto TAIL_RECURSE;
       }
-    /* Control never reaches here */
-
-    /* Skip over conditional reference or large extraction number data if
-    encountered. */
-
-    case OP_CREF:
-    case OP_BRANUMBER:
-    ecode += 3;
+    else
+      {
+      ecode += 1 + LINK_SIZE;
+      }
     break;
 
-    /* End of the pattern. If we are in a recursion, we should restore the
-    offsets appropriately and continue from after the call. */
+
+    /* End of the pattern. If we are in a top-level recursion, we should
+    restore the offsets appropriately and continue from after the call. */
 
     case OP_END:
     if (md->recursive != NULL && md->recursive->group_num == 0)
@@ -777,8 +791,7 @@ for (;;)
     case OP_ASSERTBACK:
     do
       {
-      RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
-        match_isgroup);
+      RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0);
       if (rrc == MATCH_MATCH) break;
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       ecode += GET(ecode, 1);
@@ -804,8 +817,7 @@ for (;;)
     case OP_ASSERTBACK_NOT:
     do
       {
-      RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
-        match_isgroup);
+      RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0);
       if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       ecode += GET(ecode,1);
@@ -826,8 +838,8 @@ for (;;)
 #ifdef SUPPORT_UTF8
     if (utf8)
       {
-      c = GET(ecode,1);
-      for (i = 0; i < c; i++)
+      i = GET(ecode, 1);
+      while (i-- > 0)
         {
         eptr--;
         if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
@@ -840,7 +852,7 @@ for (;;)
     /* No UTF-8 support, or not in UTF-8 mode: count is byte count */
 
       {
-      eptr -= GET(ecode,1);
+      eptr -= GET(ecode, 1);
       if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
       }
 
@@ -897,13 +909,8 @@ for (;;)
     case OP_RECURSE:
       {
       callpat = md->start_code + GET(ecode, 1);
-      new_recursive.group_num = *callpat - OP_BRA;
-
-      /* For extended extraction brackets (large number), we have to fish out
-      the number from a dummy opcode at the start. */
-
-      if (new_recursive.group_num > EXTRACT_BASIC_MAX)
-        new_recursive.group_num = GET2(callpat, 2+LINK_SIZE);
+      new_recursive.group_num = (callpat == md->start_code)? 0 :
+        GET2(callpat, 1 + LINK_SIZE);
 
       /* Add to "recursing stack" */
 
@@ -936,10 +943,11 @@ for (;;)
       restore the offset and recursion data. */
 
       DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
+      flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
       do
         {
-        RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,
-            eptrb, match_isgroup);
+        RMATCH(rrc, eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
+          md, ims, eptrb, flags);
         if (rrc == MATCH_MATCH)
           {
           DPRINTF(("Recursion matched\n"));
@@ -983,7 +991,7 @@ for (;;)
     do
       {
       RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,
-        eptrb, match_isgroup);
+        eptrb, 0);
       if (rrc == MATCH_MATCH) break;
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       ecode += GET(ecode,1);
@@ -997,7 +1005,7 @@ for (;;)
     /* Continue as from after the assertion, updating the offsets high water
     mark, since extracts may have been taken. */
 
-    do ecode += GET(ecode,1); while (*ecode == OP_ALT);
+    do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
 
     offset_top = md->end_offset_top;
     eptr = md->end_match_ptr;
@@ -1031,15 +1039,15 @@ for (;;)
       RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0);
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       ecode = prev;
-      flags = match_isgroup;
+      flags = match_tail_recursed;
       goto TAIL_RECURSE;
       }
     else  /* OP_KETRMAX */
       {
-      RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);
+      RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_cbegroup);
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       ecode += 1 + LINK_SIZE;
-      flags = 0;
+      flags = match_tail_recursed;
       goto TAIL_RECURSE;
       }
     /* Control never gets here */
@@ -1060,38 +1068,44 @@ for (;;)
     case OP_BRAZERO:
       {
       next = ecode+1;
-      RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);
+      RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, 0);
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       do next += GET(next,1); while (*next == OP_ALT);
-      ecode = next + 1+LINK_SIZE;
+      ecode = next + 1 + LINK_SIZE;
       }
     break;
 
     case OP_BRAMINZERO:
       {
       next = ecode+1;
-      do next += GET(next,1); while (*next == OP_ALT);
-      RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb,
-        match_isgroup);
+      do next += GET(next, 1); while (*next == OP_ALT);
+      RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       ecode++;
       }
     break;
 
-    /* End of a group, repeated or non-repeating. If we are at the end of
-    an assertion "group", stop matching and return MATCH_MATCH, but record the
-    current high water mark for use by positive assertions. Do this also
-    for the "once" (not-backup up) groups. */
+    /* End of a group, repeated or non-repeating. */
 
     case OP_KET:
     case OP_KETRMIN:
     case OP_KETRMAX:
     prev = ecode - GET(ecode, 1);
-    saved_eptr = eptrb->epb_saved_eptr;
 
-    /* Back up the stack of bracket start pointers. */
+    /* If this was a group that remembered the subject start, in order to break
+    infinite repeats of empty string matches, retrieve the subject start from
+    the chain. Otherwise, set it NULL. */
+
+    if (*prev >= OP_SBRA)
+      {
+      saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
+      eptrb = eptrb->epb_prev;              /* Backup to previous group */
+      }
+    else saved_eptr = NULL;
 
-    eptrb = eptrb->epb_prev;
+    /* If we are at the end of an assertion group, stop matching and return
+    MATCH_MATCH, but record the current high water mark for use by positive
+    assertions. Do this also for the "once" (atomic) groups. */
 
     if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
         *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
@@ -1102,18 +1116,15 @@ for (;;)
       RRETURN(MATCH_MATCH);
       }
 
-    /* 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. */
+    /* For capturing groups 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. Note that whole-pattern recursion is coded as
+    a recurse into group 0, so it won't be picked up here. Instead, we catch it
+    when the OP_END is reached. Other recursion is handled here. */
 
-    if (*prev != OP_COND)
+    if (*prev == OP_CBRA || *prev == OP_SCBRA)
       {
-      number = *prev - OP_BRA;
-
-      /* For extended extraction brackets (large number), we have to fish out
-      the number from a dummy opcode at the start. */
-
-      if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE);
+      number = GET2(prev, 1+LINK_SIZE);
       offset = number << 1;
 
 #ifdef DEBUG
@@ -1121,42 +1132,34 @@ for (;;)
       printf("\n");
 #endif
 
-      /* Test for a numbered group. This includes groups called as a result
-      of recursion. Note that whole-pattern recursion is coded as a recurse
-      into group 0, so it won't be picked up here. Instead, we catch it when
-      the OP_END is reached. */
-
-      if (number > 0)
+      md->capture_last = number;
+      if (offset >= md->offset_max) md->offset_overflow = TRUE; else
         {
-        md->capture_last = number;
-        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;
-          }
+        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;
+        }
 
-        /* Handle a recursively called group. Restore the offsets
-        appropriately and continue from after the call. */
+      /* Handle a recursively called group. Restore the offsets
+      appropriately and continue from after the call. */
 
-        if (md->recursive != NULL && md->recursive->group_num == number)
-          {
-          recursion_info *rec = md->recursive;
-          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
-          md->recursive = rec->prevrec;
-          md->start_match = rec->save_start;
-          memcpy(md->offset_vector, rec->offset_save,
-            rec->saved_max * sizeof(int));
-          ecode = rec->after_call;
-          ims = original_ims;
-          break;
-          }
+      if (md->recursive != NULL && md->recursive->group_num == number)
+        {
+        recursion_info *rec = md->recursive;
+        DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
+        md->recursive = rec->prevrec;
+        md->start_match = rec->save_start;
+        memcpy(md->offset_vector, rec->offset_save,
+          rec->saved_max * sizeof(int));
+        ecode = rec->after_call;
+        ims = original_ims;
+        break;
         }
       }
 
-    /* Reset the value of the ims flags, in case they got changed during
-    the group. */
+    /* For both capturing and non-capturing groups, reset the value of the ims
+    flags, in case they got changed during the group. */
 
     ims = original_ims;
     DPRINTF(("ims reset to %02lx\n", ims));
@@ -1177,20 +1180,22 @@ for (;;)
     preceding bracket, in the appropriate order. In the second case, we can use
     tail recursion to avoid using another stack frame. */
 
+    flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
+
     if (*ecode == OP_KETRMIN)
       {
       RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       ecode = prev;
-      flags = match_isgroup;
+      flags |= match_tail_recursed;
       goto TAIL_RECURSE;
       }
     else  /* OP_KETRMAX */
       {
-      RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);
+      RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, flags);
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
       ecode += 1 + LINK_SIZE;
-      flags = 0;
+      flags = match_tail_recursed;
       goto TAIL_RECURSE;
       }
     /* Control never gets here */
@@ -1202,9 +1207,7 @@ for (;;)
     if ((ims & PCRE_MULTILINE) != 0)
       {
       if (eptr != md->start_subject &&
-          (eptr == md->end_subject ||
-           eptr < md->start_subject + md->nllen ||
-           !IS_NEWLINE(eptr - md->nllen)))
+          (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
         RRETURN(MATCH_NOMATCH);
       ecode++;
       break;
@@ -1244,7 +1247,7 @@ for (;;)
       if (!md->endonly)
         {
         if (eptr != md->end_subject &&
-            (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr)))
+            (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
           RRETURN(MATCH_NOMATCH);
         ecode++;
         break;
@@ -1263,7 +1266,7 @@ for (;;)
 
     case OP_EODN:
     if (eptr != md->end_subject &&
-        (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr)))
+        (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
       RRETURN(MATCH_NOMATCH);
     ecode++;
     break;
@@ -1319,8 +1322,7 @@ for (;;)
     case OP_ANY:
     if ((ims & PCRE_DOTALL) == 0)
       {
-      if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))
-        RRETURN(MATCH_NOMATCH);
+      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
       }
     if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
     if (utf8)
@@ -1414,6 +1416,26 @@ for (;;)
     ecode++;
     break;
 
+    case OP_ANYNL:
+    if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+    GETCHARINCTEST(c, eptr);
+    switch(c)
+      {
+      default: RRETURN(MATCH_NOMATCH);
+      case 0x000d:
+      if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
+      break;
+      case 0x000a:
+      case 0x000b:
+      case 0x000c:
+      case 0x0085:
+      case 0x2028:
+      case 0x2029:
+      break;
+      }
+    ecode++;
+    break;
+
 #ifdef SUPPORT_UCP
     /* Check the next character by Unicode property. We will get here only
     if the support is in the binary; otherwise a compile-time error occurs. */
@@ -1456,7 +1478,6 @@ for (;;)
 
         default:
         RRETURN(PCRE_ERROR_INTERNAL);
-        break;
         }
 
       ecode += 3;
@@ -1926,7 +1947,7 @@ for (;;)
 
       else
         {
-        int dc;
+        unsigned int dc;
         GETCHARINC(dc, eptr);
         ecode += length;
 
@@ -1953,13 +1974,17 @@ for (;;)
       }
     break;
 
-    /* Match a single character repeatedly; different opcodes share code. */
+    /* Match a single character repeatedly. */
 
     case OP_EXACT:
     min = max = GET2(ecode, 1);
     ecode += 3;
     goto REPEATCHAR;
 
+    case OP_POSUPTO:
+    possessive = TRUE;
+    /* Fall through */
+
     case OP_UPTO:
     case OP_MINUPTO:
     min = 0;
@@ -1968,6 +1993,27 @@ for (;;)
     ecode += 3;
     goto REPEATCHAR;
 
+    case OP_POSSTAR:
+    possessive = TRUE;
+    min = 0;
+    max = INT_MAX;
+    ecode++;
+    goto REPEATCHAR;
+
+    case OP_POSPLUS:
+    possessive = TRUE;
+    min = 1;
+    max = INT_MAX;
+    ecode++;
+    goto REPEATCHAR;
+
+    case OP_POSQUERY:
+    possessive = TRUE;
+    min = 0;
+    max = 1;
+    ecode++;
+    goto REPEATCHAR;
+
     case OP_STAR:
     case OP_MINSTAR:
     case OP_PLUS:
@@ -2003,10 +2049,9 @@ for (;;)
         uschar occhars[8];
 
 #ifdef SUPPORT_UCP
-        int othercase;
+        unsigned int othercase;
         if ((ims & PCRE_CASELESS) != 0 &&
-            (othercase = _pcre_ucp_othercase(fc)) >= 0 &&
-             othercase >= 0)
+            (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)
           oclength = _pcre_ord2utf8(othercase, occhars);
 #endif  /* SUPPORT_UCP */
 
@@ -2042,7 +2087,8 @@ for (;;)
             }
           /* Control never gets here */
           }
-        else
+
+        else  /* Maximize */
           {
           pp = eptr;
           for (i = min; i < max; i++)
@@ -2056,6 +2102,8 @@ for (;;)
               eptr += oclength;
               }
             }
+
+          if (possessive) continue;
           while (eptr >= pp)
            {
            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -2110,7 +2158,7 @@ for (;;)
           }
         /* Control never gets here */
         }
-      else
+      else  /* Maximize */
         {
         pp = eptr;
         for (i = min; i < max; i++)
@@ -2118,6 +2166,7 @@ for (;;)
           if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
           eptr++;
           }
+        if (possessive) continue;
         while (eptr >= pp)
           {
           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -2146,7 +2195,7 @@ for (;;)
           }
         /* Control never gets here */
         }
-      else
+      else  /* Maximize */
         {
         pp = eptr;
         for (i = min; i < max; i++)
@@ -2154,6 +2203,7 @@ for (;;)
           if (eptr >= md->end_subject || fc != *eptr) break;
           eptr++;
           }
+        if (possessive) continue;
         while (eptr >= pp)
           {
           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -2206,6 +2256,34 @@ for (;;)
     ecode += 3;
     goto REPEATNOTCHAR;
 
+    case OP_NOTPOSSTAR:
+    possessive = TRUE;
+    min = 0;
+    max = INT_MAX;
+    ecode++;
+    goto REPEATNOTCHAR;
+
+    case OP_NOTPOSPLUS:
+    possessive = TRUE;
+    min = 1;
+    max = INT_MAX;
+    ecode++;
+    goto REPEATNOTCHAR;
+
+    case OP_NOTPOSQUERY:
+    possessive = TRUE;
+    min = 0;
+    max = 1;
+    ecode++;
+    goto REPEATNOTCHAR;
+
+    case OP_NOTPOSUPTO:
+    possessive = TRUE;
+    min = 0;
+    max = GET2(ecode, 1);
+    ecode += 3;
+    goto REPEATNOTCHAR;
+
     case OP_NOTSTAR:
     case OP_NOTMINSTAR:
     case OP_NOTPLUS:
@@ -2245,7 +2323,7 @@ for (;;)
       /* UTF-8 mode */
       if (utf8)
         {
-        register int d;
+        register unsigned int d;
         for (i = 1; i <= min; i++)
           {
           GETCHARINC(d, eptr);
@@ -2270,7 +2348,7 @@ for (;;)
         /* UTF-8 mode */
         if (utf8)
           {
-          register int d;
+          register unsigned int d;
           for (fi = min;; fi++)
             {
             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -2306,7 +2384,7 @@ for (;;)
         /* UTF-8 mode */
         if (utf8)
           {
-          register int d;
+          register unsigned int d;
           for (i = min; i < max; i++)
             {
             int len = 1;
@@ -2316,7 +2394,8 @@ for (;;)
             if (fc == d) break;
             eptr += len;
             }
-          for(;;)
+        if (possessive) continue;
+        for(;;)
             {
             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
@@ -2333,6 +2412,7 @@ for (;;)
             if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
             eptr++;
             }
+          if (possessive) continue;
           while (eptr >= pp)
             {
             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -2354,7 +2434,7 @@ for (;;)
       /* UTF-8 mode */
       if (utf8)
         {
-        register int d;
+        register unsigned int d;
         for (i = 1; i <= min; i++)
           {
           GETCHARINC(d, eptr);
@@ -2377,7 +2457,7 @@ for (;;)
         /* UTF-8 mode */
         if (utf8)
           {
-          register int d;
+          register unsigned int d;
           for (fi = min;; fi++)
             {
             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -2412,7 +2492,7 @@ for (;;)
         /* UTF-8 mode */
         if (utf8)
           {
-          register int d;
+          register unsigned int d;
           for (i = min; i < max; i++)
             {
             int len = 1;
@@ -2421,6 +2501,7 @@ for (;;)
             if (fc == d) break;
             eptr += len;
             }
+          if (possessive) continue;
           for(;;)
             {
             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -2438,6 +2519,7 @@ for (;;)
             if (eptr >= md->end_subject || fc == *eptr) break;
             eptr++;
             }
+          if (possessive) continue;
           while (eptr >= pp)
             {
             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -2469,6 +2551,34 @@ for (;;)
     ecode += 3;
     goto REPEATTYPE;
 
+    case OP_TYPEPOSSTAR:
+    possessive = TRUE;
+    min = 0;
+    max = INT_MAX;
+    ecode++;
+    goto REPEATTYPE;
+
+    case OP_TYPEPOSPLUS:
+    possessive = TRUE;
+    min = 1;
+    max = INT_MAX;
+    ecode++;
+    goto REPEATTYPE;
+
+    case OP_TYPEPOSQUERY:
+    possessive = TRUE;
+    min = 0;
+    max = 1;
+    ecode++;
+    goto REPEATTYPE;
+
+    case OP_TYPEPOSUPTO:
+    possessive = TRUE;
+    min = 0;
+    max = GET2(ecode, 1);
+    ecode += 3;
+    goto REPEATTYPE;
+
     case OP_TYPESTAR:
     case OP_TYPEMINSTAR:
     case OP_TYPEPLUS:
@@ -2571,7 +2681,6 @@ for (;;)
 
           default:
           RRETURN(PCRE_ERROR_INTERNAL);
-          break;
           }
         }
 
@@ -2611,9 +2720,7 @@ for (;;)
         for (i = 1; i <= min; i++)
           {
           if (eptr >= md->end_subject ||
-               ((ims & PCRE_DOTALL) == 0 &&
-                 eptr <= md->end_subject - md->nllen &&
-                 IS_NEWLINE(eptr)))
+               ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))
             RRETURN(MATCH_NOMATCH);
           eptr++;
           while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
@@ -2624,6 +2731,28 @@ for (;;)
         eptr += min;
         break;
 
+        case OP_ANYNL:
+        for (i = 1; i <= min; i++)
+          {
+          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+          GETCHARINC(c, eptr);
+          switch(c)
+            {
+            default: RRETURN(MATCH_NOMATCH);
+            case 0x000d:
+            if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
+            break;
+            case 0x000a:
+            case 0x000b:
+            case 0x000c:
+            case 0x0085:
+            case 0x2028:
+            case 0x2029:
+            break;
+            }
+          }
+        break;
+
         case OP_NOT_DIGIT:
         for (i = 1; i <= min; i++)
           {
@@ -2692,7 +2821,8 @@ for (;;)
 #endif     /* SUPPORT_UTF8 */
 
       /* Code for the non-UTF-8 case for minimum matching of operators other
-      than OP_PROP and OP_NOTPROP. */
+      than OP_PROP and OP_NOTPROP. We can assume that there are the minimum
+      number of bytes present, as this was tested above. */
 
       switch(ctype)
         {
@@ -2701,8 +2831,7 @@ for (;;)
           {
           for (i = 1; i <= min; i++)
             {
-            if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))
-              RRETURN(MATCH_NOMATCH);
+            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
             eptr++;
             }
           }
@@ -2713,6 +2842,28 @@ for (;;)
         eptr += min;
         break;
 
+        /* Because of the CRLF case, we can't assume the minimum number of
+        bytes are present in this case. */
+
+        case OP_ANYNL:
+        for (i = 1; i <= min; i++)
+          {
+          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
+          switch(*eptr++)
+            {
+            default: RRETURN(MATCH_NOMATCH);
+            case 0x000d:
+            if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
+            break;
+            case 0x000a:
+            case 0x000b:
+            case 0x000c:
+            case 0x0085:
+            break;
+            }
+          }
+        break;
+
         case OP_NOT_DIGIT:
         for (i = 1; i <= min; i++)
           if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
@@ -2774,7 +2925,7 @@ for (;;)
             GETCHARINC(c, eptr);
             if (prop_fail_result) RRETURN(MATCH_NOMATCH);
             }
-          break;
+          /* Control never gets here */
 
           case PT_LAMP:
           for (fi = min;; fi++)
@@ -2789,7 +2940,7 @@ for (;;)
                  prop_chartype == ucp_Lt) == prop_fail_result)
               RRETURN(MATCH_NOMATCH);
             }
-          break;
+          /* Control never gets here */
 
           case PT_GC:
           for (fi = min;; fi++)
@@ -2802,7 +2953,7 @@ for (;;)
             if ((prop_category == prop_value) == prop_fail_result)
               RRETURN(MATCH_NOMATCH);
             }
-          break;
+          /* Control never gets here */
 
           case PT_PC:
           for (fi = min;; fi++)
@@ -2815,7 +2966,7 @@ for (;;)
             if ((prop_chartype == prop_value) == prop_fail_result)
               RRETURN(MATCH_NOMATCH);
             }
-          break;
+          /* Control never gets here */
 
           case PT_SC:
           for (fi = min;; fi++)
@@ -2828,11 +2979,10 @@ for (;;)
             if ((prop_script == prop_value) == prop_fail_result)
               RRETURN(MATCH_NOMATCH);
             }
-          break;
+          /* Control never gets here */
 
           default:
           RRETURN(PCRE_ERROR_INTERNAL);
-          break;
           }
         }
 
@@ -2876,7 +3026,7 @@ for (;;)
           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
           if (fi >= max || eptr >= md->end_subject ||
                (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&
-                eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)))
+                IS_NEWLINE(eptr)))
             RRETURN(MATCH_NOMATCH);
 
           GETCHARINC(c, eptr);
@@ -2888,6 +3038,23 @@ for (;;)
             case OP_ANYBYTE:
             break;
 
+            case OP_ANYNL:
+            switch(c)
+              {
+              default: RRETURN(MATCH_NOMATCH);
+              case 0x000d:
+              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
+              break;
+              case 0x000a:
+              case 0x000b:
+              case 0x000c:
+              case 0x0085:
+              case 0x2028:
+              case 0x2029:
+              break;
+              }
+            break;
+
             case OP_NOT_DIGIT:
             if (c < 256 && (md->ctypes[c] & ctype_digit) != 0)
               RRETURN(MATCH_NOMATCH);
@@ -2932,8 +3099,7 @@ for (;;)
           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
           if (fi >= max || eptr >= md->end_subject ||
-               ((ims & PCRE_DOTALL) == 0 &&
-                 eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)))
+               ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))
             RRETURN(MATCH_NOMATCH);
 
           c = *eptr++;
@@ -2945,6 +3111,21 @@ for (;;)
             case OP_ANYBYTE:
             break;
 
+            case OP_ANYNL:
+            switch(c)
+              {
+              default: RRETURN(MATCH_NOMATCH);
+              case 0x000d:
+              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
+              break;
+              case 0x000a:
+              case 0x000b:
+              case 0x000c:
+              case 0x0085:
+              break;
+              }
+            break;
+
             case OP_NOT_DIGIT:
             if ((md->ctypes[c] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
             break;
@@ -2977,7 +3158,7 @@ for (;;)
       /* Control never gets here */
       }
 
-    /* If maximizing it is worth using inline code for speed, doing the type
+    /* If maximizing, it is worth using inline code for speed, doing the type
     test once at the start (i.e. keep it out of the loop). Again, keep the
     UTF-8 and UCP stuff separate. */
 
@@ -3058,6 +3239,7 @@ for (;;)
 
         /* eptr is now past the end of the maximum run */
 
+        if (possessive) continue;
         for(;;)
           {
           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -3093,6 +3275,7 @@ for (;;)
 
         /* eptr is now past the end of the maximum run */
 
+        if (possessive) continue;
         for(;;)
           {
           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -3135,9 +3318,7 @@ for (;;)
               {
               for (i = min; i < max; i++)
                 {
-                if (eptr >= md->end_subject ||
-                    (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)))
-                  break;
+                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
                 eptr++;
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 }
@@ -3161,9 +3342,7 @@ for (;;)
               {
               for (i = min; i < max; i++)
                 {
-                if (eptr >= md->end_subject ||
-                    (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)))
-                  break;
+                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
                 eptr++;
                 }
               break;
@@ -3171,7 +3350,8 @@ for (;;)
             else
               {
               c = max - min;
-              if (c > md->end_subject - eptr) c = md->end_subject - eptr;
+              if (c > (unsigned int)(md->end_subject - eptr))
+                c = md->end_subject - eptr;
               eptr += c;
               }
             }
@@ -3181,10 +3361,32 @@ for (;;)
 
           case OP_ANYBYTE:
           c = max - min;
-          if (c > md->end_subject - eptr) c = md->end_subject - eptr;
+          if (c > (unsigned int)(md->end_subject - eptr))
+            c = md->end_subject - eptr;
           eptr += c;
           break;
 
+          case OP_ANYNL:
+          for (i = min; i < max; i++)
+            {
+            int len = 1;
+            if (eptr >= md->end_subject) break;
+            GETCHARLEN(c, eptr, len);
+            if (c == 0x000d)
+              {
+              if (++eptr >= md->end_subject) break;
+              if (*eptr == 0x000a) eptr++;
+              }
+            else
+              {
+              if (c != 0x000a && c != 0x000b && c != 0x000c &&
+                  c != 0x0085 && c != 0x2028 && c != 0x2029)
+                break;
+              eptr += len;
+              }
+            }
+          break;
+
           case OP_NOT_DIGIT:
           for (i = min; i < max; i++)
             {
@@ -3257,6 +3459,7 @@ for (;;)
 
         /* eptr is now past the end of the maximum run */
 
+        if (possessive) continue;
         for(;;)
           {
           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -3277,9 +3480,7 @@ for (;;)
             {
             for (i = min; i < max; i++)
               {
-              if (eptr >= md->end_subject ||
-                  (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)))
-                break;
+              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
               eptr++;
               }
             break;
@@ -3288,10 +3489,30 @@ for (;;)
 
           case OP_ANYBYTE:
           c = max - min;
-          if (c > md->end_subject - eptr) c = md->end_subject - eptr;
+          if (c > (unsigned int)(md->end_subject - eptr))
+            c = md->end_subject - eptr;
           eptr += c;
           break;
 
+          case OP_ANYNL:
+          for (i = min; i < max; i++)
+            {
+            if (eptr >= md->end_subject) break;
+            c = *eptr;
+            if (c == 0x000d)
+              {
+              if (++eptr >= md->end_subject) break;
+              if (*eptr == 0x000a) eptr++;
+              }
+            else
+              {
+              if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085)
+                break;
+              eptr++;
+              }
+            }
+          break;
+
           case OP_NOT_DIGIT:
           for (i = min; i < max; i++)
             {
@@ -3352,6 +3573,7 @@ for (;;)
 
         /* eptr is now past the end of the maximum run */
 
+        if (possessive) continue;
         while (eptr >= pp)
           {
           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
@@ -3366,14 +3588,12 @@ for (;;)
       }
     /* Control never gets here */
 
-    /* There's been some horrible disaster. Since all codes > OP_BRA are
-    for capturing brackets, and there shouldn't be any gaps between 0 and
-    OP_BRA, arrival here can only mean there is something seriously wrong
-    in the code above or the OP_xxx definitions. */
+    /* There's been some horrible disaster. Arrival here can only mean there is
+    something seriously wrong in the code above or the OP_xxx definitions. */
 
     default:
     DPRINTF(("Unknown opcode %d\n", *ecode));
-    RRETURN(PCRE_ERROR_UNKNOWN_NODE);
+    RRETURN(PCRE_ERROR_UNKNOWN_OPCODE);
     }
 
   /* Do not stick any code in here without much thought; it is assumed
@@ -3411,7 +3631,6 @@ Undefine all the macros that were defined above to handle this. */
 
 #undef cur_is_word
 #undef condition
-#undef minimize
 #undef prev_is_word
 
 #undef original_ims
@@ -3484,6 +3703,7 @@ BOOL startline;
 BOOL firstline;
 BOOL first_byte_caseless = FALSE;
 BOOL req_byte_caseless = FALSE;
+BOOL utf8;
 match_data match_block;
 match_data *md = &match_block;
 const uschar *tables;
@@ -3491,6 +3711,7 @@ const uschar *start_bits = NULL;
 USPTR start_match = (USPTR)subject + start_offset;
 USPTR end_subject;
 USPTR req_byte_ptr = start_match - 1;
+eptrblock eptrchain[EPTR_WORK_SIZE];
 
 pcre_study_data internal_study;
 const pcre_study_data *study;
@@ -3567,7 +3788,7 @@ md->end_subject = md->start_subject + length;
 end_subject = md->end_subject;
 
 md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
-md->utf8 = (re->options & PCRE_UTF8) != 0;
+utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
 
 md->notbol = (options & PCRE_NOTBOL) != 0;
 md->noteol = (options & PCRE_NOTEOL) != 0;
@@ -3576,6 +3797,7 @@ md->partial = (options & PCRE_PARTIAL) != 0;
 md->hitend = FALSE;
 
 md->recursive = NULL;                   /* No recursion at top level */
+md->eptrchain = eptrchain;              /* Make workspace generally available */
 
 md->lcc = tables + lcc_offset;
 md->ctypes = tables + ctypes_offset;
@@ -3583,26 +3805,36 @@ md->ctypes = tables + ctypes_offset;
 /* Handle different types of newline. The two bits give four cases. If nothing
 is set at run time, whatever was used at compile time applies. */
 
-switch ((((options & PCRE_NEWLINE_CRLF) == 0)? re->options : options) &
-         PCRE_NEWLINE_CRLF)
+switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) &
+       PCRE_NEWLINE_BITS)
   {
-  default:              newline = NEWLINE; break;   /* Compile-time default */
+  case 0: newline = NEWLINE; break;   /* Compile-time default */
   case PCRE_NEWLINE_CR: newline = '\r'; break;
   case PCRE_NEWLINE_LF: newline = '\n'; break;
   case PCRE_NEWLINE_CR+
        PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;
+  case PCRE_NEWLINE_ANY: newline = -1; break;
+  default: return PCRE_ERROR_BADNEWLINE;
   }
 
-if (newline > 255)
+if (newline < 0)
   {
-  md->nllen = 2;
-  md->nl[0] = (newline >> 8) & 255;
-  md->nl[1] = newline & 255;
+  md->nltype = NLTYPE_ANY;
   }
 else
   {
-  md->nllen = 1;
-  md->nl[0] = newline;
+  md->nltype = NLTYPE_FIXED;
+  if (newline > 255)
+    {
+    md->nllen = 2;
+    md->nl[0] = (newline >> 8) & 255;
+    md->nl[1] = newline & 255;
+    }
+  else
+    {
+    md->nllen = 1;
+    md->nl[0] = newline;
+    }
   }
 
 /* Partial matching is supported only for a restricted set of regexes at the
@@ -3615,7 +3847,7 @@ if (md->partial && (re->options & PCRE_NOPARTIAL) != 0)
 back the character offset. */
 
 #ifdef SUPPORT_UTF8
-if (md->utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
+if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
   {
   if (_pcre_valid_utf8((uschar *)subject, length) >= 0)
     return PCRE_ERROR_BADUTF8;
@@ -3707,10 +3939,13 @@ if ((re->options & PCRE_REQCHSET) != 0)
   req_byte2 = (tables + fcc_offset)[req_byte];  /* case flipped */
   }
 
+
+/* ==========================================================================*/
+
 /* Loop for handling unanchored repeated matching attempts; for anchored regexs
 the loop runs just once. */
 
-do
+for(;;)
   {
   USPTR save_end_subject = end_subject;
 
@@ -3725,14 +3960,14 @@ do
 
   /* Advance to a unique first char if possible. If firstline is TRUE, the
   start of the match is constrained to the first line of a multiline string.
-  Implement this by temporarily adjusting end_subject so that we stop scanning
-  at a newline. If the match fails at the newline, later code breaks this loop.
-  */
+  That is, the match must be before or at the first newline. Implement this by
+  temporarily adjusting end_subject so that we stop scanning at a newline. If
+  the match fails at the newline, later code breaks this loop. */
 
   if (firstline)
     {
     USPTR t = start_match;
-    while (t <= save_end_subject - md->nllen && !IS_NEWLINE(t)) t++;
+    while (t < md->end_subject && !IS_NEWLINE(t)) t++;
     end_subject = t;
     }
 
@@ -3753,11 +3988,9 @@ do
 
   else if (startline)
     {
-    if (start_match >= md->start_subject + md->nllen +
-          start_offset)
+    if (start_match > md->start_subject + start_offset)
       {
-      while (start_match <= end_subject &&
-             !IS_NEWLINE(start_match - md->nllen))
+      while (start_match <= end_subject && !WAS_NEWLINE(start_match))
         start_match++;
       }
     }
@@ -3793,8 +4026,8 @@ do
 
   HOWEVER: when the subject string is very, very long, searching to its end can
   take a long time, and give bad performance on quite ordinary patterns. This
-  showed up when somebody was matching /^C/ on a 32-megabyte string... so we
-  don't do this when the string is sufficiently long.
+  showed up when somebody was matching something like /^\d+C/ on a 32-megabyte
+  string... so we don't do this when the string is sufficiently long.
 
   ALSO: this processing is disabled when partial matching is requested.
   */
@@ -3826,9 +4059,14 @@ do
           }
         }
 
-      /* If we can't find the required character, break the matching loop */
+      /* If we can't find the required character, break the matching loop,
+      forcing a match failure. */
 
-      if (p >= end_subject) break;
+      if (p >= end_subject)
+        {
+        rc = MATCH_NOMATCH;
+        break;
+        }
 
       /* If we have found the required character, save the point where we
       found it, so that we don't search again next time round the loop if
@@ -3838,49 +4076,70 @@ do
       }
     }
 
-  /* When a match occurs, substrings will be set for all internal extractions;
-  we just need to set up the whole thing as substring 0 before returning. If
-  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. */
+  /* OK, we can now run the match. */
 
   md->start_match = start_match;
   md->match_call_count = 0;
+  md->eptrn = 0;                          /* Next free eptrchain slot */
+  rc = match(start_match, md->start_code, 2, md, ims, NULL, 0, 0);
 
-  rc = match(start_match, md->start_code, 2, md, ims, NULL, match_isgroup, 0);
+  /* Any return other than MATCH_NOMATCH breaks the loop. */
 
-  /* When the result is no match, if the subject's first character was a
-  newline and the PCRE_FIRSTLINE option is set, break (which will return
-  PCRE_ERROR_NOMATCH). The option requests that a match occur before the first
-  newline in the subject. Otherwise, advance the pointer to the next character
-  and continue - but the continuation will actually happen only when the
-  pattern is not anchored. */
+  if (rc != MATCH_NOMATCH) break;
 
-  if (rc == MATCH_NOMATCH)
-    {
-    if (firstline &&
-        start_match <= md->end_subject - md->nllen &&
-        IS_NEWLINE(start_match))
-      break;
-    start_match++;
+  /* If PCRE_FIRSTLINE is set, the match must happen before or at the first
+  newline in the subject (though it may continue over the newline). Therefore,
+  if we have just failed to match, starting at a newline, do not continue. */
+
+  if (firstline && IS_NEWLINE(start_match)) break;
+
+  /* Advance the match position by one character. */
+
+  start_match++;
 #ifdef SUPPORT_UTF8
-    if (md->utf8)
-      while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
-        start_match++;
+  if (utf8)
+    while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
+      start_match++;
 #endif
-    continue;
-    }
 
-  if (rc != MATCH_MATCH)
-    {
-    DPRINTF((">>>> error: returning %d\n", rc));
-    return rc;
-    }
+  /* Break the loop if the pattern is anchored or if we have passed the end of
+  the subject. */
+
+  if (anchored || start_match > end_subject) break;
+
+  /* If we have just passed a CR and the newline option is CRLF or ANY, and we
+  are now at a LF, advance the match position by one more character. */
+
+  if (start_match[-1] == '\r' &&
+       (md->nltype == NLTYPE_ANY || md->nllen == 2) &&
+       start_match < end_subject &&
+       *start_match == '\n')
+    start_match++;
+
+  }   /* End of for(;;) "bumpalong" loop */
+
+/* ==========================================================================*/
+
+/* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping
+conditions is true:
 
-  /* We have a match! Copy the offset information from temporary store if
-  necessary */
+(1) The pattern is anchored;
 
+(2) We are past the end of the subject;
+
+(3) PCRE_FIRSTLINE is set and we have failed to match at a newline, because
+    this option requests that a match occur at or before the first newline in
+    the subject.
+
+When we have a match and the offset vector is big enough to deal with any
+backreferences, captured substring offsets will already be set up. In the case
+where we had to get some local store to hold offsets for backreference
+processing, copy those that we can. In this case there need not be overflow if
+certain parts of the pattern were not used, even though there are more
+capturing parentheses than vector slots. */
+
+if (rc == MATCH_MATCH)
+  {
   if (using_temporary_offsets)
     {
     if (offsetcount >= 4)
@@ -3889,15 +4148,18 @@ do
         (offsetcount - 2) * sizeof(int));
       DPRINTF(("Copied offsets from temporary memory\n"));
       }
-    if (md->end_offset_top > offsetcount)
-      md->offset_overflow = TRUE;
-
+    if (md->end_offset_top > offsetcount) md->offset_overflow = TRUE;
     DPRINTF(("Freeing temporary memory\n"));
     (pcre_free)(md->offset_vector);
     }
 
+  /* Set the return code to the number of captured strings, or 0 if there are
+  too many to fit into the vector. */
+
   rc = md->offset_overflow? 0 : md->end_offset_top/2;
 
+  /* If there is space, set up the whole thing as substring 0. */
+
   if (offsetcount < 2) rc = 0; else
     {
     offsets[0] = start_match - md->start_subject;
@@ -3908,9 +4170,8 @@ do
   return rc;
   }
 
-/* This "while" is the end of the "do" above */
-
-while (!anchored && start_match <= end_subject);
+/* Control gets here if there has been an error, or if the overall match
+attempt has failed at all permitted starting positions. */
 
 if (using_temporary_offsets)
   {
@@ -3918,7 +4179,12 @@ if (using_temporary_offsets)
   (pcre_free)(md->offset_vector);
   }
 
-if (md->partial && md->hitend)
+if (rc != MATCH_NOMATCH)
+  {
+  DPRINTF((">>>> error: returning %d\n", rc));
+  return rc;
+  }
+else if (md->partial && md->hitend)
   {
   DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));
   return PCRE_ERROR_PARTIAL;
index daf8516e074fabc160398944aa74a39bb4116679..4a8edc6f47c6754d1c3eb4c6b42d5240f601a3cb 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
index c37b7a7069a917494745446d0bdb0cd480ec8b1f..856e955a5c75379134fe80cad2e12e317856c1d8 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -436,7 +436,6 @@ pcre_get_named_substring(const pcre *code, const char *subject, int *ovector,
 int n = get_first_set(code, stringname, ovector);
 if (n <= 0) return n;
 return pcre_get_substring(subject, ovector, stringcount, n, stringptr);
-
 }
 
 
index 36b1978cb34355e6d32a90756bdd9443e52cdc0a..f29983e53bbdd5c1ecbf08311b4f87c35e3830b5 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -51,6 +51,18 @@ differently, and global variables are not used (see pcre.in). */
 
 
 #ifndef VPCOMPAT
+
+/**************************************************************************
+This code used to be here for use when compiling as a C++ library. However,
+according to Dair Grant it is not needed: "
+
+ Including 'extern "C"' in the declaration generates an "initialized and
+ declared `extern'" warning from gcc 4.0.1. Since we include pcre_internal.h,
+ which includes pcre.h, which declares these prototypes within an extern "C" {}
+ block, we shouldn't need the prefix here.
+
+So, from Release 7.0 I have cut this out.
+
 #ifdef __cplusplus
 extern "C" void *(*pcre_malloc)(size_t) = malloc;
 extern "C" void  (*pcre_free)(void *) = free;
@@ -58,12 +70,13 @@ extern "C" void *(*pcre_stack_malloc)(size_t) = malloc;
 extern "C" void  (*pcre_stack_free)(void *) = free;
 extern "C" int   (*pcre_callout)(pcre_callout_block *) = NULL;
 #else
+**************************************************************************/
+
 void *(*pcre_malloc)(size_t) = malloc;
 void  (*pcre_free)(void *) = free;
 void *(*pcre_stack_malloc)(size_t) = malloc;
 void  (*pcre_stack_free)(void *) = free;
 int   (*pcre_callout)(pcre_callout_block *) = NULL;
 #endif
-#endif
 
 /* End of pcre_globals.c */
index ccd1efa8c5c3be433b5034e449ee8bab600af1e4..b318b93eaa6fdb23dd7cf48ce0351d6aca35c97c 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
index d1931d063886fd65ca490e260962cfb51816f352..4034cf457479d7efe309d7e1deab4ad54c6982dc 100644 (file)
@@ -7,7 +7,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -54,12 +54,16 @@ functions whose names all begin with "_pcre_". */
 /* 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, or at least there were when I first wrote this. After
-all, it had only been about 10 years then... */
+all, it had only been about 10 years then...
 
+It turns out that the Mac Debugging.h header also defines the macro DPRINTF, so
+be absolutely sure we get our version. */
+
+#undef DPRINTF
 #ifdef DEBUG
 #define DPRINTF(p) printf p
 #else
-#define DPRINTF(p) /*nothing*/
+#define DPRINTF(p) /* Nothing */
 #endif
 
 
@@ -118,13 +122,48 @@ Unix, where it is defined in sys/types, so use "uschar" instead. */
 
 typedef unsigned char uschar;
 
-/* PCRE is able to support 3 different kinds of newline (CR, LF, CRLF). The
-following macro is used to package up testing for newlines. NLBLOCK is defined
-in the various modules to indicate in which datablock the parameters exist. */
+/* This is an unsigned int value that no character can ever have. UTF-8
+characters only go up to 0x7fffffff (though Unicode doesn't go beyond
+0x0010ffff). */
+
+#define NOTACHAR 0xffffffff
+
+/* PCRE is able to support several different kinds of newline (CR, LF, CRLF,
+and "all" at present). The following macros are used to package up testing for
+newlines. NLBLOCK, PSSTART, and PSEND are defined in the various modules to
+indicate in which datablock the parameters exist, and what the start/end of
+string field names are. */
+
+#define NLTYPE_FIXED   0     /* Newline is a fixed length string */
+#define NLTYPE_ANY     1     /* Newline is any Unicode line ending */
+
+/* This macro checks for a newline at the given position */
 
 #define IS_NEWLINE(p) \
-  ((p)[0] == NLBLOCK->nl[0] && \
-  (NLBLOCK->nllen == 1 || (p)[1] == NLBLOCK->nl[1]))
+  ((NLBLOCK->nltype != NLTYPE_FIXED)? \
+    ((p) < NLBLOCK->PSEND && \
+     _pcre_is_newline((p), NLBLOCK->PSEND, &(NLBLOCK->nllen), utf8) \
+    ) \
+    : \
+    ((p) <= NLBLOCK->PSEND - NLBLOCK->nllen && \
+     (p)[0] == NLBLOCK->nl[0] && \
+     (NLBLOCK->nllen == 1 || (p)[1] == NLBLOCK->nl[1]) \
+    ) \
+  )
+
+/* This macro checks for a newline immediately preceding the given position */
+
+#define WAS_NEWLINE(p) \
+  ((NLBLOCK->nltype != NLTYPE_FIXED)? \
+    ((p) > NLBLOCK->PSSTART && \
+     _pcre_was_newline((p), NLBLOCK->PSSTART, &(NLBLOCK->nllen), utf8) \
+    ) \
+    : \
+    ((p) >= NLBLOCK->PSSTART + NLBLOCK->nllen && \
+     (p)[-NLBLOCK->nllen] == NLBLOCK->nl[0] && \
+     (NLBLOCK->nllen == 1 || (p)[-NLBLOCK->nllen+1] == NLBLOCK->nl[1]) \
+    ) \
+  )
 
 /* When PCRE is compiled as a C++ library, the subject pointer can be replaced
 with a custom type. This makes it possible, for example, to allow pcre_exec()
@@ -282,7 +321,7 @@ we know we are in UTF-8 mode. */
 
 #define GETCHAR(c, eptr) \
   c = *eptr; \
-  if ((c & 0xc0) == 0xc0) \
+  if (c >= 0xc0) \
     { \
     int gcii; \
     int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */ \
@@ -300,7 +339,7 @@ pointer. */
 
 #define GETCHARTEST(c, eptr) \
   c = *eptr; \
-  if (utf8 && (c & 0xc0) == 0xc0) \
+  if (utf8 && c >= 0xc0) \
     { \
     int gcii; \
     int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */ \
@@ -318,7 +357,7 @@ know we are in UTF-8 mode. */
 
 #define GETCHARINC(c, eptr) \
   c = *eptr++; \
-  if ((c & 0xc0) == 0xc0) \
+  if (c >= 0xc0) \
     { \
     int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */ \
     int gcss = 6*gcaa; \
@@ -334,7 +373,7 @@ know we are in UTF-8 mode. */
 
 #define GETCHARINCTEST(c, eptr) \
   c = *eptr++; \
-  if (utf8 && (c & 0xc0) == 0xc0) \
+  if (utf8 && c >= 0xc0) \
     { \
     int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */ \
     int gcss = 6*gcaa; \
@@ -351,7 +390,7 @@ if there are extra bytes. This is called when we know we are in UTF-8 mode. */
 
 #define GETCHARLEN(c, eptr, len) \
   c = *eptr; \
-  if ((c & 0xc0) == 0xc0) \
+  if (c >= 0xc0) \
     { \
     int gcii; \
     int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */ \
@@ -404,20 +443,21 @@ bits. */
 /* Masks for identifying the public options that are permitted at compile
 time, run time, or study time, respectively. */
 
+#define PCRE_NEWLINE_BITS (PCRE_NEWLINE_CR|PCRE_NEWLINE_LF|PCRE_NEWLINE_ANY)
+
 #define PUBLIC_OPTIONS \
   (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
    PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \
    PCRE_NO_AUTO_CAPTURE|PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT|PCRE_FIRSTLINE| \
-   PCRE_DUPNAMES|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF)
+   PCRE_DUPNAMES|PCRE_NEWLINE_BITS)
 
 #define PUBLIC_EXEC_OPTIONS \
   (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \
-   PCRE_PARTIAL|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF)
+   PCRE_PARTIAL|PCRE_NEWLINE_BITS)
 
 #define PUBLIC_DFA_EXEC_OPTIONS \
   (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \
-   PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART|PCRE_NEWLINE_CR| \
-   PCRE_NEWLINE_LF)
+   PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART|PCRE_NEWLINE_BITS)
 
 #define PUBLIC_STUDY_OPTIONS 0   /* None defined */
 
@@ -449,9 +489,7 @@ typedef int BOOL;
 #define FALSE   0
 #define TRUE    1
 
-/* Escape items that are just an encoding of a particular data value. Note that
-ESC_n is defined as yet another macro, which is set in config.h to either \n
-(the default) or \r (which some people want). */
+/* Escape items that are just an encoding of a particular data value. */
 
 #ifndef ESC_e
 #define ESC_e 27
@@ -462,7 +500,7 @@ ESC_n is defined as yet another macro, which is set in config.h to either \n
 #endif
 
 #ifndef ESC_n
-#define ESC_n NEWLINE
+#define ESC_n '\n'
 #endif
 
 #ifndef ESC_r
@@ -501,21 +539,28 @@ 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. There's a dummy for OP_ANY because it
 corresponds to "." rather than an escape sequence. The final one must be
-ESC_REF as subsequent values are used for \1, \2, \3, etc. There is are two
-tests in the code for an escape greater than ESC_b and less than ESC_Z to
-detect the types that may be repeated. These are the types that consume
-characters. If any new escapes are put in between that don't consume a
+ESC_REF as subsequent values are used for backreferences (\1, \2, \3, etc).
+There are two tests in the code for an escape greater than ESC_b and less than
+ESC_Z to detect the types that may be repeated. These are the types that
+consume characters. 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_G, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W,
-       ESC_w, ESC_dum1, ESC_C, ESC_P, ESC_p, ESC_X, ESC_Z, ESC_z, ESC_E,
-       ESC_Q, ESC_REF };
+       ESC_w, ESC_dum1, ESC_C, ESC_P, ESC_p, ESC_R, ESC_X, ESC_Z, ESC_z,
+       ESC_E, ESC_Q, ESC_k, 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
 OP_EOD must correspond in order to the list of escapes immediately above.
-Note that whenever this list is updated, the two macro definitions that follow
-must also be updated to match. */
+
+To keep stored, compiled patterns compatible, new opcodes should be added
+immediately before OP_BRA, where (since release 7.0) a gap is left for this
+purpose.
+
+*** NOTE NOTE NOTE *** Whenever this list is updated, the two macro definitions
+that follow must also be updated to match. There is also a table called
+"coptable" in pcre_dfa_exec.c that must be updated. */
 
 enum {
   OP_END,            /* 0 End of pattern */
@@ -536,110 +581,122 @@ enum {
   OP_ANYBYTE,        /* 12 Match any byte (\C); different to OP_ANY for UTF-8 */
   OP_NOTPROP,        /* 13 \P (not Unicode property) */
   OP_PROP,           /* 14 \p (Unicode property) */
-  OP_EXTUNI,         /* 15 \X (extended Unicode sequence */
-  OP_EODN,           /* 16 End of data or \n at end of data: \Z. */
-  OP_EOD,            /* 17 End of data: \z */
-
-  OP_OPT,            /* 18 Set runtime options */
-  OP_CIRC,           /* 19 Start of line - varies with multiline switch */
-  OP_DOLL,           /* 20 End of line - varies with multiline switch */
-  OP_CHAR,           /* 21 Match one character, casefully */
-  OP_CHARNC,         /* 22 Match one character, caselessly */
-  OP_NOT,            /* 23 Match one character, not the following one */
-
-  OP_STAR,           /* 24 The maximizing and minimizing versions of */
-  OP_MINSTAR,        /* 25 all these opcodes must come in pairs, with */
-  OP_PLUS,           /* 26 the minimizing one second. */
-  OP_MINPLUS,        /* 27 This first set applies to single characters */
-  OP_QUERY,          /* 28 */
-  OP_MINQUERY,       /* 29 */
-  OP_UPTO,           /* 30 From 0 to n matches */
-  OP_MINUPTO,        /* 31 */
-  OP_EXACT,          /* 32 Exactly n matches */
-
-  OP_NOTSTAR,        /* 33 The maximizing and minimizing versions of */
-  OP_NOTMINSTAR,     /* 34 all these opcodes must come in pairs, with */
-  OP_NOTPLUS,        /* 35 the minimizing one second. */
-  OP_NOTMINPLUS,     /* 36 This set applies to "not" single characters */
-  OP_NOTQUERY,       /* 37 */
-  OP_NOTMINQUERY,    /* 38 */
-  OP_NOTUPTO,        /* 39 From 0 to n matches */
-  OP_NOTMINUPTO,     /* 40 */
-  OP_NOTEXACT,       /* 41 Exactly n matches */
-
-  OP_TYPESTAR,       /* 42 The maximizing and minimizing versions of */
-  OP_TYPEMINSTAR,    /* 43 all these opcodes must come in pairs, with */
-  OP_TYPEPLUS,       /* 44 the minimizing one second. These codes must */
-  OP_TYPEMINPLUS,    /* 45 be in exactly the same order as those above. */
-  OP_TYPEQUERY,      /* 46 This set applies to character types such as \d */
-  OP_TYPEMINQUERY,   /* 47 */
-  OP_TYPEUPTO,       /* 48 From 0 to n matches */
-  OP_TYPEMINUPTO,    /* 49 */
-  OP_TYPEEXACT,      /* 50 Exactly n matches */
-
-  OP_CRSTAR,         /* 51 The maximizing and minimizing versions of */
-  OP_CRMINSTAR,      /* 52 all these opcodes must come in pairs, with */
-  OP_CRPLUS,         /* 53 the minimizing one second. These codes must */
-  OP_CRMINPLUS,      /* 54 be in exactly the same order as those above. */
-  OP_CRQUERY,        /* 55 These are for character classes and back refs */
-  OP_CRMINQUERY,     /* 56 */
-  OP_CRRANGE,        /* 57 These are different to the three sets above. */
-  OP_CRMINRANGE,     /* 58 */
-
-  OP_CLASS,          /* 59 Match a character class, chars < 256 only */
-  OP_NCLASS,         /* 60 Same, but the bitmap was created from a negative
+  OP_ANYNL,          /* 15 \R (any newline sequence) */
+  OP_EXTUNI,         /* 16 \X (extended Unicode sequence */
+  OP_EODN,           /* 17 End of data or \n at end of data: \Z. */
+  OP_EOD,            /* 18 End of data: \z */
+
+  OP_OPT,            /* 19 Set runtime options */
+  OP_CIRC,           /* 20 Start of line - varies with multiline switch */
+  OP_DOLL,           /* 21 End of line - varies with multiline switch */
+  OP_CHAR,           /* 22 Match one character, casefully */
+  OP_CHARNC,         /* 23 Match one character, caselessly */
+  OP_NOT,            /* 24 Match one character, not the following one */
+
+  OP_STAR,           /* 25 The maximizing and minimizing versions of */
+  OP_MINSTAR,        /* 26 these six opcodes must come in pairs, with */
+  OP_PLUS,           /* 27 the minimizing one second. */
+  OP_MINPLUS,        /* 28 This first set applies to single characters.*/
+  OP_QUERY,          /* 29 */
+  OP_MINQUERY,       /* 30 */
+
+  OP_UPTO,           /* 31 From 0 to n matches */
+  OP_MINUPTO,        /* 32 */
+  OP_EXACT,          /* 33 Exactly n matches */
+
+  OP_POSSTAR,        /* 34 Possessified star */
+  OP_POSPLUS,        /* 35 Possessified plus */
+  OP_POSQUERY,       /* 36 Posesssified query */
+  OP_POSUPTO,        /* 37 Possessified upto */
+
+  OP_NOTSTAR,        /* 38 The maximizing and minimizing versions of */
+  OP_NOTMINSTAR,     /* 39 these six opcodes must come in pairs, with */
+  OP_NOTPLUS,        /* 40 the minimizing one second. They must be in */
+  OP_NOTMINPLUS,     /* 41 exactly the same order as those above. */
+  OP_NOTQUERY,       /* 42 This set applies to "not" single characters. */
+  OP_NOTMINQUERY,    /* 43 */
+
+  OP_NOTUPTO,        /* 44 From 0 to n matches */
+  OP_NOTMINUPTO,     /* 45 */
+  OP_NOTEXACT,       /* 46 Exactly n matches */
+
+  OP_NOTPOSSTAR,     /* 47 Possessified versions */
+  OP_NOTPOSPLUS,     /* 48 */
+  OP_NOTPOSQUERY,    /* 49 */
+  OP_NOTPOSUPTO,     /* 50 */
+
+  OP_TYPESTAR,       /* 51 The maximizing and minimizing versions of */
+  OP_TYPEMINSTAR,    /* 52 these six opcodes must come in pairs, with */
+  OP_TYPEPLUS,       /* 53 the minimizing one second. These codes must */
+  OP_TYPEMINPLUS,    /* 54 be in exactly the same order as those above. */
+  OP_TYPEQUERY,      /* 55 This set applies to character types such as \d */
+  OP_TYPEMINQUERY,   /* 56 */
+
+  OP_TYPEUPTO,       /* 57 From 0 to n matches */
+  OP_TYPEMINUPTO,    /* 58 */
+  OP_TYPEEXACT,      /* 59 Exactly n matches */
+
+  OP_TYPEPOSSTAR,    /* 60 Possessified versions */
+  OP_TYPEPOSPLUS,    /* 61 */
+  OP_TYPEPOSQUERY,   /* 62 */
+  OP_TYPEPOSUPTO,    /* 63 */
+
+  OP_CRSTAR,         /* 64 The maximizing and minimizing versions of */
+  OP_CRMINSTAR,      /* 65 all these opcodes must come in pairs, with */
+  OP_CRPLUS,         /* 66 the minimizing one second. These codes must */
+  OP_CRMINPLUS,      /* 67 be in exactly the same order as those above. */
+  OP_CRQUERY,        /* 68 These are for character classes and back refs */
+  OP_CRMINQUERY,     /* 69 */
+  OP_CRRANGE,        /* 70 These are different to the three sets above. */
+  OP_CRMINRANGE,     /* 71 */
+
+  OP_CLASS,          /* 72 Match a character class, chars < 256 only */
+  OP_NCLASS,         /* 73 Same, but the bitmap was created from a negative
                            class - the difference is relevant only when a UTF-8
                            character > 255 is encountered. */
 
-  OP_XCLASS,         /* 61 Extended class for handling UTF-8 chars within the
+  OP_XCLASS,         /* 74 Extended class for handling UTF-8 chars within the
                            class. This does both positive and negative. */
 
-  OP_REF,            /* 62 Match a back reference */
-  OP_RECURSE,        /* 63 Match a numbered subpattern (possibly recursive) */
-  OP_CALLOUT,        /* 64 Call out to external function if provided */
-
-  OP_ALT,            /* 65 Start of alternation */
-  OP_KET,            /* 66 End of group that doesn't have an unbounded repeat */
-  OP_KETRMAX,        /* 67 These two must remain together and in this */
-  OP_KETRMIN,        /* 68 order. They are for groups the repeat for ever. */
+  OP_REF,            /* 75 Match a back reference */
+  OP_RECURSE,        /* 76 Match a numbered subpattern (possibly recursive) */
+  OP_CALLOUT,        /* 77 Call out to external function if provided */
 
-  /* The assertions must come before ONCE and COND */
+  OP_ALT,            /* 78 Start of alternation */
+  OP_KET,            /* 79 End of group that doesn't have an unbounded repeat */
+  OP_KETRMAX,        /* 80 These two must remain together and in this */
+  OP_KETRMIN,        /* 81 order. They are for groups the repeat for ever. */
 
-  OP_ASSERT,         /* 69 Positive lookahead */
-  OP_ASSERT_NOT,     /* 70 Negative lookahead */
-  OP_ASSERTBACK,     /* 71 Positive lookbehind */
-  OP_ASSERTBACK_NOT, /* 72 Negative lookbehind */
-  OP_REVERSE,        /* 73 Move pointer back - used in lookbehind assertions */
+  /* The assertions must come before BRA, CBRA, ONCE, and COND.*/
 
-  /* 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_ASSERT,         /* 82 Positive lookahead */
+  OP_ASSERT_NOT,     /* 83 Negative lookahead */
+  OP_ASSERTBACK,     /* 84 Positive lookbehind */
+  OP_ASSERTBACK_NOT, /* 85 Negative lookbehind */
+  OP_REVERSE,        /* 86 Move pointer back - used in lookbehind assertions */
 
-  OP_ONCE,           /* 74 Once matched, don't back up into the subpattern */
-  OP_COND,           /* 75 Conditional group */
-  OP_CREF,           /* 76 Used to hold an extraction string number (cond ref) */
+  /* ONCE, BRA, CBRA, 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_BRAZERO,        /* 77 These two must remain together and in this */
-  OP_BRAMINZERO,     /* 78 order. */
+  OP_ONCE,           /* 87 Atomic group */
+  OP_BRA,            /* 88 Start of non-capturing bracket */
+  OP_CBRA,           /* 89 Start of capturing bracket */
+  OP_COND,           /* 90 Conditional group */
 
-  OP_BRANUMBER,      /* 79 Used for extracting brackets whose number is greater
-                           than can fit into an opcode. */
-
-  OP_BRA             /* 80 This and greater values are used for brackets that
-                           extract substrings up to EXTRACT_BASIC_MAX. After
-                           that, use is made of OP_BRANUMBER. */
-};
+  /* These three must follow the previous three, in the same order. There's a
+  check for >= SBRA to distinguish the two sets. */
 
-/* WARNING WARNING WARNING: There is an implicit assumption in pcre.c and
-study.c that all opcodes are less than 128 in value. This makes handling UTF-8
-character sequences easier. */
+  OP_SBRA,           /* 91 Start of non-capturing bracket, check empty  */
+  OP_SCBRA,          /* 92 Start of capturing bracket, check empty */
+  OP_SCOND,          /* 93 Conditional group, check empty */
 
-/* The highest extraction number before we have to start using additional
-bytes. (Originally PCRE didn't have support for extraction counts highter than
-this number.) The value is limited by the number of opcodes left after OP_BRA,
-i.e. 255 - OP_BRA. We actually set it a bit lower to leave room for additional
-opcodes. */
+  OP_CREF,           /* 94 Used to hold a capture number as condition */
+  OP_RREF,           /* 95 Used to hold a recursion number as condition */
+  OP_DEF,            /* 96 The DEFINE condition */
 
-#define EXTRACT_BASIC_MAX  100
+  OP_BRAZERO,        /* 97 These two must remain together and in this */
+  OP_BRAMINZERO      /* 98 order. */
+};
 
 
 /* This macro defines textual names for all the opcodes. These are used only
@@ -648,17 +705,21 @@ for debugging. The macro is referenced only in pcre_printint.c. */
 #define OP_NAME_LIST \
   "End", "\\A", "\\G", "\\B", "\\b", "\\D", "\\d",                \
   "\\S", "\\s", "\\W", "\\w", "Any", "Anybyte",                   \
-  "notprop", "prop", "extuni",                                    \
+  "notprop", "prop", "anynl", "extuni",                           \
   "\\Z", "\\z",                                                   \
   "Opt", "^", "$", "char", "charnc", "not",                       \
   "*", "*?", "+", "+?", "?", "??", "{", "{", "{",                 \
+  "*+","++", "?+", "{",                                           \
   "*", "*?", "+", "+?", "?", "??", "{", "{", "{",                 \
+  "*+","++", "?+", "{",                                           \
   "*", "*?", "+", "+?", "?", "??", "{", "{", "{",                 \
+  "*+","++", "?+", "{",                                           \
   "*", "*?", "+", "+?", "?", "??", "{", "{",                      \
   "class", "nclass", "xclass", "Ref", "Recurse", "Callout",       \
   "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not",     \
-  "AssertB", "AssertB not", "Reverse", "Once", "Cond", "Cond ref",\
-  "Brazero", "Braminzero", "Branumber", "Bra"
+  "AssertB", "AssertB not", "Reverse",                            \
+  "Once", "Bra 0", "Bra", "Cond", "SBra 0", "SBra", "SCond",      \
+  "Cond ref", "Cond rec", "Cond def", "Brazero", "Braminzero"
 
 
 /* This macro defines the length of fixed length operations in the compiled
@@ -674,7 +735,7 @@ in UTF-8 mode. The code that uses this table must know about such things. */
   1,                             /* End                                    */ \
   1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* \A, \G, \B, \B, \D, \d, \S, \s, \W, \w */ \
   1, 1,                          /* Any, Anybyte                           */ \
-  3, 3, 1,                       /* NOTPROP, PROP, EXTUNI                  */ \
+  3, 3, 1, 1,                    /* NOTPROP, PROP, EXTUNI, ANYNL           */ \
   1, 1, 2, 1, 1,                 /* \Z, \z, Opt, ^, $                      */ \
   2,                             /* Char  - the minimum length             */ \
   2,                             /* Charnc  - the minimum length           */ \
@@ -682,12 +743,15 @@ in UTF-8 mode. The code that uses this table must know about such things. */
   /* Positive single-char repeats                            ** These are  */ \
   2, 2, 2, 2, 2, 2,              /* *, *?, +, +?, ?, ??      ** minima in  */ \
   4, 4, 4,                       /* upto, minupto, exact     ** UTF-8 mode */ \
+  2, 2, 2, 4,                    /* *+, ++, ?+, upto+                      */ \
   /* Negative single-char repeats - only for chars < 256                   */ \
   2, 2, 2, 2, 2, 2,              /* NOT *, *?, +, +?, ?, ??                */ \
   4, 4, 4,                       /* NOT upto, minupto, exact               */ \
+  2, 2, 2, 4,                    /* Possessive *, +, ?, upto               */ \
   /* Positive type repeats                                                 */ \
   2, 2, 2, 2, 2, 2,              /* Type *, *?, +, +?, ?, ??               */ \
   4, 4, 4,                       /* Type upto, minupto, exact              */ \
+  2, 2, 2, 4,                    /* Possessive *+, ++, ?+, upto+           */ \
   /* Character class & ref repeats                                         */ \
   1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */ \
   5, 5,                          /* CRRANGE, CRMINRANGE                    */ \
@@ -706,17 +770,22 @@ in UTF-8 mode. The code that uses this table must know about such things. */
   1+LINK_SIZE,                   /* Assert behind                          */ \
   1+LINK_SIZE,                   /* Assert behind not                      */ \
   1+LINK_SIZE,                   /* Reverse                                */ \
-  1+LINK_SIZE,                   /* Once                                   */ \
+  1+LINK_SIZE,                   /* ONCE                                   */ \
+  1+LINK_SIZE,                   /* BRA                                    */ \
+  3+LINK_SIZE,                   /* CBRA                                   */ \
   1+LINK_SIZE,                   /* COND                                   */ \
+  1+LINK_SIZE,                   /* SBRA                                   */ \
+  3+LINK_SIZE,                   /* SCBRA                                  */ \
+  1+LINK_SIZE,                   /* SCOND                                  */ \
   3,                             /* CREF                                   */ \
+  3,                             /* RREF                                   */ \
+  1,                             /* DEF                                    */ \
   1, 1,                          /* BRAZERO, BRAMINZERO                    */ \
-  3,                             /* BRANUMBER                              */ \
-  1+LINK_SIZE                    /* BRA                                    */ \
 
 
-/* A magic value for OP_CREF to indicate the "in recursion" condition. */
+/* A magic value for OP_RREF to indicate the "any recursion" condition. */
 
-#define CREF_RECURSE  0xffff
+#define RREF_ANY  0xffff
 
 /* Error code numbers. They are given names so that they can more easily be
 tracked. */
@@ -726,7 +795,7 @@ enum { ERR0,  ERR1,  ERR2,  ERR3,  ERR4,  ERR5,  ERR6,  ERR7,  ERR8,  ERR9,
        ERR20, ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29,
        ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39,
        ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49,
-       ERR50, ERR51 };
+       ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57 };
 
 /* The real format of the start of the pcre block; the index of names and the
 code vector run on as long as necessary after the end. We store an explicit
@@ -781,17 +850,23 @@ typedef struct compile_data {
   const uschar *fcc;            /* Points to case-flipping table */
   const uschar *cbits;          /* Points to character type table */
   const uschar *ctypes;         /* Points to table of type maps */
+  const uschar *start_workspace;/* The start of working space */
   const uschar *start_code;     /* The start of the compiled code */
   const uschar *start_pattern;  /* The start of the pattern */
+  const uschar *end_pattern;    /* The end of the pattern */
+  uschar *hwm;                  /* High watermark of workspace */
   uschar *name_table;           /* The name/number table */
   int  names_found;             /* Number of entries so far */
   int  name_entry_size;         /* Size of each entry */
+  int  bracount;                /* Count of capturing parens */
   int  top_backref;             /* Maximum back reference */
   unsigned int backref_map;     /* Bitmap of low back refs */
+  int  external_options;        /* External (initial) options */
   int  req_varyopt;             /* "After variable item" flag for reqbyte */
   BOOL nopartial;               /* Set TRUE if partial won't work */
-  int  nllen;                   /* 1 or 2 for newline string length */
-  uschar nl[4];                 /* Newline string */
+  int  nltype;                  /* Newline type */
+  int  nllen;                   /* Newline string length */
+  uschar nl[4];                 /* Newline string when fixed length */
 } compile_data;
 
 /* Structure for maintaining a chain of pointers to the currently incomplete
@@ -824,6 +899,16 @@ This isn't used for a "normal" compilation of pcre. */
 
 struct heapframe;
 
+/* Structure for building a chain of data for holding the values of the subject
+pointer at the start of each subpattern, so as to detect when an empty string
+has been matched by a subpattern - to break infinite loops. */
+
+typedef struct eptrblock {
+  struct eptrblock *epb_prev;
+  USPTR epb_saved_eptr;
+} eptrblock;
+
+
 /* Structure for passing "static" information around between the functions
 doing traditional NFA matching, so that they are thread-safe. */
 
@@ -834,8 +919,9 @@ typedef struct match_data {
   int   *offset_vector;         /* Offset vector */
   int    offset_end;            /* One past the end */
   int    offset_max;            /* The maximum usable for return data */
-  int    nllen;                 /* 1 or 2 for newline string length */
-  uschar nl[4];                 /* Newline string */
+  int    nltype;                /* Newline type */
+  int    nllen;                 /* Newline string length */
+  uschar nl[4];                 /* Newline string when fixed */
   const uschar *lcc;            /* Points to lower casing table */
   const uschar *ctypes;         /* Points to table of type maps */
   BOOL   offset_overflow;       /* Set if too many extractions */
@@ -854,6 +940,8 @@ typedef struct match_data {
   int    end_offset_top;        /* Highwater mark at end of match */
   int    capture_last;          /* Most recent capture number */
   int    start_offset;          /* The start offset value */
+  eptrblock *eptrchain;         /* Chain of eptrblocks for tail recursions */
+  int    eptrn;                 /* Next free eptrblock */
   recursion_info *recursive;    /* Linked list of recursion data */
   void  *callout_data;          /* To pass back to callouts */
   struct heapframe *thisframe;  /* Used only when compiling for no recursion */
@@ -869,8 +957,9 @@ typedef struct dfa_match_data {
   const uschar *tables;         /* Character tables */
   int   moptions;               /* Match options */
   int   poptions;               /* Pattern options */
-  int    nllen;                 /* 1 or 2 for newline string length */
-  uschar nl[4];                 /* Newline string */
+  int    nltype;                /* Newline type */
+  int    nllen;                 /* Newline string length */
+  uschar nl[4];                 /* Newline string when fixed */
   void  *callout_data;          /* To pass back to callouts */
 } dfa_match_data;
 
@@ -941,13 +1030,17 @@ extern const uschar _pcre_OP_lengths[];
 one of the exported public functions. They have to be "external" in the C
 sense, but are not part of the PCRE public API. */
 
-extern int         _pcre_ord2utf8(int, uschar *);
-extern real_pcre * _pcre_try_flipped(const real_pcre *, real_pcre *,
-                     const pcre_study_data *, pcre_study_data *);
-extern int         _pcre_ucp_findprop(const unsigned int, int *, int *);
-extern int         _pcre_ucp_othercase(const int);
-extern int         _pcre_valid_utf8(const uschar *, int);
-extern BOOL        _pcre_xclass(int, const uschar *);
+extern BOOL         _pcre_is_newline(const uschar *, const uschar *, int *,
+                      BOOL);
+extern int          _pcre_ord2utf8(int, uschar *);
+extern real_pcre   *_pcre_try_flipped(const real_pcre *, real_pcre *,
+                      const pcre_study_data *, pcre_study_data *);
+extern int          _pcre_ucp_findprop(const unsigned int, int *, int *);
+extern unsigned int _pcre_ucp_othercase(const unsigned int);
+extern int          _pcre_valid_utf8(const uschar *, int);
+extern BOOL         _pcre_was_newline(const uschar *, const uschar *, int *,
+                      BOOL);
+extern BOOL         _pcre_xclass(int, const uschar *);
 
 #endif
 
index 7cba5acccc3b58116f6fd6837b753d4c1533bd08..29e40989bfe35b2044b2c08d6829dc77565a56fd 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -130,7 +130,7 @@ for (i = 0; i < 256; i++)
   meta-character, which in this sense is any character that terminates a run
   of data characters. */
 
-  if (strchr("*+?{^.$|()[", i) != 0) x += ctype_meta;
+  if (strchr("\\*+?{^.$|()[", i) != 0) x += ctype_meta;
   *p++ = x;
   }
 
diff --git a/ext/pcre/pcrelib/pcre_newline.c b/ext/pcre/pcrelib/pcre_newline.c
new file mode 100644 (file)
index 0000000..348791b
--- /dev/null
@@ -0,0 +1,135 @@
+/*************************************************
+*      Perl-Compatible Regular Expressions       *
+*************************************************/
+
+/* PCRE is a library of functions to support regular expressions whose syntax
+and semantics are as close as possible to those of the Perl 5 language.
+
+                       Written by Philip Hazel
+           Copyright (c) 1997-2006 University of Cambridge
+
+-----------------------------------------------------------------------------
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+
+    * Neither the name of the University of Cambridge nor the names of its
+      contributors may be used to endorse or promote products derived from
+      this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+-----------------------------------------------------------------------------
+*/
+
+
+/* This module contains internal functions for testing newlines when more than
+one kind of newline is to be recognized. When a newline is found, its length is
+returned. In principle, we could implement several newline "types", each
+referring to a different set of newline characters. At present, PCRE supports
+only NLTYPE_FIXED, which gets handled without these functions, and NLTYPE_ALL,
+so for now the type isn't passed into the functions. It can easily be added
+later if required. The full list of Unicode newline characters is taken from
+http://unicode.org/unicode/reports/tr18/. */
+
+
+#include "pcre_internal.h"
+
+
+
+/*************************************************
+*      Check for newline at given position       *
+*************************************************/
+
+/* It is guaranteed that the initial value of ptr is less than the end of the
+string that is being processed.
+
+Arguments:
+  ptr          pointer to possible newline
+  endptr       pointer to the end of the string
+  lenptr       where to return the length
+  utf8         TRUE if in utf8 mode
+
+Returns:       TRUE or FALSE
+*/
+
+BOOL
+_pcre_is_newline(const uschar *ptr, const uschar *endptr, int *lenptr,
+  BOOL utf8)
+{
+int c;
+if (utf8) { GETCHAR(c, ptr); } else c = *ptr;
+switch(c)
+  {
+  case 0x000a:                                       /* LF */
+  case 0x000b:                                       /* VT */
+  case 0x000c: *lenptr = 1; return TRUE;             /* FF */
+  case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1;
+               return TRUE;                          /* CR */
+  case 0x0085: *lenptr = utf8? 2 : 1; return TRUE;   /* NEL */
+  case 0x2028:                                       /* LS */
+  case 0x2029: *lenptr = 3; return TRUE;             /* PS */
+  default: return FALSE;
+  }
+}
+
+
+
+/*************************************************
+*     Check for newline at previous position     *
+*************************************************/
+
+/* It is guaranteed that the initial value of ptr is greater than the start of
+the string that is being processed.
+
+Arguments:
+  ptr          pointer to possible newline
+  startptr     pointer to the start of the string
+  lenptr       where to return the length
+  utf8         TRUE if in utf8 mode
+
+Returns:       TRUE or FALSE
+*/
+
+BOOL
+_pcre_was_newline(const uschar *ptr, const uschar *startptr, int *lenptr,
+  BOOL utf8)
+{
+int c;
+ptr--;
+if (utf8)
+  {
+  BACKCHAR(ptr);
+  GETCHAR(c, ptr);
+  }
+else c = *ptr;
+switch(c)
+  {
+  case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1;
+               return TRUE;                         /* LF */
+  case 0x000b:                                      /* VT */
+  case 0x000c:                                      /* FF */
+  case 0x000d: *lenptr = 1; return TRUE;            /* CR */
+  case 0x0085: *lenptr = utf8? 2 : 1; return TRUE;  /* NEL */
+  case 0x2028:                                      /* LS */
+  case 0x2029: *lenptr = 3; return TRUE;            /* PS */
+  default: return FALSE;
+  }
+}
+
+/* End of pcre_newline.c */
index 4eaea9303e8866cc5567ed5f4e26813d1aa6f1c8..fc4d6de81262f2d443d14fad27869774f46f4564 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
index e4de825a9b90966ab340e4413b96f6e88a8ce072..a6f433368a0285bd7adf955ea3496cccb191cfc6 100644 (file)
@@ -49,9 +49,19 @@ local functions. This source file is used in two places:
 compiled regex for debugging purposes. */
 
 
+/* Macro that decides whether a character should be output as a literal or in
+hexadecimal. We don't use isprint() because that can vary from system to system
+(even without the use of locales) and we want the output always to be the same,
+for testing purposes. This macro is used in pcretest as well as in this file. */
+
+#define PRINTABLE(c) ((c) >= 32 && (c) < 127)
+
+/* The table of operator names. */
+
 static const char *OP_names[] = { OP_NAME_LIST };
 
 
+
 /*************************************************
 *       Print single- or multi-byte character    *
 *************************************************/
@@ -63,7 +73,7 @@ int c = *ptr;
 
 if (!utf8 || (c & 0xc0) != 0xc0)
   {
-  if (isprint(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
+  if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
   return 0;
   }
 else
@@ -160,16 +170,6 @@ for(;;)
 
   fprintf(f, "%3d ", (int)(code - codestart));
 
-  if (*code >= OP_BRA)
-    {
-    if (*code - OP_BRA > EXTRACT_BASIC_MAX)
-      fprintf(f, "%3d Bra extra\n", GET(code, 1));
-    else
-      fprintf(f, "%3d Bra %d\n", GET(code, 1), *code - OP_BRA);
-    code += _pcre_OP_lengths[OP_BRA];
-    continue;
-    }
-
   switch(*code)
     {
     case OP_END:
@@ -203,6 +203,14 @@ for(;;)
     fprintf(f, "\n");
     continue;
 
+    case OP_CBRA:
+    case OP_SCBRA:
+    fprintf(f, "%3d %s %d", GET(code, 1), OP_names[*code],
+      GET2(code, 1+LINK_SIZE));
+    break;
+
+    case OP_BRA:
+    case OP_SBRA:
     case OP_KETRMAX:
     case OP_KETRMIN:
     case OP_ALT:
@@ -213,33 +221,45 @@ for(;;)
     case OP_ASSERTBACK_NOT:
     case OP_ONCE:
     case OP_COND:
+    case OP_SCOND:
     case OP_REVERSE:
     fprintf(f, "%3d %s", GET(code, 1), OP_names[*code]);
     break;
 
-    case OP_BRANUMBER:
-    printf("%3d %s", GET2(code, 1), OP_names[*code]);
+    case OP_CREF:
+    fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]);
     break;
 
-    case OP_CREF:
-    if (GET2(code, 1) == CREF_RECURSE)
-      fprintf(f, "    Cond recurse");
+    case OP_RREF:
+    c = GET2(code, 1);
+    if (c == RREF_ANY)
+      fprintf(f, "    Cond recurse any");
     else
-      fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]);
+      fprintf(f, "    Cond recurse %d", c);
+    break;
+
+    case OP_DEF:
+    fprintf(f, "    Cond def");
     break;
 
     case OP_STAR:
     case OP_MINSTAR:
+    case OP_POSSTAR:
     case OP_PLUS:
     case OP_MINPLUS:
+    case OP_POSPLUS:
     case OP_QUERY:
     case OP_MINQUERY:
+    case OP_POSQUERY:
     case OP_TYPESTAR:
     case OP_TYPEMINSTAR:
+    case OP_TYPEPOSSTAR:
     case OP_TYPEPLUS:
     case OP_TYPEMINPLUS:
+    case OP_TYPEPOSPLUS:
     case OP_TYPEQUERY:
     case OP_TYPEMINQUERY:
+    case OP_TYPEPOSQUERY:
     fprintf(f, "    ");
     if (*code >= OP_TYPESTAR)
       {
@@ -257,17 +277,20 @@ for(;;)
     case OP_EXACT:
     case OP_UPTO:
     case OP_MINUPTO:
+    case OP_POSUPTO:
     fprintf(f, "    ");
     extra = print_char(f, code+3, utf8);
     fprintf(f, "{");
-    if (*code != OP_EXACT) fprintf(f, ",");
+    if (*code != OP_EXACT) fprintf(f, "0,");
     fprintf(f, "%d}", GET2(code,1));
     if (*code == OP_MINUPTO) fprintf(f, "?");
+      else if (*code == OP_POSUPTO) fprintf(f, "+");
     break;
 
     case OP_TYPEEXACT:
     case OP_TYPEUPTO:
     case OP_TYPEMINUPTO:
+    case OP_TYPEPOSUPTO:
     fprintf(f, "    %s", OP_names[code[3]]);
     if (code[3] == OP_PROP || code[3] == OP_NOTPROP)
       {
@@ -278,20 +301,26 @@ for(;;)
     if (*code != OP_TYPEEXACT) fprintf(f, "0,");
     fprintf(f, "%d}", GET2(code,1));
     if (*code == OP_TYPEMINUPTO) fprintf(f, "?");
+      else if (*code == OP_TYPEPOSUPTO) fprintf(f, "+");
     break;
 
     case OP_NOT:
-    if (isprint(c = code[1])) fprintf(f, "    [^%c]", c);
+    c = code[1];
+    if (PRINTABLE(c)) fprintf(f, "    [^%c]", c);
       else fprintf(f, "    [^\\x%02x]", c);
     break;
 
     case OP_NOTSTAR:
     case OP_NOTMINSTAR:
+    case OP_NOTPOSSTAR:
     case OP_NOTPLUS:
     case OP_NOTMINPLUS:
+    case OP_NOTPOSPLUS:
     case OP_NOTQUERY:
     case OP_NOTMINQUERY:
-    if (isprint(c = code[1])) fprintf(f, "    [^%c]", c);
+    case OP_NOTPOSQUERY:
+    c = code[1];
+    if (PRINTABLE(c)) fprintf(f, "    [^%c]", c);
       else fprintf(f, "    [^\\x%02x]", c);
     fprintf(f, "%s", OP_names[*code]);
     break;
@@ -299,11 +328,14 @@ for(;;)
     case OP_NOTEXACT:
     case OP_NOTUPTO:
     case OP_NOTMINUPTO:
-    if (isprint(c = code[3])) fprintf(f, "    [^%c]{", c);
+    case OP_NOTPOSUPTO:
+    c = code[3];
+    if (PRINTABLE(c)) fprintf(f, "    [^%c]{", c);
       else fprintf(f, "    [^\\x%02x]{", c);
     if (*code != OP_NOTEXACT) fprintf(f, "0,");
     fprintf(f, "%d}", GET2(code,1));
     if (*code == OP_NOTMINUPTO) fprintf(f, "?");
+      else if (*code == OP_NOTPOSUPTO) fprintf(f, "+");
     break;
 
     case OP_RECURSE:
@@ -363,12 +395,14 @@ for(;;)
             for (j = i+1; j < 256; j++)
               if ((ccode[j/8] & (1 << (j&7))) == 0) break;
             if (i == '-' || i == ']') fprintf(f, "\\");
-            if (isprint(i)) fprintf(f, "%c", i); else fprintf(f, "\\x%02x", i);
+            if (PRINTABLE(i)) fprintf(f, "%c", i);
+              else fprintf(f, "\\x%02x", i);
             if (--j > i)
               {
               if (j != i + 1) fprintf(f, "-");
               if (j == '-' || j == ']') fprintf(f, "\\");
-              if (isprint(j)) fprintf(f, "%c", j); else fprintf(f, "\\x%02x", j);
+              if (PRINTABLE(j)) fprintf(f, "%c", j);
+                else fprintf(f, "\\x%02x", j);
               }
             i = j;
             }
index 40912a8dcedae8a51ea3c37c8e7dae165dfd5b81..e6965812ef2df3741c10d697166461f8d4414b47 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
index 29e0d8400b887ff99960da675f6b00fca4d21953..bdc8d4df56373a57afe276338377a1678b907855 100644 (file)
@@ -43,6 +43,7 @@ Scanner::Scanner()
     input_(data_),
     skip_(NULL),
     should_skip_(false),
+    skip_repeat_(false),
     save_comments_(false),
     comments_(NULL),
     comments_offset_(0) {
@@ -53,6 +54,7 @@ Scanner::Scanner(const string& in)
     input_(data_),
     skip_(NULL),
     should_skip_(false),
+    skip_repeat_(false),
     save_comments_(false),
     comments_(NULL),
     comments_offset_(0) {
@@ -63,15 +65,31 @@ Scanner::~Scanner() {
   delete comments_;
 }
 
+void Scanner::SetSkipExpression(const char* re) {
+  delete skip_;
+  if (re != NULL) {
+    skip_ = new RE(re);
+    should_skip_ = true;
+    skip_repeat_ = true;
+    ConsumeSkip();
+  } else {
+    skip_ = NULL;
+    should_skip_ = false;
+    skip_repeat_ = false;
+  }
+}
+
 void Scanner::Skip(const char* re) {
   delete skip_;
   if (re != NULL) {
     skip_ = new RE(re);
     should_skip_ = true;
+    skip_repeat_ = false;
     ConsumeSkip();
   } else {
     skip_ = NULL;
     should_skip_ = false;
+    skip_repeat_ = false;
   }
 }
 
@@ -118,19 +136,22 @@ bool Scanner::Consume(const RE& re,
 
 // helper function to consume *skip_ and honour save_comments_
 void Scanner::ConsumeSkip() {
+  const char* start_data = input_.data();
+  while (skip_->Consume(&input_)) {
+    if (!skip_repeat_) {
+      // Only one skip allowed.
+      break;
+    }
+  }
   if (save_comments_) {
-    if (NULL == comments_) {
+    if (comments_ == NULL) {
       comments_ = new vector<StringPiece>;
     }
-    const char *start_data = input_.data();
-    skip_->Consume(&input_);
     // already pointing one past end, so no need to +1
     int length = input_.data() - start_data;
     if (length > 0) {
       comments_->push_back(StringPiece(start_data, length));
     }
-  } else {
-    skip_->Consume(&input_);
   }
 }
 
index a73b72fd2d1c575f3e1d012e390e539b58054784..ab4583ee41ca1db1a3ac5a530e4ca73e59909eed 100644 (file)
@@ -36,7 +36,7 @@
 //      Scanner scanner(input);
 //      string var;
 //      int number;
-//      scanner.Skip("\\s+");           // Skip any white space we encounter
+//      scanner.SetSkipExpression("\\s+"); // Skip any white space we encounter
 //      while (scanner.Consume("(\\w+) = (\\d+)", &var, &number)) {
 //        ...;
 //      }
@@ -90,10 +90,16 @@ class Scanner {
   // skipped.  For example, a programming language scanner would use
   // a skip RE that matches white space and comments.
   //
-  //    scanner.Skip("(\\s|//.*|/[*](.|\n)*?[*]/)*");
+  //    scanner.SetSkipExpression("\\s+|//.*|/[*](.|\n)*?[*]/");
+  //
+  // Skipping repeats as long as it succeeds.  We used to let people do
+  // this by writing "(...)*" in the regular expression, but that added
+  // up to lots of recursive calls within the pcre library, so now we
+  // control repetition explicitly via the function call API.
   //
   // You can pass NULL for "re" if you do not want any data to be skipped.
-  void Skip(const char* re);
+  void Skip(const char* re);   // DEPRECATED; does *not* repeat
+  void SetSkipExpression(const char* re);
 
   // Temporarily pause "skip"ing. This
   //   Skip("Foo"); code ; DisableSkip(); code; EnableSkip()
@@ -109,12 +115,13 @@ class Scanner {
   /***** Special wrappers around SetSkip() for some common idioms *****/
 
   // Arranges to skip whitespace, C comments, C++ comments.
-  // The overall RE is a repeated disjunction of the following REs:
+  // The overall RE is a disjunction of the following REs:
   //    \\s                     whitespace
   //    //.*\n                  C++ comment
   //    /[*](.|\n)*?[*]/        C comment (x*? means minimal repetitions of x)
+  // We get repetition via the semantics of SetSkipExpression, not by using *
   void SkipCXXComments() {
-    Skip("((\\s|//.*\n|/[*](.|\n)*?[*]/)*)");
+    SetSkipExpression("\\s|//.*\n|/[*](?:\n|.)*?[*]/");
   }
 
   void set_save_comments(bool comments) {
@@ -143,6 +150,7 @@ class Scanner {
   StringPiece   input_;         // Unprocessed input
   RE*           skip_;          // If non-NULL, RE for skipping input
   bool          should_skip_;   // If true, use skip_
+  bool          skip_repeat_;   // If true, repeat skip_ as long as it works
   bool          save_comments_; // If true, aggregate the skip expression
 
   // the skipped comments
index 756823cbb153441bf595c6d3238049baf3123e3d..d939fedeca56b08b7b74dc20a4ebd853721cd4ed 100644 (file)
 // functionality.
 
 #include <stdio.h>
+#include <string>
 #include <vector>
 #include <pcre_stringpiece.h>
 #include <pcre_scanner.h>
 
+#define FLAGS_unittest_stack_size   49152
+
 // Dies with a fatal error if the two values are not equal.
 #define CHECK_EQ(a, b)  do {                                    \
   if ( (a) != (b) ) {                                           \
@@ -116,8 +119,31 @@ static void TestScanner() {
   comments.resize(0);
 }
 
+static void TestBigComment() {
+  string input;
+  for (int i = 0; i < 1024; ++i) {
+    char buf[1024];
+    snprintf(buf, sizeof(buf), "    # Comment %d\n", i);
+    input += buf;
+  }
+  input += "name = value;\n";
+
+  Scanner s(input.c_str());
+  s.SetSkipExpression("\\s+|#.*\n");
+
+  string name;
+  string value;
+  s.Consume("(\\w+) = (\\w+);", &name, &value);
+  CHECK_EQ(name, "name");
+  CHECK_EQ(value, "value");
+}
+
+// TODO: also test scanner and big-comment in a thread with a
+//       small stack size
+
 int main(int argc, char** argv) {
   TestScanner();
+  TestBigComment();
 
   // Done
   printf("OK\n");
index 051e484aad8880e0f16683ae6dd9faa644bf24f9..87f8c6fb510a6f338899afe7594d6d2be0a8374d 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,11 @@ supporting functions. */
 #include "pcre_internal.h"
 
 
+/* Returns from set_start_bits() */
+
+enum { SSB_FAIL, SSB_DONE, SSB_CONTINUE };
+
+
 /*************************************************
 *      Set a bit and maybe its alternate case    *
 *************************************************/
@@ -72,12 +77,16 @@ if (caseless && (cd->ctypes[c] & ctype_letter) != 0)
 
 
 /*************************************************
-*          Create bitmap of starting chars       *
+*          Create bitmap of starting bytes       *
 *************************************************/
 
-/* This function scans a compiled unanchored expression and attempts to build a
-bitmap of the set of initial characters. If it can't, it returns FALSE. As time
-goes by, we may be able to get more clever at doing this.
+/* This function scans a compiled unanchored expression recursively and
+attempts to build a bitmap of the set of possible starting bytes. As time goes
+by, we may be able to get more clever at doing this. The SSB_CONTINUE return is
+useful for parenthesized groups in patterns such as (a*)b where the group
+provides some optional starting bytes but scanning must continue at the outer
+level to find at least one mandatory byte. At the outermost level, this
+function fails unless the result is SSB_DONE.
 
 Arguments:
   code         points to an expression
@@ -86,14 +95,17 @@ Arguments:
   utf8         TRUE if in UTF-8 mode
   cd           the block with char table pointers
 
-Returns:       TRUE if table built, FALSE otherwise
+Returns:       SSB_FAIL     => Failed to find any starting bytes
+               SSB_DONE     => Found mandatory starting bytes
+               SSB_CONTINUE => Found optional starting bytes
 */
 
-static BOOL
+static int
 set_start_bits(const uschar *code, uschar *start_bits, BOOL caseless,
   BOOL utf8, compile_data *cd)
 {
 register int c;
+int yield = SSB_DONE;
 
 #if 0
 /* ========================================================================= */
@@ -114,36 +126,60 @@ volatile int dummy;
 
 do
   {
-  const uschar *tcode = code + 1 + LINK_SIZE;
+  const uschar *tcode = code + (((int)*code == OP_CBRA)? 3:1) + LINK_SIZE;
   BOOL try_next = TRUE;
 
-  while (try_next)
+  while (try_next)    /* Loop for items in this branch */
     {
-    /* 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)
+    int rc;
+    switch(*tcode)
       {
-      if (!set_start_bits(tcode, start_bits, caseless, utf8, cd))
-        return FALSE;
-      try_next = FALSE;
-      }
+      /* Fail if we reach something we don't understand */
 
-    else switch(*tcode)
-      {
       default:
-      return FALSE;
+      return SSB_FAIL;
+
+      /* If we hit a bracket or a positive lookahead assertion, recurse to set
+      bits from within the subpattern. If it can't find anything, we have to
+      give up. If it finds some mandatory character(s), we are done for this
+      branch. Otherwise, carry on scanning after the subpattern. */
+
+      case OP_BRA:
+      case OP_SBRA:
+      case OP_CBRA:
+      case OP_SCBRA:
+      case OP_ONCE:
+      case OP_ASSERT:
+      rc = set_start_bits(tcode, start_bits, caseless, utf8, cd);
+      if (rc == SSB_FAIL) return SSB_FAIL;
+      if (rc == SSB_DONE) try_next = FALSE; else
+        {
+        do tcode += GET(tcode, 1); while (*tcode == OP_ALT);
+        tcode += 1 + LINK_SIZE;
+        }
+      break;
 
-      /* Skip over callout */
+      /* If we hit ALT or KET, it means we haven't found anything mandatory in
+      this branch, though we might have found something optional. For ALT, we
+      continue with the next alternative, but we have to arrange that the final
+      result from subpattern is SSB_CONTINUE rather than SSB_DONE. For KET,
+      return SSB_CONTINUE: if this is the top level, that indicates failure,
+      but after a nested subpattern, it causes scanning to continue. */
 
-      case OP_CALLOUT:
-      tcode += 2 + 2*LINK_SIZE;
+      case OP_ALT:
+      yield = SSB_CONTINUE;
+      try_next = FALSE;
       break;
 
-      /* Skip over extended extraction bracket number */
+      case OP_KET:
+      case OP_KETRMAX:
+      case OP_KETRMIN:
+      return SSB_CONTINUE;
 
-      case OP_BRANUMBER:
-      tcode += 3;
+      /* Skip over callout */
+
+      case OP_CALLOUT:
+      tcode += 2 + 2*LINK_SIZE;
       break;
 
       /* Skip over lookbehind and negative lookahead assertions */
@@ -152,7 +188,7 @@ do
       case OP_ASSERTBACK:
       case OP_ASSERTBACK_NOT:
       do tcode += GET(tcode, 1); while (*tcode == OP_ALT);
-      tcode += 1+LINK_SIZE;
+      tcode += 1 + LINK_SIZE;
       break;
 
       /* Skip over an option setting, changing the caseless flag */
@@ -166,27 +202,30 @@ do
 
       case OP_BRAZERO:
       case OP_BRAMINZERO:
-      if (!set_start_bits(++tcode, start_bits, caseless, utf8, cd))
-        return FALSE;
+      if (set_start_bits(++tcode, start_bits, caseless, utf8, cd) == SSB_FAIL)
+        return SSB_FAIL;
 /* =========================================================================
       See the comment at the head of this function concerning the next line,
       which was an old fudge for the benefit of OS/2.
       dummy = 1;
   ========================================================================= */
       do tcode += GET(tcode,1); while (*tcode == OP_ALT);
-      tcode += 1+LINK_SIZE;
+      tcode += 1 + LINK_SIZE;
       break;
 
       /* Single-char * or ? sets the bit and tries the next item */
 
       case OP_STAR:
       case OP_MINSTAR:
+      case OP_POSSTAR:
       case OP_QUERY:
       case OP_MINQUERY:
+      case OP_POSQUERY:
       set_bit(start_bits, tcode[1], caseless, cd);
       tcode += 2;
 #ifdef SUPPORT_UTF8
-      if (utf8) while ((*tcode & 0xc0) == 0x80) tcode++;
+      if (utf8 && tcode[-1] >= 0xc0)
+        tcode += _pcre_utf8_table4[tcode[-1] & 0x3f];
 #endif
       break;
 
@@ -194,10 +233,12 @@ do
 
       case OP_UPTO:
       case OP_MINUPTO:
+      case OP_POSUPTO:
       set_bit(start_bits, tcode[3], caseless, cd);
       tcode += 4;
 #ifdef SUPPORT_UTF8
-      if (utf8) while ((*tcode & 0xc0) == 0x80) tcode++;
+      if (utf8 && tcode[-1] >= 0xc0)
+        tcode += _pcre_utf8_table4[tcode[-1] & 0x3f];
 #endif
       break;
 
@@ -210,6 +251,7 @@ do
       case OP_CHARNC:
       case OP_PLUS:
       case OP_MINPLUS:
+      case OP_POSPLUS:
       set_bit(start_bits, tcode[1], caseless, cd);
       try_next = FALSE;
       break;
@@ -283,16 +325,19 @@ do
 
       case OP_TYPEUPTO:
       case OP_TYPEMINUPTO:
+      case OP_TYPEPOSUPTO:
       tcode += 2;               /* Fall through */
 
       case OP_TYPESTAR:
       case OP_TYPEMINSTAR:
+      case OP_TYPEPOSSTAR:
       case OP_TYPEQUERY:
       case OP_TYPEMINQUERY:
+      case OP_TYPEPOSQUERY:
       switch(tcode[1])
         {
         case OP_ANY:
-        return FALSE;
+        return SSB_FAIL;
 
         case OP_NOT_DIGIT:
         for (c = 0; c < 32; c++)
@@ -418,7 +463,7 @@ do
   code += GET(code, 1);   /* Advance to next branch */
   }
 while (*code == OP_ALT);
-return TRUE;
+return yield;
 }
 
 
@@ -492,8 +537,8 @@ compile_block.ctypes = tables + ctypes_offset;
 /* 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(code, start_bits, (re->options & PCRE_CASELESS) != 0,
-  (re->options & PCRE_UTF8) != 0, &compile_block)) return NULL;
+if (set_start_bits(code, start_bits, (re->options & PCRE_CASELESS) != 0,
+  (re->options & PCRE_UTF8) != 0, &compile_block) != SSB_DONE) return NULL;
 
 /* Get a pcre_extra block and a pcre_study_data block. The study data is put in
 the latter, which is pointed to by the former, which may also get additional
index 4522d981ce0ad3a228b853a99bb5bba3e6e17aa9..53690d7c9b9cbd76db1716041dc6cf6bb59dce79 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -72,9 +72,8 @@ first byte of a character, indexed by the number of additional bytes. */
 const int _pcre_utf8_table2[] = { 0,    0xc0, 0xe0, 0xf0, 0xf8, 0xfc};
 const int _pcre_utf8_table3[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01};
 
-/* Table of the number of extra characters, indexed by the first character
-masked with 0x3f. The highest number for a valid UTF-8 character is in fact
-0x3d. */
+/* Table of the number of extra bytes, indexed by the first byte masked with
+0x3f. The highest number for a valid UTF-8 first byte is in fact 0x3d. */
 
 const uschar _pcre_utf8_table4[] = {
   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
@@ -89,6 +88,7 @@ const ucp_type_table _pcre_utt[] = {
   { "Any",                 PT_ANY,  0 },
   { "Arabic",              PT_SC,   ucp_Arabic },
   { "Armenian",            PT_SC,   ucp_Armenian },
+  { "Balinese",            PT_SC,   ucp_Balinese },
   { "Bengali",             PT_SC,   ucp_Bengali },
   { "Bopomofo",            PT_SC,   ucp_Bopomofo },
   { "Braille",             PT_SC,   ucp_Braille },
@@ -104,6 +104,7 @@ const ucp_type_table _pcre_utt[] = {
   { "Common",              PT_SC,   ucp_Common },
   { "Coptic",              PT_SC,   ucp_Coptic },
   { "Cs",                  PT_PC,   ucp_Cs },
+  { "Cuneiform",           PT_SC,   ucp_Cuneiform },
   { "Cypriot",             PT_SC,   ucp_Cypriot },
   { "Cyrillic",            PT_SC,   ucp_Cyrillic },
   { "Deseret",             PT_SC,   ucp_Deseret },
@@ -146,6 +147,7 @@ const ucp_type_table _pcre_utt[] = {
   { "N",                   PT_GC,   ucp_N },
   { "Nd",                  PT_PC,   ucp_Nd },
   { "New_Tai_Lue",         PT_SC,   ucp_New_Tai_Lue },
+  { "Nko",                 PT_SC,   ucp_Nko },
   { "Nl",                  PT_PC,   ucp_Nl },
   { "No",                  PT_PC,   ucp_No },
   { "Ogham",               PT_SC,   ucp_Ogham },
@@ -158,6 +160,8 @@ const ucp_type_table _pcre_utt[] = {
   { "Pd",                  PT_PC,   ucp_Pd },
   { "Pe",                  PT_PC,   ucp_Pe },
   { "Pf",                  PT_PC,   ucp_Pf },
+  { "Phags_Pa",            PT_SC,   ucp_Phags_Pa },
+  { "Phoenician",          PT_SC,   ucp_Phoenician },
   { "Pi",                  PT_PC,   ucp_Pi },
   { "Po",                  PT_PC,   ucp_Po },
   { "Ps",                  PT_PC,   ucp_Ps },
index cd45968a4acd5956cd495f7c77933e7c69619658..00c94fccf5560948243d27cfb8bd9dcdbd896ef5 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
index f4cac1f7640140272cf9b930a0d818eb025a6802..20bb7be83231d4ede66de39c458a930f0684f02e 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -131,11 +131,11 @@ letter, return the other case. Otherwise, return -1.
 Arguments:
   c           the character value
 
-Returns:      the other case or -1 if none
+Returns:      the other case or NOTACHAR if none
 */
 
-int
-_pcre_ucp_othercase(const int c)
+unsigned int
+_pcre_ucp_othercase(const unsigned int c)
 {
 int bot = 0;
 int top = sizeof(ucp_table)/sizeof(cnode);
@@ -161,14 +161,14 @@ for (;;)
     }
   }
 
-/* Found an entry in the table. Return -1 for a range entry. Otherwise return
-the other case if there is one, else -1. */
+/* Found an entry in the table. Return NOTACHAR for a range entry. Otherwise
+return the other case if there is one, else NOTACHAR. */
 
-if ((ucp_table[mid].f0 & f0_rangeflag) != 0) return -1;
+if ((ucp_table[mid].f0 & f0_rangeflag) != 0) return NOTACHAR;
 
 offset = ucp_table[mid].f1 & f1_casemask;
 if ((offset & f1_caseneg) != 0) offset |= f1_caseneg;
-return (offset == 0)? -1 : c + offset;
+return (offset == 0)? NOTACHAR : c + offset;
 }
 
 
index c0e268af1534961b3d014bf30a77b14ae9d4c399..727fbe8d0aafd9aaaca2a31d81575a8193606275 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -79,7 +79,7 @@ for (p = string; length-- > 0; p++)
   register int ab;
   register int c = *p;
   if (c < 128) continue;
-  if ((c & 0xc0) != 0xc0) return p - string;
+  if (c < 0xc0) return p - string;
   ab = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */
   if (length < ab) return p - string;
   length -= ab;
index d640f10b349253d97d6daffe50338f07b3b8587e..9edf3e013ef4f63a9e3d736e57d2d709a11f313e 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -49,16 +49,38 @@ string that identifies the PCRE version that is in use. */
 *          Return version string                 *
 *************************************************/
 
+/* These macros are the standard way of turning unquoted text into C strings.
+They allow macros like PCRE_MAJOR to be defined without quotes, which is
+convenient for user programs that want to test its value. */
+
 #define STRING(a)  # a
 #define XSTRING(s) STRING(s)
 
+/* A problem turned up with PCRE_PRERELEASE, which is defined empty for
+production releases. Originally, it was used naively in this code:
+
+  return XSTRING(PCRE_MAJOR)
+         "." XSTRING(PCRE_MINOR)
+             XSTRING(PCRE_PRERELEASE)
+         " " XSTRING(PCRE_DATE);
+
+However, when PCRE_PRERELEASE is empty, this leads to an attempted expansion of
+STRING(). The C standard states: "If (before argument substitution) any
+argument consists of no preprocessing tokens, the behavior is undefined." It
+turns out the gcc treats this case as a single empty string - which is what we
+really want - but Visual C grumbles about the lack of an argument for the
+macro. Unfortunately, both are within their rights. To cope with both ways of
+handling this, I had resort to some messy hackery that does a test at run time.
+I could find no way of detecting that a macro is defined as an empty string at
+pre-processor time. This hack uses a standard trick for avoiding calling
+the STRING macro with an empty argument when doing the test. */
+
 PCRE_DATA_SCOPE const char *
 pcre_version(void)
 {
-return XSTRING(PCRE_MAJOR)
-       "." XSTRING(PCRE_MINOR)
-           XSTRING(PCRE_PRERELEASE)
-       " " XSTRING(PCRE_DATE);
+return (XSTRING(Z PCRE_PRERELEASE)[1] == 0)?
+  XSTRING(PCRE_MAJOR.PCRE_MINOR PCRE_DATE) :
+  XSTRING(PCRE_MAJOR.PCRE_MINOR) XSTRING(PCRE_PRERELEASE PCRE_DATE);
 }
 
 /* End of pcre_version.c */
index 0b333515f2bbc99318ff7925e0ab67d09eef0d78..57c514b78a3c7601f80197229cf56d6a418d4756 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
index f828de732e26f6ff4a726c4cdad21e129b94fe08..b75738b36c9551d836dbff8995ea58e5bf816d2e 100644 (file)
@@ -61,7 +61,7 @@ static const string empty_string;
 // If the user doesn't ask for any options, we just use this one
 static RE_Options default_options;
 
-void RE::Init(const char* pat, const RE_Options* options) {
+void RE::Init(const string& pat, const RE_Options* options) {
   pattern_ = pat;
   if (options == NULL) {
     options_ = default_options;
@@ -78,7 +78,7 @@ void RE::Init(const char* pat, const RE_Options* options) {
     // conservative in that it may treat some "simple" patterns
     // as "complex" (e.g., if the vertical bar is in a character
     // class or is escaped).  But it seems good enough.
-    if (strchr(pat, '|') == NULL) {
+    if (strchr(pat.c_str(), '|') == NULL) {
       // Simple pattern: we can use position-based checks to perform
       // fully anchored matches
       re_full_ = re_partial_;
@@ -89,12 +89,18 @@ void RE::Init(const char* pat, const RE_Options* options) {
   }
 }
 
-RE::~RE() {
+void RE::Cleanup() {
   if (re_full_ != NULL && re_full_ != re_partial_) (*pcre_free)(re_full_);
   if (re_partial_ != NULL)                         (*pcre_free)(re_partial_);
   if (error_ != &empty_string)                     delete error_;
 }
 
+
+RE::~RE() {
+  Cleanup();
+}
+
+
 pcre* RE::Compile(Anchor anchor) {
   // First, convert RE_Options into pcre options
   int pcre_options = 0;
@@ -424,6 +430,34 @@ bool RE::Extract(const StringPiece& rewrite,
   return Rewrite(out, rewrite, text, vec, matches);
 }
 
+/*static*/ string RE::QuoteMeta(const StringPiece& unquoted) {
+  string result;
+
+  // Escape any ascii character not in [A-Za-z_0-9].
+  //
+  // Note that it's legal to escape a character even if it has no
+  // special meaning in a regular expression -- so this function does
+  // that.  (This also makes it identical to the perl function of the
+  // same name; see `perldoc -f quotemeta`.)
+  for (int ii = 0; ii < unquoted.size(); ++ii) {
+    // Note that using 'isalnum' here raises the benchmark time from
+    // 32ns to 58ns:
+    if ((unquoted[ii] < 'a' || unquoted[ii] > 'z') &&
+        (unquoted[ii] < 'A' || unquoted[ii] > 'Z') &&
+        (unquoted[ii] < '0' || unquoted[ii] > '9') &&
+        unquoted[ii] != '_' &&
+        // If this is the part of a UTF8 or Latin1 character, we need
+        // to copy this byte without escaping.  Experimentally this is
+        // what works correctly with the regexp library.
+        !(unquoted[ii] & 128)) {
+      result += '\\';
+    }
+    result += unquoted[ii];
+  }
+
+  return result;
+}
+
 /***** Actual matching and rewriting code *****/
 
 int RE::TryMatch(const StringPiece& text,
@@ -809,14 +843,14 @@ bool Arg::parse_float(const char* str, int n, void* dest) {
     return parse_##name##_radix(str, n, dest, 0);                       \
   }
 
-DEFINE_INTEGER_PARSERS(short);
-DEFINE_INTEGER_PARSERS(ushort);
-DEFINE_INTEGER_PARSERS(int);
-DEFINE_INTEGER_PARSERS(uint);
-DEFINE_INTEGER_PARSERS(long);
-DEFINE_INTEGER_PARSERS(ulong);
-DEFINE_INTEGER_PARSERS(longlong);
-DEFINE_INTEGER_PARSERS(ulonglong);
+DEFINE_INTEGER_PARSERS(short)      /*                                   */
+DEFINE_INTEGER_PARSERS(ushort)     /*                                   */
+DEFINE_INTEGER_PARSERS(int)        /* Don't use semicolons after these  */
+DEFINE_INTEGER_PARSERS(uint)       /* statements because they can cause */
+DEFINE_INTEGER_PARSERS(long)       /* compiler warnings if the checking */
+DEFINE_INTEGER_PARSERS(ulong)      /* level is turned up high enough.   */
+DEFINE_INTEGER_PARSERS(longlong)   /*                                   */
+DEFINE_INTEGER_PARSERS(ulonglong)  /*                                   */
 
 #undef DEFINE_INTEGER_PARSERS
 
index 5916d86432247f5587c365a71c5fdaafff9f3d02..e3f1b716c2b315b83031bcfd43e4be20a86739ed 100644 (file)
 //    T             (where "bool T::ParseFrom(const char*, int)" exists)
 //    NULL          (the corresponding matched sub-pattern is not copied)
 //
+// CAVEAT: An optional sub-pattern that does not exist in the matched
+// string is assigned the empty string.  Therefore, the following will
+// return false (because the empty string is not a valid number):
+//    int number;
+//    pcrecpp::RE::FullMatch("abc", "[a-z]+(\\d+)?", &number);
+//
 // -----------------------------------------------------------------------
 // DO_MATCH
 //
@@ -488,8 +494,25 @@ class RE {
   // pass in a string or a "const char*" wherever an "RE" is expected.
   RE(const char* pat) { Init(pat, NULL); }
   RE(const char *pat, const RE_Options& option) { Init(pat, &option); }
-  RE(const string& pat) { Init(pat.c_str(), NULL); }
-  RE(const string& pat, const RE_Options& option) { Init(pat.c_str(), &option); }
+  RE(const string& pat) { Init(pat, NULL); }
+  RE(const string& pat, const RE_Options& option) { Init(pat, &option); }
+
+  // Copy constructor & assignment - note that these are expensive
+  // because they recompile the expression.
+  RE(const RE& re) { Init(re.pattern_, &re.options_); }
+  const RE& operator=(const RE& re) {
+    if (this != &re) {
+      Cleanup();
+
+      // This is the code that originally came from Google
+      // Init(re.pattern_.c_str(), &re.options_);
+
+      // This is the replacement from Ari Pollak
+      Init(re.pattern_, &re.options_);
+    }
+    return *this;
+  }
+
 
   ~RE();
 
@@ -589,6 +612,15 @@ class RE {
                const StringPiece &text,
                string *out) const;
 
+  // Escapes all potentially meaningful regexp characters in
+  // 'unquoted'.  The returned string, used as a regular expression,
+  // will exactly match the original string.  For example,
+  //           1.5-2.0?
+  // may become:
+  //           1\.5\-2\.0\?
+  static string QuoteMeta(const StringPiece& unquoted);
+
+
   /***** Generic matching interface *****/
 
   // Type of match (TODO: Should be restructured as part of RE_Options)
@@ -611,7 +643,8 @@ class RE {
 
  private:
 
-  void Init(const char* pattern, const RE_Options* options);
+  void Init(const string& pattern, const RE_Options* options);
+  void Cleanup();
 
   // Match against "text", filling in "vec" (up to "vecsize" * 2/3) with
   // pairs of integers for the beginning and end positions of matched
@@ -655,11 +688,6 @@ class RE {
   pcre*         re_full_;       // For full matches
   pcre*         re_partial_;    // For partial matches
   const string* error_;         // Error indicator (or points to empty string)
-
-  // Don't allow the default copy or assignment constructors --
-  // they're expensive and too easy to do by accident.
-  RE(const RE&);
-  void operator=(const RE&);
 };
 
 }   // namespace pcrecpp
index ccd876d0813fc138a83a2118a7a3f7799a90dc7d..858728cd4e2fd72485b5f3ebbdd5480abb2931df 100644 (file)
@@ -1,4 +1,6 @@
-// Copyright (c) 2005, Google Inc.
+// -*- coding: utf-8 -*-
+//
+// Copyright (c) 2005 - 2006, Google Inc.
 // All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
@@ -445,6 +447,80 @@ static void TestRecursion() {
   CHECK(re4.FullMatch(text_bad) == false);
 }
 
+// A meta-quoted string, interpreted as a pattern, should always match
+// the original unquoted string.
+static void TestQuoteMeta(string unquoted, RE_Options options = RE_Options()) {
+  string quoted = RE::QuoteMeta(unquoted);
+  RE re(quoted, options);
+  CHECK(re.FullMatch(unquoted));
+}
+
+// A string containing meaningful regexp characters, which is then meta-
+// quoted, should not generally match a string the unquoted string does.
+static void NegativeTestQuoteMeta(string unquoted, string should_not_match,
+                                  RE_Options options = RE_Options()) {
+  string quoted = RE::QuoteMeta(unquoted);
+  RE re(quoted, options);
+  CHECK(!re.FullMatch(should_not_match));
+}
+
+// Tests that quoted meta characters match their original strings,
+// and that a few things that shouldn't match indeed do not.
+static void TestQuotaMetaSimple() {
+  TestQuoteMeta("foo");
+  TestQuoteMeta("foo.bar");
+  TestQuoteMeta("foo\\.bar");
+  TestQuoteMeta("[1-9]");
+  TestQuoteMeta("1.5-2.0?");
+  TestQuoteMeta("\\d");
+  TestQuoteMeta("Who doesn't like ice cream?");
+  TestQuoteMeta("((a|b)c?d*e+[f-h]i)");
+  TestQuoteMeta("((?!)xxx).*yyy");
+  TestQuoteMeta("([");
+}
+
+static void TestQuoteMetaSimpleNegative() {
+  NegativeTestQuoteMeta("foo", "bar");
+  NegativeTestQuoteMeta("...", "bar");
+  NegativeTestQuoteMeta("\\.", ".");
+  NegativeTestQuoteMeta("\\.", "..");
+  NegativeTestQuoteMeta("(a)", "a");
+  NegativeTestQuoteMeta("(a|b)", "a");
+  NegativeTestQuoteMeta("(a|b)", "(a)");
+  NegativeTestQuoteMeta("(a|b)", "a|b");
+  NegativeTestQuoteMeta("[0-9]", "0");
+  NegativeTestQuoteMeta("[0-9]", "0-9");
+  NegativeTestQuoteMeta("[0-9]", "[9]");
+  NegativeTestQuoteMeta("((?!)xxx)", "xxx");
+}
+
+static void TestQuoteMetaLatin1() {
+  TestQuoteMeta("3\xb2 = 9");
+}
+
+static void TestQuoteMetaUtf8() {
+#ifdef SUPPORT_UTF8
+  TestQuoteMeta("Pl\xc3\xa1\x63ido Domingo", pcrecpp::UTF8());
+  TestQuoteMeta("xyz", pcrecpp::UTF8());            // No fancy utf8
+  TestQuoteMeta("\xc2\xb0", pcrecpp::UTF8());       // 2-byte utf8 (degree symbol)
+  TestQuoteMeta("27\xc2\xb0 degrees", pcrecpp::UTF8());  // As a middle character
+  TestQuoteMeta("\xe2\x80\xb3", pcrecpp::UTF8());   // 3-byte utf8 (double prime)
+  TestQuoteMeta("\xf0\x9d\x85\x9f", pcrecpp::UTF8()); // 4-byte utf8 (music note)
+  TestQuoteMeta("27\xc2\xb0"); // Interpreted as Latin-1, but should still work
+  NegativeTestQuoteMeta("27\xc2\xb0",               // 2-byte utf (degree symbol)
+                        "27\\\xc2\\\xb0",
+                        pcrecpp::UTF8());
+#endif
+}
+
+static void TestQuoteMetaAll() {
+  printf("Testing QuoteMeta\n");
+  TestQuotaMetaSimple();
+  TestQuoteMetaSimpleNegative();
+  TestQuoteMetaLatin1();
+  TestQuoteMetaUtf8();
+}
+
 //
 // Options tests contributed by
 // Giuseppe Maxia, CTO, Stardata s.r.l.
@@ -667,6 +743,35 @@ static void TestOptions() {
   Test_all_options();
 }
 
+static void TestConstructors() {
+  printf("Testing constructors\n");
+
+  RE_Options options;
+  options.set_dotall(true);
+  const char *str = "HELLO\n" "cruel\n" "world";
+
+  RE orig("HELLO.*world", options);
+  CHECK(orig.FullMatch(str));
+
+  RE copy1(orig);
+  CHECK(copy1.FullMatch(str));
+
+  RE copy2("not a match");
+  CHECK(!copy2.FullMatch(str));
+  copy2 = copy1;
+  CHECK(copy2.FullMatch(str));
+  copy2 = orig;
+  CHECK(copy2.FullMatch(str));
+
+  // Make sure when we assign to ourselves, nothing bad happens
+  orig = orig;
+  copy1 = copy1;
+  copy2 = copy2;
+  CHECK(orig.FullMatch(str));
+  CHECK(copy1.FullMatch(str));
+  CHECK(copy2.FullMatch(str));
+}
+
 int main(int argc, char** argv) {
   // Treat any flag as --help
   if (argc > 1 && argv[1][0] == '-') {
@@ -985,11 +1090,14 @@ int main(int argc, char** argv) {
   CHECK(RE("h.*o").PartialMatch("hello!"));
   CHECK(RE("((((((((((((((((((((x))))))))))))))))))))").PartialMatch("x"));
 
+  /***** other tests *****/
+
   RadixTests();
   TestReplace();
   TestExtract();
   TestConsume();
   TestFindAndConsume();
+  TestQuoteMetaAll();
   TestMatchNumberPeculiarity();
 
   // Check the pattern() accessor
@@ -1109,6 +1217,9 @@ int main(int argc, char** argv) {
     VERBOSE_TEST  = true;
   TestOptions();
 
+  // Test the constructors
+  TestConstructors();
+
   // Done
   printf("OK\n");
 
index bb308041dfe4a4035502abe4d4e2cdfcba967992..0e57e56514c553f1a1bd01d1246ab48448cf5e0f 100644 (file)
@@ -6,7 +6,7 @@
 its pattern matching. On a Unix or Win32 system it can recurse into
 directories.
 
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,7 @@ POSSIBILITY OF SUCH DAMAGE.
 
 typedef int BOOL;
 
-#define VERSION "4.3 01-Jun-2006"
+#define VERSION "4.4 29-Nov-2006"
 #define MAX_PATTERN_COUNT 100
 
 #if BUFSIZ > 8192
@@ -65,7 +65,6 @@ typedef int BOOL;
 #define MBUFTHIRD 8192
 #endif
 
-
 /* Values for the "filenames" variable, which specifies options for file name
 output. The order is important; it is assumed that a file name is wanted for
 all values greater than FN_DEFAULT. */
@@ -83,6 +82,10 @@ enum { DEE_READ, DEE_SKIP };
 #define PO_LINE_MATCH     0x0002
 #define PO_FIXED_STRINGS  0x0004
 
+/* Line ending types */
+
+enum { EL_LF, EL_CR, EL_CRLF, EL_ANY };
+
 
 
 /*************************************************
@@ -100,8 +103,7 @@ static const char *jfriedl_prefix = "";
 static const char *jfriedl_postfix = "";
 #endif
 
-static int  endlinebyte = '\n';     /* Last byte of endline sequence */
-static int  endlineextra = 0;       /* Extra bytes for endline sequence */
+static int  endlinetype;
 
 static char *colour_string = (char *)"1;31";
 static char *colour_option = NULL;
@@ -142,6 +144,7 @@ static BOOL number = FALSE;
 static BOOL only_matching = FALSE;
 static BOOL quiet = FALSE;
 static BOOL silent = FALSE;
+static BOOL utf8 = FALSE;
 
 /* Structure for options and list of them */
 
@@ -219,6 +222,16 @@ static const char *prefix[] = {
 static const char *suffix[] = {
   "", "\\b", ")$",   ")$",   "\\E", "\\E\\b", "\\E)$",   "\\E)$" };
 
+/* UTF-8 tables - used only when the newline setting is "all". */
+
+const int utf8_table3[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01};
+
+const char utf8_table4[] = {
+  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+  2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+  3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 };
+
 
 
 /*************************************************
@@ -470,6 +483,216 @@ return sys_errlist[n];
 
 
 
+/*************************************************
+*             Find end of line                   *
+*************************************************/
+
+/* The length of the endline sequence that is found is set via lenptr. This may
+be zero at the very end of the file if there is no line-ending sequence there.
+
+Arguments:
+  p         current position in line
+  endptr    end of available data
+  lenptr    where to put the length of the eol sequence
+
+Returns:    pointer to the last byte of the line
+*/
+
+static char *
+end_of_line(char *p, char *endptr, int *lenptr)
+{
+switch(endlinetype)
+  {
+  default:      /* Just in case */
+  case EL_LF:
+  while (p < endptr && *p != '\n') p++;
+  if (p < endptr)
+    {
+    *lenptr = 1;
+    return p + 1;
+    }
+  *lenptr = 0;
+  return endptr;
+
+  case EL_CR:
+  while (p < endptr && *p != '\r') p++;
+  if (p < endptr)
+    {
+    *lenptr = 1;
+    return p + 1;
+    }
+  *lenptr = 0;
+  return endptr;
+
+  case EL_CRLF:
+  for (;;)
+    {
+    while (p < endptr && *p != '\r') p++;
+    if (++p >= endptr)
+      {
+      *lenptr = 0;
+      return endptr;
+      }
+    if (*p == '\n')
+      {
+      *lenptr = 2;
+      return p + 1;
+      }
+    }
+  break;
+
+  case EL_ANY:
+  while (p < endptr)
+    {
+    int extra = 0;
+    register int c = *((unsigned char *)p);
+
+    if (utf8 && c >= 0xc0)
+      {
+      int gcii, gcss;
+      extra = utf8_table4[c & 0x3f];  /* Number of additional bytes */
+      gcss = 6*extra;
+      c = (c & utf8_table3[extra]) << gcss;
+      for (gcii = 1; gcii <= extra; gcii++)
+        {
+        gcss -= 6;
+        c |= (p[gcii] & 0x3f) << gcss;
+        }
+      }
+
+    p += 1 + extra;
+
+    switch (c)
+      {
+      case 0x0a:    /* LF */
+      case 0x0b:    /* VT */
+      case 0x0c:    /* FF */
+      *lenptr = 1;
+      return p;
+
+      case 0x0d:    /* CR */
+      if (p < endptr && *p == 0x0a)
+        {
+        *lenptr = 2;
+        p++;
+        }
+      else *lenptr = 1;
+      return p;
+
+      case 0x85:    /* NEL */
+      *lenptr = utf8? 2 : 1;
+      return p;
+
+      case 0x2028:  /* LS */
+      case 0x2029:  /* PS */
+      *lenptr = 3;
+      return p;
+
+      default:
+      break;
+      }
+    }   /* End of loop for ANY case */
+
+  *lenptr = 0;  /* Must have hit the end */
+  return endptr;
+  }     /* End of overall switch */
+}
+
+
+
+/*************************************************
+*         Find start of previous line            *
+*************************************************/
+
+/* This is called when looking back for before lines to print.
+
+Arguments:
+  p         start of the subsequent line
+  startptr  start of available data
+
+Returns:    pointer to the start of the previous line
+*/
+
+static char *
+previous_line(char *p, char *startptr)
+{
+switch(endlinetype)
+  {
+  default:      /* Just in case */
+  case EL_LF:
+  p--;
+  while (p > startptr && p[-1] != '\n') p--;
+  return p;
+
+  case EL_CR:
+  p--;
+  while (p > startptr && p[-1] != '\n') p--;
+  return p;
+
+  case EL_CRLF:
+  for (;;)
+    {
+    p -= 2;
+    while (p > startptr && p[-1] != '\n') p--;
+    if (p <= startptr + 1 || p[-2] == '\r') return p;
+    }
+  return p;   /* But control should never get here */
+
+  case EL_ANY:
+  if (*(--p) == '\n' && p > startptr && p[-1] == '\r') p--;
+  if (utf8) while ((*p & 0xc0) == 0x80) p--;
+
+  while (p > startptr)
+    {
+    register int c;
+    char *pp = p - 1;
+
+    if (utf8)
+      {
+      int extra = 0;
+      while ((*pp & 0xc0) == 0x80) pp--;
+      c = *((unsigned char *)pp);
+      if (c >= 0xc0)
+        {
+        int gcii, gcss;
+        extra = utf8_table4[c & 0x3f];  /* Number of additional bytes */
+        gcss = 6*extra;
+        c = (c & utf8_table3[extra]) << gcss;
+        for (gcii = 1; gcii <= extra; gcii++)
+          {
+          gcss -= 6;
+          c |= (pp[gcii] & 0x3f) << gcss;
+          }
+        }
+      }
+    else c = *((unsigned char *)pp);
+
+    switch (c)
+      {
+      case 0x0a:    /* LF */
+      case 0x0b:    /* VT */
+      case 0x0c:    /* FF */
+      case 0x0d:    /* CR */
+      case 0x85:    /* NEL */
+      case 0x2028:  /* LS */
+      case 0x2029:  /* PS */
+      return p;
+
+      default:
+      break;
+      }
+
+    p = pp;  /* Back one character */
+    }        /* End of loop for ANY case */
+
+  return startptr;  /* Hit start of data */
+  }     /* End of overall switch */
+}
+
+
+
+
+
 /*************************************************
 *       Print the previous "after" lines         *
 *************************************************/
@@ -495,13 +718,13 @@ if (after_context > 0 && lastmatchnumber > 0)
   int count = 0;
   while (lastmatchrestart < endptr && count++ < after_context)
     {
+    int ellength;
     char *pp = lastmatchrestart;
     if (printname != NULL) fprintf(stdout, "%s-", printname);
     if (number) fprintf(stdout, "%d-", lastmatchnumber++);
-    while (*pp != endlinebyte) pp++;
-    fwrite(lastmatchrestart, 1, pp - lastmatchrestart + (1 + endlineextra),
-      stdout);
-    lastmatchrestart = pp + 1;
+    pp = end_of_line(pp, endptr, &ellength);
+    fwrite(lastmatchrestart, 1, pp - lastmatchrestart, stdout);
+    lastmatchrestart = pp;
     }
   hyphenpending = TRUE;
   }
@@ -558,7 +781,7 @@ way, the buffer is shifted left and re-filled. */
 
 while (ptr < endptr)
   {
-  int i;
+  int i, endlinelength;
   int mrc = 0;
   BOOL match = FALSE;
   char *t = ptr;
@@ -571,11 +794,10 @@ while (ptr < endptr)
   line. In multiline mode the PCRE_FIRSTLINE option is used for compiling, so
   that any match is constrained to be in the first line. */
 
-  linelength = 0;
-  while (t < endptr && *t++ != endlinebyte) linelength++;
+  t = end_of_line(t, endptr, &endlinelength);
+  linelength = t - ptr - endlinelength;
   length = multiline? endptr - ptr : linelength;
 
-
   /* Extra processing for Jeffrey Friedl's debugging. */
 
 #ifdef JFRIEDL_DEBUG
@@ -706,13 +928,13 @@ while (ptr < endptr)
 
       if (after_context > 0 && lastmatchnumber > 0)
         {
+        int ellength;
         int linecount = 0;
         char *p = lastmatchrestart;
 
         while (p < ptr && linecount < after_context)
           {
-          while (*p != endlinebyte) p++;
-          p++;
+          p = end_of_line(p, ptr, &ellength);
           linecount++;
           }
 
@@ -725,10 +947,9 @@ while (ptr < endptr)
           char *pp = lastmatchrestart;
           if (printname != NULL) fprintf(stdout, "%s-", printname);
           if (number) fprintf(stdout, "%d-", lastmatchnumber++);
-          while (*pp != endlinebyte) pp++;
-          fwrite(lastmatchrestart, 1, pp - lastmatchrestart +
-            (1 + endlineextra), stdout);
-          lastmatchrestart = pp + 1;
+          pp = end_of_line(pp, endptr, &ellength);
+          fwrite(lastmatchrestart, 1, pp - lastmatchrestart, stdout);
+          lastmatchrestart = pp;
           }
         if (lastmatchrestart != ptr) hyphenpending = TRUE;
         }
@@ -754,8 +975,7 @@ while (ptr < endptr)
                linecount < before_context)
           {
           linecount++;
-          p--;
-          while (p > buffer && p[-1] != endlinebyte) p--;
+          p = previous_line(p, buffer);
           }
 
         if (lastmatchnumber > 0 && p > lastmatchrestart && !hyphenprinted)
@@ -763,12 +983,13 @@ while (ptr < endptr)
 
         while (p < ptr)
           {
+          int ellength;
           char *pp = p;
           if (printname != NULL) fprintf(stdout, "%s-", printname);
           if (number) fprintf(stdout, "%d-", linenumber - linecount--);
-          while (*pp != endlinebyte) pp++;
-          fwrite(p, 1, pp - p + (1 + endlineextra), stdout);
-          p = pp + 1;
+          pp = end_of_line(pp, endptr, &ellength);
+          fwrite(p, 1, pp - p, stdout);
+          p = pp;
           }
         }
 
@@ -788,11 +1009,16 @@ while (ptr < endptr)
 
       if (multiline)
         {
+        int ellength;
         char *endmatch = ptr + offsets[1];
         t = ptr;
-        while (t < endmatch) { if (*t++ == endlinebyte) linenumber++; }
-        while (endmatch < endptr && *endmatch != endlinebyte) endmatch++;
-        linelength = endmatch - ptr;
+        while (t < endmatch)
+          {
+          t = end_of_line(t, endptr, &ellength);
+          if (t <= endmatch) linenumber++; else break;
+          }
+        endmatch = end_of_line(endmatch, endptr, &ellength);
+        linelength = endmatch - ptr - ellength;
         }
 
       /*** NOTE: Use only fwrite() to output the data line, so that binary
@@ -824,9 +1050,7 @@ while (ptr < endptr)
         fprintf(stdout, "%c[00m", 0x1b);
         fwrite(ptr + offsets[1], 1, linelength - offsets[1], stdout);
         }
-      else fwrite(ptr, 1, linelength, stdout);
-
-      fprintf(stdout, "\n");
+      else fwrite(ptr, 1, linelength + endlinelength, stdout);
       }
 
     /* End of doing what has to be done for a match */
@@ -836,13 +1060,13 @@ while (ptr < endptr)
     /* Remember where the last match happened for after_context. We remember
     where we are about to restart, and that line's number. */
 
-    lastmatchrestart = ptr + linelength + 1;
+    lastmatchrestart = ptr + linelength + endlinelength;
     lastmatchnumber = linenumber + 1;
     }
 
   /* Advance to after the newline and increment the line number. */
 
-  ptr += linelength + 1;
+  ptr += linelength + endlinelength;
   linenumber++;
 
   /* If we haven't yet reached the end of the file (the buffer is full), and
@@ -1098,7 +1322,7 @@ switch(letter)
   case 'q': quiet = TRUE; break;
   case 'r': dee_action = dee_RECURSE; break;
   case 's': silent = TRUE; break;
-  case 'u': options |= PCRE_UTF8; break;
+  case 'u': options |= PCRE_UTF8; utf8 = TRUE; break;
   case 'v': invert = TRUE; break;
   case 'w': process_options |= PO_WORD_MATCH; break;
   case 'x': process_options |= PO_LINE_MATCH; break;
@@ -1231,14 +1455,16 @@ compile_pattern(char *pattern, int options, char *filename, int count)
 {
 if ((process_options & PO_FIXED_STRINGS) != 0)
   {
+  char *eop = pattern + strlen(pattern);
   char buffer[MBUFTHIRD];
   for(;;)
     {
-    char *p = strchr(pattern, endlinebyte);
-    if (p == NULL)
+    int ellength;
+    char *p = end_of_line(pattern, eop, &ellength);
+    if (ellength == 0)
       return compile_single_pattern(pattern, options, filename, count);
-    sprintf(buffer, "%.*s", p - pattern - endlineextra, pattern);
-    pattern = p + 1;
+    sprintf(buffer, "%.*s", p - pattern - ellength, pattern);
+    pattern = p;
     if (!compile_single_pattern(buffer, options, filename, count))
       return FALSE;
     }
@@ -1267,7 +1493,9 @@ char *patterns[MAX_PATTERN_COUNT];
 const char *locale_from = "--locale";
 const char *error;
 
-/* Set the default line ending value from the default in the PCRE library. */
+/* Set the default line ending value from the default in the PCRE library;
+"lf", "cr", "crlf", and "any" are supported. Anything else is treated as "lf".
+*/
 
 (void)pcre_config(PCRE_CONFIG_NEWLINE, &i);
 switch(i)
@@ -1275,6 +1503,7 @@ switch(i)
   default:                 newline = (char *)"lf"; break;
   case '\r':               newline = (char *)"cr"; break;
   case ('\r' << 8) | '\n': newline = (char *)"crlf"; break;
+  case -1:                 newline = (char *)"any"; break;
   }
 
 /* Process the options */
@@ -1565,16 +1794,22 @@ if (colour_option != NULL && strcmp(colour_option, "never") != 0)
 if (strcmp(newline, "cr") == 0 || strcmp(newline, "CR") == 0)
   {
   pcre_options |= PCRE_NEWLINE_CR;
-  endlinebyte = '\r';
+  endlinetype = EL_CR;
   }
 else if (strcmp(newline, "lf") == 0 || strcmp(newline, "LF") == 0)
   {
   pcre_options |= PCRE_NEWLINE_LF;
+  endlinetype = EL_LF;
   }
 else if (strcmp(newline, "crlf") == 0 || strcmp(newline, "CRLF") == 0)
   {
   pcre_options |= PCRE_NEWLINE_CRLF;
-  endlineextra = 1;
+  endlinetype = EL_CRLF;
+  }
+else if (strcmp(newline, "any") == 0 || strcmp(newline, "ANY") == 0)
+  {
+  pcre_options |= PCRE_NEWLINE_ANY;
+  endlinetype = EL_ANY;
   }
 else
   {
index 49e85266a7648fa990fb5c6316c5ca0a933e3072..31c7a31ab3e616c099d880e8a8c29cd8a58af243 100644 (file)
@@ -6,7 +6,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2007 University of Cambridge
+           Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -78,7 +78,7 @@ static const int eint[] = {
   REG_BADPAT,  /* unrecognized character after (?< */
   REG_BADPAT,  /* lookbehind assertion is not fixed length */
   REG_BADPAT,  /* malformed number or name after (?( */
-  REG_BADPAT,  /* conditional group containe more than two branches */
+  REG_BADPAT,  /* conditional group contains more than two branches */
   REG_BADPAT,  /* assertion expected after (?( */
   REG_BADPAT,  /* (?R or (?digits must be followed by ) */
   REG_ECTYPE,  /* unknown POSIX class name */
@@ -93,7 +93,7 @@ static const int eint[] = {
   REG_BADPAT,  /* closing ) for (?C expected */
   REG_BADPAT,  /* recursive call could loop indefinitely */
   REG_BADPAT,  /* unrecognized character after (?P */
-  REG_BADPAT,  /* syntax error after (?P */
+  REG_BADPAT,  /* syntax error in subpattern name (missing terminator) */
   REG_BADPAT,  /* two named subpatterns have the same name */
   REG_BADPAT,  /* invalid UTF-8 string */
   REG_BADPAT,  /* support for \P, \p, and \X has not been compiled */
@@ -102,7 +102,13 @@ static const int eint[] = {
   REG_BADPAT,  /* subpattern name is too long (maximum 32 characters) */
   REG_BADPAT,  /* too many named subpatterns (maximum 10,000) */
   REG_BADPAT,  /* repeated subpattern is too long */
-  REG_BADPAT   /* octal value is greater than \377 (not in UTF-8 mode) */
+  REG_BADPAT,  /* octal value is greater than \377 (not in UTF-8 mode) */
+  REG_BADPAT,  /* internal error: overran compiling workspace */
+  REG_BADPAT,  /* internal error: previously-checked referenced subpattern not found */
+  REG_BADPAT,  /* DEFINE group contains more than one branch */
+  REG_BADPAT,  /* repeating a DEFINE group is not allowed */
+  REG_INVARG,  /* inconsistent NEWLINE options */
+  REG_BADPAT   /* \g is not followed followed by an (optionally braced) non-zero number */
 };
 
 /* Table of texts corresponding to POSIX error codes */
index 04782de275647dfb749e20dc6dbdfb1cac01f8a7..31ee03749c44f9f2c0fedd857c089c2503e479e8 100644 (file)
@@ -9,7 +9,7 @@
 Compatible Regular Expression library. It defines the things POSIX says should
 be there. I hope.
 
-            Copyright (c) 1997-2007 University of Cambridge
+            Copyright (c) 1997-2006 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
index 431378c6dc8c82ecbc4be0938e9984b3deca0ff0..d5249fa18f1780e7b595f909aa447e37d28bb294 100644 (file)
@@ -44,10 +44,29 @@ POSSIBILITY OF SUCH DAMAGE.
 #include <locale.h>
 #include <errno.h>
 
-#ifndef _WIN32
-#include <sys/resource.h>
+
+/* A number of things vary for Windows builds. Originally, pcretest opened its
+input and output without "b"; then I was told that "b" was needed in some
+environments, so it was added for release 5.0 to both the input and output. (It
+makes no difference on Unix-like systems.) Later I was told that it is wrong
+for the input on Windows. I've now abstracted the modes into two macros that
+are set here, to make it easier to fiddle with them, and removed "b" from the
+input mode under Windows. */
+
+#if defined(_WIN32) || defined(WIN32)
+#include <io.h>                /* For _setmode() */
+#include <fcntl.h>             /* For _O_BINARY */
+#define INPUT_MODE   "r"
+#define OUTPUT_MODE  "wb"
+
+#else
+#include <sys/time.h>          /* These two includes are needed */
+#include <sys/resource.h>      /* for setrlimit(). */
+#define INPUT_MODE   "rb"
+#define OUTPUT_MODE  "wb"
 #endif
 
+
 #define PCRE_SPY        /* For Win32 build, import data, not export */
 
 /* We include pcre_internal.h because we need the internal info for displaying
@@ -74,10 +93,18 @@ symbols to prevent clashes. */
 
 /* We also need the pcre_printint() function for printing out compiled
 patterns. This function is in a separate file so that it can be included in
-pcre_compile.c when that module is compiled with debugging enabled. */
+pcre_compile.c when that module is compiled with debugging enabled.
+
+The definition of the macro PRINTABLE, which determines whether to print an
+output character as-is or as a hex value when showing compiled patterns, is
+contained in this file. We uses it here also, in cases when the locale has not
+been explicitly changed, so as to get consistent output from systems that
+differ in their output from isprint() even in the "C" locale. */
 
 #include "pcre_printint.src"
 
+#define PRINTHEX(c) (locale_set? isprint(c) : PRINTABLE(c))
+
 
 /* It is possible to compile this test program without including support for
 testing the POSIX interface, though this is not available via the standard
@@ -103,6 +130,8 @@ function (define NOINFOCHECK). */
 #endif
 #endif
 
+/* This is the default loop count for timing. */
+
 #define LOOPREPEAT 500000
 
 /* Static variables */
@@ -114,6 +143,7 @@ static int callout_extra;
 static int callout_fail_count;
 static int callout_fail_id;
 static int first_callout;
+static int locale_set = 0;
 static int show_malloc;
 static int use_utf8;
 static size_t gotten_store;
@@ -157,6 +187,7 @@ uschar *here = start;
 for (;;)
   {
   int rlen = buffer_size - (here - buffer);
+
   if (rlen > 1000)
     {
     int dlen;
@@ -213,7 +244,7 @@ return NULL;  /* Control never gets here */
 
 /* We don't use strtoul() because SunOS4 doesn't have it. Rather than mess
 around with conditional compilation, just do the job by hand. It is only used
-for unpicking the -o argument, so just keep it simple.
+for unpicking arguments, so just keep it simple.
 
 Arguments:
   str           string to be converted
@@ -311,6 +342,8 @@ Arguments:
 Returns:     number of characters placed in the buffer
 */
 
+#if !defined NOUTF8
+
 static int
 ord2utf8(int cvalue, uschar *utf8bytes)
 {
@@ -327,6 +360,8 @@ for (j = i; j > 0; j--)
 return i + 1;
 }
 
+#endif
+
 
 
 /*************************************************
@@ -353,16 +388,19 @@ while (length-- > 0)
       {
       length -= rc - 1;
       p += rc;
-      if (c < 256 && isprint(c))
+      if (PRINTHEX(c))
         {
         if (f != NULL) fprintf(f, "%c", c);
         yield++;
         }
       else
         {
-        int n;
-        if (f != NULL) fprintf(f, "\\x{%02x}%n", c, &n);
-        yield += n;
+        int n = 4;
+        if (f != NULL) fprintf(f, "\\x{%02x}", c);
+        yield += (n <= 0x000000ff)? 2 :
+                 (n <= 0x00000fff)? 3 :
+                 (n <= 0x0000ffff)? 4 :
+                 (n <= 0x000fffff)? 5 : 6;
         }
       continue;
       }
@@ -371,7 +409,8 @@ while (length-- > 0)
 
    /* Not UTF-8, or malformed UTF-8  */
 
-  if (isprint(c = *(p++)))
+  c = *p++;
+  if (PRINTHEX(c))
     {
     if (f != NULL) fprintf(f, "%c", c);
     yield++;
@@ -614,7 +653,7 @@ return count;
 *************************************************/
 
 /* This is used both at compile and run-time to check for <xxx> escapes, where
-xxx is LF, CR, or CRLF. Print a message and return 0 if there is no match.
+xxx is LF, CR, CRLF, or ANY. Print a message and return 0 if there is no match.
 
 Arguments:
   p           points after the leading '<'
@@ -629,12 +668,45 @@ check_newline(uschar *p, FILE *f)
 if (strncmp((char *)p, "cr>", 3) == 0) return PCRE_NEWLINE_CR;
 if (strncmp((char *)p, "lf>", 3) == 0) return PCRE_NEWLINE_LF;
 if (strncmp((char *)p, "crlf>", 5) == 0) return PCRE_NEWLINE_CRLF;
+if (strncmp((char *)p, "any>", 4) == 0) return PCRE_NEWLINE_ANY;
 fprintf(f, "Unknown newline type at: <%s\n", p);
 return 0;
 }
 
 
 
+/*************************************************
+*             Usage function                     *
+*************************************************/
+
+static void
+usage(void)
+{
+printf("Usage:     pcretest [options] [<input> [<output>]]\n");
+printf("  -b       show compiled code (bytecode)\n");
+printf("  -C       show PCRE compile-time options and exit\n");
+printf("  -d       debug: show compiled code and information (-b and -i)\n");
+#if !defined NODFA
+printf("  -dfa     force DFA matching for all subjects\n");
+#endif
+printf("  -help    show usage information\n");
+printf("  -i       show information about compiled patterns\n"
+       "  -m       output memory used information\n"
+       "  -o <n>   set size of offsets vector to <n>\n");
+#if !defined NOPOSIX
+printf("  -p       use POSIX interface\n");
+#endif
+printf("  -q       quiet: do not output PCRE version number at start\n");
+printf("  -S <n>   set stack size to <n> megabytes\n");
+printf("  -s       output store (memory) used information\n"
+       "  -t       time compilation and execution\n");
+printf("  -t <n>   time compilation and execution, repeating <n> times\n");
+printf("  -tm      time execution (matching) only\n");
+printf("  -tm <n>  time execution (matching) only, repeating <n> times\n");
+}
+
+
+
 /*************************************************
 *                Main Program                    *
 *************************************************/
@@ -650,6 +722,7 @@ int options = 0;
 int study_options = 0;
 int op = 1;
 int timeit = 0;
+int timeitm = 0;
 int showinfo = 0;
 int showstore = 0;
 int quiet = 0;
@@ -681,16 +754,19 @@ buffer = (unsigned char *)malloc(buffer_size);
 dbuffer = (unsigned char *)malloc(buffer_size);
 pbuffer = (unsigned char *)malloc(buffer_size);
 
-/* The outfile variable is static so that new_malloc can use it. The _setmode()
-stuff is some magic that I don't understand, but which apparently does good
-things in Windows. It's related to line terminations.  */
-
-#if defined(_WIN32) || defined(WIN32)
-_setmode( _fileno( stdout ), 0x8000 );
-#endif  /* defined(_WIN32) || defined(WIN32) */
+/* The outfile variable is static so that new_malloc can use it. */
 
 outfile = stdout;
 
+/* The following  _setmode() stuff is some Windows magic that tells its runtime
+library to translate CRLF into a single LF character. At least, that's what
+I've been told: never having used Windows I take this all on trust. Originally
+it set 0x8000, but then I was advised that _O_BINARY was better. */
+
+#if defined(_WIN32) || defined(WIN32)
+_setmode( _fileno( stdout ), _O_BINARY );
+#endif
+
 /* Scan options */
 
 while (argc > 1 && argv[op][0] == '-')
@@ -699,8 +775,8 @@ while (argc > 1 && argv[op][0] == '-')
 
   if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0)
     showstore = 1;
-  else if (strcmp(argv[op], "-t") == 0) timeit = 1;
   else if (strcmp(argv[op], "-q") == 0) quiet = 1;
+  else if (strcmp(argv[op], "-b") == 0) debug = 1;
   else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
   else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1;
 #if !defined NODFA
@@ -713,11 +789,25 @@ while (argc > 1 && argv[op][0] == '-')
     op++;
     argc--;
     }
+  else if (strcmp(argv[op], "-t") == 0 || strcmp(argv[op], "-tm") == 0)
+    {
+    int both = argv[op][2] == 0;
+    int temp;
+    if (argc > 2 && (temp = get_value((unsigned char *)argv[op+1], &endptr),
+                     *endptr == 0))
+      {
+      timeitm = temp;
+      op++;
+      argc--;
+      }
+    else timeitm = LOOPREPEAT;
+    if (both) timeit = timeitm;
+    }
   else if (strcmp(argv[op], "-S") == 0 && argc > 2 &&
       ((stack_size = get_value((unsigned char *)argv[op+1], &endptr)),
         *endptr == 0))
     {
-#ifdef _WIN32
+#if defined(_WIN32) || defined(WIN32)
     printf("PCRE: -S not supported on this OS\n");
     exit(1);
 #else
@@ -749,7 +839,8 @@ while (argc > 1 && argv[op][0] == '-')
     printf("  %sUnicode properties support\n", rc? "" : "No ");
     (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);
     printf("  Newline sequence is %s\n", (rc == '\r')? "CR" :
-      (rc == '\n')? "LF" : "CRLF");
+      (rc == '\n')? "LF" : (rc == ('\r'<<8 | '\n'))? "CRLF" :
+      (rc == -1)? "ANY" : "???");
     (void)pcre_config(PCRE_CONFIG_LINK_SIZE, &rc);
     printf("  Internal link size = %d\n", rc);
     (void)pcre_config(PCRE_CONFIG_POSIX_MALLOC_THRESHOLD, &rc);
@@ -762,24 +853,16 @@ while (argc > 1 && argv[op][0] == '-')
     printf("  Match recursion uses %s\n", rc? "stack" : "heap");
     exit(0);
     }
+  else if (strcmp(argv[op], "-help") == 0 ||
+           strcmp(argv[op], "--help") == 0)
+    {
+    usage();
+    goto EXIT;
+    }
   else
     {
     printf("** Unknown or malformed option %s\n", argv[op]);
-    printf("Usage:   pcretest [options] [<input> [<output>]]\n");
-    printf("  -C     show PCRE compile-time options and exit\n");
-    printf("  -d     debug: show compiled code; implies -i\n");
-#if !defined NODFA
-    printf("  -dfa   force DFA matching for all subjects\n");
-#endif
-    printf("  -i     show information about compiled pattern\n"
-           "  -m     output memory used information\n"
-           "  -o <n> set size of offsets vector to <n>\n");
-#if !defined NOPOSIX
-    printf("  -p     use POSIX interface\n");
-#endif
-    printf("  -S <n> set stack size to <n> megabytes\n");
-    printf("  -s     output store (memory) used information\n"
-           "  -t     time compilation and execution\n");
+    usage();
     yield = 1;
     goto EXIT;
     }
@@ -803,7 +886,7 @@ if (offsets == NULL)
 
 if (argc > 1)
   {
-  infile = fopen(argv[op], "rb");
+  infile = fopen(argv[op], INPUT_MODE);
   if (infile == NULL)
     {
     printf("** Failed to open %s\n", argv[op]);
@@ -814,7 +897,7 @@ if (argc > 1)
 
 if (argc > 2)
   {
-  outfile = fopen(argv[op+1], "wb");
+  outfile = fopen(argv[op+1], OUTPUT_MODE);
   if (outfile == NULL)
     {
     printf("** Failed to open %s\n", argv[op+1]);
@@ -859,7 +942,7 @@ while (!done)
   int do_showinfo = showinfo;
   int do_showrest = 0;
   int do_flip = 0;
-  int erroroffset, len, delimiter;
+  int erroroffset, len, delimiter, poffset;
 
   use_utf8 = 0;
 
@@ -969,6 +1052,7 @@ while (!done)
     }
 
   pp = p;
+  poffset = p - buffer;
 
   for(;;)
     {
@@ -989,6 +1073,11 @@ while (!done)
     if (infile != stdin) fprintf(outfile, "%s", (char *)pp);
     }
 
+  /* The buffer may have moved while being extended; reset the start of data
+  pointer to the correct relative point in the buffer. */
+
+  p = buffer + poffset;
+
   /* If the first character after the delimiter is backslash, make
   the pattern end with backslash. This is purely to provide a way
   of testing for the error message when a pattern ends with backslash. */
@@ -1020,6 +1109,7 @@ while (!done)
 
       case '+': do_showrest = 1; break;
       case 'A': options |= PCRE_ANCHORED; break;
+      case 'B': do_debug = 1; break;
       case 'C': options |= PCRE_AUTO_CALLOUT; break;
       case 'D': do_debug = do_showinfo = 1; break;
       case 'E': options |= PCRE_DOLLAR_ENDONLY; break;
@@ -1042,14 +1132,16 @@ while (!done)
 
       case 'L':
       ppp = pp;
-      /* The '\r' test here is so that it works on Windows */
-      while (*ppp != '\n' && *ppp != '\r' && *ppp != ' ') ppp++;
+      /* The '\r' test here is so that it works on Windows. */
+      /* The '0' test is just in case this is an unterminated line. */
+      while (*ppp != 0 && *ppp != '\n' && *ppp != '\r' && *ppp != ' ') ppp++;
       *ppp = 0;
       if (setlocale(LC_CTYPE, (const char *)pp) == NULL)
         {
         fprintf(outfile, "** Failed to set locale \"%s\"\n", pp);
         goto SKIP_DATA;
         }
+      locale_set = 1;
       tables = pcre_maketables();
       pp = ppp;
       break;
@@ -1116,19 +1208,19 @@ while (!done)
 #endif  /* !defined NOPOSIX */
 
     {
-    if (timeit)
+    if (timeit > 0)
       {
       register int i;
       clock_t time_taken;
       clock_t start_time = clock();
-      for (i = 0; i < LOOPREPEAT; i++)
+      for (i = 0; i < timeit; i++)
         {
         re = pcre_compile((char *)p, options, &error, &erroroffset, tables);
         if (re != NULL) free(re);
         }
       time_taken = clock() - start_time;
-      fprintf(outfile, "Compile time %.3f milliseconds\n",
-        (((double)time_taken * 1000.0) / (double)LOOPREPEAT) /
+      fprintf(outfile, "Compile time %.4f milliseconds\n",
+        (((double)time_taken * 1000.0) / (double)timeit) /
           (double)CLOCKS_PER_SEC);
       }
 
@@ -1180,17 +1272,17 @@ while (!done)
 
     if (do_study)
       {
-      if (timeit)
+      if (timeit > 0)
         {
         register int i;
         clock_t time_taken;
         clock_t start_time = clock();
-        for (i = 0; i < LOOPREPEAT; i++)
+        for (i = 0; i < timeit; i++)
           extra = pcre_study(re, study_options, &error);
         time_taken = clock() - start_time;
         if (extra != NULL) free(extra);
-        fprintf(outfile, "  Study time %.3f milliseconds\n",
-          (((double)time_taken * 1000.0) / (double)LOOPREPEAT) /
+        fprintf(outfile, "  Study time %.4f milliseconds\n",
+          (((double)time_taken * 1000.0) / (double)timeit) /
             (double)CLOCKS_PER_SEC);
         }
       extra = pcre_study(re, study_options, &error);
@@ -1233,6 +1325,12 @@ while (!done)
 
     SHOW_INFO:
 
+    if (do_debug)
+      {
+      fprintf(outfile, "------------------------------------------------------------------\n");
+      pcre_printint(re, outfile);
+      }
+
     if (do_showinfo)
       {
       unsigned long int get_options, all_options;
@@ -1243,12 +1341,6 @@ while (!done)
       int nameentrysize, namecount;
       const uschar *nametable;
 
-      if (do_debug)
-        {
-        fprintf(outfile, "------------------------------------------------------------------\n");
-        pcre_printint(re, outfile);
-        }
-
       new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
       new_info(re, NULL, PCRE_INFO_SIZE, &size);
       new_info(re, NULL, PCRE_INFO_CAPTURECOUNT, &count);
@@ -1327,7 +1419,7 @@ while (!done)
           ((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : "",
           ((get_options & PCRE_DUPNAMES) != 0)? " dupnames" : "");
 
-      switch (get_options & PCRE_NEWLINE_CRLF)
+      switch (get_options & PCRE_NEWLINE_BITS)
         {
         case PCRE_NEWLINE_CR:
         fprintf(outfile, "Forced newline sequence: CR\n");
@@ -1341,6 +1433,10 @@ while (!done)
         fprintf(outfile, "Forced newline sequence: CRLF\n");
         break;
 
+        case PCRE_NEWLINE_ANY:
+        fprintf(outfile, "Forced newline sequence: ANY\n");
+        break;
+
         default:
         break;
         }
@@ -1358,7 +1454,7 @@ while (!done)
         int ch = first_char & 255;
         const char *caseless = ((first_char & REQ_CASELESS) == 0)?
           "" : " (caseless)";
-        if (isprint(ch))
+        if (PRINTHEX(ch))
           fprintf(outfile, "First char = \'%c\'%s\n", ch, caseless);
         else
           fprintf(outfile, "First char = %d%s\n", ch, caseless);
@@ -1373,7 +1469,7 @@ while (!done)
         int ch = need_char & 255;
         const char *caseless = ((need_char & REQ_CASELESS) == 0)?
           "" : " (caseless)";
-        if (isprint(ch))
+        if (PRINTHEX(ch))
           fprintf(outfile, "Need char = \'%c\'%s\n", ch, caseless);
         else
           fprintf(outfile, "Need char = %d%s\n", ch, caseless);
@@ -1409,7 +1505,7 @@ while (!done)
                   fprintf(outfile, "\n  ");
                   c = 2;
                   }
-                if (isprint(i) && i != ' ')
+                if (PRINTHEX(i) && i != ' ')
                   {
                   fprintf(outfile, "%c ", i);
                   c += 2;
@@ -1468,6 +1564,7 @@ while (!done)
                 strerror(errno));
               }
             else fprintf(outfile, "Study data written to %s\n", to_file);
+
             }
           }
         fclose(f);
@@ -1866,7 +1963,7 @@ while (!done)
 
     for (;; gmatched++)    /* Loop for /g or /G */
       {
-      if (timeit)
+      if (timeitm > 0)
         {
         register int i;
         clock_t time_taken;
@@ -1876,7 +1973,7 @@ while (!done)
         if (all_use_dfa || use_dfa)
           {
           int workspace[1000];
-          for (i = 0; i < LOOPREPEAT; i++)
+          for (i = 0; i < timeitm; i++)
             count = pcre_dfa_exec(re, NULL, (char *)bptr, len, start_offset,
               options | g_notempty, use_offsets, use_size_offsets, workspace,
               sizeof(workspace)/sizeof(int));
@@ -1884,13 +1981,13 @@ while (!done)
         else
 #endif
 
-        for (i = 0; i < LOOPREPEAT; i++)
+        for (i = 0; i < timeitm; i++)
           count = pcre_exec(re, extra, (char *)bptr, len,
             start_offset, options | g_notempty, use_offsets, use_size_offsets);
 
         time_taken = clock() - start_time;
-        fprintf(outfile, "Execute time %.3f milliseconds\n",
-          (((double)time_taken * 1000.0) / (double)LOOPREPEAT) /
+        fprintf(outfile, "Execute time %.4f milliseconds\n",
+          (((double)time_taken * 1000.0) / (double)timeitm) /
             (double)CLOCKS_PER_SEC);
         }
 
@@ -1966,7 +2063,28 @@ while (!done)
 
       if (count >= 0)
         {
-        int i;
+        int i, maxcount;
+
+#if !defined NODFA
+        if (all_use_dfa || use_dfa) maxcount = use_size_offsets/2; else
+#endif
+          maxcount = use_size_offsets/3;
+
+        /* This is a check against a lunatic return value. */
+
+        if (count > maxcount)
+          {
+          fprintf(outfile,
+            "** PCRE error: returned count %d is too big for offset size %d\n",
+            count, use_size_offsets);
+          count = use_size_offsets/3;
+          if (do_g || do_G)
+            {
+            fprintf(outfile, "** /%c loop abandoned\n", do_g? 'g' : 'G');
+            do_g = do_G = FALSE;        /* Break g/G loop */
+            }
+          }
+
         for (i = 0; i < count * 2; i += 2)
           {
           if (use_offsets[i] < 0)
@@ -2165,6 +2283,7 @@ while (!done)
     {
     new_free((void *)tables);
     setlocale(LC_CTYPE, "C");
+    locale_set = 0;
     }
   }
 
index 0ded82475cd536b8bede5e9120f0eac7a534c966..ed33f86d4a3ba9ecec6c7e1bc757095d52d45629 100644 (file)
@@ -593,7 +593,8 @@ aaaaa2
 ffffffffff
 
 This is a line before the binary zero.
-This line contains a binary zero here >This is a line after the binary zero.
+This line contains a binary zero here >\0< for testing.
+This is a line after the binary zero.
 
 ABOVE the elephant 
 ABOVE
diff --git a/ext/pcre/pcrelib/testdata/grepinput8 b/ext/pcre/pcrelib/testdata/grepinput8
new file mode 100644 (file)
index 0000000..e8ddc27
--- /dev/null
@@ -0,0 +1,12 @@
+X one
+X two\vX three\fX four
+X five
+X six
+X seven\85X eight
X nine
X ten
+
+Before 111
+Before 222
Before 333\85Match
+After 111
+After 222
After 333
+And so on and so on
+And so on and so on
index 1dd375b65a2b64883c44d127af891110bd0983b9..804c33fc3f1b65149575416a0cd81905eefaf372 100644 (file)
@@ -75,7 +75,14 @@ RC=1
 39:nineteen
 40:twenty
 41:
-42:This is the last line of this file.
+42:Here follows some CR/LF/CRLF test data.
+43:
+44:abc
+def
+45:ghi
+46:jkl
+47:
+48:This is the last line of this file.
 ---------------------------- Test 12 -----------------------------
 Pattern
 ---------------------------- Test 13 -----------------------------
@@ -157,7 +164,8 @@ eighteen
 nineteen
 twenty
 
-This is the last line of this file.
+Here follows some CR/LF/CRLF test data.
+
 ---------------------------- Test 25 -----------------------------
 15-
 16-complete pair
@@ -207,7 +215,8 @@ eighteen
 nineteen
 twenty
 
-This is the last line of this file.
+Here follows some CR/LF/CRLF test data.
+
 ---------------------------- Test 27 -----------------------------
 four
 five
@@ -227,7 +236,10 @@ eighteen
 nineteen
 twenty
 
-This is the last line of this file.
+Here follows some CR/LF/CRLF test data.
+
+abc
+def
 ---------------------------- Test 28 -----------------------------
 14-of lines all by themselves.
 15-
@@ -279,7 +291,12 @@ eighteen
 nineteen
 twenty
 
-This is the last line of this file.
+Here follows some CR/LF/CRLF test data.
+
+abc
+def
+ghi
+jkl
 ---------------------------- Test 30 -----------------------------
 ./testdata/grepinput-4-features should be added at the end, because some of the tests involve the
 ./testdata/grepinput-5-output of line numbers, and we don't want these to change.
@@ -329,6 +346,7 @@ RC=2
 RC=0
 ---------------------------- Test 36 -----------------------------
 ./testdata/grepinputx
+./testdata/grepinput8
 RC=0
 ---------------------------- Test 37 -----------------------------
 aaaaa0
@@ -342,10 +360,13 @@ pcregrep: check your regex for nested unlimited loops
 pcregrep: pcre_exec() error -8 while matching this line:
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 ---------------------------- Test 38 ------------------------------
-This line contains a binary zero here >---------------------------- Test 39 ------------------------------
+This line contains a binary zero here >\0< for testing.
+---------------------------- Test 39 ------------------------------
 This is a line before the binary zero.
-This line contains a binary zero here >---------------------------- Test 40 ------------------------------
-This line contains a binary zero here >This is a line after the binary zero.
+This line contains a binary zero here >\0< for testing.
+---------------------------- Test 40 ------------------------------
+This line contains a binary zero here >\0< for testing.
+This is a line after the binary zero.
 ---------------------------- Test 41 ------------------------------
 before the binary zero
 after the binary zero
@@ -378,3 +399,31 @@ ABOVE the elephant
 AB.VE
 AB.VE the turtle
 PUT NEW DATA ABOVE THIS LINE.
+---------------------------- Test 49 ------------------------------
+abc
+def
+ghi
+jkl
+---------------------------- Test 50 ------------------------------
+def
+---------------------------- Test 51 ------------------------------
+ghi
+jkl
+
+This is the last line of this file.
+---------------------------- Test 52 ------------------------------
+def
+ghi
+jkl
+
+This is the last line of this file.
+---------------------------- Test 53 ------------------------------
+ghi
+jkl
+
+This is the last line of this file.
+---------------------------- Test 54 ------------------------------
+44:abc
+45:def
+46:ghi
+47:jkl
diff --git a/ext/pcre/pcrelib/testdata/grepoutput8 b/ext/pcre/pcrelib/testdata/grepoutput8
new file mode 100644 (file)
index 0000000..6317355
--- /dev/null
@@ -0,0 +1,11 @@
+---------------------------- Test U1 ------------------------------
+1:X one
+2:X two\v3:X three\f4:X four
+5:X five
+6:X six
+7:X seven\858:X eight
9:X nine
10:X ten
+---------------------------- Test U2 ------------------------------
+12-Before 111
+13-Before 222
14-Before 333\8515:Match
+16-After 111
+17-After 222
18-After 333
index 6cb400bd7009aed6822bf8d052b2802650a1bed3..d8ef12bc429b7f2294b8488afa5ad88a4d991cdc 100644 (file)
     abc
 
 /^a    b
-  
-  \f  c/x
+    \f  c/x
     abc
 
 /^(a|)\1*b/
 /{4,5a}bc/
     {4,5a}bc
 
-/^a.b/
-    a\rb
-    *** Failers
-    a\nb
-
 /abc$/
     abc
     abc\n
 /(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\12\123/
     abcdefghijk\12S
 
-/ab\gdef/
-    abgdef
+/ab\hdef/
+    abhdef
 
 /a{0}bc/
     bc
     cdaccb
 
 /^(?:a?b?)*$/
+    \
+    a
+    ab
+    aaa   
     *** Failers
     dbcb
     a--
+    aa-- 
 
 /((?s)^a(.))((?m)^b$)/
     a\nb\nc\n
     a,b]
     [a,b,c]  
 
+/(?-x: )/x
+    A\x20B
+    
+"(?x)(?-x: \s*#\s*)"
+    A # B
+    ** Failers
+    #  
+
+"(?x-is)(?:(?-ixs) \s*#\s*) include"
+    A #include
+    ** Failers
+    A#include  
+    A #Include
+
+/a*b*\w/
+    aaabbbb
+    aaaa
+    a
+
+/a*b?\w/
+    aaabbbb
+    aaaa
+    a
+
+/a*b{0,4}\w/
+    aaabbbb
+    aaaa
+    a
+
+/a*b{0,}\w/
+    aaabbbb
+    aaaa
+    a
+    
+/a*\d*\w/
+    0a
+    a 
+    
+/a*b *\w/x
+    a 
+
+/a*b#comment
+  *\w/x
+    a 
+
+/a* b *\w/x
+    a 
+
+/^\w+=.*(\\\n.*)*/
+    abc=xyz\\\npqr
+
+/(?=(\w+))\1:/
+    abcd:
+
+/^(?=(\w+))\1:/
+    abcd:
+
+/^\Eabc/
+    abc
+    
+/^[\Eabc]/
+    a
+    ** Failers 
+    E 
+    
+/^[a-\Ec]/
+    b
+    ** Failers
+    -
+    E    
+
+/^[a\E\E-\Ec]/
+    b
+    ** Failers
+    -
+    E    
+
+/^[\E\Qa\E-\Qz\E]+/
+    b
+    ** Failers
+    -  
+    
+/^[a\Q]bc\E]/
+    a
+    ]
+    c
+    
+/^[a-\Q\E]/
+    a
+    -     
+
+/^(a()*)*/
+    aaaa
+
+/^(?:a(?:(?:))*)*/
+    aaaa
+
+/^(a()+)+/
+    aaaa
+
+/^(?:a(?:(?:))+)+/
+    aaaa
+
+/(a){0,3}(?(1)b|(c|))*D/
+    abbD
+    ccccD
+    D  
+
+/(a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/(?>a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/(?:a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/\Z/g
+  abc\n
+  
+/^(?s)(?>.*)(?<!\n)/
+  abc
+  abc\n  
+
+/^(?![^\n]*\n\z)/
+  abc
+  abc\n 
+  
+/\z(?<!\n)/
+  abc
+  abc\n  
+
 / End of testinput1 /
index 0a87466ae7ca5a1dd1cc502c08f073cf617c4612..bb21f4819b838f0aeccb59c823269851bd41791f 100644 (file)
@@ -1,6 +1,6 @@
-/(a)b|/
+/(a)b|/I
 
-/abc/
+/abc/I
     abc
     defabc
     \Aabc
@@ -8,29 +8,29 @@
     \Adefabc
     ABC
 
-/^abc/
+/^abc/I
     abc
     \Aabc
     *** Failers
     defabc
     \Adefabc
 
-/a+bc/
+/a+bc/I
 
-/a*bc/
+/a*bc/I
 
-/a{3}bc/
+/a{3}bc/I
 
-/(abc|a+z)/
+/(abc|a+z)/I
 
-/^abc$/
+/^abc$/I
     abc
     *** Failers
     def\nabc
 
-/ab\gdef/X
+/ab\hdef/X
 
-/(?X)ab\gdef/X
+/(?X)ab\hdef/X
 
 /x{5,4}/
 
 
 /(?z)abc/
 
-/.*b/
+/.*b/I
 
-/.*?b/
+/.*?b/I
 
-/cat|dog|elephant/
+/cat|dog|elephant/I
     this sentence eventually mentions a cat
     this sentences rambles on and on for a while and then reaches elephant
 
-/cat|dog|elephant/S
+/cat|dog|elephant/IS
     this sentence eventually mentions a cat
     this sentences rambles on and on for a while and then reaches elephant
 
-/cat|dog|elephant/iS
+/cat|dog|elephant/IiS
     this sentence eventually mentions a CAT cat
     this sentences rambles on and on for a while to elephant ElePhant
 
-/a|[bcd]/S
+/a|[bcd]/IS
 
-/(a|[^\dZ])/S
+/(a|[^\dZ])/IS
 
-/(a|b)*[\s]/S
+/(a|b)*[\s]/IS
 
 /(ab\2)/
 
 /{4,5}abc/
 
-/(a)(b)(c)\2/
+/(a)(b)(c)\2/I
     abcb
     \O0abcb
     \O3abcb
@@ -84,7 +84,7 @@
     \O9abcb
     \O12abcb 
 
-/(a)bc|(a)(b)\2/
+/(a)bc|(a)(b)\2/I
     abc
     \O0abc
     \O3abc
@@ -96,7 +96,7 @@
     \O9aba
     \O12aba
 
-/abc$/E
+/abc$/IE
     abc
     *** Failers
     abc\n
 
 /(a)(b)(c)(d)(e)\6/
 
-/the quick brown fox/
+/the quick brown fox/I
     the quick brown fox
     this is a line with the quick brown fox
 
-/the quick brown fox/A
+/the quick brown fox/IA
     the quick brown fox
     *** Failers
     this is a line with the quick brown fox
 
 /ab(?z)cd/
 
-/^abc|def/
+/^abc|def/I
     abcdef
     abcdef\B
 
-/.*((abc)$|(def))/
+/.*((abc)$|(def))/I
     defabc
     \Zdefabc
 
-/abc/P
+/abc/IP
     abc
     *** Failers
     
-/^abc|def/P
+/^abc|def/IP
     abcdef
     abcdef\B
 
-/.*((abc)$|(def))/P
+/.*((abc)$|(def))/IP
     defabc
     \Zdefabc
   
-/the quick brown fox/P
+/the quick brown fox/IP
     the quick brown fox
     *** Failers 
     The Quick Brown Fox 
 
-/the quick brown fox/Pi
+/the quick brown fox/IPi
     the quick brown fox
     The Quick Brown Fox 
 
-/abc.def/P
+/abc.def/IP
     *** Failers
     abc\ndef
     
-/abc$/P
+/abc$/IP
     abc
     abc\n 
 
-/(abc)\2/P
+/(abc)\2/IP
 
-/(abc\1)/P
+/(abc\1)/IP
     abc
 
 /)/
 
 /a[]b/
 
-/[^aeiou ]{3,}/
+/[^aeiou ]{3,}/I
     co-processors, and for 
     
-/<.*>/
+/<.*>/I
     abc<def>ghi<klm>nop
 
-/<.*?>/
+/<.*?>/I
     abc<def>ghi<klm>nop
 
-/<.*>/U
+/<.*>/IU
     abc<def>ghi<klm>nop
     
-/(?U)<.*>/
+/(?U)<.*>/I
     abc<def>ghi<klm>nop
 
-/<.*?>/U
+/<.*?>/IU
     abc<def>ghi<klm>nop
     
-/={3,}/U
+/={3,}/IU
     abc========def
     
-/(?U)={3,}?/
+/(?U)={3,}?/I
     abc========def
     
-/(?<!bar|cattle)foo/
+/(?<!bar|cattle)foo/I
     foo
     catfoo 
     *** Failers
 
 /(?<!(foo)a\1)bar/
 
-/(?i)abc/
+/(?i)abc/I
 
-/(a|(?m)a)/
+/(a|(?m)a)/I
 
-/(?i)^1234/
+/(?i)^1234/I
 
-/(^b|(?i)^d)/
+/(^b|(?i)^d)/I
 
-/(?s).*/
+/(?s).*/I
 
-/[abcd]/S
+/[abcd]/IS
 
-/(?i)[abcd]/S
+/(?i)[abcd]/IS
 
-/(?m)[xy]|(b|c)/S
+/(?m)[xy]|(b|c)/IS
 
-/(^a|^b)/m
+/(^a|^b)/Im
 
-/(?i)(^a|^b)/m
+/(?i)(^a|^b)/Im
 
 /(a)(?(1)a|b|c)/
 
 
 /(?(1a)/
 
+/(?(1a))/
+
 /(?(?i))/
 
 /(?(abc))/
 
 /(?(?<ab))/
 
-/((?s)blah)\s+\1/
+/((?s)blah)\s+\1/I
 
-/((?i)blah)\s+\1/
+/((?i)blah)\s+\1/I
 
-/((?i)b)/DS
+/((?i)b)/IDS
 
-/(a*b|(?i:c*(?-i)d))/S
+/(a*b|(?i:c*(?-i)d))/IS
 
-/a$/
+/a$/I
     a
     a\n
     *** Failers 
     \Za
     \Za\n   
 
-/a$/m
+/a$/Im
     a
     a\n
     \Za\n   
     *** Failers 
     \Za
     
-/\Aabc/m
+/\Aabc/Im
 
-/^abc/m 
+/^abc/I
 
-/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/
+/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/I
   aaaaabbbbbcccccdef
 
-/(?<=foo)[ab]/S
+/(?<=foo)[ab]/IS
 
-/(?<!foo)(alpha|omega)/S
+/(?<!foo)(alpha|omega)/IS
 
-/(?!alphabet)[ab]/S
+/(?!alphabet)[ab]/IS
 
-/(?<=foo\n)^bar/m
+/(?<=foo\n)^bar/Im
     foo\nbarbar 
     ***Failers
     rhubarb 
     barbell
     abc\nbarton 
 
-/^(?<=foo\n)bar/m
+/^(?<=foo\n)bar/Im
     foo\nbarbar 
     ***Failers
     rhubarb 
     barbell
     abc\nbarton 
 
-/(?>^abc)/m
+/(?>^abc)/Im
     abc
     def\nabc
     *** Failers
 
 /The next three are in testinput2 because they have variable length branches/
 
-/(?<=bullock|donkey)-cart/
+/(?<=bullock|donkey)-cart/I
     the bullock-cart
     a donkey-cart race
     *** Failers
     cart
     horse-and-cart    
       
-/(?<=ab(?i)x|y|z)/
+/(?<=ab(?i)x|y|z)/I
 
-/(?>.*)(?<=(abcd)|(xyz))/
+/(?>.*)(?<=(abcd)|(xyz))/I
     alphabetabcd
     endingxyz
 
-/(?<=ab(?i)x(?-i)y|(?i)z|b)ZZ/
+/(?<=ab(?i)x(?-i)y|(?i)z|b)ZZ/I
     abxyZZ
     abXyZZ
     ZZZ
     zzz
     bzz  
 
-/(?<!(foo)a)bar/
+/(?<!(foo)a)bar/I
     bar
     foobbar 
     *** Failers
     fooabar  
 
-/This one is here because Perl 5.005_02 doesn't fail it/
+/This one is here because Perl 5.005_02 doesn't fail it/I
 
-/^(a)?(?(1)a|b)+$/
+/^(a)?(?(1)a|b)+$/I
     *** Failers
     a 
 
-/This one is here because I think Perl 5.005_02 gets the setting of $1 wrong/
+/This one is here because I think Perl 5.005_02 gets the setting of $1 wrong/I
 
-/^(a\1?){4}$/
+/^(a\1?){4}$/I
     aaaaaa
     
-/These are syntax tests from Perl 5.005/
+/These are syntax tests from Perl 5.005/I
 
 /a[b-a]/
 
 
 /(a)|\2/
 
-/a[b-a]/i
+/a[b-a]/Ii
 
-/a[]b/i
+/a[]b/Ii
 
-/a[/i
+/a[/Ii
 
-/*a/i
+/*a/Ii
 
-/(*)b/i
+/(*)b/Ii
 
-/abc)/i
+/abc)/Ii
 
-/(abc/i
+/(abc/Ii
 
-/a**/i
+/a**/Ii
 
-/)(/i
+/)(/Ii
 
 /:(?:/
 
 
 /abc/\i
 
-/(a)bc(d)/
+/(a)bc(d)/I
     abcd
     abcd\C2
     abcd\C5
      
-/(.{20})/
+/(.{20})/I
     abcdefghijklmnopqrstuvwxyz
     abcdefghijklmnopqrstuvwxyz\C1
     abcdefghijklmnopqrstuvwxyz\G1
      
-/(.{15})/
+/(.{15})/I
     abcdefghijklmnopqrstuvwxyz
     abcdefghijklmnopqrstuvwxyz\C1\G1
 
-/(.{16})/
+/(.{16})/I
     abcdefghijklmnopqrstuvwxyz
     abcdefghijklmnopqrstuvwxyz\C1\G1\L
     
-/^(a|(bc))de(f)/
+/^(a|(bc))de(f)/I
     adef\G1\G2\G3\G4\L 
     bcdef\G1\G2\G3\G4\L 
     adefghijk\C0 
     
-/^abc\00def/
+/^abc\00def/I
     abc\00def\L\C0 
     
 /word ((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ 
 )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ 
-)?)?)?)?)?)?)?)?)?otherword/M
+)?)?)?)?)?)?)?)?)?otherword/IM
 
-/.*X/D
+/.*X/ID
 
-/.*X/Ds
+/.*X/IDs
 
-/(.*X|^B)/D
+/(.*X|^B)/ID
 
-/(.*X|^B)/Ds
+/(.*X|^B)/IDs
     
-/(?s)(.*X|^B)/D
+/(?s)(.*X|^B)/ID
 
-/(?s:.*X|^B)/D
+/(?s:.*X|^B)/ID
 
-/\Biss\B/+
+/\Biss\B/I+
     Mississippi
 
-/\Biss\B/+P
+/\Biss\B/I+P
     Mississippi
 
-/iss/G+
+/iss/IG+
     Mississippi
 
-/\Biss\B/G+
+/\Biss\B/IG+
     Mississippi
 
-/\Biss\B/g+
+/\Biss\B/Ig+
     Mississippi
     *** Failers
     Mississippi\A
 
-/(?<=[Ms])iss/g+
+/(?<=[Ms])iss/Ig+
     Mississippi
 
-/(?<=[Ms])iss/G+
+/(?<=[Ms])iss/IG+
     Mississippi
 
-/^iss/g+
+/^iss/Ig+
     ississippi
     
-/.*iss/g+
+/.*iss/Ig+
     abciss\nxyzisspqr 
 
-/.i./+g
+/.i./I+g
     Mississippi
     Mississippi\A
     Missouri river
     Missouri river\A  
 
-/^.is/+g
+/^.is/I+g
     Mississippi
 
-/^ab\n/g+
+/^ab\n/Ig+
     ab\nab\ncd
 
-/^ab\n/mg+
+/^ab\n/Img+
     ab\nab\ncd
 
-/abc/
+/abc/I
 
-/abc|bac/
+/abc|bac/I
 
-/(abc|bac)/
+/(abc|bac)/I
 
-/(abc|(c|dc))/
+/(abc|(c|dc))/I
 
-/(abc|(d|de)c)/
+/(abc|(d|de)c)/I
 
-/a*/
+/a*/I
 
-/a+/
+/a+/I
 
-/(baa|a+)/
+/(baa|a+)/I
 
-/a{0,3}/
+/a{0,3}/I
 
-/baa{3,}/
+/baa{3,}/I
 
-/"([^\\"]+|\\.)*"/
+/"([^\\"]+|\\.)*"/I
 
-/(abc|ab[cd])/
+/(abc|ab[cd])/I
 
-/(a|.)/
+/(a|.)/I
 
-/a|ba|\w/
+/a|ba|\w/I
 
-/abc(?=pqr)/
+/abc(?=pqr)/I
 
-/...(?<=abc)/
+/...(?<=abc)/I
 
-/abc(?!pqr)/
+/abc(?!pqr)/I
 
-/ab./
+/ab./I
 
-/ab[xyz]/
+/ab[xyz]/I
 
-/abc*/
+/abc*/I
 
-/ab.c*/
+/ab.c*/I
 
-/a.c*/
+/a.c*/I
 
-/.c*/
+/.c*/I
 
-/ac*/
+/ac*/I
 
-/(a.c*|b.c*)/
+/(a.c*|b.c*)/I
 
-/a.c*|aba/
+/a.c*|aba/I
 
-/.+a/
+/.+a/I
 
-/(?=abcda)a.*/
+/(?=abcda)a.*/I
 
-/(?=a)a.*/
+/(?=a)a.*/I
 
-/a(b)*/
+/a(b)*/I
 
-/a\d*/
+/a\d*/I
 
-/ab\d*/
+/ab\d*/I
 
-/a(\d)*/
+/a(\d)*/I
 
-/abcde{0,0}/
+/abcde{0,0}/I
 
-/ab\d+/
+/ab\d+/I
 
-/a(?(1)b)/
+/a(?(1)b)/I
 
-/a(?(1)bag|big)/
+/a(?(1)bag|big)/I
 
-/a(?(1)bag|big)*/
+/a(?(1)bag|big)*/I
 
-/a(?(1)bag|big)+/
+/a(?(1)bag|big)+/I
 
-/a(?(1)b..|b..)/
+/a(?(1)b..|b..)/I
 
-/ab\d{0}e/
+/ab\d{0}e/I
 
-/a?b?/
+/a?b?/I
     a
     b
     ab
     *** Failers
     \N     
     
-/|-/
+/|-/I
     abcd
     -abc
     \Nab-c
     *** Failers
     \Nabc     
 
-/a*(b+)(z)(z)/P
+/a*(b+)(z)(z)/IP
     aaaabbbbzzzz
     aaaabbbbzzzz\O0
     aaaabbbbzzzz\O1
     aaaabbbbzzzz\O4
     aaaabbbbzzzz\O5
     
-/^.?abcd/S 
+/^.?abcd/I
 
 /\(             # ( at start
   (?:           # Non-capturing bracket
   (?R)          # Recurse - i.e. nested bracketed string
   )*            # Zero or more contents
   \)            # Closing )
-  /x
+  /Ix
     (abcd)
     (abcd)xyz
     xyz(abcd)
     abcd)
     (abcd  
 
-/\(  ( (?>[^()]+) | (?R) )* \) /xg
+/\(  ( (?>[^()]+) | (?R) )* \) /Ixg
     (ab(xy)cd)pqr 
     1(abcd)(x(y)z)pqr
 
-/\(  (?: (?>[^()]+) | (?R) ) \) /x
+/\(  (?: (?>[^()]+) | (?R) ) \) /Ix
     (abcd)
     (ab(xy)cd)
     (a(b(c)d)e) 
     *** Failers
     ()   
 
-/\(  (?: (?>[^()]+) | (?R) )? \) /x
+/\(  (?: (?>[^()]+) | (?R) )? \) /Ix
     ()
     12(abcde(fsh)xyz(foo(bar))lmno)89
 
-/\(  ( (?>[^()]+) | (?R) )* \) /x
+/\(  ( (?>[^()]+) | (?R) )* \) /Ix
     (ab(xy)cd)
 
-/\( ( ( (?>[^()]+) | (?R) )* ) \) /x
+/\( ( ( (?>[^()]+) | (?R) )* ) \) /Ix
     (ab(xy)cd)
 
-/\( (123)? ( ( (?>[^()]+) | (?R) )* ) \) /x
+/\( (123)? ( ( (?>[^()]+) | (?R) )* ) \) /Ix
     (ab(xy)cd)
     (123ab(xy)cd)
 
-/\( ( (123)? ( (?>[^()]+) | (?R) )* ) \) /x
+/\( ( (123)? ( (?>[^()]+) | (?R) )* ) \) /Ix
     (ab(xy)cd)
     (123ab(xy)cd)
 
-/\( (((((((((( ( (?>[^()]+) | (?R) )* )))))))))) \) /x
+/\( (((((((((( ( (?>[^()]+) | (?R) )* )))))))))) \) /Ix
     (ab(xy)cd)
 
-/\( ( ( (?>[^()<>]+) | ((?>[^()]+)) | (?R) )* ) \) /x
+/\( ( ( (?>[^()<>]+) | ((?>[^()]+)) | (?R) )* ) \) /Ix
     (abcd(xyz<p>qrs)123)
 
-/\( ( ( (?>[^()]+) | ((?R)) )* ) \) /x
+/\( ( ( (?>[^()]+) | ((?R)) )* ) \) /Ix
     (ab(cd)ef)
     (ab(cd(ef)gh)ij)
 
 
 /[01[:alpha:]%]/D
 
-/[[.ch.]]/
+/[[.ch.]]/I
 
-/[[=ch=]]/
+/[[=ch=]]/I
 
-/[[:rhubarb:]]/
+/[[:rhubarb:]]/I
 
-/[[:upper:]]/i
+/[[:upper:]]/Ii
     A
     a 
     
-/[[:lower:]]/i
+/[[:lower:]]/Ii
     A
     a 
 
-/((?-i)[[:lower:]])[[:lower:]]/i
+/((?-i)[[:lower:]])[[:lower:]]/Ii
     ab
     aB
     *** Failers
     Ab
     AB        
 
-/[\200-\110]/
+/[\200-\110]/I
 
-/^(?(0)f|b)oo/
+/^(?(0)f|b)oo/I
 
-/This one's here because of the large output vector needed/
+/This one's here because of the large output vector needed/I
 
-/(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\w+)\s+(\270)/
+/(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\w+)\s+(\270)/I
     \O900 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 ABC ABC
 
-/This one's here because Perl does this differently and PCRE can't at present/
+/This one's here because Perl does this differently and PCRE can't at present/I
 
-/(main(O)?)+/
+/(main(O)?)+/I
     mainmain
     mainOmain
     
-/These are all cases where Perl does it differently (nested captures)/
+/These are all cases where Perl does it differently (nested captures)/I
 
-/^(a(b)?)+$/
+/^(a(b)?)+$/I
     aba
    
-/^(aa(bb)?)+$/
+/^(aa(bb)?)+$/I
     aabbaa    
     
-/^(aa|aa(bb))+$/
+/^(aa|aa(bb))+$/I
     aabbaa 
     
-/^(aa(bb)??)+$/
+/^(aa(bb)??)+$/I
     aabbaa    
     
-/^(?:aa(bb)?)+$/
+/^(?:aa(bb)?)+$/I
     aabbaa    
     
-/^(aa(b(b))?)+$/
+/^(aa(b(b))?)+$/I
     aabbaa    
 
-/^(?:aa(b(b))?)+$/
+/^(?:aa(b(b))?)+$/I
     aabbaa    
 
-/^(?:aa(b(?:b))?)+$/
+/^(?:aa(b(?:b))?)+$/I
     aabbaa    
 
-/^(?:aa(bb(?:b))?)+$/
+/^(?:aa(bb(?:b))?)+$/I
     aabbbaa    
     
-/^(?:aa(b(?:bb))?)+$/
+/^(?:aa(b(?:bb))?)+$/I
     aabbbaa    
 
-/^(?:aa(?:b(b))?)+$/
+/^(?:aa(?:b(b))?)+$/I
     aabbaa    
 
-/^(?:aa(?:b(bb))?)+$/
+/^(?:aa(?:b(bb))?)+$/I
     aabbbaa    
 
-/^(aa(b(bb))?)+$/
+/^(aa(b(bb))?)+$/I
     aabbbaa    
 
-/^(aa(bb(bb))?)+$/
+/^(aa(bb(bb))?)+$/I
     aabbbbaa    
 
-/--------------------------------------------------------------------/ 
+/--------------------------------------------------------------------/I 
     
-/#/xMD
+/#/IxMD
 
-/a#/xMD
+/a#/IxMD
 
 /[\s]/D
 
     *** Failers 
     AB  
     
-/   (?i)abc/xD
+/   (?i)abc/IxD
 
 /#this is a comment
-  (?i)abc/xD
+  (?i)abc/IxD
 
 /123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/D
 
 
 /(x)*+/D
 
-/^(\w++|\s++)*$/
+/^(\w++|\s++)*$/I
     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)/
+/(\d++)(\w)/I
     12345a
     *** Failers
     12345+ 
 
-/a++b/
+/a++b/I
     aaab
 
-/(a++b)/
+/(a++b)/I
     aaab
 
-/(a++)b/
+/(a++)b/I
     aaab
 
-/([^()]++|\([^()]*\))+/
+/([^()]++|\([^()]*\))+/I
     ((abc(ade)ufh()()x
     
-/\(([^()]++|\([^()]+\))+\)/ 
+/\(([^()]++|\([^()]+\))+\)/I 
     (abc)
     (abc(def)xyz)
     *** Failers
 
 /(abc){1,3}+/D
 
-/a+?+/
+/a+?+/I
 
-/a{2,3}?+b/
+/a{2,3}?+b/I
 
-/(?U)a+?+/
+/(?U)a+?+/I
 
-/a{2,3}?+b/U
+/a{2,3}?+b/IU
 
 /x(?U)a++b/D
     xaaaab
 
 /^x(?U)(a+)b/D
 
-/[.x.]/
+/[.x.]/I
 
-/[=x=]/
+/[=x=]/I
 
-/[:x:]/
+/[:x:]/I
 
-/\l/
+/\l/I
 
-/\L/
+/\L/I
 
-/\N{name}/
+/\N{name}/I
 
-/\u/
+/\u/I
 
-/\U/
+/\U/I
 
-/[/
+/[/I
 
-/[a-/
+/[a-/I
 
-/[[:space:]/
+/[[:space:]/I
 
-/[\s]/DM
+/[\s]/IDM
 
-/[[:space:]]/DM
+/[[:space:]]/IDM
 
-/[[:space:]abcde]/DM
+/[[:space:]abcde]/IDM
 
-/< (?: (?(R) \d++  | [^<>]*+) | (?R)) * >/x
+/< (?: (?(R) \d++  | [^<>]*+) | (?R)) * >/Ix
     <>
     <abcd>
     <abc <123> hij>
     *** Failers
     <abc
 
-|8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|DM
+|8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDM
 
-|\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|DM
+|\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDM
 
 /(.*)\d+\1/I
 
 
 /(?=a).*/I
 
-/(?=abc).xyz/iI
+/(?=abc).xyz/IiI
 
 /(?=abc)(?i).xyz/I
 
 
 /a^b/I
 
-/^a/mI
+/^a/Im
   abcde
   xy\nabc 
   *** Failers 
 
 /[ab](?i)cd/IS
 
-/abc(?C)def/
+/abc(?C)def/I
     abcdef
     1234abcdef 
     *** Failers
     abcxyz
     abcxyzf   
 
-/abc(?C)de(?C1)f/
+/abc(?C)de(?C1)f/I
     123abcdef
     
-/(?C1)\dabc(?C2)def/ 
+/(?C1)\dabc(?C2)def/I 
     1234abcdef
     *** Failers
     abcdef 
     
-/(?C255)ab/
+/(?C255)ab/I
 
-/(?C256)ab/
+/(?C256)ab/I
 
-/(?Cab)xx/ 
+/(?Cab)xx/I 
 
-/(?C12vr)x/
+/(?C12vr)x/I
 
-/abc(?C)def/
+/abc(?C)def/I
     *** Failers
     \x83\x0\x61bcdef
 
-/(abc)(?C)de(?C1)f/
+/(abc)(?C)de(?C1)f/I
     123abcdef
     123abcdef\C+ 
     123abcdef\C- 
     *** Failers
     123abcdef\C!1 
     
-/(?C0)(abc(?C1))*/
+/(?C0)(abc(?C1))*/I
     abcabcabc
     abcabc\C!1!3   
     *** Failers
     abcabcabc\C!1!3   
 
-/(\d{3}(?C))*/
+/(\d{3}(?C))*/I
     123\C+
     123456\C+
     123456789\C+  
 
-/((xyz)(?C)p|(?C1)xyzabc)/
+/((xyz)(?C)p|(?C1)xyzabc)/I
     xyzabc\C+
 
-/(X)((xyz)(?C)p|(?C1)xyzabc)/
+/(X)((xyz)(?C)p|(?C1)xyzabc)/I
     Xxyzabc\C+
 
-/(?=(abc))(?C)abcdef/
+/(?=(abc))(?C)abcdef/I
     abcdef\C+
     
-/(?!(abc)(?C1)d)(?C2)abcxyz/
+/(?!(abc)(?C1)d)(?C2)abcxyz/I
     abcxyz\C+ 
 
-/(?<=(abc)(?C))xyz/
+/(?<=(abc)(?C))xyz/I
    abcxyz\C+
    
-/a(b+)(c*)(?C1)/
+/a(b+)(c*)(?C1)/I
     abbbbbccc\C*1
 
-/a(b+?)(c*?)(?C1)/
+/a(b+?)(c*?)(?C1)/I
     abbbbbccc\C*1
    
-/(?C)abc/ 
+/(?C)abc/I 
 
-/(?C)^abc/
+/(?C)^abc/I
 
-/(?C)a|b/S
+/(?C)a|b/IS
 
-/(?R)/
+/(?R)/I
 
-/(a|(?R))/
+/(a|(?R))/I
 
-/(ab|(bc|(de|(?R))))/
+/(ab|(bc|(de|(?R))))/I
 
-/x(ab|(bc|(de|(?R))))/
+/x(ab|(bc|(de|(?R))))/I
     xab
     xbc
     xde
     *** Failers
     xyab   
 
-/(ab|(bc|(de|(?1))))/
+/(ab|(bc|(de|(?1))))/I
 
-/x(ab|(bc|(de|(?1)x)x)x)/
+/x(ab|(bc|(de|(?1)x)x)x)/I
 
-/^([^()]|\((?1)*\))*$/
+/^([^()]|\((?1)*\))*$/I
     abc
     a(b)c
     a(b(c))d  
     *** Failers)
     a(b(c)d  
 
-/^>abc>([^()]|\((?1)*\))*<xyz<$/
+/^>abc>([^()]|\((?1)*\))*<xyz<$/I
    >abc>123<xyz<
    >abc>1(2)3<xyz<
    >abc>(1(2)3)<xyz<
 
 /(a(?1)+b)/D
 
-/^\W*(?:((.)\W*(?1)\W*\2|)|((.)\W*(?3)\W*\4|\W*.\W*))\W*$/i
+/^\W*(?:((.)\W*(?1)\W*\2|)|((.)\W*(?3)\W*\4|\W*.\W*))\W*$/Ii
     1221
     Satan, oscillate my metallic sonatas!
     A man, a plan, a canal: Panama!
     *** Failers
     The quick brown fox  
     
-/^(\d+|\((?1)([+*-])(?1)\)|-(?1))$/
+/^(\d+|\((?1)([+*-])(?1)\)|-(?1))$/I
     12
     (((2+2)*-3)-7)
     -12
     *** Failers
     ((2+2)*-3)-7)
          
-/^(x(y|(?1){2})z)/
+/^(x(y|(?1){2})z)/I
     xyz
     xxyzxyzz 
     *** Failers
     xxyzz
     xxyzxyzxyzz   
 
-/((< (?: (?(R) \d++  | [^<>]*+) | (?2)) * >))/x
+/((< (?: (?(R) \d++  | [^<>]*+) | (?2)) * >))/Ix
     <>
     <abcd>
     <abc <123> hij>
     *** Failers
     <abc
 
-/(?1)/
+/(?1)/I
 
-/((?2)(abc)/
+/((?2)(abc)/I
 
-/^(abc)def(?1)/
+/^(abc)def(?1)/I
     abcdefabc
 
-/^(a|b|c)=(?1)+/
+/^(a|b|c)=(?1)+/I
     a=a
     a=b
     a=bc  
 
-/^(a|b|c)=((?1))+/
+/^(a|b|c)=((?1))+/I
     a=a
     a=b
     a=bc  
 
 /(?P<a>a)...(?P=a)bbb(?P>a)d/D
 
-/^\W*(?:(?P<one>(?P<two>.)\W*(?P>one)\W*(?P=two)|)|(?P<three>(?P<four>.)\W*(?P>three)\W*(?P=four)|\W*.\W*))\W*$/i
+/^\W*(?:(?P<one>(?P<two>.)\W*(?P>one)\W*(?P=two)|)|(?P<three>(?P<four>.)\W*(?P>three)\W*(?P=four)|\W*.\W*))\W*$/Ii
     1221
     Satan, oscillate my metallic sonatas!
     A man, a plan, a canal: Panama!
     *** Failers
     The quick brown fox  
     
-/((?(R)a|b))\1(?1)?/
+/((?(R)a|b))\1(?1)?/I
   bb
   bbaa 
 
-/(.*)a/sI
+/(.*)a/Is
 
-/(.*)a\1/sI
+/(.*)a\1/Is
 
-/(.*)a(b)\2/sI
+/(.*)a(b)\2/Is
 
-/((.*)a|(.*)b)z/sI
+/((.*)a|(.*)b)z/Is
 
-/((.*)a|(.*)b)z\1/sI
+/((.*)a|(.*)b)z\1/Is
 
-/((.*)a|(.*)b)z\2/sI
+/((.*)a|(.*)b)z\2/Is
 
-/((.*)a|(.*)b)z\3/sI
+/((.*)a|(.*)b)z\3/Is
 
-/((.*)a|^(.*)b)z\3/sI
+/((.*)a|^(.*)b)z\3/Is
 
-/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a/sI
+/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a/Is
 
-/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a\31/sI
+/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a\31/Is
 
-/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a\32/sI
+/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a\32/Is
 
-/(a)(bc)/ND
+/(a)(bc)/IND
   abc
 
-/(?P<one>a)(bc)/ND
+/(?P<one>a)(bc)/IND
   abc
 
-/(a)(?P<named>bc)/ND
+/(a)(?P<named>bc)/IND
 
-/(a+)*zz/
+/(a+)*zz/I
   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzbbbbbb\M
   aaaaaaaaaaaaaz\M
 
-/(aaa(?C1)bbb|ab)/
+/(aaa(?C1)bbb|ab)/I
    aaabbb
    aaabbb\C*0
    aaabbb\C*1
    aaabbb\C*-1
 
-/ab(?P<one>cd)ef(?P<two>gh)/
+/ab(?P<one>cd)ef(?P<two>gh)/I
     abcdefgh
     abcdefgh\C1\Gtwo
     abcdefgh\Cone\Ctwo
 
 /(?P<Test>)(?P<Tes>)/D
 
-/(?P<Z>zz)(?P<A>aa)/
+/(?P<Z>zz)(?P<A>aa)/I
     zzaa\CZ
     zzaa\CA
 
-/(?P<x>eks)(?P<x>eccs)/
+/(?P<x>eks)(?P<x>eccs)/I
 
-/(?P<abc>abc(?P<def>def)(?P<abc>xyz))/
+/(?P<abc>abc(?P<def>def)(?P<abc>xyz))/I
 
-"\[((?P<elem>\d+)(,(?P>elem))*)\]"
+"\[((?P<elem>\d+)(,(?P>elem))*)\]"I
     [10,20,30,5,5,4,4,2,43,23,4234]
     *** Failers
     []  
 
-"\[((?P<elem>\d+)(,(?P>elem))*)?\]"
+"\[((?P<elem>\d+)(,(?P>elem))*)?\]"I
     [10,20,30,5,5,4,4,2,43,23,4234]
     [] 
 
 
 /[ab]{1}+/D
 
-/((w\/|-|with)*(free|immediate)*.*?shipping\s*[!.-]*)/i
+/((w\/|-|with)*(free|immediate)*.*?shipping\s*[!.-]*)/Ii
      Baby Bjorn Active Carrier - With free SHIPPING!!
 
-/((w\/|-|with)*(free|immediate)*.*?shipping\s*[!.-]*)/iS
+/((w\/|-|with)*(free|immediate)*.*?shipping\s*[!.-]*)/IiS
      Baby Bjorn Active Carrier - With free SHIPPING!!
      
-/a*.*b/SD
+/a*.*b/ISD
 
-/(a|b)*.?c/SD 
+/(a|b)*.?c/ISD 
 
 /abc(?C255)de(?C)f/D
 
-/abcde/CD
+/abcde/ICD
   abcde
   abcdfe 
   
-/a*b/CD
+/a*b/ICD
   ab
   aaaab
   aaaacb   
 
-/a+b/CD
+/a+b/ICD
   ab
   aaaab
   aaaacb   
 
-/(abc|def)x/CD
+/(abc|def)x/ICD
   abcx
   defx
   abcdefzx
 
-/(ab|cd){3,4}/C
+/(ab|cd){3,4}/IC
   ababab
   abcdabcd
   abcdcdcdcdcd  
 
-/([ab]{,4}c|xy)/CD
+/([ab]{,4}c|xy)/ICD
     Note: that { does NOT introduce a quantifier
 
-/([ab]{1,4}c|xy){4,5}?123/CD
+/([ab]{1,4}c|xy){4,5}?123/ICD
     aacaacaacaacaac123
 
 /\b.*/I
 /(?!.bcd).*/I
   Xbcd12345 
 
-/abcde/
+/abcde/I
     ab\P
     abc\P
     abcd\P
     ** Failers\P
     the quick brown abxyz fox\P
     
-"^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/(20)?\d\d$"
+"^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/(20)?\d\d$"I
     13/05/04\P
     13/5/2004\P
     02/05/09\P 
 
 /[abc]+DE/I
 
-/[abc]?123/
+/[abc]?123/I
     123\P
     a\P
     b\P
     c12\P
     c123\P      
 
-/^(?:\d){3,5}X/
+/^(?:\d){3,5}X/I
     1\P
     123\P
     123X
     1X 
     123456\P 
 
-/abc/>testsavedregex
+/abc/I>testsavedregex
 <testsavedregex
     abc
     ** Failers
     bca
     
-/abc/F>testsavedregex
+/abc/IF>testsavedregex
 <testsavedregex
     abc
     ** Failers
     bca
 
-/(a|b)/S>testsavedregex
+/(a|b)/IS>testsavedregex
 <testsavedregex
     abc
     ** Failers
     def  
     
-/(a|b)/SF>testsavedregex
+/(a|b)/ISF>testsavedregex
 <testsavedregex
     abc
     ** Failers
     def  
     
-~<(\w+)/?>(.)*</(\1)>~smg
+~<(\w+)/?>(.)*</(\1)>~smgI
     <!DOCTYPE seite SYSTEM "http://www.lco.lineas.de/xmlCms.dtd">\n<seite>\n<dokumenteninformation>\n<seitentitel>Partner der LCO</seitentitel>\n<sprache>de</sprache>\n<seitenbeschreibung>Partner der LINEAS Consulting\nGmbH</seitenbeschreibung>\n<schluesselworte>LINEAS Consulting GmbH Hamburg\nPartnerfirmen</schluesselworte>\n<revisit>30 days</revisit>\n<robots>index,follow</robots>\n<menueinformation>\n<aktiv>ja</aktiv>\n<menueposition>3</menueposition>\n<menuetext>Partner</menuetext>\n</menueinformation>\n<lastedited>\n<autor>LCO</autor>\n<firma>LINEAS Consulting</firma>\n<datum>15.10.2003</datum>\n</lastedited>\n</dokumenteninformation>\n<inhalt>\n\n<absatzueberschrift>Die Partnerfirmen der LINEAS Consulting\nGmbH</absatzueberschrift>\n\n<absatz><link ziel="http://www.ca.com/" zielfenster="_blank">\n<bild name="logo_ca.gif" rahmen="no"/></link> <link\nziel="http://www.ey.com/" zielfenster="_blank"><bild\nname="logo_euy.gif" rahmen="no"/></link>\n</absatz>\n\n<absatz><link ziel="http://www.cisco.de/" zielfenster="_blank">\n<bild name="logo_cisco.gif" rahmen="ja"/></link></absatz>\n\n<absatz><link ziel="http://www.atelion.de/"\nzielfenster="_blank"><bild\nname="logo_atelion.gif" rahmen="no"/></link>\n</absatz>\n\n<absatz><link ziel="http://www.line-information.de/"\nzielfenster="_blank">\n<bild name="logo_line_information.gif" rahmen="no"/></link>\n</absatz>\n\n<absatz><bild name="logo_aw.gif" rahmen="no"/></absatz>\n\n<absatz><link ziel="http://www.incognis.de/"\nzielfenster="_blank"><bild\nname="logo_incognis.gif" rahmen="no"/></link></absatz>\n\n<absatz><link ziel="http://www.addcraft.com/"\nzielfenster="_blank"><bild\nname="logo_addcraft.gif" rahmen="no"/></link></absatz>\n\n<absatz><link ziel="http://www.comendo.com/"\nzielfenster="_blank"><bild\nname="logo_comendo.gif" rahmen="no"/></link></absatz>\n\n</inhalt>\n</seite>
 
 /^a/IF
 
-/line\nbreak/
+/line\nbreak/I
     this is a line\nbreak
     line one\nthis is a line\nbreak in the second line 
 
-/line\nbreak/f
+/line\nbreak/If
     this is a line\nbreak
     ** Failers 
     line one\nthis is a line\nbreak in the second line 
 
-/line\nbreak/mf
+/line\nbreak/Imf
     this is a line\nbreak
     ** Failers 
     line one\nthis is a line\nbreak in the second line 
 
-/ab.cd/P
+/ab.cd/IP
     ab-cd
     ab=cd 
     ** Failers
     ab\ncd
 
-/ab.cd/Ps
+/ab.cd/IPs
     ab-cd
     ab=cd 
     ab\ncd
 
-/(?i)(?-i)AbCd/
+/(?i)(?-i)AbCd/I
     AbCd
     ** Failers
     abcd  
     
-/a{11111111111111111111}/
+/a{11111111111111111111}/I
 
-/(){64294967295}/
+/(){64294967295}/I
 
-/(){2,4294967295}/
+/(){2,4294967295}/I
 
-"(?i:a)(?i:b)(?i:c)(?i:d)(?i:e)(?i:f)(?i:g)(?i:h)(?i:i)(?i:j)(k)(?i:l)A\1B"
+"(?i:a)(?i:b)(?i:c)(?i:d)(?i:e)(?i:f)(?i:g)(?i:h)(?i:i)(?i:j)(k)(?i:l)A\1B"I
     abcdefghijklAkB
 
-"(?P<n0>a)(?P<n1>b)(?P<n2>c)(?P<n3>d)(?P<n4>e)(?P<n5>f)(?P<n6>g)(?P<n7>h)(?P<n8>i)(?P<n9>j)(?P<n10>k)(?P<n11>l)A\11B"
+"(?P<n0>a)(?P<n1>b)(?P<n2>c)(?P<n3>d)(?P<n4>e)(?P<n5>f)(?P<n6>g)(?P<n7>h)(?P<n8>i)(?P<n9>j)(?P<n10>k)(?P<n11>l)A\11B"I
     abcdefghijklAkB
 
-"(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)A\11B"
+"(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)A\11B"I
     abcdefghijklAkB
 
-"(?P<name0>a)(?P<name1>a)(?P<name2>a)(?P<name3>a)(?P<name4>a)(?P<name5>a)(?P<name6>a)(?P<name7>a)(?P<name8>a)(?P<name9>a)(?P<name10>a)(?P<name11>a)(?P<name12>a)(?P<name13>a)(?P<name14>a)(?P<name15>a)(?P<name16>a)(?P<name17>a)(?P<name18>a)(?P<name19>a)(?P<name20>a)(?P<name21>a)(?P<name22>a)(?P<name23>a)(?P<name24>a)(?P<name25>a)(?P<name26>a)(?P<name27>a)(?P<name28>a)(?P<name29>a)(?P<name30>a)(?P<name31>a)(?P<name32>a)(?P<name33>a)(?P<name34>a)(?P<name35>a)(?P<name36>a)(?P<name37>a)(?P<name38>a)(?P<name39>a)(?P<name40>a)(?P<name41>a)(?P<name42>a)(?P<name43>a)(?P<name44>a)(?P<name45>a)(?P<name46>a)(?P<name47>a)(?P<name48>a)(?P<name49>a)(?P<name50>a)(?P<name51>a)(?P<name52>a)(?P<name53>a)(?P<name54>a)(?P<name55>a)(?P<name56>a)(?P<name57>a)(?P<name58>a)(?P<name59>a)(?P<name60>a)(?P<name61>a)(?P<name62>a)(?P<name63>a)(?P<name64>a)(?P<name65>a)(?P<name66>a)(?P<name67>a)(?P<name68>a)(?P<name69>a)(?P<name70>a)(?P<name71>a)(?P<name72>a)(?P<name73>a)(?P<name74>a)(?P<name75>a)(?P<name76>a)(?P<name77>a)(?P<name78>a)(?P<name79>a)(?P<name80>a)(?P<name81>a)(?P<name82>a)(?P<name83>a)(?P<name84>a)(?P<name85>a)(?P<name86>a)(?P<name87>a)(?P<name88>a)(?P<name89>a)(?P<name90>a)(?P<name91>a)(?P<name92>a)(?P<name93>a)(?P<name94>a)(?P<name95>a)(?P<name96>a)(?P<name97>a)(?P<name98>a)(?P<name99>a)(?P<name100>a)"
+"(?P<name0>a)(?P<name1>a)(?P<name2>a)(?P<name3>a)(?P<name4>a)(?P<name5>a)(?P<name6>a)(?P<name7>a)(?P<name8>a)(?P<name9>a)(?P<name10>a)(?P<name11>a)(?P<name12>a)(?P<name13>a)(?P<name14>a)(?P<name15>a)(?P<name16>a)(?P<name17>a)(?P<name18>a)(?P<name19>a)(?P<name20>a)(?P<name21>a)(?P<name22>a)(?P<name23>a)(?P<name24>a)(?P<name25>a)(?P<name26>a)(?P<name27>a)(?P<name28>a)(?P<name29>a)(?P<name30>a)(?P<name31>a)(?P<name32>a)(?P<name33>a)(?P<name34>a)(?P<name35>a)(?P<name36>a)(?P<name37>a)(?P<name38>a)(?P<name39>a)(?P<name40>a)(?P<name41>a)(?P<name42>a)(?P<name43>a)(?P<name44>a)(?P<name45>a)(?P<name46>a)(?P<name47>a)(?P<name48>a)(?P<name49>a)(?P<name50>a)(?P<name51>a)(?P<name52>a)(?P<name53>a)(?P<name54>a)(?P<name55>a)(?P<name56>a)(?P<name57>a)(?P<name58>a)(?P<name59>a)(?P<name60>a)(?P<name61>a)(?P<name62>a)(?P<name63>a)(?P<name64>a)(?P<name65>a)(?P<name66>a)(?P<name67>a)(?P<name68>a)(?P<name69>a)(?P<name70>a)(?P<name71>a)(?P<name72>a)(?P<name73>a)(?P<name74>a)(?P<name75>a)(?P<name76>a)(?P<name77>a)(?P<name78>a)(?P<name79>a)(?P<name80>a)(?P<name81>a)(?P<name82>a)(?P<name83>a)(?P<name84>a)(?P<name85>a)(?P<name86>a)(?P<name87>a)(?P<name88>a)(?P<name89>a)(?P<name90>a)(?P<name91>a)(?P<name92>a)(?P<name93>a)(?P<name94>a)(?P<name95>a)(?P<name96>a)(?P<name97>a)(?P<name98>a)(?P<name99>a)(?P<name100>a)"I
     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
-"(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)"
+"(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)"I
     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
-/[^()]*(?:\((?R)\)[^()]*)*/
+/[^()]*(?:\((?R)\)[^()]*)*/I
     (this(and)that
     (this(and)that) 
     (this(and)that)stuff
 
-/[^()]*(?:\((?>(?R))\)[^()]*)*/
+/[^()]*(?:\((?>(?R))\)[^()]*)*/I
     (this(and)that
     (this(and)that) 
     
-/[^()]*(?:\((?R)\))*[^()]*/
+/[^()]*(?:\((?R)\))*[^()]*/I
     (this(and)that
     (this(and)that) 
 
-/(?:\((?R)\))*[^()]*/
+/(?:\((?R)\))*[^()]*/I
     (this(and)that
     (this(and)that) 
     ((this)) 
 
-/(?:\((?R)\))|[^()]*/
+/(?:\((?R)\))|[^()]*/I
     (this(and)that
     (this(and)that) 
     (this)
     ((this)) 
     
-/a(b)c/PN
+/a(b)c/IPN
     abc
     
-/a(?P<name>b)c/PN
+/a(?P<name>b)c/IPN
     abc  
     
-/\x{100}/ 
+/\x{100}/I 
 
-/\x{0000ff}/
+/\x{0000ff}/I
 
-/^((?P<A>a1)|(?P<A>a2)b)/
+/^((?P<A>a1)|(?P<A>a2)b)/I
 
-/^((?P<A>a1)|(?P<A>a2)b)/J
+/^((?P<A>a1)|(?P<A>a2)b)/IJ
     a1b\CA
     a2b\CA 
     ** Failers
     a1b\CZ\CA 
     
-/^(?P<A>a)(?P<A>b)/J
+/^(?P<A>a)(?P<A>b)/IJ
     ab\CA
     
-/^(?P<A>a)(?P<A>b)|cd/J
+/^(?P<A>a)(?P<A>b)|cd/IJ
     ab\CA
     cd\CA 
   
-/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/J
+/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/IJ
     cdefgh\CA 
   
-/^((?P<A>a1)|(?P<A>a2)b)/J
+/^((?P<A>a1)|(?P<A>a2)b)/IJ
     a1b\GA
     a2b\GA 
     ** Failers
     a1b\GZ\GA 
     
-/^(?P<A>a)(?P<A>b)/J
+/^(?P<A>a)(?P<A>b)/IJ
     ab\GA
     
-/^(?P<A>a)(?P<A>b)|cd/J
+/^(?P<A>a)(?P<A>b)|cd/IJ
     ab\GA
     cd\GA 
   
-/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/J
+/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/IJ
     cdefgh\GA 
   
-/(?J)^((?P<A>a1)|(?P<A>a2)b)/
+/(?J)^((?P<A>a1)|(?P<A>a2)b)/I
     a1b\CA
     a2b\CA 
     
-/^(?P<A>a) (?J:(?P<B>b)(?P<B>c)) (?P<A>d)/
+/^(?P<A>a) (?J:(?P<B>b)(?P<B>c)) (?P<A>d)/I
 
 / In this next test, J is not set at the outer level; consequently it isn't
 set in the pattern's options; consequently pcre_get_named_substring() produces 
-a random value. /x
+a random value. /Ix
 
-/^(?P<A>a) (?J:(?P<B>b)(?P<B>c)) (?P<C>d)/
+/^(?P<A>a) (?J:(?P<B>b)(?P<B>c)) (?P<C>d)/I
     a bc d\CA\CB\CC
 
-/^(?P<A>a)?(?(A)a|b)/
+/^(?P<A>a)?(?(A)a|b)/I
     aabc
     bc
     ** Failers
     abc   
 
-/(?:(?(ZZ)a|b)(?P<ZZ>X))+/
+/(?:(?(ZZ)a|b)(?P<ZZ>X))+/I
     bXaX
 
-/(?:(?(2y)a|b)(X))+/
+/(?:(?(2y)a|b)(X))+/I
 
-/(?:(?(ZA)a|b)(?P<ZZ>X))+/
+/(?:(?(ZA)a|b)(?P<ZZ>X))+/I
 
-/(?:(?(ZZ)a|b)(?(ZZ)a|b)(?P<ZZ>X))+/
+/(?:(?(ZZ)a|b)(?(ZZ)a|b)(?P<ZZ>X))+/I
     bbXaaX
 
-/(?:(?(ZZ)a|\(b\))\\(?P<ZZ>X))+/
+/(?:(?(ZZ)a|\(b\))\\(?P<ZZ>X))+/I
     (b)\\Xa\\X
 
-/(?P<ABC/
+/(?P<ABC/I
 
-/(?:(?(A)(?P=A)a|b)(?P<A>X|Y))+/
+/(?:(?(A)(?P=A)a|b)(?P<A>X|Y))+/I
     bXXaYYaY
     bXYaXXaX  
 
-/()()()()()()()()()(?:(?(A)(?P=A)a|b)(?P<A>X|Y))+/
+/()()()()()()()()()(?:(?(A)(?P=A)a|b)(?P<A>X|Y))+/I
     bXXaYYaY
 
-/\777/
+/\777/I
 
-/\s*,\s*/S
+/\s*,\s*/IS
     \x0b,\x0b
     \x0c,\x0d 
 
-/^abc/m
+/^abc/Im
     xyz\nabc
     xyz\nabc\<lf>
     xyz\r\nabc\<lf>
@@ -1584,7 +1586,7 @@ a random value. /x
     xyz\rabc\<crlf>
     xyz\rabc\<lf>
     
-/abc$/m
+/abc$/Im<lf>
     xyzabc
     xyzabc\n 
     xyzabc\npqr 
@@ -1598,31 +1600,31 @@ a random value. /x
     xyzabc\r\n 
     xyzabc\r\npqr 
     
-/^abc/m<cr>
+/^abc/Im<cr>
     xyz\rabcdef
     xyz\nabcdef\<lf>
     ** Failers  
     xyz\nabcdef
        
-/^abc/m<lf>
+/^abc/Im<lf>
     xyz\nabcdef
     xyz\rabcdef\<cr>
     ** Failers  
     xyz\rabcdef
        
-/^abc/m<crlf>
+/^abc/Im<crlf>
     xyz\r\nabcdef
     xyz\rabcdef\<cr>
     ** Failers  
     xyz\rabcdef
     
-/^abc/m<bad>
+/^abc/Im<bad>
 
-/abc/
+/abc/I
     xyz\rabc\<bad>
     abc  
        
-/.*/
+/.*/I<lf>
     abc\ndef
     abc\rdef
     abc\r\ndef
@@ -1633,14 +1635,499 @@ a random value. /x
     \<crlf>abc\rdef
     \<crlf>abc\r\ndef
 
-/\w+(.)(.)?def/s
+/\w+(.)(.)?def/Is
     abc\ndef
     abc\rdef
     abc\r\ndef
 
-+((?:\s|//.*\\n|/[*](?:\\n|.)*?[*]/)*)+
++((?:\s|//.*\\n|/[*](?:\\n|.)*?[*]/)*)+I
    /* this is a C style comment */\M
 
-/(?P<B>25[0-5]|2[0-4]\d|[01]?\d?\d)(?:\.(?P>B)){3}/
+/(?P<B>25[0-5]|2[0-4]\d|[01]?\d?\d)(?:\.(?P>B)){3}/I
+
+/()()()()()()()()()()()()()()()()()()()()
+ ()()()()()()()()()()()()()()()()()()()()
+ ()()()()()()()()()()()()()()()()()()()()
+ ()()()()()()()()()()()()()()()()()()()()
+ ()()()()()()()()()()()()()()()()()()()()
+ (.(.))/Ix
+    XY\O400  
+
+/(a*b|(?i:c*(?-i)d))/IS
+
+/()[ab]xyz/IS
+
+/(|)[ab]xyz/IS
+
+/(|c)[ab]xyz/IS
+
+/(|c?)[ab]xyz/IS
+
+/(d?|c?)[ab]xyz/IS
+
+/(d?|c)[ab]xyz/IS
+
+/^a*b\d/D
+
+/^a*+b\d/D
+
+/^a*?b\d/D
+
+/^a+A\d/D
+    aaaA5
+    ** Failers
+    aaaa5 
+
+/^a*A\d/IiD
+    aaaA5
+    aaaa5
+
+/(a*|b*)[cd]/IS
+
+/(a+|b*)[cd]/IS
+
+/(a*|b+)[cd]/IS
+
+/(a+|b+)[cd]/IS
+
+/((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+ ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+ (((
+ a
+ ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+ ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+ ))) 
+/Ix  
+  large nest
+
+/a*\d/B
+
+/a*\D/B
+
+/0*\d/B
+
+/0*\D/B
+
+/a*\s/B
+
+/a*\S/B
+
+/ *\s/B
+
+/ *\S/B
+
+/a*\w/B
+
+/a*\W/B
+
+/=*\w/B
+
+/=*\W/B
+
+/\d*a/B
+
+/\d*2/B
+
+/\d*\d/B
+
+/\d*\D/B
+
+/\d*\s/B
+
+/\d*\S/B
+
+/\d*\w/B
+
+/\d*\W/B
+
+/\D*a/B
+
+/\D*2/B
+
+/\D*\d/B
+
+/\D*\D/B
+
+/\D*\s/B
+
+/\D*\S/B
+
+/\D*\w/B
+
+/\D*\W/B
+
+/\s*a/B
+
+/\s*2/B
+
+/\s*\d/B
+
+/\s*\D/B
+
+/\s*\s/B
+
+/\s*\S/B
+
+/\s*\w/B
+
+/\s*\W/B
+
+/\S*a/B
+
+/\S*2/B
+
+/\S*\d/B
+
+/\S*\D/B
+
+/\S*\s/B
+
+/\S*\S/B
+
+/\S*\w/B
+
+/\S*\W/B
+
+/\w*a/B
+
+/\w*2/B
+
+/\w*\d/B
+
+/\w*\D/B
+
+/\w*\s/B
+
+/\w*\S/B
+
+/\w*\w/B
+
+/\w*\W/B
+
+/\W*a/B
+
+/\W*2/B
+
+/\W*\d/B
+
+/\W*\D/B
+
+/\W*\s/B
+
+/\W*\S/B
+
+/\W*\w/B
+
+/\W*\W/B
+
+/[^a]+a/B
+
+/[^a]+a/Bi
+
+/[^a]+A/Bi
+
+/[^a]+b/B
+
+/[^a]+\d/B
+
+/a*[^a]/B
+
+/(?P<abc>x)(?P<xyz>y)/I
+    xy\Cabc\Cxyz
+
+/(?<abc>x)(?'xyz'y)/I
+    xy\Cabc\Cxyz
+
+/(?<abc'x)(?'xyz'y)/I
+
+/(?<abc>x)(?'xyz>y)/I
+
+/(?P'abc'x)(?P<xyz>y)/I
+
+/^(?:(?(ZZ)a|b)(?<ZZ>X))+/
+    bXaX
+    bXbX
+    ** Failers
+    aXaX   
+    aXbX 
+
+/^(?P>abc)(?<abcd>xxx)/
+
+/^(?P>abc)(?<abc>x|y)/
+    xx
+    xy
+    yy
+    yx   
+
+/^(?P>abc)(?P<abc>x|y)/
+    xx
+    xy
+    yy
+    yx   
+
+/^((?(abc)a|b)(?<abc>x|y))+/
+    bxay
+    bxby 
+    ** Failers
+    axby  
+
+/^(((?P=abc)|X)(?<abc>x|y))+/
+    XxXxxx
+    XxXyyx
+    XxXyxx
+    ** Failers
+    x  
+
+/^(?1)(abc)/
+    abcabc
+
+/^(?:(?:\1|X)(a|b))+/
+    Xaaa
+    Xaba 
+
+/^[\E\Qa\E-\Qz\E]+/B
+    
+/^[a\Q]bc\E]/B
+    
+/^[a-\Q\E]/B
+
+/^(?P>abc)[()](?<abc>)/B
+
+/^((?(abc)y)[()](?P<abc>x))+/B
+    (xy)x
+    
+/^(?P>abc)\Q()\E(?<abc>)/B 
+
+/^(?P>abc)[a\Q(]\E(](?<abc>)/B 
+
+/^(?P>abc) # this is (a comment)
+  (?<abc>)/Bx 
+
+/^\W*(?:(?<one>(?<two>.)\W*(?&one)\W*\k<two>|)|(?<three>(?<four>.)\W*(?&three)\W*\k'four'|\W*.\W*))\W*$/Ii
+    1221
+    Satan, oscillate my metallic sonatas!
+    A man, a plan, a canal: Panama!
+    Able was I ere I saw Elba. 
+    *** Failers
+    The quick brown fox  
+    
+/(?=(\w+))\1:/I
+    abcd:
+
+/(?=(?'abc'\w+))\k<abc>:/I
+    abcd:
+
+/(?'abc'\w+):\k<abc>{2}/
+    a:aaxyz
+    ab:ababxyz
+    ** Failers
+    a:axyz   
+    ab:abxyz 
+
+/(?'abc'a|b)(?<abc>d|e)\k<abc>{2}/J
+    adaa
+    ** Failers
+    addd
+    adbb   
+
+/(?'abc'a|b)(?<abc>d|e)(?&abc){2}/J
+    bdaa
+    bdab
+    ** Failers
+    bddd   
+
+/^(?<ab>a)? (?(<ab>)b|c) (?('ab')d|e)/x
+    abd
+    ce 
+    
+/(?(<bc))/
+
+/(?(''))/ 
+
+/(?('R')stuff)/
+
+/((abc (?(R) (?(R1)1) (?(R2)2) X  |  (?1)  (?2)   (?R) ))) /x
+    abcabc1Xabc2XabcXabcabc
+
+/(?<A> (?'B' abc (?(R) (?(R&A)1) (?(R&B)2) X  |  (?1)  (?2)   (?R) ))) /x
+    abcabc1Xabc2XabcXabcabc
+
+/(?<A> (?'B' abc (?(R) (?(R&1)1) (?(R&B)2) X  |  (?1)  (?2)   (?R) ))) /x
+
+/(?<1> (?'B' abc (?(R) (?(R&1)1) (?(R&B)2) X  |  (?1)  (?2)   (?R) ))) /x
+    abcabc1Xabc2XabcXabcabc
+
+/^(?(DEFINE) (?<A> a) (?<B> b) )  (?&A) (?&B) /x
+    abcd
+    
+/(?<NAME>(?&NAME_PAT))\s+(?<ADDR>(?&ADDRESS_PAT))
+  (?(DEFINE)
+  (?<NAME_PAT>[a-z]+)
+  (?<ADDRESS_PAT>\d+)
+  )/x
+    metcalfe 33
+/^(?(DEFINE) abc | xyz ) /x
+    
+/(?(DEFINE) abc) xyz/xI
+
+/(?(DEFINE) abc){3} xyz/x
+
+/(a|)*\d/
+  \O0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+  \O0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/^a.b/<lf>
+    a\rb
+    a\nb\<cr> 
+    ** Failers
+    a\nb
+    a\nb\<any>
+    a\rb\<cr>   
+    a\rb\<any>   
+
+/^abc./mgx<any>
+    abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x85abc7 \x{2028}abc8 \x{2029}abc9 JUNK
+
+/abc.$/mgx<any>
+    abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x85 abc7\x{2028} abc8\x{2029} abc9
+
+/a/<cr><any>
+
+/a/<any><crlf>
+
+/^a\Rb/
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0cb
+    a\x85b   
+    ** Failers
+    a\n\rb    
+
+/^a\R*b/
+    ab
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0cb
+    a\x85b   
+    a\n\rb    
+    a\n\r\x85\x0cb 
+
+/^a\R+b/
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0cb
+    a\x85b   
+    a\n\rb    
+    a\n\r\x85\x0cb 
+    ** Failers
+    ab  
+    
+/^a\R{1,3}b/
+    a\nb
+    a\n\rb
+    a\n\r\x85b
+    a\r\n\r\nb 
+    a\r\n\r\n\r\nb 
+    a\n\r\n\rb
+    a\n\n\r\nb 
+    ** Failers
+    a\n\n\n\rb
+    a\r
+
+/^a[\R]b/
+    aRb
+    ** Failers
+    a\nb  
+
+/(?&abc)X(?<abc>P)/I
+    abcPXP123
+
+/(?1)X(?<abc>P)/I
+    abcPXP123
+
+/(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))\b(?&byte)(\.(?&byte)){3}/
+    1.2.3.4
+    131.111.10.206
+    10.0.0.0
+    ** Failers
+    10.6
+    455.3.4.5   
+
+/\b(?&byte)(\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))/
+    1.2.3.4
+    131.111.10.206
+    10.0.0.0
+    ** Failers
+    10.6
+    455.3.4.5   
+    
+/(?:a(?&abc)b)*(?<abc>x)/
+    123axbaxbaxbx456
+    123axbaxbaxb456
+      
+/(?:a(?&abc)b){1,5}(?<abc>x)/
+    123axbaxbaxbx456
+
+/(?:a(?&abc)b){2,5}(?<abc>x)/
+    123axbaxbaxbx456
+
+/(?:a(?&abc)b){2,}(?<abc>x)/
+    123axbaxbaxbx456
+
+/(abc)(?i:(?1))/
+   defabcabcxyz
+   DEFabcABCXYZ
+
+/(abc)(?:(?i)(?1))/
+   defabcabcxyz
+   DEFabcABCXYZ
+
+/^(a(b))\1\g1\g{1}\g-1\g{-1}\g{-02}Z/
+    ababababbbabZXXXX
+
+/^(a)\g-2/
+
+/^(a)\g/
+
+/^(a)\g{0}/
+
+/^(a)\g{3/
+
+/^(a)\g{4a}/
+
+/^a.b/<lf>
+    a\rb
+    *** Failers
+    a\nb
+
+/.+foo/
+    afoo
+    ** Failers 
+    \r\nfoo 
+    \nfoo 
+
+/.+foo/<crlf>
+    afoo
+    \nfoo 
+    ** Failers 
+    \r\nfoo 
+
+/.+foo/<any>
+    afoo
+    ** Failers 
+    \nfoo 
+    \r\nfoo 
+
+/.+foo/s
+    afoo
+    \r\nfoo 
+    \nfoo 
 
 / End of testinput2 /
index 9ff0fc7a647e66e9e78693ab8f5b7f13fa9915b5..0fb850bffcaee46334598cf8d9005fdfb33f59b4 100644 (file)
     abcdefg
     ab
 
+/a*\x{100}*\w/8
+    a 
+
 / End of testinput4 /
index 54643f6516815330cbf776be93ed2690099e3443..85d3ce63db1fca3b3e7a94637b8d1fb8c7119c25 100644 (file)
 /\777/8I
   \x{1ff}
   \777 
+  
+/\x{100}*\d/8D
+
+/\x{100}*\s/8D
+
+/\x{100}*\w/8D
+
+/\x{100}*\D/8D
+
+/\x{100}*\S/8D
+
+/\x{100}*\W/8D
+
+/\x{100}+\x{200}/8D
+
+/\x{100}+X/8D
+
+/X+\x{200}/8D
+
+/()()()()()()()()()()
+ ()()()()()()()()()()
+ ()()()()()()()()()()
+ ()()()()()()()()()()
+ A (x) (?41) B/8x
+    AxxB     
+
+/^[\x{100}\E-\Q\E\x{150}]/B8
+
+/^[\QĀ\E-\QŐ\E]/B8
+
+/^[\QĀ\E-\QŐ\E/B8
+
+/^abc./mgx8<any>
+    abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x{0085}abc7 \x{2028}abc8 \x{2029}abc9 JUNK
+
+/abc.$/mgx8<any>
+    abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x{0085} abc7\x{2028} abc8\x{2029} abc9
+
+/^a\Rb/8
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0cb
+    a\x{85}b   
+    a\x{2028}b 
+    a\x{2029}b 
+    ** Failers
+    a\n\rb    
+
+/^a\R*b/8
+    ab
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0c\x{2028}\x{2029}b
+    a\x{85}b   
+    a\n\rb    
+    a\n\r\x{85}\x0cb 
+
+/^a\R+b/8
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0c\x{2028}\x{2029}b
+    a\x{85}b   
+    a\n\rb    
+    a\n\r\x{85}\x0cb 
+    ** Failers
+    ab  
+
+/^a\R{1,3}b/8
+    a\nb
+    a\n\rb
+    a\n\r\x{85}b
+    a\r\n\r\nb 
+    a\r\n\r\n\r\nb 
+    a\n\r\n\rb
+    a\n\n\r\nb 
+    ** Failers
+    a\n\n\n\rb
+    a\r
 
 / End of testinput5 /
index da5b9ca23627395cd40842f3bea7b98f541645ea..5a541f362ac6b3b1b07f8b5b91e7d7cd0fcb7336 100644 (file)
 /([\pL]=(abc))*X/
     L=abcX
 
+/The next two should be Perl-compatible, but it fails to match \x{e0}. PCRE
+will match it only with UCP support, because without that it has no notion
+of case for anything other than the ASCII letters. / 
+
+/((?i)[\x{c0}])/8
+    \x{c0}
+    \x{e0} 
+
+/(?i:[\x{c0}])/8
+    \x{c0}
+    \x{e0} 
+    
+/^\p{Balinese}\p{Cuneiform}\p{Nko}\p{Phags_Pa}\p{Phoenician}/8
+    \x{1b00}\x{12000}\x{7c0}\x{a840}\x{10900}
+
 / End of testinput6 /
index 8e2d7c3ba0a9c06b27f166779aad703fe7168d67..23b35f16d81945250e8853b1fd8910c4bc89904a 100644 (file)
     abc
 
 /^a    b
-  
-  \f  c/x
+    \f  c/x
     abc
 
 /ab{1,3}bc/
 /{4,5a}bc/
     {4,5a}bc
 
-/^a.b/
+/^a.b/<lf>
     a\rb
     *** Failers
     a\nb
 /(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\12\123/
     abcdefghijk\12S
 
-/ab\gdef/
-    abgdef
+/ab\hdef/
+    abhdef
 
 /a{0}bc/
     bc
     xyz\rabc\<crlf>
     xyz\rabc\<lf>
     
-/abc$/m
+/abc$/m<lf>
     xyzabc
     xyzabc\n 
     xyzabc\npqr 
     ** Failers  
     xyz\rabcdef
     
-/.*/
+/.*/<lf>
     abc\ndef
     abc\rdef
     abc\r\ndef
     abc\rdef
     abc\r\ndef
 
+/^\w+=.*(\\\n.*)*/
+    abc=xyz\\\npqr
+
+/^(a()*)*/
+    aaaa
+
+/^(?:a(?:(?:))*)*/
+    aaaa
+
+/^(a()+)+/
+    aaaa
+
+/^(?:a(?:(?:))+)+/
+    aaaa
+
+/(a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/(?>a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/(?:a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/^a.b/<lf>
+    a\rb
+    a\nb\<cr> 
+    ** Failers
+    a\nb
+    a\nb\<any>
+    a\rb\<cr>   
+    a\rb\<any>   
+
+/^abc./mgx<any>
+    abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x85abc7 \x{2028}abc8 \x{2029}abc9 JUNK
+
+/abc.$/mgx<any>
+    abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x85 abc7\x{2028} abc8\x{2029} abc9
+
+/^a\Rb/
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0cb
+    a\x85b   
+    ** Failers
+    a\n\rb    
+
+/^a\R*b/
+    ab
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0cb
+    a\x85b   
+    a\n\rb    
+    a\n\r\x85\x0cb 
+
+/^a\R+b/
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0cb
+    a\x85b   
+    a\n\rb    
+    a\n\r\x85\x0cb 
+    ** Failers
+    ab  
+    
+/^a\R{1,3}b/
+    a\nb
+    a\n\rb
+    a\n\r\x85b
+    a\r\n\r\nb 
+    a\r\n\r\n\r\nb 
+    a\n\r\n\rb
+    a\n\n\r\nb 
+    ** Failers
+    a\n\n\n\rb
+    a\r
+
+/^a[\R]b/
+    aRb
+    ** Failers
+    a\nb  
+
+/.+foo/
+    afoo
+    ** Failers 
+    \r\nfoo 
+    \nfoo 
+
+/.+foo/<crlf>
+    afoo
+    \nfoo 
+    ** Failers 
+    \r\nfoo 
+
+/.+foo/<any>
+    afoo
+    ** Failers 
+    \nfoo 
+    \r\nfoo 
+
+/.+foo/s
+    afoo
+    \r\nfoo 
+    \nfoo 
+
 / End of testinput7 /
index 36db2433e4f35b190e7dc8e5c8db41f1de13df0f..a19493fe63b87c0fc6ba2547ca33ffc505891924 100644 (file)
 /^\x{85}$/8i
     \x{85}
 
+/^abc./mgx8<any>
+    abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x{0085}abc7 \x{2028}abc8 \x{2029}abc9 JUNK
+
+/abc.$/mgx8<any>
+    abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x{0085} abc7\x{2028} abc8\x{2029} abc9
+
+/^a\Rb/8
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0cb
+    a\x{85}b   
+    a\x{2028}b 
+    a\x{2029}b 
+    ** Failers
+    a\n\rb    
+
+/^a\R*b/8
+    ab
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0c\x{2028}\x{2029}b
+    a\x{85}b   
+    a\n\rb    
+    a\n\r\x{85}\x0cb 
+
+/^a\R+b/8
+    a\nb
+    a\rb
+    a\r\nb
+    a\x0bb
+    a\x0c\x{2028}\x{2029}b
+    a\x{85}b   
+    a\n\rb    
+    a\n\r\x{85}\x0cb 
+    ** Failers
+    ab  
+
+/^a\R{1,3}b/8
+    a\nb
+    a\n\rb
+    a\n\r\x{85}b
+    a\r\n\r\nb 
+    a\r\n\r\n\r\nb 
+    a\n\r\n\rb
+    a\n\n\r\nb 
+    ** Failers
+    a\n\n\n\rb
+    a\r
+
 / End of testinput 8 / 
index 6f5ae19b9f0c5ad1f41c2ce127e180123723efd6..b513dca417b22777e54cf3aaa091a21fc0cb8195 100644 (file)
@@ -1817,8 +1817,7 @@ No match
 No match
 
 /^a    b
-  
-  \f  c/x
+    \f  c/x
     abc
  0: abc
 
@@ -2094,14 +2093,6 @@ No match
     {4,5a}bc
  0: {4,5a}bc
 
-/^a.b/
-    a\rb
- 0: a\x0db
-    *** Failers
-No match
-    a\nb
-No match
-
 /abc$/
     abc
  0: abc
@@ -2198,9 +2189,9 @@ No match
 10: j
 11: k
 
-/ab\gdef/
-    abgdef
- 0: abgdef
+/ab\hdef/
+    abhdef
+ 0: abhdef
 
 /a{0}bc/
     bc
@@ -5481,12 +5472,22 @@ No match
  0: b
 
 /^(?:a?b?)*$/
+    \
+ 0: 
+    a
+ 0: a
+    ab
+ 0: ab
+    aaa   
+ 0: aaa
     *** Failers
 No match
     dbcb
 No match
     a--
 No match
+    aa-- 
+No match
 
 /((?s)^a(.))((?m)^b$)/
     a\nb\nc\n
@@ -6354,4 +6355,220 @@ No match
     [a,b,c]  
  0: [a,b,c]
 
+/(?-x: )/x
+    A\x20B
+ 0:  
+    
+"(?x)(?-x: \s*#\s*)"
+    A # B
+ 0:  # 
+    ** Failers
+No match
+    #  
+No match
+
+"(?x-is)(?:(?-ixs) \s*#\s*) include"
+    A #include
+ 0:  #include
+    ** Failers
+No match
+    A#include  
+No match
+    A #Include
+No match
+
+/a*b*\w/
+    aaabbbb
+ 0: aaabbbb
+    aaaa
+ 0: aaaa
+    a
+ 0: a
+
+/a*b?\w/
+    aaabbbb
+ 0: aaabb
+    aaaa
+ 0: aaaa
+    a
+ 0: a
+
+/a*b{0,4}\w/
+    aaabbbb
+ 0: aaabbbb
+    aaaa
+ 0: aaaa
+    a
+ 0: a
+
+/a*b{0,}\w/
+    aaabbbb
+ 0: aaabbbb
+    aaaa
+ 0: aaaa
+    a
+ 0: a
+    
+/a*\d*\w/
+    0a
+ 0: 0a
+    a 
+ 0: a
+    
+/a*b *\w/x
+    a 
+ 0: a
+
+/a*b#comment
+  *\w/x
+    a 
+ 0: a
+
+/a* b *\w/x
+    a 
+ 0: a
+
+/^\w+=.*(\\\n.*)*/
+    abc=xyz\\\npqr
+ 0: abc=xyz\
+
+/(?=(\w+))\1:/
+    abcd:
+ 0: abcd:
+ 1: abcd
+
+/^(?=(\w+))\1:/
+    abcd:
+ 0: abcd:
+ 1: abcd
+
+/^\Eabc/
+    abc
+ 0: abc
+    
+/^[\Eabc]/
+    a
+ 0: a
+    ** Failers 
+No match
+    E 
+No match
+    
+/^[a-\Ec]/
+    b
+ 0: b
+    ** Failers
+No match
+    -
+No match
+    E    
+No match
+
+/^[a\E\E-\Ec]/
+    b
+ 0: b
+    ** Failers
+No match
+    -
+No match
+    E    
+No match
+
+/^[\E\Qa\E-\Qz\E]+/
+    b
+ 0: b
+    ** Failers
+No match
+    -  
+No match
+    
+/^[a\Q]bc\E]/
+    a
+ 0: a
+    ]
+ 0: ]
+    c
+ 0: c
+    
+/^[a-\Q\E]/
+    a
+ 0: a
+    -     
+ 0: -
+
+/^(a()*)*/
+    aaaa
+ 0: aaaa
+ 1: a
+ 2: 
+
+/^(?:a(?:(?:))*)*/
+    aaaa
+ 0: aaaa
+
+/^(a()+)+/
+    aaaa
+ 0: aaaa
+ 1: a
+ 2: 
+
+/^(?:a(?:(?:))+)+/
+    aaaa
+ 0: aaaa
+
+/(a){0,3}(?(1)b|(c|))*D/
+    abbD
+ 0: abbD
+ 1: a
+    ccccD
+ 0: ccccD
+ 1: <unset>
+ 2: 
+    D  
+ 0: D
+ 1: <unset>
+ 2: 
+
+/(a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+No match
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+ 0: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+ 1: 
+
+/(?>a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+No match
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+ 0: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/(?:a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+No match
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+ 0: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/\Z/g
+  abc\n
+ 0: 
+ 0: 
+  
+/^(?s)(?>.*)(?<!\n)/
+  abc
+ 0: abc
+  abc\n  
+No match
+
+/^(?![^\n]*\n\z)/
+  abc
+ 0: 
+  abc\n 
+No match
+  
+/\z(?<!\n)/
+  abc
+ 0: 
+  abc\n  
+No match
+
 / End of testinput1 /
index bcde708569e26a4d716d67f7f9a31d9176a41800..45907492f95a6e4b99b6bbab741012988ccb43ae 100644 (file)
@@ -1,10 +1,10 @@
-/(a)b|/
+/(a)b|/I
 Capturing subpattern count = 1
 No options
 No first char
 No need char
 
-/abc/
+/abc/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
@@ -22,7 +22,7 @@ No match
     ABC
 No match
 
-/^abc/
+/^abc/I
 Capturing subpattern count = 0
 Options: anchored
 No first char
@@ -38,35 +38,35 @@ No match
     \Adefabc
 No match
 
-/a+bc/
+/a+bc/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 Need char = 'c'
 
-/a*bc/
+/a*bc/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 No first char
 Need char = 'c'
 
-/a{3}bc/
+/a{3}bc/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 Need char = 'c'
 
-/(abc|a+z)/
+/(abc|a+z)/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
 First char = 'a'
 No need char
 
-/^abc$/
+/^abc$/I
 Capturing subpattern count = 0
 Options: anchored
 No first char
@@ -78,10 +78,10 @@ No match
     def\nabc
 No match
 
-/ab\gdef/X
+/ab\hdef/X
 Failed: unrecognized character follows \ at offset 3
 
-/(?X)ab\gdef/X
+/(?X)ab\hdef/X
 Failed: unrecognized character follows \ at offset 7
 
 /x{5,4}/
@@ -111,21 +111,21 @@ Failed: missing ) after comment at offset 7
 /(?z)abc/
 Failed: unrecognized character after (? at offset 2
 
-/.*b/
+/.*b/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char at start or follows newline
 Need char = 'b'
 
-/.*?b/
+/.*?b/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char at start or follows newline
 Need char = 'b'
 
-/cat|dog|elephant/
+/cat|dog|elephant/I
 Capturing subpattern count = 0
 No options
 No first char
@@ -135,7 +135,7 @@ No need char
     this sentences rambles on and on for a while and then reaches elephant
  0: elephant
 
-/cat|dog|elephant/S
+/cat|dog|elephant/IS
 Capturing subpattern count = 0
 No options
 No first char
@@ -146,7 +146,7 @@ Starting byte set: c d e
     this sentences rambles on and on for a while and then reaches elephant
  0: elephant
 
-/cat|dog|elephant/iS
+/cat|dog|elephant/IiS
 Capturing subpattern count = 0
 Options: caseless
 No first char
@@ -157,14 +157,14 @@ Starting byte set: C D E c d e
     this sentences rambles on and on for a while to elephant ElePhant
  0: elephant
 
-/a|[bcd]/S
+/a|[bcd]/IS
 Capturing subpattern count = 0
 No options
 No first char
 No need char
 Starting byte set: a b c d 
 
-/(a|[^\dZ])/S
+/(a|[^\dZ])/IS
 Capturing subpattern count = 1
 No options
 No first char
@@ -184,7 +184,7 @@ Starting byte set: \x00 \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0a
   \xed \xee \xef \xf0 \xf1 \xf2 \xf3 \xf4 \xf5 \xf6 \xf7 \xf8 \xf9 \xfa \xfb 
   \xfc \xfd \xfe \xff 
 
-/(a|b)*[\s]/S
+/(a|b)*[\s]/IS
 Capturing subpattern count = 1
 No options
 No first char
@@ -197,7 +197,7 @@ Failed: reference to non-existent subpattern at offset 6
 /{4,5}abc/
 Failed: nothing to repeat at offset 4
 
-/(a)(b)(c)\2/
+/(a)(b)(c)\2/I
 Capturing subpattern count = 3
 Max back reference = 2
 No options
@@ -228,7 +228,7 @@ Matched, but too many substrings
  2: b
  3: c
 
-/(a)bc|(a)(b)\2/
+/(a)bc|(a)(b)\2/I
 Capturing subpattern count = 3
 Max back reference = 2
 No options
@@ -270,7 +270,7 @@ Matched, but too many substrings
  2: a
  3: b
 
-/abc$/E
+/abc$/IE
 Capturing subpattern count = 0
 Options: dollar_endonly
 First char = 'a'
@@ -287,7 +287,7 @@ No match
 /(a)(b)(c)(d)(e)\6/
 Failed: reference to non-existent subpattern at offset 17
 
-/the quick brown fox/
+/the quick brown fox/I
 Capturing subpattern count = 0
 No options
 First char = 't'
@@ -297,7 +297,7 @@ Need char = 'x'
     this is a line with the quick brown fox
  0: the quick brown fox
 
-/the quick brown fox/A
+/the quick brown fox/IA
 Capturing subpattern count = 0
 Options: anchored
 No first char
@@ -312,7 +312,7 @@ No match
 /ab(?z)cd/
 Failed: unrecognized character after (? at offset 4
 
-/^abc|def/
+/^abc|def/I
 Capturing subpattern count = 0
 No options
 No first char
@@ -322,7 +322,7 @@ No need char
     abcdef\B
  0: def
 
-/.*((abc)$|(def))/
+/.*((abc)$|(def))/I
 Capturing subpattern count = 3
 Partial matching not supported
 No options
@@ -338,19 +338,19 @@ No need char
  2: <unset>
  3: def
 
-/abc/P
+/abc/IP
     abc
  0: abc
     *** Failers
 No match: POSIX code 17: match failed
     
-/^abc|def/P
+/^abc|def/IP
     abcdef
  0: abc
     abcdef\B
  0: def
 
-/.*((abc)$|(def))/P
+/.*((abc)$|(def))/IP
     defabc
  0: defabc
  1: abc
@@ -360,7 +360,7 @@ No match: POSIX code 17: match failed
  1: def
  3: def
   
-/the quick brown fox/P
+/the quick brown fox/IP
     the quick brown fox
  0: the quick brown fox
     *** Failers 
@@ -368,28 +368,28 @@ No match: POSIX code 17: match failed
     The Quick Brown Fox 
 No match: POSIX code 17: match failed
 
-/the quick brown fox/Pi
+/the quick brown fox/IPi
     the quick brown fox
  0: the quick brown fox
     The Quick Brown Fox 
  0: The Quick Brown Fox
 
-/abc.def/P
+/abc.def/IP
     *** Failers
 No match: POSIX code 17: match failed
     abc\ndef
 No match: POSIX code 17: match failed
     
-/abc$/P
+/abc$/IP
     abc
  0: abc
     abc\n 
  0: abc
 
-/(abc)\2/P
+/(abc)\2/IP
 Failed: POSIX code 15: bad back reference at offset 7     
 
-/(abc\1)/P
+/(abc\1)/IP
     abc
 No match: POSIX code 17: match failed
 
@@ -399,7 +399,7 @@ Failed: unmatched parentheses at offset 0
 /a[]b/
 Failed: missing terminating ] for character class at offset 4
 
-/[^aeiou ]{3,}/
+/[^aeiou ]{3,}/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
@@ -408,7 +408,7 @@ No need char
     co-processors, and for 
  0: -pr
     
-/<.*>/
+/<.*>/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
@@ -417,7 +417,7 @@ Need char = '>'
     abc<def>ghi<klm>nop
  0: <def>ghi<klm>
 
-/<.*?>/
+/<.*?>/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
@@ -426,7 +426,7 @@ Need char = '>'
     abc<def>ghi<klm>nop
  0: <def>
 
-/<.*>/U
+/<.*>/IU
 Capturing subpattern count = 0
 Partial matching not supported
 Options: ungreedy
@@ -435,7 +435,7 @@ Need char = '>'
     abc<def>ghi<klm>nop
  0: <def>
     
-/(?U)<.*>/
+/(?U)<.*>/I
 Capturing subpattern count = 0
 Partial matching not supported
 Options: ungreedy
@@ -444,7 +444,7 @@ Need char = '>'
     abc<def>ghi<klm>nop
  0: <def>
 
-/<.*?>/U
+/<.*?>/IU
 Capturing subpattern count = 0
 Partial matching not supported
 Options: ungreedy
@@ -453,7 +453,7 @@ Need char = '>'
     abc<def>ghi<klm>nop
  0: <def>ghi<klm>
     
-/={3,}/U
+/={3,}/IU
 Capturing subpattern count = 0
 Partial matching not supported
 Options: ungreedy
@@ -462,7 +462,7 @@ Need char = '='
     abc========def
  0: ===
     
-/(?U)={3,}?/
+/(?U)={3,}?/I
 Capturing subpattern count = 0
 Partial matching not supported
 Options: ungreedy
@@ -471,7 +471,7 @@ Need char = '='
     abc========def
  0: ========
     
-/(?<!bar|cattle)foo/
+/(?<!bar|cattle)foo/I
 Capturing subpattern count = 0
 No options
 First char = 'f'
@@ -496,65 +496,65 @@ 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/
+/(?i)abc/I
 Capturing subpattern count = 0
 Options: caseless
 First char = 'a' (caseless)
 Need char = 'c' (caseless)
 
-/(a|(?m)a)/
+/(a|(?m)a)/I
 Capturing subpattern count = 1
 No options
 First char = 'a'
 No need char
 
-/(?i)^1234/
+/(?i)^1234/I
 Capturing subpattern count = 0
 Options: anchored caseless
 No first char
 No need char
 
-/(^b|(?i)^d)/
+/(^b|(?i)^d)/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
 No need char
 
-/(?s).*/
+/(?s).*/I
 Capturing subpattern count = 0
 Partial matching not supported
 Options: anchored dotall
 No first char
 No need char
 
-/[abcd]/S
+/[abcd]/IS
 Capturing subpattern count = 0
 No options
 No first char
 No need char
 Starting byte set: a b c d 
 
-/(?i)[abcd]/S
+/(?i)[abcd]/IS
 Capturing subpattern count = 0
 Options: caseless
 No first char
 No need char
 Starting byte set: A B C D a b c d 
 
-/(?m)[xy]|(b|c)/S
+/(?m)[xy]|(b|c)/IS
 Capturing subpattern count = 1
 Options: multiline
 No first char
 No need char
 Starting byte set: b c x y 
 
-/(^a|^b)/m
+/(^a|^b)/Im
 Capturing subpattern count = 1
 Options: multiline
 First char at start or follows newline
 No need char
 
-/(?i)(^a|^b)/m
+/(?i)(^a|^b)/Im
 Capturing subpattern count = 1
 Options: caseless multiline
 First char at start or follows newline
@@ -567,6 +567,9 @@ Failed: conditional group contains more than two branches at offset 13
 Failed: conditional group contains more than two branches at offset 12
 
 /(?(1a)/
+Failed: missing ) at offset 6
+
+/(?(1a))/
 Failed: reference to non-existent subpattern at offset 6
 
 /(?(?i))/
@@ -576,9 +579,9 @@ Failed: assertion expected after (?( at offset 3
 Failed: reference to non-existent subpattern at offset 7
 
 /(?(?<ab))/
-Failed: unrecognized character after (?< at offset 5
+Failed: syntax error in subpattern name (missing terminator) at offset 7
 
-/((?s)blah)\s+\1/
+/((?s)blah)\s+\1/I
 Capturing subpattern count = 1
 Max back reference = 1
 Partial matching not supported
@@ -586,7 +589,7 @@ No options
 First char = 'b'
 Need char = 'h'
 
-/((?i)blah)\s+\1/
+/((?i)blah)\s+\1/I
 Capturing subpattern count = 1
 Max back reference = 1
 Partial matching not supported
@@ -594,16 +597,16 @@ No options
 First char = 'b' (caseless)
 Need char = 'h' (caseless)
 
-/((?i)b)/DS
+/((?i)b)/IDS
 ------------------------------------------------------------------
-  0  15 Bra 0
-  3   7 Bra 1
-  6  01 Opt
 8  NC b
- 10   7 Ket
- 13  00 Opt
- 15  15 Ket
18     End
+  0  17 Bra 0
+  3   9 Bra 1
+  8  01 Opt
10  NC b
+ 12   9 Ket
+ 15  00 Opt
+ 17  17 Ket
20     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 No options
@@ -611,7 +614,7 @@ First char = 'b' (caseless)
 No need char
 Study returned NULL
 
-/(a*b|(?i:c*(?-i)d))/S
+/(a*b|(?i:c*(?-i)d))/IS
 Capturing subpattern count = 1
 Partial matching not supported
 No options
@@ -619,7 +622,7 @@ No first char
 No need char
 Starting byte set: C a b c d 
 
-/a$/
+/a$/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
@@ -635,7 +638,7 @@ No match
     \Za\n   
 No match
 
-/a$/m
+/a$/Im
 Capturing subpattern count = 0
 Options: multiline
 First char = 'a'
@@ -651,19 +654,19 @@ No match
     \Za
 No match
     
-/\Aabc/m
+/\Aabc/Im
 Capturing subpattern count = 0
 Options: anchored multiline
 No first char
 No need char
 
-/^abc/m 
+/^abc/I
 Capturing subpattern count = 0
 Options: multiline
 First char at start or follows newline
 Need char = 'c'
 
-/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/
+/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/I
 Capturing subpattern count = 5
 Partial matching not supported
 Options: anchored
@@ -677,28 +680,28 @@ No need char
  4: bbbbccccc
  5: def
 
-/(?<=foo)[ab]/S
+/(?<=foo)[ab]/IS
 Capturing subpattern count = 0
 No options
 No first char
 No need char
 Starting byte set: a b 
 
-/(?<!foo)(alpha|omega)/S
+/(?<!foo)(alpha|omega)/IS
 Capturing subpattern count = 1
 No options
 No first char
 Need char = 'a'
 Starting byte set: a o 
 
-/(?!alphabet)[ab]/S
+/(?!alphabet)[ab]/IS
 Capturing subpattern count = 0
 No options
 No first char
 No need char
 Starting byte set: a b 
 
-/(?<=foo\n)^bar/m
+/(?<=foo\n)^bar/Im
 Capturing subpattern count = 0
 Options: multiline
 No first char
@@ -714,7 +717,7 @@ No match
     abc\nbarton 
 No match
 
-/^(?<=foo\n)bar/m
+/^(?<=foo\n)bar/Im
 Capturing subpattern count = 0
 Options: multiline
 First char at start or follows newline
@@ -730,7 +733,7 @@ No match
     abc\nbarton 
 No match
 
-/(?>^abc)/m
+/(?>^abc)/Im
 Capturing subpattern count = 0
 Options: multiline
 First char at start or follows newline
@@ -754,12 +757,8 @@ Failed: lookbehind assertion is not fixed length at offset 12
 Failed: lookbehind assertion is not fixed length at offset 13
 
 /The next three are in testinput2 because they have variable length branches/
-Capturing subpattern count = 0
-No options
-First char = 'T'
-Need char = 's'
 
-/(?<=bullock|donkey)-cart/
+/(?<=bullock|donkey)-cart/I
 Capturing subpattern count = 0
 No options
 First char = '-'
@@ -775,13 +774,13 @@ No match
     horse-and-cart    
 No match
       
-/(?<=ab(?i)x|y|z)/
+/(?<=ab(?i)x|y|z)/I
 Capturing subpattern count = 0
 No options
 No first char
 No need char
 
-/(?>.*)(?<=(abcd)|(xyz))/
+/(?>.*)(?<=(abcd)|(xyz))/I
 Capturing subpattern count = 2
 Partial matching not supported
 No options
@@ -795,7 +794,7 @@ No need char
  1: <unset>
  2: xyz
 
-/(?<=ab(?i)x(?-i)y|(?i)z|b)ZZ/
+/(?<=ab(?i)x(?-i)y|(?i)z|b)ZZ/I
 Capturing subpattern count = 0
 No options
 First char = 'Z'
@@ -823,7 +822,7 @@ No match
     bzz  
 No match
 
-/(?<!(foo)a)bar/
+/(?<!(foo)a)bar/I
 Capturing subpattern count = 1
 No options
 First char = 'b'
@@ -837,13 +836,13 @@ No match
     fooabar  
 No match
 
-/This one is here because Perl 5.005_02 doesn't fail it/
+/This one is here because Perl 5.005_02 doesn't fail it/I
 Capturing subpattern count = 0
 No options
 First char = 'T'
 Need char = 't'
 
-/^(a)?(?(1)a|b)+$/
+/^(a)?(?(1)a|b)+$/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
@@ -853,13 +852,13 @@ No match
     a 
 No match
 
-/This one is here because I think Perl 5.005_02 gets the setting of $1 wrong/
+/This one is here because I think Perl 5.005_02 gets the setting of $1 wrong/I
 Capturing subpattern count = 0
 No options
 First char = 'T'
 Need char = 'g'
 
-/^(a\1?){4}$/
+/^(a\1?){4}$/I
 Capturing subpattern count = 1
 Max back reference = 1
 Options: anchored
@@ -869,7 +868,7 @@ No need char
  0: aaaaaa
  1: aa
     
-/These are syntax tests from Perl 5.005/
+/These are syntax tests from Perl 5.005/I
 Capturing subpattern count = 0
 No options
 First char = 'T'
@@ -911,31 +910,31 @@ Failed: reference to non-existent subpattern at offset 2
 /(a)|\2/
 Failed: reference to non-existent subpattern at offset 6
 
-/a[b-a]/i
+/a[b-a]/Ii
 Failed: range out of order in character class at offset 4
 
-/a[]b/i
+/a[]b/Ii
 Failed: missing terminating ] for character class at offset 4
 
-/a[/i
+/a[/Ii
 Failed: missing terminating ] for character class at offset 2
 
-/*a/i
+/*a/Ii
 Failed: nothing to repeat at offset 0
 
-/(*)b/i
+/(*)b/Ii
 Failed: nothing to repeat at offset 1
 
-/abc)/i
+/abc)/Ii
 Failed: unmatched parentheses at offset 3
 
-/(abc/i
+/(abc/Ii
 Failed: missing ) at offset 4
 
-/a**/i
+/a**/Ii
 Failed: nothing to repeat at offset 2
 
-/)(/i
+/)(/Ii
 Failed: unmatched parentheses at offset 0
 
 /:(?:/
@@ -983,7 +982,7 @@ Failed: POSIX code 9: bad escape sequence at offset 4
 /abc/\i
 Failed: \ at end of pattern at offset 4
 
-/(a)bc(d)/
+/(a)bc(d)/I
 Capturing subpattern count = 2
 No options
 First char = 'a'
@@ -1003,7 +1002,7 @@ Need char = 'd'
  2: d
 copy substring 5 failed -7
      
-/(.{20})/
+/(.{20})/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
@@ -1021,7 +1020,7 @@ No need char
  1: abcdefghijklmnopqrst
  1G abcdefghijklmnopqrst (20)
      
-/(.{15})/
+/(.{15})/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
@@ -1036,7 +1035,7 @@ No need char
  1C abcdefghijklmno (15)
  1G abcdefghijklmno (15)
 
-/(.{16})/
+/(.{16})/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
@@ -1053,7 +1052,7 @@ No need char
  0L abcdefghijklmnop
  1L abcdefghijklmnop
     
-/^(a|(bc))de(f)/
+/^(a|(bc))de(f)/I
 Capturing subpattern count = 3
 Options: anchored
 No first char
@@ -1091,7 +1090,7 @@ get substring 4 failed -7
  3: f
  0C adef (4)
     
-/^abc\00def/
+/^abc\00def/I
 Capturing subpattern count = 0
 Options: anchored
 No first char
@@ -1103,15 +1102,15 @@ No need char
     
 /word ((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ 
 )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ )((?:[a-zA-Z0-9]+ 
-)?)?)?)?)?)?)?)?)?otherword/M
-Memory allocation (code space): 432
+)?)?)?)?)?)?)?)?)?otherword/IM
+Memory allocation (code space): 448
 Capturing subpattern count = 8
 Partial matching not supported
 No options
 First char = 'w'
 Need char = 'd'
 
-/.*X/D
+/.*X/ID
 ------------------------------------------------------------------
   0   7 Bra 0
   3     Any*
@@ -1125,7 +1124,7 @@ No options
 First char at start or follows newline
 Need char = 'X'
 
-/.*X/Ds
+/.*X/IDs
 ------------------------------------------------------------------
   0   7 Bra 0
   3     Any*
@@ -1139,18 +1138,18 @@ Options: anchored dotall
 No first char
 Need char = 'X'
 
-/(.*X|^B)/D
+/(.*X|^B)/ID
 ------------------------------------------------------------------
-  0  19 Bra 0
-  3   7 Bra 1
-  6     Any*
 8     X
- 10   6 Alt
- 13     ^
- 14     B
- 16  13 Ket
19  19 Ket
- 22     End
+  0  21 Bra 0
+  3   9 Bra 1
+  8     Any*
10     X
+ 12   6 Alt
+ 15     ^
+ 16     B
+ 18  15 Ket
21  21 Ket
+ 24     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Partial matching not supported
@@ -1158,18 +1157,18 @@ No options
 First char at start or follows newline
 No need char
 
-/(.*X|^B)/Ds
+/(.*X|^B)/IDs
 ------------------------------------------------------------------
-  0  19 Bra 0
-  3   7 Bra 1
-  6     Any*
 8     X
- 10   6 Alt
- 13     ^
- 14     B
- 16  13 Ket
19  19 Ket
- 22     End
+  0  21 Bra 0
+  3   9 Bra 1
+  8     Any*
10     X
+ 12   6 Alt
+ 15     ^
+ 16     B
+ 18  15 Ket
21  21 Ket
+ 24     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Partial matching not supported
@@ -1177,18 +1176,18 @@ Options: anchored dotall
 No first char
 No need char
     
-/(?s)(.*X|^B)/D
+/(?s)(.*X|^B)/ID
 ------------------------------------------------------------------
-  0  19 Bra 0
-  3   7 Bra 1
-  6     Any*
 8     X
- 10   6 Alt
- 13     ^
- 14     B
- 16  13 Ket
19  19 Ket
- 22     End
+  0  21 Bra 0
+  3   9 Bra 1
+  8     Any*
10     X
+ 12   6 Alt
+ 15     ^
+ 16     B
+ 18  15 Ket
21  21 Ket
+ 24     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Partial matching not supported
@@ -1196,7 +1195,7 @@ Options: anchored dotall
 No first char
 No need char
 
-/(?s:.*X|^B)/D
+/(?s:.*X|^B)/ID
 ------------------------------------------------------------------
   0  25 Bra 0
   3   9 Bra 0
@@ -1218,7 +1217,7 @@ No options
 First char at start or follows newline
 No need char
 
-/\Biss\B/+
+/\Biss\B/I+
 Capturing subpattern count = 0
 No options
 First char = 'i'
@@ -1227,12 +1226,12 @@ Need char = 's'
  0: iss
  0+ issippi
 
-/\Biss\B/+P
+/\Biss\B/I+P
     Mississippi
  0: iss
  0+ issippi
 
-/iss/G+
+/iss/IG+
 Capturing subpattern count = 0
 No options
 First char = 'i'
@@ -1243,7 +1242,7 @@ Need char = 's'
  0: iss
  0+ ippi
 
-/\Biss\B/G+
+/\Biss\B/IG+
 Capturing subpattern count = 0
 No options
 First char = 'i'
@@ -1252,7 +1251,7 @@ Need char = 's'
  0: iss
  0+ issippi
 
-/\Biss\B/g+
+/\Biss\B/Ig+
 Capturing subpattern count = 0
 No options
 First char = 'i'
@@ -1267,7 +1266,7 @@ No match
     Mississippi\A
 No match
 
-/(?<=[Ms])iss/g+
+/(?<=[Ms])iss/Ig+
 Capturing subpattern count = 0
 No options
 First char = 'i'
@@ -1278,7 +1277,7 @@ Need char = 's'
  0: iss
  0+ ippi
 
-/(?<=[Ms])iss/G+
+/(?<=[Ms])iss/IG+
 Capturing subpattern count = 0
 No options
 First char = 'i'
@@ -1287,7 +1286,7 @@ Need char = 's'
  0: iss
  0+ issippi
 
-/^iss/g+
+/^iss/Ig+
 Capturing subpattern count = 0
 Options: anchored
 No first char
@@ -1296,7 +1295,7 @@ No need char
  0: iss
  0+ issippi
     
-/.*iss/g+
+/.*iss/Ig+
 Capturing subpattern count = 0
 Partial matching not supported
 No options
@@ -1308,7 +1307,7 @@ Need char = 's'
  0: xyziss
  0+ pqr
 
-/.i./+g
+/.i./I+g
 Capturing subpattern count = 0
 No options
 No first char
@@ -1338,7 +1337,7 @@ Need char = 'i'
  0: Mis
  0+ souri river
 
-/^.is/+g
+/^.is/I+g
 Capturing subpattern count = 0
 Options: anchored
 No first char
@@ -1347,7 +1346,7 @@ No need char
  0: Mis
  0+ sissippi
 
-/^ab\n/g+
+/^ab\n/Ig+
 Capturing subpattern count = 0
 Options: anchored
 No first char
@@ -1356,7 +1355,7 @@ No need char
  0: ab\x0a
  0+ ab\x0acd
 
-/^ab\n/mg+
+/^ab\n/Img+
 Capturing subpattern count = 0
 Options: multiline
 First char at start or follows newline
@@ -1367,272 +1366,272 @@ Need char = 10
  0: ab\x0a
  0+ cd
 
-/abc/
+/abc/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'c'
 
-/abc|bac/
+/abc|bac/I
 Capturing subpattern count = 0
 No options
 No first char
 Need char = 'c'
 
-/(abc|bac)/
+/(abc|bac)/I
 Capturing subpattern count = 1
 No options
 No first char
 Need char = 'c'
 
-/(abc|(c|dc))/
+/(abc|(c|dc))/I
 Capturing subpattern count = 2
 No options
 No first char
 Need char = 'c'
 
-/(abc|(d|de)c)/
+/(abc|(d|de)c)/I
 Capturing subpattern count = 2
 No options
 No first char
 Need char = 'c'
 
-/a*/
+/a*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 No first char
 No need char
 
-/a+/
+/a+/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 No need char
 
-/(baa|a+)/
+/(baa|a+)/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
 No first char
 Need char = 'a'
 
-/a{0,3}/
+/a{0,3}/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 No first char
 No need char
 
-/baa{3,}/
+/baa{3,}/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'b'
 Need char = 'a'
 
-/"([^\\"]+|\\.)*"/
+/"([^\\"]+|\\.)*"/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
 First char = '"'
 Need char = '"'
 
-/(abc|ab[cd])/
+/(abc|ab[cd])/I
 Capturing subpattern count = 1
 No options
 First char = 'a'
 No need char
 
-/(a|.)/
+/(a|.)/I
 Capturing subpattern count = 1
 No options
 No first char
 No need char
 
-/a|ba|\w/
+/a|ba|\w/I
 Capturing subpattern count = 0
 No options
 No first char
 No need char
 
-/abc(?=pqr)/
+/abc(?=pqr)/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'r'
 
-/...(?<=abc)/
+/...(?<=abc)/I
 Capturing subpattern count = 0
 No options
 No first char
 No need char
 
-/abc(?!pqr)/
+/abc(?!pqr)/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'c'
 
-/ab./
+/ab./I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'b'
 
-/ab[xyz]/
+/ab[xyz]/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'b'
 
-/abc*/
+/abc*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 Need char = 'b'
 
-/ab.c*/
+/ab.c*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 Need char = 'b'
 
-/a.c*/
+/a.c*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 No need char
 
-/.c*/
+/.c*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 No first char
 No need char
 
-/ac*/
+/ac*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 No need char
 
-/(a.c*|b.c*)/
+/(a.c*|b.c*)/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
 No first char
 No need char
 
-/a.c*|aba/
+/a.c*|aba/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 No need char
 
-/.+a/
+/.+a/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 No first char
 Need char = 'a'
 
-/(?=abcda)a.*/
+/(?=abcda)a.*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 Need char = 'a'
 
-/(?=a)a.*/
+/(?=a)a.*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 No need char
 
-/a(b)*/
+/a(b)*/I
 Capturing subpattern count = 1
 No options
 First char = 'a'
 No need char
 
-/a\d*/
+/a\d*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 No need char
 
-/ab\d*/
+/ab\d*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 Need char = 'b'
 
-/a(\d)*/
+/a(\d)*/I
 Capturing subpattern count = 1
 No options
 First char = 'a'
 No need char
 
-/abcde{0,0}/
+/abcde{0,0}/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'd'
 
-/ab\d+/
+/ab\d+/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
 First char = 'a'
 Need char = 'b'
 
-/a(?(1)b)/
+/a(?(1)b)/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 No need char
 
-/a(?(1)bag|big)/
+/a(?(1)bag|big)/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'g'
 
-/a(?(1)bag|big)*/
+/a(?(1)bag|big)*/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 No need char
 
-/a(?(1)bag|big)+/
+/a(?(1)bag|big)+/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'g'
 
-/a(?(1)b..|b..)/
+/a(?(1)b..|b..)/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'b'
 
-/ab\d{0}e/
+/ab\d{0}e/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'e'
 
-/a?b?/
+/a?b?/I
 Capturing subpattern count = 0
 No options
 No first char
@@ -1650,7 +1649,7 @@ No need char
     \N     
 No match
     
-/|-/
+/|-/I
 Capturing subpattern count = 0
 No options
 No first char
@@ -1666,7 +1665,7 @@ No need char
     \Nabc     
 No match
 
-/a*(b+)(z)(z)/P
+/a*(b+)(z)(z)/IP
     aaaabbbbzzzz
  0: aaaabbbbzz
  1: bbbb
@@ -1693,7 +1692,7 @@ No match
  2: z
  3: z
     
-/^.?abcd/S 
+/^.?abcd/I
 Capturing subpattern count = 0
 Options: anchored
 No first char
@@ -1707,7 +1706,7 @@ Study returned NULL
   (?R)          # Recurse - i.e. nested bracketed string
   )*            # Zero or more contents
   \)            # Closing )
-  /x
+  /Ix
 Capturing subpattern count = 0
 Partial matching not supported
 Options: extended
@@ -1736,7 +1735,7 @@ No match
     (abcd  
 No match
 
-/\(  ( (?>[^()]+) | (?R) )* \) /xg
+/\(  ( (?>[^()]+) | (?R) )* \) /Ixg
 Capturing subpattern count = 1
 Partial matching not supported
 Options: extended
@@ -1751,7 +1750,7 @@ Need char = ')'
  0: (x(y)z)
  1: z
 
-/\(  (?: (?>[^()]+) | (?R) ) \) /x
+/\(  (?: (?>[^()]+) | (?R) ) \) /Ix
 Capturing subpattern count = 0
 Partial matching not supported
 Options: extended
@@ -1770,7 +1769,7 @@ No match
     ()   
 No match
 
-/\(  (?: (?>[^()]+) | (?R) )? \) /x
+/\(  (?: (?>[^()]+) | (?R) )? \) /Ix
 Capturing subpattern count = 0
 Partial matching not supported
 Options: extended
@@ -1781,7 +1780,7 @@ Need char = ')'
     12(abcde(fsh)xyz(foo(bar))lmno)89
  0: (fsh)
 
-/\(  ( (?>[^()]+) | (?R) )* \) /x
+/\(  ( (?>[^()]+) | (?R) )* \) /Ix
 Capturing subpattern count = 1
 Partial matching not supported
 Options: extended
@@ -1791,7 +1790,7 @@ Need char = ')'
  0: (ab(xy)cd)
  1: cd
 
-/\( ( ( (?>[^()]+) | (?R) )* ) \) /x
+/\( ( ( (?>[^()]+) | (?R) )* ) \) /Ix
 Capturing subpattern count = 2
 Partial matching not supported
 Options: extended
@@ -1802,7 +1801,7 @@ Need char = ')'
  1: ab(xy)cd
  2: cd
 
-/\( (123)? ( ( (?>[^()]+) | (?R) )* ) \) /x
+/\( (123)? ( ( (?>[^()]+) | (?R) )* ) \) /Ix
 Capturing subpattern count = 3
 Partial matching not supported
 Options: extended
@@ -1819,7 +1818,7 @@ Need char = ')'
  2: ab(xy)cd
  3: cd
 
-/\( ( (123)? ( (?>[^()]+) | (?R) )* ) \) /x
+/\( ( (123)? ( (?>[^()]+) | (?R) )* ) \) /Ix
 Capturing subpattern count = 3
 Partial matching not supported
 Options: extended
@@ -1836,7 +1835,7 @@ Need char = ')'
  2: 123
  3: cd
 
-/\( (((((((((( ( (?>[^()]+) | (?R) )* )))))))))) \) /x
+/\( (((((((((( ( (?>[^()]+) | (?R) )* )))))))))) \) /Ix
 Capturing subpattern count = 11
 Partial matching not supported
 Options: extended
@@ -1856,7 +1855,7 @@ Need char = ')'
 10: ab(xy)cd
 11: cd
 
-/\( ( ( (?>[^()<>]+) | ((?>[^()]+)) | (?R) )* ) \) /x
+/\( ( ( (?>[^()<>]+) | ((?>[^()]+)) | (?R) )* ) \) /Ix
 Capturing subpattern count = 3
 Partial matching not supported
 Options: extended
@@ -1868,7 +1867,7 @@ Need char = ')'
  2: 123
  3: <unset>
 
-/\( ( ( (?>[^()]+) | ((?R)) )* ) \) /x
+/\( ( ( (?>[^()]+) | ((?R)) )* ) \) /Ix
 Capturing subpattern count = 3
 Partial matching not supported
 Options: extended
@@ -2185,16 +2184,16 @@ No options
 No first char
 No need char
 
-/[[.ch.]]/
+/[[.ch.]]/I
 Failed: POSIX collating elements are not supported at offset 1
 
-/[[=ch=]]/
+/[[=ch=]]/I
 Failed: POSIX collating elements are not supported at offset 1
 
-/[[:rhubarb:]]/
+/[[:rhubarb:]]/I
 Failed: unknown POSIX class name at offset 3
 
-/[[:upper:]]/i
+/[[:upper:]]/Ii
 Capturing subpattern count = 0
 Options: caseless
 No first char
@@ -2204,7 +2203,7 @@ No need char
     a 
  0: a
     
-/[[:lower:]]/i
+/[[:lower:]]/Ii
 Capturing subpattern count = 0
 Options: caseless
 No first char
@@ -2214,7 +2213,7 @@ No need char
     a 
  0: a
 
-/((?-i)[[:lower:]])[[:lower:]]/i
+/((?-i)[[:lower:]])[[:lower:]]/Ii
 Capturing subpattern count = 1
 Options: caseless
 No first char
@@ -2233,19 +2232,19 @@ No match
     AB        
 No match
 
-/[\200-\110]/
+/[\200-\110]/I
 Failed: range out of order in character class at offset 9
 
-/^(?(0)f|b)oo/
+/^(?(0)f|b)oo/I
 Failed: invalid condition (?(0) at offset 6
 
-/This one's here because of the large output vector needed/
+/This one's here because of the large output vector needed/I
 Capturing subpattern count = 0
 No options
 First char = 'T'
 Need char = 'd'
 
-/(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\w+)\s+(\270)/
+/(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\d+(?:\s|$))(\w+)\s+(\270)/I
 Capturing subpattern count = 271
 Max back reference = 270
 Partial matching not supported
@@ -2526,13 +2525,13 @@ No need char
 270: ABC
 271: ABC
 
-/This one's here because Perl does this differently and PCRE can't at present/
+/This one's here because Perl does this differently and PCRE can't at present/I
 Capturing subpattern count = 0
 No options
 First char = 'T'
 Need char = 't'
 
-/(main(O)?)+/
+/(main(O)?)+/I
 Capturing subpattern count = 2
 No options
 First char = 'm'
@@ -2545,13 +2544,13 @@ Need char = 'n'
  1: main
  2: O
     
-/These are all cases where Perl does it differently (nested captures)/
+/These are all cases where Perl does it differently (nested captures)/I
 Capturing subpattern count = 1
 No options
 First char = 'T'
 Need char = 's'
 
-/^(a(b)?)+$/
+/^(a(b)?)+$/I
 Capturing subpattern count = 2
 Options: anchored
 No first char
@@ -2561,7 +2560,7 @@ No need char
  1: a
  2: b
    
-/^(aa(bb)?)+$/
+/^(aa(bb)?)+$/I
 Capturing subpattern count = 2
 Options: anchored
 No first char
@@ -2571,7 +2570,7 @@ No need char
  1: aa
  2: bb
     
-/^(aa|aa(bb))+$/
+/^(aa|aa(bb))+$/I
 Capturing subpattern count = 2
 Options: anchored
 No first char
@@ -2581,7 +2580,7 @@ No need char
  1: aa
  2: bb
     
-/^(aa(bb)??)+$/
+/^(aa(bb)??)+$/I
 Capturing subpattern count = 2
 Options: anchored
 No first char
@@ -2591,7 +2590,7 @@ No need char
  1: aa
  2: bb
     
-/^(?:aa(bb)?)+$/
+/^(?:aa(bb)?)+$/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
@@ -2600,7 +2599,7 @@ No need char
  0: aabbaa
  1: bb
     
-/^(aa(b(b))?)+$/
+/^(aa(b(b))?)+$/I
 Capturing subpattern count = 3
 Options: anchored
 No first char
@@ -2611,7 +2610,7 @@ No need char
  2: bb
  3: b
 
-/^(?:aa(b(b))?)+$/
+/^(?:aa(b(b))?)+$/I
 Capturing subpattern count = 2
 Options: anchored
 No first char
@@ -2621,7 +2620,7 @@ No need char
  1: bb
  2: b
 
-/^(?:aa(b(?:b))?)+$/
+/^(?:aa(b(?:b))?)+$/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
@@ -2630,7 +2629,7 @@ No need char
  0: aabbaa
  1: bb
 
-/^(?:aa(bb(?:b))?)+$/
+/^(?:aa(bb(?:b))?)+$/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
@@ -2639,7 +2638,7 @@ No need char
  0: aabbbaa
  1: bbb
     
-/^(?:aa(b(?:bb))?)+$/
+/^(?:aa(b(?:bb))?)+$/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
@@ -2648,7 +2647,7 @@ No need char
  0: aabbbaa
  1: bbb
 
-/^(?:aa(?:b(b))?)+$/
+/^(?:aa(?:b(b))?)+$/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
@@ -2657,7 +2656,7 @@ No need char
  0: aabbaa
  1: b
 
-/^(?:aa(?:b(bb))?)+$/
+/^(?:aa(?:b(bb))?)+$/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
@@ -2666,7 +2665,7 @@ No need char
  0: aabbbaa
  1: bb
 
-/^(aa(b(bb))?)+$/
+/^(aa(b(bb))?)+$/I
 Capturing subpattern count = 3
 Options: anchored
 No first char
@@ -2677,7 +2676,7 @@ No need char
  2: bbb
  3: bb
 
-/^(aa(bb(bb))?)+$/
+/^(aa(bb(bb))?)+$/I
 Capturing subpattern count = 3
 Options: anchored
 No first char
@@ -2688,13 +2687,13 @@ No need char
  2: bbbb
  3: bb
 
-/--------------------------------------------------------------------/ 
+/--------------------------------------------------------------------/I 
 Capturing subpattern count = 0
 No options
 First char = '-'
 Need char = '-'
     
-/#/xMD
+/#/IxMD
 Memory allocation (code space): 7
 ------------------------------------------------------------------
   0   3 Bra 0
@@ -2706,7 +2705,7 @@ Options: extended
 No first char
 No need char
 
-/a#/xMD
+/a#/IxMD
 Memory allocation (code space): 9
 ------------------------------------------------------------------
   0   5 Bra 0
@@ -2767,15 +2766,15 @@ No match
 
 /(a(?i)b)/D
 ------------------------------------------------------------------
-  0  17 Bra 0
-  3   9 Bra 1
-  6     a
 8  01 Opt
- 10  NC b
- 12   9 Ket
- 15  00 Opt
- 17  17 Ket
- 20     End
+  0  19 Bra 0
+  3  11 Bra 1
+  8     a
10  01 Opt
+ 12  NC b
+ 14  11 Ket
+ 17  00 Opt
+ 19  19 Ket
+ 22     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 No options
@@ -2792,7 +2791,7 @@ No match
     AB  
 No match
     
-/   (?i)abc/xD
+/   (?i)abc/IxD
 ------------------------------------------------------------------
   0   9 Bra 0
   3  NC abc
@@ -2805,7 +2804,7 @@ First char = 'a' (caseless)
 Need char = 'c' (caseless)
 
 /#this is a comment
-  (?i)abc/xD
+  (?i)abc/IxD
 ------------------------------------------------------------------
   0   9 Bra 0
   3  NC abc
@@ -2924,13 +2923,11 @@ Need char = 'c'
 
 /x*+\w/D
 ------------------------------------------------------------------
-  0  12 Bra 0
-  3   5 Once
-  6     x*
-  8   5 Ket
- 11     \w
- 12  12 Ket
- 15     End
+  0   6 Bra 0
+  3     x*+
+  5     \w
+  6   6 Ket
+  9     End
 ------------------------------------------------------------------
 Capturing subpattern count = 0
 Partial matching not supported
@@ -2944,12 +2941,10 @@ No match
     
 /x?+/D
 ------------------------------------------------------------------
-  0  11 Bra 0
-  3   5 Once
-  6     x?
-  8   5 Ket
- 11  11 Ket
- 14     End
+  0   5 Bra 0
+  3     x?+
+  5   5 Ket
+  8     End
 ------------------------------------------------------------------
 Capturing subpattern count = 0
 No options
@@ -2958,12 +2953,10 @@ No need char
 
 /x++/D
 ------------------------------------------------------------------
-  0  11 Bra 0
-  3   5 Once
-  6     x+
-  8   5 Ket
- 11  11 Ket
- 14     End
+  0   5 Bra 0
+  3     x++
+  5   5 Ket
+  8     End
 ------------------------------------------------------------------
 Capturing subpattern count = 0
 Partial matching not supported
@@ -2976,7 +2969,7 @@ No need char
   0  15 Bra 0
   3   9 Once
   6     x
-  8     x{,2}
+  8     x{0,2}
  12   9 Ket
  15  15 Ket
  18     End
@@ -2989,22 +2982,22 @@ No need char
 
 /(x)*+/D
 ------------------------------------------------------------------
-  0  18 Bra 0
-  3  12 Once
+  0  20 Bra 0
+  3  14 Once
   6     Brazero
-  7   5 Bra 1
- 10     x
- 12   5 KetRmax
- 15  12 Ket
18  18 Ket
- 21     End
+  7   7 Bra 1
+ 12     x
+ 14   7 KetRmax
+ 17  14 Ket
20  20 Ket
+ 23     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 No options
 No first char
 No need char
 
-/^(\w++|\s++)*$/
+/^(\w++|\s++)*$/I
 Capturing subpattern count = 1
 Partial matching not supported
 Options: anchored
@@ -3018,7 +3011,7 @@ No match
     this is not a line with only words and spaces!
 No match
     
-/(\d++)(\w)/
+/(\d++)(\w)/I
 Capturing subpattern count = 2
 Partial matching not supported
 No options
@@ -3033,7 +3026,7 @@ No match
     12345+ 
 No match
 
-/a++b/
+/a++b/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
@@ -3042,7 +3035,7 @@ Need char = 'b'
     aaab
  0: aaab
 
-/(a++b)/
+/(a++b)/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
@@ -3052,7 +3045,7 @@ Need char = 'b'
  0: aaab
  1: aaab
 
-/(a++)b/
+/(a++)b/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
@@ -3062,7 +3055,7 @@ Need char = 'b'
  0: aaab
  1: aaa
 
-/([^()]++|\([^()]*\))+/
+/([^()]++|\([^()]*\))+/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
@@ -3072,7 +3065,7 @@ No need char
  0: abc(ade)ufh()()x
  1: x
     
-/\(([^()]++|\([^()]+\))+\)/ 
+/\(([^()]++|\([^()]+\))+\)/I 
 Capturing subpattern count = 1
 Partial matching not supported
 No options
@@ -3091,52 +3084,50 @@ No match
 
 /(abc){1,3}+/D
 ------------------------------------------------------------------
-  0  53 Bra 0
-  3  47 Once
-  6   9 Bra 1
 9     abc
- 15   9 Ket
18     Brazero
19  28 Bra 0
- 22   9 Bra 1
- 25     abc
- 31   9 Ket
- 34     Brazero
- 35   9 Bra 1
38     abc
44   9 Ket
47  28 Ket
- 50  47 Ket
- 53  53 Ket
56     End
+  0  59 Bra 0
+  3  53 Once
+  6  11 Bra 1
11     abc
+ 17  11 Ket
20     Brazero
21  32 Bra 0
+ 24  11 Bra 1
+ 29     abc
+ 35  11 Ket
+ 38     Brazero
+ 39  11 Bra 1
44     abc
50  11 Ket
53  32 Ket
+ 56  53 Ket
+ 59  59 Ket
62     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 No options
 First char = 'a'
 Need char = 'c'
 
-/a+?+/
+/a+?+/I
 Failed: nothing to repeat at offset 3
 
-/a{2,3}?+b/
+/a{2,3}?+b/I
 Failed: nothing to repeat at offset 7
 
-/(?U)a+?+/
+/(?U)a+?+/I
 Failed: nothing to repeat at offset 7
 
-/a{2,3}?+b/U
+/a{2,3}?+b/IU
 Failed: nothing to repeat at offset 7
 
 /x(?U)a++b/D
 ------------------------------------------------------------------
-  0  15 Bra 0
+  0   9 Bra 0
   3     x
-  5   5 Once
-  8     a+
- 10   5 Ket
- 13     b
- 15  15 Ket
- 18     End
+  5     a++
+  7     b
+  9   9 Ket
+ 12     End
 ------------------------------------------------------------------
 Capturing subpattern count = 0
 Partial matching not supported
@@ -3148,14 +3139,12 @@ Need char = 'b'
 
 /(?U)xa++b/D
 ------------------------------------------------------------------
-  0  15 Bra 0
+  0   9 Bra 0
   3     x
-  5   5 Once
-  8     a+
- 10   5 Ket
- 13     b
- 15  15 Ket
- 18     End
+  5     a++
+  7     b
+  9   9 Ket
+ 12     End
 ------------------------------------------------------------------
 Capturing subpattern count = 0
 Partial matching not supported
@@ -3167,24 +3156,24 @@ Need char = 'b'
 
 /^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/D
 ------------------------------------------------------------------
-  0 106 Bra 0
+  0 116 Bra 0
   3     ^
-  4  99 Bra 1
-  7   5 Bra 2
- 10     a+
- 12   5 Ket
- 15  37 Bra 3
18     [ab]+?
- 52  37 Ket
55  37 Bra 4
58     [bc]+
- 92  37 Ket
- 95   5 Bra 5
- 98     \w*
-100   5 Ket
-103  99 Ket
-106 106 Ket
-109     End
+  4 109 Bra 1
+  9   7 Bra 2
+ 14     a+
+ 16   7 Ket
+ 19  39 Bra 3
24     [ab]+?
+ 58  39 Ket
61  39 Bra 4
66     [bc]+
+100  39 Ket
+103   7 Bra 5
+108     \w*
+110   7 Ket
+113 109 Ket
+116 116 Ket
+119     End
 ------------------------------------------------------------------
 Capturing subpattern count = 5
 Partial matching not supported
@@ -3197,7 +3186,7 @@ No need char
   0  10 Bra 0
   3     ^
   4     x
-  6     a+?
+  6     a++
   8     b
  10  10 Ket
  13     End
@@ -3210,15 +3199,15 @@ Need char = 'b'
 
 /^x(?U)(a+)b/D
 ------------------------------------------------------------------
-  0  16 Bra 0
+  0  18 Bra 0
   3     ^
   4     x
-  6   5 Bra 1
 9     a+?
- 11   5 Ket
- 14     b
- 16  16 Ket
19     End
+  6   7 Bra 1
11     a+?
+ 13   7 Ket
+ 16     b
+ 18  18 Ket
21     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Partial matching not supported
@@ -3226,40 +3215,40 @@ Options: anchored
 No first char
 Need char = 'b'
 
-/[.x.]/
+/[.x.]/I
 Failed: POSIX collating elements are not supported at offset 0
 
-/[=x=]/
+/[=x=]/I
 Failed: POSIX collating elements are not supported at offset 0
 
-/[:x:]/
+/[:x:]/I
 Failed: POSIX named classes are supported only within a class at offset 0
 
-/\l/
+/\l/I
 Failed: PCRE does not support \L, \l, \N, \U, or \u at offset 1
 
-/\L/
+/\L/I
 Failed: PCRE does not support \L, \l, \N, \U, or \u at offset 1
 
-/\N{name}/
+/\N{name}/I
 Failed: PCRE does not support \L, \l, \N, \U, or \u at offset 1
 
-/\u/
+/\u/I
 Failed: PCRE does not support \L, \l, \N, \U, or \u at offset 1
 
-/\U/
+/\U/I
 Failed: PCRE does not support \L, \l, \N, \U, or \u at offset 1
 
-/[/
+/[/I
 Failed: missing terminating ] for character class at offset 1
 
-/[a-/
+/[a-/I
 Failed: missing terminating ] for character class at offset 3
 
-/[[:space:]/
+/[[:space:]/I
 Failed: missing terminating ] for character class at offset 10
 
-/[\s]/DM
+/[\s]/IDM
 Memory allocation (code space): 40
 ------------------------------------------------------------------
   0  36 Bra 0
@@ -3272,7 +3261,7 @@ No options
 No first char
 No need char
 
-/[[:space:]]/DM
+/[[:space:]]/IDM
 Memory allocation (code space): 40
 ------------------------------------------------------------------
   0  36 Bra 0
@@ -3285,7 +3274,7 @@ No options
 No first char
 No need char
 
-/[[:space:]abcde]/DM
+/[[:space:]abcde]/IDM
 Memory allocation (code space): 40
 ------------------------------------------------------------------
   0  36 Bra 0
@@ -3298,7 +3287,7 @@ No options
 No first char
 No need char
 
-/< (?: (?(R) \d++  | [^<>]*+) | (?R)) * >/x
+/< (?: (?(R) \d++  | [^<>]*+) | (?R)) * >/Ix
 Capturing subpattern count = 0
 Partial matching not supported
 Options: extended
@@ -3321,7 +3310,7 @@ No match
     <abc
 No match
 
-|8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|DM
+|8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDM
 Memory allocation (code space): 826
 ------------------------------------------------------------------
   0 822 Bra 0
@@ -3335,7 +3324,7 @@ No options
 First char = '8'
 Need char = 'X'
 
-|\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|DM
+|\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\<EjmhUZ\?\.akp2dF\>qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b|IDM
 Memory allocation (code space): 816
 ------------------------------------------------------------------
   0 812 Bra 0
@@ -3412,7 +3401,7 @@ No options
 First char = 'a'
 No need char
 
-/(?=abc).xyz/iI
+/(?=abc).xyz/IiI
 Capturing subpattern count = 0
 Options: caseless
 First char = 'a' (caseless)
@@ -3540,7 +3529,7 @@ No options
 First char = 'a'
 Need char = 'b'
 
-/^a/mI
+/^a/Im
 Capturing subpattern count = 0
 Options: multiline
 First char at start or follows newline
@@ -3574,7 +3563,7 @@ No first char
 Need char = 'd' (caseless)
 Starting byte set: a b 
 
-/abc(?C)def/
+/abc(?C)def/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
@@ -3596,7 +3585,7 @@ No match
   0 ^  ^        d
 No match
 
-/abc(?C)de(?C1)f/
+/abc(?C)de(?C1)f/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
@@ -3607,7 +3596,7 @@ Need char = 'f'
   1    ^    ^     f
  0: abcdef
     
-/(?C1)\dabc(?C2)def/ 
+/(?C1)\dabc(?C2)def/I 
 Capturing subpattern count = 0
 No options
 No first char
@@ -3632,22 +3621,22 @@ No match
   1      ^     \d
 No match
     
-/(?C255)ab/
+/(?C255)ab/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'b'
 
-/(?C256)ab/
+/(?C256)ab/I
 Failed: number after (?C is > 255 at offset 6
 
-/(?Cab)xx/ 
+/(?Cab)xx/I 
 Failed: closing ) for (?C expected at offset 3
 
-/(?C12vr)x/
+/(?C12vr)x/I
 Failed: closing ) for (?C expected at offset 5
 
-/abc(?C)def/
+/abc(?C)def/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
@@ -3659,7 +3648,7 @@ No match
   0         ^  ^       d
  0: abcdef
 
-/(abc)(?C)de(?C1)f/
+/(abc)(?C)de(?C1)f/I
 Capturing subpattern count = 1
 No options
 First char = 'a'
@@ -3694,7 +3683,7 @@ No match
   1    ^    ^     f
 No match
     
-/(?C0)(abc(?C1))*/
+/(?C0)(abc(?C1))*/I
 Capturing subpattern count = 1
 No options
 No first char
@@ -3727,7 +3716,7 @@ No need char
  0: abcabc
  1: abc
 
-/(\d{3}(?C))*/
+/(\d{3}(?C))*/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
@@ -3770,7 +3759,7 @@ Callout 0: last capture = 1
  0: 123456789
  1: 789
 
-/((xyz)(?C)p|(?C1)xyzabc)/
+/((xyz)(?C)p|(?C1)xyzabc)/I
 Capturing subpattern count = 2
 No options
 First char = 'x'
@@ -3789,7 +3778,7 @@ Callout 1: last capture = -1
  0: xyzabc
  1: xyzabc
 
-/(X)((xyz)(?C)p|(?C1)xyzabc)/
+/(X)((xyz)(?C)p|(?C1)xyzabc)/I
 Capturing subpattern count = 3
 No options
 First char = 'X'
@@ -3811,7 +3800,7 @@ Callout 1: last capture = 1
  1: X
  2: xyzabc
 
-/(?=(abc))(?C)abcdef/
+/(?=(abc))(?C)abcdef/I
 Capturing subpattern count = 1
 No options
 First char = 'a'
@@ -3825,7 +3814,7 @@ Callout 0: last capture = 1
  0: abcdef
  1: abc
     
-/(?!(abc)(?C1)d)(?C2)abcxyz/
+/(?!(abc)(?C1)d)(?C2)abcxyz/I
 Capturing subpattern count = 1
 No options
 First char = 'a'
@@ -3842,7 +3831,7 @@ Callout 2: last capture = -1
     ^          a
  0: abcxyz
 
-/(?<=(abc)(?C))xyz/
+/(?<=(abc)(?C))xyz/I
 Capturing subpattern count = 1
 No options
 First char = 'x'
@@ -3856,7 +3845,7 @@ Callout 0: last capture = 1
  0: xyz
  1: abc
    
-/a(b+)(c*)(?C1)/
+/a(b+)(c*)(?C1)/I
 Capturing subpattern count = 2
 Partial matching not supported
 No options
@@ -3882,7 +3871,7 @@ Callout data = 1
 Callout data = 1
 No match
 
-/a(b+?)(c*?)(?C1)/
+/a(b+?)(c*?)(?C1)/I
 Capturing subpattern count = 2
 Partial matching not supported
 No options
@@ -3908,35 +3897,35 @@ Callout data = 1
 Callout data = 1
 No match
    
-/(?C)abc/ 
+/(?C)abc/I 
 Capturing subpattern count = 0
 No options
 First char = 'a'
 Need char = 'c'
 
-/(?C)^abc/
+/(?C)^abc/I
 Capturing subpattern count = 0
 Options: anchored
 No first char
 No need char
 
-/(?C)a|b/S
+/(?C)a|b/IS
 Capturing subpattern count = 0
 No options
 No first char
 No need char
 Starting byte set: a b 
 
-/(?R)/
+/(?R)/I
 Failed: recursive call could loop indefinitely at offset 3
 
-/(a|(?R))/
+/(a|(?R))/I
 Failed: recursive call could loop indefinitely at offset 6
 
-/(ab|(bc|(de|(?R))))/
+/(ab|(bc|(de|(?R))))/I
 Failed: recursive call could loop indefinitely at offset 15
 
-/x(ab|(bc|(de|(?R))))/
+/x(ab|(bc|(de|(?R))))/I
 Capturing subpattern count = 3
 No options
 First char = 'x'
@@ -3968,13 +3957,13 @@ No match
     xyab   
 No match
 
-/(ab|(bc|(de|(?1))))/
+/(ab|(bc|(de|(?1))))/I
 Failed: recursive call could loop indefinitely at offset 15
 
-/x(ab|(bc|(de|(?1)x)x)x)/
+/x(ab|(bc|(de|(?1)x)x)x)/I
 Failed: recursive call could loop indefinitely at offset 16
 
-/^([^()]|\((?1)*\))*$/
+/^([^()]|\((?1)*\))*$/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
@@ -3993,7 +3982,7 @@ No match
     a(b(c)d  
 No match
 
-/^>abc>([^()]|\((?1)*\))*<xyz<$/
+/^>abc>([^()]|\((?1)*\))*<xyz<$/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
@@ -4010,16 +3999,16 @@ Need char = '<'
 
 /(a(?1)b)/D
 ------------------------------------------------------------------
-  0  22 Bra 0
-  3  16 Bra 1
-  6     a
 8   6 Once
- 11   3 Recurse
- 14   6 Ket
- 17     b
19  16 Ket
- 22  22 Ket
- 25     End
+  0  24 Bra 0
+  3  18 Bra 1
+  8     a
10   6 Once
+ 13   3 Recurse
+ 16   6 Ket
+ 19     b
21  18 Ket
+ 24  24 Ket
+ 27     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 No options
@@ -4028,23 +4017,23 @@ Need char = 'b'
 
 /(a(?1)+b)/D
 ------------------------------------------------------------------
-  0  22 Bra 0
-  3  16 Bra 1
-  6     a
 8   6 Once
- 11   3 Recurse
- 14   6 KetRmax
- 17     b
19  16 Ket
- 22  22 Ket
- 25     End
+  0  24 Bra 0
+  3  18 Bra 1
+  8     a
10   6 Once
+ 13   3 Recurse
+ 16   6 KetRmax
+ 19     b
21  18 Ket
+ 24  24 Ket
+ 27     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 No options
 First char = 'a'
 Need char = 'b'
 
-/^\W*(?:((.)\W*(?1)\W*\2|)|((.)\W*(?3)\W*\4|\W*.\W*))\W*$/i
+/^\W*(?:((.)\W*(?1)\W*\2|)|((.)\W*(?3)\W*\4|\W*.\W*))\W*$/Ii
 Capturing subpattern count = 4
 Max back reference = 4
 Partial matching not supported
@@ -4078,7 +4067,7 @@ No match
     The quick brown fox  
 No match
     
-/^(\d+|\((?1)([+*-])(?1)\)|-(?1))$/
+/^(\d+|\((?1)([+*-])(?1)\)|-(?1))$/I
 Capturing subpattern count = 2
 Partial matching not supported
 Options: anchored
@@ -4099,7 +4088,7 @@ No match
     ((2+2)*-3)-7)
 No match
          
-/^(x(y|(?1){2})z)/
+/^(x(y|(?1){2})z)/I
 Capturing subpattern count = 2
 Options: anchored
 No first char
@@ -4119,7 +4108,7 @@ No match
     xxyzxyzxyzz   
 No match
 
-/((< (?: (?(R) \d++  | [^<>]*+) | (?2)) * >))/x
+/((< (?: (?(R) \d++  | [^<>]*+) | (?2)) * >))/Ix
 Capturing subpattern count = 2
 Partial matching not supported
 Options: extended
@@ -4154,13 +4143,13 @@ No match
     <abc
 No match
 
-/(?1)/
+/(?1)/I
 Failed: reference to non-existent subpattern at offset 3
 
-/((?2)(abc)/
-Failed: reference to non-existent subpattern at offset 4
+/((?2)(abc)/I
+Failed: missing ) at offset 10
 
-/^(abc)def(?1)/
+/^(abc)def(?1)/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
@@ -4169,7 +4158,7 @@ No need char
  0: abcdefabc
  1: abc
 
-/^(a|b|c)=(?1)+/
+/^(a|b|c)=(?1)+/I
 Capturing subpattern count = 1
 Options: anchored
 No first char
@@ -4184,7 +4173,7 @@ No need char
  0: a=bc
  1: a
 
-/^(a|b|c)=((?1))+/
+/^(a|b|c)=((?1))+/I
 Capturing subpattern count = 2
 Options: anchored
 No first char
@@ -4204,19 +4193,19 @@ No need char
 
 /a(?P<name1>b|c)d(?P<longername2>e)/D
 ------------------------------------------------------------------
-  0  28 Bra 0
+  0  32 Bra 0
   3     a
-  5   5 Bra 1
 8     b
- 10   5 Alt
- 13     c
- 15  10 Ket
18     d
- 20   5 Bra 2
- 23     e
- 25   5 Ket
28  28 Ket
- 31     End
+  5   7 Bra 1
10     b
+ 12   5 Alt
+ 15     c
+ 17  12 Ket
20     d
+ 22   7 Bra 2
+ 27     e
+ 29   7 Ket
32  32 Ket
+ 35     End
 ------------------------------------------------------------------
 Capturing subpattern count = 2
 Named capturing subpatterns:
@@ -4236,21 +4225,21 @@ Need char = 'e'
 
 /(?:a(?P<c>c(?P<d>d)))(?P<a>a)/D
 ------------------------------------------------------------------
-  0  35 Bra 0
-  3  21 Bra 0
+  0  41 Bra 0
+  3  25 Bra 0
   6     a
-  8  13 Bra 1
- 11     c
- 13   5 Bra 2
16     d
18   5 Ket
- 21  13 Ket
- 24  21 Ket
27   5 Bra 3
- 30     a
- 32   5 Ket
35  35 Ket
38     End
+  8  17 Bra 1
+ 13     c
+ 15   7 Bra 2
20     d
22   7 Ket
+ 25  17 Ket
+ 28  25 Ket
31   7 Bra 3
+ 36     a
+ 38   7 Ket
41  41 Ket
44     End
 ------------------------------------------------------------------
 Capturing subpattern count = 3
 Named capturing subpatterns:
@@ -4263,21 +4252,21 @@ Need char = 'a'
 
 /(?P<a>a)...(?P=a)bbb(?P>a)d/D
 ------------------------------------------------------------------
-  0  34 Bra 0
-  3   5 Bra 1
-  6     a
-  8   5 Ket
- 11     Any
- 12     Any
+  0  36 Bra 0
+  3   7 Bra 1
+  8     a
+ 10   7 Ket
  13     Any
- 14     \1
- 17     bbb
- 23   6 Once
- 26   3 Recurse
- 29   6 Ket
- 32     d
- 34  34 Ket
- 37     End
+ 14     Any
+ 15     Any
+ 16     \1
+ 19     bbb
+ 25   6 Once
+ 28   3 Recurse
+ 31   6 Ket
+ 34     d
+ 36  36 Ket
+ 39     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Max back reference = 1
@@ -4287,7 +4276,7 @@ No options
 First char = 'a'
 Need char = 'd'
 
-/^\W*(?:(?P<one>(?P<two>.)\W*(?P>one)\W*(?P=two)|)|(?P<three>(?P<four>.)\W*(?P>three)\W*(?P=four)|\W*.\W*))\W*$/i
+/^\W*(?:(?P<one>(?P<two>.)\W*(?P>one)\W*(?P=two)|)|(?P<three>(?P<four>.)\W*(?P>three)\W*(?P=four)|\W*.\W*))\W*$/Ii
 Capturing subpattern count = 4
 Max back reference = 4
 Named capturing subpatterns:
@@ -4326,7 +4315,7 @@ No match
     The quick brown fox  
 No match
     
-/((?(R)a|b))\1(?1)?/
+/((?(R)a|b))\1(?1)?/I
 Capturing subpattern count = 1
 Max back reference = 1
 No options
@@ -4339,14 +4328,14 @@ No need char
  0: bba
  1: b
 
-/(.*)a/sI
+/(.*)a/Is
 Capturing subpattern count = 1
 Partial matching not supported
 Options: anchored dotall
 No first char
 Need char = 'a'
 
-/(.*)a\1/sI
+/(.*)a\1/Is
 Capturing subpattern count = 1
 Max back reference = 1
 Partial matching not supported
@@ -4354,7 +4343,7 @@ Options: dotall
 No first char
 Need char = 'a'
 
-/(.*)a(b)\2/sI
+/(.*)a(b)\2/Is
 Capturing subpattern count = 2
 Max back reference = 2
 Partial matching not supported
@@ -4362,14 +4351,14 @@ Options: anchored dotall
 No first char
 Need char = 'b'
 
-/((.*)a|(.*)b)z/sI
+/((.*)a|(.*)b)z/Is
 Capturing subpattern count = 3
 Partial matching not supported
 Options: anchored dotall
 No first char
 Need char = 'z'
 
-/((.*)a|(.*)b)z\1/sI
+/((.*)a|(.*)b)z\1/Is
 Capturing subpattern count = 3
 Max back reference = 1
 Partial matching not supported
@@ -4377,7 +4366,7 @@ Options: dotall
 No first char
 Need char = 'z'
 
-/((.*)a|(.*)b)z\2/sI
+/((.*)a|(.*)b)z\2/Is
 Capturing subpattern count = 3
 Max back reference = 2
 Partial matching not supported
@@ -4385,7 +4374,7 @@ Options: dotall
 No first char
 Need char = 'z'
 
-/((.*)a|(.*)b)z\3/sI
+/((.*)a|(.*)b)z\3/Is
 Capturing subpattern count = 3
 Max back reference = 3
 Partial matching not supported
@@ -4393,7 +4382,7 @@ Options: dotall
 No first char
 Need char = 'z'
 
-/((.*)a|^(.*)b)z\3/sI
+/((.*)a|^(.*)b)z\3/Is
 Capturing subpattern count = 3
 Max back reference = 3
 Partial matching not supported
@@ -4401,14 +4390,14 @@ Options: anchored dotall
 No first char
 Need char = 'z'
 
-/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a/sI
+/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a/Is
 Capturing subpattern count = 31
 Partial matching not supported
 Options: anchored dotall
 No first char
 No need char
 
-/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a\31/sI
+/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a\31/Is
 Capturing subpattern count = 31
 Max back reference = 31
 Partial matching not supported
@@ -4416,7 +4405,7 @@ Options: dotall
 No first char
 No need char
 
-/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a\32/sI
+/(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)|(.*)a\32/Is
 Capturing subpattern count = 32
 Max back reference = 32
 Partial matching not supported
@@ -4424,7 +4413,7 @@ Options: dotall
 No first char
 No need char
 
-/(a)(bc)/ND
+/(a)(bc)/IND
 ------------------------------------------------------------------
   0  21 Bra 0
   3   5 Bra 0
@@ -4443,17 +4432,17 @@ Need char = 'c'
   abc
  0: abc
 
-/(?P<one>a)(bc)/ND
+/(?P<one>a)(bc)/IND
 ------------------------------------------------------------------
-  0  21 Bra 0
-  3   5 Bra 1
-  6     a
 8   5 Ket
- 11   7 Bra 0
- 14     bc
18   7 Ket
- 21  21 Ket
- 24     End
+  0  23 Bra 0
+  3   7 Bra 1
+  8     a
10   7 Ket
+ 13   7 Bra 0
+ 16     bc
20   7 Ket
+ 23  23 Ket
+ 26     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Named capturing subpatterns:
@@ -4465,17 +4454,17 @@ Need char = 'c'
  0: abc
  1: a
 
-/(a)(?P<named>bc)/ND
+/(a)(?P<named>bc)/IND
 ------------------------------------------------------------------
-  0  21 Bra 0
+  0  23 Bra 0
   3   5 Bra 0
   6     a
   8   5 Ket
- 11   7 Bra 1
- 14     bc
18   7 Ket
- 21  21 Ket
- 24     End
+ 11   9 Bra 1
+ 16     bc
20   9 Ket
+ 23  23 Ket
+ 26     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Named capturing subpatterns:
@@ -4484,7 +4473,7 @@ Options: no_auto_capture
 First char = 'a'
 Need char = 'c'
 
-/(a+)*zz/
+/(a+)*zz/I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
@@ -4500,7 +4489,7 @@ Minimum match() limit = 32768
 Minimum match() recursion limit = 42
 No match
 
-/(aaa(?C1)bbb|ab)/
+/(aaa(?C1)bbb|ab)/I
 Capturing subpattern count = 1
 No options
 First char = 'a'
@@ -4527,7 +4516,7 @@ Callout data = 1
 Callout data = -1
 No match
 
-/ab(?P<one>cd)ef(?P<two>gh)/
+/ab(?P<one>cd)ef(?P<two>gh)/I
 Capturing subpattern count = 2
 Named capturing subpatterns:
   one   1
@@ -4560,13 +4549,13 @@ copy substring three failed -7
 
 /(?P<Tes>)(?P<Test>)/D
 ------------------------------------------------------------------
-  0  15 Bra 0
-  3   3 Bra 1
-  6   3 Ket
 9   3 Bra 2
- 12   3 Ket
- 15  15 Ket
18     End
+  0  19 Bra 0
+  3   5 Bra 1
+  8   5 Ket
11   5 Bra 2
+ 16   5 Ket
+ 19  19 Ket
22     End
 ------------------------------------------------------------------
 Capturing subpattern count = 2
 Named capturing subpatterns:
@@ -4578,13 +4567,13 @@ No need char
 
 /(?P<Test>)(?P<Tes>)/D
 ------------------------------------------------------------------
-  0  15 Bra 0
-  3   3 Bra 1
-  6   3 Ket
 9   3 Bra 2
- 12   3 Ket
- 15  15 Ket
18     End
+  0  19 Bra 0
+  3   5 Bra 1
+  8   5 Ket
11   5 Bra 2
+ 16   5 Ket
+ 19  19 Ket
22     End
 ------------------------------------------------------------------
 Capturing subpattern count = 2
 Named capturing subpatterns:
@@ -4594,7 +4583,7 @@ No options
 No first char
 No need char
 
-/(?P<Z>zz)(?P<A>aa)/
+/(?P<Z>zz)(?P<A>aa)/I
 Capturing subpattern count = 2
 Named capturing subpatterns:
   A   2
@@ -4613,13 +4602,13 @@ Need char = 'a'
  2: aa
   C aa (2) A
 
-/(?P<x>eks)(?P<x>eccs)/
-Failed: two named subpatterns have the same name at offset 16
+/(?P<x>eks)(?P<x>eccs)/I
+Failed: two named subpatterns have the same name at offset 15
 
-/(?P<abc>abc(?P<def>def)(?P<abc>xyz))/
-Failed: two named subpatterns have the same name at offset 31
+/(?P<abc>abc(?P<def>def)(?P<abc>xyz))/I
+Failed: two named subpatterns have the same name at offset 30
 
-"\[((?P<elem>\d+)(,(?P>elem))*)\]"
+"\[((?P<elem>\d+)(,(?P>elem))*)\]"I
 Capturing subpattern count = 3
 Named capturing subpatterns:
   elem   2
@@ -4637,7 +4626,7 @@ No match
     []  
 No match
 
-"\[((?P<elem>\d+)(,(?P>elem))*)?\]"
+"\[((?P<elem>\d+)(,(?P>elem))*)?\]"I
 Capturing subpattern count = 3
 Named capturing subpatterns:
   elem   2
@@ -4655,20 +4644,20 @@ Need char = ']'
 
 /(a(b(?2)c))?/D
 ------------------------------------------------------------------
-  0  31 Bra 0
+  0  35 Bra 0
   3     Brazero
-  4  24 Bra 1
-  7     a
 9  16 Bra 2
- 12     b
- 14   6 Once
17   9 Recurse
- 20   6 Ket
- 23     c
- 25  16 Ket
28  24 Ket
- 31  31 Ket
- 34     End
+  4  28 Bra 1
+  9     a
11  18 Bra 2
+ 16     b
+ 18   6 Once
21  11 Recurse
+ 24   6 Ket
+ 27     c
+ 29  18 Ket
32  28 Ket
+ 35  35 Ket
+ 38     End
 ------------------------------------------------------------------
 Capturing subpattern count = 2
 No options
@@ -4677,20 +4666,20 @@ No need char
 
 /(a(b(?2)c))*/D
 ------------------------------------------------------------------
-  0  31 Bra 0
+  0  35 Bra 0
   3     Brazero
-  4  24 Bra 1
-  7     a
 9  16 Bra 2
- 12     b
- 14   6 Once
17   9 Recurse
- 20   6 Ket
- 23     c
- 25  16 Ket
28  24 KetRmax
- 31  31 Ket
- 34     End
+  4  28 Bra 1
+  9     a
11  18 Bra 2
+ 16     b
+ 18   6 Once
21  11 Recurse
+ 24   6 Ket
+ 27     c
+ 29  18 Ket
32  28 KetRmax
+ 35  35 Ket
+ 38     End
 ------------------------------------------------------------------
 Capturing subpattern count = 2
 No options
@@ -4699,33 +4688,33 @@ No need char
 
 /(a(b(?2)c)){0,2}/D
 ------------------------------------------------------------------
-  0  65 Bra 0
+  0  73 Bra 0
   3     Brazero
-  4  58 Bra 0
-  7  24 Bra 1
- 10     a
- 12  16 Bra 2
- 15     b
17   6 Once
- 20  12 Recurse
- 23   6 Ket
26     c
28  16 Ket
- 31  24 Ket
- 34     Brazero
- 35  24 Bra 1
38     a
- 40  16 Bra 2
43     b
45   6 Once
48  12 Recurse
- 51   6 Ket
54     c
56  16 Ket
59  24 Ket
62  58 Ket
65  65 Ket
68     End
+  4  66 Bra 0
+  7  28 Bra 1
+ 12     a
+ 14  18 Bra 2
+ 19     b
21   6 Once
+ 24  14 Recurse
+ 27   6 Ket
30     c
32  18 Ket
+ 35  28 Ket
+ 38     Brazero
+ 39  28 Bra 1
44     a
+ 46  18 Bra 2
51     b
53   6 Once
56  14 Recurse
+ 59   6 Ket
62     c
64  18 Ket
67  28 Ket
70  66 Ket
73  73 Ket
76     End
 ------------------------------------------------------------------
 Capturing subpattern count = 2
 No options
@@ -4746,7 +4735,7 @@ No options
 No first char
 No need char
 
-/((w\/|-|with)*(free|immediate)*.*?shipping\s*[!.-]*)/i
+/((w\/|-|with)*(free|immediate)*.*?shipping\s*[!.-]*)/Ii
 Capturing subpattern count = 3
 Partial matching not supported
 Options: caseless
@@ -4756,7 +4745,7 @@ Need char = 'g' (caseless)
  0: Baby Bjorn Active Carrier - With free SHIPPING!!
  1: Baby Bjorn Active Carrier - With free SHIPPING!!
 
-/((w\/|-|with)*(free|immediate)*.*?shipping\s*[!.-]*)/iS
+/((w\/|-|with)*(free|immediate)*.*?shipping\s*[!.-]*)/IiS
 Capturing subpattern count = 3
 Partial matching not supported
 Options: caseless
@@ -4767,7 +4756,7 @@ Study returned NULL
  0: Baby Bjorn Active Carrier - With free SHIPPING!!
  1: Baby Bjorn Active Carrier - With free SHIPPING!!
      
-/a*.*b/SD
+/a*.*b/ISD
 ------------------------------------------------------------------
   0   9 Bra 0
   3     a*
@@ -4783,19 +4772,19 @@ No first char
 Need char = 'b'
 Study returned NULL
 
-/(a|b)*.?c/SD 
+/(a|b)*.?c/ISD 
 ------------------------------------------------------------------
-  0  21 Bra 0
+  0  23 Bra 0
   3     Brazero
-  4   5 Bra 1
-  7     a
 9   5 Alt
- 12     b
- 14  10 KetRmax
- 17     Any?
19     c
- 21  21 Ket
- 24     End
+  4   7 Bra 1
+  9     a
11   5 Alt
+ 14     b
+ 16  12 KetRmax
+ 19     Any?
21     c
+ 23  23 Ket
+ 26     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 No options
@@ -4819,7 +4808,7 @@ No options
 First char = 'a'
 Need char = 'f'
 
-/abcde/CD
+/abcde/ICD
 ------------------------------------------------------------------
   0  49 Bra 0
   3     Callout 255 0 1
@@ -4858,11 +4847,11 @@ Need char = 'e'
  +4 ^   ^      e
 No match
   
-/a*b/CD
+/a*b/ICD
 ------------------------------------------------------------------
   0  25 Bra 0
   3     Callout 255 0 2
-  9     a*
+  9     a*+
  11     Callout 255 2 1
  17     b
  19     Callout 255 3 0
@@ -4890,22 +4879,12 @@ Need char = 'b'
 --->aaaacb
  +0 ^          a*
  +2 ^   ^      b
- +2 ^  ^       b
- +2 ^ ^        b
- +2 ^^         b
- +2 ^          b
  +0  ^         a*
  +2  ^  ^      b
- +2  ^ ^       b
- +2  ^^        b
- +2  ^         b
  +0   ^        a*
  +2   ^ ^      b
- +2   ^^       b
- +2   ^        b
  +0    ^       a*
  +2    ^^      b
- +2    ^       b
  +0     ^      a*
  +2     ^      b
  +0      ^     a*
@@ -4913,11 +4892,11 @@ Need char = 'b'
  +3      ^^    
  0: b
 
-/a+b/CD
+/a+b/ICD
 ------------------------------------------------------------------
   0  25 Bra 0
   3     Callout 255 0 2
-  9     a+
+  9     a++
  11     Callout 255 2 1
  17     b
  19     Callout 255 3 0
@@ -4945,46 +4924,40 @@ Need char = 'b'
 --->aaaacb
  +0 ^          a+
  +2 ^   ^      b
- +2 ^  ^       b
- +2 ^ ^        b
- +2 ^^         b
  +0  ^         a+
  +2  ^  ^      b
- +2  ^ ^       b
- +2  ^^        b
  +0   ^        a+
  +2   ^ ^      b
- +2   ^^       b
  +0    ^       a+
  +2    ^^      b
 No match
 
-/(abc|def)x/CD
+/(abc|def)x/ICD
 ------------------------------------------------------------------
-  0  92 Bra 0
+  0  94 Bra 0
   3     Callout 255 0 9
-  9  33 Bra 1
- 12     Callout 255 1 1
18     a
- 20     Callout 255 2 1
- 26     b
28     Callout 255 3 1
- 34     c
- 36     Callout 255 4 0
- 42  33 Alt
- 45     Callout 255 5 1
- 51     d
- 53     Callout 255 6 1
59     e
- 61     Callout 255 7 1
- 67     f
69     Callout 255 8 0
- 75  66 Ket
78     Callout 255 9 1
- 84     x
- 86     Callout 255 10 0
- 92  92 Ket
- 95     End
+  9  35 Bra 1
+ 14     Callout 255 1 1
20     a
+ 22     Callout 255 2 1
+ 28     b
30     Callout 255 3 1
+ 36     c
+ 38     Callout 255 4 0
+ 44  33 Alt
+ 47     Callout 255 5 1
+ 53     d
+ 55     Callout 255 6 1
61     e
+ 63     Callout 255 7 1
+ 69     f
71     Callout 255 8 0
+ 77  68 Ket
80     Callout 255 9 1
+ 86     x
+ 88     Callout 255 10 0
+ 94  94 Ket
+ 97     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Options:
@@ -5049,7 +5022,7 @@ Need char = 'x'
  +5        ^     d
 No match
 
-/(ab|cd){3,4}/C
+/(ab|cd){3,4}/IC
 Capturing subpattern count = 1
 Options:
 No first char
@@ -5113,34 +5086,34 @@ No need char
  0: abcdcdcd
  1: cd
 
-/([ab]{,4}c|xy)/CD
+/([ab]{,4}c|xy)/ICD
 ------------------------------------------------------------------
-  0 131 Bra 0
+  0 133 Bra 0
   3     Callout 255 0 14
-  9  88 Bra 1
- 12     Callout 255 1 4
18     [ab]
- 51     Callout 255 5 1
- 57     {
59     Callout 255 6 1
- 65     ,
- 67     Callout 255 7 1
- 73     4
- 75     Callout 255 8 1
- 81     }
- 83     Callout 255 9 1
89     c
- 91     Callout 255 10 0
- 97  25 Alt
-100     Callout 255 11 1
-106     x
-108     Callout 255 12 1
-114     y
-116     Callout 255 13 0
-122 113 Ket
-125     Callout 255 14 0
-131 131 Ket
-134     End
+  9  90 Bra 1
+ 14     Callout 255 1 4
20     [ab]
+ 53     Callout 255 5 1
+ 59     {
61     Callout 255 6 1
+ 67     ,
+ 69     Callout 255 7 1
+ 75     4
+ 77     Callout 255 8 1
+ 83     }
+ 85     Callout 255 9 1
91     c
+ 93     Callout 255 10 0
+ 99  25 Alt
+102     Callout 255 11 1
+108     x
+110     Callout 255 12 1
+116     y
+118     Callout 255 13 0
+124 115 Ket
+127     Callout 255 14 0
+133 133 Ket
+136     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Options:
@@ -5288,85 +5261,85 @@ No need char
 +11                                             ^    x
 No match
 
-/([ab]{1,4}c|xy){4,5}?123/CD
+/([ab]{1,4}c|xy){4,5}?123/ICD
 ------------------------------------------------------------------
-  0 485 Bra 0
+  0 495 Bra 0
   3     Callout 255 0 21
-  9  61 Bra 1
- 12     Callout 255 1 9
18     [ab]{1,4}
- 56     Callout 255 10 1
- 62     c
- 64     Callout 255 11 0
- 70  25 Alt
- 73     Callout 255 12 1
79     x
- 81     Callout 255 13 1
- 87     y
89     Callout 255 14 0
- 95  86 Ket
- 98  61 Bra 1
-101     Callout 255 1 9
-107     [ab]{1,4}
-145     Callout 255 10 1
-151     c
-153     Callout 255 11 0
-159  25 Alt
-162     Callout 255 12 1
-168     x
-170     Callout 255 13 1
-176     y
-178     Callout 255 14 0
-184  86 Ket
-187  61 Bra 1
-190     Callout 255 1 9
-196     [ab]{1,4}
-234     Callout 255 10 1
-240     c
-242     Callout 255 11 0
-248  25 Alt
-251     Callout 255 12 1
-257     x
-259     Callout 255 13 1
-265     y
-267     Callout 255 14 0
-273  86 Ket
-276  61 Bra 1
-279     Callout 255 1 9
-285     [ab]{1,4}
-323     Callout 255 10 1
-329     c
-331     Callout 255 11 0
-337  25 Alt
-340     Callout 255 12 1
-346     x
-348     Callout 255 13 1
-354     y
-356     Callout 255 14 0
-362  86 Ket
-365     Braminzero
-366  61 Bra 1
-369     Callout 255 1 9
-375     [ab]{1,4}
-413     Callout 255 10 1
-419     c
-421     Callout 255 11 0
-427  25 Alt
-430     Callout 255 12 1
-436     x
-438     Callout 255 13 1
-444     y
-446     Callout 255 14 0
-452  86 Ket
-455     Callout 255 21 1
-461     1
-463     Callout 255 22 1
-469     2
-471     Callout 255 23 1
-477     3
-479     Callout 255 24 0
-485 485 Ket
-488     End
+  9  63 Bra 1
+ 14     Callout 255 1 9
20     [ab]{1,4}
+ 58     Callout 255 10 1
+ 64     c
+ 66     Callout 255 11 0
+ 72  25 Alt
+ 75     Callout 255 12 1
81     x
+ 83     Callout 255 13 1
+ 89     y
91     Callout 255 14 0
+ 97  88 Ket
+100  63 Bra 1
+105     Callout 255 1 9
+111     [ab]{1,4}
+149     Callout 255 10 1
+155     c
+157     Callout 255 11 0
+163  25 Alt
+166     Callout 255 12 1
+172     x
+174     Callout 255 13 1
+180     y
+182     Callout 255 14 0
+188  88 Ket
+191  63 Bra 1
+196     Callout 255 1 9
+202     [ab]{1,4}
+240     Callout 255 10 1
+246     c
+248     Callout 255 11 0
+254  25 Alt
+257     Callout 255 12 1
+263     x
+265     Callout 255 13 1
+271     y
+273     Callout 255 14 0
+279  88 Ket
+282  63 Bra 1
+287     Callout 255 1 9
+293     [ab]{1,4}
+331     Callout 255 10 1
+337     c
+339     Callout 255 11 0
+345  25 Alt
+348     Callout 255 12 1
+354     x
+356     Callout 255 13 1
+362     y
+364     Callout 255 14 0
+370  88 Ket
+373     Braminzero
+374  63 Bra 1
+379     Callout 255 1 9
+385     [ab]{1,4}
+423     Callout 255 10 1
+429     c
+431     Callout 255 11 0
+437  25 Alt
+440     Callout 255 12 1
+446     x
+448     Callout 255 13 1
+454     y
+456     Callout 255 14 0
+462  88 Ket
+465     Callout 255 21 1
+471     1
+473     Callout 255 22 1
+479     2
+481     Callout 255 23 1
+487     3
+489     Callout 255 24 0
+495 495 Ket
+498     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Partial matching not supported
@@ -5426,7 +5399,7 @@ No need char
   Xbcd12345 
  0: bcd12345
 
-/abcde/
+/abcde/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
@@ -5446,7 +5419,7 @@ No match
     the quick brown abxyz fox\P
 No match
     
-"^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/(20)?\d\d$"
+"^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/(20)?\d\d$"I
 Capturing subpattern count = 3
 Options: anchored
 No first char
@@ -5529,7 +5502,7 @@ No options
 No first char
 Need char = 'E'
 
-/[abc]?123/
+/[abc]?123/I
 Capturing subpattern count = 0
 No options
 No first char
@@ -5547,7 +5520,7 @@ Partial match
     c123\P      
  0: c123
 
-/^(?:\d){3,5}X/
+/^(?:\d){3,5}X/I
 Capturing subpattern count = 0
 Options: anchored
 No first char
@@ -5573,7 +5546,7 @@ No match
     123456\P 
 No match
 
-/abc/>testsavedregex
+/abc/I>testsavedregex
 Capturing subpattern count = 0
 No options
 First char = 'a'
@@ -5582,10 +5555,6 @@ Compiled regex written to testsavedregex
 <testsavedregex
 Compiled regex loaded from testsavedregex
 No study data
-Capturing subpattern count = 0
-No options
-First char = 'a'
-Need char = 'c'
     abc
  0: abc
     ** Failers
@@ -5593,7 +5562,7 @@ No match
     bca
 No match
     
-/abc/F>testsavedregex
+/abc/IF>testsavedregex
 Capturing subpattern count = 0
 No options
 First char = 'a'
@@ -5602,10 +5571,6 @@ Compiled regex written to testsavedregex
 <testsavedregex
 Compiled regex (byte-inverted) loaded from testsavedregex
 No study data
-Capturing subpattern count = 0
-No options
-First char = 'a'
-Need char = 'c'
     abc
  0: abc
     ** Failers
@@ -5613,7 +5578,7 @@ No match
     bca
 No match
 
-/(a|b)/S>testsavedregex
+/(a|b)/IS>testsavedregex
 Capturing subpattern count = 1
 No options
 No first char
@@ -5624,11 +5589,6 @@ Study data written to testsavedregex
 <testsavedregex
 Compiled regex loaded from testsavedregex
 Study data loaded from testsavedregex
-Capturing subpattern count = 1
-No options
-No first char
-No need char
-Starting byte set: a b 
     abc
  0: a
  1: a
@@ -5638,7 +5598,7 @@ Starting byte set: a b
     def  
 No match
     
-/(a|b)/SF>testsavedregex
+/(a|b)/ISF>testsavedregex
 Capturing subpattern count = 1
 No options
 No first char
@@ -5649,11 +5609,6 @@ Study data written to testsavedregex
 <testsavedregex
 Compiled regex (byte-inverted) loaded from testsavedregex
 Study data loaded from testsavedregex
-Capturing subpattern count = 1
-No options
-No first char
-No need char
-Starting byte set: a b 
     abc
  0: a
  1: a
@@ -5663,7 +5618,7 @@ Starting byte set: a b
     def  
 No match
     
-~<(\w+)/?>(.)*</(\1)>~smg
+~<(\w+)/?>(.)*</(\1)>~smgI
 Capturing subpattern count = 3
 Max back reference = 1
 Partial matching not supported
@@ -5682,7 +5637,7 @@ Options: anchored
 No first char
 No need char
 
-/line\nbreak/
+/line\nbreak/I
 Capturing subpattern count = 0
 No options
 First char = 'l'
@@ -5692,7 +5647,7 @@ Need char = 'k'
     line one\nthis is a line\nbreak in the second line 
  0: line\x0abreak
 
-/line\nbreak/f
+/line\nbreak/If
 Capturing subpattern count = 0
 Options: firstline
 First char = 'l'
@@ -5704,7 +5659,7 @@ No match
     line one\nthis is a line\nbreak in the second line 
 No match
 
-/line\nbreak/mf
+/line\nbreak/Imf
 Capturing subpattern count = 0
 Options: multiline firstline
 First char = 'l'
@@ -5716,7 +5671,7 @@ No match
     line one\nthis is a line\nbreak in the second line 
 No match
 
-/ab.cd/P
+/ab.cd/IP
     ab-cd
  0: ab-cd
     ab=cd 
@@ -5726,7 +5681,7 @@ No match: POSIX code 17: match failed
     ab\ncd
 No match: POSIX code 17: match failed
 
-/ab.cd/Ps
+/ab.cd/IPs
     ab-cd
  0: ab-cd
     ab=cd 
@@ -5734,7 +5689,7 @@ No match: POSIX code 17: match failed
     ab\ncd
  0: ab\x0acd
 
-/(?i)(?-i)AbCd/
+/(?i)(?-i)AbCd/I
 Capturing subpattern count = 0
 No options
 First char = 'A'
@@ -5746,16 +5701,16 @@ No match
     abcd  
 No match
     
-/a{11111111111111111111}/
+/a{11111111111111111111}/I
 Failed: number too big in {} quantifier at offset 22
 
-/(){64294967295}/
+/(){64294967295}/I
 Failed: number too big in {} quantifier at offset 14
 
-/(){2,4294967295}/
+/(){2,4294967295}/I
 Failed: number too big in {} quantifier at offset 15
 
-"(?i:a)(?i:b)(?i:c)(?i:d)(?i:e)(?i:f)(?i:g)(?i:h)(?i:i)(?i:j)(k)(?i:l)A\1B"
+"(?i:a)(?i:b)(?i:c)(?i:d)(?i:e)(?i:f)(?i:g)(?i:h)(?i:i)(?i:j)(k)(?i:l)A\1B"I
 Capturing subpattern count = 1
 Max back reference = 1
 No options
@@ -5765,7 +5720,7 @@ Need char = 'B'
  0: abcdefghijklAkB
  1: k
 
-"(?P<n0>a)(?P<n1>b)(?P<n2>c)(?P<n3>d)(?P<n4>e)(?P<n5>f)(?P<n6>g)(?P<n7>h)(?P<n8>i)(?P<n9>j)(?P<n10>k)(?P<n11>l)A\11B"
+"(?P<n0>a)(?P<n1>b)(?P<n2>c)(?P<n3>d)(?P<n4>e)(?P<n5>f)(?P<n6>g)(?P<n7>h)(?P<n8>i)(?P<n9>j)(?P<n10>k)(?P<n11>l)A\11B"I
 Capturing subpattern count = 12
 Max back reference = 11
 Named capturing subpatterns:
@@ -5799,7 +5754,7 @@ Need char = 'B'
 11: k
 12: l
 
-"(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)A\11B"
+"(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)A\11B"I
 Capturing subpattern count = 12
 Max back reference = 11
 No options
@@ -5820,7 +5775,7 @@ Need char = 'B'
 11: k
 12: l
 
-"(?P<name0>a)(?P<name1>a)(?P<name2>a)(?P<name3>a)(?P<name4>a)(?P<name5>a)(?P<name6>a)(?P<name7>a)(?P<name8>a)(?P<name9>a)(?P<name10>a)(?P<name11>a)(?P<name12>a)(?P<name13>a)(?P<name14>a)(?P<name15>a)(?P<name16>a)(?P<name17>a)(?P<name18>a)(?P<name19>a)(?P<name20>a)(?P<name21>a)(?P<name22>a)(?P<name23>a)(?P<name24>a)(?P<name25>a)(?P<name26>a)(?P<name27>a)(?P<name28>a)(?P<name29>a)(?P<name30>a)(?P<name31>a)(?P<name32>a)(?P<name33>a)(?P<name34>a)(?P<name35>a)(?P<name36>a)(?P<name37>a)(?P<name38>a)(?P<name39>a)(?P<name40>a)(?P<name41>a)(?P<name42>a)(?P<name43>a)(?P<name44>a)(?P<name45>a)(?P<name46>a)(?P<name47>a)(?P<name48>a)(?P<name49>a)(?P<name50>a)(?P<name51>a)(?P<name52>a)(?P<name53>a)(?P<name54>a)(?P<name55>a)(?P<name56>a)(?P<name57>a)(?P<name58>a)(?P<name59>a)(?P<name60>a)(?P<name61>a)(?P<name62>a)(?P<name63>a)(?P<name64>a)(?P<name65>a)(?P<name66>a)(?P<name67>a)(?P<name68>a)(?P<name69>a)(?P<name70>a)(?P<name71>a)(?P<name72>a)(?P<name73>a)(?P<name74>a)(?P<name75>a)(?P<name76>a)(?P<name77>a)(?P<name78>a)(?P<name79>a)(?P<name80>a)(?P<name81>a)(?P<name82>a)(?P<name83>a)(?P<name84>a)(?P<name85>a)(?P<name86>a)(?P<name87>a)(?P<name88>a)(?P<name89>a)(?P<name90>a)(?P<name91>a)(?P<name92>a)(?P<name93>a)(?P<name94>a)(?P<name95>a)(?P<name96>a)(?P<name97>a)(?P<name98>a)(?P<name99>a)(?P<name100>a)"
+"(?P<name0>a)(?P<name1>a)(?P<name2>a)(?P<name3>a)(?P<name4>a)(?P<name5>a)(?P<name6>a)(?P<name7>a)(?P<name8>a)(?P<name9>a)(?P<name10>a)(?P<name11>a)(?P<name12>a)(?P<name13>a)(?P<name14>a)(?P<name15>a)(?P<name16>a)(?P<name17>a)(?P<name18>a)(?P<name19>a)(?P<name20>a)(?P<name21>a)(?P<name22>a)(?P<name23>a)(?P<name24>a)(?P<name25>a)(?P<name26>a)(?P<name27>a)(?P<name28>a)(?P<name29>a)(?P<name30>a)(?P<name31>a)(?P<name32>a)(?P<name33>a)(?P<name34>a)(?P<name35>a)(?P<name36>a)(?P<name37>a)(?P<name38>a)(?P<name39>a)(?P<name40>a)(?P<name41>a)(?P<name42>a)(?P<name43>a)(?P<name44>a)(?P<name45>a)(?P<name46>a)(?P<name47>a)(?P<name48>a)(?P<name49>a)(?P<name50>a)(?P<name51>a)(?P<name52>a)(?P<name53>a)(?P<name54>a)(?P<name55>a)(?P<name56>a)(?P<name57>a)(?P<name58>a)(?P<name59>a)(?P<name60>a)(?P<name61>a)(?P<name62>a)(?P<name63>a)(?P<name64>a)(?P<name65>a)(?P<name66>a)(?P<name67>a)(?P<name68>a)(?P<name69>a)(?P<name70>a)(?P<name71>a)(?P<name72>a)(?P<name73>a)(?P<name74>a)(?P<name75>a)(?P<name76>a)(?P<name77>a)(?P<name78>a)(?P<name79>a)(?P<name80>a)(?P<name81>a)(?P<name82>a)(?P<name83>a)(?P<name84>a)(?P<name85>a)(?P<name86>a)(?P<name87>a)(?P<name88>a)(?P<name89>a)(?P<name90>a)(?P<name91>a)(?P<name92>a)(?P<name93>a)(?P<name94>a)(?P<name95>a)(?P<name96>a)(?P<name97>a)(?P<name98>a)(?P<name99>a)(?P<name100>a)"I
 Capturing subpattern count = 101
 Named capturing subpatterns:
   name0     1
@@ -5945,7 +5900,7 @@ Matched, but too many substrings
 13: a
 14: a
 
-"(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)"
+"(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)"I
 Capturing subpattern count = 101
 No options
 First char = 'a'
@@ -5968,7 +5923,7 @@ Matched, but too many substrings
 13: a
 14: a
 
-/[^()]*(?:\((?R)\)[^()]*)*/
+/[^()]*(?:\((?R)\)[^()]*)*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
@@ -5981,7 +5936,7 @@ No need char
     (this(and)that)stuff
  0: (this(and)that)stuff
 
-/[^()]*(?:\((?>(?R))\)[^()]*)*/
+/[^()]*(?:\((?>(?R))\)[^()]*)*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
@@ -5992,7 +5947,7 @@ No need char
     (this(and)that) 
  0: (this(and)that)
     
-/[^()]*(?:\((?R)\))*[^()]*/
+/[^()]*(?:\((?R)\))*[^()]*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
@@ -6003,7 +5958,7 @@ No need char
     (this(and)that) 
  0: (this(and)that)
 
-/(?:\((?R)\))*[^()]*/
+/(?:\((?R)\))*[^()]*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
@@ -6016,7 +5971,7 @@ No need char
     ((this)) 
  0: ((this))
 
-/(?:\((?R)\))|[^()]*/
+/(?:\((?R)\))|[^()]*/I
 Capturing subpattern count = 0
 Partial matching not supported
 No options
@@ -6031,27 +5986,27 @@ No need char
     ((this)) 
  0: ((this))
     
-/a(b)c/PN
+/a(b)c/IPN
     abc
 Matched with REG_NOSUB
     
-/a(?P<name>b)c/PN
+/a(?P<name>b)c/IPN
     abc  
 Matched with REG_NOSUB
     
-/\x{100}/ 
+/\x{100}/I 
 Failed: character value in \x{...} sequence is too large at offset 6
 
-/\x{0000ff}/
+/\x{0000ff}/I
 Capturing subpattern count = 0
 No options
 First char = 255
 No need char
 
-/^((?P<A>a1)|(?P<A>a2)b)/
-Failed: two named subpatterns have the same name at offset 18
+/^((?P<A>a1)|(?P<A>a2)b)/I
+Failed: two named subpatterns have the same name at offset 17
 
-/^((?P<A>a1)|(?P<A>a2)b)/J
+/^((?P<A>a1)|(?P<A>a2)b)/IJ
 Capturing subpattern count = 3
 Named capturing subpatterns:
   A   2
@@ -6080,7 +6035,7 @@ no parentheses with name "Z"
 copy substring Z failed -7
   C a1 (2) A
     
-/^(?P<A>a)(?P<A>b)/J
+/^(?P<A>a)(?P<A>b)/IJ
 Capturing subpattern count = 2
 Named capturing subpatterns:
   A   1
@@ -6094,7 +6049,7 @@ No need char
  2: b
   C a (1) A
     
-/^(?P<A>a)(?P<A>b)|cd/J
+/^(?P<A>a)(?P<A>b)|cd/IJ
 Capturing subpattern count = 2
 Named capturing subpatterns:
   A   1
@@ -6111,7 +6066,7 @@ No need char
  0: cd
 copy substring A failed -7
   
-/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/J
+/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/IJ
 Capturing subpattern count = 4
 Named capturing subpatterns:
   A   1
@@ -6129,7 +6084,7 @@ No need char
  4: gh
   C ef (2) A
   
-/^((?P<A>a1)|(?P<A>a2)b)/J
+/^((?P<A>a1)|(?P<A>a2)b)/IJ
 Capturing subpattern count = 3
 Named capturing subpatterns:
   A   2
@@ -6158,7 +6113,7 @@ no parentheses with name "Z"
 copy substring Z failed -7
   G a1 (2) A
     
-/^(?P<A>a)(?P<A>b)/J
+/^(?P<A>a)(?P<A>b)/IJ
 Capturing subpattern count = 2
 Named capturing subpatterns:
   A   1
@@ -6172,7 +6127,7 @@ No need char
  2: b
   G a (1) A
     
-/^(?P<A>a)(?P<A>b)|cd/J
+/^(?P<A>a)(?P<A>b)|cd/IJ
 Capturing subpattern count = 2
 Named capturing subpatterns:
   A   1
@@ -6189,7 +6144,7 @@ No need char
  0: cd
 copy substring A failed -7
   
-/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/J
+/^(?P<A>a)(?P<A>b)|cd(?P<A>ef)(?P<A>gh)/IJ
 Capturing subpattern count = 4
 Named capturing subpatterns:
   A   1
@@ -6207,7 +6162,7 @@ No need char
  4: gh
   G ef (2) A
   
-/(?J)^((?P<A>a1)|(?P<A>a2)b)/
+/(?J)^((?P<A>a1)|(?P<A>a2)b)/I
 Capturing subpattern count = 3
 Named capturing subpatterns:
   A   2
@@ -6227,18 +6182,18 @@ No need char
  3: a2
   C a2 (2) A
     
-/^(?P<A>a) (?J:(?P<B>b)(?P<B>c)) (?P<A>d)/
-Failed: two named subpatterns have the same name at offset 38
+/^(?P<A>a) (?J:(?P<B>b)(?P<B>c)) (?P<A>d)/I
+Failed: two named subpatterns have the same name at offset 37
 
 / In this next test, J is not set at the outer level; consequently it isn't
 set in the pattern's options; consequently pcre_get_named_substring() produces 
-a random value. /x
+a random value. /Ix
 Capturing subpattern count = 1
 Options: extended
 First char = 'I'
 Need char = 'e'
 
-/^(?P<A>a) (?J:(?P<B>b)(?P<B>c)) (?P<C>d)/
+/^(?P<A>a) (?J:(?P<B>b)(?P<B>c)) (?P<C>d)/I
 Capturing subpattern count = 4
 Named capturing subpatterns:
   A   1
@@ -6258,7 +6213,7 @@ No need char
   C b (1) B
   C d (1) C
 
-/^(?P<A>a)?(?(A)a|b)/
+/^(?P<A>a)?(?(A)a|b)/I
 Capturing subpattern count = 1
 Named capturing subpatterns:
   A   1
@@ -6275,7 +6230,7 @@ No match
     abc   
 No match
 
-/(?:(?(ZZ)a|b)(?P<ZZ>X))+/
+/(?:(?(ZZ)a|b)(?P<ZZ>X))+/I
 Capturing subpattern count = 1
 Named capturing subpatterns:
   ZZ   1
@@ -6286,13 +6241,13 @@ Need char = 'X'
  0: bXaX
  1: X
 
-/(?:(?(2y)a|b)(X))+/
+/(?:(?(2y)a|b)(X))+/I
 Failed: reference to non-existent subpattern at offset 9
 
-/(?:(?(ZA)a|b)(?P<ZZ>X))+/
+/(?:(?(ZA)a|b)(?P<ZZ>X))+/I
 Failed: reference to non-existent subpattern at offset 9
 
-/(?:(?(ZZ)a|b)(?(ZZ)a|b)(?P<ZZ>X))+/
+/(?:(?(ZZ)a|b)(?(ZZ)a|b)(?P<ZZ>X))+/I
 Capturing subpattern count = 1
 Named capturing subpatterns:
   ZZ   1
@@ -6303,7 +6258,7 @@ Need char = 'X'
  0: bbXaaX
  1: X
 
-/(?:(?(ZZ)a|\(b\))\\(?P<ZZ>X))+/
+/(?:(?(ZZ)a|\(b\))\\(?P<ZZ>X))+/I
 Capturing subpattern count = 1
 Named capturing subpatterns:
   ZZ   1
@@ -6314,10 +6269,10 @@ Need char = 'X'
  0: (b)\Xa\X
  1: X
 
-/(?P<ABC/
-Failed: syntax error after (?P at offset 7
+/(?P<ABC/I
+Failed: syntax error in subpattern name (missing terminator) at offset 7
 
-/(?:(?(A)(?P=A)a|b)(?P<A>X|Y))+/
+/(?:(?(A)(?P=A)a|b)(?P<A>X|Y))+/I
 Capturing subpattern count = 1
 Max back reference = 1
 Named capturing subpatterns:
@@ -6332,7 +6287,7 @@ No need char
  0: bX
  1: X
 
-/()()()()()()()()()(?:(?(A)(?P=A)a|b)(?P<A>X|Y))+/
+/()()()()()()()()()(?:(?(A)(?P=A)a|b)(?P<A>X|Y))+/I
 Capturing subpattern count = 10
 Max back reference = 10
 Named capturing subpatterns:
@@ -6353,10 +6308,10 @@ No need char
  9: 
 10: Y
 
-/\777/
+/\777/I
 Failed: octal value is greater than \377 (not in UTF-8 mode) at offset 3
 
-/\s*,\s*/S
+/\s*,\s*/IS
 Capturing subpattern count = 0
 Partial matching not supported
 No options
@@ -6368,7 +6323,7 @@ Starting byte set: \x09 \x0a \x0c \x0d \x20 ,
     \x0c,\x0d 
  0: \x0c,\x0d
 
-/^abc/m
+/^abc/Im
 Capturing subpattern count = 0
 Options: multiline
 First char at start or follows newline
@@ -6396,9 +6351,10 @@ No match
     xyz\rabc\<lf>
 No match
     
-/abc$/m
+/abc$/Im<lf>
 Capturing subpattern count = 0
 Options: multiline
+Forced newline sequence: LF
 First char = 'a'
 Need char = 'c'
     xyzabc
@@ -6426,7 +6382,7 @@ No match
     xyzabc\r\npqr 
 No match
     
-/^abc/m<cr>
+/^abc/Im<cr>
 Capturing subpattern count = 0
 Options: multiline
 Forced newline sequence: CR
@@ -6441,7 +6397,7 @@ No match
     xyz\nabcdef
 No match
        
-/^abc/m<lf>
+/^abc/Im<lf>
 Capturing subpattern count = 0
 Options: multiline
 Forced newline sequence: LF
@@ -6456,7 +6412,7 @@ No match
     xyz\rabcdef
 No match
        
-/^abc/m<crlf>
+/^abc/Im<crlf>
 Capturing subpattern count = 0
 Options: multiline
 Forced newline sequence: CRLF
@@ -6471,11 +6427,11 @@ No match
     xyz\rabcdef
 No match
     
-/^abc/m<bad>
+/^abc/Im<bad>
 Unknown newline type at: <bad>
 
 
-/abc/
+/abc/I
 Capturing subpattern count = 0
 No options
 First char = 'a'
@@ -6485,10 +6441,11 @@ Unknown newline type at: <bad>
     abc  
  0: abc
        
-/.*/
+/.*/I<lf>
 Capturing subpattern count = 0
 Partial matching not supported
-No options
+Options:
+Forced newline sequence: LF
 First char at start or follows newline
 No need char
     abc\ndef
@@ -6510,7 +6467,7 @@ No need char
     \<crlf>abc\r\ndef
  0: abc
 
-/\w+(.)(.)?def/s
+/\w+(.)(.)?def/Is
 Capturing subpattern count = 2
 Partial matching not supported
 Options: dotall
@@ -6527,7 +6484,7 @@ Need char = 'f'
  1: \x0d
  2: \x0a
 
-+((?:\s|//.*\\n|/[*](?:\\n|.)*?[*]/)*)+
++((?:\s|//.*\\n|/[*](?:\\n|.)*?[*]/)*)+I
 Capturing subpattern count = 1
 Partial matching not supported
 No options
@@ -6539,7 +6496,7 @@ Minimum match() recursion limit = 6
  0: /* this is a C style comment */
  1: /* this is a C style comment */
 
-/(?P<B>25[0-5]|2[0-4]\d|[01]?\d?\d)(?:\.(?P>B)){3}/
+/(?P<B>25[0-5]|2[0-4]\d|[01]?\d?\d)(?:\.(?P>B)){3}/I
 Capturing subpattern count = 1
 Named capturing subpatterns:
   B   1
@@ -6547,8 +6504,1626 @@ No options
 No first char
 Need char = '.'
 
-/ End of testinput2 /
-Capturing subpattern count = 0
+/()()()()()()()()()()()()()()()()()()()()
+ ()()()()()()()()()()()()()()()()()()()()
+ ()()()()()()()()()()()()()()()()()()()()
+ ()()()()()()()()()()()()()()()()()()()()
+ ()()()()()()()()()()()()()()()()()()()()
+ (.(.))/Ix
+Capturing subpattern count = 102
+Options: extended
+No first char
+No need char
+    XY\O400  
+ 0: XY
+ 1: 
+ 2: 
+ 3: 
+ 4: 
+ 5: 
+ 6: 
+ 7: 
+ 8: 
+ 9: 
+10: 
+11: 
+12: 
+13: 
+14: 
+15: 
+16: 
+17: 
+18: 
+19: 
+20: 
+21: 
+22: 
+23: 
+24: 
+25: 
+26: 
+27: 
+28: 
+29: 
+30: 
+31: 
+32: 
+33: 
+34: 
+35: 
+36: 
+37: 
+38: 
+39: 
+40: 
+41: 
+42: 
+43: 
+44: 
+45: 
+46: 
+47: 
+48: 
+49: 
+50: 
+51: 
+52: 
+53: 
+54: 
+55: 
+56: 
+57: 
+58: 
+59: 
+60: 
+61: 
+62: 
+63: 
+64: 
+65: 
+66: 
+67: 
+68: 
+69: 
+70: 
+71: 
+72: 
+73: 
+74: 
+75: 
+76: 
+77: 
+78: 
+79: 
+80: 
+81: 
+82: 
+83: 
+84: 
+85: 
+86: 
+87: 
+88: 
+89: 
+90: 
+91: 
+92: 
+93: 
+94: 
+95: 
+96: 
+97: 
+98: 
+99: 
+100: 
+101: XY
+102: Y
+
+/(a*b|(?i:c*(?-i)d))/IS
+Capturing subpattern count = 1
+Partial matching not supported
 No options
-First char = ' '
-Need char = ' '
+No first char
+No need char
+Starting byte set: C a b c d 
+
+/()[ab]xyz/IS
+Capturing subpattern count = 1
+No options
+No first char
+Need char = 'z'
+Starting byte set: a b 
+
+/(|)[ab]xyz/IS
+Capturing subpattern count = 1
+No options
+No first char
+Need char = 'z'
+Starting byte set: a b 
+
+/(|c)[ab]xyz/IS
+Capturing subpattern count = 1
+No options
+No first char
+Need char = 'z'
+Starting byte set: a b c 
+
+/(|c?)[ab]xyz/IS
+Capturing subpattern count = 1
+No options
+No first char
+Need char = 'z'
+Starting byte set: a b c 
+
+/(d?|c?)[ab]xyz/IS
+Capturing subpattern count = 1
+No options
+No first char
+Need char = 'z'
+Starting byte set: a b c d 
+
+/(d?|c)[ab]xyz/IS
+Capturing subpattern count = 1
+No options
+No first char
+Need char = 'z'
+Starting byte set: a b c d 
+
+/^a*b\d/D
+------------------------------------------------------------------
+  0   9 Bra 0
+  3     ^
+  4     a*+
+  6     b
+  8     \d
+  9   9 Ket
+ 12     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: anchored
+No first char
+Need char = 'b'
+
+/^a*+b\d/D
+------------------------------------------------------------------
+  0   9 Bra 0
+  3     ^
+  4     a*+
+  6     b
+  8     \d
+  9   9 Ket
+ 12     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: anchored
+No first char
+Need char = 'b'
+
+/^a*?b\d/D
+------------------------------------------------------------------
+  0   9 Bra 0
+  3     ^
+  4     a*+
+  6     b
+  8     \d
+  9   9 Ket
+ 12     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: anchored
+No first char
+Need char = 'b'
+
+/^a+A\d/D
+------------------------------------------------------------------
+  0   9 Bra 0
+  3     ^
+  4     a++
+  6     A
+  8     \d
+  9   9 Ket
+ 12     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: anchored
+No first char
+Need char = 'A'
+    aaaA5
+ 0: aaaA5
+    ** Failers
+No match
+    aaaa5 
+No match
+
+/^a*A\d/IiD
+------------------------------------------------------------------
+  0   9 Bra 0
+  3     ^
+  4     a*
+  6  NC A
+  8     \d
+  9   9 Ket
+ 12     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: anchored caseless
+No first char
+Need char = 'A' (caseless)
+    aaaA5
+ 0: aaaA5
+    aaaa5
+ 0: aaaa5
+
+/(a*|b*)[cd]/IS
+Capturing subpattern count = 1
+Partial matching not supported
+No options
+No first char
+No need char
+Starting byte set: a b c d 
+
+/(a+|b*)[cd]/IS
+Capturing subpattern count = 1
+Partial matching not supported
+No options
+No first char
+No need char
+Starting byte set: a b c d 
+
+/(a*|b+)[cd]/IS
+Capturing subpattern count = 1
+Partial matching not supported
+No options
+No first char
+No need char
+Starting byte set: a b c d 
+
+/(a+|b+)[cd]/IS
+Capturing subpattern count = 1
+Partial matching not supported
+No options
+No first char
+No need char
+Starting byte set: a b 
+
+/((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+ ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
+ (((
+ a
+ ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+ ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+ ))) 
+/Ix  
+Capturing subpattern count = 203
+Options: extended
+First char = 'a'
+No need char
+  large nest
+Matched, but too many substrings
+ 0: a
+ 1: a
+ 2: a
+ 3: a
+ 4: a
+ 5: a
+ 6: a
+ 7: a
+ 8: a
+ 9: a
+10: a
+11: a
+12: a
+13: a
+14: a
+
+/a*\d/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     a*+
+  5     \d
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/a*\D/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     a*
+  5     \D
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/0*\d/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     0*
+  5     \d
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/0*\D/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     0*+
+  5     \D
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/a*\s/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     a*+
+  5     \s
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/a*\S/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     a*
+  5     \S
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/ *\s/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3      *
+  5     \s
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/ *\S/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3      *+
+  5     \S
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/a*\w/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     a*
+  5     \w
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/a*\W/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     a*+
+  5     \W
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/=*\w/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     =*+
+  5     \w
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/=*\W/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     =*
+  5     \W
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\d*a/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \d*+
+  5     a
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\d*2/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \d*
+  5     2
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\d*\d/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \d*
+  5     \d
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\d*\D/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \d*+
+  5     \D
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\d*\s/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \d*+
+  5     \s
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\d*\S/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \d*
+  5     \S
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\d*\w/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \d*
+  5     \w
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\d*\W/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \d*+
+  5     \W
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\D*a/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \D*
+  5     a
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\D*2/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \D*+
+  5     2
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\D*\d/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \D*+
+  5     \d
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\D*\D/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \D*
+  5     \D
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\D*\s/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \D*
+  5     \s
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\D*\S/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \D*
+  5     \S
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\D*\w/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \D*
+  5     \w
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\D*\W/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \D*
+  5     \W
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\s*a/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \s*+
+  5     a
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\s*2/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \s*+
+  5     2
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\s*\d/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \s*+
+  5     \d
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\s*\D/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \s*
+  5     \D
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\s*\s/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \s*
+  5     \s
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\s*\S/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \s*+
+  5     \S
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\s*\w/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \s*+
+  5     \w
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\s*\W/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \s*
+  5     \W
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\S*a/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \S*
+  5     a
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\S*2/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \S*
+  5     2
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\S*\d/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \S*
+  5     \d
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\S*\D/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \S*
+  5     \D
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\S*\s/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \S*+
+  5     \s
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\S*\S/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \S*
+  5     \S
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\S*\w/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \S*
+  5     \w
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\S*\W/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \S*
+  5     \W
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\w*a/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \w*
+  5     a
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\w*2/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \w*
+  5     2
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\w*\d/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \w*
+  5     \d
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\w*\D/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \w*
+  5     \D
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\w*\s/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \w*+
+  5     \s
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\w*\S/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \w*
+  5     \S
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\w*\w/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \w*
+  5     \w
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\w*\W/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \w*+
+  5     \W
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\W*a/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \W*+
+  5     a
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\W*2/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \W*+
+  5     2
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/\W*\d/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \W*+
+  5     \d
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\W*\D/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \W*
+  5     \D
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\W*\s/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \W*
+  5     \s
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\W*\S/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \W*
+  5     \S
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\W*\w/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \W*+
+  5     \w
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/\W*\W/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     \W*
+  5     \W
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/[^a]+a/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     [^a]++
+  5     a
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/[^a]+a/Bi
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     [^A]++
+  5  NC a
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/[^a]+A/Bi
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     [^A]++
+  5  NC A
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/[^a]+b/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     [^a]+
+  5     b
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/[^a]+\d/B
+------------------------------------------------------------------
+  0   6 Bra 0
+  3     [^a]+
+  5     \d
+  6   6 Ket
+  9     End
+------------------------------------------------------------------
+
+/a*[^a]/B
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     a*
+  5     [^a]
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+
+/(?P<abc>x)(?P<xyz>y)/I
+Capturing subpattern count = 2
+Named capturing subpatterns:
+  abc   1
+  xyz   2
+No options
+First char = 'x'
+Need char = 'y'
+    xy\Cabc\Cxyz
+ 0: xy
+ 1: x
+ 2: y
+  C x (1) abc
+  C y (1) xyz
+
+/(?<abc>x)(?'xyz'y)/I
+Capturing subpattern count = 2
+Named capturing subpatterns:
+  abc   1
+  xyz   2
+No options
+First char = 'x'
+Need char = 'y'
+    xy\Cabc\Cxyz
+ 0: xy
+ 1: x
+ 2: y
+  C x (1) abc
+  C y (1) xyz
+
+/(?<abc'x)(?'xyz'y)/I
+Failed: syntax error in subpattern name (missing terminator) at offset 6
+
+/(?<abc>x)(?'xyz>y)/I
+Failed: syntax error in subpattern name (missing terminator) at offset 15
+
+/(?P'abc'x)(?P<xyz>y)/I
+Failed: unrecognized character after (?P at offset 3
+
+/^(?:(?(ZZ)a|b)(?<ZZ>X))+/
+    bXaX
+ 0: bXaX
+ 1: X
+    bXbX
+ 0: bX
+ 1: X
+    ** Failers
+No match
+    aXaX   
+No match
+    aXbX 
+No match
+
+/^(?P>abc)(?<abcd>xxx)/
+Failed: reference to non-existent subpattern at offset 8
+
+/^(?P>abc)(?<abc>x|y)/
+    xx
+ 0: xx
+ 1: x
+    xy
+ 0: xy
+ 1: y
+    yy
+ 0: yy
+ 1: y
+    yx   
+ 0: yx
+ 1: x
+
+/^(?P>abc)(?P<abc>x|y)/
+    xx
+ 0: xx
+ 1: x
+    xy
+ 0: xy
+ 1: y
+    yy
+ 0: yy
+ 1: y
+    yx   
+ 0: yx
+ 1: x
+
+/^((?(abc)a|b)(?<abc>x|y))+/
+    bxay
+ 0: bxay
+ 1: ay
+ 2: y
+    bxby 
+ 0: bx
+ 1: bx
+ 2: x
+    ** Failers
+No match
+    axby  
+No match
+
+/^(((?P=abc)|X)(?<abc>x|y))+/
+    XxXxxx
+ 0: XxXxxx
+ 1: xx
+ 2: x
+ 3: x
+    XxXyyx
+ 0: XxXyyx
+ 1: yx
+ 2: y
+ 3: x
+    XxXyxx
+ 0: XxXy
+ 1: Xy
+ 2: X
+ 3: y
+    ** Failers
+No match
+    x  
+No match
+
+/^(?1)(abc)/
+    abcabc
+ 0: abcabc
+ 1: abc
+
+/^(?:(?:\1|X)(a|b))+/
+    Xaaa
+ 0: Xaaa
+ 1: a
+    Xaba 
+ 0: Xa
+ 1: a
+
+/^[\E\Qa\E-\Qz\E]+/B
+------------------------------------------------------------------
+  0  38 Bra 0
+  3     ^
+  4     [a-z]+
+ 38  38 Ket
+ 41     End
+------------------------------------------------------------------
+    
+/^[a\Q]bc\E]/B
+------------------------------------------------------------------
+  0  37 Bra 0
+  3     ^
+  4     [\]a-c]
+ 37  37 Ket
+ 40     End
+------------------------------------------------------------------
+    
+/^[a-\Q\E]/B
+------------------------------------------------------------------
+  0  37 Bra 0
+  3     ^
+  4     [\-a]
+ 37  37 Ket
+ 40     End
+------------------------------------------------------------------
+
+/^(?P>abc)[()](?<abc>)/B
+------------------------------------------------------------------
+  0  54 Bra 0
+  3     ^
+  4   6 Once
+  7  46 Recurse
+ 10   6 Ket
+ 13     [()]
+ 46   5 Bra 1
+ 51   5 Ket
+ 54  54 Ket
+ 57     End
+------------------------------------------------------------------
+
+/^((?(abc)y)[()](?P<abc>x))+/B
+------------------------------------------------------------------
+  0  66 Bra 0
+  3     ^
+  4  59 Bra 1
+  9   8 Cond
+ 12   2 Cond ref
+ 15     y
+ 17   8 Ket
+ 20     [()]
+ 53   7 Bra 2
+ 58     x
+ 60   7 Ket
+ 63  59 KetRmax
+ 66  66 Ket
+ 69     End
+------------------------------------------------------------------
+    (xy)x
+ 0: (xy)x
+ 1: y)x
+ 2: x
+    
+/^(?P>abc)\Q()\E(?<abc>)/B 
+------------------------------------------------------------------
+  0  25 Bra 0
+  3     ^
+  4   6 Once
+  7  17 Recurse
+ 10   6 Ket
+ 13     ()
+ 17   5 Bra 1
+ 22   5 Ket
+ 25  25 Ket
+ 28     End
+------------------------------------------------------------------
+
+/^(?P>abc)[a\Q(]\E(](?<abc>)/B 
+------------------------------------------------------------------
+  0  54 Bra 0
+  3     ^
+  4   6 Once
+  7  46 Recurse
+ 10   6 Ket
+ 13     [(\]a]
+ 46   5 Bra 1
+ 51   5 Ket
+ 54  54 Ket
+ 57     End
+------------------------------------------------------------------
+
+/^(?P>abc) # this is (a comment)
+  (?<abc>)/Bx 
+------------------------------------------------------------------
+  0  21 Bra 0
+  3     ^
+  4   6 Once
+  7  13 Recurse
+ 10   6 Ket
+ 13   5 Bra 1
+ 18   5 Ket
+ 21  21 Ket
+ 24     End
+------------------------------------------------------------------
+
+/^\W*(?:(?<one>(?<two>.)\W*(?&one)\W*\k<two>|)|(?<three>(?<four>.)\W*(?&three)\W*\k'four'|\W*.\W*))\W*$/Ii
+Capturing subpattern count = 4
+Max back reference = 4
+Named capturing subpatterns:
+  four    4
+  one     1
+  three   3
+  two     2
+Partial matching not supported
+Options: anchored caseless
+No first char
+No need char
+    1221
+ 0: 1221
+ 1: 1221
+ 2: 1
+    Satan, oscillate my metallic sonatas!
+ 0: Satan, oscillate my metallic sonatas!
+ 1: <unset>
+ 2: <unset>
+ 3: Satan, oscillate my metallic sonatas
+ 4: S
+    A man, a plan, a canal: Panama!
+ 0: A man, a plan, a canal: Panama!
+ 1: <unset>
+ 2: <unset>
+ 3: A man, a plan, a canal: Panama
+ 4: A
+    Able was I ere I saw Elba. 
+ 0: Able was I ere I saw Elba.
+ 1: <unset>
+ 2: <unset>
+ 3: Able was I ere I saw Elba
+ 4: A
+    *** Failers
+No match
+    The quick brown fox  
+No match
+    
+/(?=(\w+))\1:/I
+Capturing subpattern count = 1
+Max back reference = 1
+Partial matching not supported
+No options
+No first char
+Need char = ':'
+    abcd:
+ 0: abcd:
+ 1: abcd
+
+/(?=(?'abc'\w+))\k<abc>:/I
+Capturing subpattern count = 1
+Max back reference = 1
+Named capturing subpatterns:
+  abc   1
+Partial matching not supported
+No options
+No first char
+Need char = ':'
+    abcd:
+ 0: abcd:
+ 1: abcd
+
+/(?'abc'\w+):\k<abc>{2}/
+    a:aaxyz
+ 0: a:aa
+ 1: a
+    ab:ababxyz
+ 0: ab:abab
+ 1: ab
+    ** Failers
+No match
+    a:axyz   
+No match
+    ab:abxyz 
+No match
+
+/(?'abc'a|b)(?<abc>d|e)\k<abc>{2}/J
+    adaa
+ 0: adaa
+ 1: a
+ 2: d
+    ** Failers
+No match
+    addd
+No match
+    adbb   
+No match
+
+/(?'abc'a|b)(?<abc>d|e)(?&abc){2}/J
+    bdaa
+ 0: bdaa
+ 1: b
+ 2: d
+    bdab
+ 0: bdab
+ 1: b
+ 2: d
+    ** Failers
+No match
+    bddd   
+No match
+
+/^(?<ab>a)? (?(<ab>)b|c) (?('ab')d|e)/x
+    abd
+ 0: abd
+ 1: a
+    ce 
+ 0: ce
+    
+/(?(<bc))/
+Failed: malformed number or name after (?( at offset 6
+
+/(?(''))/ 
+Failed: assertion expected after (?( at offset 4
+
+/(?('R')stuff)/
+Failed: reference to non-existent subpattern at offset 7
+
+/((abc (?(R) (?(R1)1) (?(R2)2) X  |  (?1)  (?2)   (?R) ))) /x
+    abcabc1Xabc2XabcXabcabc
+ 0: abcabc1Xabc2XabcX
+ 1: abcabc1Xabc2XabcX
+ 2: abcabc1Xabc2XabcX
+
+/(?<A> (?'B' abc (?(R) (?(R&A)1) (?(R&B)2) X  |  (?1)  (?2)   (?R) ))) /x
+    abcabc1Xabc2XabcXabcabc
+ 0: abcabc1Xabc2XabcX
+ 1: abcabc1Xabc2XabcX
+ 2: abcabc1Xabc2XabcX
+
+/(?<A> (?'B' abc (?(R) (?(R&1)1) (?(R&B)2) X  |  (?1)  (?2)   (?R) ))) /x
+Failed: reference to non-existent subpattern at offset 29
+
+/(?<1> (?'B' abc (?(R) (?(R&1)1) (?(R&B)2) X  |  (?1)  (?2)   (?R) ))) /x
+    abcabc1Xabc2XabcXabcabc
+ 0: abcabc1Xabc2XabcX
+ 1: abcabc1Xabc2XabcX
+ 2: abcabc1Xabc2XabcX
+
+/^(?(DEFINE) (?<A> a) (?<B> b) )  (?&A) (?&B) /x
+    abcd
+ 0: ab
+ 1: <unset>
+ 2: <unset>
+    
+/(?<NAME>(?&NAME_PAT))\s+(?<ADDR>(?&ADDRESS_PAT))
+  (?(DEFINE)
+  (?<NAME_PAT>[a-z]+)
+  (?<ADDRESS_PAT>\d+)
+  )/x
+    metcalfe 33
+ 0: metcalfe 33
+ 1: metcalfe
+ 2: 33
+ 3: <unset>
+ 4: <unset>
+/^(?(DEFINE) abc | xyz ) /x
+Failed: DEFINE group contains more than one branch at offset 22
+
+/(?(DEFINE) abc) xyz/xI
+Capturing subpattern count = 0
+Options: extended
+First char = 'x'
+Need char = 'z'
+
+/(?(DEFINE) abc){3} xyz/x
+Failed: repeating a DEFINE group is not allowed at offset 17
+
+/(a|)*\d/
+  \O0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+No match
+  \O0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+Matched, but too many substrings
+
+/^a.b/<lf>
+    a\rb
+ 0: a\x0db
+    a\nb\<cr> 
+ 0: a\x0ab
+    ** Failers
+No match
+    a\nb
+No match
+    a\nb\<any>
+No match
+    a\rb\<cr>   
+No match
+    a\rb\<any>   
+No match
+
+/^abc./mgx<any>
+    abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x85abc7 \x{2028}abc8 \x{2029}abc9 JUNK
+ 0: abc1
+ 0: abc2
+ 0: abc3
+ 0: abc4
+ 0: abc5
+ 0: abc6
+ 0: abc7
+
+/abc.$/mgx<any>
+    abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x85 abc7\x{2028} abc8\x{2029} abc9
+ 0: abc1
+ 0: abc2
+ 0: abc3
+ 0: abc4
+ 0: abc5
+ 0: abc6
+ 0: abc9
+
+/a/<cr><any>
+Failed: inconsistent NEWLINE options at offset 0
+
+/a/<any><crlf>
+Failed: inconsistent NEWLINE options at offset 0
+
+/^a\Rb/
+    a\nb
+ 0: a\x0ab
+    a\rb
+ 0: a\x0db
+    a\r\nb
+ 0: a\x0d\x0ab
+    a\x0bb
+ 0: a\x0bb
+    a\x0cb
+ 0: a\x0cb
+    a\x85b   
+ 0: a\x85b
+    ** Failers
+No match
+    a\n\rb    
+No match
+
+/^a\R*b/
+    ab
+ 0: ab
+    a\nb
+ 0: a\x0ab
+    a\rb
+ 0: a\x0db
+    a\r\nb
+ 0: a\x0d\x0ab
+    a\x0bb
+ 0: a\x0bb
+    a\x0cb
+ 0: a\x0cb
+    a\x85b   
+ 0: a\x85b
+    a\n\rb    
+ 0: a\x0a\x0db
+    a\n\r\x85\x0cb 
+ 0: a\x0a\x0d\x85\x0cb
+
+/^a\R+b/
+    a\nb
+ 0: a\x0ab
+    a\rb
+ 0: a\x0db
+    a\r\nb
+ 0: a\x0d\x0ab
+    a\x0bb
+ 0: a\x0bb
+    a\x0cb
+ 0: a\x0cb
+    a\x85b   
+ 0: a\x85b
+    a\n\rb    
+ 0: a\x0a\x0db
+    a\n\r\x85\x0cb 
+ 0: a\x0a\x0d\x85\x0cb
+    ** Failers
+No match
+    ab  
+No match
+    
+/^a\R{1,3}b/
+    a\nb
+ 0: a\x0ab
+    a\n\rb
+ 0: a\x0a\x0db
+    a\n\r\x85b
+ 0: a\x0a\x0d\x85b
+    a\r\n\r\nb 
+ 0: a\x0d\x0a\x0d\x0ab
+    a\r\n\r\n\r\nb 
+ 0: a\x0d\x0a\x0d\x0a\x0d\x0ab
+    a\n\r\n\rb
+ 0: a\x0a\x0d\x0a\x0db
+    a\n\n\r\nb 
+ 0: a\x0a\x0a\x0d\x0ab
+    ** Failers
+No match
+    a\n\n\n\rb
+No match
+    a\r
+No match
+
+/^a[\R]b/
+    aRb
+ 0: aRb
+    ** Failers
+No match
+    a\nb  
+No match
+
+/(?&abc)X(?<abc>P)/I
+Capturing subpattern count = 1
+Named capturing subpatterns:
+  abc   1
+No options
+No first char
+Need char = 'P'
+    abcPXP123
+ 0: PXP
+ 1: P
+
+/(?1)X(?<abc>P)/I
+Capturing subpattern count = 1
+Named capturing subpatterns:
+  abc   1
+No options
+No first char
+Need char = 'P'
+    abcPXP123
+ 0: PXP
+ 1: P
+
+/(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))\b(?&byte)(\.(?&byte)){3}/
+    1.2.3.4
+ 0: 1.2.3.4
+ 1: <unset>
+ 2: .4
+    131.111.10.206
+ 0: 131.111.10.206
+ 1: <unset>
+ 2: .206
+    10.0.0.0
+ 0: 10.0.0.0
+ 1: <unset>
+ 2: .0
+    ** Failers
+No match
+    10.6
+No match
+    455.3.4.5   
+No match
+
+/\b(?&byte)(\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\d|25[0-5]|1\d\d|[1-9]?\d))/
+    1.2.3.4
+ 0: 1.2.3.4
+ 1: .4
+ 2: <unset>
+    131.111.10.206
+ 0: 131.111.10.206
+ 1: .206
+ 2: <unset>
+    10.0.0.0
+ 0: 10.0.0.0
+ 1: .0
+ 2: <unset>
+    ** Failers
+No match
+    10.6
+No match
+    455.3.4.5   
+No match
+    
+/(?:a(?&abc)b)*(?<abc>x)/
+    123axbaxbaxbx456
+ 0: axbaxbaxbx
+ 1: x
+    123axbaxbaxb456
+ 0: x
+ 1: x
+      
+/(?:a(?&abc)b){1,5}(?<abc>x)/
+    123axbaxbaxbx456
+ 0: axbaxbaxbx
+ 1: x
+
+/(?:a(?&abc)b){2,5}(?<abc>x)/
+    123axbaxbaxbx456
+ 0: axbaxbaxbx
+ 1: x
+
+/(?:a(?&abc)b){2,}(?<abc>x)/
+    123axbaxbaxbx456
+ 0: axbaxbaxbx
+ 1: x
+
+/(abc)(?i:(?1))/
+   defabcabcxyz
+ 0: abcabc
+ 1: abc
+   DEFabcABCXYZ
+No match
+
+/(abc)(?:(?i)(?1))/
+   defabcabcxyz
+ 0: abcabc
+ 1: abc
+   DEFabcABCXYZ
+No match
+
+/^(a(b))\1\g1\g{1}\g-1\g{-1}\g{-02}Z/
+    ababababbbabZXXXX
+ 0: ababababbbabZ
+ 1: ab
+ 2: b
+
+/^(a)\g-2/
+Failed: reference to non-existent subpattern at offset 4
+
+/^(a)\g/
+Failed: \g is not followed by an (optionally braced) non-zero number at offset 4
+
+/^(a)\g{0}/
+Failed: \g is not followed by an (optionally braced) non-zero number at offset 4
+
+/^(a)\g{3/
+Failed: \g is not followed by an (optionally braced) non-zero number at offset 4
+
+/^(a)\g{4a}/
+Failed: \g is not followed by an (optionally braced) non-zero number at offset 4
+
+/^a.b/<lf>
+    a\rb
+ 0: a\x0db
+    *** Failers
+No match
+    a\nb
+No match
+
+/.+foo/
+    afoo
+ 0: afoo
+    ** Failers 
+No match
+    \r\nfoo 
+No match
+    \nfoo 
+No match
+
+/.+foo/<crlf>
+    afoo
+ 0: afoo
+    \nfoo 
+ 0: \x0afoo
+    ** Failers 
+No match
+    \r\nfoo 
+No match
+
+/.+foo/<any>
+    afoo
+ 0: afoo
+    ** Failers 
+No match
+    \nfoo 
+No match
+    \r\nfoo 
+No match
+
+/.+foo/s
+    afoo
+ 0: afoo
+    \r\nfoo 
+ 0: \x0d\x0afoo
+    \nfoo 
+ 0: \x0afoo
+
+/ End of testinput2 /
index 06e2888d91bd9d60a8caf807f7c9e8ee1ae526c0..c539579832cc02a4429e63e3d6c9399cd59d40d3 100644 (file)
@@ -149,9 +149,9 @@ No match
 /[[:alpha:]][[:lower:]][[:upper:]]/DLfr_FR 
 ------------------------------------------------------------------
   0 102 Bra 0
-  3     [A-Za-zªµºÀ-ÖØ-öø-ÿ]
- 36     [a-zµß-öø-ÿ]
- 69     [A-ZÀ-ÖØ-Þ]
+  3     [A-Za-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\xff]
+ 36     [a-z\xb5\xdf-\xf6\xf8-\xff]
+ 69     [A-Z\xc0-\xd6\xd8-\xde]
 102 102 Ket
 105     End
 ------------------------------------------------------------------
index 3b4945507531db945ed766eb207bb885950bd608..966b28568ce08a6e39adde6f7768bd6be930748c 100644 (file)
@@ -914,4 +914,8 @@ No match
  0: ab
  1: ab
 
+/a*\x{100}*\w/8
+    a 
+ 0: a
+
 / End of testinput4 /
index 2c5e3c09cd470746d94e4dded427c03c8961a80c..61c6842d77bfb7fcdd43564e049f104f54097e20 100644 (file)
@@ -103,7 +103,7 @@ First char = 195
 Need char = 191
 
 /[\x{100}]/8DM
-Memory allocation (code space): 47
+Memory allocation (code space): 15
 ------------------------------------------------------------------
   0  11 Bra 0
   3     [\x{100}]
@@ -429,11 +429,11 @@ No match
 
 /Ā{3,4}/8SD
 ------------------------------------------------------------------
-  0  13 Bra 0
+  0  11 Bra 0
   3     \x{100}{3}
-  8     \x{100}{,1}
- 13  13 Ket
- 16     End
+  8     \x{100}?
+ 11  11 Ket
+ 14     End
 ------------------------------------------------------------------
 Capturing subpattern count = 0
 Partial matching not supported
@@ -445,29 +445,10 @@ Study returned NULL
  0: \x{100}\x{100}\x{100}
 
 /(\x{100}+|x)/8SD
-------------------------------------------------------------------
-  0  17 Bra 0
-  3   6 Bra 1
-  6     \x{100}+
-  9   5 Alt
- 12     x
- 14  11 Ket
- 17  17 Ket
- 20     End
-------------------------------------------------------------------
-Capturing subpattern count = 1
-Partial matching not supported
-Options: utf8
-No first char
-No need char
-Starting byte set: x \xc4 
-
-/(\x{100}*a|x)/8SD
 ------------------------------------------------------------------
   0  19 Bra 0
   3   8 Bra 1
-  6     \x{100}*
-  9     a
+  8     \x{100}+
  11   5 Alt
  14     x
  16  13 Ket
@@ -479,13 +460,13 @@ Partial matching not supported
 Options: utf8
 No first char
 No need char
-Starting byte set: x \xc4 
+Starting byte set: x \xc4 
 
-/(\x{100}{0,2}a|x)/8SD
+/(\x{100}*a|x)/8SD
 ------------------------------------------------------------------
   0  21 Bra 0
   3  10 Bra 1
-  6     \x{100}{,2}
+  8     \x{100}*+
  11     a
  13   5 Alt
  16     x
@@ -500,18 +481,37 @@ No first char
 No need char
 Starting byte set: a x \xc4 
 
+/(\x{100}{0,2}a|x)/8SD
+------------------------------------------------------------------
+  0  23 Bra 0
+  3  12 Bra 1
+  8     \x{100}{0,2}
+ 13     a
+ 15   5 Alt
+ 18     x
+ 20  17 Ket
+ 23  23 Ket
+ 26     End
+------------------------------------------------------------------
+Capturing subpattern count = 1
+Partial matching not supported
+Options: utf8
+No first char
+No need char
+Starting byte set: a x \xc4 
+
 /(\x{100}{1,2}a|x)/8SD
 ------------------------------------------------------------------
-  0  24 Bra 0
-  3  13 Bra 1
-  6     \x{100}
 9     \x{100}{,1}
- 14     a
- 16   5 Alt
19     x
- 21  18 Ket
- 24  24 Ket
- 27     End
+  0  26 Bra 0
+  3  15 Bra 1
+  8     \x{100}
11     \x{100}{0,1}
+ 16     a
+ 18   5 Alt
21     x
+ 23  20 Ket
+ 26  26 Ket
+ 29     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Partial matching not supported
@@ -628,7 +628,7 @@ Need char = 129
 /\x{100}*A/8D
 ------------------------------------------------------------------
   0   8 Bra 0
-  3     \x{100}*
+  3     \x{100}*+
   6     A
   8   8 Ket
  11     End
@@ -644,7 +644,7 @@ Need char = 'A'
 /\x{100}*\d(?R)/8D
 ------------------------------------------------------------------
   0  16 Bra 0
-  3     \x{100}*
+  3     \x{100}*+
   6     \d
   7   6 Once
  10   0 Recurse
@@ -683,7 +683,7 @@ No first char
 No need char
 
 /[\x{100}]/8DM
-Memory allocation (code space): 47
+Memory allocation (code space): 15
 ------------------------------------------------------------------
   0  11 Bra 0
   3     [\x{100}]
@@ -912,16 +912,16 @@ No match
 
 /\x{100}abc(xyz(?1))/8D
 ------------------------------------------------------------------
-  0  33 Bra 0
+  0  35 Bra 0
   3     \x{100}abc
- 12  18 Bra 1
- 15     xyz
- 21   6 Once
- 24  12 Recurse
- 27   6 Ket
- 30  18 Ket
- 33  33 Ket
- 36     End
+ 12  20 Bra 1
+ 17     xyz
+ 23   6 Once
+ 26  12 Recurse
+ 29   6 Ket
+ 32  20 Ket
+ 35  35 Ket
+ 38     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Options: utf8
@@ -930,17 +930,17 @@ Need char = 'z'
 
 /[^\x{100}]abc(xyz(?1))/8D
 ------------------------------------------------------------------
-  0  38 Bra 0
+  0  40 Bra 0
   3     [^\x{100}]
  11     abc
- 17  18 Bra 1
- 20     xyz
- 26   6 Once
29  17 Recurse
- 32   6 Ket
- 35  18 Ket
38  38 Ket
- 41     End
+ 17  20 Bra 1
+ 22     xyz
+ 28   6 Once
31  17 Recurse
+ 34   6 Ket
+ 37  20 Ket
40  40 Ket
+ 43     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Options: utf8
@@ -949,17 +949,17 @@ Need char = 'z'
 
 /[ab\x{100}]abc(xyz(?1))/8D
 ------------------------------------------------------------------
-  0  70 Bra 0
+  0  72 Bra 0
   3     [ab\x{100}]
  43     abc
- 49  18 Bra 1
- 52     xyz
58   6 Once
- 61  49 Recurse
- 64   6 Ket
- 67  18 Ket
- 70  70 Ket
- 73     End
+ 49  20 Bra 1
+ 54     xyz
60   6 Once
+ 63  49 Recurse
+ 66   6 Ket
+ 69  20 Ket
+ 72  72 Ket
+ 75     End
 ------------------------------------------------------------------
 Capturing subpattern count = 1
 Options: utf8
@@ -968,20 +968,20 @@ Need char = 'z'
 
 /(\x{100}(b(?2)c))?/D8
 ------------------------------------------------------------------
-  0  32 Bra 0
+  0  36 Bra 0
   3     Brazero
-  4  25 Bra 1
-  7     \x{100}
- 10  16 Bra 2
- 13     b
- 15   6 Once
18  10 Recurse
- 21   6 Ket
- 24     c
26  16 Ket
29  25 Ket
- 32  32 Ket
- 35     End
+  4  29 Bra 1
+  9     \x{100}
+ 12  18 Bra 2
+ 17     b
+ 19   6 Once
22  12 Recurse
+ 25   6 Ket
+ 28     c
30  18 Ket
33  29 Ket
+ 36  36 Ket
+ 39     End
 ------------------------------------------------------------------
 Capturing subpattern count = 2
 Options: utf8
@@ -990,33 +990,33 @@ No need char
 
 /(\x{100}(b(?2)c)){0,2}/D8
 ------------------------------------------------------------------
-  0  67 Bra 0
+  0  75 Bra 0
   3     Brazero
-  4  60 Bra 0
-  7  25 Bra 1
- 10     \x{100}
- 13  16 Bra 2
16     b
18   6 Once
- 21  13 Recurse
- 24   6 Ket
27     c
29  16 Ket
- 32  25 Ket
- 35     Brazero
36  25 Bra 1
39     \x{100}
- 42  16 Bra 2
45     b
47   6 Once
- 50  13 Recurse
53   6 Ket
56     c
58  16 Ket
- 61  25 Ket
64  60 Ket
67  67 Ket
- 70     End
+  4  68 Bra 0
+  7  29 Bra 1
+ 12     \x{100}
+ 15  18 Bra 2
20     b
22   6 Once
+ 25  15 Recurse
+ 28   6 Ket
31     c
33  18 Ket
+ 36  29 Ket
+ 39     Brazero
40  29 Bra 1
45     \x{100}
+ 48  18 Bra 2
53     b
55   6 Once
+ 58  15 Recurse
61   6 Ket
64     c
66  18 Ket
+ 69  29 Ket
72  68 Ket
75  75 Ket
+ 78     End
 ------------------------------------------------------------------
 Capturing subpattern count = 2
 Options: utf8
@@ -1025,20 +1025,20 @@ No need char
 
 /(\x{100}(b(?1)c))?/D8
 ------------------------------------------------------------------
-  0  32 Bra 0
+  0  36 Bra 0
   3     Brazero
-  4  25 Bra 1
-  7     \x{100}
- 10  16 Bra 2
- 13     b
- 15   6 Once
18   4 Recurse
- 21   6 Ket
- 24     c
26  16 Ket
29  25 Ket
- 32  32 Ket
- 35     End
+  4  29 Bra 1
+  9     \x{100}
+ 12  18 Bra 2
+ 17     b
+ 19   6 Once
22   4 Recurse
+ 25   6 Ket
+ 28     c
30  18 Ket
33  29 Ket
+ 36  36 Ket
+ 39     End
 ------------------------------------------------------------------
 Capturing subpattern count = 2
 Options: utf8
@@ -1047,33 +1047,33 @@ No need char
 
 /(\x{100}(b(?1)c)){0,2}/D8
 ------------------------------------------------------------------
-  0  67 Bra 0
+  0  75 Bra 0
   3     Brazero
-  4  60 Bra 0
-  7  25 Bra 1
- 10     \x{100}
- 13  16 Bra 2
16     b
18   6 Once
- 21   7 Recurse
- 24   6 Ket
27     c
29  16 Ket
- 32  25 Ket
- 35     Brazero
36  25 Bra 1
39     \x{100}
- 42  16 Bra 2
45     b
47   6 Once
- 50   7 Recurse
53   6 Ket
56     c
58  16 Ket
- 61  25 Ket
64  60 Ket
67  67 Ket
- 70     End
+  4  68 Bra 0
+  7  29 Bra 1
+ 12     \x{100}
+ 15  18 Bra 2
20     b
22   6 Once
+ 25   7 Recurse
+ 28   6 Ket
31     c
33  18 Ket
+ 36  29 Ket
+ 39     Brazero
40  29 Bra 1
45     \x{100}
+ 48  18 Bra 2
53     b
55   6 Once
+ 58   7 Recurse
61   6 Ket
64     c
66  18 Ket
+ 69  29 Ket
72  68 Ket
75  75 Ket
+ 78     End
 ------------------------------------------------------------------
 Capturing subpattern count = 2
 Options: utf8
@@ -1119,5 +1119,285 @@ Need char = 191
  0: \x{1ff}
   \777 
  0: \x{1ff}
+  
+/\x{100}*\d/8D
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \x{100}*+
+  6     \d
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: utf8
+No first char
+No need char
+
+/\x{100}*\s/8D
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \x{100}*+
+  6     \s
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: utf8
+No first char
+No need char
+
+/\x{100}*\w/8D
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \x{100}*+
+  6     \w
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: utf8
+No first char
+No need char
+
+/\x{100}*\D/8D
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \x{100}*
+  6     \D
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: utf8
+No first char
+No need char
+
+/\x{100}*\S/8D
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \x{100}*
+  6     \S
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: utf8
+No first char
+No need char
+
+/\x{100}*\W/8D
+------------------------------------------------------------------
+  0   7 Bra 0
+  3     \x{100}*
+  6     \W
+  7   7 Ket
+ 10     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: utf8
+No first char
+No need char
+
+/\x{100}+\x{200}/8D
+------------------------------------------------------------------
+  0   9 Bra 0
+  3     \x{100}++
+  6     \x{200}
+  9   9 Ket
+ 12     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: utf8
+First char = 196
+Need char = 128
+
+/\x{100}+X/8D
+------------------------------------------------------------------
+  0   8 Bra 0
+  3     \x{100}++
+  6     X
+  8   8 Ket
+ 11     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: utf8
+First char = 196
+Need char = 'X'
+
+/X+\x{200}/8D
+------------------------------------------------------------------
+  0   8 Bra 0
+  3     X++
+  5     \x{200}
+  8   8 Ket
+ 11     End
+------------------------------------------------------------------
+Capturing subpattern count = 0
+Partial matching not supported
+Options: utf8
+First char = 'X'
+Need char = 128
+
+/()()()()()()()()()()
+ ()()()()()()()()()()
+ ()()()()()()()()()()
+ ()()()()()()()()()()
+ A (x) (?41) B/8x
+    AxxB     
+Matched, but too many substrings
+ 0: AxxB
+ 1: 
+ 2: 
+ 3: 
+ 4: 
+ 5: 
+ 6: 
+ 7: 
+ 8: 
+ 9: 
+10: 
+11: 
+12: 
+13: 
+14: 
+
+/^[\x{100}\E-\Q\E\x{150}]/B8
+------------------------------------------------------------------
+  0  14 Bra 0
+  3     ^
+  4     [\x{100}-\x{150}]
+ 14  14 Ket
+ 17     End
+------------------------------------------------------------------
+
+/^[\QĀ\E-\QŐ\E]/B8
+------------------------------------------------------------------
+  0  14 Bra 0
+  3     ^
+  4     [\x{100}-\x{150}]
+ 14  14 Ket
+ 17     End
+------------------------------------------------------------------
+
+/^[\QĀ\E-\QŐ\E/B8
+Failed: missing terminating ] for character class at offset 15
+
+/^abc./mgx8<any>
+    abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x{0085}abc7 \x{2028}abc8 \x{2029}abc9 JUNK
+ 0: abc1
+ 0: abc2
+ 0: abc3
+ 0: abc4
+ 0: abc5
+ 0: abc6
+ 0: abc7
+ 0: abc8
+ 0: abc9
+
+/abc.$/mgx8<any>
+    abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x{0085} abc7\x{2028} abc8\x{2029} abc9
+ 0: abc1
+ 0: abc2
+ 0: abc3
+ 0: abc4
+ 0: abc5
+ 0: abc6
+ 0: abc7
+ 0: abc8
+ 0: abc9
+
+/^a\Rb/8
+    a\nb
+ 0: a\x{0a}b
+    a\rb
+ 0: a\x{0d}b
+    a\r\nb
+ 0: a\x{0d}\x{0a}b
+    a\x0bb
+ 0: a\x{0b}b
+    a\x0cb
+ 0: a\x{0c}b
+    a\x{85}b   
+ 0: a\x{85}b
+    a\x{2028}b 
+ 0: a\x{2028}b
+    a\x{2029}b 
+ 0: a\x{2029}b
+    ** Failers
+No match
+    a\n\rb    
+No match
+
+/^a\R*b/8
+    ab
+ 0: ab
+    a\nb
+ 0: a\x{0a}b
+    a\rb
+ 0: a\x{0d}b
+    a\r\nb
+ 0: a\x{0d}\x{0a}b
+    a\x0bb
+ 0: a\x{0b}b
+    a\x0c\x{2028}\x{2029}b
+ 0: a\x{0c}\x{2028}\x{2029}b
+    a\x{85}b   
+ 0: a\x{85}b
+    a\n\rb    
+ 0: a\x{0a}\x{0d}b
+    a\n\r\x{85}\x0cb 
+ 0: a\x{0a}\x{0d}\x{85}\x{0c}b
+
+/^a\R+b/8
+    a\nb
+ 0: a\x{0a}b
+    a\rb
+ 0: a\x{0d}b
+    a\r\nb
+ 0: a\x{0d}\x{0a}b
+    a\x0bb
+ 0: a\x{0b}b
+    a\x0c\x{2028}\x{2029}b
+ 0: a\x{0c}\x{2028}\x{2029}b
+    a\x{85}b   
+ 0: a\x{85}b
+    a\n\rb    
+ 0: a\x{0a}\x{0d}b
+    a\n\r\x{85}\x0cb 
+ 0: a\x{0a}\x{0d}\x{85}\x{0c}b
+    ** Failers
+No match
+    ab  
+No match
+
+/^a\R{1,3}b/8
+    a\nb
+ 0: a\x{0a}b
+    a\n\rb
+ 0: a\x{0a}\x{0d}b
+    a\n\r\x{85}b
+ 0: a\x{0a}\x{0d}\x{85}b
+    a\r\n\r\nb 
+ 0: a\x{0d}\x{0a}\x{0d}\x{0a}b
+    a\r\n\r\n\r\nb 
+ 0: a\x{0d}\x{0a}\x{0d}\x{0a}\x{0d}\x{0a}b
+    a\n\r\n\rb
+ 0: a\x{0a}\x{0d}\x{0a}\x{0d}b
+    a\n\n\r\nb 
+ 0: a\x{0a}\x{0a}\x{0d}\x{0a}b
+    ** Failers
+No match
+    a\n\n\n\rb
+No match
+    a\r
+No match
 
 / End of testinput5 /
index ee174a6b016d8f80af6e451f451ef24faeec5e56..a8bb0adaaab92bfa58b2ef354c6e7ff87b81f1ff 100644 (file)
@@ -609,7 +609,7 @@ No first char
 No need char
 
 /[\p{Nd}]/8DM
-Memory allocation (code space): 47
+Memory allocation (code space): 15
 ------------------------------------------------------------------
   0  11 Bra 0
   3     [\p{Nd}]
@@ -1410,4 +1410,26 @@ No match
  1: L=abc
  2: abc
 
+/The next two should be Perl-compatible, but it fails to match \x{e0}. PCRE
+will match it only with UCP support, because without that it has no notion
+of case for anything other than the ASCII letters. / 
+
+/((?i)[\x{c0}])/8
+    \x{c0}
+ 0: \x{c0}
+ 1: \x{c0}
+    \x{e0} 
+ 0: \x{e0}
+ 1: \x{e0}
+
+/(?i:[\x{c0}])/8
+    \x{c0}
+ 0: \x{c0}
+    \x{e0} 
+ 0: \x{e0}
+    
+/^\p{Balinese}\p{Cuneiform}\p{Nko}\p{Phags_Pa}\p{Phoenician}/8
+    \x{1b00}\x{12000}\x{7c0}\x{a840}\x{10900}
+ 0: \x{1b00}\x{12000}\x{7c0}\x{a840}\x{10900}
+
 / End of testinput6 /
index 53d4e5a301287de585527db70ca031998c479513..5bddc1e1535fdf757156938cdc77263093ae80b9 100644 (file)
@@ -2735,8 +2735,7 @@ No match
 No match
 
 /^a    b
-  
-  \f  c/x
+    \f  c/x
     abc
  0: abc
 
@@ -2974,7 +2973,7 @@ No match
     {4,5a}bc
  0: {4,5a}bc
 
-/^a.b/
+/^a.b/<lf>
     a\rb
  0: a\x0db
     *** Failers
@@ -3040,9 +3039,9 @@ No match
     abcdefghijk\12S
  0: abcdefghijk\x0aS
 
-/ab\gdef/
-    abgdef
- 0: abgdef
+/ab\hdef/
+    abhdef
+ 0: abhdef
 
 /a{0}bc/
     bc
@@ -6601,7 +6600,7 @@ No match
     xyz\rabc\<lf>
 No match
     
-/abc$/m
+/abc$/m<lf>
     xyzabc
  0: abc
     xyzabc\n 
@@ -6657,7 +6656,7 @@ No match
     xyz\rabcdef
 No match
     
-/.*/
+/.*/<lf>
     abc\ndef
  0: abc
  1: ab
@@ -6729,4 +6728,228 @@ No match
     abc\r\ndef
  0: abc\x0d\x0adef
 
+/^\w+=.*(\\\n.*)*/
+    abc=xyz\\\npqr
+ 0: abc=xyz\\x0apqr
+ 1: abc=xyz\\x0apq
+ 2: abc=xyz\\x0ap
+ 3: abc=xyz\\x0a
+ 4: abc=xyz\
+ 5: abc=xyz
+ 6: abc=xy
+ 7: abc=x
+ 8: abc=
+
+/^(a()*)*/
+    aaaa
+ 0: aaaa
+ 1: aaa
+ 2: aa
+ 3: a
+ 4: 
+
+/^(?:a(?:(?:))*)*/
+    aaaa
+ 0: aaaa
+ 1: aaa
+ 2: aa
+ 3: a
+ 4: 
+
+/^(a()+)+/
+    aaaa
+ 0: aaaa
+ 1: aaa
+ 2: aa
+ 3: a
+
+/^(?:a(?:(?:))+)+/
+    aaaa
+ 0: aaaa
+ 1: aaa
+ 2: aa
+ 3: a
+
+/(a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+No match
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+ 0: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/(?>a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+No match
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+ 0: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/(?:a|)*\d/
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+No match
+  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+ 0: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4
+
+/^a.b/<lf>
+    a\rb
+ 0: a\x0db
+    a\nb\<cr> 
+ 0: a\x0ab
+    ** Failers
+No match
+    a\nb
+No match
+    a\nb\<any>
+No match
+    a\rb\<cr>   
+No match
+    a\rb\<any>   
+No match
+
+/^abc./mgx<any>
+    abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x85abc7 \x{2028}abc8 \x{2029}abc9 JUNK
+ 0: abc1
+ 0: abc2
+ 0: abc3
+ 0: abc4
+ 0: abc5
+ 0: abc6
+ 0: abc7
+
+/abc.$/mgx<any>
+    abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x85 abc7\x{2028} abc8\x{2029} abc9
+ 0: abc1
+ 0: abc2
+ 0: abc3
+ 0: abc4
+ 0: abc5
+ 0: abc6
+ 0: abc9
+
+/^a\Rb/
+    a\nb
+ 0: a\x0ab
+    a\rb
+ 0: a\x0db
+    a\r\nb
+ 0: a\x0d\x0ab
+    a\x0bb
+ 0: a\x0bb
+    a\x0cb
+ 0: a\x0cb
+    a\x85b   
+ 0: a\x85b
+    ** Failers
+No match
+    a\n\rb    
+No match
+
+/^a\R*b/
+    ab
+ 0: ab
+    a\nb
+ 0: a\x0ab
+    a\rb
+ 0: a\x0db
+    a\r\nb
+ 0: a\x0d\x0ab
+    a\x0bb
+ 0: a\x0bb
+    a\x0cb
+ 0: a\x0cb
+    a\x85b   
+ 0: a\x85b
+    a\n\rb    
+ 0: a\x0a\x0db
+    a\n\r\x85\x0cb 
+ 0: a\x0a\x0d\x85\x0cb
+
+/^a\R+b/
+    a\nb
+ 0: a\x0ab
+    a\rb
+ 0: a\x0db
+    a\r\nb
+ 0: a\x0d\x0ab
+    a\x0bb
+ 0: a\x0bb
+    a\x0cb
+ 0: a\x0cb
+    a\x85b   
+ 0: a\x85b
+    a\n\rb    
+ 0: a\x0a\x0db
+    a\n\r\x85\x0cb 
+ 0: a\x0a\x0d\x85\x0cb
+    ** Failers
+No match
+    ab  
+No match
+    
+/^a\R{1,3}b/
+    a\nb
+ 0: a\x0ab
+    a\n\rb
+ 0: a\x0a\x0db
+    a\n\r\x85b
+ 0: a\x0a\x0d\x85b
+    a\r\n\r\nb 
+ 0: a\x0d\x0a\x0d\x0ab
+    a\r\n\r\n\r\nb 
+ 0: a\x0d\x0a\x0d\x0a\x0d\x0ab
+    a\n\r\n\rb
+ 0: a\x0a\x0d\x0a\x0db
+    a\n\n\r\nb 
+ 0: a\x0a\x0a\x0d\x0ab
+    ** Failers
+No match
+    a\n\n\n\rb
+No match
+    a\r
+No match
+
+/^a[\R]b/
+    aRb
+ 0: aRb
+    ** Failers
+No match
+    a\nb  
+No match
+
+/.+foo/
+    afoo
+ 0: afoo
+    ** Failers 
+No match
+    \r\nfoo 
+No match
+    \nfoo 
+No match
+
+/.+foo/<crlf>
+    afoo
+ 0: afoo
+    \nfoo 
+ 0: \x0afoo
+    ** Failers 
+No match
+    \r\nfoo 
+No match
+
+/.+foo/<any>
+    afoo
+ 0: afoo
+    ** Failers 
+No match
+    \nfoo 
+No match
+    \r\nfoo 
+No match
+
+/.+foo/s
+    afoo
+ 0: afoo
+    \r\nfoo 
+ 0: \x0d\x0afoo
+    \nfoo 
+ 0: \x0afoo
+
 / End of testinput7 /
index 72e7673f560c1498494741a6c82d917910cb3d05..f8251ff5eaa1a62236930b9960e810454a91ffa5 100644 (file)
@@ -1028,4 +1028,114 @@ No match
     \x{85}
  0: \x{85}
 
+/^abc./mgx8<any>
+    abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x{0085}abc7 \x{2028}abc8 \x{2029}abc9 JUNK
+ 0: abc1
+ 0: abc2
+ 0: abc3
+ 0: abc4
+ 0: abc5
+ 0: abc6
+ 0: abc7
+ 0: abc8
+ 0: abc9
+
+/abc.$/mgx8<any>
+    abc1\x0a abc2\x0b abc3\x0c abc4\x0d abc5\x0d\x0a abc6\x{0085} abc7\x{2028} abc8\x{2029} abc9
+ 0: abc1
+ 0: abc2
+ 0: abc3
+ 0: abc4
+ 0: abc5
+ 0: abc6
+ 0: abc7
+ 0: abc8
+ 0: abc9
+
+/^a\Rb/8
+    a\nb
+ 0: a\x{0a}b
+    a\rb
+ 0: a\x{0d}b
+    a\r\nb
+ 0: a\x{0d}\x{0a}b
+    a\x0bb
+ 0: a\x{0b}b
+    a\x0cb
+ 0: a\x{0c}b
+    a\x{85}b   
+ 0: a\x{85}b
+    a\x{2028}b 
+ 0: a\x{2028}b
+    a\x{2029}b 
+ 0: a\x{2029}b
+    ** Failers
+No match
+    a\n\rb    
+No match
+
+/^a\R*b/8
+    ab
+ 0: ab
+    a\nb
+ 0: a\x{0a}b
+    a\rb
+ 0: a\x{0d}b
+    a\r\nb
+ 0: a\x{0d}\x{0a}b
+    a\x0bb
+ 0: a\x{0b}b
+    a\x0c\x{2028}\x{2029}b
+ 0: a\x{0c}\x{2028}\x{2029}b
+    a\x{85}b   
+ 0: a\x{85}b
+    a\n\rb    
+ 0: a\x{0a}\x{0d}b
+    a\n\r\x{85}\x0cb 
+ 0: a\x{0a}\x{0d}\x{85}\x{0c}b
+
+/^a\R+b/8
+    a\nb
+ 0: a\x{0a}b
+    a\rb
+ 0: a\x{0d}b
+    a\r\nb
+ 0: a\x{0d}\x{0a}b
+    a\x0bb
+ 0: a\x{0b}b
+    a\x0c\x{2028}\x{2029}b
+ 0: a\x{0c}\x{2028}\x{2029}b
+    a\x{85}b   
+ 0: a\x{85}b
+    a\n\rb    
+ 0: a\x{0a}\x{0d}b
+    a\n\r\x{85}\x0cb 
+ 0: a\x{0a}\x{0d}\x{85}\x{0c}b
+    ** Failers
+No match
+    ab  
+No match
+
+/^a\R{1,3}b/8
+    a\nb
+ 0: a\x{0a}b
+    a\n\rb
+ 0: a\x{0a}\x{0d}b
+    a\n\r\x{85}b
+ 0: a\x{0a}\x{0d}\x{85}b
+    a\r\n\r\nb 
+ 0: a\x{0d}\x{0a}\x{0d}\x{0a}b
+    a\r\n\r\n\r\nb 
+ 0: a\x{0d}\x{0a}\x{0d}\x{0a}\x{0d}\x{0a}b
+    a\n\r\n\rb
+ 0: a\x{0a}\x{0d}\x{0a}\x{0d}b
+    a\n\n\r\nb 
+ 0: a\x{0a}\x{0a}\x{0d}\x{0a}b
+    ** Failers
+No match
+    a\n\n\n\rb
+No match
+    a\r
+No match
+
 / End of testinput 8 / 
index 1ca23c9c10c5cae1add94412be94852ea0101999..3a4179b7693176dd43a45c02fd45f35bbc6ebae9 100644 (file)
@@ -6,7 +6,9 @@
 #define _UCP_H
 
 /* This file contains definitions of the property values that are returned by
-the function _pcre_ucp_findprop(). */
+the function _pcre_ucp_findprop(). New values that are added for new releases
+of Unicode should always be at the end of each enum, for backwards
+compatibility. */
 
 /* These are the general character categories. */
 
@@ -118,7 +120,12 @@ enum {
   ucp_Tibetan,
   ucp_Tifinagh,
   ucp_Ugaritic,
-  ucp_Yi
+  ucp_Yi,
+  ucp_Balinese,      /* New for Unicode 5.0.0 */
+  ucp_Cuneiform,     /* New for Unicode 5.0.0 */
+  ucp_Nko,           /* New for Unicode 5.0.0 */
+  ucp_Phags_Pa,      /* New for Unicode 5.0.0 */
+  ucp_Phoenician     /* New for Unicode 5.0.0 */
 };
 
 #endif
index 16dfbe9b0f7eeaeb1fdc88a3e4a567845e15b07f..811a373c8871e28e5ef9ebb4616a8fc9ae84e618 100644 (file)
@@ -2,6 +2,9 @@
 *           Unicode Property Table handler       *
 *************************************************/
 
+#ifndef _UCPINTERNAL_H
+#define _UCPINTERNAL_H
+
 /* Internal header file defining the layout of the bits in each pair of 32-bit
 words that form a data item in the table. */
 
@@ -84,4 +87,6 @@ When searching the data, proceed as follows:
     (2).
 */
 
+#endif /* _UCPINTERNAL_H */
+
 /* End of ucpinternal.h */
index ae665b37607936ca969246be62230ae392050b73..0b17906b128fbd8de9a87e6cda670942e579ffc3 100644 (file)
@@ -1,5 +1,6 @@
 /* This source module is automatically generated from the Unicode
-property table. See ucpinternal.h for a description of the layout. */
+property table. See ucpinternal.h for a description of the layout.
+This version was made from the Unicode 5.0.0 tables. */
 
 static cnode ucp_table[] = {
   { 0x09800000, 0x0000001f },
@@ -298,7 +299,7 @@ static cnode ucp_table[] = {
   { 0x2100017d, 0x24000001 },
   { 0x2100017e, 0x1400ffff },
   { 0x2100017f, 0x1400fed4 },
-  { 0x21000180, 0x14000000 },
+  { 0x21000180, 0x140000c3 },
   { 0x21000181, 0x240000d2 },
   { 0x21000182, 0x24000001 },
   { 0x21000183, 0x1400ffff },
@@ -475,13 +476,27 @@ static cnode ucp_table[] = {
   { 0x21000232, 0x24000001 },
   { 0x21000233, 0x1400ffff },
   { 0x21800234, 0x14000005 },
-  { 0x2100023a, 0x24000000 },
+  { 0x2100023a, 0x24002a2b },
   { 0x2100023b, 0x24000001 },
   { 0x2100023c, 0x1400ffff },
   { 0x2100023d, 0x2400ff5d },
-  { 0x2100023e, 0x24000000 },
+  { 0x2100023e, 0x24002a28 },
   { 0x2180023f, 0x14000001 },
-  { 0x21000241, 0x24000053 },
+  { 0x21000241, 0x24000001 },
+  { 0x21000242, 0x1400ffff },
+  { 0x21000243, 0x2400ff3d },
+  { 0x21000244, 0x24000045 },
+  { 0x21000245, 0x24000047 },
+  { 0x21000246, 0x24000001 },
+  { 0x21000247, 0x1400ffff },
+  { 0x21000248, 0x24000001 },
+  { 0x21000249, 0x1400ffff },
+  { 0x2100024a, 0x24000001 },
+  { 0x2100024b, 0x1400ffff },
+  { 0x2100024c, 0x24000001 },
+  { 0x2100024d, 0x1400ffff },
+  { 0x2100024e, 0x24000001 },
+  { 0x2100024f, 0x1400ffff },
   { 0x21800250, 0x14000002 },
   { 0x21000253, 0x1400ff2e },
   { 0x21000254, 0x1400ff32 },
@@ -499,25 +514,30 @@ static cnode ucp_table[] = {
   { 0x21800264, 0x14000003 },
   { 0x21000268, 0x1400ff2f },
   { 0x21000269, 0x1400ff2d },
-  { 0x2180026a, 0x14000004 },
+  { 0x2100026a, 0x14000000 },
+  { 0x2100026b, 0x140029f7 },
+  { 0x2180026c, 0x14000002 },
   { 0x2100026f, 0x1400ff2d },
   { 0x21800270, 0x14000001 },
   { 0x21000272, 0x1400ff2b },
   { 0x21800273, 0x14000001 },
   { 0x21000275, 0x1400ff2a },
-  { 0x21800276, 0x14000009 },
+  { 0x21800276, 0x14000006 },
+  { 0x2100027d, 0x140029e7 },
+  { 0x2180027e, 0x14000001 },
   { 0x21000280, 0x1400ff26 },
   { 0x21800281, 0x14000001 },
   { 0x21000283, 0x1400ff26 },
   { 0x21800284, 0x14000003 },
   { 0x21000288, 0x1400ff26 },
-  { 0x21000289, 0x14000000 },
+  { 0x21000289, 0x1400ffbb },
   { 0x2100028a, 0x1400ff27 },
   { 0x2100028b, 0x1400ff27 },
-  { 0x2180028c, 0x14000005 },
+  { 0x2100028c, 0x1400ffb9 },
+  { 0x2180028d, 0x14000004 },
   { 0x21000292, 0x1400ff25 },
   { 0x21000293, 0x14000000 },
-  { 0x21000294, 0x1400ffad },
+  { 0x21000294, 0x1c000000 },
   { 0x21800295, 0x1400001a },
   { 0x218002b0, 0x18000011 },
   { 0x098002c2, 0x60000003 },
@@ -532,6 +552,9 @@ static cnode ucp_table[] = {
   { 0x1b800346, 0x30000029 },
   { 0x13800374, 0x60000001 },
   { 0x1300037a, 0x18000000 },
+  { 0x1300037b, 0x14000082 },
+  { 0x1300037c, 0x14000082 },
+  { 0x1300037d, 0x14000082 },
   { 0x0900037e, 0x54000000 },
   { 0x13800384, 0x60000001 },
   { 0x13000386, 0x24000026 },
@@ -647,7 +670,9 @@ static cnode ucp_table[] = {
   { 0x130003fa, 0x24000001 },
   { 0x130003fb, 0x1400ffff },
   { 0x130003fc, 0x14000000 },
-  { 0x138003fd, 0x24000002 },
+  { 0x130003fd, 0x2400ff7e },
+  { 0x130003fe, 0x2400ff7e },
+  { 0x130003ff, 0x2400ff7e },
   { 0x0c000400, 0x24000050 },
   { 0x0c000401, 0x24000050 },
   { 0x0c000402, 0x24000050 },
@@ -835,7 +860,7 @@ static cnode ucp_table[] = {
   { 0x0c0004bd, 0x1400ffff },
   { 0x0c0004be, 0x24000001 },
   { 0x0c0004bf, 0x1400ffff },
-  { 0x0c0004c0, 0x24000000 },
+  { 0x0c0004c0, 0x2400000f },
   { 0x0c0004c1, 0x24000001 },
   { 0x0c0004c2, 0x1400ffff },
   { 0x0c0004c3, 0x24000001 },
@@ -850,6 +875,7 @@ static cnode ucp_table[] = {
   { 0x0c0004cc, 0x1400ffff },
   { 0x0c0004cd, 0x24000001 },
   { 0x0c0004ce, 0x1400ffff },
+  { 0x0c0004cf, 0x1400fff1 },
   { 0x0c0004d0, 0x24000001 },
   { 0x0c0004d1, 0x1400ffff },
   { 0x0c0004d2, 0x24000001 },
@@ -892,6 +918,12 @@ static cnode ucp_table[] = {
   { 0x0c0004f7, 0x1400ffff },
   { 0x0c0004f8, 0x24000001 },
   { 0x0c0004f9, 0x1400ffff },
+  { 0x0c0004fa, 0x24000001 },
+  { 0x0c0004fb, 0x1400ffff },
+  { 0x0c0004fc, 0x24000001 },
+  { 0x0c0004fd, 0x1400ffff },
+  { 0x0c0004fe, 0x24000001 },
+  { 0x0c0004ff, 0x1400ffff },
   { 0x0c000500, 0x24000001 },
   { 0x0c000501, 0x1400ffff },
   { 0x0c000502, 0x24000001 },
@@ -908,6 +940,10 @@ static cnode ucp_table[] = {
   { 0x0c00050d, 0x1400ffff },
   { 0x0c00050e, 0x24000001 },
   { 0x0c00050f, 0x1400ffff },
+  { 0x0c000510, 0x24000001 },
+  { 0x0c000511, 0x1400ffff },
+  { 0x0c000512, 0x24000001 },
+  { 0x0c000513, 0x1400ffff },
   { 0x01000531, 0x24000030 },
   { 0x01000532, 0x24000030 },
   { 0x01000533, 0x24000030 },
@@ -989,8 +1025,7 @@ static cnode ucp_table[] = {
   { 0x01000587, 0x14000000 },
   { 0x09000589, 0x54000000 },
   { 0x0100058a, 0x44000000 },
-  { 0x19800591, 0x30000028 },
-  { 0x198005bb, 0x30000002 },
+  { 0x19800591, 0x3000002c },
   { 0x190005be, 0x54000000 },
   { 0x190005bf, 0x30000000 },
   { 0x190005c0, 0x54000000 },
@@ -1043,6 +1078,13 @@ static cnode ucp_table[] = {
   { 0x37800780, 0x1c000025 },
   { 0x378007a6, 0x3000000a },
   { 0x370007b1, 0x1c000000 },
+  { 0x3f8007c0, 0x34000009 },
+  { 0x3f8007ca, 0x1c000020 },
+  { 0x3f8007eb, 0x30000008 },
+  { 0x3f8007f4, 0x18000001 },
+  { 0x3f0007f6, 0x68000000 },
+  { 0x3f8007f7, 0x54000002 },
+  { 0x3f0007fa, 0x18000000 },
   { 0x0e800901, 0x30000001 },
   { 0x0e000903, 0x28000000 },
   { 0x0e800904, 0x1c000035 },
@@ -1059,7 +1101,7 @@ static cnode ucp_table[] = {
   { 0x09800964, 0x54000001 },
   { 0x0e800966, 0x34000009 },
   { 0x09000970, 0x54000000 },
-  { 0x0e00097d, 0x1c000000 },
+  { 0x0e80097b, 0x1c000004 },
   { 0x02000981, 0x30000000 },
   { 0x02800982, 0x28000001 },
   { 0x02800985, 0x1c000007 },
@@ -1203,7 +1245,9 @@ static cnode ucp_table[] = {
   { 0x1c800cd5, 0x28000001 },
   { 0x1c000cde, 0x1c000000 },
   { 0x1c800ce0, 0x1c000001 },
+  { 0x1c800ce2, 0x30000001 },
   { 0x1c800ce6, 0x34000009 },
+  { 0x1c800cf1, 0x68000001 },
   { 0x24800d02, 0x28000001 },
   { 0x24800d05, 0x1c000007 },
   { 0x24800d0e, 0x1c000002 },
@@ -1452,13 +1496,33 @@ static cnode ucp_table[] = {
   { 0x05801a17, 0x30000001 },
   { 0x05801a19, 0x28000002 },
   { 0x05801a1e, 0x54000001 },
+  { 0x3d801b00, 0x30000003 },
+  { 0x3d001b04, 0x28000000 },
+  { 0x3d801b05, 0x1c00002e },
+  { 0x3d001b34, 0x30000000 },
+  { 0x3d001b35, 0x28000000 },
+  { 0x3d801b36, 0x30000004 },
+  { 0x3d001b3b, 0x28000000 },
+  { 0x3d001b3c, 0x30000000 },
+  { 0x3d801b3d, 0x28000004 },
+  { 0x3d001b42, 0x30000000 },
+  { 0x3d801b43, 0x28000001 },
+  { 0x3d801b45, 0x1c000006 },
+  { 0x3d801b50, 0x34000009 },
+  { 0x3d801b5a, 0x54000006 },
+  { 0x3d801b61, 0x68000009 },
+  { 0x3d801b6b, 0x30000008 },
+  { 0x3d801b74, 0x68000008 },
   { 0x21801d00, 0x1400002b },
   { 0x21801d2c, 0x18000035 },
   { 0x21801d62, 0x14000015 },
   { 0x0c001d78, 0x18000000 },
-  { 0x21801d79, 0x14000021 },
+  { 0x21801d79, 0x14000003 },
+  { 0x21001d7d, 0x14000ee6 },
+  { 0x21801d7e, 0x1400001c },
   { 0x21801d9b, 0x18000024 },
-  { 0x1b801dc0, 0x30000003 },
+  { 0x1b801dc0, 0x3000000a },
+  { 0x1b801dfe, 0x30000001 },
   { 0x21001e00, 0x24000001 },
   { 0x21001e01, 0x1400ffff },
   { 0x21001e02, 0x24000001 },
@@ -1967,7 +2031,7 @@ static cnode ucp_table[] = {
   { 0x1b8020dd, 0x2c000003 },
   { 0x1b0020e1, 0x30000000 },
   { 0x1b8020e2, 0x2c000002 },
-  { 0x1b8020e5, 0x30000006 },
+  { 0x1b8020e5, 0x3000000a },
   { 0x09802100, 0x68000001 },
   { 0x09002102, 0x24000000 },
   { 0x09802103, 0x68000003 },
@@ -1995,7 +2059,7 @@ static cnode ucp_table[] = {
   { 0x0900212e, 0x68000000 },
   { 0x0900212f, 0x14000000 },
   { 0x09802130, 0x24000001 },
-  { 0x09002132, 0x68000000 },
+  { 0x21002132, 0x2400001c },
   { 0x09002133, 0x24000000 },
   { 0x09002134, 0x14000000 },
   { 0x09802135, 0x1c000003 },
@@ -2008,7 +2072,8 @@ static cnode ucp_table[] = {
   { 0x09802146, 0x14000003 },
   { 0x0900214a, 0x68000000 },
   { 0x0900214b, 0x64000000 },
-  { 0x0900214c, 0x68000000 },
+  { 0x0980214c, 0x68000001 },
+  { 0x2100214e, 0x1400ffe4 },
   { 0x09802153, 0x3c00000c },
   { 0x09002160, 0x38000010 },
   { 0x09002161, 0x38000010 },
@@ -2042,7 +2107,9 @@ static cnode ucp_table[] = {
   { 0x0900217d, 0x3800fff0 },
   { 0x0900217e, 0x3800fff0 },
   { 0x0900217f, 0x3800fff0 },
-  { 0x09802180, 0x38000003 },
+  { 0x09802180, 0x38000002 },
+  { 0x09002183, 0x24000001 },
+  { 0x21002184, 0x1400ffff },
   { 0x09802190, 0x64000004 },
   { 0x09802195, 0x68000004 },
   { 0x0980219a, 0x64000001 },
@@ -2073,10 +2140,9 @@ static cnode ucp_table[] = {
   { 0x0900237c, 0x64000000 },
   { 0x0980237d, 0x6800001d },
   { 0x0980239b, 0x64000018 },
-  { 0x090023b4, 0x58000000 },
-  { 0x090023b5, 0x48000000 },
-  { 0x090023b6, 0x54000000 },
-  { 0x098023b7, 0x68000024 },
+  { 0x098023b4, 0x68000027 },
+  { 0x098023dc, 0x64000005 },
+  { 0x098023e2, 0x68000005 },
   { 0x09802400, 0x68000026 },
   { 0x09802440, 0x6800000a },
   { 0x09802460, 0x3c00003b },
@@ -2143,7 +2209,7 @@ static cnode ucp_table[] = {
   { 0x09802600, 0x6800006e },
   { 0x0900266f, 0x64000000 },
   { 0x09802670, 0x6800002c },
-  { 0x098026a0, 0x68000011 },
+  { 0x098026a0, 0x68000012 },
   { 0x09802701, 0x68000003 },
   { 0x09802706, 0x68000003 },
   { 0x0980270c, 0x6800001b },
@@ -2174,6 +2240,7 @@ static cnode ucp_table[] = {
   { 0x098027c0, 0x64000004 },
   { 0x090027c5, 0x58000000 },
   { 0x090027c6, 0x48000000 },
+  { 0x098027c7, 0x64000003 },
   { 0x098027d0, 0x64000015 },
   { 0x090027e6, 0x58000000 },
   { 0x090027e7, 0x48000000 },
@@ -2215,7 +2282,8 @@ static cnode ucp_table[] = {
   { 0x090029fc, 0x58000000 },
   { 0x090029fd, 0x48000000 },
   { 0x098029fe, 0x64000101 },
-  { 0x09802b00, 0x68000013 },
+  { 0x09802b00, 0x6800001a },
+  { 0x09802b20, 0x68000003 },
   { 0x11002c00, 0x24000030 },
   { 0x11002c01, 0x24000030 },
   { 0x11002c02, 0x24000030 },
@@ -2310,6 +2378,23 @@ static cnode ucp_table[] = {
   { 0x11002c5c, 0x1400ffd0 },
   { 0x11002c5d, 0x1400ffd0 },
   { 0x11002c5e, 0x1400ffd0 },
+  { 0x21002c60, 0x24000001 },
+  { 0x21002c61, 0x1400ffff },
+  { 0x21002c62, 0x2400d609 },
+  { 0x21002c63, 0x2400f11a },
+  { 0x21002c64, 0x2400d619 },
+  { 0x21002c65, 0x1400d5d5 },
+  { 0x21002c66, 0x1400d5d8 },
+  { 0x21002c67, 0x24000001 },
+  { 0x21002c68, 0x1400ffff },
+  { 0x21002c69, 0x24000001 },
+  { 0x21002c6a, 0x1400ffff },
+  { 0x21002c6b, 0x24000001 },
+  { 0x21002c6c, 0x1400ffff },
+  { 0x21002c74, 0x14000000 },
+  { 0x21002c75, 0x24000001 },
+  { 0x21002c76, 0x1400ffff },
+  { 0x21002c77, 0x14000000 },
   { 0x0a002c80, 0x24000001 },
   { 0x0a002c81, 0x1400ffff },
   { 0x0a002c82, 0x24000001 },
@@ -2559,6 +2644,8 @@ static cnode ucp_table[] = {
   { 0x3c80a016, 0x1c000476 },
   { 0x3c80a490, 0x68000036 },
   { 0x0980a700, 0x60000016 },
+  { 0x0980a717, 0x18000003 },
+  { 0x0980a720, 0x60000001 },
   { 0x3080a800, 0x1c000001 },
   { 0x3000a802, 0x28000000 },
   { 0x3080a803, 0x1c000002 },
@@ -2570,6 +2657,8 @@ static cnode ucp_table[] = {
   { 0x3080a825, 0x30000001 },
   { 0x3000a827, 0x28000000 },
   { 0x3080a828, 0x68000003 },
+  { 0x4080a840, 0x1c000033 },
+  { 0x4080a874, 0x54000003 },
   { 0x1780ac00, 0x1c002ba3 },
   { 0x0980d800, 0x1000037f },
   { 0x0980db80, 0x1000007f },
@@ -2765,13 +2854,15 @@ static cnode ucp_table[] = {
   { 0x1301018a, 0x3c000000 },
   { 0x29810300, 0x1c00001e },
   { 0x29810320, 0x3c000003 },
-  { 0x12810330, 0x1c000019 },
+  { 0x12810330, 0x1c000010 },
+  { 0x12010341, 0x38000000 },
+  { 0x12810342, 0x1c000007 },
   { 0x1201034a, 0x38000000 },
   { 0x3b810380, 0x1c00001d },
   { 0x3b01039f, 0x54000000 },
   { 0x2a8103a0, 0x1c000023 },
   { 0x2a8103c8, 0x1c000007 },
-  { 0x2a0103d0, 0x68000000 },
+  { 0x2a0103d0, 0x54000000 },
   { 0x2a8103d1, 0x38000004 },
   { 0x0d010400, 0x24000028 },
   { 0x0d010401, 0x24000028 },
@@ -2861,6 +2952,9 @@ static cnode ucp_table[] = {
   { 0x0b810837, 0x1c000001 },
   { 0x0b01083c, 0x1c000000 },
   { 0x0b01083f, 0x1c000000 },
+  { 0x41810900, 0x1c000015 },
+  { 0x41810916, 0x3c000003 },
+  { 0x4101091f, 0x54000000 },
   { 0x1e010a00, 0x1c000000 },
   { 0x1e810a01, 0x30000002 },
   { 0x1e810a05, 0x30000001 },
@@ -2872,6 +2966,9 @@ static cnode ucp_table[] = {
   { 0x1e010a3f, 0x30000000 },
   { 0x1e810a40, 0x3c000007 },
   { 0x1e810a50, 0x54000008 },
+  { 0x3e812000, 0x1c00036e },
+  { 0x3e812400, 0x38000062 },
+  { 0x3e812470, 0x54000003 },
   { 0x0981d000, 0x680000f5 },
   { 0x0981d100, 0x68000026 },
   { 0x0981d12a, 0x6800003a },
@@ -2890,6 +2987,7 @@ static cnode ucp_table[] = {
   { 0x1381d242, 0x30000002 },
   { 0x1301d245, 0x68000000 },
   { 0x0981d300, 0x68000056 },
+  { 0x0981d360, 0x3c000011 },
   { 0x0981d400, 0x24000019 },
   { 0x0981d41a, 0x14000019 },
   { 0x0981d434, 0x24000019 },
@@ -2957,6 +3055,8 @@ static cnode ucp_table[] = {
   { 0x0981d7aa, 0x14000018 },
   { 0x0901d7c3, 0x64000000 },
   { 0x0981d7c4, 0x14000005 },
+  { 0x0901d7ca, 0x24000000 },
+  { 0x0901d7cb, 0x14000000 },
   { 0x0981d7ce, 0x34000031 },
   { 0x16820000, 0x1c00a6d6 },
   { 0x1682f800, 0x1c00021d },