[Python-ideas] This seems like a wart to me...
Ron Adam
rrr at ronadam.com
Fri Dec 12 01:38:05 CET 2008
Bruce Leban wrote:
> I think string.split(list) probably won't do what people expect either.
> Here's what I would expect it to do:
>
> >>> '1 (123) 456-7890'.split([' ', '(', ')', '-'])
> ['1', '', '123', '', '456', '7890']
>
> but what you probably want is:
>
> >>>re.split(r'[ ()-]*', '1 (123) 456-7890')
> ['1', '123', '456', '7890']
>
> using allows you to do that and avoids ambiguity about what it does.
>
> --- Bruce
Without getting into regular expressions, it's easier to just allow
adjacent char matches to act as one match so the following is true.
longstring.splitchars(string.whitespace) = longstring.split()
More information about the Python-ideas
mailing list