ikegami's replies have pretty well covered this question, but for further discussion of template evaluation in a substitution replacement (which is what I take the OP to be about), see nodes
printig with variables in text and
simple regular expression and, with a bit of redundancy,
s/// treat rhs as regex.