Javascript 正则模板替换代码

function sub(str,data) {
    return str
        .replace(/{(.*?)}/igm,function($,$1) {
            return data[$1]?data[$1]:$;
        });
}
var json=[
    {
        name:"Jim",
        blog:"jim.com"
    },
    {
        name:"Tom",
        blog:"tom.com"
    },
    {
        name:"Sam",
        blog:"saam.com"
    },
];

var tpl='{name} (blog: {blog})',
    html = '';
for(var i = 0;i<json.length;i++) {
    html += sub(tpl,json[i]);
}

console.log(html);
2014-05-24 00:0012