fork download
  1. import re
  2.  
  3. regex = r"\d+\s*((?:Apple|Banana|Orange|Pineapple)s?\b[\s\S]*?)(?=$|\d+\s*(?:Apple|Banana|Orange|Pineapple)s?\b)"
  4.  
  5. test_str = "I have 2 apples in my bag and apples are great food toeat. you shud eat apples daily.\n\n it is very good for health. 3 bananas are also good. it reduces fat."
  6.  
  7. matches = re.findall(regex, test_str, re.IGNORECASE)
  8.  
  9. for match in matches: print(match + "\n")
  10.  
Success #stdin #stdout 0.07s 126528KB
stdin
Standard input is empty
stdout
apples in my bag and apples are great food toeat. you shud eat apples daily.

 it is very good for health. 

bananas are also good. it reduces fat.