代碼如下:var arr = ["aab", "aab"];var p = /(.)(?:\1+)/g;p.test("aab");//truep.test(arr[0]);//falsep.test(arr[1]);//true再次進行測試:p.test(arr[0]);//falsep.test(arr[1]);//truep.test(arr[0]);//falsep.test(arr[1]);//true發現是true false交替下去的隨機換了組數據測試:var arr1 = ["a", "a"];var p1 = /\w/g;p1.test("a");//truep1.test(arr[0]);//truep1.test(arr[1]);//true應該是我關于js數組或者正則表達式有什么地方的特性沒有了解到。還望解答: )
一個JS數組有兩個值相同的元素,用正則test()方法測試出來卻是一個true,一個false?
牛魔王的故事
2018-10-10 13:15:57

