var t1 = { id: '1000' ,name: 'mp' ,text: '主产品' ,seq: 1 ,child:[{ id: '1001' ,text: '列1' ,name: 'c1' ,type: 'INTEGER' ,seq: 1 },{ id: '1002' ,text: '列2' ,name: 'c2' ,type: 'STRING' ,seq: 2 },{ id: '1003' ,text: '列3' ,name: 'c3' ,type: 'INTEGER' ,seq: 3 }] }; var t2 = { id: '2000' ,name: 'fp' ,text: '附属产品' ,seq: 2 ,child:[{ id: '2001' ,text: '列1' ,name: 'c1' ,type: 'STRING' ,seq: 1 },{ id: '2002' ,text: '列2' ,name: 'c2' ,type: 'INTEGER' ,seq: 2 },{ id: '2003' ,text: '列3' ,name: 'c3' ,type: 'DATE' ,seq: 3 }] }; var arr = [t1, t2]; var example = "( ${主产品.列1} + ${主产品.列2} / ( ${附属产品.列1} - ${附属产品.列3} ) ) * 2 = ( ${附属产品.列3} + ${附属产品.列2} / ( ${附属产品.列1} - ${主产品.列3} ) )"; var reg = //${(?:.|/s)*?/.(?:.|/s)*?/}/gi; example = example.replace(reg, function(str){ var reg = //$|/{|/}/g; str = str.replace(reg, ""); var spt = str.split("."); //alert(spt); var newStr = null; for (var i = 0, len = arr.length; i < len; i++) { if (spt[0] == arr[i].text) { var child = arr[i].child; if (child) { for (var j = 0, c_len = child.length; j < c_len; j++) { if (spt[1] == child[j].text) { newStr = '${' + child[j].type + ',' + arr[i].name + '.' + child[j].name + ',' + arr[i].seq + '.' + child[j].seq + '}'; return newStr; } } } } } return newStr; }); alert(example); 其中{(?:.|/s)*?可以匹配全部字符