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
.
精彩评论