python .replace() 正则表达式 [英] python .replace() regex
本文介绍了python .replace() 正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在 '</html>'
标记之后抓取所有内容并将其删除,但我的代码似乎没有做任何事情..replace()
不支持正则表达式吗?
I am trying to do a grab everything after the '</html>'
tag and delete it, but my code doesn't seem to be doing anything. Does .replace()
not support regex?
z.write(article.replace('</html>.+', '</html>'))
推荐答案
没有.Python 中的正则表达式由 re
模块处理.
No. Regular expressions in Python are handled by the re
module.
article = re.sub(r'(?is)</html>.+', '</html>', article)
一般来说:
text_after = re.sub(regex_search_term, regex_replacement, text_before)
这篇关于python .replace() 正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文