import re
regex = re.compile(r"(?<=attn\s)(?:[0-9]{1,2}|1[01][0-9]|12[0-8])$", flags=re.MULTILINE)
test_str = ("_4ÑZŸs_4ÑZâ7o[?1034h\n"
"_4ÑZ8obash-3.2$ e4ÑZ”C\n"
"i[A e4ÑZõD\n"
"oscript -re4ÑZˇ?\n"
"i[Ae4ÑZ∑@\n"
"opython go.pyf4ÑZÌ\n"
"i\n"
"f4ÑZ£Ì\n"
"o\n"
"f4ÑZÊÚoattn 0\n"
"f4ÑZ,Ûoattn 0\n"
"attn 0\n"
"Hf4ÑZuÛoattn 99\n"
"attn 100\n"
"attn 0\n"
"attn 0\n"
"attn 0\n"
"attn 128\n"
"attn 0")
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