我有一個電子郵件串列,該電子郵件有兩種格式:
- 有名字
name <[email protected]> - 沒有名字
[email protected]
我想知道是否有辦法在 Javascript 中用不同的分隔符分割這個串列。
示例串列:
[email protected],name1 <[email protected]>,[email protected]
或
[email protected],[email protected],[email protected]
或
[email protected] [email protected] name2 <[email protected]>
或
[email protected] [email protected] [email protected]
或
email@address.com
name1 <email1@address.com>
email2@address.com
或者
email@address.com
email1@address.com
email2@address.com
目前,我將串列與簡單電子郵件格式的三個分隔符分開,但[email protected]我仍然對如何做到這一點感到困惑,包括名稱格式name <[email protected]>?
這是我用于此的代碼:
var emailInput = $(this);
var clipboardData = e.originalEvent.clipboardData || window.clipboardData;
var pastedData = clipboardData.getData('Text');
var emails = pastedData.split(/[\r,\s] /);
例如我需要提取的內容
[email protected] name <[email protected]>
==>["[email protected]","name <[email protected]>"]
uj5u.com熱心網友回復:
假設您不是在尋找電子郵件地址驗證器,并且已經知道您的串列有電子郵件地址,那么您可以執行以下操作:
let data = `
[email protected],name2 <[email protected]>,[email protected]
[email protected],[email protected],[email protected]
[email protected] [email protected] name9 <[email protected]>
[email protected] [email protected] [email protected]
name13 <[email protected]>
[email protected]
[email protected]
[email protected]
`;
let result = data.match(/[^,;<>\s] @[^,;<>\s] |[^,;<>\s] \s <[^,;<>\s] @[^,;<>\s] >/g);
console.log(result);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/330270.html
標籤:javascript 查询 正则表达式 电子邮件 分裂
上一篇:無法在Mimekit中發送郵件
