Regex to replace path
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, '/')
精彩评论