Просто хочу поделиться грубой идеей ...
import re
soe = "abc_123@123.com ,you@yahoo.com , we@gmail.co.uk, gmail.com, me@outlook.com ,"
soel = soe.split(',')
#first entry cannot have space
if soel[0].count(" ")!=0 :
print("Error\t\t:: First entry cannot contain space!")
#then, all subsequent must start with and contain exactly one space, along with a valid email
for email in soel[1:]:
if email.count(" ") > 1:
print("Invalid entry\t::" + email, ":: too many spaces")
continue
#simple email regex (with a single space in front)
match = re.search(r' ([\w\.-]+)@([\w\.-]+)', email)
if match == None:
print("Invalid entry\t::" + email + ":: make sure it follows the rule!")
else:
print("Valid entry\t::" + email)
или, для более подробной информации,
import re
soe = " abc_123@123.com,you@yahoo.com , we@gmail.co.uk, gmail.com, me@outlook.com ,"
soel = soe.split(',')
end = len(soel)
if soel[-1].strip()=='':
print("Error:: Comma near the end of string!")
end -= 1
if soel[0].count(" ")>0:
print("Error:: First entry cannot contain space!")
for email in soel[1:end]:
if email.count(" ") != 1 :
print("Error:: " + email + " :: too many spaces!")
continue
if not email.startswith(" "):
print("Error:: " + email + " :: one space is needed after comma!")
continue
#simple email regex
match = re.search(r'([\w\.-]+)@([\w\.-]+)', email)
if match != None:
print("Correct format: " + match.group())