layout = '%(group)s/foo-%(locale)s/file.txt'
print(format_to_re(layout))
pattern = re.compile(format_to_re(layout))
print(pattern.match('something/foo-en-gb/file.txt').groupdict())
Python: Convert format string to regular expression