fork download
  1. import re
  2.  
  3. regex = r"^[^.]*\.\s*(?=.*\bcosts\b)(.*\bapple\b.*\.)$"
  4. test_str = ("Supermarket. This apple costs 0.99.\n"
  5. "Supermarket. This costs apple 0.99.\n"
  6. "Supermarket. This apple is 0.99.\n"
  7. "Supermarket. This orange costs 0.99.")
  8.  
  9. print(re.findall(regex, test_str, re.MULTILINE))
Success #stdin #stdout 0.02s 9624KB
stdin
Standard input is empty
stdout
['This apple costs 0.99.', 'This costs apple 0.99.']