import re
regex = re.compile(r"^(?!.*\b(\d+)\b.*\b\1\b) *[1-9]\d* *(?:, *[1-9]\d* *)*$", flags=re.MULTILINE)
test_str = ("992,1005,1007,992,456,456,1008\n"
"44,1005,1110\n"
"13, 44 , 1005, 10078 \n"
"11,1203,6666\n"
"1,11,99,2222\n"
"3435\n"
" 1234 ")
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