I have a string that may contain 0 or more urls. I want to replace each url in the string with that url wrapped in <a></a>
. Is there a way I can get a reference to the current matched object inside a replace()
?
For example:
var msg = "Go to http://google.com and youtube.com";
var regex = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi;
msg.replace(regex, "<a href='"+<blank>+"'></a>") // Where <blank> is a reference to the current matched url
Thanks!