python .replace() 正規表現 [重複] 質問する

python .replace() 正規表現 [重複] 質問する

タグの後のすべてを取得し'</html>'て削除しようとしていますが、コードは何も実行していないようです。.replace()正規表現をサポートしていないのでしょうか?

z.write(article.replace('</html>.+', '</html>'))

ベストアンサー1

いいえ。Pythonの正規表現は、reモジュール。

article = re.sub(r'(?is)</html>.+', '</html>', article)

一般的に:

str_output = re.sub(regex_search_term, regex_replacement, str_input)

おすすめ記事