var params = ['John', 10]; var str = 'Hi ?, you are ? age!'; var result = str.replace(/\?/img, function (q, w, e, r) { return params.shift(); }); alert(result);