Regex pattern for anchor tags (part 2)

Thanks to a comment by Jerry Pisk, I have revised the RegEx pattern to allow the anchor tag to include other attributes as well.  Here is the revision:

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

Published Friday, June 18, 2004 9:54 PM by Palermo4
Filed under: ,

Comments

# re: Regex pattern for anchor tags (part 2)

Saturday, June 19, 2004 1:19 AM by Jerry Fan
Jerry Pisk needs a blog! Where is Jerry's blog?!?!

# re: Regex pattern for anchor tags (part 2)

Monday, June 21, 2004 12:04 AM by scott cate
even this needs to check for white space.

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

does that work for everyone?

I added the [.\s] on both sides

# re: Regex pattern for anchor tags (part 2)

Monday, June 21, 2004 12:05 AM by scott cate
also, my original article was at
http://scottcate.mykb.com/Article_625C8.aspx

Thanks,

# re: Regex pattern for anchor tags (part 2)

Monday, June 21, 2004 2:29 AM by J. Michael Palermo IV
Actually, there is no need to check for white space specifically, is there? I tried the following pattern with no issues (regardless of white space)

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

Notice I also added the [^"^'] where the url content exists

Leave a Comment

(required) 
(required) 
(optional)
(required)