def define_field(key: str, pattern: str = r'[^\s\'"]+') -> str:
    """Gives a regex pattern for a key/value with a named group for value; 'pattern'
    is the regex for the value. The value may optionally be single or double quoted.
    E.g. key='map', pattern='\w+' will match "map 'e'" and groupdict()['map']='e'
    """
    return rf"""^{key}(?:\s+|\s*[:=]\s*)(?:"(?={pattern}")|'(?={pattern}'))?(?P<{key}>{pattern})['"]?$"""