fork(2) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var html = @"
  9. <div>
  10. <a href=""http://g...content-available-to-author-only...1.com:1139"" target=""_blank"">http://g...content-available-to-author-only...2.com:1139</a>
  11. http://g...content-available-to-author-only...3.com:1139
  12. </div>
  13. <div>
  14. <a href=""http://g...content-available-to-author-only...4.com:1139"" target=""_blank"">http://g...content-available-to-author-only...5.com:1139</a>
  15. http://g...content-available-to-author-only...6.com:1139
  16. </div>
  17. ";
  18. html = Regex.Replace(html,
  19. @"<a.*?</a>|(?:https?|ftp)://[\w_.-]+:\d+",
  20. m => m.Value.StartsWith("<")
  21. ? m.Value : string.Format("<a target='_blank' href='{0}'>{0}</a>", m.Value));
  22. Console.WriteLine(html);
  23. }
  24. }
Success #stdin #stdout 0.04s 134400KB
stdin
Standard input is empty
stdout
            <div>
              <a href="http://g...content-available-to-author-only...1.com:1139" target="_blank">http://g...content-available-to-author-only...2.com:1139</a> 
              <a target='_blank' href='http://g...content-available-to-author-only...3.com:1139'>http://g...content-available-to-author-only...3.com:1139</a>
            </div>
            <div>
              <a href="http://g...content-available-to-author-only...4.com:1139" target="_blank">http://g...content-available-to-author-only...5.com:1139</a>
              <a target='_blank' href='http://g...content-available-to-author-only...6.com:1139'>http://g...content-available-to-author-only...6.com:1139</a>
            </div>