function test() { var s = 'hello {0} world {1} child'; var word = ["t1", "t2"]; var pattern = /\{\d+\}/g; var i =0 ; while (true) { var match = pattern.exec(s);
if (match) { s = s.replace(match, word[i]); } else { break; } i++; if (i >= word.length) { break; } } }把s和word作成参数就可以用了。自己再改改
function test()
{
var s = 'hello {0} world {1} child';
var word = ["t1", "t2"];
var pattern = /\{\d+\}/g;
var i =0 ;
while (true)
{
var match = pattern.exec(s);
if (match)
{
s = s.replace(match, word[i]);
}
else
{
break;
}
i++;
if (i >= word.length)
{
break;
}
}
}把s和word作成参数就可以用了。自己再改改