What if the forbidden word is part of a longer word? For example, what if you want the lines to start with "first" and end with "last", but not contain the word "word"? For example:
"first one two word last"
"first three wordplay four last"
"first five swordfish six seven last"
Adapting the accepted answer will give you the following:
/^first (?:(?!word).)+ last$/i
... but this will reject all three lines. In any case, there is no need to view in each position. Just do it once at the beginning of each word:
/^first(?:\s+(?!word\b)\w+)*\s+last$/i
Watch a live demo
source
share