Re: potential preg_replace bug; unsure however
| From: | * R&zE: | Date: | Mon, 03 Sep 2001 08:02:07 +0000 |
| Subject: | Re: potential preg_replace bug; unsure however | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-65720@lists.php.net to get a copy of this message | ||
<Original message>
From: alvarez@sto13.st-oneline.de <alvarez@sto13.st-oneline.de>
Date: Sat, Sep 01, 2001 at 08:55:15PM +0200
Message-ID: <200109011855.UAA14431@sto13.st-oneline.de>
Subject: [PHP] potential preg_replace bug; unsure however
> I built a Perl-style regex to match function calls in C-like
> languages where $name is the functions name. The functions
> are assumed to accept a single string as parameter.
>
> Here it is.
>
> /$name\s*\(\s*\"(.*)\"\s*\)\s*;/s
>
> The expression is successfully preg_match'ed on a stream
> of code, but when preg_replace is passed the same expression
> it does not return. The piece of code I tested this with was
> fairly small so that an increased demand of computation time
> is unlikely be the reason for this behaviour.
>
> Substituting the subexpression (.*) by ([^\"]*) remedies this.
>
> The version of the PHP install is 4.05.
>
>
> Any ideas?
>
>
> D. Alvarez Arribas <alvarez@st-oneline.net>
</Original message>
<Reply>
Well... Don't think this is a bug. Regexps usualy are greedy. They
try to take as much code/text as they can get. And well... '.*' can
take up about everything it encounters. Actually (IMO) you should
try to avoid using '.*'. What you mentioned "Substituting the
subexpression (.*) by ([^\"]*) remedies this." is a much better
solution. It's what you're looking for in the first place. I mean...
you're looking for some text that goes 'till the ". Why would you
want to use '.*' then?
</Reply>
--
* R&zE:
-- »»»»»»»»»»»»»»»»»»»»»»»»
-- Renze Munnik
-- DataLink BV
--
-- E: renze@datalink.nl
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- ««««««««««««««««««««««««