String substitution with interpolation

Hello, I’d like to have something like:

foo(rs::String, t::String) = replace(rs, r"(aa|bb)" => s"\1$(t)")

Note the replacement string uses both a substitution (\1) and an interpolation ($t). This does not seem to be allowed and I’m not sure what my options are short of doing a match and writing the replacement myself manually.

Ideally the function would do:

foo("aac", "dd") == "aaddc"
foo("bbe", "ff") == "bbffe"

Am I missing something? is there a natural way to do this? thanks!

Ok well I should have thought for two minutes more, using the SubstitutionString constructor does what I want. I’ll leave this here lest it should be useful for someone else:

foo(rs::String, t::String) = replace(rs, r"(aa|bb)" => SubstitutionString("\\1$(t)"))