[英]Remove only anchor tags from string with regex
I know that to remove all html tags from a string one can use: 我知道从字符串中删除所有html标签可以使用:
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>
Thanks revo it worked perfectly. 谢谢revo,它运作良好。 I also manage to fix this problem using this regex
我也设法使用此正则表达式解决此问题
string = re.sub('<a.*?>|</a> ', '', string)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.