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
3 Antworten
+ 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"]
+ 1
what I think ill do is HNNX's answer thanks :)