Skip to content

Instantly share code, notes, and snippets.

@mehdi-farsi
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehdi-farsi/5fd37368fa9d11eb2d99 to your computer and use it in GitHub Desktop.
Save mehdi-farsi/5fd37368fa9d11eb2d99 to your computer and use it in GitHub Desktop.
Ruby Trick To Extract an Email From a String Using Regex
# The goal of this code snippet isn't to make an email validator..
# So the REGEX is not steady but works for simple cases.
#
# You can extract whatever you want by changing the Regex. :)
line = "Congratulation ! here is your email : mehdi-farsi@long-and_boring-company_name.com. Are you happy ?"
email = line[/(\w|[\.\-])+@(\w|[\.\-])+\.[a-zA-Z]+/]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment