[英]Parsing season and episode information using RegEx
我正在嘗試使用RegEx
為季節和情節信息RegEx
。 我負責處理同一文件中有多個季節的特殊情況:
文件名示例:
Defiance.S03E01+E02.Custom.DKSubs.720p.HDTV.x264-NGSerier
Sofar我寫了這個正則表達式:
S(?<season>\d{1,2})|E(\d{1,2}){1,}
它給了我季節和情節清單。 但是問題在於,這種模式也會匹配
Defiance.S03E01-E03.Custom.DKSubs.720p.HDTV.x264-NGSerier
和
Defiance.S03E01E02E03.Custom.DKSubs.720p.HDTV.x264-NGSerier
那么我怎么知道情節列表是否用-
或+
或什么都不分開?
如果有任何差異,請注意該表達式將在ac#程序中使用。
您可以使用此正則表達式:
S\\d{1,2}([-+]?E\\d{1,2})+
代碼:
void Main()
{
Regex regex = new Regex(@"S\d{1,2}([-+]?E\d{1,2})+");
Match match = regex.Match("Defiance.S03E01E02E03.Custom.DKSubs.720p.HDTV.x264-NGSerier");
if (match.Success)
{
Console.WriteLine(match.Value);
}
match = regex.Match("Defiance.S03E01-E03.Custom.DKSubs.720p.HDTV.x264-NGSerier");
if (match.Success)
{
Console.WriteLine(match.Value);
}
match = regex.Match("Defiance.S03E01E02E03.Custom.DKSubs.720p.HDTV.x264-NGSerier");
if (match.Success)
{
Console.WriteLine(match.Value);
}
}
3結果:
S03E01E02E03
S03E01-E03
S03E01E02E03
+
也可以使用
編輯:您的評論后:
使用此正則表達式:
(?<season>S\d{1,2})((?<sep>[-+]?)(?<epi>E\d{1,2}))+
你現在可以看到 :
看這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.