Can I interpolate a string in a regular expression?


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

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.


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


I tried searching first but nothing useful came up :frowning:

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