Python regex split without empty string

后端 未结 5 1520
栀梦
栀梦 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:20

    I'm no Python expert but maybe you could just remove the empty strings from your list?

    str_list = re.split('^[0-9]+_[LU]_|-|\.txt$', f)
    time_info = filter(None, str_list)
    

提交回复
热议问题