I need to replace all chars which are not match with range a-zA-Z_-0-9. So I do val.replace(/[^a-zA-Z_-0-9]/g, \'\') but get error. How can I bit t
a-zA-Z_-0-9
val.replace(/[^a-zA-Z_-0-9]/g, \'\')
You need to escape the "-"
val.replace(/[^a-zA-Z_\-0-9]/g, '')