Re: ereg() problem: solution

From: Date: Thu, 01 Feb 2007 05:22:34 +0000
Subject: Re: ereg() problem: solution
Groups: php.general 
Request: Send a blank email to php-general+get-248136@lists.php.net to get a copy of this message
Hi In reference to my query about 'greed' in regex in php and the following code
$x = ereg("<route name='$to' x='\.\./(.*)/in' rec='.*' />", $get_route, $m); I solved the immediate problem with the following:
<route name='$to' x='\.\./([a-z]{2}|a?u_[0-9a-z]{8})/in' rec='.*' /> as you can see, the regex is quite a bit more complicated and I do not know if it will match all the possibilities that it will have to. It looks like it should. one possibility that it is matching is just two letters, in this case jk. The other possibility is u_ or au_ followed by 8 randomly selected letters and/or numbers. In short I was trying to be as simple and comprehensive as possible with (.*) as the regular expression. But the idea of greed came to mind when the match was containing far more than antic- ipated. Greed is when the regular expression tries to match as much as possible, in this case (.*) appears to be matching every instance of anything and everything else in the way, so it ends up including the entire balance of the line. A least that is my explanation. So I did something more complicated to get what I wanted. Simplicity is not always so simple. Thanks for all responses. JK

« previous php.general (#248136) next »