That's pattern is way longer than it need to be,have you look into the basic regex before?
Quick test.
I like pendulum the best(and most correct) date tool that's is made for Python in the latest years.
Quick test.
>>> import re >>> >>> text = "foo 2019-06-12.123 bar" >>> r = re.search(r"\d{4}-\d{2}-\d{2}\.\d{3}", text).group() >>> r '2019-06-12.123'If it's a common valid date format can parse with dateutil as mention bye @Gribouillis
I like pendulum the best(and most correct) date tool that's is made for Python in the latest years.
>>> import pendulum >>> >>> d = '2019-06-12' >>> pendulum.parse(d) DateTime(2019, 6, 12, 0, 0, 0, tzinfo=Timezone('UTC')It will fail on auto parse with
2019-06-12.123
,but can write a own with formatter.>>> import pendulum >>> >>> dt = pendulum.from_format('2019-06-12.123', 'YYYY-DD-MM.hms') >>> dt DateTime(2019, 12, 6, 1, 2, 3, tzinfo=Timezone('UTC'))As you see pendulum dos this way better than strptime().