Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
813 views
in Technique[技术] by (71.8m points)

javascript - How to parse/trim email addresses from text

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

A trusted user (don't need to be concerned with validating input) is typing/pasting email addresses into a text field. On the blur event, I'd like to look at the text and clean up whatever he inputed (typically after copying and pasting a list of addresses from an email client).

"Bob Smith" <[email protected]>, [email protected], "John Doe"<[email protected]>

would be trimmed to:

[email protected], [email protected], [email protected]

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This regex should remove anything in double-quotes as well as < and > characters.

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

In Javascript, you might have something along these lines:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...