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 };