簡體   English   中英

如何使用python在約會后獲取文本?

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

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

我想提取該日期之后出現的部分。

例如:

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

應該回來

output = "and terminates on"

我的建議是

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

嘗試將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'))

一種方法來做到這一點。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM