Reg ex doubt regarding the output

Screenshot 2023-03-03 222923
This is a python programme to check the domain name of website,i am getting an ouput like this…but the expected output must be like “commercial domain”.
what is the error in this code
@dsedyoda

@vimalgeorge1999

Why are you using the loop?

Screenshot 2023-03-04 103719
mam, for the same code which used for checking the email domain its working fine and i’m getting the right output…for checking website domain the answer gone wrong…

1 Like

@vimalgeorge1999

For checking website domain we have to change our approach because we have more than one dots (.) In the website name. And as I know here finditer is not checking for dot (.).
Please use different approach for website domain name checking because for loop will iterate to full length when match will be dot (.).

I am giving you one example for one approach

import re

commercial_pattern = r’^www.[a-zA-Z0-9-]{1,63}.com$’

org_pattern = r’^www.[a-zA-Z0-9-]{1,63}.org$’

website to check

website = ‘www.example.com

if re.match(commercial_pattern, website):
print(f"{website} is a commercial website")

elif re.match(org_pattern, website):
print(f"{website} is an organizational website")

else:
print(f"{website} is neither a commercial nor an organizational website")