I want to detect whether a word is in a sentence using python regex. Also, want to be able to negate it.
import re re.match(r\'(?=.*\\bfoo\\b)\', \'bar red f
You need the .* because re.match() tries to match the pattern to the beginning of the string. If you want to search the whole string, use re.search().
.*
re.match()
re.search()
Just as you can do if re.search(...):, you can also do if not re.search(...):
if re.search(...):
if not re.search(...):