highlightText
by evgkch
JavaScript
var myString = "Hello 1 word. Sentence number 2."
const highlightText = (str) => (words) => {
let re = new RegExp(words, 'i');
return (re.test(str))
? str.replace(re, '<h>$&</h>')
: str;
}
console.log(highlightText(myString)('el'))