// 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)^\w+(?:[_-][^\W_]+)*@(?![\d._-]+\.[^\W_]+$)[^\W_]+(?:[_-][^\W_]+)*\.[^\W_]{2,3}$").unwrap();
let string = "xxx@_domain.com
xxx@domain_.com
xxx@-domain.com
xxx@domain-.com
-xxx@domain.in
xxx@111.com
xxx@1and1.com
xxx@us.com
xxx@my-india.com
xxx@me2.com
xxx@tv.com
xxx@abc_efg.com
_muth@tamil.com
xx-u@my-india.commmmm
x-xx@1and1.com
xxx@_domain.com => invalid @ starts with _
xxx@domain_.com => invalid domain ends with _
xxx@-domain.com => invalid @ starts with - ( hypen)
xxx@domain-.com => invlaid domain ends with - (hypen)
-xxx@domain.in => invalid domain start with - (hypen)
xxx@111.com => invalid domain only contains numbers
xxx@1and1.com => valid domain contains both number and chars
xxx@us.com => valid
xxx@my-india.com => valid
xxx@me2.com => valid
xxx@tv.com =>
xxx@abc_efg.com => valid _ inside the chars
_muth@tamil.com => valid _ start with ";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
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/