代码之家  ›  专栏  ›  技术社区  ›  William Entriken

javascript:s/digit/“”x该数字/g

  •  0
  • William Entriken  · 技术社区  · 15 年前

    我想匹配一个数字,用这么多空格替换它。这能在少于9行的代码中完成吗?

    例子

    "asnthsnth4nts4h3n" --> "asnthsnth    nts    h   n"
    
    1 回复  |  直到 15 年前
        1
  •  3
  •   Gumbo    15 年前

    试试这个:

    "asnthsnth4nts4h3n".replace(/\d+/g, function($0) { return Array(parseInt($0, 10)+1).join(" "); })