import re


def byteform_to_num(byte_format):
    """Converts a string expressing a size of a file in bytes into the
        corresponding number of bytes. Accepts commas and decimal points in nums.
        Allows 'b', 'mb', 'gb', and variants like 'bytes', but not 'tb', 'zb', etc.
    Note that format_bytes is a lossy function (it doesn't retain all sigfigs
        by default), so byteform_to_num(format_bytes(x)) does not always equal x.
    """
    x = re.findall("([\d,\.]+)\s*([a-z]*)", byte_format, re.I)[0]
    num, suf = float(x[0].replace(",", "")), x[1].lower()
    if suf == "" or suf[0] == "b":
        return num
    elif suf[:2] == "kb":
        return num * 1e3
    elif suf[:2] == "mb":
        return num * 1e6
    elif suf[:2] == "gb":
        return num * 1e9

    raise ValueError(f"byteform_to_num couldn't recognize quantifier '{suf}'")