Last active
January 27, 2018 07:25
-
-
Save xbalaji/da129694c8480fa69ac5fb60386dcb51 to your computer and use it in GitHub Desktop.
python regular expression replace
This file contains hidden or 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
import re | |
mystr="this is a complex string !@#$%^&*()-=+,.?:;'\\/\" with numbers 1234?" | |
# note: raw string used with double quotes in re.sub | |
out_str = re.sub(r"([ !@#$%^&*()\-=+,.?:;'/\\\"])", r'_', mystr) | |
print(mystr) | |
print(out_str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment