title: Javascript: highlight substring keeping original case but searching in case insensitive mode
body: <p>I'm trying to write a "suggestion search box" and I cannot find a solution that allows to highlight a substring with javascript keeping the original case.</p>
  
  <p>For example if I search for "<code>ca</code>" I search server side in a case insensitive mode and I have the following results:</p>
  
  <p>Calculator</p>
  
  <p>calendar</p>
  
  <p>ESCAPE</p>
  
  <p>I would like to view the search string in all the previous words, so the result should be:</p>
  
  <p><b>Ca</b>lculator</p>
  
  <p><b>ca</b>lendar</p>
  
  <p>ES<b>CA</b>PE</p>
  
  <p>I tried with the following code:</p>
  
  <pre><code>var reg = new RegExp(querystr, 'gi');
  var final_str = 'foo ' + result.replace(reg, '&lt;b&gt;'+querystr+'&lt;/b&gt;');
  $('#'+id).html(final_str);
  </code></pre>
  
  <p>But obviously in this way I loose the original case!</p>
  
  <p>Is there a way to solve this problem?</p>