开发者

how to replace special character other than "[" and "]"

开发者 https://www.devze.com 2023-03-22 15:49 出处:网络
I am using regex replace function as to r开发者_运维知识库eplace some special character, but i do not want to replace [ and ] also , how can i do this

I am using regex replace function as to r开发者_运维知识库eplace some special character, but i do not want to replace [ and ] also , how can i do this

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


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


You can use the pattern:

/[^ \w*?:.+\][-]+/g

Make sure to escape the dash or place it last/first in the character class. Replaced a-zA-Z0-9_ with \w.

0

精彩评论

暂无评论...
验证码 换一张
取 消