The following works
examples = ["john.doe@acme.com", "https://www.web-site.com", "Doe, John", "junk", r"\\computer\folder\file", "smtp://mailserver.acme.com"]
for text in examples:
match tuple(
i for i, e in
enumerate(
[
r"[A-Za-z0-9\.\-]+@[A-Za-z0-9\.\-]+$", # e-mail address pattern => 0
r"http[s]{0,1}://[A-Za-z0-9\/\.\-]*$", # url pattern => 1
r"[A-Za-z]+, [A-Za-z]+$" # name pattern => 2
]
)
if re.match(e, text) is not None
):
case (0,): print(f"'{text}' is an e-mail address")
case (1,): print(f"'{text}' is a url")
case (2,): print(f"'{text}' is a name")
case (0, 1) | (0, 2) | (1,2) | (0, 1, 2): print(f"'{text}' is impossible, because the patterns are mutually exclusive")
case _ : print(f"'{text}' is unrecognizable")
and results in
'john.doe@acme.com' is an e-mail address
'https://www.web-site.com' is a url
'Doe, John' is a name
'junk' is unrecognizable
'\\computer\folder\file' is unrecognizable
'smtp://mailserver.acme.com' is unrecognizable