I haven't used regex much before but found something useful on the net that I'm using:
private string ConvertUrlsToLinks(string msg)
{
string regex = @"((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\\||\# |!|\(|?|\[|,| |>|<|;|\)])";
Regex r = new Regex(regex, RegexOptions.IgnoreCase);
return r.Replace(msg, "<a href=\"$1\" title=\"Click to open in a new window or tab\" target=\"_blank\">$1</a>").Replace("href=\"www", "href=\"http://www").Replace(@"\r\n", "<br />").Replace(@"\n", "<br />").Replace(@"\r", "<br />");
}
It does a good job but now I want it to exclude urls that already have a "a href=" in front. There's the ending "/a" to consider too.
Can that be done with regex or have to use totally different approach, like coding?