fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string[] strings = { "File name without 3 digit end.jpg",
  9. "File name with 3 digit 123.gif",
  10. "File name with 3, digit 123.gif",
  11. "Single 123.jpg",
  12. "Single.png",
  13. "File name with ,3 digit 123.gif",
  14. "Single 123.jpg",
  15. "Single 1.jpg",
  16. "Single 123b.gif",
  17. "More words 123b.png"};
  18.  
  19. string pattern = @"^(?!.*[ ]{2})(?!.* ,).*\b(?:\p{L}+|\d{3})\.\w{3}$";
  20. foreach (String s in strings) {
  21. if (Regex.IsMatch(s, pattern)) {
  22. Console.WriteLine("Match: {0}", s);
  23. } else {
  24. Console.WriteLine("No match: {0}", s);
  25. }
  26. }
  27. }
  28. }
Success #stdin #stdout 0.03s 134592KB
stdin
Standard input is empty
stdout
Match: File name without 3 digit end.jpg
Match: File name with 3 digit 123.gif
Match: File name with 3, digit 123.gif
Match: Single 123.jpg
Match: Single.png
No match: File name with ,3 digit 123.gif
No match: Single  123.jpg
No match: Single 1.jpg
No match: Single 123b.gif
No match: More words 123b.png