using System; using System.Text.RegularExpressions; public class Test { public static void Main() { string[] strings = { "File name without 3 digit end.jpg", "File name with 3 digit 123.gif", "File name with 3, digit 123.gif", "Single 123.jpg", "Single.png", "File name with ,3 digit 123.gif", "Single 123.jpg", "Single 1.jpg", "Single 123b.gif", "More words 123b.png"}; string pattern = @"^(?!.*[ ]{2})(?!.* ,).*\b(?:\p{L}+|\d{3})\.\w{3}$"; foreach (String s in strings) { if (Regex.IsMatch(s, pattern)) { Console.WriteLine("Match: {0}", s); } else { Console.WriteLine("No match: {0}", s); } } } }