Skip to content

Instantly share code, notes, and snippets.

@jphall663
Last active January 17, 2017 18:49
Show Gist options
  • Save jphall663/813cabfee914a3f7197bc75ad726befd to your computer and use it in GitHub Desktop.
Save jphall663/813cabfee914a3f7197bc75ad726befd to your computer and use it in GitHub Desktop.
python re string replace
import re
replace_char = '_'
source = 'he"l*&l# o@@'
target = re.sub(r'[-\/\\;,\s\.\/<>&\!:\"\)\(\*\+\?\|=#@]', replace_char, source)
target = re.sub(r"\'", replace_char, target)
print(target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment