Email Scanner is a simple ruby file with a method that takes a text as input. The output is an array of hashes with two keys ":name" and ":email".
The :email key uses regular expressions to find a valid email. Valid email examples that are caught by this regular expression are -
- first.last@gmail.com
- < first.last@gmail.com >
- [mailto:first.last@gmail.com]
- < first.last+title@gmail.com >
- firstlast@gmaii.com
- f@gmail.com
- first.lAST@gmail.com
- FirST.LasT@GMaIL.com
The :name key uses regular expressions to find any string in quotes immediately preceding the email address. If the name is not in quotes…it will not be found. If the name is not followed by an email address…it will not be found.
Valid => "Andrew Dennis"
Invalid => Andrew Dennis
[{:name => "Andrew Dennis", :email => "example@gmail.com"}, {:name => "Foo Bar", :email => "foo.bar@gmail.com"}, {:name => "Lionel Messi", :email => "MyLeftFoot@aol.com"}]