实际工作代码
$("#encontrar").click(function(){
var palabra = $("#palabra").val();
var codigo = $("#codigo").val();
var str = codigo, strToMatch = palabra,
re = new RegExp(palabra,'ig');
var numero = str.match(re).length;
alert(numero);
})
答案 0 :(得分:0)
试试这个正则表达式
var str = "Hey hello hi history hey", strToMatch = 'hey',
re = new RegExp('hey','ig');
str.match(re).length;