// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"url\([\.]{2}\/(\w+(([\/]\w+)*(-\w+|\.\w+))*)").unwrap();
let string = "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
}
}";
let substitution = "url(//en.wikipedia.org/${1})";
// result will be a String with the substituted value
let result = regex.replace_all(string, substitution);
println!("{}", 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 Rust, please visit: https://docs.rs/regex/latest/regex/