我正在尝试抓取 '</html>'
之后的所有内容标记并删除它,但我的代码似乎没有做任何事情。是否 .replace()
不支持正则表达式?
z.write(article.replace('</html>.+', '</html>'))
最佳答案
没有。 Python 中的正则表达式由 re
处理。模块。
article = re.sub(r'(?is)</html>.+', '</html>', article)
一般:
text_after = re.sub(regex_search_term, regex_replacement, text_before)
关于python .replace() 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11475885/