簡體   English   中英

使用RegEx解析季節和劇集信息

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM