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

前端 未结 7 1938
没有蜡笔的小新
没有蜡笔的小新 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条回答
  • 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;
    }
    
    0 讨论(0)
提交回复
热议问题