Doing a practice problem for Python. Nothing is printing out. I've tried a lot of different things in the pattern variable. pattern = '@gmail\.com'
works just fine for the code, but I wanted to be precise with the parameters.
pattern = '^[a-z]{1,20}\s+[a-z]{1,50}@gmail\.com$'
works at Rubular.com utilizing the rules shown below on their website. When I do use the above pattern on Python, the syntax error occurs at the carrot or curly brackets. I would like some explanation on what is wrong with the above line of code.
The pattern should be firstName emailID@gmail.com
Constraints
- First name should be at most 20 characters (edit: and should be lowercase).
- Email ID is at most 50 characters (edit: and should be lowercase).
- All emails should be @gmail.com
My Code
import math
import os
import random
import re
import sys
def appendUserName(firstNameEmailID):
pattern = '^[a-z]{1,20}\s+[a-z]{1,50}@gmail\.com$'
if re.search(pattern,emailID):
userList.append(firstName)
if __name__ == '__main__':
N = int(input())
userList = []
for N_itr in range(N):
firstNameEmailID = input().split()
firstName = firstNameEmailID[0]
emailID = firstNameEmailID[1]
appendUserName(firstNameEmailID)
print(*sorted(userList), sep = '\n')