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


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

Ajax/ JSONP/ CORS 相關筆記

Ajax/ JSONP/ CORS 相關筆記

深入學習 lsd-slam - 3

深入學習 lsd-slam - 3

JS30 days

JS30 days


Comments