2010-11-24 132 views
0

可能重複:
How to extract email address from a string using perl?獲取電子郵件

說我有一個這樣的字符串:

X大學博士學校名稱的無處皮特@ school.edu Blah blah 3 one niner

我如何從那裏獲取電子郵件?

+0

不,不是完全相同的副本。這是從自由流動的文本中提取電子郵件地址。 – 2010-11-24 17:20:23

+0

如果這是你的問題,你絕對不應該使用`[A-Z]`的正則表達式,而不是一個不敏感的情況下的標誌。 – Axeman 2010-11-24 18:22:02

回答

5

你可以試試Email::Find

#!/usr/bin/perl 

use strict; use warnings; 
use YAML; 
use Email::Find; 

my $finder = Email::Find->new(\&print_email); 

while (my $data = <DATA>) { 
    $finder->find(\$data); 
} 

sub print_email { 
    print Dump \@_; 
} 

__DATA__ 
Say I have a string like this: 

Dr. X University of School name in nowhere [email protected] Blah blah 3 one niner 

How would I get the email out of there? 

輸出:

--- 
- !!perl/array:Mail::Address 
    - '' 
    - [email protected] 
- [email protected]