title: Variable inside a search pattern in python
body: <p>I have a soup from BeautifulSoup and I have a list of keys (key_image) which value or values I want to introduce in another list.</p>
  
  <pre><code>    soup = BeautifulSoup(stringapplet)
      key_image = ['archivo=', 'imagen=', 'image=', 'imaxe=', 'arquivo=']
      imageslist = []
  </code></pre>
  
  <p>This way I get the list of values for <i>archivo</i>:</p>
  
  <pre><code>    patron = re.compile(r"archivo='([\w\./]+)'")
      for tag in soup.findAll('param'):
          if patron.search(tag['value']):
              imageslist.append(patron.search(tag['value']).group(1))
  </code></pre>
  
  <p>good, but... I need in <i>imageslist</i> also searches of <i>"patrons"</i> like <i>archivo</i>: of <i>imagen</i>, of <i>imaxe</i>... etc. so I suppose I need to introduce a variable in a search pattern, then I do:</p>
  
  <pre><code>    for x in key_image:
          if string.find(stringapplet, x) != -1:
              expression = 'r' + '"' + x + "'" + '([\w\./]+)' + "'" + '"'
              patron = re.compile(expression)
              for tag in soup.findAll('param'):
                  if patron.search(tag['value']):
                      imageslist.append(patron.search(tag['value']).group(1))
  </code></pre>
  
  <p>but <i>imageslist</i> is empty because the last line is never loaded.
  ¿?</p>
  
  <p>I do <i>patron.pattern</i> and I get <i>r"archivo='([\w./]+)'"</i>   also, so what is wrong?</p>
  
  <p>How can I do the search of all values of all key_images values?</p>
  
  <p>Thanks.</p>