RE: [PHP] EREG_REPLACE different from 4.04 to 4.06
| From: | Jeremy Allen | Date: | Mon, 05 Nov 2001 15:37:38 +0000 |
| Subject: | RE: [PHP] EREG_REPLACE different from 4.04 to 4.06 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-73499@lists.php.net to get a copy of this message | ||
IIRC,
The question mark after the greedy operator (*) controls
its greediness. For Perl REGEX I know this is true. For
EREG I am not sure, but that would fit. So the question
mark after the greedy operator (*) does not have the same
meaning it usually does. If you want the question mark
put it in a character class [].
This way you are sure you get only the characters you want
, and the only character is your question mark.
Then "aaaaaaaaaaaaaa?site="
Would match be matched by the regex ".*[?]site=".
I don't know of any changes in the versions you mention,
however if the ? is able to control greediness in EREG
you must watch out for that.
Thanks
Jeremy Allen
-----Original Message-----
From: Christoph Starkmann [mailto:kiko@nfq.de]
Sent: Monday, November 05, 2001 9:47 AM
To: 'php-general@lists.php.net'
Subject: RE: [PHP] EREG_REPLACE different from 4.04 to 4.06
Well...
> >From: Christoph Starkmann <kiko@nfq.de>
> > > ereg_replace(".*?site=", "", $path);
> >
> >Depends on what you want to find, but as far as I see
> >your expression doesn't make too much sense when you
> >DON'T excape the "?".
> >
> >In the above case, it would search for
> >
> >.* any number (0 to ...) of characters
> >? one or none character
> >site=
>
> Yes, I think you are right. So why doesn't it match something like
> /aaaaaa?site=x in 4.06? I thought regexp should find the
> longest match which
> would include would be /aaaaaa?site=
> Just a comment :)
I see... I think now YOU are right.
.*?site should match any string that contains site= because
.* can be any (or no) char and
? can be zero or any (one) char.
And YES, IMHO
/aaaaa?site=x
should be matched.
Anybody knows what's going on here?
Cheers,
Kiko
-----
It's not a bug, it's a feature.
christoph starkmann
mailto:kiko@nfq.de
http://www.fh-augsburg.de/~kiko
ICQ: 100601600
-----
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com