Search code examples
regexre2

re2 regex expression that starts with From: and ends with domain.com


I'm trying to come up with a regex expression I can use for filtering incoming email to my Google Apps domain. I'm using Content Compliance to check if it's signed using DKIM and then see if the "From:" part of the header contains our domain name. If it's unsigned and DOES contain our domain name I'm sending it to quarantine.

The expression I have in place is probably over-complex and still missing things. Today it missed:

From: "Employee Name" <employeename@mydomain.com>

What I need is an re2 (the version Google uses) regex expression that will match:

From: any-combination-of-letters-and-special-characters@mydomain.com

I've been using the following but, it's missing some:

((From:)\s{0,1}([\w.+\-]{0,40})\s{0,1}(\W|^)[\w.+\-]{0,25}@(mydomain)\.com(\W))

Any help would be greatly appreciated!


Solution

  • For us, this is working. Thank you to everyone that helped!

    ^(From:).*@(mevion)\.com(\W)