python .replace() regex

user1442957 picture user1442957 · Jul 13, 2012 · Viewed 419.3k times · Source

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>'))

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Jul 13, 2012

No. Regular expressions in Python are handled by the re module.

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