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>

3 Comments

  • Jerry Pisk needs a blog! Where is Jerry's blog?!?!

  • even this needs to check for white space.



    &lt;a[.\s]*href=[&quot;'](?&lt;url&gt;[^&quot;]+[.\s]*)[&quot;'][.\s]*&gt;(?&lt;name&gt;[^&lt;]+[.\s]*)&lt;/a&gt;



    does that work for everyone?



    I added the [.\s] on both sides

  • 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)



    &lt;a.*href=[&quot;'](?&lt;url&gt;[^&quot;^']+[.]*)[&quot;'].*&gt;(?&lt;name&gt;[^&lt;]+[.]*)&lt;/a&gt;



    Notice I also added the [^&quot;^'] where the url content exists

Comments have been disabled for this content.