the space is necessary. Replacing `return\nthis` without the space in the replacement generates broken code. \s indeed matches \r and \n, but your regexp already uses them, I assumed for clarity, in which case the ()* wrapper   adds to that. If we just want to go with \s covering all whitespace tokens, we can simplify it to `/\s+/g`