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)
I believe the approach you describe in perl could also be used in python, eg:
re.sub(r'[^\w=]', '',mystring)
would remove everything except word-characters and =