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,910 points
622 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,300 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,090 points
865 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,090 points
11,179 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,090 points
7,484 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 19, 2020 in Python by Gitika
• 65,910 points
1,495 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,058 views
0 votes
1 answer
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,300 points
841 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,300 points
2,094 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP