So, I want to built a regular expression that I can pass in a string of 0s and 1s (e.g. “0010101000111100100011110001101100011”) and then make sure that for every 6 consecutive characters, there needs to be at least two 1s in that block.
Also, strings less than length 6 should pass.
Examples of passing strings:
- “”
- “00”
- “11000011”
- “01010100”
Examples of failing strings:
- “110000000011”
- “000001”
These examples are of very small strings, but I want to build one to take any length string.
Now, I’m looking for a nice way to express this in a regular expression, rather than having solution with a loop and such.
Just use this regex and check that it doesn’t match: