Skip to content

gajus/extract-email-address

Repository files navigation

extract-email-address 📧

Travis build status Coveralls NPM version Canonical Code Style Twitter Follow

Extracts email address from an arbitrary text input.

API

import {
  extractEmail,
  type EmailMatch,
} from 'extract-email-address';

extractEmail(input: string): readonly EmailMatch[];

Usage

import { extractEmail } from 'extract-email-address';

extractEmail('extracts email from anywhere within the input [email protected]');
// [{email: '[email protected]'}]

extractEmail('extracts multiple emails located anywhere within the input: [email protected], [email protected]');
// [{email: '[email protected]'}, {email: '[email protected]'}]

extractEmail('extracts all sorts of obfuscated emails, e.g. f o o @ b a r . c o m or baz [at] qux [dot] com');
// [{email: '[email protected]'}, {email: '[email protected]'}]

extractEmail('extracts tagged emails, e.g. [email protected]');
// [{email: '[email protected]'}]

extractEmail('extracts emails surrounded by odd unicode characters, e.g. 邮箱:[email protected]');
// [{email: '[email protected]'}]

extractEmail('extracts emails surrounded by emojis, e.g. 📧[email protected]');
// [{email: '[email protected]'}]

extractEmail('excludes invalid emails with invalid TLDs, e.g. [email protected]');
// []

extractEmail('ignores invalid emails foo@bar');
// []

Filtering results

Some matches might be syntactically valid email addresses, but not actual email addresses, e.g. [email protected].

extract-email-address uses a list of valid top-level domains to filter out matches that are definitely not emails (such as png example), but you might still need to filter out domain specific false-positives.

Related projects

  • extract-date – Extracts date from an arbitrary text input.
  • extract-price – Extracts price from an arbitrary text input.
  • extract-time – Extracts time from an arbitrary text input.