# Regex on an Expr

**URL:** https://discourse.julialang.org/t/regex-on-an-expr/88560
**Category:** General Usage
**Tags:** metaprogramming
**Created:** [October 11, 2022, 8:09am UTC](https://discourse.julialang.org/t/regex-on-an-expr/88560 "2022-10-11T08:09:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![nandoconde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nandoconde/32/19497_2.png) [@nandoconde](https://discourse.julialang.org/u/nandoconde)
#### Post date: [October 11, 2022, 8:09am UTC](https://discourse.julialang.org/t/regex-on-an-expr/88560/1 "2022-10-11T08:09:57Z")

</div>

Hi!

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

```julia
ex = :(Float64[32])

```

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

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

```

?

Thanks!

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [October 11, 2022, 8:17am UTC](https://discourse.julialang.org/t/regex-on-an-expr/88560/2 "2022-10-11T08:17:25Z")

</div>

```julia
julia> ex = :(Float64[32])
:(Float64[32])

julia> number = ex.args[2]
32

```

---

<div class="post-metadata">

### Author: ![nandoconde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nandoconde/32/19497_2.png) [@nandoconde](https://discourse.julialang.org/u/nandoconde)
#### Post date: [October 11, 2022, 9:07am UTC](https://discourse.julialang.org/t/regex-on-an-expr/88560/3 "2022-10-11T09:07:58Z")

</div>

Great, thanks!!

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

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [October 11, 2022, 10:50am UTC](https://discourse.julialang.org/t/regex-on-an-expr/88560/4 "2022-10-11T10:50:14Z")

</div>

> [@nandoconde](#):
>
> `:(Float64[32])`

Also always helpful:

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

```
