JSFiddle - React, Tailwind, and code Playground

by David Thomas

HTML

<div id="input"></div>
<div id="result"></div>

CSS

strong {
    font-weight: bold;
}

JavaScript

var string = "This is a Test string.",
    needle = "test",
    re = new RegExp(needle, "gi"),
    newString = string.replace(re, function(a,b){
        return "<strong>" + a + "</strong>";
    });

document.getElementById('input').appendChild(document.createTextNode(string));
document.getElementById('result').innerHTML = newString;