How to determine if a string contains a sequence of repeated letters

前端 未结 7 1941
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 16:01

Using JavaScript, I need to check if a given string contains a sequence of repeated letters, like this:

\"aaaaa\"

How can I do t

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-17 16:22

    You can use this function:

    function hasRepeatedLetters(str) {
        var patt = /^([a-z])\1+$/;
        var result = patt.test(str);
        return result;
    }
    

提交回复
热议问题