For what it's worth, you can also use eval to use variables in replace.
string.replace(eval("/"+somevar+"/gi"),"replacementString")
Code:
alert(
(function(){
var rvar = " simple";
return "This is a simple example with a simple string".replace(eval("/"+rvar+"/gi"),"n evaled")
})()
);