fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string msg1 = "<a href='http://w...content-available-to-author-only...t.com'>http://w...content-available-to-author-only...t.com</a>";
  9. string msg2 = "http://w...content-available-to-author-only...t.com";
  10.  
  11. string regex = @".+((www\.|(http|https|ftp|news|file)+\:\/\/)[&#95;.a-z0-9-]+\.[a-z0-9\/&#95;:@=.+?,##%&~-]*[^.|\'|\\||\# |!|\(|?|\[|,| |>|<|;|\)])(.+)?";
  12. Regex r = new Regex(regex, RegexOptions.IgnoreCase);
  13.  
  14. string f = r.Replace(msg1, "<a href=\"$1\" title=\"Click to open in a new window or tab\" target=\"&#95;blank\">$1</a>").Replace("href=\"www", "href=\"http://www").Replace(@"\r\n", "<br />").Replace(@"\n", "<br />").Replace(@"\r", "<br />");
  15. Console.WriteLine(f);
  16.  
  17. string g = r.Replace(msg2, "<a href=\"$1\" title=\"Click to open in a new window or tab\" target=\"&#95;blank\">$1</a>").Replace("href=\"www", "href=\"http://www").Replace(@"\r\n", "<br />").Replace(@"\n", "<br />").Replace(@"\r", "<br />");
  18. Console.WriteLine(g);
  19. }
  20. }
Success #stdin #stdout 0.08s 24552KB
stdin
Standard input is empty
stdout
<a href="http://w...content-available-to-author-only...t.com" title="Click to open in a new window or tab" target="&#95;blank">www.test.com</a>
<a href="http://w...content-available-to-author-only...t.com" title="Click to open in a new window or tab" target="&#95;blank">www.test.com</a>