import re
regex = re.compile(r"(?:\b|_)(?!\d+\b|[A-Z]+\b)([A-Z\d]{10})(?:\b|_)", flags=re.MULTILINE)
test_str = ("LEGION T5 (90SV003WGE)\n"
"FLEX 5 (82R700BEGE) XKLUSIV\n"
"V17-IRU 83A2001NGE\n"
"LENOVO E16 G1 21JT000HGE_WIN 11\n"
"LENOVO THINKCENTRE M70T 12Q6000AGE I7-12\n"
"IDEAPAD 3 17ALC6\n"
"TEST 12345ABCDE TEST ZYXWV98765")
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