I'm trying to get all the words before and after a given pattern in a sentence. Below is the code I'm using. Of course this is not perfect, so any suggestions are welcome. My issue at hand is that, this is working for some patterns but not for others. For example, the given pattern below is not working, ie. re.match returns None.
sentence = "The agreements in this Section shall survive the resignation of the Administrative Agent, the L/C Issuer and the Swing Line Lender, the replacement of any Lender, the termination of the Aggregate Commitments and the repayment, satisfaction or discharge of all the other Obligations."
s = "commitments.*repayment"
rex = "(?i)((?:\\S+\\s+){0,30})\\b" + s + "\\b\\W*((?:\\S+\\s+){0,30})"
p = re.match(rex, sentence, re.IGNORECASE)
print p
What am I doing wrong?