Python
# Program to validate email using regex
import re
email = input("Enter email: ")
pattern = r"^[\w\.-]+@[\w\.-]+\.\w+$"
if re.match(pattern, email):
print("Valid email")
else:
print("Invalid email")Output
Enter email: [email protected] Valid email
Another example of using regular expressions to validate an email-like pattern.