If I have the string:
var myStr = \"foo_0_bar_0\";
and I guess we should have a function called getAndIncrementLastNumber(str)
If you want to only get the last number of string, Here is a good way using parseInt()
if(Stringname.substr(-3)==parseInt(Stringname.substr(-3)))
var b=Stringname.substr(-3);
else if(Stringname.substr(-2)==parseInt(Stringname.substr(-2)))
var b=Stringname.substr(-2);
else
var b=Stringname.substr(-1);
It checks and give the correct answer and store it in variable b for 1 digit number and upto 3 digit number. You can make it to any if you got the logic