def parse_stat(stat):
    """Parses the stat html text to get rank, code, and count"""
    stat_clean = stat.replace('\n', ' ').replace('.', '').strip()
    stat_list = stat_clean.split(' ')

    rank = stat_list[0]
    code = code_orig = ' '.join(stat_list[1:-1])
    # remove xx and dd from the end of the code so we can get more matches
    # Note: rstrip will remove 'd' even if it doesn't find 'dd' ...
    if code.endswith('dd') or code.endswith('xx'):
        code = code[:-2]
    count = stat_list[-1]

    return [rank, code, code_orig, count]