题目描述
解答:
1、我的初次解答为
function containsRepeatingLetter(str) {
return /(\w)\1/g.test(str);
}
通过率为80%,上面正则表达式我的理解是匹配全局中是否有重复的字符,重复长度为2,
注意:\w是单词字符(包括[a-zA-Z_0-9)字母数字下划线,而题目中让匹配的是重复的字母
/(\w)\1+/g.test('wedfsfsfd33d');
true
正确答案:
function containsRepeatingLetter(str) {
return /([a-zA-Z])\1/g.test(str);
}