Skip to content

Instantly share code, notes, and snippets.

@huffmanks
Created February 18, 2022 21:48
Show Gist options
  • Save huffmanks/eea0df158e58decd46854d29da0f9289 to your computer and use it in GitHub Desktop.
Save huffmanks/eea0df158e58decd46854d29da0f9289 to your computer and use it in GitHub Desktop.
/*
* @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