Get numbers from end of string JavaScript Regular Expression

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);

Leave a Reply