Link to home
Start Free TrialLog in
Avatar of Craig Sharp
Craig SharpFlag for United States of America

asked on

URGENT: Email Regex Help

I am trying to put together a regex to search for specific emails in the To: section of an email header.  I have several email addresses, any one of which can be in the To: section of the header.  There may be one or several of the specific addresses and there must be a match if there are one or more of the addresses.

I have this as a start.

^To:\s+(usera|userb|userc|userd|usere|userf)@mydomain\.com

The email header may contain the following examples in any combination depending on the senders requirements, however I only need to trigger on the first match of the specific addresses.  Based on the regex finding the match, I will trigger other processes.  There also may be other extraneous email addresses which I expect will be ignored based on the criteria.

To: usera@mydomain.com
To: usera@mydomain.com, userb@mydomain.com
To: usera@mydomain.com, userb@mydomain.com, userc@mydomain.com
To: userb@mydomain.com, usere@mydomain.com

I have hit a wall as I am no expert at Regex.

Any help would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Lorenda Christensen
Lorenda Christensen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Craig Sharp

ASKER

Thank you for the reply.

This is being used in Postfix running on Linux.  It is designed to be a single Regex statement such as the example.  Postfix uses the regex to scan the email header and then act on that header match such as forwarding an email that has one or more of the addresses in question to a different email server.

I am searching for the first match of any of the specified users email addresses.  This will trigger the forward.
Sorry, I will be searching for about 8 specific email addresses.
Ah - okay - what I posted above would really only work "well" client side ad hoc. Hopefully you'll find a postfix expert. :)
Thanks for your response Lorenda :-)
I have found my solution:

^To:.*(usera@mydomain\.com|userb@mydomain\.com|userc@mydomain\.com)+

Lorenda, you were my only response.  Awarding you the points!

Thank you