// 判断substr字符串在str中出现的次数 isIgnore是否忽略大小写!
代码语言:javascript复制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;
}