How to remove double underscore using JavaScript

javascript, replace, string

Solution

You can use `replace()` with a regex to match consecutive underscores:

'stack__overflow___website'.replace(/_+/g, '_')

Problem

How do I remove double or multiple underscores in a string using JavaScript? E.g. `stack__overflow___website` I will need to eliminate the `__` and replace it with a single `_`.

Original source

Related problems