Q: Replace the special character and space from the string in javascript I have a below string. I need to remove all the special character and space.
var Uid = "s/Information Needed1-s84102-p306";

I tried the below code.It didn't replace the space from the string.
console.log(Uid.replace(/[^\w\s]/gi, '')}")

The output is:-    sInformation Needed1s84102p306
I want the output as sInformationNeeded1s84102p306

A: Simply try using
/[\W_]/g



*

*\W match any non-word character [^a-zA-Z0-9_]
Included _ if you also want to remove it then
Regex

A: You can just use:
console.log(Uid.replace(/\W+/g, '')}")

\W will match any non-word character including a space.
RegEx Demo

A: You can use this expression for your case
var x = "s/Information Needed1-s84102-p306";
console(x.replace(/[^A-Z0-9]/ig, ""));

Here is the working Link
