【发布时间】:2021-12-17 05:57:18
【问题描述】:
我不是正则表达式专家,但我是从头开始做的 基于此,我只需要获取数字和字母 [a-e]:
SnnEnn where n represent numbers
SnnEnnl where l = letter [a-e]
nnXnn where n represent numbers
nnXnnl where l = letter [a-e]
但在少数情况下它会失败:
02x01 match '02x01' fail (It should be '02' '01')
03x02a match '03x02'..............groups 'a' fail (It should be '03' '02' 'a')
S03E01 match 'S03E01'.............groups '03' '01' ok
S03E01a match 'S03E01a'............groups 'S03E01' 'a' fail.(It should be '03' '01' 'a')
03x02xxxx match '03X02xxxx' groups '03x02xxxx' fail (it should be just [a-e] and limit to one letter)
S03E01xxx match '03E01xxxx' groups '03e01xxxx' fail (idem)
我正在使用这个正则表达式:
(\d+[x]\d+\w)([a-e])|(\d+[x]\w+)|\bS(?P<Season>\d+)E(?P<Episode>\d+)|(\b[s]\d+[e]\d+)([a-e])
感谢您的帮助
【问题讨论】:
-
嗨,这是一个例子。这意味着它只需要一次抓取“a-e”(我只需要从 a 到 e 的一个字母)
-
几乎对于第二个正则表达式 (5zdiDU/1) ,它不应该像这样抓取字符串:S03x01e 因为 'x' ,它应该始终是 SnnEnn 或 nnXnn