Split on multiple delimiters, and also treat consecutive delimiters as a single delimiter?

MRAB python at mrabarnett.plus.com
Tue Jul 28 10:30:25 EDT 2015


On 2015-07-28 15:09, Victor Hooi wrote:
> On Tuesday, 28 July 2015 23:59:11 UTC+10, m  wrote:
>> W dniu 28.07.2015 o 15:55, Victor Hooi pisze:
>> > I know the regex library also has a split, unfortunately, that does not collapse consecutive whitespace:
>> >
>> > In [19]: re.split(' |', f)
>>
>> Try ' *\|'
>>
>> p. m.
>
> Hmm, that seems to be getting closer (it returns a four-element list):
>
> In [23]: re.split(' *\|', f)
> Out[23]:
> ['    14     *0    330     *0     760   411',
>   '0       0   770g  1544g   117g   1414 computedshopcartdb:103.5%          0      30',
>   '0     0',
>   '1    19m    97m  1538 ComputedCartRS  PRI   09:40:26']
>
Try '[ |]+'.




More information about the Python-list mailing list