2024-09-30 02:21:32 发布
网友
如何从字符串text1__text2_text3_text4_text5_text6中提取text1__text2_text3_text4_text5? 我尝试过这样的方法(这会给出我不感兴趣的text6),但无法得到正确的结果:
text1__text2_text3_text4_text5_text6
text1__text2_text3_text4_text5
y = text1__text2_text3_text4_text5_text6 z = y.split('_')[6]
有人能帮忙吗(最好不用正则表达式)
您也可以尝试以下方法:
y = "text1__text2_text3_text4_text5_text6" z = y.rsplit("_", 1)[0]
您正在访问位置,而不是访问直到位置
y = "text1__text2_text3_text4_text5_text6" z = y.split('_')[:6] print("_".join(z))
您也可以尝试以下方法:
您正在访问位置,而不是访问直到位置
相关问题 更多 >
编程相关推荐