This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Quantifier follows nothing in regex
authorKarl Williamson <public@khwilliamson.com>
Tue, 11 Jun 2013 02:07:14 +0000 (20:07 -0600)
committerKarl Williamson <public@khwilliamson.com>
Tue, 11 Jun 2013 02:24:25 +0000 (20:24 -0600)
This changes the code so that any '?' immediately (subject to /x rules)
following a {0} quantifier is absorbed immediately as part of that
quantifier.  This allows the optimization to NOTHING to work for
non-greedy matches.

Thanks to Yves Orton for doing most of the leg work on this

regcomp.c
t/re/re_tests

index a9eebd7..a837306 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -9699,6 +9699,12 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
                     RExC_emit = orig_emit;
                 }
                 ret = reg_node(pRExC_state, NOTHING);
                     RExC_emit = orig_emit;
                 }
                 ret = reg_node(pRExC_state, NOTHING);
+
+                /* But the quantifier includes any '?' (the non-greedy
+                 * modifier) after the {}, [perl #118375] */
+                if (RExC_parse < RExC_end && *RExC_parse == '?') {
+                    nextchar(pRExC_state);
+                }
                 return ret;
             }
 
                 return ret;
             }
 
index a317904..ae28e14 100644 (file)
@@ -1740,4 +1740,8 @@ m?^xy\?$? xy?     y       $&      xy?
 # patterns
 ^(\x{100}|a)(??{ qr/.?\xF7/d}) a_\xF7  y       -       -
 
 # patterns
 ^(\x{100}|a)(??{ qr/.?\xF7/d}) a_\xF7  y       -       -
 
+# [perl #118375]
+/(a|(bc)){0,0}?xyz/    xyz     y       $&      xyz
+/( a | ( bc ) ) {0,0} ? xyz/x  xyz     y       $&      xyz
+
 # vim: softtabstop=0 noexpandtab
 # vim: softtabstop=0 noexpandtab