-2
import re

email = input("What's your email? ").strip()

if re.search(r"^.+@.+\.edu$", email):
    print("Valid")
else:
    print("Invalid")

(FYI: I'm a total beginner when it comes to python) I'm learning with the help of HarvardX CS50P and have come across a problem.

if re.search(r"^.+@.+\.edu$", email):

when adding the r, the plus sign is turning white and is not doing what it's supposed to.

the input:

My email address is malan@harvard.edu

the code regards it as Valid even tho it should return as Invalid. Is there maybe a problem with how i set up VScode? I've tried uninstalling regex and installing it again but did not help.

Any Idea what could be the Problem?

oriasirmi
  • 1
  • 1

1 Answers1

0

. matches whitespace also.

You can try

^\S+@\S+\.edu$

See demo.

https://regex101.com/r/4gNW4f/1

vks
  • 67,027
  • 10
  • 91
  • 124