Skip to content

Instantly share code, notes, and snippets.

@zhasm
Created December 27, 2010 06:49
Show Gist options
  • Save zhasm/755925 to your computer and use it in GitHub Desktop.
Save zhasm/755925 to your computer and use it in GitHub Desktop.
escape html tag
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#author: rex
#blog: http://iregex.org
#filename dictregex.py
#created: 2010-12-27 14:27
import re
htmldict={
"&": "&",
'"': """,
"'": "'",
">": ">",
"<": "&lt;",
}
text=" hello & \" ' <> &"
def escape(string):
return htmldict[string.group(0)]
text=re.sub(r'''[&'"><]''', escape, text)
print text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment