import re


def parse_hardware(hardware_string):
    """Extract fields from the hardware string."""
    m = re.match(
        r"(?P<cpu_type>[^,;]+), (?P<cpu_freq>\d+) MHz, (?P<ram>\d+)MB RAM, (?P<flash>\d+)MB FLASH",
        hardware_string,
    )
    if not m:
        raise ValueError("hardware string was not recognized: regex did not match")
    return {
        "cpu_type": m.group("cpu_type"),
        "cpu_freq": int(m.group("cpu_freq")),
        "ram": int(m.group("ram")),
        "flash": int(m.group("flash")),
    }