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