Skip to content

Instantly share code, notes, and snippets.

@itashdv
Created August 27, 2020 06:49
Show Gist options
  • Save itashdv/3a7bd5d5eaa78c92d86c83254a09050a to your computer and use it in GitHub Desktop.
Save itashdv/3a7bd5d5eaa78c92d86c83254a09050a to your computer and use it in GitHub Desktop.
Extract all Email addresses from a string
function findEmailAddresses(StrObj) {
var separateEmailsBy = ", ";
var email = "<none>"; // if no match, use this
var emailsArray = StrObj.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9._-]+)/gi);
if (emailsArray) {
email = "";
for (var i = 0; i < emailsArray.length; i++) {
if (i != 0) email += separateEmailsBy;
email += emailsArray[i];
}
}
return email;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment