For example, suppose I have the following text:
"Constants cons are CONTAGIOUS"
I want all the "cons" replaced irrespective of case, but preserving case on the replace.
For example, suppose I want to put bold tags around them, I would want the output to be:
"<b>Con</b>stants <b>cons</b> are <b>CON</b>TAGIOUS"
In JavaScript, I have tried:
var re = new RegExp("con", 'ig');
var newText = text.replace(re,"<b>" + "con" + "</b>");
This does a case insensitive search but I lose the case on the replace. Is there a way to preserve case on the replace?