RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

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: The rating for this expression. Kevin Spencer
Source Kevin Spencer
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

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*>


Copyright © 2001-2018, RegexAdvice.com | ASP.NET Tutorials