How to remove symbols character from string in js? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

How to remove symbols character from string in js?

Example : let text = "@#wz32r$r&(A)+(6&"

12th Jan 2021, 10:52 AM
sasan zare
sasan zare - avatar
2 Answers
+ 4
const result = str.replace(/\W/g, "")) \W matches any character that isn't included in a-z, A-Z, 0-9 and _, and we are replacing it with "". If you wanna filter out "_" as well, use this regex, /\W|_/g, which means \W or _, find any of these, replace it with "".
12th Jan 2021, 12:20 PM
maf
maf - avatar
+ 3
maf Good. thank you
13th Jan 2021, 11:55 AM
sasan zare
sasan zare - avatar