I have a list of multiple items. Need to create a loop that finds an item from the list and prints it out. If item not found prints out only once that it hasn't been found.
for x in range(len(regs)):
rex = regs[x]
if re.match(rex,hostname):
print (dev[x],'Regex matched')
break
else:
print('wrong format')
Currently it prints out multiple times that it hasn't been found. When it matches the regex it prints out at the end. I only want the If Else to prints "wrong format" once.
currently prints out wrong format wrong format wrong format wrong format wrong format wrong format wrong format "DeviceX Regex matched"
Aucun commentaire:
Enregistrer un commentaire