newby question: Splitting a string - separator

Noah noah at noah.org
Thu Dec 8 14:27:43 EST 2005


Thomas Liesner wrote:
> ...
> The only thing i can rely on, ist that the
> recordseparator is always more than a single whitespace.
>
> I thought of something like defining the separator for split() by using
>  a regex for "more than one whitespace". RegEx for whitespace is \s, but
> what would i use for "more than one"? \s+?

For your split regex you could say
    "\s\s+"
or
    "\s{2,}"

This should work for you:
    YOUR_SPLIT_LIST = re.split("\s{2,}", YOUR_STRING)

Yours,
Noah




More information about the Python-list mailing list