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 results = s.Split('_').TakeWhile(x => x.All(char.IsDigit) && x.Length >= 3).ToList(); if (results.Count > 0) Console.WriteLine("Results: {0}", string.Join(", ", results)); else Console.WriteLine("No match: '{0}'", s); } } }