[英]Extracting time from text using REGEX giving output as NONE
我有這樣的文字。
string = '\n# From r Wed Oct 30 21:41:56 2002\n# Return-Path: <james_ngola2002@maktoob.com>\n# X-Sieve: cmu-sieve 2.0\nReturn-Path: <james_ngola2002@maktoob.com>\n# Message-Id: <200210310241.g9V2fNm6028281@cs.CU>\n# From: "MR. JAMES NGOLA." <james_ngola2002@maktoob.com>\n# Reply-To: james_ngola2002@maktoob.com\n# To: webmaster@aclweb.org\n# Date: Thu, 31 Oct 2002 02:38:20 +0000'
我想從這個字符串中提取日期和時間。 我已經盡力了。
import re
regex = re.compile(r'\b\d{4}[-/]\d{2}[-/]\d{2}\s\d{2}:\d{2}:\d{2}\s[-+]\d{4}\b')
regex.findall(string)
output
[]
預期 output。
['02:38:20', '21:41:56']
注意:使用 REGEX 問題提取日期和時間在互聯網上有各種答案。 我已經嘗試了每一個建議。 但是,我仍然沒有得到 output。 我猜字符串有問題? 你們能幫我看看我在做什么錯嗎?
regex = re.compile(r'\b\d{2}:\d{2}:\d{2}\b')
regex.findall(string)
output
['21:41:56', '02:38:20']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.