import re
regex = re.compile(r"\[\[ *([0-9]{3}0)[^]]*\| *([0-9]{3}[^0]) *\]\]|\[\[ *([0-9]{3}1)[^]]*\| *([0-9]{3}[^5]) *\]\]|\[\[ *([0-9]{3}2)[^]]*\| *([0-9]{3}[^2]) *\]\]|\[\[ *([0-9]{3}3)[^]]*\| *([0-9]{3}[^3]) *\]\]|\[\[ *([0-9]{3}4)[^]]*\| *([0-9]{3}[^4]) *\]\]|\[\[ *([0-9]{3}5)[^]]*\| *([0-9]{3}[^5]) *\]\]|\[\[ *([0-9]{3}6)[^]]*\| *([0-9]{3}[^6]) *\]\]|\[\[ *([0-9]{3}7)[^]]*\| *([0-9]{3}[^7]) *\]\]|\[\[ *([0-9]{3}8)[^]]*\| *([0-9]{3}[^8]) *\]\]|\[\[ *([0-9]{3}9)[^]]*\| *([0-9]{3}[^9]) *\]\]|\[\[ *([0-9]{2}0[0-9])[^]]*\| *([0-9]{2}[^0][0-9]) *\]\]|\[\[ *([0-9]{2}1[0-9])[^]]*\| *([0-9]{2}[^1][0-9]) *\]\]|\[\[ *([0-9]{2}2[0-9])[^]]*\| *([0-9]{2}[^2][0-9]) *\]\]|\[\[ *([0-9]{2}3[0-9])[^]]*\| *([0-9]{2}[^3][0-9]) *\]\]|\[\[ *([0-9]{2}4[0-9])[^]]*\| *([0-9]{2}[^4][0-9]) *\]\]|\[\[ *([0-9]{2}5[0-9])[^]]*\| *([0-9]{2}[^5][0-9]) *\]\]|\[\[ *([0-9]{2}6[0-9])[^]]*\| *([0-9]{2}[^6][0-9]) *\]\]|\[\[ *([0-9]{2}7[0-9])[^]]*\| *([0-9]{2}[^7][0-9]) *\]\]|\[\[ *([0-9]{2}8[0-9])[^]]*\| *([0-9]{2}[^8][0-9]) *\]\]|\[\[ *([0-9]{2}9[0-9])[^]]*\| *([0-9]{2}[^9][0-9]) *\]\]", flags=re.IGNORECASE)
test_str = ("[[1900]] [[1900 en truc|1901]]\n"
"[[1901|1900]]\n"
"[[1900 en truc|1900]]\n"
"[[1900 en truc|1901]]\n"
"[[1904 en truc|1901]]\n"
"[[1900|1901]]\n"
"[[1900 en truc|1901]] [[1900 en truc|1900]] [[1900 en truc|1910]]\n\n"
"[[1940 en truc|1910]]\n"
"[[1940|1910]]\n\n\n"
"\\[\\[ *([0-9]{3}0)[^]]*\\| *([0-9]{3}[^0]) *\\]\\]\n"
"\\[\\[ *([0-9]{3}1)[^]]*\\| *([0-9]{3}[^5]) *\\]\\]\n"
"\\[\\[ *([0-9]{3}2)[^]]*\\| *([0-9]{3}[^2]) *\\]\\]\n"
"\\[\\[ *([0-9]{3}3)[^]]*\\| *([0-9]{3}[^3]) *\\]\\]\n"
"\\[\\[ *([0-9]{3}4)[^]]*\\| *([0-9]{3}[^4]) *\\]\\]\n"
"\\[\\[ *([0-9]{3}5)[^]]*\\| *([0-9]{3}[^5]) *\\]\\]\n"
"\\[\\[ *([0-9]{3}6)[^]]*\\| *([0-9]{3}[^6]) *\\]\\]\n"
"\\[\\[ *([0-9]{3}7)[^]]*\\| *([0-9]{3}[^7]) *\\]\\]\n"
"\\[\\[ *([0-9]{3}8)[^]]*\\| *([0-9]{3}[^8]) *\\]\\]\n"
"\\[\\[ *([0-9]{3}9)[^]]*\\| *([0-9]{3}[^9]) *\\]\\]\n"
"\\[\\[ *([0-9]{2}0[0-9])[^]]*\\| *([0-9]{2}[^0][0-9]) *\\]\\]\n"
"\\[\\[ *([0-9]{2}1[0-9])[^]]*\\| *([0-9]{2}[^1][0-9]) *\\]\\]\n"
"\\[\\[ *([0-9]{2}2[0-9])[^]]*\\| *([0-9]{2}[^2][0-9]) *\\]\\]\n"
"\\[\\[ *([0-9]{2}3[0-9])[^]]*\\| *([0-9]{2}[^3][0-9]) *\\]\\]\n"
"\\[\\[ *([0-9]{2}4[0-9])[^]]*\\| *([0-9]{2}[^4][0-9]) *\\]\\]\n"
"\\[\\[ *([0-9]{2}5[0-9])[^]]*\\| *([0-9]{2}[^5][0-9]) *\\]\\]\n"
"\\[\\[ *([0-9]{2}6[0-9])[^]]*\\| *([0-9]{2}[^6][0-9]) *\\]\\]\n"
"\\[\\[ *([0-9]{2}7[0-9])[^]]*\\| *([0-9]{2}[^7][0-9]) *\\]\\]\n"
"\\[\\[ *([0-9]{2}8[0-9])[^]]*\\| *([0-9]{2}[^8][0-9]) *\\]\\]\n"
"\\[\\[ *([0-9]{2}9[0-9])[^]]*\\| *([0-9]{2}[^9][0-9]) *\\]\\]\n\n\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