If you really need one regex then it will be very large and very slow due to return. For your specific example (John AND Barbara) AND (Happy or Sad), it will start as follows:
\bJohn\b.*?\bBarbara\n.*?\bHappy\b|\bJohn\b.*?\bBarbara\n.*?\bSad\b|......
Ultimately, you will need to put all the combinations in a regular expression. Sort of:
JBH, JBS, JHB, JSB, HJB, SJB, BJH, BJS, BHJ, BSJ, HBJ, SBJ
Again, going back would be prohibitive, as would an explosion in the number of cases. Stay away from regular expressions here.
source share