`/\s+/g` is actually pretty similar to what your regex does - as you've made the character class optional, your regular expression can be simplified to `(\s*)*`, which for a string replacement is just the same as `\s*`.

```
"return  test".replace(/return(\s*[\n\r]?)*/g, "return "); // "return test"
```

My regular expression ensures that there is actually at least one newline contained within the whitespace, which makes it more efficient. It doesn't really need the `+` after the character class, but it isn't worth removing. The expression is also shorter and more readable.

```
"return  test".replace(/return\s*[\n\r]+/g, "return "); // "return  test"
```