another alteration to fix problems with apostrophes var $s = function(s) { p = s.replace(/'/g, '"').replace(/#{/g, "' + ").replace(/}/g, " + '"); p = "'" + p + "'"; return eval(p); }
this replaces " with ' in your input string, it works best if you use " " to signify the edge of your string and ' inside : e.g. $s("#{a}'s cat is #{b} years old") ==> Jonah's cat is 30 years old