fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var lst = new List<string> {"70707_70708_70709_display1.jpg",
  12. "70707_Front010.jpg",
  13. "626-this files is tagged.jpg",
  14. "1000x1000_webbanner2.jpg",
  15. "2000 years ago_files.jpg",
  16. "626gamingassets_styleguide.jpg" };
  17. foreach (var s in lst)
  18. {
  19. var results = s.Split('_').TakeWhile(x => x.All(char.IsDigit) && x.Length >= 3).ToList();
  20. if (results.Count > 0)
  21. Console.WriteLine("Results: {0}", string.Join(", ", results));
  22. else
  23. Console.WriteLine("No match: '{0}'", s);
  24. }
  25. }
  26. }
Success #stdin #stdout 0.02s 131648KB
stdin
Standard input is empty
stdout
Results: 70707, 70708, 70709
Results: 70707
No match: '626-this files is tagged.jpg'
No match: '1000x1000_webbanner2.jpg'
No match: '2000 years ago_files.jpg'
No match: '626gamingassets_styleguide.jpg'