Craig Sharp
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|user e|userf)@m ydomain\.c om
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.
I have this as a start.
^To:\s+(usera|userb|userc|
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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. :)
ASKER
Thanks for your response Lorenda :-)
ASKER
I have found my solution:
^To:.*(usera@mydomain\.com |userb@myd omain\.com |userc@myd omain\.com )+
Lorenda, you were my only response. Awarding you the points!
Thank you
^To:.*(usera@mydomain\.com
Lorenda, you were my only response. Awarding you the points!
Thank you
ASKER
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.