// 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)^(?=.*\bj(oe\.)?smith@)(?=.*\ba(lly\.)?cat@)(?=.*\bb(ob\.)?builder@)(?=.*\bc(harleston\.)?chew@)(?!.*@(?!domain\.com\b))").unwrap();
let string = "=== MATCH ===
joe.smith@domain.com, acat@domain.com, bob.builder@domain.com, cchew@domain.com
bob.builder@domain.com, cchew@domain.com, joe.smith@domain.com, acat@domain.com
=== NO MATCH ===
joe.smith@domain.com, acat@domain.com, bob.builder@domain.com, cchew@domain.comm
joe.smith@doman.com, acat@domain.com, bob.builder@domain.com, cchew@domain.com
joe.smith@domain.com, acat@domain.com, bob.builderdomain.com, cchew@domain.com
joe.smith@domains.com, acat@domain.com, bob.builder@domain.com, cchew@domain.com
jjoe.smith@domain.com, acat@domain.com, bob.builder@domain.com, cchew@domain.com";
// 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/