# Can I interpolate a string in a regular expression?

**URL:** <https://discourse.julialang.org/t/can-i-interpolate-a-string-in-a-regular-expression/10763>\
**Category:** New to Julia\
**Tags:** regex, string-interpolation\
**Created:** [May 7, 2018, 5:00pm UTC](https://discourse.julialang.org/t/can-i-interpolate-a-string-in-a-regular-expression/10763 "2018-05-07T17:00:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [May 7, 2018, 5:00pm UTC](https://discourse.julialang.org/t/can-i-interpolate-a-string-in-a-regular-expression/10763/1 "2018-05-07T17:00:26Z")

</div>

As in the title, how can I make the code below `match`?

```julia
a = "a"

ismatch(r"th$(a)t", "this that") # returns false

```

The problem is that `$` has a meaning in a regular expression, but is also used for interpolating strings in Julia.

---

<div class="post-metadata">

**Author:** ![NiclasMattsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niclasmattsson/32/21988_2.png) [@NiclasMattsson](https://discourse.julialang.org/u/NiclasMattsson)\
**Post date:** [May 7, 2018, 5:07pm UTC](https://discourse.julialang.org/t/can-i-interpolate-a-string-in-a-regular-expression/10763/2 "2018-05-07T17:07:36Z")

</div>

In an ideal world this thread would pop up as a suggestion as you typed the title of your post:

> [@Regex w/ String Interpolation](https://discourse.julialang.org/t/regex-w-string-interpolation/3545):
>
> I want to do something along the lines of: a = "focus" ismatch(r"$(a)\s\*:\s\*true", "# focus: true") But this doesnt work // probably similar to [issue #1797](https://github.com/JuliaLang/julia/issues/1797) What is the correct way to do this? eval( parse( "ismatch(r\"$(a)\\s\*:\\s\*true\", \"# focus: true\")" ) ) feels super dirty

---

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [May 7, 2018, 5:11pm UTC](https://discourse.julialang.org/t/can-i-interpolate-a-string-in-a-regular-expression/10763/3 "2018-05-07T17:11:03Z")

</div>

I tried searching first but nothing useful came up ☹

---

<div class="post-metadata">

**Author:** ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)\
**Post date:** [May 7, 2018, 5:39pm UTC](https://discourse.julialang.org/t/can-i-interpolate-a-string-in-a-regular-expression/10763/4 "2018-05-07T17:39:14Z")

</div>

```julia
julia> a = "a"
julia> ismatch(Regex("th$(a)t"), "this that")
true

```
