Regex between strings

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Digeart
Forum Newbie
Posts: 7
Joined: Wed Mar 03, 2004 8:47 am

Regex between strings

Post 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?
Simon.T
Forum Newbie
Posts: 6
Joined: Tue Dec 20, 2005 5:36 am
Location: Malaga, Spain

Post 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
Post Reply