Split Strings into words with multiple word boundary delimiters

前端 未结 30 2621
既然无缘
既然无缘 2020-11-21 05:09

I think what I want to do is a fairly common task but I\'ve found no reference on the web. I have text with punctuation, and I want a list of the words.

\"H         


        
30条回答
  •  滥情空心
    2020-11-21 05:55

    I had a similar dilemma and didn't want to use 're' module.

    def my_split(s, seps):
        res = [s]
        for sep in seps:
            s, res = res, []
            for seq in s:
                res += seq.split(sep)
        return res
    
    print my_split('1111  2222 3333;4444,5555;6666', [' ', ';', ','])
    ['1111', '', '2222', '3333', '4444', '5555', '6666']
    

提交回复
热议问题