Extract number between brackets and increment
JavaScript
existingId = 'foo_0_bar_0';
newIdOnly = existingId.replace(/foo_0_bar_(\d+)/g, "$1");
alert(newIdOnly);
getAndIncrementLastNumber(existingId);
function getAndIncrementLastNumber(existingId){
alert(existingId);
newId = existingId.replace(/(\d+)/g, function(match, number) {
return parseInt(number) + 1;
});
alert(newId);
}