import re


def _get_match(
    prefix_pattern, code_pattern, s, result_prefix, result_zeropad=0
):
    """
    Extract ontology codes from strings

    Coerces values to consistent output formats and allows truncated
    input numbers, and optional input prefixes. Prefixes can be separated by
    either : or _, and outputs are given consistent prefixes and zero padding
    """
    s = s.strip().upper()

    if prefix_pattern:
        prefix_pattern = f"(?:{prefix_pattern}[:_])?"

    if re.compile(code_pattern).groups == 0:
        code_pattern = f"({code_pattern})"

    capture_pattern = f"^{prefix_pattern}{code_pattern}$"
    assert re.compile(capture_pattern).groups == 1

    match = re.match(capture_pattern, s)
    if match:
        return f"{result_prefix}{match.group(1).zfill(result_zeropad)}"
    else:
        return None