How to split() by multiple characters?

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu May 8 04:43:35 EDT 2003


nforest at airpost.net (Nick Forest) wrote in
news:d83b5be4.0305080038.53741bec at posting.google.com: 

> Given an piece of text in a long string, how to split() it by ',' or
> '.' or ';' ... 
> 
> i.e. text.split ( '[,.;]' )
> 
> Of course, the code doesn't work. :-(
> Is there any good way to do this?
> 

>>> import re
>>> re.split('[,.;]', "Once,upon;a.time")
['Once', 'upon', 'a', 'time']


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list