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.
replace api を使用して 201656 (任意の 6 桁の数字) を 20-16-56 に変換するにはどうすればよいですか?
これはあなたのニーズに合うでしょう:
"124578".replace(/(.{2})(?!$)/g,"$1-")
デモ
'201656'.replace(/(?!\d{2}$)\d{2}/g, '$&-')