Search code examples
pythonregexrawstring

re.search ingores "+" sign when adding a "r" for raw string


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 [email protected]

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?


Solution

  • . matches whitespace also.

    You can try

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

    See demo.

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