summaryrefslogtreecommitdiff
path: root/regexec.c
diff options
context:
space:
mode:
Diffstat (limited to 'regexec.c')
-rw-r--r--regexec.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/regexec.c b/regexec.c
index e63fa6f070..f9f2cc0535 100644
--- a/regexec.c
+++ b/regexec.c
@@ -3045,8 +3045,14 @@ S_regmatch(pTHX_ regnode *prog)
n = regrepeat(scan, n);
locinput = PL_reginput;
if (ln < n && PL_regkind[(U8)OP(next)] == EOL &&
- (!PL_multiline || OP(next) == SEOL))
+ (!PL_multiline || OP(next) == SEOL || OP(next) == EOS)) {
ln = n; /* why back off? */
+ /* ...because $ and \Z can match before *and* after
+ newline at the end. Consider "\n\n" =~ /\n+\Z\n/.
+ We should back off by one in this case. */
+ if (UCHARAT(PL_reginput - 1) == '\n' && OP(next) != EOS)
+ ln--;
+ }
REGCP_SET;
if (paren) {
while (n >= ln) {