首页 > 解决方案 > 如何将字符串拆分为长度不同的字母数字列表

问题描述

test_str = "1123456789ExampleDataEntryNumberOne2123456789ExampleDataEntryTwo"

我想以这种形式拆分上面的字符串

['1123456789ExampleDataEntryNumberOne', '2123456789ExampleDataEntryTwo']

标签: pythonregex

解决方案


可以用正则表达式解决

import re
 
test_str = "1123456789ExampleDataEntryNumberOne2123456789ExampleDataEntryTwo"
res = list(filter(None,re.split("([0-9]+[a-zA-Z]+)", test_str)))

print (res)

推荐阅读