var n=str.replace(/blue/g,"red");
This replaces blue in the string to red.
But I get only string blue as a string to replace. I need to replace all instances of it case insensitive as well. I am not able to keep blue in a variable and then use it in replace. I tried this. But it wont work.
var i = blue;
var rep = "/"+i+"/gi";
var n=str.replace(rep,"red");