如何在 Python 中使用正则表达式删除 HTML 注释 [英] How to remove HTML comments using Regex in Python
本文介绍了如何在 Python 中使用正则表达式删除 HTML 注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从 html 文本中删除 HTML 注释
I want to remove HTML comments from an html text
<h1>heading</h1> <!-- comment-with-hyphen --> some text <-- con --> more text <hello></hello> more text
应该导致:
<h1>heading</h1> some text <-- con --> more text <hello></hello> more text
推荐答案
你不应该忽略回车.
re.sub("(<!--.*?-->)", "", s, flags=re.DOTALL)
这篇关于如何在 Python 中使用正则表达式删除 HTML 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文