码迷,mamicode.com
首页 > 其他好文 > 详细

删除除了Src属性以后的全部属性

时间:2016-08-30 13:35:22      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

 

public static string RemoveAllAttributesWithoutSrc(string input)
     {
        
         string pattern = @"<([a-z][a-z0-9]*)(?:[^>]*(\ssrc=[‘\""][^‘\""]*[‘\""]))?[^>]*?(\/?)>";
         var result = Regex.Replace(input, pattern, "<$1$2$3>");

         return result;
     }

 

 

[TestMethod]
      public void TestMethod1()
      {
          var input = @" <a style=‘asdfasdfasdfasdfasdf‘ class=""afasdfasdfasdfasdf"" /> <img src=‘www.abc.com/jpg/dd‘ />";
          string pattern = @"<([a-z][a-z0-9]*)(?:[^>]*(\ssrc=[‘\""][^‘\""]*[‘\""]))?[^>]*?(\/?)>";
          var result = Regex.Replace(input, pattern, "<$1$2$3>");

          Console.WriteLine (result);
      }

 

 

 

PHP:http://stackoverflow.com/questions/2994448/regex-strip-html-attributes-except-src

删除除了Src属性以后的全部属性

标签:

原文地址:http://www.cnblogs.com/zbw911/p/5821560.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!