I know that to remove all html tags from a string one can use:
string = re.sub('<[^<]*?/?>', '', string)
But is there anyway that I can remove only anchor tags and keep all other tags. So for example:
<p>Some text<a href="#">link</a></p>
become:
<p>Some text link</p>
It's enough to look for opening and closing a
tags separately and omit them:
<(?:a\b[^>]*>|/a>)
Live demo
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