I am trying to replace commas, full stops, hyphens, and spaces with underscores. I have tried the below but get the error Range out of order in character class
'Helo,._cool '.replace(/[,.- ]/g, "_")
I am trying to replace commas, full stops, hyphens, and spaces with underscores. I have tried the below but get the error Range out of order in character class
'Helo,._cool '.replace(/[,.- ]/g, "_")
You need to escape the -
character, because it's used to specify a range of characters like 0-9
or a-z
.
console.log('Helo,._cool '.replace(/[,.\- ]/g, "_"));