0

I have a write function for counting from output in a string, with language English, true function, but with multiple other languages like Arabic language, invalid function

    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
Ba Trần
  • 43
  • 3

0 Answers0