How to remove tabs and newlines with a regex

In Python 3.x, the special re sequence '\s' matches Unicode whitespace characters including [ \t\n\r\f\v].

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)

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."

Need Your Help

Utilizing the GPU with c#

c# gpu gpgpu

I am trying to get more processing power out of my grid.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.