I have gone through many of the regex questions on here and used the advice in them, but can't seem to get my code to run still. I have a list of strings, and I am attempting to find the entries in this list that contain one of the following patterns:
- a BLANK of a BLANK
- an BLANK of an BLANK
- a BLANK of an BLANK
- an BLANK of a BLANK
- that BLANK of a BLANK
- that BLANK of an BLANK
- the BLANK of a BLANK
- the BLANK of an BLANK
For example, I should be able to find sentences that contain phrases like "an idiot of a doctor" or "the hard-worker of a student."
Once found, I want to make a list of the sentences that satisfy this criteria. So far, this is my code:
for sentence in sentences:
matched = re.search(r"a [.*]of a " \
r"an [.*]of an " \
r"a [.*]of an" \
r"an [.*]of a " \
r"that [.*]of a " \
r"that [.*]of an " \
r"the [.*]of a " \
r"the [.*]of an ", sentence)
if matched:
bnp.append(matched)
#Below two lines for testing purposes only
print(matched)
print(bnp)
This code turns up no results, despite the fact that there are phrases that should satisfy the criteria in the list.
[.*], take the time to read regex tutorial before, don't try random things.(.*)instead