This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Cases

Cases
gives a list of the that match the pattern.
Cases
gives a list of the values of rhs corresponding to the that match the pattern.
Cases
gives a list of all parts of expr on levels specified by levelspec that match the pattern.
Cases
gives the values of rhs that match the pattern.
Cases
gives the first n parts in expr that match the pattern.
  • The first argument to Cases need not have head List.
  • Cases evaluates rhs only when the pattern is found.
  • Cases uses standard level specifications:
nlevels through n
Infinitylevels through Infinity
{n}level n only
{n1,n2}levels through
  • The default value for levelspec in Cases is .
  • A positive level n consists of all parts of expr specified by n indices.
  • A negative level -n consists of all parts of expr with depth n.
  • Level consists of numbers, symbols and other objects that do not have subparts.
  • Level corresponds to the whole expression.
  • With the option setting Heads->True, Cases looks at heads of expressions, and their parts.
  • Cases traverses the parts of expr in a depth-first order, with leaves visited before roots.
Find cases that explicitly match integers:
Find cases that do not match integers:
Return the from inside each matched:
Find cases that explicitly match integers:
In[1]:=
Click for copyable input
Out[1]=
Find cases that do not match integers:
In[2]:=
Click for copyable input
Out[2]=
 
Return the from inside each matched:
In[1]:=
Click for copyable input
Out[1]=
Find all cases of lists of two elements:
Find the sum of every pair of elements:
Pick out elements that are not :
Pick out cases of integers down to level 2:
Use to evaluate only after explicit elements have been found:
New in 1 | Last modified in 5