This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Built-in Functions / Programming / Pattern Matching  /

  • DeleteCases[ expr , pattern ] removes all elements of expr which match pattern.
  • DeleteCases[ expr , pattern , levspec ] removes all parts of expr on levels specified by levspec which match pattern.
  • Example: DeleteCases[ 1, a, 2, b , _Integer].
  • With the option Heads -> True, you can delete heads with DeleteCases. Deleting the head of a particular element in an expression is equivalent to applying FlattenAt to the expression at that point.
  • Example: DeleteCases[ 1, f[2, 3], 4 , f, 2 , Heads -> True].
  • Level specifications are described in Section A.3.6.
  • See the Mathematica book: Section 2.3.2.
  • See also: Cases, ReplaceAll, Delete.

    Further Examples

    This deletes all elements of the list that are real numbers.



    This command deletes all integers from levels 1 to 2.



    In contrast this command deletes all integers only at level 2.