xem/prettycode — pull request #4 by subzey (2014-05-16 06:50:04+00:00)
Title: 169: replace(/re/g, function(){/*weird stuff*/})

I tried another approach, similar to yours, a single regexp-replace pass.
Results are in reverse order again :)