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(" "); })
精彩评论