Search code examples
javascriptregexemail-validationzapier

Email regex returning empty


I am trying to extract multiple email addresses from a string of text using a regex in Zapier code.

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)

This always returns emailList as null. I pulled this regex expression from https://www.regular-expressions.info/index.html I have also tried Email regular expressions from other websites with still the same experiences.

I have also used Zapier's Formatter's Extract Pattern option and tried the same expression with no luck either. Not sure what is going on here?


Solution

  • Your regex code doesn't work. You should use /(([A-Za-z0-9]+\w*[\.\-]?){1,}\w*@([A-Za-z0-9]+\.){1,2}[A-z]{2,3})/gm.

    See test below.

    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);