I am trying to construct a REGEX pattern, to convert relative URLs to absolute URLs in javascript scripts.
Example: I would like to replace ALL instances of the following (taken from js script):
url('fonts/fontawesome-webfont.eot?v=4.2.0');
And return the following:
url('http://example.com/fonts/fontawesome-webfont.eot?v=4.2.0');
Example pattern that works for HTML tags (link):
$pattern = "#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#"
Preferred use of this pattern:
$result = preg_replace($pattern,'$1http://example.com/$2$3', $result);
The closest I have managed to guess (unsuccessfully) is:
$pattern = "#(url\s*=\s*[\"'])(?!http)([\"'])#";
=s in your search string, or not in the formurl =.. Try(url\(["'])(?!http).