Title |
Test
Find
HTML href
|
Expression |
(?i)(?s)<a[^>]+?href="?(?<url>[^"]+)"?>(?<innerHtml>.+?)</a\s*> |
Description |
Matches a complete HTML href tag, placing the URL into a group named "url" and the innerHTML into a group named "innerHtml" |
Matches |
<a href="http://regexplib.com">Inner <span>html</span></a> |
Non-Matches |
<a href="http://regexplib.com"> |
Author |
Rating:
Kevin Spencer
|
Source |
Kevin Spencer |
Your Rating |
|
Title: Thanks!
Name: Eugene Rosenfeld
Date: 12/30/2009 9:27:46 PM
Comment:
Thanks for the regex. Saved me a lot of time. I did find one issue: it was only detecting anchor tags where the href attribute was the last attribute in the anchor tag. So, tags like the following would get missed:
<A href="http://thingsthatshouldbeeasy.blogspot.com/2009/08/anycpu-x86-x64-whats-difference.html" target="_blank">differences between AnyCPU, x86, and x64 compiler options</A>
because of the (in this case) the target attribute after the href attribute.
All it took was a slight addition to your regex: add [^>]+ between the end of the href group and the closing of the anchor tag > .
Here's the full new expression:
(?i)(?s)<a[^>]+?href="?(?<url>[^"]+)"?[^>]+>(?<innerHtml>.+?)</a\s*>