How do I exclude spaces from regex, but will not ignore on special characters. My current code is:-
pattern=re.compile("[^\w]")
var = pattern.sub('', var)
I know \w will remove all whitespace characters, but how to exclude space only?
Example:
var = "hi this is test!@#$%%^^"
after regex it will become:
var = "hi this is test"
\wmatches word characters.