

def _maybe_strip_national_prefix_carrier_code(number, metadata):
    'Strips any national prefix (such as 0, 1) present in a number.\n\n    Arguments:\n    number -- The normalized telephone number that we wish to strip any\n              national dialing prefix from\n    metadata -- The metadata for the region that we think this number\n              is from.\n\n    Returns a 3-tuple of\n     - The carrier code extracted if it is present, otherwise an empty string.\n     - The number with the prefix stripped.\n     - Boolean indicating if a national prefix or carrier code (or both) could be extracted.\n     '
    carrier_code = U_EMPTY_STRING
    possible_national_prefix = metadata.national_prefix_for_parsing
    if ((len(number) == 0) or (possible_national_prefix is None) or (len(possible_national_prefix) == 0)):
        return (U_EMPTY_STRING, number, False)
    prefix_pattern = re.compile(possible_national_prefix)
    prefix_match = prefix_pattern.match(number)
    if prefix_match:
        national_number_pattern = re.compile((metadata.general_desc.national_number_pattern or U_EMPTY_STRING))
        is_viable_original_number = fullmatch(national_number_pattern, number)
        num_groups = len(prefix_match.groups())
        transform_rule = metadata.national_prefix_transform_rule
        if ((transform_rule is None) or (len(transform_rule) == 0) or (prefix_match.groups()[(num_groups - 1)] is None)):
            national_number_match = fullmatch(national_number_pattern, number[prefix_pattern.end():])
            if (is_viable_original_number and (not national_number_match)):
                return (U_EMPTY_STRING, number, False)
            if ((num_groups > 0) and (prefix_match.groups(num_groups) is not None)):
                carrier_code = prefix_match.group(1)
            return (carrier_code, number[prefix_match.end():], True)
        else:
            transformed_number = re.sub(prefix_pattern, transform_rule, number, count=1)
            national_number_match = fullmatch(national_number_pattern, transformed_number)
            if (is_viable_original_number and (not national_number_match)):
                return ('', number, False)
            if (num_groups > 1):
                carrier_code = prefix_match.group(1)
            return (carrier_code, transformed_number, True)
    else:
        return (carrier_code, number, False)

dataset/ETHPy150Open daviddrysdale/python-phonenumbers/python/phonenumbers/phonenumberutil.py _maybe_strip_national_prefix_carrier_code/VarMisuse@174/478 `prefix_match`->`prefix_pattern`