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

Victor Hooi victorhooi at gmail.com
Tue Jul 28 16:09:45 CEST 2015


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']


More information about the Python-list mailing list