import re


def parse_organ_region_ontology_id(term):
    """Extract term id from valid identifiers or raise a ValueError
    """
    try:
        ontology_shortname, term_id = re.split("[_:]", term)
        if ontology_shortname == "MBA":
            # remove leading zeroes (e.g. '000786' => '786') since the dictionary file doesn't have them
            return term_id.lstrip("0")
        else:
            error_msg = f'organ_region: Invalid ontology code, "{ontology_shortname}"'
            raise ValueError(error_msg)
    except (TypeError, ValueError):
        # when term value is empty string -> TypeError, convert this to a value error
        raise ValueError(
            f'organ_region: Could not parse provided ontology id, "{term}"'
        )