首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

? 怎么获取网页中的email

2012-01-23 
??? 如何获取网页中的email我现在获取了网页代码,我想把这个页面所有的email提取出来有好的办法么?[解决办

??? 如何获取网页中的email
我现在获取了网页代码,我想把这个页面所有的email提取出来
有好的办法么?

[解决办法]
static string[] getMailAddress(string source)
{
string p = @ "\w+([-+. ']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* ";
System.Text.RegularExpressions.Regex reg = new Regex(p);
System.Text.RegularExpressions.MatchCollection mc = reg.Matches(source);
string[] result=new string[mc.Count];
for (int i = 0; i < result.Length; i++)
{
result[i] = mc[i].Value;
}
return result;
}


static void Main(string[] args)
{

string source = "a@b.net <b> 或者 </b> b@c.net ";
string[] s = getMailAddress(source);
for (int i = 0; i < s.Length;i++ )
{
Console.WriteLine(s[i]);
}
}

热点排行