I've got stuck with this one. Got a string, just as this one:
<div id="result">Hello there Paul :) How are you</div>
Now I'd like to replace the smiley face with an image. If that was a single instance it wouldn't give me any headache. This is what I've got:
$.fn.emoji = function(){
var keys = ':-D|:D|:-)|:)|;-)|;)|:-O|:o|:-P|:p|:-(|:(|:-S|:s|:-l|:l|B-)|B)|*-)|*)|8ol|8l';
return this.each(function(){
var regex = new RegExp('(' + keys + ')', 'g');
$(this).html($(this).html().replace(regex, <img />));
});
};
What I'm trying to do is find if any of the keys are within the string and then replace it with an image. But my RegExp object is completely wrong. Anyone's able to fix it?