def extract_answer(response_text):
    """
    Extract the answer from the response.
    For example, "xxxxx. Answer: (A) a gas." -> "A"
    If extraction fails, return the entire string after "Answer: ".
    """
    # Attempt to match the format "Answer: (A)" or "Answer: (a)" in case-sensitive manner
    match = re.search(r"Answer: \(([A-Z])\)", response_text)
    if match:
        return match.group(1).upper()  # Return as uppercase
    else:
        # Fallback: match the format "Answer: " followed by any characters until the next period or end of line
        fallback_match = re.search(r"Answer: ([^\.]+)", response_text)
        if fallback_match:
            return fallback_match.group(1).strip()
    return response_text

    Extract the answer from the response.
    For example, "xxxxx. Answer: (A) a gas." -> "A"
    If extraction fails, return the entire string after "Answer: ".
    
textgrad/tasks/multimodal/scienceqa.py