I’m working on a regexp to find and replace all matches that don’t start with url(http
relative paths are going to be converted to full absolut paths
ie:
url(foo/bar) > url(‘http://foo/bar‘)
match:
- url(foo/bar)
- url(‘foo/bar’)
don’t match:
- url(http://foo/bar)
- url(‘http://foo/bar‘)
This is what I’ve come up with so far, but I’m not 100% there
$fileContents = preg_replace(
'/url\(("|\')?(?<!(http))(.+?)("|\')?\)/i',
'url(\'' . $glmBaseUrl . $subDir . '/$3\')',
$fileContents
);
Something like this should suffice:
The problem with yours is that you used negative lookbehind instead of negative lookahead. You should also use
[^\']instead of., otherwiseurl('http://foo/bar')will match by not matching the optional', failing the negative lookahead because it’s'httpand nothttpand then matching the single quote with.+?.