-1

I would like to remove every non alphanumeric character from a word, however I rather keep whitespaces. Is it able to somehow join these two cases together?

const word = 'dwa$-I| awd#4'.replace(/\W/g, '');
console.log(word); // whitespace removed =((
aloisdg
  • 22,270
  • 6
  • 85
  • 105
Patrickkx
  • 1,740
  • 7
  • 31
  • 60

1 Answers1

1

You can use [^\w\s] which means you're excluding alpha-numeric and space character from the search.

const word = 'dwa$-I| awd#4'.replace(/[^\w\s]/g, '');
console.log(word);
vrintle
  • 5,501
  • 2
  • 16
  • 46