View Single Post

  #2 (permalink)  
Old 07-08-2006
Jos van Uden
 
Posts: n/a
Default Re: regular expression for parsing html using preg_match_all

crescent_au@yahoo.com wrote:

> preg_match_all("/(<a\ class\=link\ href\=(.*)>)(<\/a>)/", $lines,
> $matches1);
>

The above RE gives me "Shopping Cart" plus "New Age" as well. I just
> want "Shopping Cart". What am I doing wrong? My RE is somehow ignoring
> </a> tag right after Shopping Cart and instead accepting </a> after New
> Age. Please help!


By default the multipliers are "greedy" and match as
much as possible. You can stop this by placing a question
mark behind the multiplier like (.*?)

Then it will match as little a possible.

Jos

PS. This little prog may be useful if you have trouble
with Regexes: http://www.regexbuddy.com/

(not mine)

Reply With Quote