【发布时间】:2017-07-11 18:44:24
【问题描述】:
如何只针对脚本元素内部的 cmets,而不是所有“双斜线” cmets,例如,这样:
<a href="https://www.example.com">Link to example.com</a>
<script type="text/javascript">
// I am a comment, I describe this script
console.log("Hello World!");
</script>
变成这样:
<a href="https://www.example.com">Link to example.com</a>
<script type="text/javascript">
console.log("Hello World!");
</script>
到目前为止,我有这个:
html = re.sub(re.compile(r"\/\/.*?\n"), "\n", html)
它有效,但它也删除了我的 href 和 src 属性中的链接。
【问题讨论】:
标签: python html regex python-3.x comments