fork download
  1. import re
  2.  
  3. negations = ["no", "not"]
  4. words = ["text", "sample text", "text book", "notebook"]
  5. sentences = [
  6. "first sentence with no and sample text",
  7. "second with a text but also a not",
  8. "third has a no, a text and a not",
  9. "fourth alone is what is neeeded with just text",
  10. "keep putting line here no"
  11. ]
  12.  
  13. for sentence in sentences:
  14. negationsRegex = re.compile(r"\b(?:" + "|".join([re.escape(n) for n in negations]) + r")\b")
  15. wordsRegex = re.compile(r"\b(?:" + "|".join([re.escape(w) for w in words]) + r")\b")
  16. if not (re.search(negationsRegex, sentence) and re.search(wordsRegex, sentence)):
  17. print sentence
Success #stdin #stdout 0.02s 6988KB
stdin
Standard input is empty
stdout
fourth alone is what is neeeded with just text
keep putting line here no