I need to use python to extract the date from filenames. The date is in the following format:
month-day-year.somefileextension
Examples:
You want to use a capture group.
m = re.search('\b(\d{2}-\d{2}-\d{4})\.', 'derer-10-12-2001.zip')
print m.group(1)
Should print 10-12-2001.
You could get away with a more terse regex, but ensuring that it is preceded by a - and followed by a . provides some minimal protection against double-matches with funky filenames, or malformed filenames that shouldn't match at all.
EDIT: I replaced the initial - with a \b, which matches any border between an alphanumeric and a non-alphanumeric. That way it will match whether there is a hyphen or the beginning of the string preceding the date.