I do not know a library with the functionality you ask but it isn't that difficult to write a function which will return the matching formats on given string.
Although this does not overcome the problem of a string being matched in more than one format.
Here is a sample for some static common formats on numeric based date.
date_formats = ["%Y-%m-%d", "%d-%m-%Y", "%m-%d-%Y", "%Y/%m/%d", "%d/%m/%Y", "%m/%d/%Y", "%Y.%m.%d", "%d.%m.%Y", "%m.%d.%Y", "%c", "%x"]
def string_to_date(str):
match = []
for fmt in date_formats:
try:
datetime.strptime(str, fmt)
except ValueError as e:
print(e)
continue
match.append(fmt)
return match
And some representative output:
print(string_to_date("11.12.2015")) # ['%d.%m.%Y', '%m.%d.%Y']
print(string_to_date("21/12/2015")) # ['%d/%m/%Y']
Of course you can write code in order to build dynamically your formats but in that case i think, it's getting too broad.
In case you would go for a dynamic approach i would suggest to catch the possible delimiter first in your script and then try to build the format.