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) ;
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dC5SZWd1bGFyRXhwcmVzc2lvbnM7CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJc3RyaW5nW10gc3RyaW5ncyA9IHsgIkZpbGUgbmFtZSB3aXRob3V0IDMgZGlnaXQgZW5kLmpwZyIsCiAgICAgICAgICAgICAgICAiRmlsZSBuYW1lIHdpdGggMyBkaWdpdCAxMjMuZ2lmIiwKICAgICAgICAgICAgICAgICJGaWxlIG5hbWUgd2l0aCAzLCBkaWdpdCAxMjMuZ2lmIiwKICAgICAgICAgICAgICAgICJTaW5nbGUgMTIzLmpwZyIsCiAgICAgICAgICAgICAgICAiU2luZ2xlLnBuZyIsCiAgICAgICAgICAgICAgICAiRmlsZSBuYW1lIHdpdGggLDMgZGlnaXQgMTIzLmdpZiIsCiAgICAgICAgICAgICAgICAiU2luZ2xlICAxMjMuanBnIiwKICAgICAgICAgICAgICAgICJTaW5nbGUgMS5qcGciLAogICAgICAgICAgICAgICAgIlNpbmdsZSAxMjNiLmdpZiIsCiAgICAgICAgICAgICAgICAiTW9yZSB3b3JkcyAxMjNiLnBuZyJ9OwoKICAgICAgICAgICAgc3RyaW5nIHBhdHRlcm4gPSBAIl4oPyEuKlsgXXsyfSkoPyEuKiAsKS4qXGIoPzpccHtMfSt8XGR7M30pXC5cd3szfSQiOwogICAgICAgICAgICBmb3JlYWNoIChTdHJpbmcgcyBpbiBzdHJpbmdzKSB7CiAgICAgICAgICAgICAgICBpZiAoUmVnZXguSXNNYXRjaChzLCBwYXR0ZXJuKSkgewogICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCJNYXRjaDogezB9Iiwgcyk7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCJObyBtYXRjaDogezB9Iiwgcyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KCX0KfQ==