in reply to matching file names using regex
Other responses have explained how you can use lookbehind to satisfy the check for "not ending in a ~". A more minor point, but worth thinking about, is the fact that since the "one or more digits" can be followed by arbitrary characters, you can replace "one or more digits" with "one digit" in the spec and still retain a functionally equivalent set of constraints::
/^test\d.*(?<!~)\z/
This insight is implicit in a couple of the responses to date, but was not mentioned explicitly in either of them.
In terms of efficiency (which may not be greatly relevant to your particular problem), the main potential problem is that when the filename does end in '~' the regexp engine will do a lot of needless backtracking trying to find some other way to match. That can be avoided with a cut operator:
but is only likely to gain anything if the filenames can be of arbitrary length: on any O/S that limits the length of filenames to something reasonably small it is unlikely to be noticeable./^test\d(?>.*)(?<!~)\z/
Hugo
|
|---|