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 _
.
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 _
.
You can use replace()
with a regex to match consecutive underscores:
'stack__overflow___website'.replace(/_+/g, '_')
var myString = "stack__overflow___website",
myFormattedString = myString.split('__').join('_');