import re


def parse_hgvs(hgvs):
    """
    Parse an hgvs (or hgvs-like) description of a tandem repeat unit

    :param hgvs: a string containing the variant description
    :return: a dictionary containing of the form
        {
            "start": start_position,
            "end": end_position,
            "unit": the repeat unit string
            "count": the number of repeats
        }
    """
    regex_string = "(?P<start>[0-9]+)_(?P<end>[0-9]+)(?P<unit>[A-Za-z]*)\[(?P<count>[0-9]+)\]"
    regex = re.compile(regex_string)

    match = regex.match(hgvs)

    assert match is not None, "description could not be parsed"
    if len(match.group("unit")) > 0:
        assert len(match.group("unit")) == int(match.group("end")) + 1 - int(match.group("start")), "range and sequence do not match"

    return {
        "start": int(match.group("start")),
        "end": int(match.group("end")),
        "unit": match.group("unit"),
        "count": int(match.group("count"))
    }