How to remove HTML comments using Regex in Python

后端 未结 6 1584
眼角桃花
眼角桃花 2020-12-19 11:23

I want to remove HTML comments from an html text

heading

some text <-- con --> more text
6条回答
  •  囚心锁ツ
    2020-12-19 12:10

    html = re.sub(r"", "", html)
    

    re.sub basically find the matching instance and replace with the second arguments. For this case, matches anything start with . The dot and ? means anything, and the \s and \n add the cases of muti line comment.

提交回复
热议问题