Romi
Romi

Reputation: 4921

Prolem in replacing special characters "@" with a blank using regex replace function

i am using following regex expression to replace

query=query.replace(/[^a-zA-Z 0-9*?:.+-^""_]+/g,'')

But when my query is diam!@#%d i get diam@d after execution of this. it means it is not replacing @ . Why is so ??

Upvotes: 1

Views: 248

Answers (1)

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56162

You need to escape - sign in your regex (- => \-), i.e.: [^a-zA-Z 0-9*?:.+\-^""_]+, therefore it will match: !@#%.

Upvotes: 3

Related Questions