regex - 基于正则表达式删除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'}=();
}
}
}
}
}
}
}
}
解决方案
尝试:
...
if ($key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'} =~ /^(?!962)/)
{
delete $key->{$_}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'};
}
变化:
要删除密钥,请使用delete
对于“不以”正则表达式开头,请使用:^(?!WHATEVER)
,例如^(?!962)
推荐阅读
- python - 错误UnicodeDecodeError:'utf-8'编解码器无法解码位置2的字节0xbe:无效的起始字节
- sql - ORA-04044: 此处不允许过程、函数、包或类型
- javascript - React.js datepicker 在时区之间转换
- python - os.write() 追加文件而不是覆盖,但不使用 O_APPEND
- cs50 - CS50 Pset 4 模糊 | 二进制表达式的无效操作数
- python - 如何将压缩的 MNIST 数据集提取到测试、训练集中?
- flutter - 升级颤振后 Xcode 构建的颤振错误输出
- javascript - 无法写入 Firebase 数据库
- django - Apache + mod_wsgi + django:为积压的请求发送默认响应
- python - 如何从python中的文本文件制作两个列表?