0

how do i remove certain characters from a string

so I have a string that i need to remove special characters from like {}:">?!@#$%^&*()_ how can i do this

30th Jan 2020, 4:26 PM
Ben Carvalho
Ben Carvalho - avatar
2 Respostas
+ 4
Using regular expression https://stackoverflow.com/questions/4374822/remove-all-special-characters-with-regexp Example: let str = 'he//o w&&rld' var output = str.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, ''); This is a bit messy so I'm sure you can figure out better solution Maybe it's better to only accept letters & numbers? str.replace["^A-Za-z"]
30th Jan 2020, 4:39 PM
HNNX 🐿
HNNX 🐿 - avatar
+ 1
what I think ill do is HNNX's answer thanks :)
30th Jan 2020, 6:56 PM
Ben Carvalho
Ben Carvalho - avatar