-1

上のタイトルの通り、javascriptのRegExp()関数でこの2文字をパターンにする方法が知りたいです。
私はその前にバックラッシュを入れようとしました。別の特殊文字では機能しますが、これら 2 つでは機能しません。
これは私の現在のパターンです:

var disallowed_char=new RegExp("[~!@#$%\^&*()\{\}\\\|\'\"\;\:\.\,\>\<\=\_\+\`\?\/\-]");
// It works

[charをパターンの一部にしたい]ので、これらをパターンに追加します。

var disallowed_char=new RegExp("[~!@#$%\^&*()\{\}\\\|\'\"\;\:\.\,\>\<\=\_\+\`\?\/\[\]\-]");
//I put it before - (minus) char, 
//because minus char won't work if placed at the first or in the middle of the pattern
//note : I have tried to put "[" and "]" in other place
//but still doesn't work

私が望むようにする方法はありますか?

4

1 に答える 1