AMit SiNgh
AMit SiNgh

Reputation: 325

regex to find anchor tag which have not closing tag?

I am using the below regex to find anchor tag which have not closing tag but it is not working. Only match which does not have closing tag. can any provide the correct regex which would really works in this condition.

Regex :

<a[^><]+\b(?!>) 

(It also selects the anchor tag which have closing tag)

https://regex101.com/r/LbmI2G/1

enter image description here

Upvotes: 0

Views: 1063

Answers (1)

David542
David542

Reputation: 110572

A bit more simplistic than Tim's but here's a basic idea:

  1. Match on a < before a >, or:
  2. Match on no following >

<a[^><]+((?=<)|(?!.*>))

enter image description here

Upvotes: 2

Related Questions