Split Strings into words with multiple word boundary delimiters

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

    First of all, always use re.compile() before performing any RegEx operation in a loop because it works faster than normal operation.

    so for your problem first compile the pattern and then perform action on it.

    import re
    DATA = "Hey, you - what are you doing here!?"
    reg_tok = re.compile("[\w']+")
    print reg_tok.findall(DATA)
    

提交回复
热议问题