import re
regex = re.compile(r"((?<!\d|\.)([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?!\d|\.) *[,;] *){2}(?<!\d|\.)([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(?!\d|\.)", flags=re.IGNORECASE)
test_str = ("RGBA: (0-255) 204, 128, 128, 255\n"
"RGBA: (0-255) 4, 128, 128, 255\n"
"RGBA: (0-255) 204, 18, 928, 255\n"
"RGBA: (0-255) 304, 1, 18, 255\n"
"RGBA: (0-255) 204, 28, 128, 25, 25, 255, 152, 12\n"
"RGBA: (0-255) 204, 128, 8, 5\n"
"RGBA: (0-255) 204, 128, 128, 355\n"
"RGBA: (0-255) 204, 128, 128, 265\n"
"RGBA: (0-255) 204, 128, 128, 256\n\n"
"bonjour, 18, 928, 255\n\n"
"RGBA: (0-1) 0.8, 0.502, 0.502, 1\n"
"RGB: #cc8080\n"
"RGBA: #cc8080ff\n"
"ARGB: #ffcc8080\n"
"CMYK: 0, 37, 37, 19\n"
"HSLA: 360, 43, 65, 1")
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