开发者

Regex to replace path

开发者 https://www.devze.com 2023-03-10 14:16 出处:网络
I have the below css div style=\"background: transparent url(\'http://test.com/assets/admin/R7AcNoiUzbrr89.png\') no-repeat\"></div>

I have the below css

div style="background: transparent url('http://test.com/assets/admin/R7AcNoiUzbrr89.png') no-repeat"></div>

div style="backgroun开发者_Go百科d: transparent url(http://another.com/assets/admin/R7AcNeer89.png) no-repeat"></div>

How can I get rid of the hostname with a regex?

Thanks


You can try to replace that :

style="(.*)(http://([^/])*)(.*)"

by that :

style="$1$4"


Ruby:

str.gsub(/http:\/\/[^\/]+([^\)])/i, '/')

Js:

str.replace(/http:\/\/[^\/]+([^\)])/i, '/')
0

精彩评论

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