Clear[s1,s2,…]
clears values and definitions for the symbols si.
Clear[patt1,patt2,…]
clears values and definitions for all symbols whose names textually match any of the arbitrary string patterns patti.
Clear[{spec1,spec2,…}]
clears values and definitions for any symbols that are equal to or whose names match any of the speci.
Clear
Clear[s1,s2,…]
clears values and definitions for the symbols si.
Clear[patt1,patt2,…]
clears values and definitions for all symbols whose names textually match any of the arbitrary string patterns patti.
Clear[{spec1,spec2,…}]
clears values and definitions for any symbols that are equal to or whose names match any of the speci.
Details
- Clear does not clear attributes, defaults, options or messages associated with symbols. »
- The pattern patt can be given as a string with metacharacters, as StringExpression[…] or as RegularExpression["regex"]. »
- Clear allows abbreviated string patterns containing the following metacharacters:
-
* zero or more characters @ one or more characters, excluding uppercase letters - Clear["context`*"] clears all symbols in a particular context. »
- Clear["`*"] clears all symbols in the current context. »
- Clear does not affect symbols with the attribute Protected. »
- Clear has attribute HoldAll. »
Examples
open all close allBasic Examples (2)
Scope (12)
Symbol Inputs (7)
Clear values of variables (ownvalues):
x = 5;xClear[x]xfact[1] = 1;
fact[n_] := n fact[n - 1]fact[3]Clear[fact]fact[3]h/:f[h[x_]] := hf[x]f[h[x]]Clear[h]f[h[x]]f[x_][y_] := h[x, y]f[x][y]Clear[f]f[x][y]Format[kappa] := κkappaClear[kappa]kappaa = 5;
f[x_] := x ^ 3f[a]Clear[a, f]f[a]Use a combination of symbols and symbol names:
x1 = 1;x2 = 3;x3 = 5;Clear[{x1, "x2"}]{x1, x2, x3}Using Patterns (5)
Specify symbols to clear as string patterns:
x1 = 1;x2 = 3;y = 5;Clear["x*"]{x1, x2, y}Clear all symbols in the current context:
x1 = 1;x2 = 3;y = 5;Clear["`*"]{x1, x2, y}Clear all symbols in a given context:
abc`x1 = 1;abc`x2 = 3;abc`y = 5;Clear["abc`*"]{abc`x1, abc`x2, abc`y}Clear all 2-character symbols in the current context using StringExpression:
x1 = 1;x2 = 3;y = 5;Clear["`" ~~ _ ~~ _]The symbols x1 and x2 were cleared, but y remains unaffected:
{x1, x2, y}Clear all 3-character symbols in the current context using RegularExpression:
x = 1;yy = 3;zzz = 5;Clear[RegularExpression["`..."]]{x, yy, zzz}Applications (2)
Clear any old definitions before making new ones:
Clear[fib]fib[1] = fib[2] = 1;
fib[n_] := fib[n] = fib[n - 1] + fib[n - 2]fib[5]Unprotect and clear all symbols in a package, to allow it to be read twice:
Begin["`Private`"];Unprotect["`*"];
Clear["`*"];f[x_] := x ^ 2Protect[f];End[];Properties & Relations (6)
Clear[pattern] clears the same symbols as Clear/@Names[pattern]:
x = 1;y = 2; xy = 3;
Clear["x*"];
{x, y, xy}x = 1;y = 2; xy = 3;
Clear /@ Names["x*"];
{x, y, xy}Use Unset (=.) to clear definitions with a particular left-hand side:
fact[0] = 1;
fact[n_Integer] /; n > 0 := n fact[n - 1]
fact[n_Integer] /; n < 0 := -∞fact[0]=.Definition[fact]Clear[fact]Definition[fact]Clear does not remove attributes, defaults or options:
SetAttributes[f, Listable];
Default[f] = 0;
Options[f] = {opt1 -> def1, opt2 -> def2};
f[x_.] := x ^ 2Clear[f]Definition[f]Use ClearAll to clear everything:
ClearAll[f]Definition[f]Clear does not remove messages:
f::usage = "f[x] gives (x - 1)(x + 1)";Clear[f]Message[f::usage]Use ClearAll to clear messages:
ClearAll[f]Message[f::usage]Clear removes all definitions but leaves the symbol intact:
f[x_] := x ^ 2Clear[f]? fRemove removes the symbol completely:
Remove[f]? fClear has the attribute HoldAll:
Definition[Clear]symbol = {"x", "y", "z"};x = 1;y = 3;z = 5;Clear[symbol]{symbol, x, y, z}symbol = {"x", "y", "z"};Clear[Evaluate[symbol]]{symbol, x, y, z}Possible Issues (2)
Protected symbols cannot be cleared:
x = 5;
Protect[x];Clear[x]Use Unprotect to clear definitions of protected symbols:
Unprotect[x];
Clear[x]When using a pattern without a context mark, all matching symbols on $ContextPath are cleared:
x = 1;y = 2;xy = 3;
Clear[_ ~~ _]The symbol xy was cleared, along with attempts to clear several system symbols:
xyUse a pattern with an explicit context mark to avoid potentially matching symbols from system or other contexts:
Clear["`" ~~ _]Related Guides
Related Workflows
- Clear Definitions for Symbols and Functions
History
Introduced in 1988 (1.0) | Updated in 2022 (13.2)
Text
Wolfram Research (1988), Clear, Wolfram Language function, https://reference.wolfram.com/language/ref/Clear.html (updated 2022).
CMS
Wolfram Language. 1988. "Clear." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/Clear.html.
APA
Wolfram Language. (1988). Clear. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Clear.html
BibTeX
@misc{reference.wolfram_2026_clear, author="Wolfram Research", title="{Clear}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Clear.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_clear, organization={Wolfram Research}, title={Clear}, year={2022}, url={https://reference.wolfram.com/language/ref/Clear.html}, note=[Accessed: 12-June-2026]}