Using python, I need to extract an ID and Date from this filename:
export-foobar-54321-2015_02_18_23_30_00.csv.gz
Where:
ID = 54321
Date = 2015_02_18
So far, I can match the file name with this regular expression:
export-foobar-[0-9]{5}\-[0-9]{4}_[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{2}.csv.gz
What I'd like as my final print out put would be:
ID = 54321
Date =02-18-2015
Being new to python, I tried the following, however, im not sure how to print what I need. I have this so far:
>>> import re
>>> filename='export-generic-33605-2015_02_18_23_30_00.csv.gz'
>>> matches=re.search("export-foobar-[0-9]{5}\-[0-9]{4}_[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{2}.csv.gz",filename)
>>> print(matches)
<_sre.SRE_Match object at 0x7f2ee3616718>
If I could please get some help in printing out what I need and then customizing the print to match the date MM-DD-YYYY correctly would be appreciated.