[Tutor] Split string on 2 delimiters ?
Timothy Grant
timothy.grant at gmail.com
Thu Aug 7 23:36:28 CEST 2008
On Thu, Aug 7, 2008 at 2:25 PM, dave selby <dave6502 at googlemail.com> wrote:
> Hi all,
>
> Is there a neat way to split a string on either of two delimiters ie
> space and comma
>
> Cheers
>
> Dave
>>> import re
>>> string = 'this is, a test of splitting; on two delimiters'
>>> re.split(r'[,;]', string)
['this is', ' a test of splitting', ' on two delimiters']
>>> re.split(r'[, ]', string)
['this', 'is', '', 'a', 'test', 'of', 'splitting;', 'on', 'two', 'delimiters']
--
Stand Fast,
tjg. [Timothy Grant]
More information about the Tutor
mailing list