Solved

URGENT: Email Regex Help

Posted on 2014-02-05
6
396 Views
Last Modified: 2014-02-06
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.
0
Comment
Question by:Craig Sharp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
lorenda earned 500 total points
ID: 39835775
What language/system are you writing this code in? How many email addresses are you searching for? If it's not a TON, it might be faster to simply write a Select statement to catch your emails.

For each msg in object.msg

'code to parse your userID's here, depending on your delimiters
'Also might add another loop here if there are multiple emails in a to field

Select Case userID

Case usera, userb, etc

End Case

next msg
0
 
LVL 3

Author Comment

by:Craig Sharp
ID: 39835816
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.
0
 
LVL 3

Author Comment

by:Craig Sharp
ID: 39835822
Sorry, I will be searching for about 8 specific email addresses.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:lorenda
ID: 39835889
Ah - okay - what I posted above would really only work "well" client side ad hoc. Hopefully you'll find a postfix expert. :)
0
 
LVL 3

Author Comment

by:Craig Sharp
ID: 39835913
Thanks for your response Lorenda :-)
0
 
LVL 3

Author Closing Comment

by:Craig Sharp
ID: 39839196
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
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question