title: Python regex, pulling patterns out of a match and using them as input back into the match
body: <p>I have searched for an answer.  I am sure they are out there, but there are way too many false hits.</p>
  
  <p>This is my script (my attempt fails):</p>
  
  <pre><code>#!/bin/env python
  
  import re
  
  usage="""
      My favorite restaurant is &lt;&lt;&lt;res&gt;&gt;&gt;
      My favorite person is &lt;&lt;&lt;per&gt;&gt;&gt;
  """
  
  res="pizza hut"
  per="my sister"
  
  def main():
      value = re.sub(r'&lt;&lt;&lt;(\w+)&gt;&gt;&gt;', globals()[r'\1'], usage)
      print 'value=%s.' % (value)
  
  if ( __name__ == "__main__"):
      main()
  </code></pre>
  
  <p>What I am trying to output is:</p>
  
  <pre><code>value=
      My favorite restaurant is pizza hut
      My favorite person is my sister
  .
  </code></pre>
  
  <p>The closest <a href="https://stackoverflow.com/questions/6206804/regex-to-replace-variables">answer</a> that I have seen, involves maintaining a separate list.  I do not want to have to maintain a separate list.</p>