import re
regex = re.compile(r"(?<=^|$|[\s,\/-])(?:(?P<var1>(?<![\/-])(?!(?:(\d+(?:[,.][05])?)[\/-]){2}(?-1))(\d+(?:[,.][05])?)[\/-](?-1)|(?-1)))(?=^|$|[\s,\/-])", flags=re.UNICODE | re.IGNORECASE)
test_str = ("32/34, 36/38, 40/42, 44/46\n"
"40/42/44/46/48\n"
"58/60\n"
"39-42\n"
"40-50-60\n"
"24-25,26,28,30\n"
"36 40,5 44\n")
subst = "\\g<var1>\\n"
result = regex.sub(subst, test_str)
if result:
print(result)
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