Here is a regular expression that will match the numbers at the end of the string and return an array with the match it made.
var mystringwithnumbersatend="mycoolname32";
var thenumbersmatch = mystringwithnumbersatend.match(/\d+$/);
if(thenumbersmatch){number=thenumbersmatch [0];}
To use the number in a calculation, make sure to parse it:
number=parseInt(number, 10);