开发者

Javascript: s/digit/" " x that digit/g

I 开发者_StackOverflow社区would like to match a digit and replace it with that many spaces. Can this be done in less than 9 lines of code?

Example

"asnthsnth4nts4h3n" --> "asnthsnth    nts    h   n"


Try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜