RE: mail header split
- From: Ankur.Gupta@xxxxxxxxxxxx (Ankur Gupta)
- Date: Tue, 31 May 2005 15:31:35 +0530
> I have an email To field that I want regex on
>
> The email is as so:
>
> 76867487489-bookings@xxxxxxxxxx
>
> Im trying to get the number before the hyphen.
>
> Currently I have it as so
>
> my ($bookrefNumber, $discard) = split('-',$pop3MailContent{'To'});
You don't need to use $discard variable.
You can use splice to capture only the relevant fields.
change it to this...
my ($bookrefNumber) = (split(/-/,$pop3MailContent{'To'}))[0];
> but I dont like this method.
If you do not like this method then use regexp.
A simple regexp without any checks would be(assuming that all email-ids have
the format you specified).
# This will capture all the numbers from the starting till it finds a hyphen
(-).
$pop3MailContent{'To'} =~ /^(\d+)-/;
#$1 contains the pattern matched within the parentheses. If no match is
found then $1 would be undef.
my $bookrefNumber = $1;
And if you want, go through perlre/perlretut. It has lots of information on
regular expressions.
--Ankur
.
- References:
- mail header split
- From: Brent Clark
- mail header split
- Prev by Date: mail header split
- Next by Date: simple open file
- Previous by thread: mail header split
- Next by thread: simple open file
- Index(es):
Relevant Pages
|