I want to change the color of keywords of given sentence. So far I have this:
const engSample = document.querySelector(".eng-sample"); engSample.innerHTML = getColoredEngSample("I have been walking"); function getColoredEngSample(text) { let result; const keywords = ["have", "has", "been", "ing"]; keywords.forEach(key => { result = text.replace(key, `<span class='bold-sample'>${key}</span>`); }); return result; } .bold-sample { color: #ff3c00; } <p class="eng-sample"></p> As you see only ing color changes and the rest of keywords not.
How can I fix this or achieve the same result using regex?