Regex
Here is a regular expression using the named groups:
S(?<season>\d{1,2})E(?<episode>\d{1,2})
Using
Then you can get the named groups (season and episode) as follows:
string sample = "Stargate.SG-1.S01E08.iNT.DVDRip.XviD-LOCK.avi"; Regex regex = new Regex(@"S(?<season>\d{1,2})E(?<episode>\d{1,2})"); Match match = regex.Match(sample); if (match.Success) { string season = match.Groups["season"].Value; string episode = match.Groups["episode"].Value; Console.WriteLine("Season: " + season + ", Episode: " + episode); } else { Console.WriteLine("No match!"); }
Regular expression explanation
S // match 'S' ( // start of a capture group ?<season> // name of the capture group: season \d{1,2} // match 1 to 2 digits ) // end of the capture group E // match 'E' ( // start of a capture group ?<episode> // name of the capture group: episode \d{1,2} // match 1 to 2 digits ) // end of the capture group
source share