You are here: Re: regular expression for parsing html using preg_match_all « PHP Programming Language « IT news, forums, messages
Re: regular expression for parsing html using preg_match_all

Posted by Karel de Vos on 12/17/54 11:52

crescent_au@yahoo.com wrote:
>> It most likely has to do with the greediness of *. Regular expressions
>> will match the *longest* possible string. To prevent this, use '?'.
>> given the string: "<a>text</a>more</a>"
>> <a>.*</a> matches "<a>text</a>more</a>"
>> <a>.*?</a> matches "<a>text</a>"
>
> Well what i basically want is:
> <a class="something" href=http://something.com/abc.php">Shopping
> Cart</a>
>
> I want the RE to parse the HTML tag and see if it starts with '<a
> class="something" href=', then IGNORE whatever is between 'href=' and
> '>', and ending with '</a>'. I couldn't figure out how to "ignore" the
> text in between.
>

Instead of a (greedy) * operator, use a negation class that parses
everything upto an certain character :
/(<a\ class\=link\ href\=([^>]*)>)([^<]*)(<\/a>)/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация