I want to use HTML and JS to implement a function that can highlight all the words which included in a negative word lexicon in a text. Here is my JS code:
{% for neg in negative_words_list %}
var m=document.getElementById("a")
m.innerHTML = m.innerHTML.replace(/{{neg}}/ig,"<font color=red>$&</font>");
{% endfor %}
But when I run the code, I found parts of some words are also highlighted, because these parts just match some negative words in the lexicon. Just like this picture ("hired", "begins", and "stumped"): enter image description here
I just want my program to highlight the whole words instead of a part of a word. What should I do?