import re


def extract_flag_from_string(str, var_name):
    """Parse a flag value from a string formatted as a flagfile is.

    Args:
        str (str): String expected to be in the format of a flagfile, i.e.
            --a=a.val --b=b.val
        flag_name (str): Name of the flag.

    Returns:
        _: Value corresponding to the flag. If the flag does not exist in
            the flagfile, an empty result will be given.
    """
    m = re.findall(f"--{var_name}=(.*)", str)
    return m[0] if len(m) == 1 else ""