Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51688 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83155 invoked from network); 14 Mar 2011 20:36:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Mar 2011 20:36:37 -0000 Authentication-Results: pb1.pair.com header.from=landeholm@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=landeholm@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: landeholm@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-iw0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:32869] helo=mail-iw0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 81/CB-16045-45C7E7D4 for ; Mon, 14 Mar 2011 15:36:37 -0500 Received: by iwn3 with SMTP id 3so5674548iwn.29 for ; Mon, 14 Mar 2011 13:36:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=us7nAyJecR1tTBwTB4mgXaUOOK34mC2hjWqN1yYFMfc=; b=OUCnl6Oh7GCLJUp2Q0GHGIbmV65xDoiRC601NQxAYMyfOc0gTwBq4d8F1rxv9fVpYV hlf7yPUDK7QZPKVE0iffOsc4iZUs1it3Y+d+kWE6xP2Eau0s8N5EmTsXZnSq3bv+XqI2 t5nTHTc0LC3tECb6AWZHMC4F/iK+w/DOlZYgA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=AIKWG6WPYuCPHqyfup+GEaO6bvUjTAn270fbbSARvlaTKLHRYzKJMXDV3PZ3g6mW/o pejTsVmsJ9kE0Ye6gB8dMexAGTbZ9k1LfNHIQ+uC8iZaIqxYk5KRTwy3iHDOP7scNTCQ l358eq/A+QbSf36wg/fFFnZ1UU7XjW5No8qQQ= MIME-Version: 1.0 Received: by 10.42.77.3 with SMTP id g3mr1309735ick.6.1300134994323; Mon, 14 Mar 2011 13:36:34 -0700 (PDT) Received: by 10.231.13.73 with HTTP; Mon, 14 Mar 2011 13:36:34 -0700 (PDT) In-Reply-To: References: Date: Mon, 14 Mar 2011 21:36:34 +0100 Message-ID: To: Martin Scotta , internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] preg_replace does not replace all occurrences From: landeholm@gmail.com (Hannes Landeholm) What is more likely to be wrong? Your understanding of a specific regex pattern (which happens to be full of escapes making it incredibly hard to read) or the implementation of preg_replace? ~Hannes On 14 March 2011 16:18, Martin Scotta wrote: > > I chose the simplest example to show the preg_replace behavior, there are > better (and safer) ways to scape slash characters. > Anyways, *is this the expected preg_replace behavior?* > > =A0Martin > > function test($str) { > =A0 =A0static $re =3D '/(^|[^\\\\])\'/'; > =A0 =A0static $change =3D '$1\\\''; > > =A0 =A0echo $str, PHP_EOL, > =A0 =A0 =A0 =A0preg_replace($re, $change, $str), PHP_EOL, PHP_EOL; > } > > test("str '' str"); // bug? > test("str \\'\\' str"); // ok > test("'str'"); // ok > test("\'str\'"); // ok > > ---- > Expected: > > str '' str > str \'\' str > > str \'\' str > str \'\' str > > 'str' > \'str\' > > \'str\' > \'str\' > > ---- > Result: > > str '' str > str \'' str > > str \'\' str > str \'\' str > > 'str' > \'str\' > > \'str\' > \'str\' > > > =A0Martin Scotta