作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我当前的正则表达式可以识别免费电话号码,我想做的是查找非免费电话号码。这是我当前的代码:
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/
我是一名优秀的程序员,十分优秀!