开发者

Regex to remove hostname from image

开发者 https://www.devze.com 2023-03-08 15:20 出处:网络
I want to 开发者_开发知识库remove the hostname from all the background css declarations I have in a html page

I want to 开发者_开发知识库remove the hostname from all the background css declarations I have in a html page

ie

<div style="background:transparent url(http://www.some-domain.com/images/test.png) no-repeat"></div>

to become

<div style="background:transparent url(images/test.png) no-repeat"></div>

Any ideas guys?

Thanks


replace the regex "http://[^/]*" with "/".


http://(.*?)images

If you do a regex replace, you can then remove the match and you should be ok.


try

(http:\/\/\w.*\/)

and replace the matched pattern with /

DEMO

0

精彩评论

暂无评论...
验证码 换一张
取 消