# Regex interpolation

**URL:** <https://discourse.julialang.org/t/regex-interpolation/133683>\
**Category:** General Usage\
**Created:** [November 5, 2025, 5:24pm UTC](https://discourse.julialang.org/t/regex-interpolation/133683 "2025-11-05T17:24:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![healyp](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@healyp](https://discourse.julialang.org/u/healyp)\
**Post date:** [November 5, 2025, 5:24pm UTC](https://discourse.julialang.org/t/regex-interpolation/133683/1 "2025-11-05T17:24:35Z")

</div>

I would like to match a string exactly (using word boundaries) against an interpolated `Regex`. Here’s what I have but the output looks wrong to me. Am I doing something wrong?

```julia
julia> k="t2"
"t2"

julia> r = Regex("\b$(k)\b")
rt"

julia> match(r, "t2") == nothing
true

```

Many thanks.

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [November 5, 2025, 5:42pm UTC](https://discourse.julialang.org/t/regex-interpolation/133683/2 "2025-11-05T17:42:32Z")

</div>

Since you are constructing a string first with `""`, you need to escape the `\b`:

```julia-auto
julia> r = Regex("\\b$(k)\\b")
r"\bt2\b"

julia> match(r, "t2") == nothing
false

```

There is an example at the end of the [documentation](https://docs.julialang.org/en/v1/manual/strings/#man-regex-literals) for regex literals.
