[英]Python Regex text and time same line
I'm trying to grab a NHL schedule, its format is: 我正在尝试获取NHL时间表,其格式为:
tabindex="1" >Game: Wild at Blackhawks 8:00PM ET</a>
I can grab it like: 我可以像这样抓住它:
tabindex="1" >Game: (.)(.*?) at (.)(.*?)</a>
That Grabs the first letter of the team names then the rest (coloring purposes) plus the start time. 这样就可以抓住团队名称的第一个字母,然后是其余的(着色目的)加上开始时间。
I have tried variations of the following from posts I've found in here: 我尝试从以下文章中找到以下内容的变体:
(?:(?:(\d+):)?(\d+):)?(.+?)$ (ET|PT)
However I would like to grab the Time, AM/PM, and ET separately for coloring as well. 但是,我也想分别获取时间,AM / PM和ET进行着色。 What stumps me is to figure out how to grab Text and Date following eachother in a line.
让我感到困扰的是弄清楚如何在一行中紧随彼此而获取文本和日期。 Any help would be appreciated, Thanks
任何帮助,将不胜感激,谢谢
How about this: 这个怎么样:
>>> s = 'tabindex="1" >Game: Wild at Blackhawks 8:00PM ET</a>'
>>> m = re.search(r'tabindex="1" >Game: (\w)(\w*?) at (\w)(\w*?) (\d+:\d\d)(\w\w) (\w\w)</a>', s)
>>> m.groups(0)
('W', 'ild', 'B', 'lackhawks', '8:00', 'PM', 'ET')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.