Re: regular expressions
| From: | Victor | Date: | Wed, 14 Jun 2000 19:05:47 +0000 |
| Subject: | Re: regular expressions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-1858@lists.php.net to get a copy of this message | ||
"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
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 .*
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.
Victor