def METHOD_NAME(fmt):
    r"""
    Converts a string like
       '%(title)s - %(artist)s'
    to a regex like
       '(?P<title>.+)\ \-\ (?P<artist>.+)'
    """
    if not re.search(r'%\(\w+\)s', fmt):
        return fmt
    lastpos = 0
    regex = ''
    # replace %(..)s with regex group and escape other string parts
    for match in re.finditer(r'%\((\w+)\)s', fmt):
        regex += re.escape(fmt[lastpos:match.start()])
        regex += rf'(?P<{match.group(1)}>.+)'
        lastpos = match.end()
    if lastpos < len(fmt):
        regex += re.escape(fmt[lastpos:])
    return regex