Ruby で作った。ファイル名を左右反転して処理した。
xy4_12.txt → xy4_012.txt

NUMBERS = ( 0..9 ).to_a.map( &:to_s ) # 0〜9 の文字の配列

str = "xy4_12.txt"
str.reverse! # 左右反転

dot_pos = str.index( "." ) # 前から探す

num_pos = dot_pos + 1
while NUMBERS.include? str[ num_pos ] # 数字なら
num_pos += 1
end

return if num_pos == dot_pos + 1 # 数字が存在しない

nums = str[ dot_pos + 1...num_pos ]
nums.reverse! # 左右反転

zero_num = "%03d" % nums # 3桁、0 埋め
zero_num.reverse! # 左右反転

result = str[ 0..dot_pos ] + zero_num + str[ num_pos..-1 ]
result.reverse! # 左右反転

puts result