所以我想使用正则表达式搜索后面没有剧集编号的季节,我有以下列表:
string = ['Fear the walking dead Season 2 Episode 9',
'Veep Season 5',
'Martine Season 2 (unknown number of episodes)',
'New Girl Season 5 Episode 16']
我写了这段代码 re.search('.+? Season [0-9]{1,2}', string, re.I) 但它似乎考虑到了该系列也有剧集编号。 我希望它仅在 Veep 第 5 季
请您参考如下方法:
我建议使用 ^ 和 $ 来匹配从一行的开头到结尾。因此,您可以将正则表达式更改为:
re.search('^(.+?Season\s[0-9]{1,2})$', string, re.I | re.M)
