JavaScript implementaion of ruby's gsub