#42411 [Opn->Bgs]: ".*" pattern triggers doubled output

From: Date: Fri, 24 Aug 2007 12:04:34 +0000
Subject: #42411 [Opn->Bgs]: ".*" pattern triggers doubled output
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-116617@lists.php.net to get a copy of this message
ID: 42411 Updated by: jani@php.net Reported By: axelm-php at nona dot net -Status: Open +Status: Bogus Bug Type: Regexps related Operating System: Debian/GNU Linux PHP Version: 5.2.3 New Comment: Expected behaviour. And you should really use PCRE functions instead. Previous Comments: ------------------------------------------------------------------------ [2007-08-24 11:54:23] axelm-php at nona dot net Description: ------------ The function ereg_replace() "duplicates" the replacement string when the match string is ".*". Example: - input "BLABLA" - match ".*" - replace "TEST" Output is "TESTTEST", although it would be expected to be "TEST". Reproduce code: --------------- <? $source = "BLABLA"; $match = ".*"; $replace = "TEST"; print ereg_replace($match, $replace, $source); print "\n"; ?> Expected result: ---------------- only a single "TEST" (as this is the case with sed, too), because i expect ".*" to have maximum greediness. Actual result: -------------- see example code. produces "TESTTEST". This happens in all PHP versions i have access to (older PHP4, current PHP4 and PHP5). Using "^.*" as match, or ".+" works as expected. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42411&edit=1

« previous php.bugs (#116617) next »