diff --git a/src/model.rs b/src/model.rs index 4334fdc..4c40072 100644 --- a/src/model.rs +++ b/src/model.rs @@ -429,6 +429,28 @@ mod tests { assert_eq!(results.get(3).unwrap().pattern, "url"); } + #[test] + fn match_emails() { + let buffer = + "Lorem ipsum john@server.department.company.com lorem"; + let named_pat = vec![]; + let custom = vec![]; + let alphabet = Alphabet("abcd".to_string()); + let results = Model::new(buffer, &alphabet, &named_pat, &custom, false).matches(false); + + assert_eq!(results.len(), 2); + assert_eq!(results.get(0).unwrap().pattern, "email"); + assert_eq!( + results.get(0).unwrap().text, + "first.last+social@example.com" + ); + assert_eq!(results.get(1).unwrap().pattern, "email"); + assert_eq!( + results.get(1).unwrap().text, + "john@server.department.company.com" + ); + } + #[test] fn match_addresses() { let buffer = "Lorem 0xfd70b5695 0x5246ddf lorem\n Lorem 0x973113tlorem"; diff --git a/src/regexes.rs b/src/regexes.rs index cca6679..86fdbd0 100644 --- a/src/regexes.rs +++ b/src/regexes.rs @@ -3,12 +3,13 @@ use crate::error; pub const EXCLUDE_PATTERNS: [(&'static str, &'static str); 1] = [("ansi_colors", r"[[:cntrl:]]\[([0-9]{1,2};)?([0-9]{1,2})?m")]; -pub const PATTERNS: [(&'static str, &'static str); 14] = [ +pub const PATTERNS: [(&'static str, &'static str); 15] = [ ("markdown_url", r"\[[^]]*\]\(([^)]+)\)"), ( "url", r"((https?://|git@|git://|ssh://|ftp://|file:///)[^ \(\)\[\]\{\}]+)", ), + ("email", r"\b[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,}\b"), ("diff_a", r"--- a/([^ ]+)"), ("diff_b", r"\+\+\+ b/([^ ]+)"), ("docker", r"sha256:([0-9a-f]{64})"),