ack uses Perl regular expressions, and they allow viewing statements :
^(?!.*bar).*foo.*$
will match a string containing foo but not containing bar .
I am not familiar with using ack , but something like this should work:
ack '^(?!.*bar).*foo.*$' myfile
source share