格式化贴子内容中的图片路径(正则表达式)

本文介绍了一种使用正则表达式来格式化网页中图片路径的方法。通过替换图片源链接,确保图片能够正确加载显示。该方法适用于处理包含特定目录结构的图片URL。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//格式化贴子内容中的图片路径by gjr 2006.7.3

           // body = Regex.Replace(body, "src=/"(https://[^/]+/[^/]+)?/AspNetForums(?<imgUrl>/images///w+.//w+)/"", "src=/".${imgUrl}/"", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            string aa = "<img height='110' src=/"http://localhost/web/images/200673110548.gif/" width='104' border='0' /><br /><br />sdfgsdgdsfgsdfgsdfgsdfgsdfgsdfgsd<br /><img height='100' src=/"/web/images/200673110559.jpg/" width='100' border='0' /><br />宽度:100 pix 高度:100 pix 水平分辩率:72/1 DPI 垂直分辩率:72/1 DPI<br />";

            string treg="src=/"(http://[^/]+/[^/]+)?/web(?<imgUrl>/images///w+.//w+)/"";

            string rp = "src=/".${imgUrl}/"";

           // aa = Regex.Replace(aa, treg, rp);

            string naa = Regex.Replace(aa, "src=/"(https://[^/]+/[^/]+)?/web(?<imgUrl>/images///w+.//w+)/"", "src=/".${imgUrl}/"", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            Console.Write(naa);

            Console.Read();

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值