gpt4 book ai didi

javascript - 有没有办法找到正则表达式的逆

转载 作者:行者123 更新时间:2023-11-30 16:19:24 25 4
gpt4 key购买 nike

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

    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
}

关于javascript - 有没有办法找到正则表达式的逆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34963669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com