// 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)^(?P<Username>[-\w\.]+)(?:\s+\W*at\W*\s+|\s*[^\@\s]*?@[^\@\s]*?\s*)(?P<Domain>([\w\-]+)(?:(?:\.|\s+\W*?dot\W*?\s+)([\w\-]+))+?(?:(?:\.|\s+\W*?dot\W*?\s+)([\w\-]+))??$)").unwrap();
let string = "Parse email, also distorted ones, and convert them back to the real ones.
Inspirated by dislick's work: https://regex101.com/r/wB7xJ7/1
frenci98@gmail.com
st11389@copernico.bo.it
gigilafontana .at. gmail [dot] com
d98.copernico@gmail.com
domenico-tosello at dotcom-sas dot com
my.e-M4il [at] w3-spAce.org
email@sub-sub.sub dot domain dot info
email@foo dot foo dot foo dot foo";
let substitution = "\\1@\\3.\\4";
// 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/