How to exclude Special characters " / \ [ ] : ; | = , + * ? < >
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 09:18 PM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 09:24 PM
Hi @Ashwini Jadhao ,
var output = variable.replace(/[^\w\s]/gi, '');// use proper variable name instead of variable
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 09:38 PM
Hi @Danish Bhairag2 ,
This is not working accepting all special characters " / \ [ ] : ; | = , + * ? < >
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 09:51 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 10:55 PM
Other characters are excluding but how to exclude Square bracket