Regex on an Expr


Within the program I have coded, I arrived at a place where I have the following Expr:

ex = :(Float64[32])

Is there any way to extract the number within brackets without doing

ex_str = String(Symbol(ex))
num = match(r"\[\d*\]",ex_str)



julia> ex = :(Float64[32])

julia> number = ex.args[2]

Great, thanks!!

I had tried to inspect the expression with fieldnames(ex), but forgot that it should have been fieldnames(Expr)!

Also always helpful:

julia> :(Float64[32]) |> dump
  head: Symbol ref
  args: Array{Any}((2,))
    1: Symbol Float64
    2: Int64 32
1 Like