75/100 - задача 4 от пайтън фундаменшълс (регулярни изрази) "4. Extract Emails"
4. Extract Emails
Write a program that receives a single string and extracts all email addresses from it. Print the extracted email
addresses on separate lines. Emails are in the format "{user}@{host}", where:
   •    {user} could consist only of letters and digits; the symbols ".", "-" and "_" can appear between them.
            o   Examples of valid users: "stephan", "mike03", "s.johnson", "st_steward", "softuni-
                bulgaria", "12345"
            o   Examples of invalid users: ''--123", ".....", "nakov_-", "_steve", ".info"
   •    {host} is a sequence of at least two words, each couple of words must be separated by a single dot ".".
        Each word consists of only letters and can have hyphens "-" between the letters.
            o   Examples of valid hosts: "softuni.bg", "software-university.com",
                "intoprogramming.info", "mail.softuni.org"
            o   Examples of invalid hosts: "helloworld", ".unknown.soft." , "invalid-host-",
                "invalid-"
Examples of valid emails: info@softuni-bulgaria.org, kiki@hotmail.co.uk, no-reply@github.com,
s.peterson@mail.uu.net, info-bg@software-university.software.academy
Examples of invalid emails: --123@gmail.com, …@mail.bg, .info@info.info, _steve@yahoo.cn,
mike@helloworld, mike@.unknown.soft., s.johnson@invalid-
Examples
                                        Input                                                       Output
 Please contact us at: support@github.com.                                             support@github.com
 Just send email to s.miller@mit.edu and j.hopking@york.ac.uk                          s.miller@mit.edu
 for more information.                                                                 j.hopking@york.ac.uk
 Many users @ SoftUni confuse email addresses. We @                                    steve.parker@softuni.de
 Softuni.BG provide high-quality training @ home or @ class.
 –- steve.parker@softuni.de.
Моето 108-мо решение:
import re
s = str(input())
if len(s) > 0 and '.' == s[-1]: s = s[:len(s)-1]
for e in s.split():
    e = e.lower()
    m = e.split("@")
    if len(m) != 2: continue;
    a = re.fullmatch(r'([a-z0-9][a-z0-9\.\-_]*[a-z0-9]|[a-z0-9])', m[0])
    if not a: continue;
    n = m[1].split(".")
    if len(n) < 2: continue;
    p = False
    for q in n:
        if not re.fullmatch(r'([a-z][a-z\-]*[a-z]|[a-z])', q):
            p = True
            break;
    if p: continue
    print(e)
75/100
Свел съм нещата до максимално простички. Кое от условията не покривам? (Имам и вариант без регулярни изрази който филтрира варианти като a--b@foo.net - не е това)
Бихте ли дали насоки за валиден/невалиден вх./изх.
Благодаря предварително.