JSFiddle - React, Tailwind, and code Playground
HTML
Hello Nurse
<p>Goodbye World</p>
<p>Cowboy says: Howdy</p>
<p>Why Hello there!</p>
CSS
span { background: #ddd }
.foo { background: #ff0 }
JavaScript
var regex = /(Hello|Goodbye)/g;
$('*').each(function() {
var $this = $(this);
var text = $this.text();
if (regex.test(text)) {
$this.html(
$this.html().replace(regex, '<span>$1</span>')
);
}
});