Bug #79670 [Opn->Nab]: Regex with non-greedy dot-all does not match "$" correctly
| From: | cmb@php.net | Date: | Wed, 03 Jun 2020 12:05:15 +0000 |
| Subject: | Bug #79670 [Opn->Nab]: Regex with non-greedy dot-all does not match "$" correctly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227293@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79670&edit=1
ID: 79670
Updated by: cmb@php.net
Reported by: not-implemented at mark-plomer dot de
Summary: Regex with non-greedy dot-all does not match "$"
correctly
-Status: Open
+Status: Not a bug
Type: Bug
Package: PCRE related
Operating System: any
PHP Version: 7.3.18
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
From the PHP manual[1]:
| [â¦] while the "end of line" metacharacter ($) matches only at
| the end of the string, or before a terminating newline (unless D
| modifier is set).
So you may want to use the D modifier: <https://3v4l.org/ea3SQ>.
[1] <https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php>
Previous Comments:
------------------------------------------------------------------------
[2020-06-03 11:51:06] not-implemented at mark-plomer dot de
Description:
------------
The following regex with non-greedy dot-all selector does not consume the last newline from input.
Note that the PCRE-Modifier "m" is NOT used, so "$" should match the
end-of-string only.
Test script:
---------------
$x = preg_replace('/A.*?$/s', 'X', "A\n");
echo json_encode($x);
Expected result:
----------------
"X"
Actual result:
--------------
"X\n"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79670&edit=1