首页 > 解决方案 > 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

标签: pythonregex

解决方案


要获取第二个下划线之后的数据(根据问题),您可以将split函数的 maxsplit 参数设置为 2:

str = 'abc_def 1223_this_6729'
str.split('_',2)[2]

回报:

this_6729

由于返回的数组是从零开始的,[2]因此将在两个下划线后获得字符串的其余部分。


推荐阅读