Regex to find word on page including inside tags

后端 未结 4 633
-上瘾入骨i
-上瘾入骨i 2021-01-28 15:13

Thanks to Chetan Sastry I have this Regex code to parse my page for a list of words and add the TM to them.

var wordList = [\"jQuery UI\", \"jQuery\", \"is\"];
v         


        
4条回答
  •  孤独总比滥情好
    2021-01-28 16:03

    If you are only trying to replace words within a link then the following should work:

    var wordList = ["jQuery UI", "jQuery", "is"];
    var regExp = new RegExp("\\b" + wordList.join("\\b|\\b") + "\\b", "g");
    var $elem = $("#divWithText a");
    $elem.html($elem.html().replace(regExp, "$&™"));
    

提交回复
热议问题