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
Find char in the group then match repeats
(.).*(\1{3,})
I used the simple ^(.)(?!\1\1){8,}$
for a 8 or more character that doesn't have any characters that repeat more than twice.
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))*$
You need to put the .*
inside the lookahead:
(?!.*?(.)\1{3,})
The way you're doing it, the .*
consumes the whole string, then the lookahead asserts that there aren't four of the same character after the end of the string, which of course is always true.
I used a non-greedy star in my lookahead because it seemed more appropriate, but greedy will work too--it just has to be inside the lookahead.
I'm assuming this is just one of several lookaheads, that being the usual technique for validating password strength in a regex. And by the way, while regex-negation is appropriate, you would have gotten more responses to your question much more quickly if you had used the regex tag as well.
I think, use this regex .*(.).*\1+.*
to matches existd repeated characters. But for four, depend on you.
Good luck!