"""
    %(delim)s(?:
      (?P<escaped>%(delim)s) |   
      (?P<named>%(id)s)      |   
      {(?P<braced>%(id)s)}   |   
      (?P<invalid>^$)            
    )
    """
String substitutions using templates in Python