<img src="http://www.zyue.com/heh.jpg" alt="abc" />求在C#中怎么获取出alt的值

解决方案 »

  1.   

    (?i)(?<=<img\b[^>]*?alt=(['"]?))[^'"]+(?=\1)
      

  2.   

    string pattern=@"(?is)<img\s*[^>]*?src=""http://www.zyue.com/heh.jpg""[^>]*?alt="([^""]*?)"/>";
    取Groups[1].Value
      

  3.   

    string str= Regex.Match(string yourstr,"<img[\w\W]+?alt="([^"]+)"").group[1].Value;自己专义一下..
      

  4.   

    Regex reg = new Regex(@"(?is)(?<=<img[^>]*alt="")[^""]*(?=""[^>]*>)");
      

  5.   

    string pattern=@"(?is)<img\s*[^>]*?src=""http://www.zyue.com/heh.jpg""[^>]*?alt="([^""]*?)"[^>]*?/>";
    取Groups[1].Value
      

  6.   

                Regex reg = new Regex(@"(?is)(?<=<img[^>]*alt="")[^""]*(?=""[^>]*>)");
                MatchCollection mc = reg.Matches(yourStr);
                foreach (Match m in mc)
                {
                    richTextBox2.Text += m.Value + "\n";
                }
      

  7.   


     string txt = "<img src=\"http://www.zyue.com/heh.jpg\" alt=\"abc\" />";
                Match ma = Regex.Match(txt,"<img.+alt=\"(.+)\" />");
                Console.WriteLine(ma.Groups[1].Value);
                Console.Read();