Python-text-processing-python-extract-emails-from-text
提供:Dev Guides
Python-テキストからメールを抽出する
電子メールからテキストを抽出するために、正規表現を使用できます。 次の例では、正規表現パッケージを使用して電子メールIDのパターンを定義し、* findall()*関数を使用して、このパターンに一致するテキストを取得します。
import re
text = "Please contact us at contact@finddevguides.com for further information."+\
" You can also give feedbacl at feedback@tp.com"
emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", text)
print emails
上記のプログラムを実行すると、次の出力が得られます-
['contact@finddevguides.com', 'feedback@tp.com']