// 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"(?m)[a-zA-Z0-9\-\_]*\.[a-zA-Z0-9\-\_]*\.\w{1,3}(\.\w{1,3})?").unwrap();
let string = "
service.mensfitness.co.uk
updates.mensfitness.co.uk
promo.mensfitness.co.uk
deals.mensfitness.co.uk
subs.mensfitness.co.uk
service.healthandfitnessoneline.co.uk
updates.healthandfitnessoneline.co.uk
promo.healthandfitnessoneline.co.uk
deals.healthandfitnessoneline.co.uk
subs.healthandfitnessoneline.co.uk
service.custompc.co.uk
updates.custompc.co.uk
promo.custompc.co.uk
deals.custompc.co.uk
subs.custompc.co.uk
service.digitalslrphoto.com
updates.digitalslrphoto.com
promo.digitalslrphoto.com
deals.digitalslrphoto.com
subs.digitalslrphoto.com
";
let substitution = "'\\g<0>'";
// 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/