The Ibu callback solution is pretty clean, but can be further optimized:
x = x.replace(/\b(?:old|whatever|car)\b/gi, function (m0) { return {'old': 'new', 'car': 'boat', 'whatever': 'something'}[m0]; });
This method of using an object literal is quite effective. I changed the regular expression to match whole words, adding word boundaries (so as not to change gold to gnew , etc.).
EDIT: on closer inspection, I see that the jfriend00 solution uses the same technique (and generalizes to be more useful).
source share