JSFiddle - React, Tailwind, and code Playground

HTML

<p>
this is some text which includes the word foo twice in a row to demo the foo based issue.
</p>

JavaScript

$("p").text(function(index, text) {
return text.replace(/foo/g, 'foo2');
});