0

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, "_")
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Max888
  • 3,089
  • 24
  • 55

1 Answers1

2

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, "_"));
Barmar
  • 741,623
  • 53
  • 500
  • 612