Perl regular expression bug

From: Date: Mon, 15 Jan 2001 21:40:06 +0000
Subject: Perl regular expression bug
Groups: php.general 
Request: Send a blank email to php-general+get-34683@lists.php.net to get a copy of this message
This only applies to PHP 4.0.4 Back with PHP 4.0.2, I could do this: <?PHP $string = "[["; $string = preg_replace("/(\W)/", "\\\\1", $string); ?> $string would then contain "\[\[". Now, if I use that same code, $string contains "\\1\\1\\1\\1". I tried to compensate for this using PHP's new ability to allow perl syntax in the replace section. <?PHP $string = "[["; $string = preg_replace("/(\W)/", "\\$1", $string); ?> That leaves $string with "\$1\$1\$1\$1". Which tells me it thought I was backreferencing the $. So, to combat said assumption, I tried three, four, even five slashes in front of $1, and nothing worked. All I got were variations of "\$1\$1\$1\$1". I have to assume this is a bug, since this worked back in 4.0.2 which I stopped using due to segfaults under certain circumstances. Ideas? -- +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+ | Shaun M. Thomas INN Database Programmer | | Phone: (309) 743-0812 Fax : (309) 743-0830 | | Email: sthomas@townnews.com AIM : trifthen | | Web : hamster.lee.net | | | | "Most of our lives are about proving something, either to | | "ourselves or to someone else." | | -- Anonymous | +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

« previous php.general (#34683) next »