fork(4) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. var text = "Look at http://google.com some more text here possibly,\nLook at www.google.com some more text here possibly";
  8. text = text.Trim();
  9. text = Regex.Replace(text,
  10. @"((https?|ftp)://(?:www\.|(?!www))[^\s.]+\.\S{2,}|www\.\S+\.\S{2,})", m =>
  11. m.Groups[2].Success ?
  12. string.Format("<a target='_blank' href='{0}'>{0}</a>", m.Groups[1].Value) :
  13. string.Format("<a target='_blank' href='http://{0}'>{0}</a>", m.Groups[1].Value));
  14. Console.WriteLine(text);
  15. }
  16. }
Success #stdin #stdout 0.02s 30136KB
stdin
Standard input is empty
stdout
Look at <a target='_blank' href='http://google.com'>http://google.com</a> some more text here possibly,
Look at <a target='_blank' href='http://www.google.com'>www.google.com</a> some more text here possibly