Simple regex with whitespaces

Mark Peters mpeters42 at gmail.com
Mon Sep 11 00:12:47 EDT 2006


>   Which of course does not work. I cannot express the fact: sentence
> have 0 or 1 whitespace, separation of group have two or more
> whitespaces.
>
> Any suggestion ? Thanks a bunch !
How about this:

>>> import re
>>> s = '    hello world               how are you'
>>> re.split(r"\s{2,}",s)
['', 'hello world', 'how are you']




More information about the Python-list mailing list