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);
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);
相关文章推荐
- php 正则过滤文章中所有的图片
- asp.net正则表达式提取网页网址、标题、图片实例以及过滤所有HTML标签实例
- c#中用正则过滤所有标点符号
- C#正则表达试来读取网页所有内容里的链接地址和链接内容
- ASP.NET正则表达式提取网页网址、标题、图片实例以及过滤所有HTML标签实例
- asp.net正则表达式提取网页网址、标题、图片实例以及过滤所有HTML标签实例
- 一个用C#过滤HTML代码的函数
- 用C#和正则表达式截取html代码
- 常用正则表达式 C#正则表达 正则表达式上下文中的行为 示例
- c#正则过滤html标记
- java使用正则表达式过滤所有的字符和数字
- C#(ASP.NET)正则表达式 过滤危险字符函数代码 防SQL注入 很全面的SQL关键字过滤
- 【随手写】JS过滤所有script正则
- 使用C#正则表达式获取必应每日图片地址
- C# 正则表达式及返回匹配的所有结果
- C#正则表达式之过滤掉双引号...
- [原]用正则得到HTML中所有的图片路径
- C# 用正则表达式替换字符串中所有特殊字符
- c# 正则过滤非中文字符