import re
regex = re.compile(r"[A-Z0-9-\/_]{7,}", flags=re.IGNORECASE | re.MULTILINE)
test_str = ("Te poniższe bym chciał:\n"
"ZOC1050056\n"
"23639583\n"
"GL20/11878/17\n"
"20700246365_1\n"
"WR50/11349/17\n"
"PL201709120448\n"
"pl2017072600414\n"
"1054332/1133787\n"
"H201709201932-01\n"
"143392/DLS/17 KO/455/17\n\n"
"a to już false positives:\n\n"
"bardzodlugieslowo\n"
"niechcetegoo?")
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