python在字符串中拆分数字

-1 python regex string split module

我想知道以下方式将字符串中的数字分开是最简单的方法(可能是正则表达式).示例:"abc12de34f5" to:["abc", "12", "de", "34", "f", "5"]

但是如果字符串中有连接标记,则以这种方式分开:示例:"abc1,2de3.4f5" to:["abc", "1,2", "de", "3.4", "f", "5"]

感谢您的任何建议和意见

Joe*_*ett 5

>>> import re
>>> s = "abc12de34f5"
>>> re.findall(r'[\d\W]+|[a-zA-Z]+', s)
['abc', '12', 'de', '34', 'f', '5']
>>> t = "abc1,2de3.4f5"
>>> re.findall(r'[\d\W]+|[a-zA-Z]+', t)
['abc', '1,2', 'de', '3.4', 'f', '5']
Run Code Online (Sandbox Code Playgroud)