in src/alpaca_eval/utils.py [0:0]
def _find_first_match(text: str, outputs_to_match: dict[str, Any]) -> tuple[Any, Any]:
"""Given text to parse and a dictionary of compiled regex to match, return the first match and corresponding key."""
first_match = None
first_key = None
for key, compiled_regex in outputs_to_match.items():
match = compiled_regex.search(text)
if match and (not first_match or match.start() < first_match.start()):
first_match = match
first_key = key
return first_match, first_key