str = "IV_04.03.2019-10-56-45_example_c584536f-ab26-40ce-b5b6-386f755ba747_1.csv"
我想提取example
部分和这个c584536f-ab26-40ce-b5b6-386f755ba747
答案 0 :(得分:1)
str = "IV_04.03.2019-10-56-45_example_c584536f-ab26-40ce-b5b6-386f755ba747_1.csv"
s1= str.split("_")[2]
s2= str.split("_")[3]
print (s1)
print (s2)
输出:
example
c584536f-ab26-40ce-b5b6-386f755ba747
答案 1 :(得分:0)
>>> "IV_04.03.2019-10-56-45_example_c584536f-ab26-40ce-b5b6-386f755ba747_1.csv".split("_")[1:-1]
['04.03.2019-10-56-45', 'example', 'c584536f-ab26-40ce-b5b6-386f755ba747']
这将提取所有由下划线包围且内部不包含下划线的子字符串。