google chrome - javascript replace is replacing nested words -
i creating google chrome extension messes words on whatever website reading, having trouble section of code specifically.
if(math.random() > 0.0){document.body.innerhtml = document.body.innerhtml.replace(/he/g, "it");}
unfortunately working on word inside inside another. example: when comes across word "the", turns 'he' it, unfortunately making says "tit". how can change code avoid this?
.replace(/\bhe\b/g, "it")
\b
matches word boundary, replace single word he
, not he
part of word
Comments
Post a Comment