Scott Cate Weblog 

scott.cate@myKB.com
http://scottcate.myKB.com



Scott Cate KB > Regular Expressions Start Over
Search the Knowledge Base
 
Start Search in the Following Category
Date Modified
Friday, June 18, 2004
Find and parse hyperlinks in string

<a[\s]?href=["'](?<url>[^"]+[.\s]*)["']>(?<name>[^<]+[.\s]*)</a>

Isn't she a beauty? This is my first ever regular expression, that I actually come up with on my own. I did have help from Eric Gunnerson's "Regular Expression Workbench", but I still take credit for coming up with the regular expression on my own.

So I feed in an HTML string, and this Regex.Matches returns a MatchCollection that I can cycle through. Each Match has a groups collection that looks something like this.

[0] = <a href="http://www.scottcate.com">scottcate</a>
[url] = "http://www.scottcate.com"
[name] = scottcate

And there is one of these for every hyperlink on the page. Basically gives me access to the href="" property and the display text.

Hope this helps someone else out there in happy coding land...


All rights reserved. All details are the personal opinion of Scott Cate.
All trademarks referenced are the property of their respective owners.
Scott Cate is a lead programmer for www.myKB.com and
owner of The Arizona .NET User Group and an all around nice guy ;)


Knowledge Base Software - myKB.com

 

Cameron Cate Pictures
Cameron Cate Pix

Site Navigation

Home
Knowledge Base
Wiki Discussions
Photo Album

Sites I Own & Run


Easy Search ASP.NET
mykb.com knowledge base software logo
myKB.com
Knowledgebase Software

KBAlertz.com
Arizona .NET user Group
Group Leader

Affiliations


ASP.NET MVP
2004
2005
2006
2007
2008
2009


Blog Sites I Read

Brady Gaster
Rob Howard
G. Andrew  Duthie
Robert McLaws
Alex Lowe

World of Scott.Net

Scott Guthrie
  -  Father of ASP.NET

Scott Watermasyk
  - .Text (Weblog)

Scott Sargent
Scott Mitchell
ScottG.net
Scott Bellware
Scott Forsyth
Scott Hanselman
Scott Cate

Favorite Books


ASP.NET Cookbook


First Looks @ ASP.NET 2.0