# Recommended way to delete user-defined variables

**URL:** <https://discourse.julialang.org/t/recommended-way-to-delete-user-defined-variables/56209>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 28, 2021, 7:59pm UTC](https://discourse.julialang.org/t/recommended-way-to-delete-user-defined-variables/56209 "2021-02-28T19:59:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Post date:** [February 28, 2021, 7:59pm UTC](https://discourse.julialang.org/t/recommended-way-to-delete-user-defined-variables/56209/1 "2021-02-28T19:59:13Z")

</div>

I currently delete all my user-defined variables like this.

```julia
varinfo()
variable1, variable2, variable3 = fill(nothing, 3)

```

Is there a way to make varinfo() output an array of only user-defined variable names instead of a markdown table with extra things like Base, Core, Main, and InteractiveUtils?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [February 28, 2021, 8:08pm UTC](https://discourse.julialang.org/t/recommended-way-to-delete-user-defined-variables/56209/2 "2021-02-28T20:08:14Z")

</div>

I don’t think so. The thing is that `Base`, `Core`, etc. are actually “variables” of `Main`, i.e. `Main.Base` and `Main.Core` etc. In contrast, try this: `module ABC end; varinfo(ABC)`.

What you can do is use the regex option of `varinfo` to filter out `Base`, `Core`, etc.

---

<div class="post-metadata">

**Author:** ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Post date:** [February 28, 2021, 8:12pm UTC](https://discourse.julialang.org/t/recommended-way-to-delete-user-defined-variables/56209/3 "2021-02-28T20:12:16Z")

</div>

how to use the regex option?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [February 28, 2021, 8:30pm UTC](https://discourse.julialang.org/t/recommended-way-to-delete-user-defined-variables/56209/4 "2021-02-28T20:30:05Z")

</div>

Does this do the job for you?

```julia
julia> getvars() = [string(v) for v in sort!(names(Main)) if isdefined(Main, v) && !(v in (:Base, :Main, :Core, :InteractiveUtils, :ans))]
getvars (generic function with 1 method)

julia> getvars()
1-element Array{String,1}:
 "getvars"

julia> x =5
5

julia> getvars()
2-element Array{String,1}:
 "getvars"
 "x"

julia> y = 10
10

julia> getvars()
3-element Array{String,1}:
 "getvars"
 "x"
 "y"

```

---

<div class="post-metadata">

**Author:** ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Post date:** [February 28, 2021, 8:34pm UTC](https://discourse.julialang.org/t/recommended-way-to-delete-user-defined-variables/56209/5 "2021-02-28T20:34:08Z")

</div>

This convenient function should a built-in function for Julia.
