(HELP) Stuck on regex exercise in Python course
As the title would suggest, I'm stuck on the exercise at the end of the regex module in the Python course. I polished off most of the module end of last week, couldn't get in on Monday, And now I've been staring at my screen for nearly two hours trying to solve this god damn exercise. As you may know, you are supposed to take a string of numbers as input and check if it's a valid phone number. A valid phone number is 8 characters long and starts with the numbers 1, 8, or 9. Checking the length was simple enough to do with the len function and some if statements, the problems started when I had to check the first character. I threw together a solution, hit run, and everything came back invalid. I've tried a whole host of different methods and done quite a bit of googling, but I still can't get something that that actually meets the requirements. I've been at this for nearly two hours and am near-totally out of ideas, So I'm turning to the community over here for help. Am I doing something wrong? Am I missing something? Whatever it is, I hope someone else can see it. In the interests of problem-solving, here is the code as it currently stands: import re phonenum = str(input) pattern = r"^[1|8|9]" if len(phonenum) == 8: if re.match(pattern, phonenum): print("Valid") else: print("Invalid") else: print("Invalid") UPDATE: It's done. thanks to everyone in the comments.