#! /usr/bin/python """ reads text from standard input and outputs any email addresses it finds, one to a line. """ import re from sys import stdin # pat is a regular expression object with a pattern that approximates # a valid email address pat = re.compile(r'[-\w][-.\w]*@[-\w][-\w.]+[a-zA-Z]{2,4}') # if you iterate over a file (eg stdin) you get a line at a time for line in stdin: # findall(S) method returns a list matches of the re obj pattern to S for address in pat.findall(line): print address