const regex = /url\([\.]{2}\/(\w+(([\/]\w+)*(-\w+|\.\w+))*)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('url\\([\\.]{2}\\\/(\\w+(([\\\/]\\w+)*(-\\w+|\\.\\w+))*)', 'g')
const 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
}
}`;
const subst = `url(//en.wikipedia.org/${1})`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', 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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions