Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用替换 api 将 201656(可以是任何 6 位数字)转换为 20-16-56
这将满足您的需求:
"124578".replace(/(.{2})(?!$)/g,"$1-")
演示
'201656'.replace(/(?!\d{2}$)\d{2}/g, '$&-')