日期:2014-05-16  浏览次数:20340 次

如何獲取電郵地址?
大家好,我想實現這樣的功能:


在變量str中查詢符合@yahoo.com格式的電郵地址,并將其放到數組a中。

請問代碼如何寫?

------解决方案--------------------
C# code

using System.Text.RegularExpressions;

//字符串
string str = "abc@yahoo.com alsdjfsaldjfa as a@yahoo.com asdf";
string pattern = @"\S+@yahoo.com";
Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
MatchCollection mc = reg.Matches(str);
string[] result = new string[mc.Count];

for (int i = 0; i < mc.Count; i++)
{
    result[i] = mc[i].ToString();
}

//----测试
for (int i = 0; i < result.Length; i++)
{
    Response.Write(result[i] + "<br />");
}

------解决方案--------------------
用javascript:
JScript code

var str = "abc@yahoo.com alsdjfsaldjfa as a@yahoo.com asdf";
var reg = /\S+@yahoo.com/gi;
var result = str.match(reg);  //result为数组

------解决方案--------------------
现在一般人都注意了,邮箱都改成
abc#yahoo.com或
abc_yahoo.com等形式
这种采集的效果很难说了。