js判断字符串出现的次数


// 判断substr字符串在str中出现的次数 isIgnore是否忽略大小写!

function countSubstr(str, substr, isIgnore) {
	var count;
	var reg = "";
	if (isIgnore == true) {
		reg = "/" + substr + "/gi";
	} else {
		reg = "/" + substr + "/g";
	}
	reg = eval(reg);
	if (str.match(reg) == null) {
		count = 0;
	} else {
		count = str.match(reg).length;
	}
	return count;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM