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 this? Thanks
a-zA-Z_-0-9
val.replace(/[^a-zA-Z_-0-9]/g, '')
If you want to include the minus sign "-" in the character class, you have to put it into the end of range:
val.replace(/[^a-zA-Z_0-9-]/g, '')
2.1m questions
2.1m answers
60 comments
57.0k users