# How to remove comments from a Julia file?

**URL:** https://discourse.julialang.org/t/how-to-remove-comments-from-a-julia-file/55783
**Category:** General Usage
**Tags:** question
**Created:** [February 22, 2021, 4:38pm UTC](https://discourse.julialang.org/t/how-to-remove-comments-from-a-julia-file/55783 "2021-02-22T16:38:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)
#### Post date: [February 22, 2021, 4:38pm UTC](https://discourse.julialang.org/t/how-to-remove-comments-from-a-julia-file/55783/1 "2021-02-22T16:38:09Z")

</div>

I am processing some Julia code with regexes, to convert the colorschemes in [Colorschemes.jl](https://github.com/JuliaGraphics/ColorSchemes.jl) to `go` objects. I want to remove the comments before feeding the Julia code to my `zsh` script. What are the options?

PS: For the record, this code set is small enough that I can hardcode the problem away, but I’m curious for future reference.

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [February 22, 2021, 4:48pm UTC](https://discourse.julialang.org/t/how-to-remove-comments-from-a-julia-file/55783/2 "2021-02-22T16:48:00Z")

</div>

In the general case, you’ll have to parse the file - simple regexes can grow very complicated once you try to take care of text that looks like a comment inside a string literal.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [February 22, 2021, 4:59pm UTC](https://discourse.julialang.org/t/how-to-remove-comments-from-a-julia-file/55783/3 "2021-02-22T16:59:24Z")

</div>

> [@NightMachinary](#):
>
> I am processing some Julia code with regexes, to convert the colorschemes in [Colorschemes.jl](https://github.com/JuliaGraphics/ColorSchemes.jl) to `go` objects.

Rather than using regexes, you might consider simply using Julia’s parser, which gives you a syntax tree that you can walk to output anything you want. This will be a lot more robust than processing code as strings.

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [February 22, 2021, 5:24pm UTC](https://discourse.julialang.org/t/how-to-remove-comments-from-a-julia-file/55783/4 "2021-02-22T17:24:25Z")

</div>

In case you want to export them all from Julia, it might be simpler to just do this:

```julia
using ColorSchemes
for cs in ColorSchemes.colorschemes
    println(first(cs))
    for color in last(cs).colors
        println(color)
    end
end

=> ...
seaborn_bright
RGB{Float64}(0.00784313725490196,0.24313725490196078,1.0)
RGB{Float64}(1.0,0.48627450980392156,0.0)
RGB{Float64}(0.10196078431372549,0.788235294117647,0.2196078431372549)
RGB{Float64}(0.9098039215686274,0.0,0.043137254901960784)
RGB{Float64}(0.5450980392156862,0.16862745098039217,0.8862745098039215)
RGB{Float64}(0.6235294117647059,0.2823529411764706,0.0)
RGB{Float64}(0.9450980392156862,0.2980392156862745,0.7568627450980392)
RGB{Float64}(0.6392156862745098,0.6392156862745098,0.6392156862745098)
RGB{Float64}(1.0,0.7686274509803922,0.0)
RGB{Float64}(0.0,0.8431372549019608,1.0)

....

```

but parsing Julia code is obviously more fun! 🙂
