Based on your post, you can update the code to use the following example. The below example will replace the last character of a string with a corresponding alphabet number.
var s = "Filename AA";
s = s.replace(/\w([^\w]*)$/, "1");
console.log(s);
var s = "Filename A1";
s = s.replace(/\w([^\w]*)$/, "B");
console.log(s);