JSFiddle - React, Tailwind, and code Playground

HTML

<p id = "str">How much wood could a wood chip chop</p>
<br>
<input type = "text" value = "" id = "txt1"/>
<button id="searchButton"> Search </button>

<p id="demo">Display the result here.</p>

JavaScript

$("#searchButton").click(function() {
  var myString = document.getElementById("str").innerHTML;
  var myWord = document.getElementById("txt1").value;
  var myPattern = new RegExp('(\\w*'+myWord+'\\w*)','gi');

  var matches = myString.match(myPattern);
   
  if (matches === null)
  {
      document.getElementById("demo").innerHTML = "No results";
      return;
  }
    
  document.getElementById("demo").innerHTML = matches + " - " +  matches.length + " result(s) found.";
});