-1
我想允許像中文字符等Unicode字符,但不希望允許特殊字符如*,[,],〜並且還有空格,輸入等。Javascript的正則表達式允許unicode,但不允許少數特殊字符,如*,[,],〜等
我想允許像中文字符等Unicode字符,但不希望允許特殊字符如*,[,],〜並且還有空格,輸入等。Javascript的正則表達式允許unicode,但不允許少數特殊字符,如*,[,],〜等
元字符\W
找到包含所有特殊字符的非字元字符。
var str = "{,[]&$pop^%$%%}";
var patt = /\W/g;
var string = str.replace(patt,"");
window.alert(string);
「\ w或\ W只匹配基於ASCII的字符」 - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Regular_expression_and_Unicode_characters –
我該如何提出一個好問題? http://stackoverflow.com/help/how-to-ask –
可能重複的[Javascript + Unicode正則表達式](http://stackoverflow.com/questions/280712/javascript-unicode-regexes) –
也可能重複的[ javascript-unicode-string-chinese-character-but-no-punctuation](http://stackoverflow.com/questions/21109011/javascript-unicode-string-chinese-character-but-no-punctuation) –