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


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

[筆記] HTTP 協定

[筆記] HTTP 協定

[Golang] strconv

[Golang] strconv

Laptop Repair Singapore: Navigating the Maze of Technical Glitches with Expert Solutions

Laptop Repair Singapore: Navigating the Maze of Technical Glitches with Expert Solutions


Comments