JS正则判断多个连续相同字符
var reg1 = /(\w)\1\1/g; //判断2个连续字符 var reg2 = /(\w)\1{2}/g; //判断3个连续字符 var reg3 = /(\w)\1\1/g; //判断3个连续字符 var str = 'aa!@#123AaAaAAA3'; str.match(reg1); // 输出['aa','AA'] str.match(reg2); // 输出['AAA'] str.match(reg3); // 输出['AAA'] //reg2和reg3表达的意思相同
好文推荐