Page 1 of 1

Regex between strings

Posted: Tue Dec 20, 2005 8:39 pm
by Digeart
Hello,

Im trying to parse an .emlx file for the from address.

ie.

To: name@domain.com.au
Message-Id: <C327BE72-24CA-410B-B27E-3351B824EFA7@domain.com.au>
Content-Type: multipart/alternative; boundary=Apple-Mail-3-454776749
Cc: name@name.com.au, newname@name.com.au
Subject: Testing new email accounts 12.56pm 12-10-05
From: FirstName LastName <mrname@domain.com.au>
Date: Wed, 12 Oct 2005 12:57:12 +1000
X-Mailer: Apple Mail (2.734)
X-TPG-Antivirus: Passed

so what I want is just the email address "mrname@domain.com.au"

Code: Select all

$myFile = "2477.emlx";	
$theString = file_get_contents ($myFile);

preg_match (SOME REGEX THING HERE!, $theString, $match);
is kinda the way I was heading.

Any ideas?

Posted: Wed Dec 21, 2005 7:39 am
by Simon.T
never used preg_match but with "ereg" i`d use something as simple as

Code: Select all

ereg('From:.*<(.*)>',$theString,$match)
$match[1] would then contain "mrname@domain.com.au"

this doesn`t check for the valididty of the email address, it just extracts everything from between "<" and ">"

Hope it helps,

Simon