generated_String
hi @davide_zorzenon @alsultanm can pleas take a look on this I had to use the exrex library to be able to generate result without doing it manually in the code but I am not happy that the exrex works so that first it prints all possible occurrence of b and then the 2a with on or more b however I would like to hear your opinion about it
import re
import numpy as np
import exrex
class StringGenerator:
def __init__(self):
self.result = []
def generate_strings(self, pattern, search_str):
if not re.fullmatch(pattern, search_str):
print("The search string does not match the pattern.")
return []
max_count = len(search_str) * 30
count = 0
for string in exrex.generate(pattern):
self.result.append(string)
count += 1
if count >= max_count:
break
return self.result
ps = StringGenerator()
pattern = r"(2a)*b*"
search_str = "2a"
ps.generate_strings(pattern, search_str)
print("Generated strings:", ps.result)
Generated strings: ['', 'b', 'bb', 'bbb', 'bbbb', 'bbbbb', 'bbbbbb', 'bbbbbbb', 'bbbbbbbb', 'bbbbbbbbb', 'bbbbbbbbbb', 'bbbbbbbbbbb', 'bbbbbbbbbbbb', 'bbbbbbbbbbbbb', 'bbbbbbbbbbbbbb', 'bbbbbbbbbbbbbbb', 'bbbbbbbbbbbbbbbb', 'bbbbbbbbbbbbbbbbb', 'bbbbbbbbbbbbbbbbbb', 'bbbbbbbbbbbbbbbbbbb', '2a', '2ab', '2abb', '2abbb', '2abbbb', '2abbbbb', '2abbbbbb', '2abbbbbbb', '2abbbbbbbb', '2abbbbbbbbb', '2abbbbbbbbbb', '2abbbbbbbbbbb', '2abbbbbbbbbbbb', '2abbbbbbbbbbbbb', '2abbbbbbbbbbbbbb', '2abbbbbbbbbbbbbbb', '2abbbbbbbbbbbbbbbb', '2abbbbbbbbbbbbbbbbb', '2abbbbbbbbbbbbbbbbbb', '2abbbbbbbbbbbbbbbbbbb', '2a2a', '2a2ab', '2a2abb', '2a2abbb', '2a2abbbb', '2a2abbbbb', '2a2abbbbbb', '2a2abbbbbbb', '2a2abbbbbbbb', '2a2abbbbbbbbb', '2a2abbbbbbbbbb', '2a2abbbbbbbbbbb', '2a2abbbbbbbbbbbb', '2a2abbbbbbbbbbbbb', '2a2abbbbbbbbbbbbbb', '2a2abbbbbbbbbbbbbbb', '2a2abbbbbbbbbbbbbbbb', '2a2abbbbbbbbbbbbbbbbb', '2a2abbbbbbbbbbbbbbbbbb', '2a2abbbbbbbbbbbbbbbbbbb']