Stuck with a silly problem. I have an input field, where user can input limited amount of letters (ABCDEFG). Here is the problem: I do not want users to be able to have more than 3 A, C, E and G’s letters in a single subsequence of the input, that is: no AAA, CCC, EEE, GGG. And the second thing is almost the same as the first one: no more than 1 B, D, F in a single subsequence, that is: no BB, DD, FF. These two rules are somehow to be combined together.
So, for example, AABFGECC is valid. GEFFFAABG is invalid.
Hope, you will help me! Thank you!
P.S If it is important, I am writing my app in Visual Basic. But I think, this is not so important.
While you could be clever and use back-references, a simple solution is to black-list the invalid sequences using a negative look ahead:
Logically, that is the same has having those 7 invalid sequences in a list, and checking the string does not contain either one, which also gives you a nice alternative.