I have the following CSS background-image rules wherein I want the URL replaced with a new domain (you know, for the sake of loading images via a cookie-less domain):
background-image : url(/image/test.png);background-image : url("/image/test.png");background-image : url('/image/test.png');
I can catch the quotes before /image and then replace the URL correctly with the following sed expression:
local someVar=123
local replace='url\("\/\/img.mydomain.com\/'"$someVar"'\1\")'
sed -E 's,url\(.(.+).\),'"$replace"',g' file.css
The snippet
url\(.
takes care of the quote (single or double) in the URL string. But if the quotes are not there (first example above), the regex will obviously fail. What would be the correct regex to check for this?
I tried the following but it doesn't work:
local someVar=123
local replace='url\("\/\/img.mydomain.com\/'"$someVar"'\1\")'
sed -E 's,url\((\'|\")(.+)(\'|\")\),'"$replace"',g' file.css
and it just throws error: syntax error near unexpected token `)'