测试网址是否不包含集合

Testing if URL does not contain set

本文关键字:包含 集合 是否 测试      更新时间:2023-09-26
 if(/'/?p('d+)$/.test(window.location.pathname)) {
      } else {
        if(hrefArray.length > 1) {
     postLast.html('<center><img  class="loadingImg" src="'+imgUrl+'"/></center>');
     infiniteScroll();
       }
   }

我知道代码中有一些元素是数组,但我的问题是而不是做

 if() {
  } else {
      //run code here
  }

我想知道如果 url 不包含 p19,我将如何测试/'/?p('d+)$/

 var regex=(/'/?p('d+)$/);
 if(!regex.test(window.location.pathname) {}

对此很好奇,我知道如何测试元素是否被定义等等,只是不确定用正则表达式。

regex.test返回一个布尔值。 JavaScript 中的 .(对象解析运算符(比 !(not 运算符(具有更高的优先级(括号除外(。

也就是说,在

! /(?:)/.test("")

.出现在!之前,反转了它的值。

您可以检查p19(或p后跟至少一个数字(是否不在字符串中

!/p'd+$/.test(window.location.pathname)

您在正则表达式中的其他部分没有用。