Почти тоже самое )))
<script type="text/javascript">
var Smiles=[
{
id:':),:-)',
value:'111'
},
{
id:':D,:-D,XD,X-D',
value:'222'
},
{
id:'~,~~,~~~',
value:'333'
}
];
var str = " :) ~ XD :)";
function getSmile(b) {
for (var c = Smiles.length, a = 0; a < c; a++)
var d = Smiles[a].id.replace(/([\$\^\*\(\)\+\[\]\{\}\|\.\/\?\\])/g, "\\$1").split(",").join("|"),
b = b.replace(RegExp(d, "gim"), Smiles[a].value);
return b
};
document.write(getSmile(str));
</script>