Let's consider a string named **str*, which is defined as :
let str = "I am looking for the forum";
And a function named highlight which can be used something as :
let f = highlight(str);
console.log(f);
// Expected Result : I am looking <b>for</b> the forum.
I tried to make the function with regex. My try :
const highlight = (val) => {
return val = val.replace(/for/gim, "<b>for</b>");
};
But the output was :
I am looking <b>for</b> the <b>for</b>um
So, how can I solve it ?