python - How to remove tabs and newlines with a regex -
in python 3.x, special re sequence '\s' matches unicode whitespace characters including [ \t\n\r\f\v].
the following piece of code intended replace tabs , newlines space.
import re text = """hello friends. how doing? i'm fine.""" output = re.sub('\s', ' ', text) print(output) however, tab still present in output. why?
the problem is(likely) tab character bunch of spaces.
>>> re.sub(r"\s+", " ", text) "hello friends. how doing? i'm fine."
Comments
Post a Comment