title: python: extracting variables from string templates
body: <p>I am familiar with the ability to insert variables into a string using <a href="https://docs.python.org/2/library/string.html#template-strings" rel="noreferrer">Templates</a>, like this:</p>
  
  <pre><code>Template('value is between $min and $max').substitute(min=5, max=10)
  </code></pre>
  
  <p>What I now want to know is if it is possible to do the reverse.  I want to take a string, and extract the values from it using a template, so that I have some data structure (preferably just named variables, but a dict is fine) that contains the extracted values.  For example:</p>
  
  <pre><code>&gt;&gt;&gt; string = 'value is between 5 and 10'
  &gt;&gt;&gt; d = Backwards_template('value is between $min and $max').extract(string)
  &gt;&gt;&gt; print d
  {'min': '5', 'max':'10'}
  </code></pre>
  
  <p>Is this possible?</p>