Replace a list of emoticons with their images
Another approach: function replaceEmoticons(text) { var emoticons = { ‘:-)’ : ‘smile1.gif’, ‘:)’ : ‘smile2.gif’, ‘:D’ : ‘smile3.gif’ }, url = “http://www.domain.com/”; // a simple regex to match the characters used in the emoticons return text.replace(/[:\-)D]+/g, function (match) { return typeof emoticons[match] != ‘undefined’ ? ‘<img src=”‘+url+emoticons[match]+'”/>’ : match; }); } replaceEmoticons(‘this is a simple … Read more