How to split a string (using regex?) depending on digit/ not digit

前端 未结 4 904
没有蜡笔的小新
没有蜡笔的小新 2021-01-28 12:54

I want to split a string into a list in python, depending on digit/ not digit. For example,

5 55+6+  5/

should return

[\'5\',\'         


        
4条回答
  •  难免孤独
    2021-01-28 13:42

    Use findall or finditer:

    >>> re.findall(r'\d+|[^\s\d]+', '5 55+6+ 5/')
    ['5', '55', '+', '6', '+', '5', '/']
    

提交回复
热议问题