Created
November 1, 2024 10:20
-
-
Save danielcranney/43c5a780a7f5c27d4d167728dc913117 to your computer and use it in GitHub Desktop.
newsletter unsubscription tracker / 07 - extractEmail() helper function.js
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
// 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