I am trying to write a substitution that does essentially the following:

`\gamma_{a}_{\alpha \beta} \gamma_{b}^{\beta \gamma} -> X_{a b}_{\alpha}^{\gamma}`

but with $a$ and $b$ allowed to be a range of vector indices, e.g. I want to also encompass

`\gamma_{a1 a2 a3}_{\alpha \beta} \gamma_{b}^{\beta \gamma} -> X_{a1 a2 a3 b}_{\alpha}^{\gamma}`

and so on. I can of course define this for all possible collective indices a_i and b_i, or introduce some intermediate kluge, but I suspect there ought to be a compact, elegant way of doing this. My initial instinct was to try

`\gamma_{A??}_{\alpha \beta} \gamma_{B??}^{\beta \gamma} -> X_{A?? B??}_{\alpha}^{\gamma}`

but this doesn't seem to work. Any ideas of a simple solution?