RegEx pattern for anchor tags

Scott Cate just wrote a blog on his first (from scratch) RegEx pattern to find anchor <a> tag.  Here is my revision:

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

I simply added support for the href value to be enclosed in either single or double quotes.

2 Comments

  • You don't care about anchors with other attributes, such as id, class, style, event handlers and so on?

  • Good point! Thanks for the comment. Although I don't care about extracting such information, your comment made me realize that the pattern did not match anything that included such. Therefore, I am posting a new blog to remedy the situation.

Comments have been disabled for this content.