python .replace() 正则表达式

标签 python regex

我正在尝试抓取 '</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/

相关文章:

java - 正则表达式 - 多个匹配

python - 正则表达式从给定类型的字符串中获取多个日期

python - 如何在 Flask 中验证 URL 参数

python - Postgres 数据库安全 : what to store in environment variables?

python - 添加 misfire_grace_time 后 APScheduler 丢失作业

python 3.6安装和lib64

c# - 正则表达式,制作基本标题

java - 如何拆分字符串,只保留某些分隔符?

javascript - 使用数组查找文本并替换为类等于文本的文本周围的链接

python - 查找具有最大表面积(不包括相交区域)的边界框轮廓