string  str = "<form id=\"form1\" runat=\"server\"><div><p><img src=\"img/01300000278409123123126754611.jpg\" alt=\"\" /></p><p><img src=\"img/16583711.jpg\" alt=\"\" /></p><p><img src=\"img/2_091208000854_6.jpg\" alt=\"\" /></p></div></form>";
for (int j = ; j < GetHtmlImageUrlList(str).Length; j++)
{
//获取图片路径字符串
string img = GetHtmlImageUrlList(str)[i];
//删除服务器上的图片
string filepath = Server.MapPath(img);
FileInfo file = new FileInfo(filepath);
if (file.Exists)
{
file.Delete();
}
}
/// <summary>
/// 获取Img的路径
/// </summary>
/// <param name="htmlText">Html字符串文本</param>
/// <returns>以数组形式返回图片路径</returns>
public static string[] GetHtmlImageUrlList(string htmlText)
{
Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
//新建一个matches的MatchCollection对象 保存 匹配对象个数(img标签)
MatchCollection matches = regImg.Matches(htmlText);
int i = ;
string[] sUrlList = new string[matches.Count];
//遍历所有的img标签对象
foreach (Match match in matches)
{
//获取所有Img的路径src,并保存到数组中
sUrlList[i++] = match.Groups["imgUrl"].Value;
}
return sUrlList;
}

C# 正则 获取 Img Src路径的更多相关文章

  1. java如何从一段html代码中获取图片的src路径

    java如何从一段html代码中获取图片的src路径 package com.cellstrain.icell.Test; import java.util.ArrayList;import java ...

  2. 【转】Java Web 项目获取运行时路径 classpath

    Java Web 项目获取运行时路径 classpath 假设资源文件放在maven工程的 src/main/resources 资源文件夹下,源码文件放在 src/main/java/下, 那么ja ...

  3. Android从相册中获取图片以及路径

    首先是相册图片的获取: private final String IMAGE_TYPE = "image/*"; private final int IMAGE_CODE = 0; ...

  4. 20180821 Python学习笔记:如何获取当前程序路径

    20180821 Python学习笔记:如何获取当前程序路径 启动的脚本的路径为:D:\WORK\gitbase\ShenzhenHouseInfoCrawler\main.py 当前脚本的路径为:D ...

  5. java获取当前文件路径的方法

    第一种: File f = new File(this.getClass().getResource("/").getPath()); System.out.println(f); ...

  6. HDFS 读取、写入、遍历文件夹获取文件全路径、append

    版权声明:本文为博主原创文章,未经博主同意不得转载.安金龙 的博客. https://blog.csdn.net/smile0198/article/details/37573081 1.从HDFS中 ...

  7. js 获取文件本地路径

    1.代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  8. golang获取程序运行路径

    golang获取程序运行路径: /* 获取程序运行路径 */ func getCurrentDirectory() string { dir, err := filepath.Abs(filepath ...

  9. C#、ASP.NET获取当前应用程序的绝对路径,获取程序工作路径 (转帖)

    C#.ASP.NET获取当前应用程序的绝对路径,获取程序工作路径   ============================================ 使用 Application.Start ...

随机推荐

  1. NYOJ-20 吝啬的国度 AC 分类: NYOJ 2014-01-23 12:18 200人阅读 评论(0) 收藏

    #include<cstdio> #include<cstring> #include<vector> using namespace std; int pre[1 ...

  2. NYOJ-655 光棍的YY AC 分类: NYOJ 2013-12-29 19:24 224人阅读 评论(0) 收藏

    #include<stdio.h> #include<string.h> char str[210]; int max[210][52]={0}; int sum(int n, ...

  3. .NET设计模式(4):建造者模式(Builder Pattern)(转)

    概述 在软件系统中,有时候面临着“一个复杂对象”的创建工作,其通常由各个部分的子对象用一定的算法构成:由于需求的变化,这个复杂对象的各个部分经常面临着剧烈的变化,但是将它们组合在一起的算法确相对稳定. ...

  4. 测试c语言函数调用性能因素之测试三

    函数调用:即调用函数调用被调用函数,调用函数压栈,被调用函数执行,调用函数出栈,调用函数继续执行的一个看似简单的过程,系统底层却做了大量操作. 操作: 1,               调用函数帧指针 ...

  5. BZOJ1191: [HNOI2006]超级英雄Hero

    这题标解是改一下匈牙利算法,显然,像我这种从不用匈牙利的人,会找个办法用网络流… 具体做法是这样,二分最后的答案ans,然后对前ans个问题建图跑网络流,看最大流能不能到ans. /********* ...

  6. 学生信息管理 --- c语言实现

    第一次写比较大的程序,昨晚看了  大话数据结构  有感-----同样求 1+2+3+4+...+100,我则是简单的从1+2+3+4+...+100. 而不是 (1+100) / 2 * 100;(高 ...

  7. Python并发与并行的新手指南

    点这里 在批评Python的讨论中,常常说起Python多线程是多么的难用.还有人对 global interpreter lock(也被亲切的称为“GIL”)指指点点,说它阻碍了Python的多线程 ...

  8. 2015年4月 15款免费jQuery插件

    点这里 We have collected for you the 15 fresh, free and handy jQuery plugins that will help to speed up ...

  9. POJ 1953

    //FINBONACI数列 #include <iostream> #define MAXN 100 using namespace std; int _m[MAXN]; int main ...

  10. Windows服务创建及安装

    Windows服务创建及安装http://www.cnblogs.com/tuyile006/archive/2006/11/27/573654.html