Best way to identify and extract dates from text Python?

前端 未结 7 792
孤城傲影
孤城傲影 2020-12-13 06:10

As part of a larger personal project I\'m working on, I\'m attempting to separate out inline dates from a variety of text sources.

For example, I have a large list o

相关标签:
7条回答
  • 2020-12-13 07:13

    You can use the dateutil module's parse method with the fuzzy option.

    >>> from dateutil.parser import parse
    >>> parse("Central design committee session Tuesday 10/22 6:30 pm", fuzzy=True)
    datetime.datetime(2018, 10, 22, 18, 30)
    >>> parse("There will be another one on December 15th for those who are unable to make it today.", fuzzy=True)
    datetime.datetime(2018, 12, 15, 0, 0)
    >>> parse("Workbook 3 (Minimum Wage): due Wednesday 9/18 11:59pm", fuzzy=True)
    datetime.datetime(2018, 3, 9, 23, 59)
    >>> parse("He will be flying in Sept. 15th.", fuzzy=True)
    datetime.datetime(2018, 9, 15, 0, 0)
    >>> parse("Th 9/19 LAB: Serial encoding (Section 2.2)", fuzzy=True)
    datetime.datetime(2002, 9, 19, 0, 0)
    
    0 讨论(0)
提交回复
热议问题