.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,390 points
57 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
• 12,200 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
• 56,160 points
37 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
• 56,160 points
554 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
• 56,160 points
475 views
+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,810 points
87 views
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 122 views
0 votes
1 answer

Python Regex Search And Replace

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

answered May 20 in Python by SDeb
• 12,200 points
29 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
• 12,200 points
157 views