I have some text which is sentences, some of which are questions. I'm trying to create a regular expression which will extract only the questions which contain a specific phrase, namely 'NSF' :
import re
s = "This is a string. Is this a question? This isn't a question about NSF. Is this one about NSF? This one is a question about NSF but is it longer?"
Ideally, the re.findall would return:
['Is this one about NSF?','This one is a question about NSF but is it longer?']
but my current best attempt is:
re.findall('([\.\?].*?NSF.*\?)+?',s)
[". Is this a question? This isn't a question about NSF. Is this one about NSF? This one is a question about NSF but is it longer?"]
I know I need to do something with non-greedy-ness, but I'm not sure where I'm messing up.