regex in python to python to remove sapces code example Example: python 3 replace all whitespace characters >>> s = " \t foo \n bar " >>> "".join(s.split()) 'foobar'