public int compareParts(string a, string b) { Regex pattern = new Regex(@"-(.*)\.(mp4|avi)"); int aEnd = Convert.ToInt32(pattern.Match(a).Groups[1].Value); int bEnd = Convert.ToInt32(pattern.Match(b).Groups[1].Value); return aEnd.CompareTo(bEnd); }