I need to extract the word local when it comes before gun store. But, the below function is not returning it because of using split. Is there any way to get around this?
Source looks like this: As reported on 30 December 2019, in Maipu, Metropolitan region, a group of at least 10 rioters attempted to loot a local gun store.
Here is the function:
regex_filter = r'local|dozen|several|looted'
property_key = r"\b(gun store|establishments|supermarket)\b"
source= source.split()
for i, w in enumerate(source):
if (re.search(property_key, w)):
if re.match(re.compile(regex_filter, flags=re.IGNORECASE), source[i-1]):
return source[i-1]```