fork download
  1. import re
  2. answer = "king tut"
  3. bad_context = "we run with the king tut? on sunday"
  4. good_context = "we run with the king tut on sunday"
  5.  
  6. reg_answer = re.compile(r"(?<!\S)" + re.escape(answer) + r"(?!\S)")
  7. if reg_answer.search(good_context):
  8. print("good_context matched")
  9. else:
  10. print("good_context not matched")
  11.  
  12. if reg_answer.search(bad_context):
  13. print("bad_context matched")
  14. else:
  15. print("bad_context not matched")
Success #stdin #stdout 0s 23352KB
stdin
Standard input is empty
stdout
good_context matched
bad_context not matched