I have a list of words - "foo", "bar", "baz" - and I want to write a regexp which would match strings which contain at least 2 of them. E.g., "foo baz" should match while "ba foo z" should not.
The obvious solution "(foo|bar|baz).*(foo|bar|baz)" works, but I find it unsatisfactory because it lists the words twice. What if I have 25 words instead of just 3? What if I am looking for strings which contain at least 4 given words instead of just 2?