I'm trying to match a substring which does not contain a specific substring "href"
THE STRING
blabla bladibla <a class="link-ch" href="add-tt-2021-s18-chapter-4.1.html#ch-9-1-1-21-3">9.1.1.21.3</a> blabla <a class="link-ch" href="add-tt-2021-s18-chapter-4.1.html#ch-9-1-1-21-5">9.1.1.21.5</a> more blabla <a class="link-tbl">tabel 9.1.1.21.6</a>, some more bladibla
THE DESIRED OUTCOME:
The following line should be matched:
<a class="link-tbl">tabel 9.1.1.21.6</a>
WHAT I HAVE TRIED:
I tried a negative lookahead, but this still matches a-tags having href as a substring
<a class="link.*?(?!href).*?<\/a>
You may use this regex:
<a (?![^<>]*href)[^>]*>.*?<\/a>
RegEx Demo
RegEx Details:
<a : Match <a (?![^<>]*href): Negative lookahead that makes sure that there is no href ahead after 0 or more of any char that are not < and >[^>]*: Match 0 or more of any char that are not >>: Match >.*?: Match 0 or more of any characters<\/a>: Match </a>If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With