看到正则就犯晕了HTML格式如下<a href="mailto:[email protected]">[email protected]</a>
 WebClient wClient = new WebClient();
            byte[] meWeb = wClient.DownloadData("http://xxx");
            string meHtml = System.Text.Encoding.Default.GetString(meWeb);
            string meEmail = "";            Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)(?<href>[^'""\s>]+)\1[^>]*>");
            MatchCollection mc = reg.Matches(meHtml);
            foreach (Match m in mc)
            {
                TextBox2.Text += m.Groups["href"].Value + "\n";
            }
我这个是把所有的href整出来了如何只提取这个a标签的email地址呢。 求教了

解决方案 »

  1.   

    Regex regex = new Regex("<a.*?href=\"(?<href>.*?)\".*?title=\"(?<title>.*?)\".*?>", RegexOptions.Compiled);
      

  2.   

    晕了 我这个是获取 href 和title的。
      

  3.   

    正则:<a .*?href=\"mailto:(.+?@.+?\..+?)\">TextBox2.Text += Match.Groups.Item(1).ToString + "\n";
      

  4.   

    用这条吧: <a .*?href=\"mailto:(.+?@.+?\..+?)\".*?>
      

  5.   

     WebClient wClient = new WebClient();
                byte[] meWeb = wClient.DownloadData("http://xxx");
                string meHtml = System.Text.Encoding.Default.GetString(meWeb);
                string meEmail = "";            Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)mailto:(?<email>[^'""]*?)\1[^>]*>");
                MatchCollection mc = reg.Matches(meHtml);
                foreach (Match m in mc)
                {
                    TextBox2.Text += m.Groups["email"].Value + "\n";
                }