JavaScript RegExp match text ignoring HTML

后端 未结 6 1959
时光取名叫无心
时光取名叫无心 2020-12-09 22:28

Is it possible to match \"the dog is really really fat\" in \"The dog is really really fat!\" and add \"

6条回答
  •  盖世英雄少女心
    2020-12-09 22:57

    A simpler way with JQuery would be.

    originalHtml = $("#div").html();
    
        newHtml = originalHtml.replace(new RegExp(keyword + "(?![^<>]*>)", "g"), function(e){
                          return "" + e + "";
                       });
    
    $("#div").html(newHtml);
    

    This works just fine for me.

提交回复
热议问题