If one has the dynamic array formula FILTER():
=AVERAGE(FILTER(B2:B15,ISNUMBER(MATCH(--RIGHT(A2:A15),{2,5},0))))

If not then use this array formula:
=AVERAGE(IF(ISNUMBER(MATCH(--RIGHT(A2:A15),{2,5},0)),B2:B15))
As it is an array formula, exiting edit mode requires pressing Ctrl-Shift-Enter rather than Enter.
