Clear
✖
Clear
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 allclose allBasic Examples (2)Summary of the most common use cases

https://wolfram.com/xid/0girdm-badhbb

https://wolfram.com/xid/0girdm-q44gp
The variable no longer has a value:

https://wolfram.com/xid/0girdm-k3zdk


https://wolfram.com/xid/0girdm-sn84w8

https://wolfram.com/xid/0girdm-lbffi1


https://wolfram.com/xid/0girdm-qhk8ri

https://wolfram.com/xid/0girdm-gds8wx

Scope (12)Survey of the scope of standard use cases
Symbol Inputs (7)
Clear values of variables (ownvalues):

https://wolfram.com/xid/0girdm-cdnu4f

https://wolfram.com/xid/0girdm-u5749k


https://wolfram.com/xid/0girdm-c2li30

https://wolfram.com/xid/0girdm-5u4ym


https://wolfram.com/xid/0girdm-c9dse6

https://wolfram.com/xid/0girdm-ltkigq


https://wolfram.com/xid/0girdm-gfghut

https://wolfram.com/xid/0girdm-1k5ot4


https://wolfram.com/xid/0girdm-gkvbc1

https://wolfram.com/xid/0girdm-6g8nd2


https://wolfram.com/xid/0girdm-dm4hnz

https://wolfram.com/xid/0girdm-n06ifj


https://wolfram.com/xid/0girdm-fwskr0

https://wolfram.com/xid/0girdm-hnjc85


https://wolfram.com/xid/0girdm-uv4cc5

https://wolfram.com/xid/0girdm-p9a816


https://wolfram.com/xid/0girdm-vial91

https://wolfram.com/xid/0girdm-xn9q7u


https://wolfram.com/xid/0girdm-32e7wj

https://wolfram.com/xid/0girdm-rtnqpj


https://wolfram.com/xid/0girdm-bp50b

https://wolfram.com/xid/0girdm-tizdpb


https://wolfram.com/xid/0girdm-m4f4ut

https://wolfram.com/xid/0girdm-ch1vzf

Use a combination of symbols and symbol names:

https://wolfram.com/xid/0girdm-2onlhh

https://wolfram.com/xid/0girdm-e3odz5

https://wolfram.com/xid/0girdm-1f1k6s

Using Patterns (5)
Specify symbols to clear as string patterns:

https://wolfram.com/xid/0girdm-c2ufd6

https://wolfram.com/xid/0girdm-d7ttq9

https://wolfram.com/xid/0girdm-rysaf

Clear all symbols in the current context:

https://wolfram.com/xid/0girdm-6slgzo

https://wolfram.com/xid/0girdm-r70m2k

https://wolfram.com/xid/0girdm-lgaxot

Clear all symbols in a given context:

https://wolfram.com/xid/0girdm-wqeqjc

https://wolfram.com/xid/0girdm-wzpzb

https://wolfram.com/xid/0girdm-6wx1zi

Clear all 2-character symbols in the current context using StringExpression:

https://wolfram.com/xid/0girdm-x7ppwu

https://wolfram.com/xid/0girdm-0ghtad
The symbols x1 and x2 were cleared, but y remains unaffected:

https://wolfram.com/xid/0girdm-zwe7vm

Clear all 3-character symbols in the current context using RegularExpression:

https://wolfram.com/xid/0girdm-26w1um

https://wolfram.com/xid/0girdm-ln5y9g

https://wolfram.com/xid/0girdm-sxd17n

Applications (2)Sample problems that can be solved with this function
Clear any old definitions before making new ones:

https://wolfram.com/xid/0girdm-lanl90

https://wolfram.com/xid/0girdm-o08r3d

https://wolfram.com/xid/0girdm-p7j2an

Unprotect and clear all symbols in a package, to allow it to be read twice:

https://wolfram.com/xid/0girdm-xyeurw

https://wolfram.com/xid/0girdm-tkjxv3

https://wolfram.com/xid/0girdm-1ogb5x

https://wolfram.com/xid/0girdm-1eht7q

https://wolfram.com/xid/0girdm-wsiohw
Properties & Relations (6)Properties of the function, and connections to other functions
Clear[pattern] clears the same symbols as Clear/@Names[pattern]:

https://wolfram.com/xid/0girdm-g68m9z


https://wolfram.com/xid/0girdm-olxyis

Use Unset (=.) to clear definitions with a particular left-hand side:

https://wolfram.com/xid/0girdm-mpj5jz

https://wolfram.com/xid/0girdm-wqsuy

https://wolfram.com/xid/0girdm-z4e5a


https://wolfram.com/xid/0girdm-dvfuo1

https://wolfram.com/xid/0girdm-fjiqex

Clear does not remove attributes, defaults or options:

https://wolfram.com/xid/0girdm-d9ifq8

https://wolfram.com/xid/0girdm-i9a3c3

https://wolfram.com/xid/0girdm-gbg3pw

Use ClearAll to clear everything:

https://wolfram.com/xid/0girdm-fc1pz8

https://wolfram.com/xid/0girdm-foikwx

Clear does not remove messages:

https://wolfram.com/xid/0girdm-3r2fk5

https://wolfram.com/xid/0girdm-1rtdik

https://wolfram.com/xid/0girdm-fcys54

Use ClearAll to clear messages:

https://wolfram.com/xid/0girdm-0lejh3

https://wolfram.com/xid/0girdm-3t4ohc

Clear removes all definitions but leaves the symbol intact:

https://wolfram.com/xid/0girdm-swru6m

https://wolfram.com/xid/0girdm-1270ov

https://wolfram.com/xid/0girdm-4mv80x

Remove removes the symbol completely:

https://wolfram.com/xid/0girdm-bn6db5

https://wolfram.com/xid/0girdm-topoov

Clear has the attribute HoldAll:

https://wolfram.com/xid/0girdm-h5353g


https://wolfram.com/xid/0girdm-fx3wr4

https://wolfram.com/xid/0girdm-4d3chu

https://wolfram.com/xid/0girdm-svaskv


https://wolfram.com/xid/0girdm-rc7lad

https://wolfram.com/xid/0girdm-u2f10x

https://wolfram.com/xid/0girdm-68t1mh

Possible Issues (2)Common pitfalls and unexpected behavior
Protected symbols cannot be cleared:

https://wolfram.com/xid/0girdm-f41vz7

https://wolfram.com/xid/0girdm-npqgli

Use Unprotect to clear definitions of protected symbols:

https://wolfram.com/xid/0girdm-csvxte
When using a pattern without a context mark, all matching symbols on $ContextPath are cleared:

https://wolfram.com/xid/0girdm-yjoaby




The symbol xy was cleared, along with attempts to clear several system symbols:

https://wolfram.com/xid/0girdm-fhjmtu

Use a pattern with an explicit context mark to avoid potentially matching symbols from system or other contexts:

https://wolfram.com/xid/0girdm-8w4y3l
Wolfram Research (1988), Clear, Wolfram Language function, https://reference.wolfram.com/language/ref/Clear.html (updated 2022).
Text
Wolfram Research (1988), Clear, Wolfram Language function, https://reference.wolfram.com/language/ref/Clear.html (updated 2022).
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.
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
Wolfram Language. (1988). Clear. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Clear.html
BibTeX
@misc{reference.wolfram_2025_clear, author="Wolfram Research", title="{Clear}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Clear.html}", note=[Accessed: 28-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_clear, organization={Wolfram Research}, title={Clear}, year={2022}, url={https://reference.wolfram.com/language/ref/Clear.html}, note=[Accessed: 28-April-2025
]}