In Python 3.x, the special re sequence 's' matches Unicode whitespace characters including [ fv].
The following piece of code is intended to replace tabs and newlines with a space.
import re text = """Hello my friends. How are you doing? I'm fine.""" output = re.sub('s', ' ', text) print(output)
However, the tab is still present in output. Why?
The problem is(likely) that your tab character is just a bunch of spaces.
>>> re.sub(r"s+", " ", text) "Hello my friends. How are you doing? I'm fine."
1.4m articles
1.4m replys
5 comments
56.9k users