Skip to content

Instantly share code, notes, and snippets.

@justinabrahms
Created December 13, 2009 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinabrahms/255657 to your computer and use it in GitHub Desktop.
Save justinabrahms/255657 to your computer and use it in GitHub Desktop.
# Escaped string issue.
encoded_str = "Caf\\xc3\\xa9"
encoded_str.replace('\\\\', '\')
# returns: "Caf\\xc3\\xa9"
encoded_str.replace('\\', '')
# returns: "Cafxc3xa9"
import re
re.sub('\\\\', '\\', encoded_str)
# returns: "Caf\\xc3\\xa9"
# This one works
encoded_str.decode('string_escape')
# returns: "Caf\xc3\xa9"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment