Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51686 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67331 invoked from network); 14 Mar 2011 18:44:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Mar 2011 18:44:54 -0000 Authentication-Results: pb1.pair.com header.from=mail_ben_schmidt@yahoo.com.au; sender-id=unknown; domainkeys=good Authentication-Results: pb1.pair.com smtp.mail=mail_ben_schmidt@yahoo.com.au; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain yahoo.com.au from 98.139.91.240 cause and error) DomainKey-Status: good X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: mail_ben_schmidt@yahoo.com.au X-Host-Fingerprint: 98.139.91.240 nm11-vm0.bullet.mail.sp2.yahoo.com Received: from [98.139.91.240] ([98.139.91.240:37179] helo=nm11-vm0.bullet.mail.sp2.yahoo.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/19-16045-5226E7D4 for ; Mon, 14 Mar 2011 13:44:54 -0500 Received: from [98.139.91.62] by nm11.bullet.mail.sp2.yahoo.com with NNFMP; 14 Mar 2011 18:44:50 -0000 Received: from [98.139.91.57] by tm2.bullet.mail.sp2.yahoo.com with NNFMP; 14 Mar 2011 18:44:50 -0000 Received: from [127.0.0.1] by omp1057.mail.sp2.yahoo.com with NNFMP; 14 Mar 2011 18:44:50 -0000 X-Yahoo-Newman-Id: 822800.39184.bm@omp1057.mail.sp2.yahoo.com Received: (qmail 97770 invoked from network); 14 Mar 2011 18:44:50 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com.au; h=DKIM-Signature:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=hPzYDx8seqEzG9Kzhl6aZKpgAVp56yhcqdwwqO0uicDI6tmuCnmgk1LEUvsf+Zojkz7HpY9l7DJ/YApaxpzZhr4ksSVSZb5H8stV75xFO8kA5V5ljBM75Xg5yEzas8yqEGpeR8LMtegZA5sCK2gqTcUaM/XRhIg4rLlDWxIGN9I= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com.au; s=s1024; t=1300128290; bh=XaZE2YXEDUn/oTcp+05nGUtunsCKw30BavYrOUCaMQs=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=FxVSyza+myUbaHmyOLtH2Q2JQUunHUVLhisOrTbdaxHPeRvHiU2qdk0EKrnTif2pFskKDc5NgviNJNyrOG2QvjFJzeDVvBy1zQlfG3VoxdK3gQeTpJG6xtcXWe0CcFeg/e6Ppa4u3SH43brZY4rK2486hNdmJuhrGmaAB21GIGw= Received: from thought.local (mail_ben_schmidt@203.217.72.107 with plain) by smtp144.mail.mud.yahoo.com with SMTP; 14 Mar 2011 11:44:49 -0700 PDT X-Yahoo-SMTP: enFMnPSswBAexaHyzgobwuUTrYOhZdJ0KRA2SjA- X-YMail-OSG: v3kph9UVM1n62k8rBS2ZvkkGBeX8l9G.Yxyv.f3dLPnOaxh _hQFwA6Wfa5nJLmAisl.U.fsm3_uUK16cGzJBc.Dkubkcoc.tfcLVkyKVUso Pe.NfQH3iew1hJ436Ne11ZHLEYgv3.rI623NO2SzouWJxYPFfFj5bkTivUmU uyRGK9gFys8dJWdgMVHf7cvjnQ87a2.uyCvs_gAQVriyAycexpleUKjT2wgM oeWfoFjnPAvMOTxarhVrcqTCyKutfuf2.qQV5147HTkDXYXlZG1u0r98o5CJ 1v8iqoHFWhD2c4A-- X-Yahoo-Newman-Property: ymail-3 Message-ID: <4D7E621F.2000608@yahoo.com.au> Date: Tue, 15 Mar 2011 05:44:47 +1100 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-GB; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 ThunderBrowse/3.3.5 MIME-Version: 1.0 To: Martin Scotta CC: PHP internals References: <4D7E60BA.4040208@yahoo.com.au> In-Reply-To: <4D7E60BA.4040208@yahoo.com.au> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] preg_replace does not replace all occurrences From: mail_ben_schmidt@yahoo.com.au (Ben Schmidt) On 15/03/11 5:38 AM, Ben Schmidt wrote: > On 15/03/11 2:18 AM, Martin Scotta wrote: >> I chose the simplest example to show the preg_replace behavior, > > You've GOT to be kidding. The SIMPLEST?! > > How about an example that doesn't require escaping ALL the interesting > characters involved? > > Here's a modified version that I think it quite a bit simpler: > > function test($str) { > static $re = '/(^|[^a])b/'; > static $change = '$1ab'; > > echo $str, PHP_EOL; // input > echo preg_replace($re, $change, $str), PHP_EOL, PHP_EOL; // output > } > > test("str bb str"); // bug? > test("str abab str"); // ok > test("b str b"); // ok > test("ab str ab"); // ok > ?> > > The way I interpret it, it should put an 'a' before every 'b' that is > not already preceded by an 'a'. > > But the buggy case gives 'str abb str' rather than the expected > 'str abab str'. > > It does look like a bug to me. Actually, no it doesn't. The behaviour is correct. Matches cannot overlap. Since the character preceding 'b' is part of the match, there is only one match in the string 'str bb str'. The match is ' b'. After that match, the You actually want an assertion. I think this: static $re = '/(^|(?