我有以下一段代碼來計算一個字符串中的特殊字符數......不知它不會返回我想計數字符串中的特殊字符
var sectionToCheck = $('input').val(); //it could be any kind of string entered in an input field such as "Hello @&% everybody"
var specialChars = /^[[email protected]#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*$/;
var allFoundCharacters = sectionToCheck.match(specialChars);
console.log(allFoundCharacters);
它返回一個空值爲變量allFoundCharacters。請提供任何提示?
是我們應該去猜測什麼''sectionToCheck是? – Alex
你能編輯你的問題並添加一個示例輸入嗎? – Aserre
[在Javascript中計算字符串中字符出現次數]的可能重複(http://stackoverflow.com/questions/881085/count-the-number-of-occurences-of-a-character-in- a-string-in-javascript) –