def to_digit(value):
    if value.isdigit():
        return int(value)
    match = RE_NUM.match(value)
    return (int(match.groups()[0]) if match else 0)
def to_digit(value):
    if value.isdigit():
        return int(value)
    match = RE_NUM.match(value)
    return (int(match.groups()[0]) if match else 0)