读书人

? 怎么获取网页中的email

发布时间: 2012-01-23 21:57:28 作者: rapoo

??? 如何获取网页中的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]);
}
}

读书人网 >C#

热点推荐