原文:<a href="http://www.wywan.com" >aaa1</a><a href="http://www.dnfclub.com" >aaa2</a><a href="http://www.97bet.com" >aaaa3</a><a href="http://www.hao123.com" >hao123</a>
要求提取除了www.dnfclub.com 之外的所有超链接 格式为www.97bet.com
要求提取除了www.dnfclub.com 之外的所有超链接 格式为www.97bet.com
帮下忙啊 谢谢了
MatchCollection mc=Regex.Matches(input,@"(?is)<a\s*href=""https?://www.[^dnfclub]+.[^""]+""[^>]*>.*?</a>");
froeach(Match m in mc)
{
Console.WriteLine(m.Value);
}
改一下string input=@"<a href=""http://www.wywan.com"" >aaa1</a><a href=""http://www.dnfclub.com"" >aaa2</a><a href=""http://www.97bet.com"" >aaaa3</a><a href=""http://www.hao123.com"" >hao123</a>";
MatchCollection mc=Regex.Matches(input,@"(?is)<a\s*href=""https?://www.[^dnfclub]+.[^""]+""[^>]*>.*?</a>");
froeach(Match m in mc)
{
Console.WriteLine(m.Value);
}
[^dnfclub]这个是排除型字符组不是单词
{
string bdurl = "http://" + url;
string bdcontent =@getHtml(bdurl, "");
MatchCollection mc=Regex.Matches(bdcontent,@"(?is)<a\s*href=""https?://www.[^97bet]+.[^""]+""[^>]*>.*?</a>"); foreach (Match m in mc)
{
MessageBox.Show(m.Value);
} return mc.Count;
}不知道为什么 提取不出啦 C#新手 帮忙看下
MatchCollection mcReg = Regex.Matches(input, @"(?is)<a\s*href=""https?://www.(?!(dnfclub))+.[^""]+""[^>]*>.*?</a>");
foreach (Match m in mcReg)
{
Console.WriteLine(m.Value);
}
为什么获取不到匹配内容
现在提取到的是包含<a href这些的
string input = @"<a href=""http://www.wywan.com"" >aaa1</a><a href=""http://www.dnfclub.com"" >aaa2</a><a href=""http://www.97bet.com"" >aaaa3</a><a href=""http://www.hao123.com"" >hao123</a><a href=""http://www.dnfclu.com"" >aaa4</a>";
MatchCollection mcReg = Regex.Matches(input, @"(?is)<a\s*href=""(https?://www.(?!(dnfclub))+.[^""]+)""[^>]*>.*?</a>");
foreach (Match m in mcReg)
{
Console.WriteLine(m.Groups[1].Value);
}
就是说有这3种可能
<a href="http://..
<a href='http://
<a href=http://
MatchCollection mcReg = Regex.Matches(input, @"(?is)<a\s*href=[""']*(https?://www.(?!(dnfclub))+.[^""']+)[""']*[^>]*>.*?</a>");