'Converts a string like
\'%(title)s - %(artist)s\'
to a regex like
\'(?P<title>.+)\ \-\ (?P<artist>.+)\''

def format_to_regex(self, fmt):

    lastpos = 0
    regex = u''
    for match in re.finditer(u'%\\((\\w+)\\)s', fmt):
        regex += re.escape(fmt[lastpos:match.start()])
        regex += ((u'(?P<' + match.group(1)) + u'>.+)')
        lastpos = match.end()
    if (lastpos < len(fmt)):
        regex += re.escape(fmt[lastpos:])
    return regex
