Blank
_
matches any expression.
_head
matches any expression with a Head
of head
.
Attributes[Blank] := {Protected}
Simple examples
In[1]:= MatchQ[a + b, _] Out[1]= True
In[2]:= MatchQ[1, _Integer] Out[2]= True
In[3]:= MatchQ[s, _Integer] Out[3]= False
Blank
works with nonatomic head
s:
In[4]:= ((a*b*c*d)) /. ((_Times -> 2)) Out[4]= 2
Further examples
For Orderless
functions, the match engine will attempt to find a match in any order:
In[1]:= MatchQ[x + 3., c1match_Real + matcha_] Out[1]= True