Created
July 8, 2019 13:00
-
-
Save thomasJang/661d7b0a6dc41998845693e3f517676f to your computer and use it in GitHub Desktop.
getUniqName 숫자가 증가되는
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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