爲什麼這個正則表達式不正確地解析字符串「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);
你是完全正確的,那是我的錯誤。這是固定模式:'var pattern = @「S \ w * \ s *(\ d \ d)\ s * E \ w * \ s *(\ d \ d)」;'。 –