tags:

views:

32

answers:

1

I 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"
+2  A: 

Try this:

"asnthsnth4nts4h3n".replace(/\d+/g, function($0) { return Array(parseInt($0, 10)+1).join(" "); })
Gumbo
Awesome. I didn't know you could do cool perl stuff like that! Thanks.
Full Decent