Python regex split without empty string

后端 未结 5 1518
栀梦
栀梦 2020-12-03 09:54

I have the following file names that exhibit this pattern:

000014_L_20111007T084734-20111008T023142.txt
000014_U_20111007T084734-20111008T023142.txt
...
         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 10:41

    If the timestamps are always after the second _ then you can use str.split and str.strip:

    >>> strs = "000014_L_20111007T084734-20111008T023142.txt"
    >>> strs.strip(".txt").split("_",2)[-1].split("-")
    ['20111007T084734', '20111008T023142']
    

提交回复
热议问题