Re: regular expressions

From: Date: Wed, 14 Jun 2000 19:11:36 +0000
Subject: Re: regular expressions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-1859@lists.php.net to get a copy of this message
At 03:05 PM 6/14/00 -0400, Victor wrote:
"Robert J. Cissell" wrote: Hi, I've been trying to use regular expressions to read some of the urls and links from an html file: eregi("<li><a href=\"http://(.*)\">(.*)</a>",$myLine, $temp); I had a similar problem, which is related to not being able to explicitly specify whether the regexp is greedy or not. You see the first (.*) looks greedy and will capture everything until \n, thus the rest will not be matched. One way you can do this is this
Hi Victor, AFAIK you cannot specify that a regex is non-greedy using any of the ereg functions. Try using the perl-compatible regex functions.
eregi("<li><a href=\"http://([^\"]+)">(.+)</a>",$myLine,$temp); Try that. The reason I used .+ and not .* is that I think .+ is not greedy be default, but I could be wrong (In perl, it is greedy). I know that php can be compiled with pcre (I guess perl expressions). Then you want to change your .* to .*? which are nongreedy versions of .*
+ is greedy.
Hopefully someone who know php regexp will post, but the regexp don't seem to be as compliant as they are supposed to be with the stardard. Well, if it doesn't work, then there must be some way to make .* nongreedy in PHP. If I find the syntax, I'll post it.
HTH, Zak Zak Greant Creative Director Nucleus Information Service Inc. "I am rather like a mosquito in a nudist camp: I know what I ought to do, but I don't know where to begin." - Stephen Bayne

« previous php.general (#1859) next »