title: Python library to generate regular expressions
body: <p>Is there any lib out there that can take a text (like a html document) and a list of strings (like the name of some products) and then find a pattern in the list of strings and generate a regular expression that would extract all the strings in the text (html document) that match the pattern it found?</p>
  
  <p>For example, given the following html:</p>
  
  <pre><code>&lt;table&gt;
    &lt;tr&gt;
      &lt;td&gt;Product 1&lt;/td&gt;
      &lt;td&gt;Product 2&lt;/td&gt;
      &lt;td&gt;Product 3&lt;/td&gt;
      &lt;td&gt;Product 4&lt;/td&gt;
      &lt;td&gt;Product 5&lt;/td&gt;
      &lt;td&gt;Product 6&lt;/td&gt;
      &lt;td&gt;Product 7&lt;/td&gt;
      &lt;td&gt;Product 8&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>and the following list of strings:</p>
  
  <pre><code>['Product 1', 'Product 2', 'Product 3']
  </code></pre>
  
  <p><strong>I'd like a function that would build a regex like the following</strong>:</p>
  
  <pre><code>'&lt;td&gt;(.*?)&lt;/td&gt;'
  </code></pre>
  
  <p>and then extract all the information from the html that match the regex.
  In this case, the output would be:</p>
  
  <pre><code>['Product 1', 'Product 2', 'Product 3', 'Product 4', 'Product 5', 'Product 6', 'Product 7', 'Product 8']
  </code></pre>
  
  <p>CLARIFICATION:</p>
  
  <p>I'd like the function to look at the surrounding of the samples, not at the samples themselves.
  So, for example, if the html was:</p>
  
  <pre><code>&lt;tr&gt;
    &lt;td&gt;Word&lt;/td&gt;
    &lt;td&gt;More words&lt;/td&gt;
    &lt;td&gt;101&lt;/td&gt;
    &lt;td&gt;-1-0-1-&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>and the samples <code>['Word', 'More words']</code> I'd like it to extract:</p>
  
  <pre><code>['Word', 'More words', '101', '-1-0-1-']
  </code></pre>