Patterns

  • You can match a pattern expression that contains _ or some other pattern expression. The following example returns all values in which the Head is an integer.
    In[1]:= Position[{7, _Integer}, _Integer]
    Out[1]= {{1}}

    To match _Integer, and not the item with a Head of Integer as in the above example, you need to use Verbatim.

    In[2]:= Position[{7, _Integer},
                     Verbatim[_Integer]]

    Out[2]= {{2}}


Return to the Mathematica tips index.