How to parse / trim email addresses from text

Like this question , but not sure how to implement in this case.

A trusted user (does not have to consider data entry) enters / inserts email addresses in the text box. In case of blurring, I would like to look at the text and clear everything that it entered (usually after copying and pasting the address list from the mail client).

"Bob Smith" <bob@company.com>, joe@company.com, "John Doe"<john@company.com>

will be cropped to:

bob@company.com, joe@company.com, john@company.com

+5
source share
5 answers
myEmailList=userInput.match(/[a-zA-z0-9_.]+@[a-zA-Z0-9_.]+\.(com|org|whatever)/g);
myEmailListString=myEmailList.join(', ');

Or just follow the first line if you need an array of email addresses.

-2
source

- , < >.

/".*?"|[<>]/

Javascript - :

line.replace(/".*?"|[<>]/g, '');
+4

, - , , , .

. RFC .

+4
var emailList = userInput
    .replace(/[^,;]*.?</g, "")
    .replace(/>/g, "")
    .replace(/[,; ]{1,}/g, "\n")
    .replace(/[\n]{2,}/g, "\n")
    .split("\n")

( Google ):

"Bob Rob"<bob@company.com>, job@company.com; rob@company.com job@somewhere.com

,, ; .

+3

.math(), :

inputval.match(/[A-z0-9]+@[A-z0-9]+.[A-z]{2,3}/g)

If you want to convert this to a string, you can add .join(', ')or to it .join('; '). The regular expression is simplified. There are quite a few regular expressions for analyzing emails, but the above is a simplified version. It does not account for subdomains, as indicated in the comments below, or multiple TLDs (it also does not account for the character +in the first part of the email address). Substitute a regular expression that matches your needs.

+1
source

All Articles