// 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\.]*)(?=@\w+\.[\w\.]+)\b").unwrap();
let string = "
I need a regular expression that will match email addresses, but exclude specific email addresses from the match
e.g. do not match;
charlie@outrunthebear.co.uk
mailto: sponge.bob@example.com
jim.bob@example.com
billy.bob@example.com
match all other email addresses;
may be test@example.com or a@b.com a.b.c@d.e.f.com
no.body@example.com
another.test.email@example.com
and.another.one@example.com.au";
// 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/