Created
April 4, 2011 05:28
-
-
Save rajib/901168 to your computer and use it in GitHub Desktop.
ruby method to extract emails from a string into an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_emails_to_array(txt) | |
reg = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i | |
txt.scan(reg).uniq | |
end | |
input = IO.readlines("in.txt") | |
output = File.new("mails.txt", "w+") | |
result_array = extract_emails_to_array(input.join(" ")).sort | |
puts result_array.size #optional | |
result_array.each{|s| output << s.to_s+"\n" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment