constructing a regex

bwana
10-01-2009, 09:25 PM
I need to check if a filename has the following format:

Lastname,Firstname text.filetype

where
lastname is made of letters only but may have a hyphen in it
firstname is made of letters only
there is a space after firstname and some text after it
I dont really care what the filetype is

I tried
"Lastname,Firstname text.filetype" Like "[a-zA-Z-]+[,][a-zA-Z]+[ ][.a-zA-Z-]+"

but it evaluates false.

Help?

tpaksu
10-02-2009, 12:45 AM
the space character may be a reason. you can try it with \x40 or \040 instead of [ ]. you can use a regular expressions editor to test your regex pattern. and there's a forum named regexadvice.com which is full of regex examples etc..

bwana
10-04-2009, 09:39 AM
tried this

[A-Za-z-]+[,]\040[,.A-Za-z-]+\040[,.A-Za-z-]+

and although this is a valid expression as tested by various regex apps, it still evaluates as false in VBA word.

stuck

tpaksu
10-05-2009, 03:51 PM
(?+),(?+)\040(?+)\.(?+)

try this. i didnt test it but i think that should work..

Or maybe (.+),(.+)\040(.+)\.(.+)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum