62,046
社区成员
发帖
与我相关
我的任务
分享
Regex reg = new Regex(@"(?is)(?<!<a[^>]*?)https?://[^/\s]+(?<!\.)(/([\w-]+/)*([\w-]+\.[\w-]+(\?([^=,.]+=[^&,\s.]+)+)?)?)?(?!(?:(?!</?a\b).)*</a>)");
(?<!<a [^>]+>(?=[^<]*</a>)|<a [^>]+)http://[^/ ]+(/?(\w+\/)*(\w+\.+\w+((\?|&)([^ ,&=.]+=[^ ,&=.]+)?)+)?)?
string test = "http://www.163.com/a.aspx?p%id=1&id=1,http://www.163.com/a.aspx?p%id=1&id=1.aspx?http://www.163.com/a.aspx?p%id=1&id=1 http://test. http://test/,http://test.com/abc.aspx. http://test http://test/a/a/a.aspx?p%id=1&id=1. <a href=\"http://www.1.1\" name=\"1\">http://www.1.1 </a>.aspx?";
Regex reg = new Regex(@"(?is)(?<!<a[^>]*?)https?://[^/\s]+(/([\w-]+/)*([\w-]+\.[\w-]+(\?([^=,.]+=[^&,\s.]+)+)?)?)?(?!(?:(?!</?a\b).)*</a>)");
MatchCollection mc = reg.Matches(test);
foreach (Match m in mc)
{
richTextBox2.Text += m.Value + "\n";
}
/*-------输出--------
http://www.163.com/a.aspx?p%id=1&id=1
http://www.163.com/a.aspx?p%id=1&id=1
http://www.163.com/a.aspx?p%id=1&id=1
http://test.
http://test/
http://test.com/abc.aspx
http://test
http://test/a/a/a.aspx?p%id=1&id=1
*/
string test = "http://www.163.com/a.aspx?p%id=1&id=1,http://www.163.com/a.aspx?p%id=1&id=1.aspx?http://www.163.com/a.aspx?p%id=1&id=1 http://test. http://test/, http://test http://test/a/a/a.aspx?p%id=1&id=1. <a href=\"http://www.1.1\" name=\"1\">http://www.1.1 </a>.aspx?";
Regex reg = new Regex(@"(?is)(?<!<a[^>]*?)https?://[\w-]+((\.[\w-]+)+)?/?([\w-]+/)*([\w-]+\.[\w-]+\?([^=,.]+=[^&,\s.]+)+)?(?!(?:(?!</?a\b).)*</a>)");
MatchCollection mc = reg.Matches(test);
foreach (Match m in mc)
{
richTextBox2.Text += m.Value + "\n";
}
//输出
http://www.163.com/a.aspx?p%id=1&id=1
http://www.163.com/a.aspx?p%id=1&id=1
http://www.163.com/a.aspx?p%id=1&id=1
http://test
http://test/
http://test
http://test/a/a/a.aspx?p%id=1&id=1