删除  onmousewheel='return bbim(this)' onload='javascript:if(this.width>screen.width-600)this.width=screen.width-600;if(this.height>100)this.height=100;'剩下
<IMG src='2.gif'/>

解决方案 »

  1.   

    Re: minrange(Minrange)
     你说的很对,怎么删除?
      

  2.   

    如果形式是:on*='*',其中单引号里面不能再包含单引号。
    求出所有匹配模式的正则表达式如下:on[a-z]+='[^']+'在对所有的匹配模式进行删除处理就行了
      

  3.   

    RE:V、97ce_twinkle(毛毛虫) 
      你的方法可行,但我发现有些标记里面不用' 和'的地方呢?
    比如onload=fun();
      

  4.   

    那总得要其他分隔符可以分开其他属性的,比如说空格。on[a-z]+=[.]+\
      

  5.   

    RE:V、97ce_twinkle(毛毛虫) 
       对,有道理,谢谢你
      

  6.   

    看样子是应该可以了,但是还有问题。
     我的原始字符串为:<IMG onmousewheel='return bbimg(this)' height=100 src='http://www.moongest.com/bbs/lt/UploadFile/200441110142526851.gif' onclick='fun();'  onload='javascript:if(this.width>screen.width-600)this.width=screen.width-600;if(this.height>100)this.height=100;' border=0>正则表达式是:
    (<img[^>]*)(on[a-zA-Z ]+=(\s|')+[^']+(\s|')+)([^>]*>)结果输出的结果为:
    <IMG onmousewheel='return bbimg(this)' height=100 src='http://www.moongest.com/bbs/lt/UploadFile/200441110142526851.gif' onclick='fun();'   border=0>即只过滤掉了最后一个onload
    有什么问题吗?
      

  7.   

    你的replace怎么写的?另外你这样写是整个字符串仅作为一次匹配给匹配进去了
      

  8.   

    (on[a-zA-Z ]+=(\s|')+[^']+(\s|')+)就行了
      

  9.   

    //我的意思是先从字符串中找出含有img标记的部分,然后把其中的事件过程过滤掉,并不事直接给出img部分去掉事件过程
    string htmlString = @"<table><tr><td><IMG onmousewheel='return bbimg(this)' height=100 src='http://www.moongest.com/bbs/lt/UploadFile/200441110142526851.gif' onclick='fun();'  onload='javascript:if(this.width>screen.width-600)this.width=screen.width-600;if(this.height>100)this.height=100;' border=0></td></tr></table>";


    string regexString = ? string replaceString = ? Console.WriteLine(htmlString);
    htmlString = Regex.Replace(htmlString,regexString, replaceString,RegexOptions.IgnoreCase);
    Console.WriteLine(htmlString);