import re re_noscript = re.compile('<(/?)script',re.IGNORECASE) html = re_noscript.sub(r'<\1noscript',html)