I am trying to extract emails from text. I used re.search
, which returned the 1. occurrence, but then I went on and used re.findall
. To my surprise re.findall
finds less emails than re.search
. What could be the problem?
Code:
searchObj = re.search( r'[A-Za-z0-9\._+-]+@[A-Za-z0-9]+(\.|-)[A-Za-z0-9\.-]+', text)
if searchObj:
mail = searchObj.group()
if mail not in emails:
emails.add(mail)
listEmails = re.findall( r'[A-Za-z0-9\._+-]+@[A-Za-z0-9]+(\.|-)[A-Za-z0-9\.-]+', text)
for mail in listEmails:
if mail not in emails:
emails.add(mail)