def format_to_re(format):
    parts = (format % MarkPlaceholders()).split(UNIQ)
for i in range(0, len(parts), 2):
    parts[i] = re.escape(parts[i])
return ''.join(parts)
Python: Convert format string to regular expression