I'm aware that Replace and ReplaceAll behave differently as discussed in this question, but still get confused with the following example when Flat is involved:
f//Attributes = {Flat, OneIdentity}; Replace[f[x, 2 y, z], f[x_, 2 y_] :> f[x, y], {0, Infinity}] (* f[x, 2 y, z] *) ReplaceAll[f[x, 2 y, z], f[x_, 2 y_] :> f[x, y]] (* f[x, y, z] *) The result of ReplaceAll is as expected, but why does Replace not try the pattern f[f[x, 2y], z]? Is there a simple workaround for Replace without modifying the rule?
Update 1
A simpler example by @user293787:
SetAttributes[f, Flat]; ReplaceAll[f[a,b],f[a]->0] (*f[0,b]*) Replace[f[a,b],f[a]->0,All] (*f[a,b]*) Update 2
It seems that in the sequence inside f, a non-Pattern head will stop the matching from left to right, e.g.
Replace[f[a,b,c],f[a_,b]->g[a,b],All] (*f[a, b, c]*) Replace[f[a,b,c],f[a_,c]:>g[a,c],All] (*g[f[a, b], c]*) (the update 2 is from part of my answer, in which the solution is totally wrong. I delete it to avoid confusions.)
f[a,b]/.f[a]->0givesf[0,b]butReplace[f[a,b],f[a]->0,{0,Infinity}]givesf[a,b]. $\endgroup$SetAttributes[M,{Flat}];Replace[M[F1[a]],M[x_F1]|M[x_F2]->x]returnsM[F1[a]], but if I run it now I getF1[a]. Apparently this was "fixed". Perhaps you found a similar problem. $\endgroup$