This passed on https://regex101.com/ without any issues. Did I miss anything? The entire string is in one line.
def get_title_and_content(html):
html = """<!DOCTYPE html> <html> <head> <title>Change delivery date with Deliv</title> </head> <body> <div class="gkms web">The delivery date can be changed up until the package is assigned to a driver.</div> </body> </html> """
title_pattern = re.compile(r'<title>(.*?)</title>(.*)')
match = title_pattern.match(html)
if match:
print('successfully extract title and answer')
return match.groups()[0].strip(), match.groups()[1].strip()
else:
print('unable to extract title or answer')