You could use a regular expression using Python's re
module:
import re
if re.match(r'^.*_v\d+\.txt$', filename):
pass # valid
else:
pass # invalid
Let's pick the regular expression apart:
^
matches the start of the string.*
matches anything_v
matches_v
literally\d+
matches one or more digits\.txt
matches.txt
literally$
matches the end of the string