【问题标题】:Email regex returning empty [duplicate]电子邮件正则表达式返回空 [重复]
【发布时间】:2018-11-08 13:55:42
【问题描述】:

我正在尝试使用 Zapier 代码中的正则表达式从文本字符串中提取多个电子邮件地址。

var rawList = "This is just a test of everything@test.com not sure how regex@email.com can extract multiple email@addresses.com but we will see";

var emailList = rawList.match(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/);

console.log(emailList)

这总是将emailList 返回为空。我从https://www.regular-expressions.info/index.html 中提取了这个正则表达式我还尝试了来自其他网站的电子邮件正则表达式,但体验仍然相同。

我还使用了 Zapier 的 Formatter 的 Extract Pattern 选项并尝试了相同的表达式,但也没有运气。不知道这里发生了什么?

【问题讨论】:

  • 可能你错过了/gi修饰符:var emailList=rawList.match(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi);

标签: javascript regex email-validation zapier


【解决方案1】:

您的正则表达式代码不起作用。你应该使用/(([A-Za-z0-9]+\w*[\.\-]?){1,}\w*@([A-Za-z0-9]+\.){1,2}[A-z]{2,3})/gm

请参阅下面的测试。

var rawList="This is just a test of everything@test.com not sure how regex@email.com can extract multiple email@addresses.com but we will see";
var emailList=rawList.match(/(([A-Za-z0-9]+\w*[\.\-]?){1,}\w*@([A-Za-z0-9]+\.){1,2}[A-z]{2,3})/gm);
console.log(emailList);

【讨论】:

    猜你喜欢
    • 2010-11-03
    • 2010-11-18
    • 2019-05-05
    • 2014-12-09
    • 2015-12-20
    • 2010-10-30
    • 1970-01-01
    • 2011-06-24
    相关资源
    最近更新 更多