- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find HTML href
Matches a complete HTML href tag, placing the URL into a group named "url" and the innerHTML into a group named "innerHtml"
<a href="">Inner <span>html</span></a>
<a href="">
Author Rating: The rating for this expression. Kevin Spencer
Source Kevin Spencer
Your Rating
Bad Good

Enter New 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
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="" 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-2024, | ASP.NET Tutorials