Reputation: 642
given an string containing one or more email addresses,how can I go about writing a function that prints all valid email addresses of the string. consider code below which can decide if the string is exactly an email address ,meaning it can not decide if a string contains an email address. How can I develop this code, so it will check if a string contains one or more email addresses and then print them ?
import re
def check(email):
return re.match(r'[^@]+@[^@]+\.[^@]+', email) != None
Upvotes: 0
Views: 106
Reputation: 460
Use re.findall:
emails = re.findall('[^@ ]+@[^@ ]+\.[^@ ]+', stringWithEmails)
Edit: Well, probably you'll need a better RE for matching e-mails, see this question, for example.
Upvotes: 2