我有一个写函数,用于计算字符串中的输出,语言为英语,函数为true,但是有多种其他语言,如阿拉伯语,函数无效
function countWordInString(str, word){
var str = str.toUpperCase();
var count = str.match( new RegExp('\\b' + word.toUpperCase() +'\\b','g') );
return count? count.length : 0;
}
// Language English:
var result = countWordInString('hello world','hello');
console.log(result);// 1 => true
// Language Arabic:
var result = countWordInString('باركود','باركود');
console.log(result);// 0=>false