I'm constructing a regex query using a for loop as follows:
query = '^(?:'
for num, element in enumerate(my_list):
values = element.split('-')
if num > 0:
query += '|'
for v in values:
query += f'(?=.*{v})'
query += ')'
my_list = ['a-b', 'b-c']
However, I believe this is inefficient as this results in a quadratic runtime so may not scale well.
How would I be able to convert this process to avoid this inefficiency?
I'm thinking something related to the .join()
method but I'm confused how this would work in my case as it doesn't seem straightforward to me.