how to remove text between [removed] and [removed] using python?

后端 未结 9 648
眼角桃花
眼角桃花 2021-02-04 19:19

how to remove text between using python?

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-04 20:05

    You can do this with the HTMLParser module (complicated) or use regular expressions:

    import re
    content = "asdf  end"
    x=re.search("", content, re.DOTALL)
    span = x.span() # gives (5, 27)
    
    stripped_content = content[:span[0]] + content[span[1]:]
    

    EDIT: re.DOTALL, thanks to tgray

提交回复
热议问题