C#中使用 正则表达式 替换img中src路径但保留图片名
text = Regex.Replace(text, @"(?i)(?<=<img\b[^>]*?src=\s*(['""]?))([^'""]*/)+(?=[^'""/]+\1)", "/Images/");
//text 为HTML代码段
///////////////////////////////////////////////////////////////////////////////////////////以下是获取HTML代码段中所有<img>标签里的src属性里的路径
// 定义正则表达式用来匹配 img 标签
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);
// 搜索匹配的字符串
MatchCollection matches = regImg.Matches(text);
int i = 0;
string[] UrlList = new string[matches.Count];
// 取得匹配项列表
foreach (Match match in matches)
{
UrlList[i++] = match.Groups["imgUrl"].Value;
}
C#中使用 正则表达式 替换img中src路径但保留图片名的更多相关文章
- 使用Dreamweaver正则表达式替换href中的内容
在Dreamweaver中使用正则表达式替换href中的内容,就像下面这些href中的内容复杂多样的情况下,href="/html/u.html",href="/tuho ...
- 正则表达式替换字符串中的html标签
正则表达式替换字符串中的html标签 ··· var newStr = str.replace(/<[^>]+>/g, ''); ···
- C# 使用正则表达式替换PPT中的文本(附vb.net代码)
文本介绍如何在C#程序中使用正则表达式替换PPT幻灯片中的指定文本内容.具体操作步骤如下: 1. 在程序中引用Spire.Presentation.dll.两种方法可参考如下: (1)直接在程序中通过 ...
- 关于在Eclipse中使用正则表达式替换的一点记录(使用正则表达式的分组)
今天在工作中遇到了点替换的麻烦事,由于数据类进行了变动,具体情况是这样的,需要将下面的代码: player.skillData[i].name 替换为: player.skillData.getSki ...
- UltraEdit中使用正则表达式替换
UltraEdit在使用正则表达式进行查找替换时有两个可使用的语法集合.一个是 UltraEdit 的更早的版本被使用的原来的 UltraEdit 句法.另一个是"Unix"类型的 ...
- 使用java中replaceAll方法替换字符串中的反斜杠
今天在项目中使用java中replaceAll方法将字符串中的反斜杠("\")替换成空字符串(""),结果出现如下的异常: java.util.regex.Pa ...
- 在Ant Build文件中使用正则表达式替换文件内容
这需要在build文件中使用<replaceregexp>标签, 这个标签的使用大概是这个样子的: <replaceregexp file="${src}/build.pr ...
- SQL Server中利用正则表达式替换字符串
--如果存在则删除原有函数 IF OBJECT_ID(N'dbo.RegexReplace') IS NOT NULL DROP FUNCTION dbo.RegexReplace G ...
- C# 用正则表达式替换字符串中所有特殊字符
descriptionXML = Regex.Replace(ToDBC(descriptionXML.ToUpper().Replace((char)32, ' ').Replace((char)1 ...
随机推荐
- debian8修改kde桌面语言
apt-get install kde-l10n-zhcn, language里面改中文 亲测可用 来源:http://tieba.baidu.com/p/2489771177
- mysql连接报10038
1. netstat -ntpl # 查看端口状态,发现3306状态丢失(不理解操作,但确实解决了问题) 2. iptables -vnL # 这里要清除防火墙中链中的规则 3. iptable ...
- dns bind记录
自建DNS服务, 使用的工具是bind, 当然也有其他更轻量的工具 yum -y install bind /etc/named.conf 监听端口和ip修改 默认监听127.0.0.1 其他机器无法 ...
- 定义变量|dirname|basename|printf
$ basename /xxxx/test test $ dirname /xxxx/test /xxx $ dirname /xxx/test|while read p;do sp=$p" ...
- AJAX数据传输(原生js)
原生ajax写法 <!DOCTYPE html> <html lang=""> <head> <meta charset="UT ...
- 【flask】RestFul的基本鉴权
编写API的基本鉴权 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : shenqiang from flask import Fla ...
- Python之循环条件、变量、字符串格式化
一.认识python python语言的优缺点,自行百度,这里不概述,简单说下,python是一门面向对象,解释型计算机语言.那么问题来了,解释型和编译型语言有什么区别? 1.解释型和编译型语言区别 ...
- Java 的 LinkedList 的底层数据结构
1. 数据结构--LinkedList源码摘要 public class LinkedList<E> extends AbstractSequentialList<E> imp ...
- abrupt|promising
N-VAR 典礼;(宗教)仪式A ritual is a religious service or other ceremony which involves a series of actions ...
- resume|issue|transmit|sake|obliged|beyond her wildest dreams|echo|transmission|immense|consistent |convey to| boasted|satisfaction|rub|enrol|demonize
If an activity resumes, or if you resume it, it startsagain after a pause. (中断后)继续,重新开始 Normal servi ...