Im trying to filter texts using regex in python. The goal is: Check if the text has the word W not preceded by X or not followed by Y. so lets say:
W="day", X="awful", Y="light"
"what a beautiful day it is" => should pass
"nice day" => should pass
"awful day" => should fail
"such an awful day" => should fail
"the day light" => should fail
"awful day light" => should fail
"day light" => should fail
I've tried several things like:
r".*\b(?!awful\b)day\b.*"
r"\W*\b(?!awful\b)day\b.*" => to be able to include \n \r since '.' doesnt
r".*\b(day)\b(?!light\b).*"
r"\W*\b(day)\b(?!light\b)\W*" => to be able to include \n \r since '.' doesnt
So complete example would be, (should fail)
if (re.search(r".*\b(?!awful\b)day\b.*", "such an awful day", re.UNICODE):
print "Found awful day! no good!"
Still wondering how to do that! any ideas?
daylight? How abouttoday? How aboutthis day is awful?