繁体   English   中英

如何使用正则表达式从该字符串中捕获时间

[英]How to capture the time from this string with regex

我有这个字符串<td>pending since<br/>Thu 15 Sep 2022 11:43:49 PM UTC </td>我想在正则表达式中捕获“2022 年 9 月 15 日星期四 11:43:49 PM UTC” .

我试过re.compile('<td>pending since<br/>* </td>')无济于事。

我可能会在这里使用正则表达式查找方法来寻找时间戳:

inp = "<td>pending since<br/>Thu 15 Sep 2022 11:43:49 PM UTC </td>"
ts = re.findall(r'\b\w{3} \d{1,2} \w{3} \d{4} \d{2}:\d{2}:\d{2} [AP]M \w+', inp)
print(ts)  # ['Thu 15 Sep 2022 11:43:49 PM UTC']

正则表达式就是这样!

import re

time = re.findall(r'(\d{2}:\d{2}:\d{2})', test_string_goes_here)[0]
print(time)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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