Created
February 18, 2022 21:48
-
-
Save huffmanks/eea0df158e58decd46854d29da0f9289 to your computer and use it in GitHub Desktop.
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
/* | |
* @title Get all emails from a string | |
* @desc Puts every email into an array | |
*/ | |
const text = 'This email was sent to someone@example.com by "Example News Services" <news@example.com>. Unsubscribe from email sent by Example News Services.' | |
const regexp = /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gim | |
const getEmails = (text) => { | |
const emailArray = Array.from(text.matchAll(regexp), (m) => m[0]) | |
emailArray.map((email) => { | |
return console.log(email) | |
}) | |
} | |
getEmails(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment