<script>
  var a="ddddcdddcddsaf";
  function getNum(str,c){
return str.match(new RegExp("c","g")).length;
  }
  alert(getNum(a,"c"))
</script>