您的位置:首页 > Web前端 > HTML

C#中用正则表达示过滤出HTML代码中的所有图片

2008-10-08 13:55 183 查看
  string str = "sdfdfd<img
name=''src='http://cp.a8.com/image/128X128GIF/50686.gif' width='32'
height='32' alt='' />dsfsdfsdf<img
name=''src='http://cp.a8.com/image/128X128GIF/53075.gif' width='32'
height='32' alt='' />dsfffffffff<img
name=''src='http://cp.a8.com/image/128X128GIF/53099.gif' width='32'
height='32' alt='' />";

       
str += "sdfdfd<img
name=''src='http://cp.a8.com/image/128X128GIF/50686.gif' width='32'
height='32' alt='' />dsfsdfsdf<img
name=''src='http://cp.a8.com/image/128X128GIF/53075.gif' width='32'
height='32' alt='' />dsfffffffff<img
name=''src='http://cp.a8.com/image/128X128GIF/53099.gif' width='32'
height='32' alt='' />";

       
Regex r = new
Regex("<img.{25,100}/>");

       
MatchCollection mc = r.Matches(str);

   

       
string[] results = new string[mc.Count];

       
for (int i = 0; i < mc.Count; i++)

       
{

           
results[i]=(mc[i].Value);

     

       
}

       
// List the results.

       
for (int ctr = 0; ctr <= results.Length - 1;
ctr++)

       
{

           
Response.Write( results[ctr]);

           
Response.Write("<br>");

       
}

       
Response.Write(results.Length);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: