用 RegExp 对象 var str = 'blog.csdn.net'; var reStr = "csdn"; var re = new RegExp(reStr, "gi"); alert(str.replace(re, "####")); 用 eval var str = 'blog.csdn.net'; var reStr = "csdn"; alert(str.replace(eval("/" + reStr + "/gi"), "@@@@"));