<a  onmousedown="return aliclick(this,&#39;?tracelog=offeredetail_pic1_TP&#39;);"  onclick="openOfferImageUrl();" style="cursor:pointer">
      <img src="????" onload="javascript:if(this.height>this.width){this.height=250}else{this.width=250}" alt="二手汽车-供应日本尼桑(NISSAN DIESEL)牵引车-牵引车尽在阿里巴巴" class="picgrayborder" />
    </a>这样一段html标记  变的内容为 ????部分 我想用正则匹配得到????部分 其中斜体部分可有可无  如何得到 很急 多谢高手!

解决方案 »

  1.   

    using System.Text.RegularExpressions;// 正则表达式对象
    Regex re = new Regex(@"<img.*?src=""([^""])""");// Match 对象
    Match m = re.Match("your string");// 是否找到
    if( m.Success )
    {
        // 找到
    }
    else
    {
        // 未找到
    }
      

  2.   

     static void Main(string[] args)
            {
                Regex r = new Regex(@"<img.*src=""[^""]*""");
                string youRstr=@"<img src=""..."" onload=""javascript:if(this.height>this.width){this.height=250}else{this.width=250}"" alt=""二手汽车-供应日本尼桑(NISSAN DIESEL)牵引车-牵引车尽在阿里巴巴"" class=""picgrayborder"" /> ";
                if(r.Match(youRstr).Success)
                    Console.WriteLine("ok");
                else
                    Console.WriteLine("error");                  }
      

  3.   

       string text=@"<a  onmousedown=""return aliclick(this,&#39;?tracelog=offeredetail_pic1_TP&#39;);""  onclick=""openOfferImageUrl();"" style=""cursor:pointer""> 
      <img src=""????"" onload=""javascript:if(this.height>this.width){this.height=250}else{this.width=250}"" alt=""二手汽车-供应日本尼桑(NISSAN DIESEL)牵引车-牵引车尽在阿里巴巴"" class=""picgrayborder"" /> 
    </a>";
    MatchCollection mc = Regex.Matches(text, @"<img\s+src=""([^>""]*?)"".*>"); 
    foreach (Match m in mc) 

    Console.WriteLine(m.Groups[1].Value ); 
      

  4.   

    using System.Text.RegularExpressions;// 正则表达式对象
    Regex re = new Regex(@"<img.*?src=""([^""]*)""");// Match 对象
    Match m = re.Match("your string");// 是否找到
    if( m.Success )
    {
        // 找到
    }
    else
    {
        // 未找到
    }
      

  5.   

    那表达式前面要加上a  onmousedown="return aliclick(this,&#39;?tracelog=offeredetail_pic1_TP&#39;);"  onclick="openOfferImageUrl();" style="cursor:pointer"> 怎么写表达式啊
      

  6.   

    Regex re = new Regex(@"(?is)<a\s+onmousedown=""return\s+aliclick\(this,&#39;\?tracelog=offeredetail_pic1_TP&#39;\);"" \s+onclick=""openOfferImageUrl\(\);""\s+style=""cursor:pointer""\s*>\s*<img.*?src=""([^""]*)""", RegexOptions.None);
    MatchCollection mc = re.Matches("text");
    foreach (Match ma in mc)
    {
     Console.WriteLine(ma.Groups[1].Value ); 
    }
      

  7.   

    前面一样的部分可以不放在正则判断中,用一个变量来相加即可。
    感觉你是在做采集程序,参考别人的程序会快一些。
    http://blog.csdn.net/kindsjay/archive/2009/04/15/4075074.aspx