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

C#替换html代码中所有img标签的路径保留文件名称

2017-03-09 17:18 447 查看
using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Text.RegularExpressions;

namespace picturetongbu

{

public partial class pic_replace : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string a = "dsadadadsa<img src=\"/ueditor/net/upload/image/20161019/6361247280411203326293743.jpg\"";

string turl = "aaa";//替换的路径

string url = "";

Regex res = new Regex(a);

MatchCollection match = res.Matches(a);

if (res.IsMatch(a))

{

foreach (var item in match)

{

url = Regex.Replace(a, @"(?i)(?<=<img\b[^>]*?src=\s*(['""]?))([^'""]*/)+(?=[^'""/]+\1)", turl);

lbl1.Text = url;

}

}

lbl1.Text = url;

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息