var word = "trololo"; reg1 = new RegExp("/\\b($" + word + ")\\b/"); reg2 = new RegExp('\\b($trololo)\\b'); alert(reg1.toString()==reg2.toString());