In: Computer Science
I am confused with Python I have to write a specification for an email address. In one string a valid email address and the other without a valid email address.
Ex:
print(text_match("My teacher’s email is [email protected]"))
print(text_match("My teacher has no email address"))
Thanks for the question. Below is the code you will be needing. We need to use the re (Regular Expression) module to check if the email satisfies the email format. Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! =========================================================================== import re def text_match(email): regex = '^.+[@]\w+[.]\w{2,3}$' pattern = re.compile(regex) if (pattern.search(email)): return 'Valid' else: return 'Invalid' print(text_match("My teacher’s email is [email protected]")) print(text_match("My teacher has no email address"))
======================================================================