Bug #79670 [Com]: Regex with non-greedy dot-all does not match "$" correctly

From: Date: Wed, 03 Jun 2020 12:37:06 +0000
Subject: Bug #79670 [Com]: Regex with non-greedy dot-all does not match "$" correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227295@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 Comment by: not-implemented at mark-plomer dot de Reported by: not-implemented at mark-plomer dot de Summary: Regex with non-greedy dot-all does not match "$" correctly Status: Not a bug Type: Bug Package: PCRE related Operating System: any PHP Version: 7.3.18 Assigned To: cmb Block user comment: N Private report: N New Comment: Oh wow ... even after coding PHP for so many years, there is always something new to learn :D Thanks for reading the docs for me ;-) Previous Comments: ------------------------------------------------------------------------ [2020-06-03 12:05:15] cmb@php.net 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> ------------------------------------------------------------------------ [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

« previous php.bugs (#227295) next »