Skip to content

Instantly share code, notes, and snippets.

@thomasJang
Created July 8, 2019 13:00
Show Gist options
  • Save thomasJang/661d7b0a6dc41998845693e3f517676f to your computer and use it in GitHub Desktop.
Save thomasJang/661d7b0a6dc41998845693e3f517676f to your computer and use it in GitHub Desktop.
getUniqName 숫자가 증가되는
function getUniqName(name) {
const re = /\d+(?=\D+$)|\d+$/;
if (re.test(name)) {
return name.replace(re, function(match) {
return ('' + (Number(match) + 1)).padStart(match.length, '0');
});
} else {
return `${name}_1`;
}
}
console.log(getUniqName('장기영-ABCE-001'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment