abcdef<img src='1.img'/>hijk<img width='20px' src='2.img'/>lmno<img height='20px' src='3.img'/>pqrst
字符串去图片的正则
怎么去掉那些中间的img
abcdefhijklmnopqrst

解决方案 »

  1.   

                string str = "abcdef<img src='1.img'/>hijk<img width='20px' src='2.img'/>lmno<img height='20px' src='3.img'/>pqrst";
                string result = Regex.Replace(str, @"(?is)<img[^>]*?src=(['""\s]?)([^'""\s]+)\1[^>]*?>", "");
                Response.Write(result);
      

  2.   

    Regex.Replace("abcdef<img src='1.img'/>hijk<img width='20px' src='2.img'/>lmno<img height='20px' src='3.img'/>pqrst
    ", "<.+?>", string.Empty)
      

  3.   

    sorry 不用那么长,刚直接把刚才回复提取图片的正则拿来用了,改一下
                string str = "abcdef<img src='1.img'/>hijk<img width='20px' src='2.img'/>lmno<img height='20px' src='3.img'/>pqrst";
                string result = Regex.Replace(str, @"(?is)<img[^>]*?>", "");
                Response.Write(result);