I need to count the number of occurrences of a character in a string.
For example, suppose my string contains:
var mainStr = \"str1,str2,str3,str4\";
My solution:
function countOcurrences(str, value){ var regExp = new RegExp(value, "gi"); return str.match(regExp) ? str.match(regExp).length : 0; }