Regex Email extraction help

I confess that I don't know how to write regex but I have found examples on the forum that I've copied for my own use that seem to work pretty well. However the regex variable below has a problem wherein if an email address has a period in it then it will only extract the address after the period. Does anyone know how to modify it so that it will extract an email address that has a period in it?

Customer Info: {formtext: name=name1; cols=80; default=John Smith john.smith99@bananamail.com}

Regex Extracted Text:
{formtext: name=firstname1; cols=30}{formtext: name=lastname1; cols=30}{formtext: name=Email1; cols=30}

{firstname1=extractregex(name1, "(.+?) ")}
{lastname1=extractregex(name1, ".+? (.+? )")}
{Email1=extractregex(name1, "\w+@[.\w]+\b")}

@Joe_P Hi Joe, you can use the pattern [.\w]+@[.\w]+\b as follows:

Customer Info: {formtext: name=name1; cols=80; default=John Smith john.smith99@bananamail.com}

Regex Extracted Text:
{formtext: name=firstname1; cols=30}{formtext: name=lastname1; cols=30}{formtext: name=Email1; cols=30}

{firstname1=extractregex(name1, "(.+?) ")}
{lastname1=extractregex(name1, ".+? (.+? )")}
{Email1=extractregex(name1, "[.\w]+@[.\w]+\b")}

1 Like

Amazing! Thanks for the help. Could you also assist me with the "last name" regex? It adds a space at the end of extracted name. I've been cleaning it with a {key: backspace} command but I reckon it's better to get it right. I plan on learning the regex syntax at some point this year but I appreciate the help in the meantime.

Sure, you may move the space out of the brackets in your regex as follows:

Customer Info: {formtext: name=name1; cols=80; default=John Smith john.smith99@bananamail.com}

Regex Extracted Text:
{formtext: name=firstname1; cols=30}{formtext: name=lastname1; cols=30}{formtext: name=Email1; cols=30}

{firstname1=extractregex(name1, "(.+?) ")}
{lastname1=extractregex(name1, ".+? (.+?) ")}
{Email1=extractregex(name1, "[.\w]+@[.\w]+\b")}

1 Like

Thank you very much for that

1 Like