I have a string:
res = 'qwer!@ 234234 4234gdf36/\////// // \ \\\$%^$% dsfg' and I want to remove ALL slashes and backslashes. I tried this:
import string import re symbolsToRemove = string.punctuation res = 'qwer!@ 234234 4234gdf36/\////// // \ \\\$%^$% dsfg' res = re.sub(r'['+symbolsToRemove+']', ' ', res) print(res) But get the next result:
qwer 234234 4234gdf36 \ \ \ dsfg
What am I doing wrong?
res.replace ("\\", "").replace ("/", "")[!"#$%&'()*+,-./:;<=>?@[\]^_{|}~]` and the\escaspes a]in it. You should escape the symbols to match literal chars. Or at least escape the-,],^and\.'[' + re.escape(symbolsToRemove) + ']'