2

In Python, Is there a way to definitively check if a string contains a date.? It would be preferable if it could catch any date format, but, if not, could it catch the %B-%w-%Y format.

smci
  • 32,567
  • 20
  • 113
  • 146
ceradon
  • 73
  • 1
  • 8

1 Answers1

1

You can use dateutil.parser module which will parse any human readable date format for you from a string.

http://labix.org/python-dateutil#head-a23e8ae0a661d77b89dfb3476f85b26f0b30349c

jaho
  • 4,852
  • 6
  • 40
  • 66
  • Note, however, that this method has a lot of false positives, e.g: `"4"` will be considered a date. Also, dates with extra content are not parsed, e.g: `"Today is 26/03/19"` is not considered a date. – Carlos Roldán Mar 27 '19 at 01:31