Dec-21-2016, 05:14 PM
It's bad that you have a task where you most use regex with html.
There are parser for this you should learn to use instead.
Eg.
There are parser for this you should learn to use instead.
Eg.
from bs4 import BeautifulSoup html = '<html><head><title>new title</title></head></html>' soup = BeautifulSoup(html, 'html.parser') find_tile = soup.find('title') find_tile.string = 'hello world' print(soup.prettify())
Output:<html>
<head>
<title>
hello world
</title>
</head>
</html>