$re = '/url\([\.]{2}\/(\w+(([\/]\w+)*(-\w+|\.\w+))*)/';
$str = 'd: url(../images/printer.gif) top left no-repeat; {
.preview .mw-wiki-logo {
background-image: url(/static/images/project-logos/enwiki-1.5x.png); background-size: 135px auto background-image: url(/static/images/project-logos/enwiki-2x.png);
.preview li.mw-changeslist-line-watched, .preview li.mw-history-line-updated {
list-style-image: url(//upload.wikimedia.org/wikipedia/commons/1/19/ChangedBulletVector.svg);
list-style-image: url(//upload.wikimedia.org/wikipedia/commons/c/c2/ChangedBulletVector.png) \\9
}
}
}
@media (-webkit-min-device-pixel-ratio: 2),(min--moz-device-pixel-ratio: 2),(min-resolution: 2dppx),(min-resolution: 192dpi) {
.preview .mw-wiki-logo {
background-image: url(/static/images/project-logos/enwiki-2x.png);
background-size: 135px auto
}
}';
$subst = "url(//en.wikipedia.org/${1})";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php