简体   繁体   中英

Extracting time from text using REGEX giving output as NONE

I've a text like this.

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'

I want to extract date & time from this string. I've worked upto.

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

[]

Expected output.

['02:38:20', '21:41:56']

Note: Extracting date & times using REGEX questions have various answers all over the internet. I've tried every suggestions. But, Still I'm getting nothing as output. I guess problem with string?. Can you guys help me what's wrong I'm doing?

regex = re.compile(r'\b\d{2}:\d{2}:\d{2}\b')
regex.findall(string)

output

['21:41:56', '02:38:20']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM