ReplaceList

ReplaceList[expr, rule] returns all the possible replacements using rule on expr.

Attributes[ReplaceList] := {Protected}

Simple examples

In[1]:= ReplaceList[a + b, x_ + y_ -> {x, y}]
Out[1]= {{a, b}, {b, a}}
In[2]:= ReplaceList[foo[a + b, b], foo[j_ + k_, j_] -> {j, k}]
Out[2]= {{b, a}}
In[3]:= ReplaceList[foo[a + b], foo[x_ + y_] -> {x, y}]
Out[3]= {{a, b}, {b, a}}
In[4]:= ReplaceList[bar[foo[a + b] + c], bar[foo[x_ + y_] + z_] -> {x, y, z}]
Out[4]= {{a, b, c}, {b, a, c}}
In[5]:= ReplaceList[bar[foo[a + b] + c + d], bar[w_ + x_ + foo[y_ + z_]] -> {w, x, y, z}]
Out[5]= {{c, d, a, b}, {c, d, b, a}, {d, c, a, b}, {d, c, b, a}}
In[6]:= ReplaceList[foo[a + b, c], foo[j_ + k_, j_] -> {j, k}]
Out[6]= {}