title: javascript replace all with case insensitive and keeping correct case in original string
body: <p>My problem is i want to do something like this:</p>
  
  <p><code>Javascript vaja =&gt; &lt;b&gt;Ja&lt;/b&gt;vascript va&lt;b&gt;ja&lt;/b&gt;</code>
  i.e i have a query string(ja) and i want to replace all the occurances(case insensitive) of that query string in a bigger string (Javascript vaja).</p>
  
  <p>The closest solution i have right now is:</p>
  
  <p><code>"Javascript vaja".replace(/ja/gi, '&lt;b&gt;ja&lt;/b&gt;');</code> </p>
  
  <p>which gives me:</p>
  
  <p><code>"&lt;b&gt;ja&lt;/b&gt;vascript va&lt;b&gt;ja&lt;/b&gt;"</code></p>
  
  <p>but what i need is:</p>
  
  <p><code>Javascript vaja =&gt; &lt;b&gt;Ja&lt;/b&gt;vascript va&lt;b&gt;ja&lt;/b&gt;</code></p>
  
  <p>one solution that i have in mind is to keep the indexes of upcase letters before replacement and then re replace them. But that is way too hacky.
  I am pretty sure i am not the first one trying this and pretty sure there is some elegant and simpler solution hidden somewhere.</p>