I tried package dateutil to extract date part from string. It works good if the exact date included in the string, like:
from dateutil.parser import parse
try:
date = parse(string, fuzzy=True)
print(str(date)[:10])
except ValueError:
print("no date in text")
string = "an example of date:8 march 2019"
output: 2019-03-08
string = "an example of date: 2019/3/8"
output: 2019-03-08
string = "an example of pure string"
output: no date in text
But when a number is included in string instead of date, it goes wrong and considers it as a date:
string = "an example of wrong date: 8"
output: 2022-03-08
My question here is, how can I use this package or similar packages to solve this problem. There are some posts related to extracting dates, like Extract date from string in python, but they have not covered this topic and they work for specific date format.
Your help much appreciated!