Skip to main content
1 of 2
István Zachar
  • 47.2k
  • 20
  • 145
  • 293

If you have even more complicated expressions, you might want to use Heads -> True.

expr = {f, Subscript[g, i], h[i[j[a, b]]], s'[t] == u[t] + v[t]};

Union@Cases[expr, Except[__Symbol?(Context@# === "System`" &), _Symbol],
    {1, Infinity}, Heads -> True]
{a, b, f, g, h, i, j, s, t, u, v}

Without checking heads:

Union@Cases[expr, Except[__Symbol?(Context@# === "System`" &), _Symbol], {1, Infinity}]
{a, b, f, g, i, t}
István Zachar
  • 47.2k
  • 20
  • 145
  • 293