using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var lst = new List {"70707_70708_70709_display1.jpg", "70707_Front010.jpg", "626-this files is tagged.jpg", "1000x1000_webbanner2.jpg", "2000 years ago_files.jpg", "626gamingassets_styleguide.jpg" }; foreach (var s in lst) { var mcoll = Regex.Matches(s, @"^(?\d{3,})(?:_(?\d{3,}))*_") .Cast() .SelectMany(m => m.Groups["v"].Captures.Cast().Select(c => c.Value)) .ToList(); if (mcoll.Count > 0) Console.WriteLine("Results: {0}", string.Join(", ", mcoll)); else Console.WriteLine("No match: '{0}'", s); } } }