Page 1 of 1

Just href and rel from anchor tags.

Posted: Mon Feb 25, 2008 3:58 pm
by HCBen
I had to come up with this one the other day to search through all anchor tags for the "href" and "rel" values, in any position in the anchor tag, and ignore all other attributes:

Code: Select all

 
#<a\s+(?:(?:title|class|id|style)=["\']?[^\'"]*["\']?\s*)*(?:href=["\']([^"\']*)["\']\s*)(?:(?:title|class|id|style)=["\']?[^\'"]*["\']?\s*)*(rel=["\']?(\w+)["\']?)*(?:[^>]*)?>(.*?)</a>#is
 
So far it works and does what I need but, man, is that ugly or what?

Just thought I'd share...

Cheers,
Ben