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

前端 未结 7 1926
没有蜡笔的小新
没有蜡笔的小新 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:11

    This will check if the string has repeats more than twice:

    function checkStr(str) {
        str = str.replace(/\s+/g,"_");
        return /(\S)(\1{2,})/g.test(str);
    }
    

提交回复
热议问题