How to exclude Special characters " / \ [ ] : ; | = , + * ? < >

Ashwini Jadhao
Giga Guru

Hi 

I have a single line text variable and in that I want to exclude " / \ [ ] : ; | = , + * ? < > all this special character.
Could you please help me with it?What should be the RegEx for it?

 

Thank you!

7 REPLIES 7

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Ashwini Jadhao ,

 

var output = variable.replace(/[^\w\s]/gi, '');// use proper variable name instead of variable

 

Thanks,

Danish

 

 

Hi @Danish Bhairag2 ,

This is not working accepting all special characters " / \ [ ] : ; | = , + * ? < >

@Ashwini Jadhao ,

 

Try either of below:

 

 

You can do it specifying the characters you want to remove:

string = string.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '');

Alternatively, to change all characters except numbers and letters, try:

string = string.replace(/[^a-zA-Z0-9]/g, '');

 

Thanks,

Danish

 

Other characters are excluding but how to exclude Square bracket