Re: [PHP] potential preg_replace bug; unsure however

2001-09-03 Thread


From: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Sat, Sep 01, 2001 at 08:55:15PM +0200
Message-ID: <[EMAIL PROTECTED]>
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 <[EMAIL PROTECTED]>




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?



-- 

* R&zE:


-- 
-- Renze Munnik
-- DataLink BV
--
-- E: [EMAIL PROTECTED]
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM  HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] potential preg_replace bug; unsure however

2001-09-01 Thread alvarez


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 <[EMAIL PROTECTED]>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]