using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
var html = @"
<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>
http://g...content-available-to-author-only...3.com:1139
</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>
http://g...content-available-to-author-only...6.com:1139
</div>
";
html = Regex.Replace(html,
@"<a.*?</a>|(?:https?|ftp)://[\w_.-]+:\d+",
m => m.Value.StartsWith("<")
? m.Value : string.Format("<a target='_blank' href='{0}'>{0}</a>", m.Value));
Console.WriteLine(html);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dC5SZWd1bGFyRXhwcmVzc2lvbnM7CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CiAgICAgICAgdmFyIGh0bWwgPSBAIgogICAgICAgICAgICA8ZGl2PgogICAgICAgICAgICAgIDxhIGhyZWY9IiJodHRwOi8vZy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4uMS5jb206MTEzOSIiIHRhcmdldD0iIl9ibGFuayIiPmh0dHA6Ly9nLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi4yLmNvbToxMTM5PC9hPiAKICAgICAgICAgICAgICBodHRwOi8vZy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4uMy5jb206MTEzOQogICAgICAgICAgICA8L2Rpdj4KICAgICAgICAgICAgPGRpdj4KICAgICAgICAgICAgICA8YSBocmVmPSIiaHR0cDovL2cuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLjQuY29tOjExMzkiIiB0YXJnZXQ9IiJfYmxhbmsiIj5odHRwOi8vZy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx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