Split Strings into words with multiple word boundary delimiters

前端 未结 30 2623
既然无缘
既然无缘 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:46

    Here is my go at a split with multiple deliminaters:

    def msplit( str, delims ):
      w = ''
      for z in str:
        if z not in delims:
            w += z
        else:
            if len(w) > 0 :
                yield w
            w = ''
      if len(w) > 0 :
        yield w
    

提交回复
热议问题