[英]Regex to capture episode number
What is wrong with the following regular expression I have:我的以下正则表达式有什么问题:
s = "s4, ep2 -- The one"
>>> re.search(r'(Episode|Ep?\.?)?\s?(\d{0,})', s, re.IGNORECASE).group(2)
''
I am trying to capture the 2
from the "S4, Ep2"
.我正在尝试从"S4, Ep2"
捕获2
。 I thought the Ep?\\.?\\s?d{0,}
would capture it but it seems like I'm missing something.我以为Ep?\\.?\\s?d{0,}
会捕获它,但似乎我遗漏了一些东西。
Here are other example inputs that might be entered:以下是可能输入的其他示例输入:
Episode 2
Ep. 2
E. 2
2
Season 4, E 2 -- Hello
All of the above should come out as "2"以上所有内容都应显示为“2”
This version is working.这个版本正在运行。 We can try matching on Episode
, Ep
, or just E
, followed by an optional dot and/or space.我们可以尝试在Episode
、 Ep
或E
上进行匹配,后跟可选的点和/或空格。 Then, capture an episode number.然后,捕获剧集编号。
s = "s4, ep2 -- The one"
print(re.search(r'(?:Season \d+,\s+)?(?:Episode|Ep|E)?\.?\s?(\d{0,})',
s, re.IGNORECASE).group(1))
2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.