I don't think
sed is advanced enough to do that, at least not in a tidy manner.
Code:
sed -n -Ee '/^\s*[0-9]+.+\*FOOBAR=.+\b[Ff][Oo][Oo]\b.+\b[Bb][Aa][Rr]/p' F
However, you can do it easily with Perl or PCRE:
Code:
perl -n -e '/^\s*[0-9]+.+\*FOOBAR=.+(?i)\bfoo\b.+\bbar/ && print' F
grep -h -P -e '^\s*[0-9]+.+\*FOOBAR=.+(?i)\bfoo\b.+\bbar' F
The (?i) turns on case-insensitivity. Leaving off a matching (?-i) means it applies through to the end of the pattern.
See "man perlre" and scroll down to the section on Extended Patterns and the paragraphs with the heading "(?adlupimnsx-imnsx)" and "(?^alupimnsx)"