gpt4 book ai didi

python : Using regex to get episode

转载 作者:行者123 更新时间:2023-12-04 15:02:31 27 4
gpt4 key购买 nike

此代码适用于此 fileName 除外:

Terkel in Trouble 2004


它应该返回“null”而不是匹配返回“e 200”
因为:
      e|x|episode|Ep|^        
    (\d{2,3})                 
我怎样才能防止这种情况?
def getEpisode(filename):
match = re.search(
r'''(?ix)
(?:
e|x|episode|Ep|^
)
\s*
(\d{2,3})
''', filename)
if match:
print (match)
return match.group(1)


**EDIT:**
test = (
"0x01 GdG LO Star Lord Part 1", #1
"S01E01 GdG Verso Nowhere", #2
"Wacky Races Episode 20 X264 Ac3", #3
"Terkel in Trouble 2004", #4 return None, it's ok
"Yu Yu Hakusho Ep 100 secret", #5
"Kakegurui S1 Ep11 La donna che scommette", #6
"Kakegurui S1 Ep12 La donna che gioca", #7
"ep 01 wolf's rain", #8
"Toradora! 08" #9
)

最佳答案

尝试使用字边界 \b正则表达式更新

\b(?:e(?:p(?:isode)?)?|0x|S\d\dE)?\s*?(\d{2,3})\b
结果
1 ->  0x01
2 -> S01E01
3 -> Episode 20
4 ->
5 -> Ep 100
6 -> Ep11
7 -> Ep12
8 -> ep 01
9 -> 08

关于 python : Using regex to get episode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66727867/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com