Sending / Receiving links issue

I have developped a chat application on my phone. I noticed that when my messages are links, they are not recognized.

So I used regex to solve the issue and met an other problem.

Here is the string I’m sending :

var input = document.getElementById("myMessage").value;
var mm = input.replace(/((?:https?://|www)[^s]+)/g,"<a href='$1'>$1</a>");  

The received string is like this :

receivedMessage.replace(/((?:https?://|www)[^s]+)/g,"<a href='$1'>$1</a>");

For instance, if I send :, the guy at the other side of the chat receives :'>'>

while I’m expecting

I don’t understand why am I getting this. Should the reveiving string be formatted like the opposite of the sending string ? meaning

receivedMessage.replace("<a href='$1'>$1</a>",/((?:https?://|www)[^s]+)/g);

I don’t know regex at all so I may tell crap.

Source: regex

Leave a Reply