

def _format_nsn_using_pattern(national_number, formatting_pattern, number_format, carrier_code=None):
    number_format_rule = formatting_pattern.format
    m_re = re.compile(formatting_pattern.pattern)
    formatted_national_number = U_EMPTY_STRING
    if ((number_format == PhoneNumberFormat.NATIONAL) and (carrier_code is not None) and (len(carrier_code) > 0) and (formatting_pattern.domestic_carrier_code_formatting_rule is not None) and (len(formatting_pattern.domestic_carrier_code_formatting_rule) > 0)):
        cc_format_rule = formatting_pattern.domestic_carrier_code_formatting_rule
        cc_format_rule = re.sub(_CC_PATTERN, carrier_code, cc_format_rule, count=1)
        number_format_rule = re.sub(_FIRST_GROUP_PATTERN, cc_format_rule, number_format_rule, count=1)
        formatted_national_number = re.sub(m_re, number_format_rule, national_number)
    else:
        national_prefix_formatting_rule = formatting_pattern.national_prefix_formatting_rule
        if ((number_format == PhoneNumberFormat.NATIONAL) and (national_prefix_formatting_rule is not None) and (len(national_prefix_formatting_rule) > 0)):
            first_group_rule = re.sub(_FIRST_GROUP_PATTERN, national_prefix_formatting_rule, number_format_rule, count=1)
            formatted_national_number = re.sub(m_re, first_group_rule, national_number)
        else:
            formatted_national_number = re.sub(m_re, number_format_rule, national_number)
    if (m_re == PhoneNumberFormat.RFC3966):
        m = _SEPARATOR_PATTERN.match(formatted_national_number)
        if m:
            formatted_national_number = re.sub(_SEPARATOR_PATTERN, U_EMPTY_STRING, formatted_national_number, count=1)
        formatted_national_number = re.sub(_SEPARATOR_PATTERN, U_DASH, formatted_national_number)
    return formatted_national_number

dataset/ETHPy150Open daviddrysdale/python-phonenumbers/python/phonenumbers/phonenumberutil.py _format_nsn_using_pattern/VarMisuse@233/418 `number_format`->`m_re`