I have a regex that matches some binary strings. How to create a generator expression that defines a list of all strings that are accepted by this regex?
Please find the pseudocode.
pattern = re.compile("^(001|010|100){5}$") #accepts {001100001001001, 100100100001001,...} but not accepts {000000000000000,111111111111111,...}
def infinite_sequence():
num = 000000000000000
while True:
yield num
num += 1
good_binary_strings = [x for x in infinite_sequence() if re.match(pattern, x)]
I am interested in the most efficient code as possible. The real subset of strings is huge.