Regex for “Does not contain four or more repeated characters”

后端 未结 5 1123
盖世英雄少女心
盖世英雄少女心 2021-01-15 16:22

My experience with regular expressions is limited and I\'ve been reading various tutorials and posts on negation and negative lookahead, etc, but nothing seems to quite matc

5条回答
  •  温柔的废话
    2021-01-15 16:49

    Turn the problem around: a character can be followed by at most 3 of the same. Then it must be followed by something else. Finally, the whole string must consist of sequences like this. In the perl flavor:

    ^((.)\2{0,3}(?!\2))*$
    

提交回复
热议问题