I'm converting my PHP code for replacing smiley codes with images, activating links and a few other things to JavaScript.
Separately the functions work well, but together I'm getting the same problem as this. I think that this method is a bit overkill, I've used the following regex in PHP and it avoided conflicting with activated links
loop..
$message = preg_replace('#(?<!\w)'.$smiley.'(?!\w)#i', '<img src="images/smilies/'.$img.'" class="smiley" />', $message);
endloop
Is there any way to convert this regex to JavaScript valid rules? Thanks
Edit to clarify what/how I'm doing:
var input = 'HellO! :* :P ;P :-( http://google.com www.google.com';
//input = input.replace(/(\b(((https?|ftp|file):\/\/)|(www\.))[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,'<a href="$1">$1</a>');
var smilies = {
'sad.png': [':\(', ':-\('],
'kiss.png': [':\*', ':-\*', ';\*', ';-\*'],
'tongue.png': [':P', ':-P', ';P', ';-P']
};
for(var smiley in smilies) {
input = input.replace(new RegExp(smilies[smiley].join('|'), "gi"), '<img src="images/smilies/'+ smiley +'" class="smiley" />');
}
console.log(input);