到GOOGLE上一找就一大堆。。
http://blog.csdn.net/laily/archive/2004/06/24/25872.aspx

解决方案 »

  1.   

    landlordh(software) 和 xzq686(瞬) 两位兄弟的方法不行啊,没有完成这个转换。
      

  2.   

    问题就是这样的:
    把img 图像链接中 带有onclick等javascript事件之类的杂项去掉,只留下最基本的属性。如这一段:
    <IMG alt='' src='http://......./4_394.jpg' border=0  onclick='javascript:if(this.width>screen.width-333)this.width=screen.width-333' dypop='按此在新窗口浏览图片'> 经过正则表达式过滤过后,应变成<IMG alt='' src='http://......./4_394.jpg' border=0>现在就是求这个 正则表达式如何写
      

  3.   

    http://\S+.\S+ 出自ASP.net揭秘
      

  4.   

    imgstring="img  src=\"http://bbs.youhow.net/non-cgi/usr/4/4_394.jpg\" onclick=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\" border=0 dypop=\"按此在新窗口浏览图片\">";imgstring=System.Text.RegularExpressions.Regex.Replace(imgstring,@"<img [^<]*>","");是这样吗?
    imgstring="<img  src=\"http://bbs.youhow.net/non-cgi/usr/4/4_394.jpg\" border=0> 
    得不到这样的值啊
      

  5.   

    try something like
    string s = "<IMG alt='' src='http://......./4_394.jpg' border=0  onclick='javascript:if(this.width>screen.width-333)this.width=screen.width-333' dypop='按此在新窗口浏览图片'>";
      s = Regex.Replace(s,@"<IMG\s+(((?<alt>alt=\S+)|(?<src>src=\S+)|(?<border>border=\S+)|\S*)\s*)*[^>]*>", "<IMG ${alt} ${src} ${border}>", RegexOptions.IgnoreCase);
      
    ors = Regex.Replace(s,@"<IMG\s+(((?<alt>alt=('[^']*'|""[^""]*""|\S*))|(?<src>src=('[^']*'|""[^""]*""|\S*))|(?<border>border=('[^']*'|""[^""]*""|\S*))|\S*)\s*)*[^>]*>", "<IMG ${alt} ${src} ${border}>", RegexOptions.IgnoreCase);
     
      Console.WriteLine(s);
      

  6.   

    我确实看不懂。
    思归老大:感谢你的帮助!不过刚才测试了一下,你的方法能让单个的<img >很完美的过滤掉其它杂项,可是只能过滤第一个啊,假如还有第二个<img .....>之类的,就会把后边的都给去掉了,要怎么改一下啊?
      

  7.   

    string s = "<IMG alt=\"\" src='http://......./4_39422.jpg' style=\"xxx:\" onclick='javascript:if(this.width>screen.width-333)this.width=screen.width-333' border=0><IMG alt='x' src='http://......./4_394.jpgx' border=012  onclick='javascript:if(this.width>screen.width-333)this.width=screen.width-333' dypop='按此在新窗口浏览图片234'>";
    s = Regex.Replace(s,@"<IMG\s+(((?<alt>alt=('[^']*'|""[^""]*""|[^\s>]*))|(?<src>src=('[^']*'|""[^""]*""|[^\s>]*))|(?<border>border=('[^']*'|""[^""]*""|[^\s>]*))|(?<others>[^=<>]+=('[^']*'|""[^""]*""|[^\s>]*)))\s*)*[^>]*>", "<IMG ${alt} ${src} ${border}>", RegexOptions.IgnoreCase); Console.WriteLine(s);
      

  8.   

    saucer(思归)  so good ~~~楼主,你只想得到 <IMG.*> 里的标准html 吗(saucer的就可以了)?如果不是,那你要写的太多了,非常复杂!!!不推荐使用。记得前几天看了一个叫 htmlDom(好像是,记不起来什么名了) 的类库挺不错的,
    可以先转成 DOM 结构的然后对其节点进行重新组合
      

  9.   

    完美!!!
    比着画了一个 
    s= Regex.Replace(s,@"<A\s+(((?<title>title=('[^']*'|""[^""]*""|[^\s>]*))|(?<href>href=('[^']*'|""[^""]*""|[^\s>]*))|(?<target>target=('[^']*'|""[^""]*""|[^\s>]*))|(?<others>[^=<>]+=('[^']*'|""[^""]*""|[^\s>]*)))\s*)*[^>]*>", "<A ${title} ${href} ${target}>", RegexOptions.IgnoreCase);谢谢思归老大帮忙!
    我是用这个来完成论坛发贴时处理来自粘贴其它处的网页的
    http://www.chinasf.net/bbs