I'm trying to write a password validator, and the validator requires an expression to match. If a password matches the when the expression is applied, the password is valid.
In this case, I'm trying to match on any valid password, except ones that contains three or more uninterrupted repeating characters. This could be any character, and it shouldn't matter where it occurs in the entire string.
Valid Passwords:
Password1! Paasswwoorroodd1!
<- I'd like these passwords to match. Note that there are 4 'o's in the second password, though only two 'o' appear one after the other, so it's valid.
Invalid Passwords:
Password111! Passwooord!1
<- There are three repeating characters, back-to-back, therefore, I'd like it to not match.
In a previous attempt, I wrote a regular expression:
(.)\1{2}
Which allowed me to match repeating characters, but matching on everything BUT a string containing repeating characters is proving much more difficult.
Is it even possible to do through regex alone? I require a pure regex solution, rather than relying on running a match and manipulating it via code.
Any help would be appreciated.
Edit: Found my answer, thanks to Malte's comment below
^((.)\2?(?!\2))+$
Seems to match on all my criteria. I was missing the negative lookahead and the + at the end. Cheers.