Created
December 27, 2010 06:49
-
-
Save zhasm/755925 to your computer and use it in GitHub Desktop.
escape html tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# | |
#author: rex | |
#blog: http://iregex.org | |
#filename dictregex.py | |
#created: 2010-12-27 14:27 | |
import re | |
htmldict={ | |
"&": "&", | |
'"': """, | |
"'": "'", | |
">": ">", | |
"<": "<", | |
} | |
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