首页 > 解决方案 > 基于正则表达式删除msisdn元素

问题描述

我正在尝试msisdn从 TAP3.11 上的 MO 调用中删除字段,但它不能处理所需的内容。

我想设置一个条件,如果 Msisdn 不是以 962 开头,则删除该元素。

我的背景只有python,这是第一次使用perl。我使用它是因为经过搜索我相信只有 perl 可以处理 TAP 文件。

# Will scan all the calls for MTC's.
foreach $key ( @{$struct->{'transferBatch'}->{'callEventDetails'} } ) {

    foreach ( keys %{$key} ) {

        if ( $_ eq "mobileOriginatedCall" )
        {
            if ( defined $key->{$_}->{'basicCallInformation'} )
            {
                if ( defined $key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'} )
                {
                    if ( defined $key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'})
                    {
                        if ( defined $key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'})
                        {
                            if ($key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'} =~ /^[962]/)
                            {
                                $key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'}=();
                            }
                        }
                    }
                }
            }
        }
    }
}

标签: regexperl

解决方案


尝试:

...
if ($key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'} =~ /^(?!962)/)
{
    delete $key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'};
}

变化:

要删除密钥,请使用delete

对于“不以”正则表达式开头,请使用:^(?!WHATEVER),例如^(?!962)


推荐阅读