The concrete problem I want to solve: I want to replace a product of two gamma matrices by the one in reverse order using the Clifford relation. i.e.
$\gamma\mu \gamma\nu -> 2 \eta{\mu \nu} - \gamma\nu \gamma_\mu $
When I use a substitution it's applied to all products of 2 gamma matrices, even if they already have the 'right' order. Since patterns select both terms, I cannot zoom into one of the terms selectively. Regexp does not seem to help either (or at least not without knowing the internal represantation of a placeholder like M??). Your trick works fine in your example, but I cannot ditinguish the order of the Dirac matrices by contracting with a vecor/tensor, so it does not help here.
Instead trying to sort the terms appropriately and then applying $\gamma\mu \gamma\nu + \gamma\nu \gamma\mu -> 2 \eta_{\mu \nu} $ instead seems not to work either, so I'm lost - should be a trivial exercise in gamma matrices...
Added: I found an analogous trick: Contract with a tensor $F^{\mu \nu} $ then one can match with a pattern containing $\gamma\mu \gamma\nu F^{\mu \nu}$. Due to non-commutativity of Dirac matrices this patterns really matches only one of the two terms.
However, considering that this is essnetially the most trvial transformation with Dirac matrices, it is surprising that such a painfull worakround seems to be needed. Hopefully, I'm overlooking some easy solution.