In perl s/[^\\w:]//g would replace all non alphanumeric characters EXCEPT :
s/[^\\w:]//g
In python I\'m using re.sub(r\'\\W+\', \'\',mystring)
re.sub(r\'\\W+\', \'\',mystring)
re.sub(r'[^a-zA-Z0-9=]', '',mystring)
You can add whatever you want like _ whichever you want to save.
_