Last active
August 29, 2015 14:08
-
-
Save mehdi-farsi/5fd37368fa9d11eb2d99 to your computer and use it in GitHub Desktop.
Ruby Trick To Extract an Email From a String Using Regex
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
# 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