Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51693 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98826 invoked from network); 15 Mar 2011 10:33:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2011 10:33:16 -0000 Authentication-Results: pb1.pair.com header.from=rquadling@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=rquadling@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@gmail.com X-Host-Fingerprint: 209.85.216.42 mail-qw0-f42.google.com Received: from [209.85.216.42] ([209.85.216.42:60239] helo=mail-qw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/7D-10215-B604F7D4 for ; Tue, 15 Mar 2011 05:33:16 -0500 Received: by qwi4 with SMTP id 4so292706qwi.29 for ; Tue, 15 Mar 2011 03:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=6WmnmubLetHmgV7v7xejs7e2lkod08rpfE1Oij7isdk=; b=jgjix7xj7haMQoUA3byZ8OCp5vpP8Y3YNAWl30JXLFq6YiofwxNZ/E5z/Xl5N1XZSd zt6JjeGByDoI01jeHy5UuLaeaLykAvV0Nv8morlXBUSpJaE2on81QIwzWgDVLarH41RO 7EdRKn82y+ZWsCSj0c+GNKdXx0+Q6VhQebUjc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; b=FqDCEznjc8+ZwGSLCNolDC9mxo7hMxQiDjWGEmMbMVKqm4QhQkkQJqttZWnlcy3/h3 cMvPXdhUJ4QRNaaK0VEXgqGrRxj+PB+OALs4Ky4Jt2Tkz24G5ro6EJ9D9ckPLsDZtN/K /a9FxyaO7iRbYB6dDUFjcKPOhIiviKNNsTCRQ= Received: by 10.229.124.145 with SMTP id u17mr11049510qcr.71.1300185193108; Tue, 15 Mar 2011 03:33:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.40.147 with HTTP; Tue, 15 Mar 2011 03:32:53 -0700 (PDT) Reply-To: RQuadling@googlemail.com In-Reply-To: References: Date: Tue, 15 Mar 2011 10:32:53 +0000 Message-ID: To: Hannes Landeholm Cc: Martin Scotta , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] preg_replace does not replace all occurrences From: rquadling@gmail.com (Richard Quadling) On 14 March 2011 20:36, Hannes Landeholm wrote: > 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 ar= e >> better (and safer) ways to scape slash characters. >> Anyways, *is this the expected preg_replace behavior?* >> >> =C2=A0Martin >> >> > function test($str) { >> =C2=A0 =C2=A0static $re =3D '/(^|[^\\\\])\'/'; >> =C2=A0 =C2=A0static $change =3D '$1\\\''; >> >> =C2=A0 =C2=A0echo $str, PHP_EOL, >> =C2=A0 =C2=A0 =C2=A0 =C2=A0preg_replace($re, $change, $str), PHP_EOL, PH= P_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\' >> >> >> =C2=A0Martin Scotta > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > Did no one see why the regex was wrong? RegexBuddy (a windows app) explains regexes VERY VERY well. --=20 Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY