拆分多种分隔符的字符串

map实现

def mySplit(s, ds):
    res = [s]

    for d in ds:
        t = []
        list(map(lambda x: t.extend(x.split(d)), res))
        res = t
    return [x for x in res if x]


s = 'ab;cd|efg|hi,jkl|mn\topq;rst,uvw\txyz'
ds = ';,|\t'
print(mySplit(s, ds))

 

re.split实现

import re

s = 'ab;cd|efg|hi,jkl|mn\topq;rst,uvw\txyz'
ds = ';,|\t'


print(re.split(r'[,;\t|]+', s))

 

posted @ 2019-03-03 12:04  Ray_chen  阅读(160)  评论(0编辑  收藏  举报