How to disallow the use of more than two repeating digits in a string?
I really don’t understand. I think I need to use backreferences
Valid:
122122122
949944494
5656665
10111001
Not valid:
122142122 <---- 4
949984494 <---- 8
5656265 <---- 2
10113001 <---- 3
>Solution :
You can capture the first character, match it with a backreference until you can capture a different second character, and then match the two captured characters with backrefereces in an alternation pattern until the end:
^(.)?\1*(.)?(?:\1|\2)*$
Demo: https://regex101.com/r/5wvoAp/4