Q:

How to increment only digits of string?

I may have following type strings
A1 or 1A or AB....1 or 1AB......
so how to increment only digits of above type of strings in javascript?
var adminNo = data.Admission_No.slice(-2);
                alert(adminNo);
                var removedNo = data.Admission_No.substring(data.Admission_No.length-1);
                alert(removedNo);

A:

Use the replace method as shown in demo below

    function incrementer(input)
    {
       return input.replace(/\d+/, function(match){ return parseInt(match) + 1 });
    }

    alert(incrementer("A1"));
    alert(incrementer("1A"));

This will find the integer anywhere in the input string and increment it by one.

A:

string.replace(/\d+/, function(n){ return ++n });

