Dec-21-2016, 06:47 PM
here is the solution...
import re def rewrite_title(hb,nt): """ Replace the HTML title contents with the given TITLE """ return re.sub(r'(<title>)(.*?)(</title>)',r'\1'+nt+r'\3',hb,0, re.IGNORECASE) #hb = 'blah<TITLE>{title}</TiTle>halb' #nt = 'Bar title' #rewrite_title(hb,nt)