tokenize a string keeping delimiters in Python

后端 未结 5 975
无人共我
无人共我 2021-02-05 10:32

Is there any equivalent to str.split in Python that also returns the delimiters?

I need to preserve the whitespace layout for my output after processing som

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 11:16

    >>> re.compile(r'(\s+)').split("\tthis is an  example")
    ['', '\t', 'this', ' ', 'is', ' ', 'an', '  ', 'example']
    

提交回复
热议问题