I need to use python to extract the date from filenames. The date is in the following format:
month-day-year.somefileextension
Examples:
I think you can extract the date using re.split as follows
$ ipython
In [1]: import re
In [2]: input_file = '10-12-2011.zip'
In [3]: file_split = re.split('(\d{2}-\d{2}-\d{4})', input_file, 1)
In [4]: file_split
Out[4]: ['', '10-12-2011', '.zip']
In [5]: file_split[1]
Out[5]: '10-12-2011'
In [6]: input_file = 'somedatabase-10-04-2011.sql.tar.gz'
In [7]: file_split = re.split('(\d{2}-\d{2}-\d{4})', input_file, 1)
In [8]: file_split
Out[8]: ['somedatabase-', '10-04-2011', '.sql.tar.gz']
In [9]: file_split[1]
Out[9]: '10-04-2011'
I ran the tests with Python 3.6.6, IPython 5.3.0