title: Convert uppercase characters back to uppercase after case insensitive regex being applied
body: <p>Here trying to convert uppercase characters back to uppercase after a regex match removes the characters that are uppercase : </p>
  
  <pre><code>var text = 'Test Text';
  var stringToStyle = 'test';                   
  var update = "&lt;span style='color:blue' &gt;" + stringToStyle + "&lt;/span&gt;";
  var regexp = new RegExp(stringToStyle, 'gi');
  var updated = text.replace(regexp, update);
  
  function replaceAt(text , index, character) {
      return text.substr(0, index) + character + text.substr(index+character.length);
  }
  
  function getPositionsOfUppercaseChars(text) {
     var p = [];
  
     var i = text.length;
     while (i--) {
     if(text[i] == text[i].toUpperCase() &amp;&amp; text[i].trim() != ''){
       p.push(i)
     }
  }
  return p;
  }
  
  console.log(updated)
  var positions = getPositionsOfUppercaseChars(text)
  console.log(positions)
  </code></pre>
  
  <p><code>var positions</code> contains the positions of the characters which are to be converted
  to uppercase, wo I will loop through that updated text and replace characters that were previously
  uppercase. But I will need to add an offset to the positions as [5,0] is not correct.</p>
  
  <p>Update : </p>
  
  <p>updated var should be <code>&lt;span style='color:blue' &gt;Test&lt;/span&gt; Text</code> instead of</p>
  
  <pre><code>&lt;span style='color:blue' &gt;test&lt;/span&gt; Text
  </code></pre>
  
  <p>This seems a convulated method of achieving solution, is there  a more elegant way ?</p>
  
  <p><a href="https://plnkr.co/edit/6uO3M8kATQLXvWWVx1Vw?p=preview" rel="nofollow">https://plnkr.co/edit/6uO3M8kATQLXvWWVx1Vw?p=preview</a></p>