I have a problem where i need to search for email addresses in a long string. I need to return all the occurences of matches, and not only one.
I've tried:
def email():
try:
a = re.search(r'abc.{1,11}@xyz.co.za|[email protected]',string)
return a.group(0)
except Exception:
return 1
and
def email():
try:
a = re.search(r'abc.{1,11}@xyz.co.za' or '[email protected]',string)
return a.group(0)
except Exception:
return 1
and
def email():
try:
a = re.search('abc.{1,11}@xyz.co.za',string)
b = re.search('[email protected]',string)
return a.group(0),b.group(0)
except Exception:
return 1
as well as other different combinations of this.
From the first script, I receive the first match of email address. From the second script I receive only one match From the third script i receive all the matches. My problem is that if one of them doesn't match, it returns 1.
What i would like to see is that it returns all the email addresses that matches, regardless of how many match.
a?r'(abc.{1,11}@xyz.co.za)|([email protected])'