// 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"((?:\/[A-Za-z0-9-]+)+)?(\/tag\/[A-Za-z0-9-%]+)+(\/.*)?").unwrap();
let string = "http://example.com/cat1/subcat3/subcat4/tag/this%20is%20page/asdasda?start=130/asdasdasd
http://example.com/cat1/subcat3/subcat4/tag/this%20is%20pageasdasd
example.it/news/tag/this%is%20n%page?adsadsadasd
http://example.com/tag/thispage/asdasdasd.-?asds=
http://example.com/tag/this%20is%20page/asdasd
http://example.com/tag/this
";
let substitution = "$2";
// 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/