Sorry

$regsubex is used to make a "while" with 8 iteration (input string is 8 'x', and we're matching all of them using /g).
When replacing each 'x', just check for $did($calc(\n + 2)).state (\n represent the match number) in order to have number from 3 to 10, if state is 1, replace with 0, else with 1.
Then use isin to check if there is a 0 in the result of $regsubex, if so, it mean that at least one your condition is true.
Hope this help
Edit : in fact the //g parameter was missing.
Edit2 : $regsubex is generally faster than a while, but here, it will test all your $did().state even if previous are 1, whereas an if statement won't do this, so really, I don't know if this code is better.