首页 > 其他 > 详细

正则表达式:将图片的相对网址补全。

时间:2017-05-26 11:41:45      阅读:454      评论:0      收藏:0      [点我收藏+]

Q:

I have an image tag with a src and I want to prepend a website url onto the src but only if it doesn‘t start with http://. so far I have

content.replace(/(<img *src=")(.*?)"/, ‘$1‘ + this.websiteUrl + ‘$2"‘);

but I don‘t know how to do the not starting with http:// bit

?

A:

Use a negative lookahead:

content.replace(/(<img *src=")(?!http:\/\/)(.*?)"/, ‘$1‘ + this.websiteUrl + ‘$2"‘);
					

?

my codes:

strText = Regex.Replace(strText, @"(<img.*src="")(?!http:\/\/)(.*?)""", "$1" + siteRootUrl + @"$2""");

?

正则表达式:将图片的相对网址补全。

原文:http://www.cnblogs.com/time-is-life/p/6907629.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!