Skip to content

Replace

Replace[expr, rules] applies rules to expr if they match at the base level.

Attributes[Replace] := {Protected}

Simple examples

In[1]:= Replace[a + b, a + b -> 2]
Out[1]= 2
In[2]:= Replace[a + b, a -> 2]
Out[2]= a + b
In[3]:= Replace[a + b, _ -> 2]
Out[3]= 2
In[4]:= Replace[a + b, {a + b -> c + d, c + d -> 3}]
Out[4]= c + d