Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

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