Escape template delimiters before using them in a RegExp
(cherry picked from commit 3482ec1259005c175c9e7147cd0ebe8ee4b73581)