2010-11-24 7 views
0

をメールでお知らせします。可能性の重複:
How to extract email address from a string using perl?文字列から

私はこのような文字列があるとしましょう:

博士はX大学の名前どこピートに@ school.edu Blah blah 3 one niner

どうすれば電子メールをそこから取り出すことができますか?

+0

いや、ない正確な複製。これは自由に流れるテキストから電子メールアドレスを抽出することです。 –

+0

それがあなたの問題なら、間違いない大文字小文字のフラグではなく、 '[A-Z]'で正規表現を使うべきではありません。 – Axeman

答えて

-2

あなたは言葉を言うことはありませんが、この方法で使用できます。

http://www.codeproject.com/KB/vb/extractemail.aspx http://www.webdeveloper.com/forum/showthread.php?t=200875

をし、多くがありましたGoogleの他のユーザー(違反行為ではなく、私があなたを助けて見たもの)

+3

彼は言語にタグをつけた。 – cdhowie

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]