Javascript algorithm problem

How can i strip all white spaces and special characters from a string in javascript?

If you only want letters and numbers left? If so, you can use a regular expression like:

var str = 'hello ;;; !!! _" " " goodbye';
var cleanStr = str.replace(/\W|_/g,'');
console.log(cleanStr); // 'hellogoodbye'
1 Like

Thank you.
But can you please explain that replace method working with that regular expression.
This will help me understand it a little better.