I am trying to create a regular expression which will look for a email address after Cc field in the email header. I don’t have programming control on the string, so its not specific to any particular programming language. It’s just a part of integration of some software which expects some regular expression in a search criteria
The email header looks like this:
Received: by hermit.cdu-staff.local
id <01CCE6E3.19910AB8@hetmit.ere-tyumm.local>; Thu, 9 Feb 2012 13:57:14 +0930
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01CCE6E3.19910AB8"
Content-class: urn:content-classes:message
X-MimeOLE: Produced By Microsoft Exchange V6.5
Subject: Email header example
Date: Thu, 9 Feb 2012 13:57:10 +0930
Message-ID: <6434D994F5A495428AB3B69877565EF97040C469A@hermit.cdi-stann.local>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: Email header example
Thread-Index: Aczm4xa7dGVpHUWERSSOuR8HCNmrAw==
From: "Bishnu Paudel" <Bishnu.Paudel@company.com>
To: "Study" <study@company.com>
Cc: "Cameron Loudon" <Cameron.Loudon@company.com>
I have created a regular expression which works great if the string is a one line string (the last line in the header). Here is the expression
(^|,)\s*.*Cc:.*(bishnu.paudel|cameron.loudon)@company[.]com\s*($|,).
Any help would greatly be appreciated.
The following regex should solve the problem
which is an adaption of the regex presented here. Please note the comments on the original website on what a ‘valid’ e-mail address is defined as.