Dec. 12, 2008
12:38 a.m.
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()