-4

i need to make a regex which can match anchor tags having href attribute. It should match any anchor tag having href attribute regardless of having any other attribute or not. So far i came up with this

<\s*a\s*\w*\W*\w*\W*\s*href[^>]*>

but its not working on cases like
<a name="anything" id="anything" href="anything"/>

Abdul Ahad
  • 55
  • 1
  • 6

1 Answers1

-2

Try this one:

<a\s+[^>]*\bhref\b=\"[^\"]+\"[^>]*>
Mayur Koshti
  • 1,794
  • 15
  • 20
  • It's validating `` wich isn't a valid href attribute. Add a check for a whitespace before the `href` – naurel Nov 26 '15 at 10:45
  • And it doesn't validate this case : `` – naurel Nov 26 '15 at 10:50
  • Don't realy know since it's not my question – naurel Nov 26 '15 at 11:43
  • Will not match `< a...`. –  Nov 26 '15 at 11:50
  • No it is not OK. Stop trying to come up with [a broken solution](http://stackoverflow.com/questions/33936144/regex-to-find-special-pattern-in-anchor-tag#comment55632138_33936144). There are (subtle) ways this will break. Just stop. – PeeHaa Nov 26 '15 at 11:50