79750940

Date: 2025-08-30 05:32:01
Score: 0.5
Natty:
Report link

Drawing inspiration from the wonderful answer given by @anubhava, you can do the above using the positive lookbehind assertion as well like below:

import re

lines = """water                                                      
I have water                                     
I never have water
Where is the water.                                           
I never have food or water
I never have food but I always have water                     
I never have food or chips. I like to walk. I have water"""

for line in lines.split("\n"):
    if not re.search(r"(?<=never).{,20}\bwater\b", line):
        print(line)
# OUTPUT:
water
I have water
Where is the water.
I never have food but I always have water
I never have food or chips. I like to walk. I have water
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @anubhava
  • Low reputation (0.5):
Posted by: Vivek