0
import re

def validate_email(email):
    pattern = r'^(?:(?:[a-zA-Z0-9_-]+\.)*[a-zA-Z0-9_-]+@)?(?:[a-zA-Z0-9_-]+\.)?example\.com$'
    return re.match(pattern, email)

emails = [
    "[email protected]",
    "[email protected]",
    "[email protected]",
    "[email protected]",
]

for email in emails:
    if validate_email(email):
        print(f"{email} is a valid email.")
    else:
        print(f"{email} is NOT a valid email.")

In this code, the regular expression is designed to match email addresses that belong to the domain example.com and can include optional subdomains. It should handle variations like [email protected], [email protected], and [email protected]. but its not working as expected

prabu naresh
  • 405
  • 1
  • 10

0 Answers0