Last active
August 29, 2015 14:12
-
-
Save streetcarmonkey/ac71c4487ca81aa3dbd2 to your computer and use it in GitHub Desktop.
Ruby script to extract email addresses from a string using a regular expression.
This file contains hidden or 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
@string = '<p><a href="http://plop.com">plop</a><br /><a mailto:[email protected]>[email protected]</a><br />[email protected]</p>' | |
RE = /[\w.!#\$%+-]+@[\w-]+(?:\.[\w-]+)+/ | |
def email_extract(doc = @string) | |
puts "Attempting to extract emails from a string" | |
emails = Array.new | |
doc.downcase.scan(RE).each do | email | emails.push email end | |
emails.uniq! | |
return emails | |
end | |
emails = email_extract #'<p><a href="http://notplop.com">not plop</a><br /><a mailto:[email protected]>[email protected]</a><br />[email protected]</p>' | |
puts emails.size | |
puts emails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment