Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting an email address

Status
Not open for further replies.

gerald

Programmer
Apr 10, 2000
152
US
Hi, Im kinda just getting started with Perl. I have been here before but it has been a while. heh.

I might be able to figure this out shortly, but time is of the essence so I was hoping somebody might be able to help me.

I need to take a string, and find any email address that is in that string and put it in a variable.

I am working on a web-based email program and need to be able to parse the From: and To: fields from the header and pull out any actual email addresses since the fields can be arranged in many different ways.

So if I have the string:

&quot;Gerald&quot; <geefunk@geefunk.com> blahblahjblah

I want ot be able to extract geefunk@geefunk.com from the string just by recognizing it as an email address and not knowing where it is supposed to be located in the string.

Im sure there is a regular expression that I can use for this, but my head is kinda spinning from trying to get a crash course in reg expressions. heh

Any help would be appreciated

Thanks,
Gerald
 
Actually I found a solution already...

What I did was, I split the string into words that are seperated by blank space, and then checked each word with the Email::Valid CPAN module to see if it is a valid email address. CPAN is a beautiful thing. heh

(I also removed any < or > or [ or ] characters from each word before doing the check, because sometimes the headers enclose the email address in one of these sets. )

Regards,
Gerald

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top