有没有办法找到正则表达式的反转

Is there a way to find the inverse of a regex

本文关键字:正则表达式 有没有      更新时间:2023-09-26

我当前的正则表达式可以识别免费号码,我正在尝试做的是查找不免费电话号码。这是我当前的代码:

    if ( phoneNumbers.match(/^('+?1)?(8(00|44|55|66|77|88)[2-9]'d{6})$/) && data.results[i].duration > 90 && data.results[i].disposition === "ANSWERED") {
        console.log(phoneNumbers);
    }

我尝试了以下表达式:

/^('+?!1)?!(8(00|44|55|66|77|88)[2-9]'d{6})$/
    if ( phoneNumbers/not().match(/^('+?1)?(8(00|44|55|66|77|88)[2-9]'d{6})$/) && data.results[i].duration > 90 && data.results[i].disposition === "ANSWERED") {
        console.log(phoneNumbers);
    }

但这似乎也行不通。甚至可以查找正则表达式的反转吗?

你想在javascript中使用的任何条件都可以用!"反转"

if(condition){
   //Here you do something if the condition is true
}
if(!condition){
    //Here you do something if the condition is false
}

在你绳子里

if(phoneNumbers.match(/^('+?1)?(8(00|44|55|66|77|88)[2-9]'d{6})$/)){
   //Here you have a toll free
}
if(!phoneNumbers.match(/^('+?1)?(8(00|44|55|66|77|88)[2-9]'d{6})$/)){
    //Here you have a NO toll free
}