Working example: http://alpha.jsfiddle.net/gTpWv/
Both of the methods work separately, but once regexp for smilies gets raw HTML code to process, things get ugly.
K = K.replace(/\b((http:\/\/)|(www\.))[^ ]{5,}/g, function (x) {
var b = x;
if (b.indexOf("www") == 0) {
b = "http://" + b
}
return '<a href="' + b + '" target="_blank">' + x + "</a>"
// K is now /"Testing <a href="http://www.google.com," target="_blank">http://www.google.com,</a> :D, ^^"/
for (var d = 0; d < smiliesArray.length; d++) {
K = K.replace(new RegExp(smiliesArray[d][0], "g"), '<img src="' + smiliesArray[d][1] + '">');
}
// K is now Testing <a href="http%3Cimg%20src=" http:="" i.imgur.com="" mvk87.gif"="">/www.google.com," target="_blank">http<img src="http://i.imgur.com/MVk87.gif">/www.google.com,</a> <img src="http%3Cimg%20src=" http:="" i.imgur.com="" mvk87.gif"="">/i.imgur.com/7JJNL.gif">, <img src="http%3Cimg%20src=" http:="" i.imgur.com="" mvk87.gif"="">/i.imgur.com/vRgA3.gif">
I did find regexp claiming to solve this issue, but inserting it into the regexp: http://alpha.jsfiddle.net/gTpWv/1/ returns nothing.
I've also found interesting the idea to follow this procedure, but I would be left with two seperate lines, one with links and one with smilies and it would take another regexp to inject one into another.
I'm not sure should I meddle with a better regexp(s) or try to find another way to solve this problem.