Skip to content

Instantly share code, notes, and snippets.

@jadient
Last active January 4, 2016 01:59
Show Gist options
  • Save jadient/8551803 to your computer and use it in GitHub Desktop.
Save jadient/8551803 to your computer and use it in GitHub Desktop.
import re
def replace_one_hex_with_chr(m):
return str(unichr(int(m.group()[1:], 16)))
def replace_hex_with_chr(s):
return re.sub(r'%[0-9A-Fa-f][0-9A-Fa-f]', replace_one_hex_with_chr, s)
if __name__ == '__main__':
import sys, os
if len(sys.argv) < 2:
print 'Usage: %s <string>' % os.path.basename(sys.argv[0])
print 'where <string> contains %xx hex escapes'
else:
print replace_hex_with_chr(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment