0

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
Lev Levitsky
  • 59,844
  • 20
  • 139
  • 166
Soheil
  • 612
  • 1
  • 8
  • 17

1 Answers1

2

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.

Community
  • 1
  • 1
pvgoran
  • 440
  • 3
  • 13