title: highlight text in a variable using RegExp and span
body: <p>I have a div of text. I want to highlight some of this text stored in a variable using RegExp and span. the text to be highlighted is unknown at run time.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var t = $("#highlightOutput").html(); //sentence
   var s = t.search(hStr);//what shd be replaced
   var query = new RegExp(s, "g");
   console.log(s);
   t = t.replace(query, "&lt;span class='highlight'&gt;"+s+ "&lt;/span&gt;"); //problem is here
   //how to write a regex code to highlight text stored in s.
   $("#highlightOutput").html(t);</code></pre>
  </div>
  </div>
  </p>