I want to replace a link as plain text format to html format.
But I got the issue that, I don't know how to prepend the http:// prefix for the new replacement if in the original link does not exist.
var text = "google.com and http://google.com";
var pattern = /(\b((https?)\:\/\/)?[A-Za-z0-9]+\.(com|net|org))/ig;
text = text.replace(pattern,"<a href='$1'>$1</a>");
I meant:
- If:
google.comwill be replaced<a href="http://google.com">google.com</a> - If:
http://google.comwill be replaced<a href="http://google.com">http://google.com</a>
www.google.comis not handled by your regex