in reply to matching file names using regex

I agree with the others that it's cleanest to do it with two separate checks,
if (/^test\d/ && !/~$/){ ...
(Note that the + and the .* don't add anything. Anything that matches the above will also match your regexp, and vice versa (except for your broken / in the middle)). There is a way to do it all in one regexp without lookaheads or lookbehinds, though.
if (/^test\d(?:$|.*[^~]$)/){
Which says that after your first digit, there are either no characters at all, or as many as you like provided the last one isn't a ~.