If you know the filename format will not change, you don't need re
:
filename = 'myfile-20101019.txt'
basename, extension = filename.rsplit('.', 1)
firstpart, date = basename.rsplit('-', 1)
In : firstpart, date, extension
Out: ('myfile', '20101019', 'txt')
or just without extension:
firstpart, date = filename.rsplit('.', 1)[0].rsplit('-', 1)
# ['myfile', '20101019']
Works with more complicated filenames too:
filename = 'more.complicated-filename-20101004.txt'
firstpart, date = filename.rsplit('.', 1)[0].rsplit('-', 1)
# ['more.complicated-filename', '20101004']
Or, just to split the extension even more nicely:
import os
filename = 'more.complicated-filename-20101004.txt'
firstpart, date = os.path.splitext(filename)[0].rsplit('-', 1)
# ['more.complicated-filename', '20101004']