import re


def _parse_length(txt):
    """
    extract length and unit from a given css string
    """
    if txt == "auto":
        return 100, "%"
    result = re.search(r"(?P<val>[\d.]*?)(?P<unit>(pt|px|em|rem|cm|ex|in|%))", txt)
    if result is None:
        raise ValueError("Cannot parse length! Please enter valid unit: {}".format(txt))
    unit = result.group("unit")
    try:
        length = float(result.group("val"))
    except ValueError:
        length = None
    return length, unit