I want to check if the input line should follow the pattern, and if it extracts information from it.
My model is like this one Episode 000 (Season 00). 00s are numbers that can range from 0 to 9. Now I want to check if this input matches Episode 094 (Season 02)this pattern, and therefore it needs to extract these two numbers, so I get two integer variables 94and 2:
string latestFile = "Episode 094 (Season 02)";
if (!Regex.IsMatch(latestFile, @"^(Episode)\s[0-9][0-9][0-9]\s\((Season)\s[0-9][0-9]\)$"))
return
int Episode = Int32.Parse(Regex.Match(latestFile, @"\d+").Value);
int Season = Int32.Parse(Regex.Match(latestFile, @"\d+").Value);
The first part, where I check to see if the common string works with the template, but I think it can be improved. In the second part, where I actually extract the numbers that I am stuck with and what I wrote above obviously does not work, because it captures all the digits from the string. Therefore, if any of you can help me figure out how to extract only three characters after Episodeand two characters after, Seasonthat would be great.
source
share