title: Python template safe substitution with the custom double-braces format
body: <p>I am trying to substitute variables in the format <code>{{var}}</code> with Python's Template.</p>
  <pre><code>from string import Template
  
  class CustomTemplate(Template):
      delimiter = '{{'
      pattern = r'''
      \{\{(?:
      (?P&lt;escaped&gt;\{\{)|
      (?P&lt;named&gt;[_a-z][_a-z0-9]*)\}\}|
      (?P&lt;braced&gt;[_a-z][_a-z0-9]*)\}\}|
      (?P&lt;invalid&gt;)
      )
      '''
  
  replacement_dict = {
      &quot;test&quot;: &quot;hello&quot;
  }
  
  tpl = '''{
      &quot;unaltered&quot;: &quot;{{foo}}&quot;,
      &quot;replaced&quot;: &quot;{{test}}&quot;
  }'''
  
  a = CustomTemplate(tpl)
  b = a.safe_substitute(replacement_dict)
  
  print(b)
  </code></pre>
  <p>The output:</p>
  <pre><code>{
      &quot;unaltered&quot;: &quot;{{foo&quot;,
      &quot;replaced&quot;: &quot;hello&quot;
  }
  </code></pre>
  <p>As you can see, the <code>{{foo}}</code> variable (which is not part of the replacement) has the closing brackets chopped off. I think it's the way the regex is written (the closing <code>\}\}</code>)?</p>
  <p>I want to solve this with Template, not with any other external libraries.</p>