import re
regex = re.compile(r"• (.+?)\s+- FF([A-F0-9]{2})([A-F0-9]{2})([A-F0-9]{2})", flags=re.MULTILINE | re.IGNORECASE)
test_str = (" • White - FFe4e4e4 \n"
" • Light Gray - FFa0a7a7 \n"
" • Dark Gray - FF414141 \n"
" • Black - FF181414 \n"
" • Red - FF9e2b27 \n"
" • Orange - FFea7e35 \n"
" • Yellow - FFc2b51c \n"
" • Lime Green - FF39ba2e \n"
" • Green - FF364b18 \n"
" • Light Blue - FF6387d2 \n"
" • Cyan - FF267191 \n"
" • Blue - FF253193 \n"
" • Purple - FF7e34bf \n"
" • Magenta - FFbe49c9 \n"
" • Pink - FFd98199 \n"
" • Brown - FF56331c")
subst = "\"$1\": [0x$2, 0x$3, 0x$4],"
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