假设我有一个mac地址列表,例如:“00:11:22:33:44:55,11:22:33:44:55:66,22:33:44:55:66:77”
我想对该列表进行正则表达式检查。
var re = /(([A-Fa-f0-9]{2}[:]){5}[A-Fa-f0-9]{2}[,]?)+/g
但是,它不起作用。这是输入测试。
var t1 = "11:22:33:44:55:66";
var t2 = t1 + ",12:22:33:44:55:66";
var t3 = t1 + ",11asdfasdf:22:33:44:55:66";
var t4 = t1 + ",haha";
var t5 = t1 + ",";
var t6 = "123123123123";
var t7 = t1 + ",33:44:55:66:77:88:";
var t8 = t1 + ",33:44:55:66:77:88asdfasdfasdfasdfasdfasd";
var t9 = t1 + ",dfasdfasdfasdfasdfasd";
var t10 = t2 + ",12:33:44:55:66:77";
var t11 = t2 + ",wahaa";
console.log("t1: [" + t1 + "] " + re.test(t1));
console.log("t2: [" + t2 + "] " + re.test(t2));
console.log("t3: [" + t3 + "] " + re.test(t3));
console.log("t4: [" + t4 + "] " + re.test(t4));
console.log("t5: [" + t5 + "] " + re.test(t5));
console.log("t6: [" + t6 + "] " + re.test(t6));
console.log("t7: [" + t7 + "] " + re.test(t7));
console.log("t8: [" + t8 + "] " + re.test(t8));
console.log("t9: [" + t9 + "] " + re.test(t9));
console.log("t10: [" + t10 + "] " + re.test(t10));
console.log("t11: [" + t11 + "] " + re.test(t11));
结果
t1: [11:22:33:44:55:66] true
t2: [11:22:33:44:55:66,12:22:33:44:55:66] true
t3: [11:22:33:44:55:66,11asdfasdf:22:33:44:55:66] false
t4: [11:22:33:44:55:66,haha] true
t5: [11:22:33:44:55:66,] false
t6: [123123123123] false
t7: [11:22:33:44:55:66,33:44:55:66:77:88:] true
t8: [11:22:33:44:55:66,33:44:55:66:77:88asdfasdfasdfasdfasdfasd] false
t9: [11:22:33:44:55:66,dfasdfasdfasdfasdfasd] true
t10: [11:22:33:44:55:66,12:22:33:44:55:66,12:33:44:55:66:77] true
t11: [11:22:33:44:55:66,12:22:33:44:55:66,wahaa] false
谁能告诉我为什么 t7、t9 和 t4 会返回 true?此外,当我re.test(t11)
在 chrome 控制台上输入时,我发现结果会在真假之间切换。有谁知道为什么?