I have a very good regex that works and is capable of replacing URLs in a single line to click once.
string regex = @"((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])";
Now, how can I say to ignore already available links and images?
Therefore, it ignores the lines below:
<a href="http://www.someaddress.com">Some Text</a> <img src="http://www.someaddress.com/someimage.jpg" />
Example:
The website www.google.com, once again <a href="http://www.google.com">www.google.com</a>, the logo <img src="http://www.google.com/images/logo.gif" />
Result:
The website <a href="http://www.google.com">www.google.com</a>, once again <a href="http://www.google.com">www.google.com</a>, the logo <img src="http://www.google.com/images/logo.gif" />
Full Parser Code for HTML:
string regex = @"((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])"; Regex r = new Regex(regex, RegexOptions.IgnoreCase); text = r.Replace(text, "<a href=\"$1\" title=\"Click to open in a new window or tab\" target=\"_blank\" rel=\"nofollow\">$1</a>").Replace("href=\"www", "href=\"http://www"); return text;
source share