regex - Find if the sentence does not contains specific words -
i have regular expression find if sentences contains specific words
my query is:
(?=.*hello)(?=.*hi)(?=.*hey).* but want check if sentence not contains words
i have tried:
(?=.*((?!hello).))(?=.*((?!hi).))(?=.*((?!hey).)).* but not works
how should build query?
example:
this query should return true when sentence is:
hi, how you?
and must return false when sentence is:
hi hello hey ..
thanks in advance,
if problem match string if 3 words/patterns don't appear in string together, here simpler solution problem:
^(?!(?=.*hello)(?=.*hi)(?=.*hey)).* or alternative solution (by de morgan's law):
^(?:(?!.*hello)|(?!.*hi)|(?!.*hey)).* (not(a , b , c) equivalent not(a) or not(b) or not (c))
note scans pattern many times number of words checked, , again runs permutation problem if want check whether k out of n words appear in string.
Comments
Post a Comment