Skip to content

Instantly share code, notes, and snippets.

@davidwaterston
Created April 20, 2014 10:22
Show Gist options
  • Save davidwaterston/c61479f318074ec45325 to your computer and use it in GitHub Desktop.
Save davidwaterston/c61479f318074ec45325 to your computer and use it in GitHub Desktop.
Javascript: increment the number part of a text field e.g. take a text field containing "abc15" and increment it by 1 to return "abc16", "xyz99" will become "xyz100", etc. Really shouldn't be doing this but if you have to then this will do it. See it in action: http://jsfiddle.net/davidwaterston/a8yXH/
var myString = "abc99";
newString = myString.replace(/\d+$/, function(n) { return ++n });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment