fork download
  1. import re
  2.  
  3. pattern = r"(?<!\bIf\sI\s)\brecall(?:s|ed)?\b"
  4.  
  5. s = "Hi, I am talking about a recall on the product I bought last month. If I recall correctly, I purchased this at your store on august 15th. Can you tell me if I can get a refund on this recall?"
  6. matches = re.finditer(pattern, s, re.IGNORECASE)
  7. for matchNum, match in enumerate(matches, start=1):
  8. print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
  9.  
Success #stdin #stdout 0.03s 9728KB
stdin
Standard input is empty
stdout
Match 1 was found at 25-31: recall
Match 2 was found at 184-190: recall