css - Regular Expression - replace urls in style tags -
i have searched on google , stackoverflow didnt find answer. tryed myself, iam no regex guru.
my goal replace relative urls in html style tag absolute version.
e.g.
style="url(/test.png)"
style="url(http://mysite.com/test.png)"
style="url("/test.png")"
style="url("http://mysite.com/test.png")"
style="url('/test.png')"
style="url('http://mysite.com/test.png')"
style="url(../test.png)"
style="url(http://mysite.com/test.png)"
style="url("../test.png")"
style="url('http://mysite.com/test.png')"
style="url('../test.png')"
style="url('http://mysite.com/test.png')"
and on.
here tryed poor regex "skils"
url\((?<url>[^\)]*)\)
gives me url in "url" function.
thanks in advance!
well, can try regex:
style="url\((['"])?(?:\.\.)?(?<url>[^'"]+)\1?\)"
and replace with:
style="url($1http://mysite.com$2$1)"
(['"])?
capture quotes if present , use them again @ \1?
([^'"]+)
capture url itself.
Comments
Post a Comment