[英]Regex issue parsing Season / Episode pattern
為什么此正則表達式模式無法正確解析字符串“ Season 02 Episode 01”?
例如,這不是匹配項:
var fileName = "Its Always Sunny in Philadelphia Season 02 Episode 01 - Charlie Gets Crippled.avi"
// Regex explanation:
// Starts with "S" and can contain more letters, can continue with space, then contains two numbers.
// Then starts with "E" again and can contain more letters, can continue with space, then contains two numbers.
var pattern = @"S\w?\s?(\d\d)\s?E\w?\s?(\d\d)";
var regex = new Regex(pattern, RegexOptions.IgnoreCase);
var match = regex.Match(fileName);
使用*
代替?
?
是0或1次。 *
表示0次或多次。
以“ S”開頭,可以包含更多字母[...]
你的意思是+
,不是?
。
var pattern = @"S\w+\s+(\d+)\s+E\w+\s+(\d+)";
請注意,此正則表達式非常明確。 當心誤報。 我建議使表達式更具體。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.