import re
regex = re.compile(r"[A-Z]+:span-[0-9]+:[a-z]+:[A-Z]+:(?!Connected)[a-zA-Z]+")
test_str = ("message = 'OK - physical_ok:23/24 signal_up:23/24. Details: OK:span-1:ok:UP:Connected OK:span-2:ok:UP:Connected OK:span-3:ok:UP:Connected OK:span-4:ok:UP:Connected OK:span-5:ok:UP:Connected OK:span-6:ok:UP:Connected OK:span-7:ok:UP:Connected OK:span-8:ok:UP:Connected OK:span-9:ok:UP:Connected OK:span-10:ok:UP:Connected OK:span-11:alarmed:DOWN:Disconnected OK:span-12:ok:UP:Connected OK:span-13:ok:UP:Connected OK:span-14:ok:UP:Connected OK:span-15:ok:UP:Connected OK:span-16:ok:UP:Connected OK:span-17:ok:UP:Connected OK:span-18:ok:UP:Connected OK:span-19:ok:UP:Connected OK:span-20:ok:UP:Connected OK:span-21:ok:UP:Connected OK:span-22:ok:UP:Connected OK:span-23:ok:UP:Connected OK:span-24:ok:UP:Connected | physical_ok=23;24 signal_up=23;24\n")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html