JSFiddle - React, Tailwind, and code Playground

HTML

<div id="outer">A simple tool to store and display texts longer than a few lines.
The search button <div id="xyz">will highlight all</div> the words matching the name of objects that are members of the classes listed in searchedClasses, 
    itself a member of the KeySet class. The highlighted words are hypertext.</div>

JavaScript

// textContent for w3 compliance, innerText for IE
var full, result,
    txt = "textContent" in document.body ? "textContent" : "innerText",
    out = document.getElementById("outer"),
    xyz = document.getElementById("xyz"),
    old = xyz[txt];

// wrap the inner text with something we can easily search for:
xyz[txt] = "||||" + xyz[txt] + "||||";

// Get the whole text, change the DOM text back to what it was
full = out[txt];
xyz[txt] = old;

// Find the text with our markers and surrounding text:
result = /.{0,10}\|{4}.*?\|{4}.{0,10}/.exec(full);

alert(result[0]);

result = result[0].replace(/\|{4}/g, "");

alert(result);