分析的内容:
<DIV id=body><IMG alt=内容1 src=1.jpg><FONT face=宋体>你好.</FONT><IMG alt=内容2 src=2.jpg></DIV>希望能得到:内容1和内容2使用:    string p1 = "(?is)<IMG alt=(?<Title>[^\\s].*?)>";
            Regex re = new Regex(p1, RegexOptions.IgnoreCase);//正则表达式得到的结果是 :”内容1 src=1.jpg“   和  “内容2 src=2.jpg 希望只得到内容1和内容2,请帮忙修改一下正则表达式。谢谢。

解决方案 »

  1.   

    (?is)<img([^>]*)alt=(?<Title>[^\s]*?)\1.*?>取title分组
      

  2.   


    void Main()
    {
       string html=@"<DIV id=body><IMG alt=内容1 src=1.jpg><FONT face=宋体>你好.</FONT><IMG alt=内容2 src=2.jpg></DIV>"; foreach(Match m in  Regex.Matches(html,@"(?is)<img([^>]*)alt=(?<Title>[^\s]*)\1.*?>"))
    {
      Console.WriteLine(m.Groups["Title"].Value);
    }
    }/*
    内容1
    内容2
    */
      

  3.   

    你也可以修改你的正则为:(?is)<IMG alt=(?<Title>[^\s]*)
      

  4.   

    MatchCollection mc = Regex.Matches(yourHtml,@"(?is)(?<=<img[^>]*?alt=\s*)[^\s<>]*");
    foreach(Match m in mc)
    {
        m.Value;//就是你要的
    }
      

  5.   


                string html = "<DIV id=body><IMG alt=内容1 src=1.jpg><FONT face=宋体>你好.</FONT><IMG alt=内容2 src=2.jpg></DIV>";
                MatchCollection mc = Regex.Matches(html, @"(?is)(?<=<img alt=)[^>]*(?=>)");
                foreach (Match m in mc)
                    Console.WriteLine(m.Value);
                //输出:
                //内容1 src=1.jpg
                //内容2 src=2.jpg
      

  6.   

     楼上正则都写的很炫
    可是具体怎么,解释下啊还有这个东西,如果是想知道alt的值,用jquery可以么
      

  7.   

    sorry  没仔细看你的需求,重写一份            string html = "<DIV id=body><IMG alt=内容1 src=1.jpg><FONT face=宋体>你好.</FONT><IMG alt=内容2 src=2.jpg></DIV>";
                MatchCollection mc = Regex.Matches(html, @"(?is)(?<Title>(?<=<img alt=)[^\s>]*)");
                foreach (Match m in mc)
                    //Console.WriteLine(m.Groups["Title"].Value);
                    //或者
                    Console.WriteLine(m.Value);
                //输出:
                //内容1
                //内容2
      

  8.   

    写完才发现,和逍遥哥的差不多,那我改下吧
    (?is)(?<Title>(?<=<img alt=)[^\s]+(?=[^>]+>))