replace regex in Python

0 votes
I am using the </html> tag to grab everything and delete it. But the code doesn't seem to work. Can anyone tell if .replace() does not support regex?

z.write(article.replace('</html>.+', '</html>'))
Nov 26, 2018 in Python by ana1504.k
• 7,890 points
159 views

1 answer to this question.

0 votes

No,  .replace() does not support regex. Regular expressions in Python are handled by the re module.

such as :

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

answered Nov 26, 2018 by SDeb
• 13,250 points

Related Questions In Python

0 votes
1 answer

How to use string.replace() in python 3.x

replace() is a method of <class 'str'> ...READ MORE

answered Aug 3, 2018 in Python by Priyaj
• 58,080 points
343 views
0 votes
1 answer

How to replace values with None in Pandas data frame in Python?

Actually in later versions of pandas this ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 58,080 points
7,405 views
0 votes
1 answer

Replace NaN in rolling mean in python

Try this: In [92]: ts.rolling(window=2, min_periods=1).mean() Out[92]: ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 58,080 points
3,121 views
0 votes
1 answer

Speed up millions of regex replacements in Python 3

One thing you can try is to ...READ MORE

answered Nov 18, 2020 in Python by Gitika
• 65,850 points
43 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,731 views
0 votes
0 answers
0 votes
1 answer

Python Regex Search And Replace

You need not use a regex. Your ...READ MORE

answered May 20, 2019 in Python by SDeb
• 13,250 points
443 views
0 votes
1 answer

Indentation of Python in Notepad++

To indent the block, select the entire ...READ MORE

answered Sep 18, 2018 in Python by SDeb
• 13,250 points
995 views