python - 如何将字符串拆分为长度不同的字母数字列表
问题描述
test_str = "1123456789ExampleDataEntryNumberOne2123456789ExampleDataEntryTwo"
我想以这种形式拆分上面的字符串
['1123456789ExampleDataEntryNumberOne', '2123456789ExampleDataEntryTwo']
解决方案
可以用正则表达式解决
import re
test_str = "1123456789ExampleDataEntryNumberOne2123456789ExampleDataEntryTwo"
res = list(filter(None,re.split("([0-9]+[a-zA-Z]+)", test_str)))
print (res)
推荐阅读
- typescript - 来自 PHP 编码器的类映射和 PSR-4 的打字稿中的命名空间
- ios - 调整自定义导航返回按钮的位置
- zend-framework3 - zf3骨架应用程序在更改应用程序模块的module.config.php时不起作用
- python-3.x - pathlib mkdir 按文件名创建文件夹
- javascript - 使用 javascript 应用 CSS 规则
- xcode - 存档的 macOS 应用程序以空白窗口启动
- qt - QDir::SortFlag 成员在 QML 中可用
- php - 如何使用 PHP 显示 MySQL 多对多关系
- svelte - 是否可以在插槽内制作子组件以将数据发送给其父组件?
- php - 如何在页面内容(Divi Builder)中显示此自定义简码?