如何使用 python 获取日期后的文本?

How do I get the text after a date using python?

我有一个字符串,其中可能包含某种形式的日期。

我想提取刚好在该日期之后出现的部分。

例如:

s = "The term starts on Jan 1, 2000 and terminates on"

应该return

output = "and terminates on"

我的建议是

s[s.find(', 2') + 6]

一种方法。

s = "The term starts on Jan 1, 2000 and terminates on"
ss = s.split('0')
output = ss[-1]

尝试将 dateutilfuzzy_with_tokens=True

结合使用

例如:

from dateutil.parser import parse
s = "The term starts on Jan 1, 2000 and terminates on"
print(parse(s, fuzzy_with_tokens=True))

输出:

(datetime.datetime(2000, 1, 1, 0, 0), ('The term starts on ', ' ', ' ', 'and terminates on'))