Can I interpolate a string in a regular expression?


#1

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.


#2

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


#3

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


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