import re


def extract_answer_text(options_text: str, answer_tag: str):
  """Extracts correct answer's text from all options.

  Args:
    options_text: all options as text in various format.
    answer_tag: correct answers tag a, b, c, ...

  Returns:
    parsed option text corresponding to the correct answer.
  """
  if options_text.startswith('[') and options_text.endswith(']'):
    options = eval(options_text)  # pylint: disable = eval-used
    options = [re.sub('[abcde] \\)', '', x).strip() for x in options]
  else:
    options = re.split('[abcde] \\)', options_text)
    if options[0]:
      raise ValueError(f'Expects first segment to be empty in {options}.')
    options = [x.strip().rstrip(',').strip() for x in options[1:]]
  correct_id = ord(answer_tag) - ord('a')
  if correct_id >= len(options):
    raise ValueError(f'Ill parsed dictionary {options} from {options_text}.')
  return options[correct_id]