I have a large list of data and another list of patterns. I'm trying to filter data using the patterns. Here's my code using some sample data:
dataList = [ '4334 marked val 5656 bin',
'76-67-34 done this 99',
'bin ket AZZ3R434 pid'
]
for data in dataList:
regexList = [ re.search(r'val ([\d]+) bin', data),
re.search(r'bin ket ([A-Z\d-]+)\b', data)
]
for reg in regexList:
if reg: #If there's a match
#...do something...
break
In the above code in regexlist the 're.search()' part is getting repeated again and again. I want to keep only a list of patterns, something like below:
regexList = [ 'val ([\d]+) bin',
'bin ket ([A-Z\d-]+)\b'
]
And use these patterns one by one with re.search() later. I tried using eval() and exec() both, but just kept getting errors.
I would also like to know whether 'regexList' is getting created again and again under for loop?