Just href and rel from anchor tags.

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
HCBen
Forum Commoner
Posts: 33
Joined: Thu Jun 22, 2006 3:15 pm
Location: Indiana

Just href and rel from anchor tags.

Post 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
Post Reply