Bug #53855 [Opn->Bgs]: preg_replace doing double replacement

From: Date: Thu, 27 Jan 2011 14:07:20 +0000
Subject: Bug #53855 [Opn->Bgs]: preg_replace doing double replacement
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-158237@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53855&edit=1 ID: 53855 Updated by: salathe@php.net Reported by: richard at roguewavelimited dot com Summary: preg_replace doing double replacement -Status: Open +Status: Bogus Type: Bug Package: Regexps related Operating System: Mac OSX 10.6.6 PHP Version: 5.3.3 Block user comment: N Private report: N New Comment: This is expected behaviour and nothing peculiar to PHP. The * quantifier allows an "empty" match to occur at the end of your subject string. Previous Comments: ------------------------------------------------------------------------ [2011-01-27 15:00:03] richard at roguewavelimited dot com Correct php version ------------------------------------------------------------------------ [2011-01-27 14:58:49] richard at roguewavelimited dot com Description: ------------ The preg_replace is doing a double replacement when the parenthesized pattern is the whole string. Test script: --------------- define ('EOL', "\n"); $patterns = '|(.*)|'; $replacements = '$1-new'; $line = 'OLD'; $line = @preg_replace($patterns, $replacements, $line, -1, $changes); print $line . EOL; Expected result: ---------------- 'OLD-new' Actual result: -------------- 'OLD-new-new' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53855&edit=1

« previous php.bugs (#158237) next »