two or more whitespace regular expression?

Alex Martelli aleax at aleax.it
Sun Sep 15 03:33:50 EDT 2002


eugene kim wrote:

> i used this..
> 
> words = string.split(line, '['+string.whitespace
> +']'+'['string.whitespace+']+')
> 
> which didn't work..

The split method of a string (and the old split
function in module string, which internally just
invokes the split method) takes a string, not a
regular expression.  To use regular expressions,
you must import re first.  Then, for example:

import re
twoormorewhites = re.compile(r'\s\s+')

words = twoormorewhites.split(line)


Alex




More information about the Python-list mailing list