python - Python Regex : Get data after second underscore?
问题描述
I'm trying to get data after second underscore?
sample:
abc_def 1223_this_6729
abc_def,1223_this_6729
abc_def1223_this_6729
output
this_6729
解决方案
要获取第二个下划线之后的数据(根据问题),您可以将split
函数的 maxsplit 参数设置为 2:
str = 'abc_def 1223_this_6729'
str.split('_',2)[2]
回报:
this_6729
由于返回的数组是从零开始的,[2]
因此将在两个下划线后获得字符串的其余部分。
推荐阅读
- python - 从数据框中的一列中提取和拆分文本的正则表达式
- javascript - 三js渲染OBJ为线框(应该是渲染面和底纹)
- java - 滚动工具栏时 FloatingActionButton 被切断
- android - Kotlin/Native -> androidMain -> 未解析的符号
- android - 如何从列表中更新颤动中的文本
- python - 我不能忽略 jupyter notebook 中 python 的弃用警告
- javascript - Voxeet 示例应用程序已启动,但访问 https://localhost:8080 显示错误
- c++ - 如何在 C++ 中对齐或填充打印的文本?
- wordpress - Divi:桌面视图中的部分突然消失
- jira - 发布与变更之间的区别