var str = "[可爱],很有趣,是啊[惊讶]";
var name=["[可爱]","[惊讶]"],
replacement={"[可爱]":"<img src='keai.gif' title='可爱'/>","[惊讶]":"<img src='jingya.gif' title='惊讶'/>"};
reg =new RegExp("("+name.join(")|(").replace(/([\[\]])/g,"\\$1")+")","g");
uw=str.replace(reg, function(word){
var name=["[可爱]","[惊讶]"],
replacement={"[可爱]":"<img src='keai.gif' title='可爱'/>","[惊讶]":"<img src='jingya.gif' title='惊讶'/>"};
reg =new RegExp("("+name.join(")|(").replace(/([\[\]])/g,"\\$1")+")","g");
uw=str.replace(reg, function(word){
var rep=replacement[word];
return rep ? rep : word;
return rep ? rep : word;
});