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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -