From 39c88272408a241c3da7e970e7c553aaacc6b61b Mon Sep 17 00:00:00 2001 From: DeshmukhHrishikesh <126752755+DeshmukhHrishikesh@users.noreply.github.com> Date: Sat, 11 Apr 2026 14:49:26 +0530 Subject: [PATCH] Added a method to extract emails The extractEmails() method scans a string and identifies all substrings that match a standard email pattern. It returns a list of email addresses found in the input text. This method is designed to be: Case-insensitive Robust for common email formats Safe (returns empty array if no matches found) All extracted emails are normalized to lowercase to ensure consistency and avoid duplicates caused by case differences. --- lib/textMetadataAndExtraction.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/textMetadataAndExtraction.js b/lib/textMetadataAndExtraction.js index 8310fa0..7f884a0 100644 --- a/lib/textMetadataAndExtraction.js +++ b/lib/textMetadataAndExtraction.js @@ -6,6 +6,15 @@ function extractNumbers(string) { return matches ? matches.map(Number) : []; } +// Extracts all emails from a text using regex pattern that finds all the vaalid emails from text and mas then into an array +function extractEmails(text) { + return (text.match( + /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi + ) || []).map(email => email.toLowerCase()); +} + + + // Counts the number of words in a string. function countWords(string) { // Input: 'Hello world, this is a test.' @@ -165,4 +174,4 @@ function extractJSONStrings(string) { } // Grouped exports -export { extractNumbers, countWords, countCharacter, findPositions, extractHashtags, extractURLs, extractEmails, extractMentions, extractParenthesizedContent, extractQuotedText, extractHTMLTags, extractDates, extractPhoneNumbers, extractIPv4Addresses, extractIPv6Addresses, extractFilePaths, extractFilePaths, extractDomainNames, extractJSONStrings }; +export { extractNumbers, extractEmails, countWords, countCharacter, findPositions, extractHashtags, extractURLs, extractEmails, extractMentions, extractParenthesizedContent, extractQuotedText, extractHTMLTags, extractDates, extractPhoneNumbers, extractIPv4Addresses, extractIPv6Addresses, extractFilePaths, extractFilePaths, extractDomainNames, extractJSONStrings };