Does not match foo
^((?!foo).)*$
Result:
foo
bar <- match
baz <- match
qux <- match
foobar
barbaz <- match
Matches exactly foo, bar
((^|, )(foo|bar))+$
Result:
foo <- match
bar <- match
baz
qux
foobar
barbaz
^((?!((^|, )(foo|bar))+$).)*$
foo
bar
baz <- match
qux <- match
foobar <- match
barbaz <- match