Efficiently split a string using multiple separators and retaining each separator?

前端 未结 9 1347
野趣味
野趣味 2021-02-02 10:44

I need to split strings of data using each character from string.punctuation and string.whitespace as a separator.

Furthermore, I need for the

9条回答
  •  梦毁少年i
    2021-02-02 11:33

    My take:

    from string import whitespace, punctuation
    import re
    
    pattern = re.escape(whitespace + punctuation)
    print re.split('([' + pattern + '])', 'now is the winter of')
    

提交回复
热议问题