使用正規表達式,在數字中加入逗號!


Posted by hoyi-23 on 2021-07-26

var num ="123456444";

console.log(num.replace(/\B(?=(\d{3})+(?!\d))/g, ','))
  1. \B非文字邊界(兩邊一定同時是文字或同時不是文字) ;\b文字邊界
  2. x(?=y) : 符合 X,後面接 Y
  3. \d{3}三個數字
  4. 匹配前一字元 1 至多次
  5. x(?!y) : 符合'x',且後接的不是'y'









Related Posts

[week3] 給自己看的 ES6 筆記

[week3] 給自己看的 ES6 筆記

【Day01】瀏覽器運作原理(客戶端-伺服器(Client/Server)架構)

【Day01】瀏覽器運作原理(客戶端-伺服器(Client/Server)架構)

Git change specific commit message

Git change specific commit message


Comments