前台js读出页面的所有html源码存储在 string 里我想获取图片的名称:
...<IMG id=IMG1 style="DISPLAY: inline" alt=iBanner onerror="javascript:this.src=''" src="http://localhost:2673/Platform/Image/AllBanner/join.jpg" width="100%">...
我想取出 join.jpg 有没有什么好方法?

解决方案 »

  1.   


                string source = "http://localhost:2673/Platform/Image/AllBanner/join.jpg";
                Regex reg = new Regex(@"/([^/.]+.jpg)");
                Match mm = reg.Match(source);
                MessageBox.Show(mm.Groups[1].Value);
      

  2.   

    我的意思是 string 里面是整个页面的html源码html源码 + <IMG id=IMG1 style="DISPLAY: inline" alt=iBanner onerror="javascript:this.src=''" src="http://localhost:2673/Platform/Image/AllBanner/join.jpg" width="100%"> + html源码我想从整个字符串中取出  join.jpg
      

  3.   

    var reg=/<img\b[^>]*\/(.+\.\jpg)"[^>]*>/gi;
    if(reg.test(yourhtml))
       var result=RegEx.$1;
      

  4.   

    tring pattern = "<img\\s+src=\"(?<src>[^\"]+?)\"[\\s\\S]*?>";
    Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
    MatchCollection m = r.Matches("");
    foreach(Match m in mc)
    {
      Console.WriteLine(mc.Groups["src"].Value);
    }
      

  5.   

    帮忙拼下正则串
    <IMG *** alt=iBanner *** src="http://***/Platform/Image/AllBanner/***" width="100%">***内容不确定,什么都可能是其他的确定,求正则
      

  6.   

    我要取出 用正则取出
    <IMG id=IMG1 style="DISPLAY: inline" alt=iBanner onerror="javascript:this.src=''" src="http://localhost:2673/Platform/Image/AllBanner/join.jpg" width="100%">
    部分东西,在进行1楼的操作
      

  7.   

    js:var reg=/<img\b[^>]*alt=iBanner[^>]*\/(.+\.\(?:jpe?g|bmp|gif))"[^>]*>/gi;
    if(reg.test(yourhtml))
     alert(RegExp.$1);C#:
    Regex reg=new Regex(@"(?i)<img\b[^>]*alt=iBanner[^>]*\/(.+\.\(?:jpe?g|bmp|gif))"[^>]*>");
      

  8.   

    "http://localhost:2673/Platform/Image/AllBanner/join.jpg";Path.GetFileName获取文件名
      

  9.   

    (?i)<IMG\s*[^>]*?alt=(["']?)iBanner\1[^>]*?src=(["']?)http:\/\/\w+\/Platform\/Image\/AllBanner\/[\w\W]+\2[^>]*?width="100%">注意转移字符
      

  10.   

    可以用split函数把src按'/'拆分,取数组最后一个字符串吧
      

  11.   

    string pattern = @"(?i)<img.*?alt=iBanner.*?src="".*?(\w+\.jpg)[^>]*>";
    string img= Regex.Match(str, pattern).Value;
      

  12.   

    唉,昨晚家里的网络不能上网,不然就回你的帖了,现只能写成博文了:
    http://www.cnblogs.com/insus/archive/2012/10/30/2745843.html