Skip to content

Instantly share code, notes, and snippets.

@danielcranney
Created November 1, 2024 10:20
Show Gist options
  • Save danielcranney/43c5a780a7f5c27d4d167728dc913117 to your computer and use it in GitHub Desktop.
Save danielcranney/43c5a780a7f5c27d4d167728dc913117 to your computer and use it in GitHub Desktop.
newsletter unsubscription tracker / 07 - extractEmail() helper function.js
// Helper function to extract the first email address found in a given text
function extractEmail(body) {
var emailPattern = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/; // Regex pattern to match an email address
var match = body.match(emailPattern); // Find the first email that matches the pattern
return match ? match[0] : null; // Return the email if found, otherwise return null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment