5
Great trick Zolley! Here's a small improvement.
Instead of:
=CONCATENATE(G3,"|",G4,"|",G5,"|",G6,"|",G7)
we can use
=TEXTJOIN("|",1,G3:G7)
That also allows us to work with bigger arrays when adding every cell into the formula one by one just doesn't make sense.
UPD:
Going further I tried to compose two formulas together to exclude the helping cell and here we go:
=QUERY(Sheet1!A3:AB50,"Select A,B, AB WHERE B matches '^.(" & TEXTJOIN("|",1,G3:G7) & ").$'")
Used this in my own project and it worked perfectly!