JSFiddle - React, Tailwind, and code Playground
HTML
<p>123 hello 123</p>
<p>Hello</p>
<p>neither</p>
<p>Goodbye</p>
<p>123 goodbye 123</p>
CSS
.blue{ color: #000080}
.red{ color: #c00}
JavaScript
$("p").each(function() {
if ($(this).children().length == 0) {
var txt = $(this).text();
var blue = /hello/i.exec(txt);
var red = /goodby/i.exec(txt);
if (blue) {
$(this).html(txt.replace(/hello/i, '<span class="blue">' + blue + '</span>'));
} else if (red) {
$(this).html(txt.replace(/goodbye/i, '<span class="red">' + red + '</span>'));
}
}
});